python_code
stringlengths
0
1.8M
repo_name
stringclasses
7 values
file_path
stringlengths
5
99
// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for Digigram Lola PCI-e boards * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/dma-mapping.h> #include <linux/pci.h> #include <linux/delay.h> #include <sound/core.h> #include <sound/pcm.h> #include "lola.h" #define LOLA_MAX_BDL_ENTRIES 8 #define LOLA_MAX_BUF_SIZE (1024*1024*1024) #define LOLA_BDL_ENTRY_SIZE (16 * 16) static struct lola_pcm *lola_get_pcm(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); return &chip->pcm[substream->stream]; } static struct lola_stream *lola_get_stream(struct snd_pcm_substream *substream) { struct lola_pcm *pcm = lola_get_pcm(substream); unsigned int idx = substream->number; return &pcm->streams[idx]; } static unsigned int lola_get_lrc(struct lola *chip) { return lola_readl(chip, BAR1, LRC); } static unsigned int lola_get_tstamp(struct lola *chip, bool quick_no_sync) { unsigned int tstamp = lola_get_lrc(chip) >> 8; if (chip->granularity) { unsigned int wait_banks = quick_no_sync ? 0 : 8; tstamp += (wait_banks + 1) * chip->granularity - 1; tstamp -= tstamp % chip->granularity; } return tstamp << 8; } /* clear any pending interrupt status */ static void lola_stream_clear_pending_irq(struct lola *chip, struct lola_stream *str) { unsigned int val = lola_dsd_read(chip, str->dsd, STS); val &= LOLA_DSD_STS_DESE | LOLA_DSD_STS_BCIS; if (val) lola_dsd_write(chip, str->dsd, STS, val); } static void lola_stream_start(struct lola *chip, struct lola_stream *str, unsigned int tstamp) { lola_stream_clear_pending_irq(chip, str); lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRUN | LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_VLRCV | tstamp); } static void lola_stream_stop(struct lola *chip, struct lola_stream *str, unsigned int tstamp) { lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_VLRCV | tstamp); lola_stream_clear_pending_irq(chip, str); } static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str) { unsigned long end_time = jiffies + msecs_to_jiffies(200); while (time_before(jiffies, end_time)) { unsigned int val; val = lola_dsd_read(chip, str->dsd, CTL); if (!(val & LOLA_DSD_CTL_SRST)) return; msleep(1); } dev_warn(chip->card->dev, "SRST not clear (stream %d)\n", str->dsd); } static int lola_stream_wait_for_fifo(struct lola *chip, struct lola_stream *str, bool ready) { unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0; unsigned long end_time = jiffies + msecs_to_jiffies(200); while (time_before(jiffies, end_time)) { unsigned int reg = lola_dsd_read(chip, str->dsd, STS); if ((reg & LOLA_DSD_STS_FIFORDY) == val) return 0; msleep(1); } dev_warn(chip->card->dev, "FIFO not ready (stream %d)\n", str->dsd); return -EIO; } /* sync for FIFO ready/empty for all linked streams; * clear paused flag when FIFO gets ready again */ static int lola_sync_wait_for_fifo(struct lola *chip, struct snd_pcm_substream *substream, bool ready) { unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0; unsigned long end_time = jiffies + msecs_to_jiffies(200); struct snd_pcm_substream *s; int pending = 0; while (time_before(jiffies, end_time)) { pending = 0; snd_pcm_group_for_each_entry(s, substream) { struct lola_stream *str; if (s->pcm->card != substream->pcm->card) continue; str = lola_get_stream(s); if (str->prepared && str->paused) { unsigned int reg; reg = lola_dsd_read(chip, str->dsd, STS); if ((reg & LOLA_DSD_STS_FIFORDY) != val) { pending = str->dsd + 1; break; } if (ready) str->paused = 0; } } if (!pending) return 0; msleep(1); } dev_warn(chip->card->dev, "FIFO not ready (pending %d)\n", pending - 1); return -EIO; } /* finish pause - prepare for a new resume */ static void lola_sync_pause(struct lola *chip, struct snd_pcm_substream *substream) { struct snd_pcm_substream *s; lola_sync_wait_for_fifo(chip, substream, false); snd_pcm_group_for_each_entry(s, substream) { struct lola_stream *str; if (s->pcm->card != substream->pcm->card) continue; str = lola_get_stream(s); if (str->paused && str->prepared) lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRUN | LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE); } lola_sync_wait_for_fifo(chip, substream, true); } static void lola_stream_reset(struct lola *chip, struct lola_stream *str) { if (str->prepared) { if (str->paused) lola_sync_pause(chip, str->substream); str->prepared = 0; lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE); lola_stream_wait_for_fifo(chip, str, false); lola_stream_clear_pending_irq(chip, str); lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRST); lola_dsd_write(chip, str->dsd, LVI, 0); lola_dsd_write(chip, str->dsd, BDPU, 0); lola_dsd_write(chip, str->dsd, BDPL, 0); wait_for_srst_clear(chip, str); } } static const struct snd_pcm_hardware lola_pcm_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_FLOAT_LE), .rates = SNDRV_PCM_RATE_8000_192000, .rate_min = 8000, .rate_max = 192000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = LOLA_MAX_BUF_SIZE, .period_bytes_min = 128, .period_bytes_max = LOLA_MAX_BUF_SIZE / 2, .periods_min = 2, .periods_max = LOLA_MAX_BDL_ENTRIES, .fifo_size = 0, }; static int lola_pcm_open(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_pcm *pcm = lola_get_pcm(substream); struct lola_stream *str = lola_get_stream(substream); struct snd_pcm_runtime *runtime = substream->runtime; mutex_lock(&chip->open_mutex); if (str->opened) { mutex_unlock(&chip->open_mutex); return -EBUSY; } str->substream = substream; str->master = NULL; str->opened = 1; runtime->hw = lola_pcm_hw; runtime->hw.channels_max = pcm->num_streams - str->index; if (chip->sample_rate) { /* sample rate is locked */ runtime->hw.rate_min = chip->sample_rate; runtime->hw.rate_max = chip->sample_rate; } else { runtime->hw.rate_min = chip->sample_rate_min; runtime->hw.rate_max = chip->sample_rate_max; } chip->ref_count_rate++; snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); /* period size = multiple of chip->granularity (8, 16 or 32 frames)*/ snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, chip->granularity); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, chip->granularity); mutex_unlock(&chip->open_mutex); return 0; } static void lola_cleanup_slave_streams(struct lola_pcm *pcm, struct lola_stream *str) { int i; for (i = str->index + 1; i < pcm->num_streams; i++) { struct lola_stream *s = &pcm->streams[i]; if (s->master != str) break; s->master = NULL; s->opened = 0; } } static int lola_pcm_close(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_stream *str = lola_get_stream(substream); mutex_lock(&chip->open_mutex); if (str->substream == substream) { str->substream = NULL; str->opened = 0; } if (--chip->ref_count_rate == 0) { /* release sample rate */ chip->sample_rate = 0; } mutex_unlock(&chip->open_mutex); return 0; } static int lola_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct lola_stream *str = lola_get_stream(substream); str->bufsize = 0; str->period_bytes = 0; str->format_verb = 0; return 0; } static int lola_pcm_hw_free(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_pcm *pcm = lola_get_pcm(substream); struct lola_stream *str = lola_get_stream(substream); mutex_lock(&chip->open_mutex); lola_stream_reset(chip, str); lola_cleanup_slave_streams(pcm, str); mutex_unlock(&chip->open_mutex); return 0; } /* * set up a BDL entry */ static int setup_bdle(struct snd_pcm_substream *substream, struct lola_stream *str, __le32 **bdlp, int ofs, int size) { __le32 *bdl = *bdlp; while (size > 0) { dma_addr_t addr; int chunk; if (str->frags >= LOLA_MAX_BDL_ENTRIES) return -EINVAL; addr = snd_pcm_sgbuf_get_addr(substream, ofs); /* program the address field of the BDL entry */ bdl[0] = cpu_to_le32((u32)addr); bdl[1] = cpu_to_le32(upper_32_bits(addr)); /* program the size field of the BDL entry */ chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); bdl[2] = cpu_to_le32(chunk); /* program the IOC to enable interrupt * only when the whole fragment is processed */ size -= chunk; bdl[3] = size ? 0 : cpu_to_le32(0x01); bdl += 4; str->frags++; ofs += chunk; } *bdlp = bdl; return ofs; } /* * set up BDL entries */ static int lola_setup_periods(struct lola *chip, struct lola_pcm *pcm, struct snd_pcm_substream *substream, struct lola_stream *str) { __le32 *bdl; int i, ofs, periods, period_bytes; period_bytes = str->period_bytes; periods = str->bufsize / period_bytes; /* program the initial BDL entries */ bdl = (__le32 *)(pcm->bdl->area + LOLA_BDL_ENTRY_SIZE * str->index); ofs = 0; str->frags = 0; for (i = 0; i < periods; i++) { ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes); if (ofs < 0) goto error; } return 0; error: dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n", str->bufsize, period_bytes); return -EINVAL; } static unsigned int lola_get_format_verb(struct snd_pcm_substream *substream) { unsigned int verb; switch (substream->runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: verb = 0x00000000; break; case SNDRV_PCM_FORMAT_S24_LE: verb = 0x00000200; break; case SNDRV_PCM_FORMAT_S32_LE: verb = 0x00000300; break; case SNDRV_PCM_FORMAT_FLOAT_LE: verb = 0x00001300; break; default: return 0; } verb |= substream->runtime->channels; return verb; } static int lola_set_stream_config(struct lola *chip, struct lola_stream *str, int channels) { int i, err; unsigned int verb, val; /* set format info for all channels * (with only one command for the first channel) */ err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT, str->format_verb, 0, &val, NULL); if (err < 0) { dev_err(chip->card->dev, "Cannot set stream format 0x%x\n", str->format_verb); return err; } /* update stream - channel config */ for (i = 0; i < channels; i++) { verb = (str->index << 6) | i; err = lola_codec_read(chip, str[i].nid, LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb, &val, NULL); if (err < 0) { dev_err(chip->card->dev, "Cannot set stream channel %d\n", i); return err; } } return 0; } /* * set up the SD for streaming */ static int lola_setup_controller(struct lola *chip, struct lola_pcm *pcm, struct lola_stream *str) { dma_addr_t bdl; if (str->prepared) return -EINVAL; /* set up BDL */ bdl = pcm->bdl->addr + LOLA_BDL_ENTRY_SIZE * str->index; lola_dsd_write(chip, str->dsd, BDPL, (u32)bdl); lola_dsd_write(chip, str->dsd, BDPU, upper_32_bits(bdl)); /* program the stream LVI (last valid index) of the BDL */ lola_dsd_write(chip, str->dsd, LVI, str->frags - 1); lola_stream_clear_pending_irq(chip, str); lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_SRUN); str->prepared = 1; return lola_stream_wait_for_fifo(chip, str, true); } static int lola_pcm_prepare(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_pcm *pcm = lola_get_pcm(substream); struct lola_stream *str = lola_get_stream(substream); struct snd_pcm_runtime *runtime = substream->runtime; unsigned int bufsize, period_bytes, format_verb; int i, err; mutex_lock(&chip->open_mutex); lola_stream_reset(chip, str); lola_cleanup_slave_streams(pcm, str); if (str->index + runtime->channels > pcm->num_streams) { mutex_unlock(&chip->open_mutex); return -EINVAL; } for (i = 1; i < runtime->channels; i++) { str[i].master = str; str[i].opened = 1; } mutex_unlock(&chip->open_mutex); bufsize = snd_pcm_lib_buffer_bytes(substream); period_bytes = snd_pcm_lib_period_bytes(substream); format_verb = lola_get_format_verb(substream); str->bufsize = bufsize; str->period_bytes = period_bytes; str->format_verb = format_verb; err = lola_setup_periods(chip, pcm, substream, str); if (err < 0) return err; err = lola_set_sample_rate(chip, runtime->rate); if (err < 0) return err; chip->sample_rate = runtime->rate; /* sample rate gets locked */ err = lola_set_stream_config(chip, str, runtime->channels); if (err < 0) return err; err = lola_setup_controller(chip, pcm, str); if (err < 0) { lola_stream_reset(chip, str); return err; } return 0; } static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_stream *str; struct snd_pcm_substream *s; unsigned int start; unsigned int tstamp; bool sync_streams; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: start = 1; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_STOP: start = 0; break; default: return -EINVAL; } /* * sample correct synchronization is only needed starting several * streams. On stop or if only one stream do as quick as possible */ sync_streams = (start && snd_pcm_stream_linked(substream)); tstamp = lola_get_tstamp(chip, !sync_streams); spin_lock(&chip->reg_lock); snd_pcm_group_for_each_entry(s, substream) { if (s->pcm->card != substream->pcm->card) continue; str = lola_get_stream(s); if (start) lola_stream_start(chip, str, tstamp); else lola_stream_stop(chip, str, tstamp); str->running = start; str->paused = !start; snd_pcm_trigger_done(s, substream); } spin_unlock(&chip->reg_lock); return 0; } static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream) { struct lola *chip = snd_pcm_substream_chip(substream); struct lola_stream *str = lola_get_stream(substream); unsigned int pos = lola_dsd_read(chip, str->dsd, LPIB); if (pos >= str->bufsize) pos = 0; return bytes_to_frames(substream->runtime, pos); } void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits) { int i; u8 num_streams = min_t(u8, pcm->num_streams, ARRAY_SIZE(pcm->streams)); for (i = 0; bits && i < num_streams; i++) { if (bits & (1 << i)) { struct lola_stream *str = &pcm->streams[i]; if (str->substream && str->running) snd_pcm_period_elapsed(str->substream); bits &= ~(1 << i); } } } static const struct snd_pcm_ops lola_pcm_ops = { .open = lola_pcm_open, .close = lola_pcm_close, .hw_params = lola_pcm_hw_params, .hw_free = lola_pcm_hw_free, .prepare = lola_pcm_prepare, .trigger = lola_pcm_trigger, .pointer = lola_pcm_pointer, }; int lola_create_pcm(struct lola *chip) { struct snd_pcm *pcm; int i, err; for (i = 0; i < 2; i++) { chip->pcm[i].bdl = snd_devm_alloc_pages(&chip->pci->dev, SNDRV_DMA_TYPE_DEV, PAGE_SIZE); if (!chip->pcm[i].bdl) return -ENOMEM; } err = snd_pcm_new(chip->card, "Digigram Lola", 0, chip->pcm[SNDRV_PCM_STREAM_PLAYBACK].num_streams, chip->pcm[SNDRV_PCM_STREAM_CAPTURE].num_streams, &pcm); if (err < 0) return err; strscpy(pcm->name, "Digigram Lola", sizeof(pcm->name)); pcm->private_data = chip; for (i = 0; i < 2; i++) { if (chip->pcm[i].num_streams) snd_pcm_set_ops(pcm, i, &lola_pcm_ops); } /* buffer pre-allocation */ snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, &chip->pci->dev, 1024 * 64, 32 * 1024 * 1024); return 0; } /* */ static int lola_init_stream(struct lola *chip, struct lola_stream *str, int idx, int nid, int dir) { unsigned int val; int err; str->nid = nid; str->index = idx; str->dsd = idx; if (dir == PLAY) str->dsd += MAX_STREAM_IN_COUNT; err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid); return err; } if (dir == PLAY) { /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */ if ((val & 0x00f00dff) != 0x00000010) { dev_err(chip->card->dev, "Invalid wcaps 0x%x for 0x%x\n", val, nid); return -EINVAL; } } else { /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) * (bug : ignore bit8: Conn list = 0/1) */ if ((val & 0x00f00cff) != 0x00100010) { dev_err(chip->card->dev, "Invalid wcaps 0x%x for 0x%x\n", val, nid); return -EINVAL; } /* test bit9:DIGITAL and bit12:SRC_PRESENT*/ if ((val & 0x00001200) == 0x00001200) chip->input_src_caps_mask |= (1 << idx); } err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read FORMATS 0x%x\n", nid); return err; } val &= 3; if (val == 3) str->can_float = true; if (!(val & 1)) { dev_err(chip->card->dev, "Invalid formats 0x%x for 0x%x", val, nid); return -EINVAL; } return 0; } int lola_init_pcm(struct lola *chip, int dir, int *nidp) { struct lola_pcm *pcm = &chip->pcm[dir]; int i, nid, err; nid = *nidp; for (i = 0; i < pcm->num_streams; i++, nid++) { err = lola_init_stream(chip, &pcm->streams[i], i, nid, dir); if (err < 0) return err; } *nidp = nid; return 0; }
linux-master
sound/pci/lola/lola_pcm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for Digigram Lola PCI-e boards * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h> #include <linux/dma-mapping.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/slab.h> #include <linux/pci.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/initval.h> #include "lola.h" /* Standard options */ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Digigram Lola driver."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Digigram Lola driver."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Digigram Lola driver."); /* Lola-specific options */ /* for instance use always max granularity which is compatible * with all sample rates */ static int granularity[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1)] = LOLA_GRANULARITY_MAX }; /* below a sample_rate of 16kHz the analogue audio quality is NOT excellent */ static int sample_rate_min[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS - 1) ] = 16000 }; module_param_array(granularity, int, NULL, 0444); MODULE_PARM_DESC(granularity, "Granularity value"); module_param_array(sample_rate_min, int, NULL, 0444); MODULE_PARM_DESC(sample_rate_min, "Minimal sample rate"); /* */ MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Digigram Lola driver"); MODULE_AUTHOR("Takashi Iwai <[email protected]>"); #ifdef CONFIG_SND_DEBUG_VERBOSE static int debug; module_param(debug, int, 0644); #define verbose_debug(fmt, args...) \ do { if (debug > 1) pr_debug(SFX fmt, ##args); } while (0) #else #define verbose_debug(fmt, args...) #endif /* * pseudo-codec read/write via CORB/RIRB */ static int corb_send_verb(struct lola *chip, unsigned int nid, unsigned int verb, unsigned int data, unsigned int extdata) { unsigned long flags; int ret = -EIO; chip->last_cmd_nid = nid; chip->last_verb = verb; chip->last_data = data; chip->last_extdata = extdata; data |= (nid << 20) | (verb << 8); spin_lock_irqsave(&chip->reg_lock, flags); if (chip->rirb.cmds < LOLA_CORB_ENTRIES - 1) { unsigned int wp = chip->corb.wp + 1; wp %= LOLA_CORB_ENTRIES; chip->corb.wp = wp; chip->corb.buf[wp * 2] = cpu_to_le32(data); chip->corb.buf[wp * 2 + 1] = cpu_to_le32(extdata); lola_writew(chip, BAR0, CORBWP, wp); chip->rirb.cmds++; smp_wmb(); ret = 0; } spin_unlock_irqrestore(&chip->reg_lock, flags); return ret; } static void lola_queue_unsol_event(struct lola *chip, unsigned int res, unsigned int res_ex) { lola_update_ext_clock_freq(chip, res); } /* retrieve RIRB entry - called from interrupt handler */ static void lola_update_rirb(struct lola *chip) { unsigned int rp, wp; u32 res, res_ex; wp = lola_readw(chip, BAR0, RIRBWP); if (wp == chip->rirb.wp) return; chip->rirb.wp = wp; while (chip->rirb.rp != wp) { chip->rirb.rp++; chip->rirb.rp %= LOLA_CORB_ENTRIES; rp = chip->rirb.rp << 1; /* an RIRB entry is 8-bytes */ res_ex = le32_to_cpu(chip->rirb.buf[rp + 1]); res = le32_to_cpu(chip->rirb.buf[rp]); if (res_ex & LOLA_RIRB_EX_UNSOL_EV) lola_queue_unsol_event(chip, res, res_ex); else if (chip->rirb.cmds) { chip->res = res; chip->res_ex = res_ex; smp_wmb(); chip->rirb.cmds--; } } } static int rirb_get_response(struct lola *chip, unsigned int *val, unsigned int *extval) { unsigned long timeout; again: timeout = jiffies + msecs_to_jiffies(1000); for (;;) { if (chip->polling_mode) { spin_lock_irq(&chip->reg_lock); lola_update_rirb(chip); spin_unlock_irq(&chip->reg_lock); } if (!chip->rirb.cmds) { *val = chip->res; if (extval) *extval = chip->res_ex; verbose_debug("get_response: %x, %x\n", chip->res, chip->res_ex); if (chip->res_ex & LOLA_RIRB_EX_ERROR) { dev_warn(chip->card->dev, "RIRB ERROR: " "NID=%x, verb=%x, data=%x, ext=%x\n", chip->last_cmd_nid, chip->last_verb, chip->last_data, chip->last_extdata); return -EIO; } return 0; } if (time_after(jiffies, timeout)) break; udelay(20); cond_resched(); } dev_warn(chip->card->dev, "RIRB response error\n"); if (!chip->polling_mode) { dev_warn(chip->card->dev, "switching to polling mode\n"); chip->polling_mode = 1; goto again; } return -EIO; } /* aynchronous write of a codec verb with data */ int lola_codec_write(struct lola *chip, unsigned int nid, unsigned int verb, unsigned int data, unsigned int extdata) { verbose_debug("codec_write NID=%x, verb=%x, data=%x, ext=%x\n", nid, verb, data, extdata); return corb_send_verb(chip, nid, verb, data, extdata); } /* write a codec verb with data and read the returned status */ int lola_codec_read(struct lola *chip, unsigned int nid, unsigned int verb, unsigned int data, unsigned int extdata, unsigned int *val, unsigned int *extval) { int err; verbose_debug("codec_read NID=%x, verb=%x, data=%x, ext=%x\n", nid, verb, data, extdata); err = corb_send_verb(chip, nid, verb, data, extdata); if (err < 0) return err; err = rirb_get_response(chip, val, extval); return err; } /* flush all pending codec writes */ int lola_codec_flush(struct lola *chip) { unsigned int tmp; return rirb_get_response(chip, &tmp, NULL); } /* * interrupt handler */ static irqreturn_t lola_interrupt(int irq, void *dev_id) { struct lola *chip = dev_id; unsigned int notify_ins, notify_outs, error_ins, error_outs; int handled = 0; int i; notify_ins = notify_outs = error_ins = error_outs = 0; spin_lock(&chip->reg_lock); for (;;) { unsigned int status, in_sts, out_sts; unsigned int reg; status = lola_readl(chip, BAR1, DINTSTS); if (!status || status == -1) break; in_sts = lola_readl(chip, BAR1, DIINTSTS); out_sts = lola_readl(chip, BAR1, DOINTSTS); /* clear Input Interrupts */ for (i = 0; in_sts && i < chip->pcm[CAPT].num_streams; i++) { if (!(in_sts & (1 << i))) continue; in_sts &= ~(1 << i); reg = lola_dsd_read(chip, i, STS); if (reg & LOLA_DSD_STS_DESE) /* error */ error_ins |= (1 << i); if (reg & LOLA_DSD_STS_BCIS) /* notify */ notify_ins |= (1 << i); /* clear */ lola_dsd_write(chip, i, STS, reg); } /* clear Output Interrupts */ for (i = 0; out_sts && i < chip->pcm[PLAY].num_streams; i++) { if (!(out_sts & (1 << i))) continue; out_sts &= ~(1 << i); reg = lola_dsd_read(chip, i + MAX_STREAM_IN_COUNT, STS); if (reg & LOLA_DSD_STS_DESE) /* error */ error_outs |= (1 << i); if (reg & LOLA_DSD_STS_BCIS) /* notify */ notify_outs |= (1 << i); lola_dsd_write(chip, i + MAX_STREAM_IN_COUNT, STS, reg); } if (status & LOLA_DINT_CTRL) { unsigned char rbsts; /* ring status is byte access */ rbsts = lola_readb(chip, BAR0, RIRBSTS); rbsts &= LOLA_RIRB_INT_MASK; if (rbsts) lola_writeb(chip, BAR0, RIRBSTS, rbsts); rbsts = lola_readb(chip, BAR0, CORBSTS); rbsts &= LOLA_CORB_INT_MASK; if (rbsts) lola_writeb(chip, BAR0, CORBSTS, rbsts); lola_update_rirb(chip); } if (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR)) { /* clear global fifo error interrupt */ lola_writel(chip, BAR1, DINTSTS, (status & (LOLA_DINT_FIFOERR | LOLA_DINT_MUERR))); } handled = 1; } spin_unlock(&chip->reg_lock); lola_pcm_update(chip, &chip->pcm[CAPT], notify_ins); lola_pcm_update(chip, &chip->pcm[PLAY], notify_outs); return IRQ_RETVAL(handled); } /* * controller */ static int reset_controller(struct lola *chip) { unsigned int gctl = lola_readl(chip, BAR0, GCTL); unsigned long end_time; if (gctl) { /* to be sure */ lola_writel(chip, BAR1, BOARD_MODE, 0); return 0; } chip->cold_reset = 1; lola_writel(chip, BAR0, GCTL, LOLA_GCTL_RESET); end_time = jiffies + msecs_to_jiffies(200); do { msleep(1); gctl = lola_readl(chip, BAR0, GCTL); if (gctl) break; } while (time_before(jiffies, end_time)); if (!gctl) { dev_err(chip->card->dev, "cannot reset controller\n"); return -EIO; } return 0; } static void lola_irq_enable(struct lola *chip) { unsigned int val; /* enalbe all I/O streams */ val = (1 << chip->pcm[PLAY].num_streams) - 1; lola_writel(chip, BAR1, DOINTCTL, val); val = (1 << chip->pcm[CAPT].num_streams) - 1; lola_writel(chip, BAR1, DIINTCTL, val); /* enable global irqs */ val = LOLA_DINT_GLOBAL | LOLA_DINT_CTRL | LOLA_DINT_FIFOERR | LOLA_DINT_MUERR; lola_writel(chip, BAR1, DINTCTL, val); } static void lola_irq_disable(struct lola *chip) { lola_writel(chip, BAR1, DINTCTL, 0); lola_writel(chip, BAR1, DIINTCTL, 0); lola_writel(chip, BAR1, DOINTCTL, 0); } static int setup_corb_rirb(struct lola *chip) { unsigned char tmp; unsigned long end_time; chip->rb = snd_devm_alloc_pages(&chip->pci->dev, SNDRV_DMA_TYPE_DEV, PAGE_SIZE); if (!chip->rb) return -ENOMEM; chip->corb.addr = chip->rb->addr; chip->corb.buf = (__le32 *)chip->rb->area; chip->rirb.addr = chip->rb->addr + 2048; chip->rirb.buf = (__le32 *)(chip->rb->area + 2048); /* disable ringbuffer DMAs */ lola_writeb(chip, BAR0, RIRBCTL, 0); lola_writeb(chip, BAR0, CORBCTL, 0); end_time = jiffies + msecs_to_jiffies(200); do { if (!lola_readb(chip, BAR0, RIRBCTL) && !lola_readb(chip, BAR0, CORBCTL)) break; msleep(1); } while (time_before(jiffies, end_time)); /* CORB set up */ lola_writel(chip, BAR0, CORBLBASE, (u32)chip->corb.addr); lola_writel(chip, BAR0, CORBUBASE, upper_32_bits(chip->corb.addr)); /* set the corb size to 256 entries */ lola_writeb(chip, BAR0, CORBSIZE, 0x02); /* set the corb write pointer to 0 */ lola_writew(chip, BAR0, CORBWP, 0); /* reset the corb hw read pointer */ lola_writew(chip, BAR0, CORBRP, LOLA_RBRWP_CLR); /* enable corb dma */ lola_writeb(chip, BAR0, CORBCTL, LOLA_RBCTL_DMA_EN); /* clear flags if set */ tmp = lola_readb(chip, BAR0, CORBSTS) & LOLA_CORB_INT_MASK; if (tmp) lola_writeb(chip, BAR0, CORBSTS, tmp); chip->corb.wp = 0; /* RIRB set up */ lola_writel(chip, BAR0, RIRBLBASE, (u32)chip->rirb.addr); lola_writel(chip, BAR0, RIRBUBASE, upper_32_bits(chip->rirb.addr)); /* set the rirb size to 256 entries */ lola_writeb(chip, BAR0, RIRBSIZE, 0x02); /* reset the rirb hw write pointer */ lola_writew(chip, BAR0, RIRBWP, LOLA_RBRWP_CLR); /* set N=1, get RIRB response interrupt for new entry */ lola_writew(chip, BAR0, RINTCNT, 1); /* enable rirb dma and response irq */ lola_writeb(chip, BAR0, RIRBCTL, LOLA_RBCTL_DMA_EN | LOLA_RBCTL_IRQ_EN); /* clear flags if set */ tmp = lola_readb(chip, BAR0, RIRBSTS) & LOLA_RIRB_INT_MASK; if (tmp) lola_writeb(chip, BAR0, RIRBSTS, tmp); chip->rirb.rp = chip->rirb.cmds = 0; return 0; } static void stop_corb_rirb(struct lola *chip) { /* disable ringbuffer DMAs */ lola_writeb(chip, BAR0, RIRBCTL, 0); lola_writeb(chip, BAR0, CORBCTL, 0); } static void lola_reset_setups(struct lola *chip) { /* update the granularity */ lola_set_granularity(chip, chip->granularity, true); /* update the sample clock */ lola_set_clock_index(chip, chip->clock.cur_index); /* enable unsolicited events of the clock widget */ lola_enable_clock_events(chip); /* update the analog gains */ lola_setup_all_analog_gains(chip, CAPT, false); /* input, update */ /* update SRC configuration if applicable */ lola_set_src_config(chip, chip->input_src_mask, false); /* update the analog outputs */ lola_setup_all_analog_gains(chip, PLAY, false); /* output, update */ } static int lola_parse_tree(struct lola *chip) { unsigned int val; int nid, err; err = lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read VENDOR_ID\n"); return err; } val >>= 16; if (val != 0x1369) { dev_err(chip->card->dev, "Unknown codec vendor 0x%x\n", val); return -EINVAL; } err = lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read FUNCTION_TYPE\n"); return err; } if (val != 1) { dev_err(chip->card->dev, "Unknown function type %d\n", val); return -EINVAL; } err = lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read SPECCAPS\n"); return err; } chip->lola_caps = val; chip->pin[CAPT].num_pins = LOLA_AFG_INPUT_PIN_COUNT(chip->lola_caps); chip->pin[PLAY].num_pins = LOLA_AFG_OUTPUT_PIN_COUNT(chip->lola_caps); dev_dbg(chip->card->dev, "speccaps=0x%x, pins in=%d, out=%d\n", chip->lola_caps, chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins); if (chip->pin[CAPT].num_pins > MAX_AUDIO_INOUT_COUNT || chip->pin[PLAY].num_pins > MAX_AUDIO_INOUT_COUNT) { dev_err(chip->card->dev, "Invalid Lola-spec caps 0x%x\n", val); return -EINVAL; } nid = 0x02; err = lola_init_pcm(chip, CAPT, &nid); if (err < 0) return err; err = lola_init_pcm(chip, PLAY, &nid); if (err < 0) return err; err = lola_init_pins(chip, CAPT, &nid); if (err < 0) return err; err = lola_init_pins(chip, PLAY, &nid); if (err < 0) return err; if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) { err = lola_init_clock_widget(chip, nid); if (err < 0) return err; nid++; } if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) { err = lola_init_mixer_widget(chip, nid); if (err < 0) return err; nid++; } /* enable unsolicited events of the clock widget */ err = lola_enable_clock_events(chip); if (err < 0) return err; /* if last ResetController was not a ColdReset, we don't know * the state of the card; initialize here again */ if (!chip->cold_reset) { lola_reset_setups(chip); chip->cold_reset = 1; } else { /* set the granularity if it is not the default */ if (chip->granularity != LOLA_GRANULARITY_MIN) lola_set_granularity(chip, chip->granularity, true); } return 0; } static void lola_stop_hw(struct lola *chip) { stop_corb_rirb(chip); lola_irq_disable(chip); } static void lola_free(struct snd_card *card) { struct lola *chip = card->private_data; if (chip->initialized) lola_stop_hw(chip); lola_free_mixer(chip); } static int lola_create(struct snd_card *card, struct pci_dev *pci, int dev) { struct lola *chip = card->private_data; int err; unsigned int dever; err = pcim_enable_device(pci); if (err < 0) return err; spin_lock_init(&chip->reg_lock); mutex_init(&chip->open_mutex); chip->card = card; chip->pci = pci; chip->irq = -1; card->private_free = lola_free; chip->granularity = granularity[dev]; switch (chip->granularity) { case 8: chip->sample_rate_max = 48000; break; case 16: chip->sample_rate_max = 96000; break; case 32: chip->sample_rate_max = 192000; break; default: dev_warn(chip->card->dev, "Invalid granularity %d, reset to %d\n", chip->granularity, LOLA_GRANULARITY_MAX); chip->granularity = LOLA_GRANULARITY_MAX; chip->sample_rate_max = 192000; break; } chip->sample_rate_min = sample_rate_min[dev]; if (chip->sample_rate_min > chip->sample_rate_max) { dev_warn(chip->card->dev, "Invalid sample_rate_min %d, reset to 16000\n", chip->sample_rate_min); chip->sample_rate_min = 16000; } err = pcim_iomap_regions(pci, (1 << 0) | (1 << 2), DRVNAME); if (err < 0) return err; chip->bar[0].addr = pci_resource_start(pci, 0); chip->bar[0].remap_addr = pcim_iomap_table(pci)[0]; chip->bar[1].addr = pci_resource_start(pci, 2); chip->bar[1].remap_addr = pcim_iomap_table(pci)[2]; pci_set_master(pci); err = reset_controller(chip); if (err < 0) return err; if (devm_request_irq(&pci->dev, pci->irq, lola_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; dever = lola_readl(chip, BAR1, DEVER); chip->pcm[CAPT].num_streams = (dever >> 0) & 0x3ff; chip->pcm[PLAY].num_streams = (dever >> 10) & 0x3ff; chip->version = (dever >> 24) & 0xff; dev_dbg(chip->card->dev, "streams in=%d, out=%d, version=0x%x\n", chip->pcm[CAPT].num_streams, chip->pcm[PLAY].num_streams, chip->version); /* Test LOLA_BAR1_DEVER */ if (chip->pcm[CAPT].num_streams > MAX_STREAM_IN_COUNT || chip->pcm[PLAY].num_streams > MAX_STREAM_OUT_COUNT || (!chip->pcm[CAPT].num_streams && !chip->pcm[PLAY].num_streams)) { dev_err(chip->card->dev, "invalid DEVER = %x\n", dever); return -EINVAL; } err = setup_corb_rirb(chip); if (err < 0) return err; strcpy(card->driver, "Lola"); strscpy(card->shortname, "Digigram Lola", sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx irq %i", card->shortname, chip->bar[0].addr, chip->irq); strcpy(card->mixername, card->shortname); lola_irq_enable(chip); chip->initialized = 1; return 0; } static int __lola_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct lola *chip; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) { dev_err(&pci->dev, "Error creating card!\n"); return err; } chip = card->private_data; err = lola_create(card, pci, dev); if (err < 0) return err; err = lola_parse_tree(chip); if (err < 0) return err; err = lola_create_pcm(chip); if (err < 0) return err; err = lola_create_mixer(chip); if (err < 0) return err; lola_proc_debug_new(chip); err = snd_card_register(card); if (err < 0) return err; pci_set_drvdata(pci, card); dev++; return 0; } static int lola_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { return snd_card_free_on_error(&pci->dev, __lola_probe(pci, pci_id)); } /* PCI IDs */ static const struct pci_device_id lola_ids[] = { { PCI_VDEVICE(DIGIGRAM, 0x0001) }, { 0, } }; MODULE_DEVICE_TABLE(pci, lola_ids); /* pci_driver definition */ static struct pci_driver lola_driver = { .name = KBUILD_MODNAME, .id_table = lola_ids, .probe = lola_probe, }; module_pci_driver(lola_driver);
linux-master
sound/pci/lola/lola.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for Digigram Lola PCI-e boards * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/vmalloc.h> #include <linux/io.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/tlv.h> #include "lola.h" static int lola_init_pin(struct lola *chip, struct lola_pin *pin, int dir, int nid) { unsigned int val; int err; pin->nid = nid; err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid); return err; } val &= 0x00f00fff; /* test TYPE and bits 0..11 */ if (val == 0x00400200) /* Type = 4, Digital = 1 */ pin->is_analog = false; else if (val == 0x0040000a && dir == CAPT) /* Dig=0, InAmp/ovrd */ pin->is_analog = true; else if (val == 0x0040000c && dir == PLAY) /* Dig=0, OutAmp/ovrd */ pin->is_analog = true; else { dev_err(chip->card->dev, "Invalid wcaps 0x%x for 0x%x\n", val, nid); return -EINVAL; } /* analog parameters only following, so continue in case of Digital pin */ if (!pin->is_analog) return 0; if (dir == PLAY) err = lola_read_param(chip, nid, LOLA_PAR_AMP_OUT_CAP, &val); else err = lola_read_param(chip, nid, LOLA_PAR_AMP_IN_CAP, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read AMP-caps for 0x%x\n", nid); return err; } pin->amp_mute = LOLA_AMP_MUTE_CAPABLE(val); pin->amp_step_size = LOLA_AMP_STEP_SIZE(val); pin->amp_num_steps = LOLA_AMP_NUM_STEPS(val); if (pin->amp_num_steps) { /* zero as mute state */ pin->amp_num_steps++; pin->amp_step_size++; } pin->amp_offset = LOLA_AMP_OFFSET(val); err = lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL); if (err < 0) { dev_err(chip->card->dev, "Can't get MAX_LEVEL 0x%x\n", nid); return err; } pin->max_level = val & 0x3ff; /* 10 bits */ pin->config_default_reg = 0; pin->fixed_gain_list_len = 0; pin->cur_gain_step = 0; return 0; } int lola_init_pins(struct lola *chip, int dir, int *nidp) { int i, err, nid; nid = *nidp; for (i = 0; i < chip->pin[dir].num_pins; i++, nid++) { err = lola_init_pin(chip, &chip->pin[dir].pins[i], dir, nid); if (err < 0) return err; if (chip->pin[dir].pins[i].is_analog) chip->pin[dir].num_analog_pins++; } *nidp = nid; return 0; } void lola_free_mixer(struct lola *chip) { vfree(chip->mixer.array_saved); } int lola_init_mixer_widget(struct lola *chip, int nid) { unsigned int val; int err; err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid); return err; } if ((val & 0xfff00000) != 0x02f00000) { /* test SubType and Type */ dev_dbg(chip->card->dev, "No valid mixer widget\n"); return 0; } chip->mixer.nid = nid; chip->mixer.caps = val; chip->mixer.array = (struct lola_mixer_array __iomem *) (chip->bar[BAR1].remap_addr + LOLA_BAR1_SOURCE_GAIN_ENABLE); /* reserve memory to copy mixer data for sleep mode transitions */ chip->mixer.array_saved = vmalloc(sizeof(struct lola_mixer_array)); if (!chip->mixer.array_saved) return -ENOMEM; /* mixer matrix sources are physical input data and play streams */ chip->mixer.src_stream_outs = chip->pcm[PLAY].num_streams; chip->mixer.src_phys_ins = chip->pin[CAPT].num_pins; /* mixer matrix destinations are record streams and physical output */ chip->mixer.dest_stream_ins = chip->pcm[CAPT].num_streams; chip->mixer.dest_phys_outs = chip->pin[PLAY].num_pins; /* mixer matrix may have unused areas between PhysIn and * Play or Record and PhysOut zones */ chip->mixer.src_stream_out_ofs = chip->mixer.src_phys_ins + LOLA_MIXER_SRC_INPUT_PLAY_SEPARATION(val); chip->mixer.dest_phys_out_ofs = chip->mixer.dest_stream_ins + LOLA_MIXER_DEST_REC_OUTPUT_SEPARATION(val); /* example : MixerMatrix of LoLa881 (LoLa16161 uses unused zones) * +-+ 0-------8------16-------8------16 * | | | | | | | * |s| | INPUT | | INPUT | | * | |->| -> |unused | -> |unused | * |r| |CAPTURE| | OUTPUT| | * | | | MIX | | MIX | | * |c| 8-------------------------------- * | | | | | | | * | | | | | | | * |g| |unused |unused |unused |unused | * | | | | | | | * |a| | | | | | * | | 16------------------------------- * |i| | | | | | * | | | PLAYBK| | PLAYBK| | * |n|->| -> |unused | -> |unused | * | | |CAPTURE| | OUTPUT| | * | | | MIX | | MIX | | * |a| 8-------------------------------- * |r| | | | | | * |r| | | | | | * |a| |unused |unused |unused |unused | * |y| | | | | | * | | | | | | | * +++ 16--|---------------|------------ * +---V---------------V-----------+ * | dest_mix_gain_enable array | * +-------------------------------+ */ /* example : MixerMatrix of LoLa280 * +-+ 0-------8-2 * | | | | | * |s| | INPUT | | INPUT * |r|->| -> | | -> * |c| |CAPTURE| | <- OUTPUT * | | | MIX | | MIX * |g| 8---------- * |a| | | | * |i| | PLAYBK| | PLAYBACK * |n|->| -> | | -> * | | |CAPTURE| | <- OUTPUT * |a| | MIX | | MIX * |r| 8---|----|- * |r| +---V----V-------------------+ * |a| | dest_mix_gain_enable array | * |y| +----------------------------+ */ if (chip->mixer.src_stream_out_ofs > MAX_AUDIO_INOUT_COUNT || chip->mixer.dest_phys_out_ofs > MAX_STREAM_IN_COUNT) { dev_err(chip->card->dev, "Invalid mixer widget size\n"); return -EINVAL; } chip->mixer.src_mask = ((1U << chip->mixer.src_phys_ins) - 1) | (((1U << chip->mixer.src_stream_outs) - 1) << chip->mixer.src_stream_out_ofs); chip->mixer.dest_mask = ((1U << chip->mixer.dest_stream_ins) - 1) | (((1U << chip->mixer.dest_phys_outs) - 1) << chip->mixer.dest_phys_out_ofs); dev_dbg(chip->card->dev, "Mixer src_mask=%x, dest_mask=%x\n", chip->mixer.src_mask, chip->mixer.dest_mask); return 0; } static int lola_mixer_set_src_gain(struct lola *chip, unsigned int id, unsigned short gain, bool on) { unsigned int oldval, val; if (!(chip->mixer.src_mask & (1 << id))) return -EINVAL; oldval = val = readl(&chip->mixer.array->src_gain_enable); if (on) val |= (1 << id); else val &= ~(1 << id); /* test if values unchanged */ if ((val == oldval) && (gain == readw(&chip->mixer.array->src_gain[id]))) return 0; dev_dbg(chip->card->dev, "lola_mixer_set_src_gain (id=%d, gain=%d) enable=%x\n", id, gain, val); writew(gain, &chip->mixer.array->src_gain[id]); writel(val, &chip->mixer.array->src_gain_enable); lola_codec_flush(chip); /* inform micro-controller about the new source gain */ return lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_SOURCE_GAIN, id, 0); } #if 0 /* not used */ static int lola_mixer_set_src_gains(struct lola *chip, unsigned int mask, unsigned short *gains) { int i; if ((chip->mixer.src_mask & mask) != mask) return -EINVAL; for (i = 0; i < LOLA_MIXER_DIM; i++) { if (mask & (1 << i)) { writew(*gains, &chip->mixer.array->src_gain[i]); gains++; } } writel(mask, &chip->mixer.array->src_gain_enable); lola_codec_flush(chip); if (chip->mixer.caps & LOLA_PEAK_METER_CAN_AGC_MASK) { /* update for all srcs at once */ return lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_SOURCE_GAIN, 0x80, 0); } /* update manually */ for (i = 0; i < LOLA_MIXER_DIM; i++) { if (mask & (1 << i)) { lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_SOURCE_GAIN, i, 0); } } return 0; } #endif /* not used */ static int lola_mixer_set_mapping_gain(struct lola *chip, unsigned int src, unsigned int dest, unsigned short gain, bool on) { unsigned int val; if (!(chip->mixer.src_mask & (1 << src)) || !(chip->mixer.dest_mask & (1 << dest))) return -EINVAL; if (on) writew(gain, &chip->mixer.array->dest_mix_gain[dest][src]); val = readl(&chip->mixer.array->dest_mix_gain_enable[dest]); if (on) val |= (1 << src); else val &= ~(1 << src); writel(val, &chip->mixer.array->dest_mix_gain_enable[dest]); lola_codec_flush(chip); return lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_MIX_GAIN, src, dest); } #if 0 /* not used */ static int lola_mixer_set_dest_gains(struct lola *chip, unsigned int id, unsigned int mask, unsigned short *gains) { int i; if (!(chip->mixer.dest_mask & (1 << id)) || (chip->mixer.src_mask & mask) != mask) return -EINVAL; for (i = 0; i < LOLA_MIXER_DIM; i++) { if (mask & (1 << i)) { writew(*gains, &chip->mixer.array->dest_mix_gain[id][i]); gains++; } } writel(mask, &chip->mixer.array->dest_mix_gain_enable[id]); lola_codec_flush(chip); /* update for all dests at once */ return lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_DESTINATION_GAIN, id, 0); } #endif /* not used */ /* */ static int set_analog_volume(struct lola *chip, int dir, unsigned int idx, unsigned int val, bool external_call); int lola_setup_all_analog_gains(struct lola *chip, int dir, bool mute) { struct lola_pin *pin; int idx, max_idx; pin = chip->pin[dir].pins; max_idx = chip->pin[dir].num_pins; for (idx = 0; idx < max_idx; idx++) { if (pin[idx].is_analog) { unsigned int val = mute ? 0 : pin[idx].cur_gain_step; /* set volume and do not save the value */ set_analog_volume(chip, dir, idx, val, false); } } return lola_codec_flush(chip); } void lola_save_mixer(struct lola *chip) { /* mute analog output */ if (chip->mixer.array_saved) { /* store contents of mixer array */ memcpy_fromio(chip->mixer.array_saved, chip->mixer.array, sizeof(*chip->mixer.array)); } lola_setup_all_analog_gains(chip, PLAY, true); /* output mute */ } void lola_restore_mixer(struct lola *chip) { int i; /*lola_reset_setups(chip);*/ if (chip->mixer.array_saved) { /* restore contents of mixer array */ memcpy_toio(chip->mixer.array, chip->mixer.array_saved, sizeof(*chip->mixer.array)); /* inform micro-controller about all restored values * and ignore return values */ for (i = 0; i < chip->mixer.src_phys_ins; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_SOURCE_GAIN, i, 0); for (i = 0; i < chip->mixer.src_stream_outs; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_SOURCE_GAIN, chip->mixer.src_stream_out_ofs + i, 0); for (i = 0; i < chip->mixer.dest_stream_ins; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_DESTINATION_GAIN, i, 0); for (i = 0; i < chip->mixer.dest_phys_outs; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_DESTINATION_GAIN, chip->mixer.dest_phys_out_ofs + i, 0); lola_codec_flush(chip); } } /* */ static int set_analog_volume(struct lola *chip, int dir, unsigned int idx, unsigned int val, bool external_call) { struct lola_pin *pin; int err; if (idx >= chip->pin[dir].num_pins) return -EINVAL; pin = &chip->pin[dir].pins[idx]; if (!pin->is_analog || pin->amp_num_steps <= val) return -EINVAL; if (external_call && pin->cur_gain_step == val) return 0; if (external_call) lola_codec_flush(chip); dev_dbg(chip->card->dev, "set_analog_volume (dir=%d idx=%d, volume=%d)\n", dir, idx, val); err = lola_codec_write(chip, pin->nid, LOLA_VERB_SET_AMP_GAIN_MUTE, val, 0); if (err < 0) return err; if (external_call) pin->cur_gain_step = val; return 0; } int lola_set_src_config(struct lola *chip, unsigned int src_mask, bool update) { int ret = 0; int success = 0; int n, err; /* SRC can be activated and the dwInputSRCMask is valid? */ if ((chip->input_src_caps_mask & src_mask) != src_mask) return -EINVAL; /* handle all even Inputs - SRC is a stereo setting !!! */ for (n = 0; n < chip->pin[CAPT].num_pins; n += 2) { unsigned int mask = 3U << n; /* handle the stereo case */ unsigned int new_src, src_state; if (!(chip->input_src_caps_mask & mask)) continue; /* if one IO needs SRC, both stereo IO will get SRC */ new_src = (src_mask & mask) != 0; if (update) { src_state = (chip->input_src_mask & mask) != 0; if (src_state == new_src) continue; /* nothing to change for this IO */ } err = lola_codec_write(chip, chip->pcm[CAPT].streams[n].nid, LOLA_VERB_SET_SRC, new_src, 0); if (!err) success++; else ret = err; } if (success) ret = lola_codec_flush(chip); if (!ret) chip->input_src_mask = src_mask; return ret; } /* */ static int init_mixer_values(struct lola *chip) { int i; /* all sample rate converters on */ lola_set_src_config(chip, (1 << chip->pin[CAPT].num_pins) - 1, false); /* clear all mixer matrix settings */ memset_io(chip->mixer.array, 0, sizeof(*chip->mixer.array)); /* inform firmware about all updated matrix columns - capture part */ for (i = 0; i < chip->mixer.dest_stream_ins; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_DESTINATION_GAIN, i, 0); /* inform firmware about all updated matrix columns - output part */ for (i = 0; i < chip->mixer.dest_phys_outs; i++) lola_codec_write(chip, chip->mixer.nid, LOLA_VERB_SET_DESTINATION_GAIN, chip->mixer.dest_phys_out_ofs + i, 0); /* set all digital input source (master) gains to 0dB */ for (i = 0; i < chip->mixer.src_phys_ins; i++) lola_mixer_set_src_gain(chip, i, 336, true); /* 0dB */ /* set all digital playback source (master) gains to 0dB */ for (i = 0; i < chip->mixer.src_stream_outs; i++) lola_mixer_set_src_gain(chip, i + chip->mixer.src_stream_out_ofs, 336, true); /* 0dB */ /* set gain value 0dB diagonally in matrix - part INPUT -> CAPTURE */ for (i = 0; i < chip->mixer.dest_stream_ins; i++) { int src = i % chip->mixer.src_phys_ins; lola_mixer_set_mapping_gain(chip, src, i, 336, true); } /* set gain value 0dB diagonally in matrix , part PLAYBACK -> OUTPUT * (LoLa280 : playback channel 0,2,4,6 linked to output channel 0) * (LoLa280 : playback channel 1,3,5,7 linked to output channel 1) */ for (i = 0; i < chip->mixer.src_stream_outs; i++) { int src = chip->mixer.src_stream_out_ofs + i; int dst = chip->mixer.dest_phys_out_ofs + i % chip->mixer.dest_phys_outs; lola_mixer_set_mapping_gain(chip, src, dst, 336, true); } return 0; } /* * analog mixer control element */ static int lola_analog_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct lola *chip = snd_kcontrol_chip(kcontrol); int dir = kcontrol->private_value; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = chip->pin[dir].num_pins; uinfo->value.integer.min = 0; uinfo->value.integer.max = chip->pin[dir].pins[0].amp_num_steps; return 0; } static int lola_analog_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); int dir = kcontrol->private_value; int i; for (i = 0; i < chip->pin[dir].num_pins; i++) ucontrol->value.integer.value[i] = chip->pin[dir].pins[i].cur_gain_step; return 0; } static int lola_analog_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); int dir = kcontrol->private_value; int i, err; for (i = 0; i < chip->pin[dir].num_pins; i++) { err = set_analog_volume(chip, dir, i, ucontrol->value.integer.value[i], true); if (err < 0) return err; } return 0; } static int lola_analog_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, unsigned int size, unsigned int __user *tlv) { struct lola *chip = snd_kcontrol_chip(kcontrol); int dir = kcontrol->private_value; unsigned int val1, val2; struct lola_pin *pin; if (size < 4 * sizeof(unsigned int)) return -ENOMEM; pin = &chip->pin[dir].pins[0]; val2 = pin->amp_step_size * 25; val1 = -1 * (int)pin->amp_offset * (int)val2; #ifdef TLV_DB_SCALE_MUTE val2 |= TLV_DB_SCALE_MUTE; #endif if (put_user(SNDRV_CTL_TLVT_DB_SCALE, tlv)) return -EFAULT; if (put_user(2 * sizeof(unsigned int), tlv + 1)) return -EFAULT; if (put_user(val1, tlv + 2)) return -EFAULT; if (put_user(val2, tlv + 3)) return -EFAULT; return 0; } static struct snd_kcontrol_new lola_analog_mixer = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), .info = lola_analog_vol_info, .get = lola_analog_vol_get, .put = lola_analog_vol_put, .tlv.c = lola_analog_vol_tlv, }; static int create_analog_mixer(struct lola *chip, int dir, char *name) { if (!chip->pin[dir].num_pins) return 0; /* no analog volumes on digital only adapters */ if (chip->pin[dir].num_pins != chip->pin[dir].num_analog_pins) return 0; lola_analog_mixer.name = name; lola_analog_mixer.private_value = dir; return snd_ctl_add(chip->card, snd_ctl_new1(&lola_analog_mixer, chip)); } /* * Hardware sample rate converter on digital input */ static int lola_input_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct lola *chip = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = chip->pin[CAPT].num_pins; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int lola_input_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); int i; for (i = 0; i < chip->pin[CAPT].num_pins; i++) ucontrol->value.integer.value[i] = !!(chip->input_src_mask & (1 << i)); return 0; } static int lola_input_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); int i; unsigned int mask; mask = 0; for (i = 0; i < chip->pin[CAPT].num_pins; i++) if (ucontrol->value.integer.value[i]) mask |= 1 << i; return lola_set_src_config(chip, mask, true); } static const struct snd_kcontrol_new lola_input_src_mixer = { .name = "Digital SRC Capture Switch", .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .info = lola_input_src_info, .get = lola_input_src_get, .put = lola_input_src_put, }; /* * Lola16161 or Lola881 can have Hardware sample rate converters * on its digital input pins */ static int create_input_src_mixer(struct lola *chip) { if (!chip->input_src_caps_mask) return 0; return snd_ctl_add(chip->card, snd_ctl_new1(&lola_input_src_mixer, chip)); } /* * src gain mixer */ static int lola_src_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { unsigned int count = (kcontrol->private_value >> 8) & 0xff; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = count; uinfo->value.integer.min = 0; uinfo->value.integer.max = 409; return 0; } static int lola_src_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); unsigned int ofs = kcontrol->private_value & 0xff; unsigned int count = (kcontrol->private_value >> 8) & 0xff; unsigned int mask, i; mask = readl(&chip->mixer.array->src_gain_enable); for (i = 0; i < count; i++) { unsigned int idx = ofs + i; unsigned short val; if (!(chip->mixer.src_mask & (1 << idx))) return -EINVAL; if (mask & (1 << idx)) val = readw(&chip->mixer.array->src_gain[idx]) + 1; else val = 0; ucontrol->value.integer.value[i] = val; } return 0; } static int lola_src_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); unsigned int ofs = kcontrol->private_value & 0xff; unsigned int count = (kcontrol->private_value >> 8) & 0xff; int i, err; for (i = 0; i < count; i++) { unsigned int idx = ofs + i; unsigned short val = ucontrol->value.integer.value[i]; if (val) val--; err = lola_mixer_set_src_gain(chip, idx, val, !!val); if (err < 0) return err; } return 0; } /* raw value: 0 = -84dB, 336 = 0dB, 408=18dB, incremented 1 for mute */ static const DECLARE_TLV_DB_SCALE(lola_src_gain_tlv, -8425, 25, 1); static struct snd_kcontrol_new lola_src_gain_mixer = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), .info = lola_src_gain_info, .get = lola_src_gain_get, .put = lola_src_gain_put, .tlv.p = lola_src_gain_tlv, }; static int create_src_gain_mixer(struct lola *chip, int num, int ofs, char *name) { lola_src_gain_mixer.name = name; lola_src_gain_mixer.private_value = ofs + (num << 8); return snd_ctl_add(chip->card, snd_ctl_new1(&lola_src_gain_mixer, chip)); } #if 0 /* not used */ /* * destination gain (matrix-like) mixer */ static int lola_dest_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { unsigned int src_num = (kcontrol->private_value >> 8) & 0xff; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = src_num; uinfo->value.integer.min = 0; uinfo->value.integer.max = 433; return 0; } static int lola_dest_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); unsigned int src_ofs = kcontrol->private_value & 0xff; unsigned int src_num = (kcontrol->private_value >> 8) & 0xff; unsigned int dst_ofs = (kcontrol->private_value >> 16) & 0xff; unsigned int dst, mask, i; dst = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + dst_ofs; mask = readl(&chip->mixer.array->dest_mix_gain_enable[dst]); for (i = 0; i < src_num; i++) { unsigned int src = src_ofs + i; unsigned short val; if (!(chip->mixer.src_mask & (1 << src))) return -EINVAL; if (mask & (1 << dst)) val = readw(&chip->mixer.array->dest_mix_gain[dst][src]) + 1; else val = 0; ucontrol->value.integer.value[i] = val; } return 0; } static int lola_dest_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lola *chip = snd_kcontrol_chip(kcontrol); unsigned int src_ofs = kcontrol->private_value & 0xff; unsigned int src_num = (kcontrol->private_value >> 8) & 0xff; unsigned int dst_ofs = (kcontrol->private_value >> 16) & 0xff; unsigned int dst, mask; unsigned short gains[MAX_STREAM_COUNT]; int i, num; mask = 0; num = 0; for (i = 0; i < src_num; i++) { unsigned short val = ucontrol->value.integer.value[i]; if (val) { gains[num++] = val - 1; mask |= 1 << i; } } mask <<= src_ofs; dst = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + dst_ofs; return lola_mixer_set_dest_gains(chip, dst, mask, gains); } static const DECLARE_TLV_DB_SCALE(lola_dest_gain_tlv, -8425, 25, 1); static struct snd_kcontrol_new lola_dest_gain_mixer = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), .info = lola_dest_gain_info, .get = lola_dest_gain_get, .put = lola_dest_gain_put, .tlv.p = lola_dest_gain_tlv, }; static int create_dest_gain_mixer(struct lola *chip, int src_num, int src_ofs, int num, int ofs, char *name) { lola_dest_gain_mixer.count = num; lola_dest_gain_mixer.name = name; lola_dest_gain_mixer.private_value = src_ofs + (src_num << 8) + (ofs << 16) + (num << 24); return snd_ctl_add(chip->card, snd_ctl_new1(&lola_dest_gain_mixer, chip)); } #endif /* not used */ /* */ int lola_create_mixer(struct lola *chip) { int err; err = create_analog_mixer(chip, PLAY, "Analog Playback Volume"); if (err < 0) return err; err = create_analog_mixer(chip, CAPT, "Analog Capture Volume"); if (err < 0) return err; err = create_input_src_mixer(chip); if (err < 0) return err; err = create_src_gain_mixer(chip, chip->mixer.src_phys_ins, 0, "Digital Capture Volume"); if (err < 0) return err; err = create_src_gain_mixer(chip, chip->mixer.src_stream_outs, chip->mixer.src_stream_out_ofs, "Digital Playback Volume"); if (err < 0) return err; #if 0 /* FIXME: buggy mixer matrix handling */ err = create_dest_gain_mixer(chip, chip->mixer.src_phys_ins, 0, chip->mixer.dest_stream_ins, 0, "Line Capture Volume"); if (err < 0) return err; err = create_dest_gain_mixer(chip, chip->mixer.src_stream_outs, chip->mixer.src_stream_out_ofs, chip->mixer.dest_stream_ins, 0, "Stream-Loopback Capture Volume"); if (err < 0) return err; err = create_dest_gain_mixer(chip, chip->mixer.src_phys_ins, 0, chip->mixer.dest_phys_outs, chip->mixer.dest_phys_out_ofs, "Line-Loopback Playback Volume"); if (err < 0) return err; err = create_dest_gain_mixer(chip, chip->mixer.src_stream_outs, chip->mixer.src_stream_out_ofs, chip->mixer.dest_phys_outs, chip->mixer.dest_phys_out_ofs, "Stream Playback Volume"); if (err < 0) return err; #endif /* FIXME */ return init_mixer_values(chip); }
linux-master
sound/pci/lola/lola_mixer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Support for Digigram Lola PCI-e boards * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/delay.h> #include <sound/core.h> #include <sound/pcm.h> #include "lola.h" unsigned int lola_sample_rate_convert(unsigned int coded) { unsigned int freq; /* base frequency */ switch (coded & 0x3) { case 0: freq = 48000; break; case 1: freq = 44100; break; case 2: freq = 32000; break; default: return 0; /* error */ } /* multiplier / devisor */ switch (coded & 0x1c) { case (0 << 2): break; case (4 << 2): break; case (1 << 2): freq *= 2; break; case (2 << 2): freq *= 4; break; case (5 << 2): freq /= 2; break; case (6 << 2): freq /= 4; break; default: return 0; /* error */ } /* ajustement */ switch (coded & 0x60) { case (0 << 5): break; case (1 << 5): freq = (freq * 999) / 1000; break; case (2 << 5): freq = (freq * 1001) / 1000; break; default: return 0; /* error */ } return freq; } /* * Granualrity */ #define LOLA_MAXFREQ_AT_GRANULARITY_MIN 48000 #define LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX 96000 static bool check_gran_clock_compatibility(struct lola *chip, unsigned int val, unsigned int freq) { if (!chip->granularity) return true; if (val < LOLA_GRANULARITY_MIN || val > LOLA_GRANULARITY_MAX || (val % LOLA_GRANULARITY_STEP) != 0) return false; if (val == LOLA_GRANULARITY_MIN) { if (freq > LOLA_MAXFREQ_AT_GRANULARITY_MIN) return false; } else if (val < LOLA_GRANULARITY_MAX) { if (freq > LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX) return false; } return true; } int lola_set_granularity(struct lola *chip, unsigned int val, bool force) { int err; if (!force) { if (val == chip->granularity) return 0; #if 0 /* change Gran only if there are no streams allocated ! */ if (chip->audio_in_alloc_mask || chip->audio_out_alloc_mask) return -EBUSY; #endif if (!check_gran_clock_compatibility(chip, val, chip->clock.cur_freq)) return -EINVAL; } chip->granularity = val; val /= LOLA_GRANULARITY_STEP; /* audio function group */ err = lola_codec_write(chip, 1, LOLA_VERB_SET_GRANULARITY_STEPS, val, 0); if (err < 0) return err; /* this can be a very slow function !!! */ usleep_range(400 * val, 20000); return lola_codec_flush(chip); } /* * Clock widget handling */ int lola_init_clock_widget(struct lola *chip, int nid) { unsigned int val; int i, j, nitems, nb_verbs, idx, idx_list; int err; err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); if (err < 0) { dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid); return err; } if ((val & 0xfff00000) != 0x01f00000) { /* test SubType and Type */ dev_dbg(chip->card->dev, "No valid clock widget\n"); return 0; } chip->clock.nid = nid; chip->clock.items = val & 0xff; dev_dbg(chip->card->dev, "clock_list nid=%x, entries=%d\n", nid, chip->clock.items); if (chip->clock.items > MAX_SAMPLE_CLOCK_COUNT) { dev_err(chip->card->dev, "CLOCK_LIST too big: %d\n", chip->clock.items); return -EINVAL; } nitems = chip->clock.items; nb_verbs = DIV_ROUND_UP(nitems, 4); idx = 0; idx_list = 0; for (i = 0; i < nb_verbs; i++) { unsigned int res_ex; unsigned short items[4]; err = lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST, idx, 0, &val, &res_ex); if (err < 0) { dev_err(chip->card->dev, "Can't read CLOCK_LIST\n"); return -EINVAL; } items[0] = val & 0xfff; items[1] = (val >> 16) & 0xfff; items[2] = res_ex & 0xfff; items[3] = (res_ex >> 16) & 0xfff; for (j = 0; j < 4; j++) { unsigned char type = items[j] >> 8; unsigned int freq = items[j] & 0xff; int format = LOLA_CLOCK_FORMAT_NONE; bool add_clock = true; if (type == LOLA_CLOCK_TYPE_INTERNAL) { freq = lola_sample_rate_convert(freq); if (freq < chip->sample_rate_min) add_clock = false; else if (freq == 48000) { chip->clock.cur_index = idx_list; chip->clock.cur_freq = 48000; chip->clock.cur_valid = true; } } else if (type == LOLA_CLOCK_TYPE_VIDEO) { freq = lola_sample_rate_convert(freq); if (freq < chip->sample_rate_min) add_clock = false; /* video clock has a format (0:NTSC, 1:PAL)*/ if (items[j] & 0x80) format = LOLA_CLOCK_FORMAT_NTSC; else format = LOLA_CLOCK_FORMAT_PAL; } if (add_clock) { struct lola_sample_clock *sc; sc = &chip->clock.sample_clock[idx_list]; sc->type = type; sc->format = format; sc->freq = freq; /* keep the index used with the board */ chip->clock.idx_lookup[idx_list] = idx; idx_list++; } else { chip->clock.items--; } if (++idx >= nitems) break; } } return 0; } /* enable unsolicited events of the clock widget */ int lola_enable_clock_events(struct lola *chip) { unsigned int res; int err; err = lola_codec_read(chip, chip->clock.nid, LOLA_VERB_SET_UNSOLICITED_ENABLE, LOLA_UNSOLICITED_ENABLE | LOLA_UNSOLICITED_TAG, 0, &res, NULL); if (err < 0) return err; if (res) { dev_warn(chip->card->dev, "error in enable_clock_events %d\n", res); return -EINVAL; } return 0; } int lola_set_clock_index(struct lola *chip, unsigned int idx) { unsigned int res; int err; err = lola_codec_read(chip, chip->clock.nid, LOLA_VERB_SET_CLOCK_SELECT, chip->clock.idx_lookup[idx], 0, &res, NULL); if (err < 0) return err; if (res) { dev_warn(chip->card->dev, "error in set_clock %d\n", res); return -EINVAL; } return 0; } bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val) { unsigned int tag; /* the current EXTERNAL clock information gets updated by interrupt * with an unsolicited response */ if (!val) return false; tag = (val >> LOLA_UNSOL_RESP_TAG_OFFSET) & LOLA_UNSOLICITED_TAG_MASK; if (tag != LOLA_UNSOLICITED_TAG) return false; /* only for current = external clocks */ if (chip->clock.sample_clock[chip->clock.cur_index].type != LOLA_CLOCK_TYPE_INTERNAL) { chip->clock.cur_freq = lola_sample_rate_convert(val & 0x7f); chip->clock.cur_valid = (val & 0x100) != 0; } return true; } int lola_set_clock(struct lola *chip, int idx) { int freq = 0; bool valid = false; if (idx == chip->clock.cur_index) { /* current clock is allowed */ freq = chip->clock.cur_freq; valid = chip->clock.cur_valid; } else if (chip->clock.sample_clock[idx].type == LOLA_CLOCK_TYPE_INTERNAL) { /* internal clocks allowed */ freq = chip->clock.sample_clock[idx].freq; valid = true; } if (!freq || !valid) return -EINVAL; if (!check_gran_clock_compatibility(chip, chip->granularity, freq)) return -EINVAL; if (idx != chip->clock.cur_index) { int err = lola_set_clock_index(chip, idx); if (err < 0) return err; /* update new settings */ chip->clock.cur_index = idx; chip->clock.cur_freq = freq; chip->clock.cur_valid = true; } return 0; } int lola_set_sample_rate(struct lola *chip, int rate) { int i; if (chip->clock.cur_freq == rate && chip->clock.cur_valid) return 0; /* search for new dwClockIndex */ for (i = 0; i < chip->clock.items; i++) { if (chip->clock.sample_clock[i].type == LOLA_CLOCK_TYPE_INTERNAL && chip->clock.sample_clock[i].freq == rate) break; } if (i >= chip->clock.items) return -EINVAL; return lola_set_clock(chip, i); }
linux-master
sound/pci/lola/lola_clock.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Power management for audio on multifunction CS5535 companion device * Copyright (C) Jaya Kumar */ #include <linux/init.h> #include <linux/pci.h> #include <linux/delay.h> #include <sound/core.h> #include <sound/control.h> #include <sound/initval.h> #include <sound/asoundef.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> #include "cs5535audio.h" static void snd_cs5535audio_stop_hardware(struct cs5535audio *cs5535au) { /* we depend on snd_ac97_suspend to tell the AC97 codec to shutdown. the amd spec suggests that the LNK_SHUTDOWN be done at the same time that the codec power-down is issued. instead, we do it just after rather than at the same time. excluding codec specific build_ops->suspend ac97 powerdown hits: 0x8000 EAPD 0x4000 Headphone amplifier 0x0300 ADC & DAC 0x0400 Analog Mixer powerdown (Vref on) I am not sure if this is the best that we can do. The remainder to be investigated are: - analog mixer (vref off) 0x0800 - AC-link powerdown 0x1000 - codec internal clock 0x2000 */ /* set LNK_SHUTDOWN to shutdown AC link */ cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_SHUTDOWN); } static int __maybe_unused snd_cs5535audio_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct cs5535audio *cs5535au = card->private_data; int i; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_ac97_suspend(cs5535au->ac97); for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) { struct cs5535audio_dma *dma = &cs5535au->dmas[i]; if (dma && dma->substream) dma->saved_prd = dma->ops->read_prd(cs5535au); } /* save important regs, then disable aclink in hw */ snd_cs5535audio_stop_hardware(cs5535au); return 0; } static int __maybe_unused snd_cs5535audio_resume(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct cs5535audio *cs5535au = card->private_data; u32 tmp; int timeout; int i; /* set LNK_WRM_RST to reset AC link */ cs_writel(cs5535au, ACC_CODEC_CNTL, ACC_CODEC_CNTL_LNK_WRM_RST); timeout = 50; do { tmp = cs_readl(cs5535au, ACC_CODEC_STATUS); if (tmp & PRM_RDY_STS) break; udelay(1); } while (--timeout); if (!timeout) dev_err(cs5535au->card->dev, "Failure getting AC Link ready\n"); /* set up rate regs, dma. actual initiation is done in trig */ for (i = 0; i < NUM_CS5535AUDIO_DMAS; i++) { struct cs5535audio_dma *dma = &cs5535au->dmas[i]; if (dma && dma->substream) { dma->substream->ops->prepare(dma->substream); dma->ops->setup_prd(cs5535au, dma->saved_prd); } } /* we depend on ac97 to perform the codec power up */ snd_ac97_resume(cs5535au->ac97); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } SIMPLE_DEV_PM_OPS(snd_cs5535audio_pm, snd_cs5535audio_suspend, snd_cs5535audio_resume);
linux-master
sound/pci/cs5535audio/cs5535audio_pm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for audio on multifunction CS5535/6 companion device * Copyright (C) Jaya Kumar * * Based on Jaroslav Kysela and Takashi Iwai's examples. * This work was sponsored by CIS(M) Sdn Bhd. */ #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/io.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/rawmidi.h> #include <sound/ac97_codec.h> #include <sound/initval.h> #include <sound/asoundef.h> #include "cs5535audio.h" #define DRIVER_NAME "cs5535audio" static char *ac97_quirk; module_param(ac97_quirk, charp, 0444); MODULE_PARM_DESC(ac97_quirk, "AC'97 board specific workarounds."); static const struct ac97_quirk ac97_quirks[] = { #if 0 /* Not yet confirmed if all 5536 boards are HP only */ { .subvendor = PCI_VENDOR_ID_AMD, .subdevice = PCI_DEVICE_ID_AMD_CS5536_AUDIO, .name = "AMD RDK", .type = AC97_TUNE_HP_ONLY }, #endif {} }; static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for " DRIVER_NAME); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for " DRIVER_NAME); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable " DRIVER_NAME); static const struct pci_device_id snd_cs5535audio_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_AUDIO) }, { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_AUDIO) }, {} }; MODULE_DEVICE_TABLE(pci, snd_cs5535audio_ids); static void wait_till_cmd_acked(struct cs5535audio *cs5535au, unsigned long timeout) { unsigned int tmp; do { tmp = cs_readl(cs5535au, ACC_CODEC_CNTL); if (!(tmp & CMD_NEW)) break; udelay(1); } while (--timeout); if (!timeout) dev_err(cs5535au->card->dev, "Failure writing to cs5535 codec\n"); } static unsigned short snd_cs5535audio_codec_read(struct cs5535audio *cs5535au, unsigned short reg) { unsigned int regdata; unsigned int timeout; unsigned int val; regdata = ((unsigned int) reg) << 24; regdata |= ACC_CODEC_CNTL_RD_CMD; regdata |= CMD_NEW; cs_writel(cs5535au, ACC_CODEC_CNTL, regdata); wait_till_cmd_acked(cs5535au, 50); timeout = 50; do { val = cs_readl(cs5535au, ACC_CODEC_STATUS); if ((val & STS_NEW) && reg == (val >> 24)) break; udelay(1); } while (--timeout); if (!timeout) dev_err(cs5535au->card->dev, "Failure reading codec reg 0x%x, Last value=0x%x\n", reg, val); return (unsigned short) val; } static void snd_cs5535audio_codec_write(struct cs5535audio *cs5535au, unsigned short reg, unsigned short val) { unsigned int regdata; regdata = ((unsigned int) reg) << 24; regdata |= val; regdata &= CMD_MASK; regdata |= CMD_NEW; regdata &= ACC_CODEC_CNTL_WR_CMD; cs_writel(cs5535au, ACC_CODEC_CNTL, regdata); wait_till_cmd_acked(cs5535au, 50); } static void snd_cs5535audio_ac97_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { struct cs5535audio *cs5535au = ac97->private_data; snd_cs5535audio_codec_write(cs5535au, reg, val); } static unsigned short snd_cs5535audio_ac97_codec_read(struct snd_ac97 *ac97, unsigned short reg) { struct cs5535audio *cs5535au = ac97->private_data; return snd_cs5535audio_codec_read(cs5535au, reg); } static int snd_cs5535audio_mixer(struct cs5535audio *cs5535au) { struct snd_card *card = cs5535au->card; struct snd_ac97_bus *pbus; struct snd_ac97_template ac97; int err; static const struct snd_ac97_bus_ops ops = { .write = snd_cs5535audio_ac97_codec_write, .read = snd_cs5535audio_ac97_codec_read, }; err = snd_ac97_bus(card, 0, &ops, NULL, &pbus); if (err < 0) return err; memset(&ac97, 0, sizeof(ac97)); ac97.scaps = AC97_SCAP_AUDIO | AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE; ac97.private_data = cs5535au; ac97.pci = cs5535au->pci; /* set any OLPC-specific scaps */ olpc_prequirks(card, &ac97); err = snd_ac97_mixer(pbus, &ac97, &cs5535au->ac97); if (err < 0) { dev_err(card->dev, "mixer failed\n"); return err; } snd_ac97_tune_hardware(cs5535au->ac97, ac97_quirks, ac97_quirk); err = olpc_quirks(card, cs5535au->ac97); if (err < 0) { dev_err(card->dev, "olpc quirks failed\n"); return err; } return 0; } static void process_bm0_irq(struct cs5535audio *cs5535au) { u8 bm_stat; spin_lock(&cs5535au->reg_lock); bm_stat = cs_readb(cs5535au, ACC_BM0_STATUS); spin_unlock(&cs5535au->reg_lock); if (bm_stat & EOP) { snd_pcm_period_elapsed(cs5535au->playback_substream); } else { dev_err(cs5535au->card->dev, "unexpected bm0 irq src, bm_stat=%x\n", bm_stat); } } static void process_bm1_irq(struct cs5535audio *cs5535au) { u8 bm_stat; spin_lock(&cs5535au->reg_lock); bm_stat = cs_readb(cs5535au, ACC_BM1_STATUS); spin_unlock(&cs5535au->reg_lock); if (bm_stat & EOP) snd_pcm_period_elapsed(cs5535au->capture_substream); } static irqreturn_t snd_cs5535audio_interrupt(int irq, void *dev_id) { u16 acc_irq_stat; unsigned char count; struct cs5535audio *cs5535au = dev_id; if (cs5535au == NULL) return IRQ_NONE; acc_irq_stat = cs_readw(cs5535au, ACC_IRQ_STATUS); if (!acc_irq_stat) return IRQ_NONE; for (count = 0; count < 4; count++) { if (acc_irq_stat & (1 << count)) { switch (count) { case IRQ_STS: cs_readl(cs5535au, ACC_GPIO_STATUS); break; case WU_IRQ_STS: cs_readl(cs5535au, ACC_GPIO_STATUS); break; case BM0_IRQ_STS: process_bm0_irq(cs5535au); break; case BM1_IRQ_STS: process_bm1_irq(cs5535au); break; default: dev_err(cs5535au->card->dev, "Unexpected irq src: 0x%x\n", acc_irq_stat); break; } } } return IRQ_HANDLED; } static void snd_cs5535audio_free(struct snd_card *card) { olpc_quirks_cleanup(); } static int snd_cs5535audio_create(struct snd_card *card, struct pci_dev *pci) { struct cs5535audio *cs5535au = card->private_data; int err; err = pcim_enable_device(pci); if (err < 0) return err; if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_warn(card->dev, "unable to get 32bit dma\n"); return -ENXIO; } spin_lock_init(&cs5535au->reg_lock); cs5535au->card = card; cs5535au->pci = pci; cs5535au->irq = -1; err = pci_request_regions(pci, "CS5535 Audio"); if (err < 0) return err; cs5535au->port = pci_resource_start(pci, 0); if (devm_request_irq(&pci->dev, pci->irq, snd_cs5535audio_interrupt, IRQF_SHARED, KBUILD_MODNAME, cs5535au)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } cs5535au->irq = pci->irq; card->sync_irq = cs5535au->irq; pci_set_master(pci); return 0; } static int __snd_cs5535audio_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct cs5535audio *cs5535au; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*cs5535au), &card); if (err < 0) return err; cs5535au = card->private_data; card->private_free = snd_cs5535audio_free; err = snd_cs5535audio_create(card, pci); if (err < 0) return err; err = snd_cs5535audio_mixer(cs5535au); if (err < 0) return err; err = snd_cs5535audio_pcm(cs5535au); if (err < 0) return err; strcpy(card->driver, DRIVER_NAME); strcpy(card->shortname, "CS5535 Audio"); sprintf(card->longname, "%s %s at 0x%lx, irq %i", card->shortname, card->driver, cs5535au->port, cs5535au->irq); err = snd_card_register(card); if (err < 0) return err; pci_set_drvdata(pci, card); dev++; return 0; } static int snd_cs5535audio_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { return snd_card_free_on_error(&pci->dev, __snd_cs5535audio_probe(pci, pci_id)); } static struct pci_driver cs5535audio_driver = { .name = KBUILD_MODNAME, .id_table = snd_cs5535audio_ids, .probe = snd_cs5535audio_probe, #ifdef CONFIG_PM_SLEEP .driver = { .pm = &snd_cs5535audio_pm, }, #endif }; module_pci_driver(cs5535audio_driver); MODULE_AUTHOR("Jaya Kumar"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("CS5535 Audio");
linux-master
sound/pci/cs5535audio/cs5535audio.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for audio on multifunction CS5535 companion device * Copyright (C) Jaya Kumar * * Based on Jaroslav Kysela and Takashi Iwai's examples. * This work was sponsored by CIS(M) Sdn Bhd. * * todo: add be fmt support, spdif, pm */ #include <linux/init.h> #include <linux/pci.h> #include <sound/core.h> #include <sound/control.h> #include <sound/initval.h> #include <sound/asoundef.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/ac97_codec.h> #include "cs5535audio.h" static const struct snd_pcm_hardware snd_cs5535audio_playback = { .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME ), .formats = ( SNDRV_PCM_FMTBIT_S16_LE ), .rates = ( SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 ), .rate_min = 4000, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (64*1024 - 16), .periods_min = 1, .periods_max = CS5535AUDIO_MAX_DESCRIPTORS, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_cs5535audio_capture = { .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID ), .formats = ( SNDRV_PCM_FMTBIT_S16_LE ), .rates = ( SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 ), .rate_min = 4000, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (64*1024 - 16), .periods_min = 1, .periods_max = CS5535AUDIO_MAX_DESCRIPTORS, .fifo_size = 0, }; static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream) { int err; struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; runtime->hw = snd_cs5535audio_playback; runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_FRONT_DAC]; snd_pcm_limit_hw_rates(runtime); cs5535au->playback_substream = substream; runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]); err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; return 0; } static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream) { return 0; } #define CS5535AUDIO_DESC_LIST_SIZE \ PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc)) static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au, struct cs5535audio_dma *dma, struct snd_pcm_substream *substream, unsigned int periods, unsigned int period_bytes) { unsigned int i; u32 addr, jmpprd_addr; struct cs5535audio_dma_desc *lastdesc; if (periods > CS5535AUDIO_MAX_DESCRIPTORS) return -ENOMEM; if (dma->desc_buf.area == NULL) { if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &cs5535au->pci->dev, CS5535AUDIO_DESC_LIST_SIZE+1, &dma->desc_buf) < 0) return -ENOMEM; dma->period_bytes = dma->periods = 0; } if (dma->periods == periods && dma->period_bytes == period_bytes) return 0; /* the u32 cast is okay because in snd*create we successfully told pci alloc that we're only 32 bit capable so the upper will be 0 */ addr = (u32) substream->runtime->dma_addr; for (i = 0; i < periods; i++) { struct cs5535audio_dma_desc *desc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i]; desc->addr = cpu_to_le32(addr); desc->size = cpu_to_le16(period_bytes); desc->ctlreserved = cpu_to_le16(PRD_EOP); addr += period_bytes; } /* we reserved one dummy descriptor at the end to do the PRD jump */ lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods]; lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr); lastdesc->size = 0; lastdesc->ctlreserved = cpu_to_le16(PRD_JMP); jmpprd_addr = (u32)dma->desc_buf.addr + sizeof(struct cs5535audio_dma_desc) * periods; dma->substream = substream; dma->period_bytes = period_bytes; dma->periods = periods; spin_lock_irq(&cs5535au->reg_lock); dma->ops->disable_dma(cs5535au); dma->ops->setup_prd(cs5535au, jmpprd_addr); spin_unlock_irq(&cs5535au->reg_lock); return 0; } static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN); } static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM0_CMD, 0); } static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE); } static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au, u32 prd_addr) { cs_writel(cs5535au, ACC_BM0_PRD, prd_addr); } static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au) { return cs_readl(cs5535au, ACC_BM0_PRD); } static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au) { return cs_readl(cs5535au, ACC_BM0_PNTR); } static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN); } static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM1_CMD, 0); } static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au) { cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE); } static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au, u32 prd_addr) { cs_writel(cs5535au, ACC_BM1_PRD, prd_addr); } static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au) { return cs_readl(cs5535au, ACC_BM1_PRD); } static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au) { return cs_readl(cs5535au, ACC_BM1_PNTR); } static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au, struct cs5535audio_dma *dma, struct snd_pcm_substream *substream) { snd_dma_free_pages(&dma->desc_buf); dma->desc_buf.area = NULL; dma->substream = NULL; } static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); struct cs5535audio_dma *dma = substream->runtime->private_data; int err; dma->buf_addr = substream->runtime->dma_addr; dma->buf_bytes = params_buffer_bytes(hw_params); err = cs5535audio_build_dma_packets(cs5535au, dma, substream, params_periods(hw_params), params_period_bytes(hw_params)); if (!err) dma->pcm_open_flag = 1; return err; } static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); struct cs5535audio_dma *dma = substream->runtime->private_data; if (dma->pcm_open_flag) { if (substream == cs5535au->playback_substream) snd_ac97_update_power(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE, 0); else snd_ac97_update_power(cs5535au->ac97, AC97_PCM_LR_ADC_RATE, 0); dma->pcm_open_flag = 0; } cs5535audio_clear_dma_packets(cs5535au, dma, substream); return 0; } static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE, substream->runtime->rate); } static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); struct cs5535audio_dma *dma = substream->runtime->private_data; int err = 0; spin_lock(&cs5535au->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_PAUSE_PUSH: dma->ops->pause_dma(cs5535au); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: dma->ops->enable_dma(cs5535au); break; case SNDRV_PCM_TRIGGER_START: dma->ops->enable_dma(cs5535au); break; case SNDRV_PCM_TRIGGER_RESUME: dma->ops->enable_dma(cs5535au); break; case SNDRV_PCM_TRIGGER_STOP: dma->ops->disable_dma(cs5535au); break; case SNDRV_PCM_TRIGGER_SUSPEND: dma->ops->disable_dma(cs5535au); break; default: dev_err(cs5535au->card->dev, "unhandled trigger\n"); err = -EINVAL; break; } spin_unlock(&cs5535au->reg_lock); return err; } static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream *substream) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); u32 curdma; struct cs5535audio_dma *dma; dma = substream->runtime->private_data; curdma = dma->ops->read_dma_pntr(cs5535au); if (curdma < dma->buf_addr) { dev_err(cs5535au->card->dev, "curdma=%x < %x bufaddr.\n", curdma, dma->buf_addr); return 0; } curdma -= dma->buf_addr; if (curdma >= dma->buf_bytes) { dev_err(cs5535au->card->dev, "diff=%x >= %x buf_bytes.\n", curdma, dma->buf_bytes); return 0; } return bytes_to_frames(substream->runtime, curdma); } static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream) { int err; struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; runtime->hw = snd_cs5535audio_capture; runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_ADC]; snd_pcm_limit_hw_rates(runtime); cs5535au->capture_substream = substream; runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]); err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; olpc_capture_open(cs5535au->ac97); return 0; } static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); olpc_capture_close(cs5535au->ac97); return 0; } static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream) { struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE, substream->runtime->rate); } static const struct snd_pcm_ops snd_cs5535audio_playback_ops = { .open = snd_cs5535audio_playback_open, .close = snd_cs5535audio_playback_close, .hw_params = snd_cs5535audio_hw_params, .hw_free = snd_cs5535audio_hw_free, .prepare = snd_cs5535audio_playback_prepare, .trigger = snd_cs5535audio_trigger, .pointer = snd_cs5535audio_pcm_pointer, }; static const struct snd_pcm_ops snd_cs5535audio_capture_ops = { .open = snd_cs5535audio_capture_open, .close = snd_cs5535audio_capture_close, .hw_params = snd_cs5535audio_hw_params, .hw_free = snd_cs5535audio_hw_free, .prepare = snd_cs5535audio_capture_prepare, .trigger = snd_cs5535audio_trigger, .pointer = snd_cs5535audio_pcm_pointer, }; static const struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = { .type = CS5535AUDIO_DMA_PLAYBACK, .enable_dma = cs5535audio_playback_enable_dma, .disable_dma = cs5535audio_playback_disable_dma, .setup_prd = cs5535audio_playback_setup_prd, .read_prd = cs5535audio_playback_read_prd, .pause_dma = cs5535audio_playback_pause_dma, .read_dma_pntr = cs5535audio_playback_read_dma_pntr, }; static const struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = { .type = CS5535AUDIO_DMA_CAPTURE, .enable_dma = cs5535audio_capture_enable_dma, .disable_dma = cs5535audio_capture_disable_dma, .setup_prd = cs5535audio_capture_setup_prd, .read_prd = cs5535audio_capture_read_prd, .pause_dma = cs5535audio_capture_pause_dma, .read_dma_pntr = cs5535audio_capture_read_dma_pntr, }; int snd_cs5535audio_pcm(struct cs5535audio *cs5535au) { struct snd_pcm *pcm; int err; err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm); if (err < 0) return err; cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops = &snd_cs5535audio_playback_dma_ops; cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops = &snd_cs5535audio_capture_dma_ops; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs5535audio_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs5535audio_capture_ops); pcm->private_data = cs5535au; pcm->info_flags = 0; strcpy(pcm->name, "CS5535 Audio"); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &cs5535au->pci->dev, 64*1024, 128*1024); cs5535au->pcm = pcm; return 0; }
linux-master
sound/pci/cs5535audio/cs5535audio_pcm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * OLPC XO-1 additional sound features * * Copyright © 2006 Jaya Kumar <[email protected]> * Copyright © 2007-2008 Andres Salomon <[email protected]> */ #include <sound/core.h> #include <sound/info.h> #include <sound/control.h> #include <sound/ac97_codec.h> #include <linux/gpio.h> #include <asm/olpc.h> #include "cs5535audio.h" #define DRV_NAME "cs5535audio-olpc" /* * OLPC has an additional feature on top of the regular AD1888 codec features. * It has an Analog Input mode that is switched into (after disabling the * High Pass Filter) via GPIO. It is supported on B2 and later models. */ void olpc_analog_input(struct snd_ac97 *ac97, int on) { int err; if (!machine_is_olpc()) return; /* update the High Pass Filter (via AC97_AD_TEST2) */ err = snd_ac97_update_bits(ac97, AC97_AD_TEST2, 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT); if (err < 0) { dev_err(ac97->bus->card->dev, "setting High Pass Filter - %d\n", err); return; } /* set Analog Input through GPIO */ gpio_set_value(OLPC_GPIO_MIC_AC, on); } /* * OLPC XO-1's V_REFOUT is a mic bias enable. */ void olpc_mic_bias(struct snd_ac97 *ac97, int on) { int err; if (!machine_is_olpc()) return; on = on ? 0 : 1; err = snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT); if (err < 0) dev_err(ac97->bus->card->dev, "setting MIC Bias - %d\n", err); } static int olpc_dc_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) { v->value.integer.value[0] = gpio_get_value(OLPC_GPIO_MIC_AC); return 0; } static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) { struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]); return 1; } static int olpc_mic_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int olpc_mic_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) { struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); struct snd_ac97 *ac97 = cs5535au->ac97; int i; i = (snd_ac97_read(ac97, AC97_AD_MISC) >> AC97_AD_VREFD_SHIFT) & 0x1; v->value.integer.value[0] = i ? 0 : 1; return 0; } static int olpc_mic_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) { struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); olpc_mic_bias(cs5535au->ac97, v->value.integer.value[0]); return 1; } static const struct snd_kcontrol_new olpc_cs5535audio_ctls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DC Mode Enable", .info = olpc_dc_info, .get = olpc_dc_get, .put = olpc_dc_put, .private_value = 0, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "MIC Bias Enable", .info = olpc_mic_info, .get = olpc_mic_get, .put = olpc_mic_put, .private_value = 0, }, }; void olpc_prequirks(struct snd_card *card, struct snd_ac97_template *ac97) { if (!machine_is_olpc()) return; /* invert EAPD if on an OLPC B3 or higher */ if (olpc_board_at_least(olpc_board_pre(0xb3))) ac97->scaps |= AC97_SCAP_INV_EAPD; } int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) { struct snd_ctl_elem_id elem; int i, err; if (!machine_is_olpc()) return 0; if (gpio_request(OLPC_GPIO_MIC_AC, DRV_NAME)) { dev_err(card->dev, "unable to allocate MIC GPIO\n"); return -EIO; } gpio_direction_output(OLPC_GPIO_MIC_AC, 0); /* drop the original AD1888 HPF control */ memset(&elem, 0, sizeof(elem)); elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; strscpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); snd_ctl_remove_id(card, &elem); /* drop the original V_REFOUT control */ memset(&elem, 0, sizeof(elem)); elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; strscpy(elem.name, "V_REFOUT Enable", sizeof(elem.name)); snd_ctl_remove_id(card, &elem); /* add the OLPC-specific controls */ for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i], ac97->private_data)); if (err < 0) return err; } /* turn off the mic by default */ olpc_mic_bias(ac97, 0); return 0; } void olpc_quirks_cleanup(void) { if (machine_is_olpc()) gpio_free(OLPC_GPIO_MIC_AC); }
linux-master
sound/pci/cs5535audio/cs5535audio_olpc.c
// SPDX-License-Identifier: GPL-2.0 #define NM_TOTAL_COEFF_COUNT 0x3158 static const char coefficients[NM_TOTAL_COEFF_COUNT * 4] = { 0xFF, 0xFF, 0x2F, 0x00, 0x4B, 0xFF, 0xA5, 0x01, 0xEF, 0xFC, 0x21, 0x05, 0x87, 0xF7, 0x62, 0x11, 0xE9, 0x45, 0x5E, 0xF9, 0xB5, 0x01, 0xDE, 0xFF, 0xA4, 0xFF, 0x60, 0x00, 0xCA, 0xFF, 0x0D, 0x00, 0xFD, 0xFF, 0x36, 0x00, 0x36, 0xFF, 0xE6, 0x01, 0x3D, 0xFC, 0xD6, 0x06, 0x4C, 0xF3, 0xED, 0x20, 0x3D, 0x3D, 0x4A, 0xF3, 0x4E, 0x05, 0xB1, 0xFD, 0xE1, 0x00, 0xC3, 0xFF, 0x05, 0x00, 0x02, 0x00, 0xFD, 0xFF, 0x2A, 0x00, 0x5C, 0xFF, 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x06, 0x47, 0xF4, 0x94, 0x1C, 0x1F, 0x40, 0x85, 0xF4, 0x7D, 0x04, 0x36, 0xFE, 0x93, 0x00, 0xEA, 0xFF, 0xF7, 0xFF, 0x04, 0x00, 0xFF, 0xFF, 0x32, 0x00, 0x42, 0xFF, 0xBE, 0x01, 0xB4, 0xFC, 0xA4, 0x05, 0x61, 0xF6, 0xFB, 0x14, 0x53, 0x44, 0x86, 0xF7, 0xB6, 0x02, 0x49, 0xFF, 0xF7, 0xFF, 0x37, 0x00, 0xD9, 0xFF, 0x0A, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x57, 0xFF, 0x86, 0x01, 0x36, 0xFD, 0x89, 0x04, 0xCD, 0xF8, 0xB7, 0x0D, 0x3D, 0x47, 0x91, 0xFB, 0x91, 0x00, 0x83, 0x00, 0x4A, 0xFF, 0x8C, 0x00, 0xB9, 0xFF, 0x11, 0x00, 0x00, 0x00, 0x23, 0x00, 0x73, 0xFF, 0x3D, 0x01, 0xD6, 0xFD, 0x46, 0x03, 0x61, 0xFB, 0x00, 0x07, 0xBF, 0x48, 0x98, 0x00, 0x26, 0xFE, 0xD5, 0x01, 0x95, 0xFE, 0xE3, 0x00, 0x96, 0xFF, 0x1A, 0x00, 0x1A, 0x00, 0x94, 0xFF, 0xEA, 0x00, 0x87, 0xFE, 0xF0, 0x01, 0xF5, 0xFD, 0x05, 0x01, 0xCE, 0x48, 0x83, 0x06, 0x94, 0xFB, 0x2C, 0x03, 0xE4, 0xFD, 0x37, 0x01, 0x76, 0xFF, 0x22, 0x00, 0x00, 0x00, 0x12, 0x00, 0xB6, 0xFF, 0x93, 0x00, 0x3C, 0xFF, 0x9D, 0x00, 0x63, 0x00, 0xEB, 0xFB, 0x69, 0x47, 0x2D, 0x0D, 0xFF, 0xF8, 0x72, 0x04, 0x42, 0xFD, 0x81, 0x01, 0x59, 0xFF, 0x2B, 0x00, 0x00, 0x00, 0x0A, 0x00, 0xD7, 0xFF, 0x3E, 0x00, 0xEA, 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09, 0x5A, 0xF8, 0x4F, 0x05, 0xEF, 0xFC, 0x5F, 0x01, 0x9A, 0xFF, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0xAD, 0xFF, 0x48, 0x01, 0xE2, 0xFC, 0xDA, 0x05, 0x97, 0xF6, 0x0B, 0x0F, 0x79, 0x42, 0xC7, 0x03, 0x9E, 0xFA, 0x71, 0x04, 0x28, 0xFD, 0x63, 0x01, 0x8D, 0xFF, 0x0F, 0x00 }; static const u16 coefficient_sizes[8 * 2] = { /* Playback */ 0x00C0, 0x5000, 0x0060, 0x2800, 0x0040, 0x0060, 0x1400, 0x0000, /* capture */ 0x0020, 0x1260, 0x0020, 0x1260, 0x0000, 0x0040, 0x1260, 0x0000, };
linux-master
sound/pci/nm256/nm256_coef.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for NeoMagic 256AV and 256ZX chipsets. * Copyright (c) 2000 by Takashi Iwai <[email protected]> * * Based on nm256_audio.c OSS driver in linux kernel. * The original author of OSS nm256 driver wishes to remain anonymous, * so I just put my acknoledgment to him/her here. * The original author's web page is found at * http://www.uglx.org/sony.html */ #include <linux/io.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/mutex.h> #include <sound/core.h> #include <sound/info.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> #include <sound/initval.h> #define CARD_NAME "NeoMagic 256AV/ZX" #define DRIVER_NAME "NM256" MODULE_AUTHOR("Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("NeoMagic NM256AV/ZX"); MODULE_LICENSE("GPL"); /* * some compile conditions. */ static int index = SNDRV_DEFAULT_IDX1; /* Index */ static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ static int playback_bufsize = 16; static int capture_bufsize = 16; static bool force_ac97; /* disabled as default */ static int buffer_top; /* not specified */ static bool use_cache; /* disabled */ static bool vaio_hack; /* disabled */ static bool reset_workaround; static bool reset_workaround_2; module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); module_param(playback_bufsize, int, 0444); MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard."); module_param(capture_bufsize, int, 0444); MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard."); module_param(force_ac97, bool, 0444); MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard."); module_param(buffer_top, int, 0444); MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard."); module_param(use_cache, bool, 0444); MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access."); module_param(vaio_hack, bool, 0444); MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks."); module_param(reset_workaround, bool, 0444); MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops."); module_param(reset_workaround_2, bool, 0444); MODULE_PARM_DESC(reset_workaround_2, "Enable extended AC97 RESET workaround for some other laptops."); /* just for backward compatibility */ static bool enable; module_param(enable, bool, 0444); /* * hw definitions */ /* The BIOS signature. */ #define NM_SIGNATURE 0x4e4d0000 /* Signature mask. */ #define NM_SIG_MASK 0xffff0000 /* Size of the second memory area. */ #define NM_PORT2_SIZE 4096 /* The base offset of the mixer in the second memory area. */ #define NM_MIXER_OFFSET 0x600 /* The maximum size of a coefficient entry. */ #define NM_MAX_PLAYBACK_COEF_SIZE 0x5000 #define NM_MAX_RECORD_COEF_SIZE 0x1260 /* The interrupt register. */ #define NM_INT_REG 0xa04 /* And its bits. */ #define NM_PLAYBACK_INT 0x40 #define NM_RECORD_INT 0x100 #define NM_MISC_INT_1 0x4000 #define NM_MISC_INT_2 0x1 #define NM_ACK_INT(chip, X) snd_nm256_writew(chip, NM_INT_REG, (X) << 1) /* The AV's "mixer ready" status bit and location. */ #define NM_MIXER_STATUS_OFFSET 0xa04 #define NM_MIXER_READY_MASK 0x0800 #define NM_MIXER_PRESENCE 0xa06 #define NM_PRESENCE_MASK 0x0050 #define NM_PRESENCE_VALUE 0x0040 /* * For the ZX. It uses the same interrupt register, but it holds 32 * bits instead of 16. */ #define NM2_PLAYBACK_INT 0x10000 #define NM2_RECORD_INT 0x80000 #define NM2_MISC_INT_1 0x8 #define NM2_MISC_INT_2 0x2 #define NM2_ACK_INT(chip, X) snd_nm256_writel(chip, NM_INT_REG, (X)) /* The ZX's "mixer ready" status bit and location. */ #define NM2_MIXER_STATUS_OFFSET 0xa06 #define NM2_MIXER_READY_MASK 0x0800 /* The playback registers start from here. */ #define NM_PLAYBACK_REG_OFFSET 0x0 /* The record registers start from here. */ #define NM_RECORD_REG_OFFSET 0x200 /* The rate register is located 2 bytes from the start of the register area. */ #define NM_RATE_REG_OFFSET 2 /* Mono/stereo flag, number of bits on playback, and rate mask. */ #define NM_RATE_STEREO 1 #define NM_RATE_BITS_16 2 #define NM_RATE_MASK 0xf0 /* Playback enable register. */ #define NM_PLAYBACK_ENABLE_REG (NM_PLAYBACK_REG_OFFSET + 0x1) #define NM_PLAYBACK_ENABLE_FLAG 1 #define NM_PLAYBACK_ONESHOT 2 #define NM_PLAYBACK_FREERUN 4 /* Mutes the audio output. */ #define NM_AUDIO_MUTE_REG (NM_PLAYBACK_REG_OFFSET + 0x18) #define NM_AUDIO_MUTE_LEFT 0x8000 #define NM_AUDIO_MUTE_RIGHT 0x0080 /* Recording enable register. */ #define NM_RECORD_ENABLE_REG (NM_RECORD_REG_OFFSET + 0) #define NM_RECORD_ENABLE_FLAG 1 #define NM_RECORD_FREERUN 2 /* coefficient buffer pointer */ #define NM_COEFF_START_OFFSET 0x1c #define NM_COEFF_END_OFFSET 0x20 /* DMA buffer offsets */ #define NM_RBUFFER_START (NM_RECORD_REG_OFFSET + 0x4) #define NM_RBUFFER_END (NM_RECORD_REG_OFFSET + 0x10) #define NM_RBUFFER_WMARK (NM_RECORD_REG_OFFSET + 0xc) #define NM_RBUFFER_CURRP (NM_RECORD_REG_OFFSET + 0x8) #define NM_PBUFFER_START (NM_PLAYBACK_REG_OFFSET + 0x4) #define NM_PBUFFER_END (NM_PLAYBACK_REG_OFFSET + 0x14) #define NM_PBUFFER_WMARK (NM_PLAYBACK_REG_OFFSET + 0xc) #define NM_PBUFFER_CURRP (NM_PLAYBACK_REG_OFFSET + 0x8) struct nm256_stream { struct nm256 *chip; struct snd_pcm_substream *substream; int running; int suspended; u32 buf; /* offset from chip->buffer */ int bufsize; /* buffer size in bytes */ void __iomem *bufptr; /* mapped pointer */ unsigned long bufptr_addr; /* physical address of the mapped pointer */ int dma_size; /* buffer size of the substream in bytes */ int period_size; /* period size in bytes */ int periods; /* # of periods */ int shift; /* bit shifts */ int cur_period; /* current period # */ }; struct nm256 { struct snd_card *card; void __iomem *cport; /* control port */ unsigned long cport_addr; /* physical address */ void __iomem *buffer; /* buffer */ unsigned long buffer_addr; /* buffer phyiscal address */ u32 buffer_start; /* start offset from pci resource 0 */ u32 buffer_end; /* end offset */ u32 buffer_size; /* total buffer size */ u32 all_coeff_buf; /* coefficient buffer */ u32 coeff_buf[2]; /* coefficient buffer for each stream */ unsigned int coeffs_current: 1; /* coeff. table is loaded? */ unsigned int use_cache: 1; /* use one big coef. table */ unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */ unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */ unsigned int in_resume: 1; int mixer_base; /* register offset of ac97 mixer */ int mixer_status_offset; /* offset of mixer status reg. */ int mixer_status_mask; /* bit mask to test the mixer status */ int irq; int irq_acks; irq_handler_t interrupt; int badintrcount; /* counter to check bogus interrupts */ struct mutex irq_mutex; struct nm256_stream streams[2]; struct snd_ac97 *ac97; unsigned short *ac97_regs; /* register caches, only for valid regs */ struct snd_pcm *pcm; struct pci_dev *pci; spinlock_t reg_lock; }; /* * include coefficient table */ #include "nm256_coef.c" /* * PCI ids */ static const struct pci_device_id snd_nm256_ids[] = { {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO), 0}, {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO), 0}, {PCI_VDEVICE(NEOMAGIC, PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO), 0}, {0,}, }; MODULE_DEVICE_TABLE(pci, snd_nm256_ids); /* * lowlvel stuffs */ static inline u8 snd_nm256_readb(struct nm256 *chip, int offset) { return readb(chip->cport + offset); } static inline u16 snd_nm256_readw(struct nm256 *chip, int offset) { return readw(chip->cport + offset); } static inline u32 snd_nm256_readl(struct nm256 *chip, int offset) { return readl(chip->cport + offset); } static inline void snd_nm256_writeb(struct nm256 *chip, int offset, u8 val) { writeb(val, chip->cport + offset); } static inline void snd_nm256_writew(struct nm256 *chip, int offset, u16 val) { writew(val, chip->cport + offset); } static inline void snd_nm256_writel(struct nm256 *chip, int offset, u32 val) { writel(val, chip->cport + offset); } static inline void snd_nm256_write_buffer(struct nm256 *chip, const void *src, int offset, int size) { offset -= chip->buffer_start; #ifdef CONFIG_SND_DEBUG if (offset < 0 || offset >= chip->buffer_size) { dev_err(chip->card->dev, "write_buffer invalid offset = %d size = %d\n", offset, size); return; } #endif memcpy_toio(chip->buffer + offset, src, size); } /* * coefficient handlers -- what a magic! */ static u16 snd_nm256_get_start_offset(int which) { u16 offset = 0; while (which-- > 0) offset += coefficient_sizes[which]; return offset; } static void snd_nm256_load_one_coefficient(struct nm256 *chip, int stream, u32 port, int which) { u32 coeff_buf = chip->coeff_buf[stream]; u16 offset = snd_nm256_get_start_offset(which); u16 size = coefficient_sizes[which]; snd_nm256_write_buffer(chip, coefficients + offset, coeff_buf, size); snd_nm256_writel(chip, port, coeff_buf); /* ??? Record seems to behave differently than playback. */ if (stream == SNDRV_PCM_STREAM_PLAYBACK) size--; snd_nm256_writel(chip, port + 4, coeff_buf + size); } static void snd_nm256_load_coefficient(struct nm256 *chip, int stream, int number) { /* The enable register for the specified engine. */ u32 poffset = (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_ENABLE_REG : NM_PLAYBACK_ENABLE_REG); u32 addr = NM_COEFF_START_OFFSET; addr += (stream == SNDRV_PCM_STREAM_CAPTURE ? NM_RECORD_REG_OFFSET : NM_PLAYBACK_REG_OFFSET); if (snd_nm256_readb(chip, poffset) & 1) { dev_dbg(chip->card->dev, "NM256: Engine was enabled while loading coefficients!\n"); return; } /* The recording engine uses coefficient values 8-15. */ number &= 7; if (stream == SNDRV_PCM_STREAM_CAPTURE) number += 8; if (! chip->use_cache) { snd_nm256_load_one_coefficient(chip, stream, addr, number); return; } if (! chip->coeffs_current) { snd_nm256_write_buffer(chip, coefficients, chip->all_coeff_buf, NM_TOTAL_COEFF_COUNT * 4); chip->coeffs_current = 1; } else { u32 base = chip->all_coeff_buf; u32 offset = snd_nm256_get_start_offset(number); u32 end_offset = offset + coefficient_sizes[number]; snd_nm256_writel(chip, addr, base + offset); if (stream == SNDRV_PCM_STREAM_PLAYBACK) end_offset--; snd_nm256_writel(chip, addr + 4, base + end_offset); } } /* The actual rates supported by the card. */ static const unsigned int samplerates[8] = { 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, }; static const struct snd_pcm_hw_constraint_list constraints_rates = { .count = ARRAY_SIZE(samplerates), .list = samplerates, .mask = 0, }; /* * return the index of the target rate */ static int snd_nm256_fixed_rate(unsigned int rate) { unsigned int i; for (i = 0; i < ARRAY_SIZE(samplerates); i++) { if (rate == samplerates[i]) return i; } snd_BUG(); return 0; } /* * set sample rate and format */ static void snd_nm256_set_format(struct nm256 *chip, struct nm256_stream *s, struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; int rate_index = snd_nm256_fixed_rate(runtime->rate); unsigned char ratebits = (rate_index << 4) & NM_RATE_MASK; s->shift = 0; if (snd_pcm_format_width(runtime->format) == 16) { ratebits |= NM_RATE_BITS_16; s->shift++; } if (runtime->channels > 1) { ratebits |= NM_RATE_STEREO; s->shift++; } runtime->rate = samplerates[rate_index]; switch (substream->stream) { case SNDRV_PCM_STREAM_PLAYBACK: snd_nm256_load_coefficient(chip, 0, rate_index); /* 0 = playback */ snd_nm256_writeb(chip, NM_PLAYBACK_REG_OFFSET + NM_RATE_REG_OFFSET, ratebits); break; case SNDRV_PCM_STREAM_CAPTURE: snd_nm256_load_coefficient(chip, 1, rate_index); /* 1 = record */ snd_nm256_writeb(chip, NM_RECORD_REG_OFFSET + NM_RATE_REG_OFFSET, ratebits); break; } } /* acquire interrupt */ static int snd_nm256_acquire_irq(struct nm256 *chip) { mutex_lock(&chip->irq_mutex); if (chip->irq < 0) { if (request_irq(chip->pci->irq, chip->interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "unable to grab IRQ %d\n", chip->pci->irq); mutex_unlock(&chip->irq_mutex); return -EBUSY; } chip->irq = chip->pci->irq; chip->card->sync_irq = chip->irq; } chip->irq_acks++; mutex_unlock(&chip->irq_mutex); return 0; } /* release interrupt */ static void snd_nm256_release_irq(struct nm256 *chip) { mutex_lock(&chip->irq_mutex); if (chip->irq_acks > 0) chip->irq_acks--; if (chip->irq_acks == 0 && chip->irq >= 0) { free_irq(chip->irq, chip); chip->irq = -1; chip->card->sync_irq = -1; } mutex_unlock(&chip->irq_mutex); } /* * start / stop */ /* update the watermark (current period) */ static void snd_nm256_pcm_mark(struct nm256 *chip, struct nm256_stream *s, int reg) { s->cur_period++; s->cur_period %= s->periods; snd_nm256_writel(chip, reg, s->buf + s->cur_period * s->period_size); } #define snd_nm256_playback_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_PBUFFER_WMARK) #define snd_nm256_capture_mark(chip, s) snd_nm256_pcm_mark(chip, s, NM_RBUFFER_WMARK) static void snd_nm256_playback_start(struct nm256 *chip, struct nm256_stream *s, struct snd_pcm_substream *substream) { /* program buffer pointers */ snd_nm256_writel(chip, NM_PBUFFER_START, s->buf); snd_nm256_writel(chip, NM_PBUFFER_END, s->buf + s->dma_size - (1 << s->shift)); snd_nm256_writel(chip, NM_PBUFFER_CURRP, s->buf); snd_nm256_playback_mark(chip, s); /* Enable playback engine and interrupts. */ snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, NM_PLAYBACK_ENABLE_FLAG | NM_PLAYBACK_FREERUN); /* Enable both channels. */ snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, 0x0); } static void snd_nm256_capture_start(struct nm256 *chip, struct nm256_stream *s, struct snd_pcm_substream *substream) { /* program buffer pointers */ snd_nm256_writel(chip, NM_RBUFFER_START, s->buf); snd_nm256_writel(chip, NM_RBUFFER_END, s->buf + s->dma_size); snd_nm256_writel(chip, NM_RBUFFER_CURRP, s->buf); snd_nm256_capture_mark(chip, s); /* Enable playback engine and interrupts. */ snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, NM_RECORD_ENABLE_FLAG | NM_RECORD_FREERUN); } /* Stop the play engine. */ static void snd_nm256_playback_stop(struct nm256 *chip) { /* Shut off sound from both channels. */ snd_nm256_writew(chip, NM_AUDIO_MUTE_REG, NM_AUDIO_MUTE_LEFT | NM_AUDIO_MUTE_RIGHT); /* Disable play engine. */ snd_nm256_writeb(chip, NM_PLAYBACK_ENABLE_REG, 0); } static void snd_nm256_capture_stop(struct nm256 *chip) { /* Disable recording engine. */ snd_nm256_writeb(chip, NM_RECORD_ENABLE_REG, 0); } static int snd_nm256_playback_trigger(struct snd_pcm_substream *substream, int cmd) { struct nm256 *chip = snd_pcm_substream_chip(substream); struct nm256_stream *s = substream->runtime->private_data; int err = 0; if (snd_BUG_ON(!s)) return -ENXIO; spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_RESUME: s->suspended = 0; fallthrough; case SNDRV_PCM_TRIGGER_START: if (! s->running) { snd_nm256_playback_start(chip, s, substream); s->running = 1; } break; case SNDRV_PCM_TRIGGER_SUSPEND: s->suspended = 1; fallthrough; case SNDRV_PCM_TRIGGER_STOP: if (s->running) { snd_nm256_playback_stop(chip); s->running = 0; } break; default: err = -EINVAL; break; } spin_unlock(&chip->reg_lock); return err; } static int snd_nm256_capture_trigger(struct snd_pcm_substream *substream, int cmd) { struct nm256 *chip = snd_pcm_substream_chip(substream); struct nm256_stream *s = substream->runtime->private_data; int err = 0; if (snd_BUG_ON(!s)) return -ENXIO; spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: if (! s->running) { snd_nm256_capture_start(chip, s, substream); s->running = 1; } break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: if (s->running) { snd_nm256_capture_stop(chip); s->running = 0; } break; default: err = -EINVAL; break; } spin_unlock(&chip->reg_lock); return err; } /* * prepare playback/capture channel */ static int snd_nm256_pcm_prepare(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct nm256_stream *s = runtime->private_data; if (snd_BUG_ON(!s)) return -ENXIO; s->dma_size = frames_to_bytes(runtime, substream->runtime->buffer_size); s->period_size = frames_to_bytes(runtime, substream->runtime->period_size); s->periods = substream->runtime->periods; s->cur_period = 0; spin_lock_irq(&chip->reg_lock); s->running = 0; snd_nm256_set_format(chip, s, substream); spin_unlock_irq(&chip->reg_lock); return 0; } /* * get the current pointer */ static snd_pcm_uframes_t snd_nm256_playback_pointer(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); struct nm256_stream *s = substream->runtime->private_data; unsigned long curp; if (snd_BUG_ON(!s)) return 0; curp = snd_nm256_readl(chip, NM_PBUFFER_CURRP) - (unsigned long)s->buf; curp %= s->dma_size; return bytes_to_frames(substream->runtime, curp); } static snd_pcm_uframes_t snd_nm256_capture_pointer(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); struct nm256_stream *s = substream->runtime->private_data; unsigned long curp; if (snd_BUG_ON(!s)) return 0; curp = snd_nm256_readl(chip, NM_RBUFFER_CURRP) - (unsigned long)s->buf; curp %= s->dma_size; return bytes_to_frames(substream->runtime, curp); } /* Remapped I/O space can be accessible as pointer on i386 */ /* This might be changed in the future */ #ifndef __i386__ /* * silence / copy for playback */ static int snd_nm256_playback_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) { struct snd_pcm_runtime *runtime = substream->runtime; struct nm256_stream *s = runtime->private_data; memset_io(s->bufptr + pos, 0, count); return 0; } static int snd_nm256_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *src, unsigned long count) { struct snd_pcm_runtime *runtime = substream->runtime; struct nm256_stream *s = runtime->private_data; return copy_from_iter_toio(s->bufptr + pos, src, count); } /* * copy to user */ static int snd_nm256_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *dst, unsigned long count) { struct snd_pcm_runtime *runtime = substream->runtime; struct nm256_stream *s = runtime->private_data; return copy_to_iter_fromio(dst, s->bufptr + pos, count); } #endif /* !__i386__ */ /* * update playback/capture watermarks */ /* spinlock held! */ static void snd_nm256_playback_update(struct nm256 *chip) { struct nm256_stream *s; s = &chip->streams[SNDRV_PCM_STREAM_PLAYBACK]; if (s->running && s->substream) { spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(s->substream); spin_lock(&chip->reg_lock); snd_nm256_playback_mark(chip, s); } } /* spinlock held! */ static void snd_nm256_capture_update(struct nm256 *chip) { struct nm256_stream *s; s = &chip->streams[SNDRV_PCM_STREAM_CAPTURE]; if (s->running && s->substream) { spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(s->substream); spin_lock(&chip->reg_lock); snd_nm256_capture_mark(chip, s); } } /* * hardware info */ static const struct snd_pcm_hardware snd_nm256_playback = { .info = SNDRV_PCM_INFO_MMAP_IOMEM |SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | /*SNDRV_PCM_INFO_PAUSE |*/ SNDRV_PCM_INFO_RESUME, .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .periods_min = 2, .periods_max = 1024, .buffer_bytes_max = 128 * 1024, .period_bytes_min = 256, .period_bytes_max = 128 * 1024, }; static const struct snd_pcm_hardware snd_nm256_capture = { .info = SNDRV_PCM_INFO_MMAP_IOMEM | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | /*SNDRV_PCM_INFO_PAUSE |*/ SNDRV_PCM_INFO_RESUME, .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_KNOT/*24k*/ | SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .periods_min = 2, .periods_max = 1024, .buffer_bytes_max = 128 * 1024, .period_bytes_min = 256, .period_bytes_max = 128 * 1024, }; /* set dma transfer size */ static int snd_nm256_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { /* area and addr are already set and unchanged */ substream->runtime->dma_bytes = params_buffer_bytes(hw_params); return 0; } /* * open */ static void snd_nm256_setup_stream(struct nm256 *chip, struct nm256_stream *s, struct snd_pcm_substream *substream, const struct snd_pcm_hardware *hw_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; s->running = 0; runtime->hw = *hw_ptr; runtime->hw.buffer_bytes_max = s->bufsize; runtime->hw.period_bytes_max = s->bufsize / 2; runtime->dma_area = (void __force *) s->bufptr; runtime->dma_addr = s->bufptr_addr; runtime->dma_bytes = s->bufsize; runtime->private_data = s; s->substream = substream; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); } static int snd_nm256_playback_open(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); if (snd_nm256_acquire_irq(chip) < 0) return -EBUSY; snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK], substream, &snd_nm256_playback); return 0; } static int snd_nm256_capture_open(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); if (snd_nm256_acquire_irq(chip) < 0) return -EBUSY; snd_nm256_setup_stream(chip, &chip->streams[SNDRV_PCM_STREAM_CAPTURE], substream, &snd_nm256_capture); return 0; } /* * close - we don't have to do special.. */ static int snd_nm256_playback_close(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); snd_nm256_release_irq(chip); return 0; } static int snd_nm256_capture_close(struct snd_pcm_substream *substream) { struct nm256 *chip = snd_pcm_substream_chip(substream); snd_nm256_release_irq(chip); return 0; } /* * create a pcm instance */ static const struct snd_pcm_ops snd_nm256_playback_ops = { .open = snd_nm256_playback_open, .close = snd_nm256_playback_close, .hw_params = snd_nm256_pcm_hw_params, .prepare = snd_nm256_pcm_prepare, .trigger = snd_nm256_playback_trigger, .pointer = snd_nm256_playback_pointer, #ifndef __i386__ .copy = snd_nm256_playback_copy, .fill_silence = snd_nm256_playback_silence, #endif .mmap = snd_pcm_lib_mmap_iomem, }; static const struct snd_pcm_ops snd_nm256_capture_ops = { .open = snd_nm256_capture_open, .close = snd_nm256_capture_close, .hw_params = snd_nm256_pcm_hw_params, .prepare = snd_nm256_pcm_prepare, .trigger = snd_nm256_capture_trigger, .pointer = snd_nm256_capture_pointer, #ifndef __i386__ .copy = snd_nm256_capture_copy, #endif .mmap = snd_pcm_lib_mmap_iomem, }; static int snd_nm256_pcm(struct nm256 *chip, int device) { struct snd_pcm *pcm; int i, err; for (i = 0; i < 2; i++) { struct nm256_stream *s = &chip->streams[i]; s->bufptr = chip->buffer + (s->buf - chip->buffer_start); s->bufptr_addr = chip->buffer_addr + (s->buf - chip->buffer_start); } 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_nm256_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_nm256_capture_ops); pcm->private_data = chip; pcm->info_flags = 0; chip->pcm = pcm; return 0; } /* * Initialize the hardware. */ static void snd_nm256_init_chip(struct nm256 *chip) { /* Reset everything. */ snd_nm256_writeb(chip, 0x0, 0x11); snd_nm256_writew(chip, 0x214, 0); /* stop sounds.. */ //snd_nm256_playback_stop(chip); //snd_nm256_capture_stop(chip); } static irqreturn_t snd_nm256_intr_check(struct nm256 *chip) { if (chip->badintrcount++ > 1000) { /* * I'm not sure if the best thing is to stop the card from * playing or just release the interrupt (after all, we're in * a bad situation, so doing fancy stuff may not be such a good * idea). * * I worry about the card engine continuing to play noise * over and over, however--that could become a very * obnoxious problem. And we know that when this usually * happens things are fairly safe, it just means the user's * inserted a PCMCIA card and someone's spamming us with IRQ 9s. */ if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running) snd_nm256_playback_stop(chip); if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running) snd_nm256_capture_stop(chip); chip->badintrcount = 0; return IRQ_HANDLED; } return IRQ_NONE; } /* * Handle a potential interrupt for the device referred to by DEV_ID. * * I don't like the cut-n-paste job here either between the two routines, * but there are sufficient differences between the two interrupt handlers * that parameterizing it isn't all that great either. (Could use a macro, * I suppose...yucky bleah.) */ static irqreturn_t snd_nm256_interrupt(int irq, void *dev_id) { struct nm256 *chip = dev_id; u16 status; u8 cbyte; status = snd_nm256_readw(chip, NM_INT_REG); /* Not ours. */ if (status == 0) return snd_nm256_intr_check(chip); chip->badintrcount = 0; /* Rather boring; check for individual interrupts and process them. */ spin_lock(&chip->reg_lock); if (status & NM_PLAYBACK_INT) { status &= ~NM_PLAYBACK_INT; NM_ACK_INT(chip, NM_PLAYBACK_INT); snd_nm256_playback_update(chip); } if (status & NM_RECORD_INT) { status &= ~NM_RECORD_INT; NM_ACK_INT(chip, NM_RECORD_INT); snd_nm256_capture_update(chip); } if (status & NM_MISC_INT_1) { status &= ~NM_MISC_INT_1; NM_ACK_INT(chip, NM_MISC_INT_1); dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n"); snd_nm256_writew(chip, NM_INT_REG, 0x8000); cbyte = snd_nm256_readb(chip, 0x400); snd_nm256_writeb(chip, 0x400, cbyte | 2); } if (status & NM_MISC_INT_2) { status &= ~NM_MISC_INT_2; NM_ACK_INT(chip, NM_MISC_INT_2); dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n"); cbyte = snd_nm256_readb(chip, 0x400); snd_nm256_writeb(chip, 0x400, cbyte & ~2); } /* Unknown interrupt. */ if (status) { dev_dbg(chip->card->dev, "NM256: Fire in the hole! Unknown status 0x%x\n", status); /* Pray. */ NM_ACK_INT(chip, status); } spin_unlock(&chip->reg_lock); return IRQ_HANDLED; } /* * Handle a potential interrupt for the device referred to by DEV_ID. * This handler is for the 256ZX, and is very similar to the non-ZX * routine. */ static irqreturn_t snd_nm256_interrupt_zx(int irq, void *dev_id) { struct nm256 *chip = dev_id; u32 status; u8 cbyte; status = snd_nm256_readl(chip, NM_INT_REG); /* Not ours. */ if (status == 0) return snd_nm256_intr_check(chip); chip->badintrcount = 0; /* Rather boring; check for individual interrupts and process them. */ spin_lock(&chip->reg_lock); if (status & NM2_PLAYBACK_INT) { status &= ~NM2_PLAYBACK_INT; NM2_ACK_INT(chip, NM2_PLAYBACK_INT); snd_nm256_playback_update(chip); } if (status & NM2_RECORD_INT) { status &= ~NM2_RECORD_INT; NM2_ACK_INT(chip, NM2_RECORD_INT); snd_nm256_capture_update(chip); } if (status & NM2_MISC_INT_1) { status &= ~NM2_MISC_INT_1; NM2_ACK_INT(chip, NM2_MISC_INT_1); dev_dbg(chip->card->dev, "NM256: Got misc interrupt #1\n"); cbyte = snd_nm256_readb(chip, 0x400); snd_nm256_writeb(chip, 0x400, cbyte | 2); } if (status & NM2_MISC_INT_2) { status &= ~NM2_MISC_INT_2; NM2_ACK_INT(chip, NM2_MISC_INT_2); dev_dbg(chip->card->dev, "NM256: Got misc interrupt #2\n"); cbyte = snd_nm256_readb(chip, 0x400); snd_nm256_writeb(chip, 0x400, cbyte & ~2); } /* Unknown interrupt. */ if (status) { dev_dbg(chip->card->dev, "NM256: Fire in the hole! Unknown status 0x%x\n", status); /* Pray. */ NM2_ACK_INT(chip, status); } spin_unlock(&chip->reg_lock); return IRQ_HANDLED; } /* * AC97 interface */ /* * Waits for the mixer to become ready to be written; returns a zero value * if it timed out. */ static int snd_nm256_ac97_ready(struct nm256 *chip) { int timeout = 10; u32 testaddr; u16 testb; testaddr = chip->mixer_status_offset; testb = chip->mixer_status_mask; /* * Loop around waiting for the mixer to become ready. */ while (timeout-- > 0) { if ((snd_nm256_readw(chip, testaddr) & testb) == 0) return 1; udelay(100); } return 0; } /* * Initial register values to be written to the AC97 mixer. * While most of these are identical to the reset values, we do this * so that we have most of the register contents cached--this avoids * reading from the mixer directly (which seems to be problematic, * probably due to ignorance). */ struct initialValues { unsigned short reg; unsigned short value; }; static const struct initialValues nm256_ac97_init_val[] = { { AC97_MASTER, 0x8000 }, { AC97_HEADPHONE, 0x8000 }, { AC97_MASTER_MONO, 0x8000 }, { AC97_PC_BEEP, 0x8000 }, { AC97_PHONE, 0x8008 }, { AC97_MIC, 0x8000 }, { AC97_LINE, 0x8808 }, { AC97_CD, 0x8808 }, { AC97_VIDEO, 0x8808 }, { AC97_AUX, 0x8808 }, { AC97_PCM, 0x8808 }, { AC97_REC_SEL, 0x0000 }, { AC97_REC_GAIN, 0x0B0B }, { AC97_GENERAL_PURPOSE, 0x0000 }, { AC97_3D_CONTROL, 0x8000 }, { AC97_VENDOR_ID1, 0x8384 }, { AC97_VENDOR_ID2, 0x7609 }, }; static int nm256_ac97_idx(unsigned short reg) { int i; for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) if (nm256_ac97_init_val[i].reg == reg) return i; return -1; } /* * some nm256 easily crash when reading from mixer registers * thus we're treating it as a write-only mixer and cache the * written values */ static unsigned short snd_nm256_ac97_read(struct snd_ac97 *ac97, unsigned short reg) { struct nm256 *chip = ac97->private_data; int idx = nm256_ac97_idx(reg); if (idx < 0) return 0; return chip->ac97_regs[idx]; } /* */ static void snd_nm256_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { struct nm256 *chip = ac97->private_data; int tries = 2; int idx = nm256_ac97_idx(reg); u32 base; if (idx < 0) return; base = chip->mixer_base; snd_nm256_ac97_ready(chip); /* Wait for the write to take, too. */ while (tries-- > 0) { snd_nm256_writew(chip, base + reg, val); msleep(1); /* a little delay here seems better.. */ if (snd_nm256_ac97_ready(chip)) { /* successful write: set cache */ chip->ac97_regs[idx] = val; return; } } dev_dbg(chip->card->dev, "nm256: ac97 codec not ready..\n"); } /* static resolution table */ static const struct snd_ac97_res_table nm256_res_table[] = { { AC97_MASTER, 0x1f1f }, { AC97_HEADPHONE, 0x1f1f }, { AC97_MASTER_MONO, 0x001f }, { AC97_PC_BEEP, 0x001f }, { AC97_PHONE, 0x001f }, { AC97_MIC, 0x001f }, { AC97_LINE, 0x1f1f }, { AC97_CD, 0x1f1f }, { AC97_VIDEO, 0x1f1f }, { AC97_AUX, 0x1f1f }, { AC97_PCM, 0x1f1f }, { AC97_REC_GAIN, 0x0f0f }, { } /* terminator */ }; /* initialize the ac97 into a known state */ static void snd_nm256_ac97_reset(struct snd_ac97 *ac97) { struct nm256 *chip = ac97->private_data; /* Reset the mixer. 'Tis magic! */ snd_nm256_writeb(chip, 0x6c0, 1); if (! chip->reset_workaround) { /* Dell latitude LS will lock up by this */ snd_nm256_writeb(chip, 0x6cc, 0x87); } if (! chip->reset_workaround_2) { /* Dell latitude CSx will lock up by this */ snd_nm256_writeb(chip, 0x6cc, 0x80); snd_nm256_writeb(chip, 0x6cc, 0x0); } if (! chip->in_resume) { int i; for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) { /* preload the cache, so as to avoid even a single * read of the mixer regs */ snd_nm256_ac97_write(ac97, nm256_ac97_init_val[i].reg, nm256_ac97_init_val[i].value); } } } /* create an ac97 mixer interface */ static int snd_nm256_mixer(struct nm256 *chip) { struct snd_ac97_bus *pbus; struct snd_ac97_template ac97; int err; static const struct snd_ac97_bus_ops ops = { .reset = snd_nm256_ac97_reset, .write = snd_nm256_ac97_write, .read = snd_nm256_ac97_read, }; chip->ac97_regs = devm_kcalloc(chip->card->dev, ARRAY_SIZE(nm256_ac97_init_val), sizeof(short), GFP_KERNEL); if (! chip->ac97_regs) return -ENOMEM; err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus); if (err < 0) return err; memset(&ac97, 0, sizeof(ac97)); ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */ ac97.private_data = chip; ac97.res_table = nm256_res_table; pbus->no_vra = 1; err = snd_ac97_mixer(pbus, &ac97, &chip->ac97); if (err < 0) return err; if (! (chip->ac97->id & (0xf0000000))) { /* looks like an invalid id */ sprintf(chip->card->mixername, "%s AC97", chip->card->driver); } return 0; } /* * See if the signature left by the NM256 BIOS is intact; if so, we use * the associated address as the end of our audio buffer in the video * RAM. */ static int snd_nm256_peek_for_sig(struct nm256 *chip) { /* The signature is located 1K below the end of video RAM. */ void __iomem *temp; /* Default buffer end is 5120 bytes below the top of RAM. */ unsigned long pointer_found = chip->buffer_end - 0x1400; u32 sig; temp = ioremap(chip->buffer_addr + chip->buffer_end - 0x400, 16); if (temp == NULL) { dev_err(chip->card->dev, "Unable to scan for card signature in video RAM\n"); return -EBUSY; } sig = readl(temp); if ((sig & NM_SIG_MASK) == NM_SIGNATURE) { u32 pointer = readl(temp + 4); /* * If it's obviously invalid, don't use it */ if (pointer == 0xffffffff || pointer < chip->buffer_size || pointer > chip->buffer_end) { dev_err(chip->card->dev, "invalid signature found: 0x%x\n", pointer); iounmap(temp); return -ENODEV; } else { pointer_found = pointer; dev_info(chip->card->dev, "found card signature in video RAM: 0x%x\n", pointer); } } iounmap(temp); chip->buffer_end = pointer_found; return 0; } #ifdef CONFIG_PM_SLEEP /* * APM event handler, so the card is properly reinitialized after a power * event. */ static int nm256_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct nm256 *chip = card->private_data; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_ac97_suspend(chip->ac97); chip->coeffs_current = 0; return 0; } static int nm256_resume(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct nm256 *chip = card->private_data; int i; /* Perform a full reset on the hardware */ chip->in_resume = 1; snd_nm256_init_chip(chip); /* restore ac97 */ snd_ac97_resume(chip->ac97); for (i = 0; i < 2; i++) { struct nm256_stream *s = &chip->streams[i]; if (s->substream && s->suspended) { spin_lock_irq(&chip->reg_lock); snd_nm256_set_format(chip, s, s->substream); spin_unlock_irq(&chip->reg_lock); } } snd_power_change_state(card, SNDRV_CTL_POWER_D0); chip->in_resume = 0; return 0; } static SIMPLE_DEV_PM_OPS(nm256_pm, nm256_suspend, nm256_resume); #define NM256_PM_OPS &nm256_pm #else #define NM256_PM_OPS NULL #endif /* CONFIG_PM_SLEEP */ static void snd_nm256_free(struct snd_card *card) { struct nm256 *chip = card->private_data; if (chip->streams[SNDRV_PCM_STREAM_PLAYBACK].running) snd_nm256_playback_stop(chip); if (chip->streams[SNDRV_PCM_STREAM_CAPTURE].running) snd_nm256_capture_stop(chip); } static int snd_nm256_create(struct snd_card *card, struct pci_dev *pci) { struct nm256 *chip = card->private_data; int err, pval; u32 addr; err = pcim_enable_device(pci); if (err < 0) return err; chip->card = card; chip->pci = pci; chip->use_cache = use_cache; spin_lock_init(&chip->reg_lock); chip->irq = -1; mutex_init(&chip->irq_mutex); /* store buffer sizes in bytes */ chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize = playback_bufsize * 1024; chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize = capture_bufsize * 1024; /* * The NM256 has two memory ports. The first port is nothing * more than a chunk of video RAM, which is used as the I/O ring * buffer. The second port has the actual juicy stuff (like the * mixer and the playback engine control registers). */ chip->buffer_addr = pci_resource_start(pci, 0); chip->cport_addr = pci_resource_start(pci, 1); err = pci_request_regions(pci, card->driver); if (err < 0) return err; /* Init the memory port info. */ /* remap control port (#2) */ chip->cport = devm_ioremap(&pci->dev, chip->cport_addr, NM_PORT2_SIZE); if (!chip->cport) { dev_err(card->dev, "unable to map control port %lx\n", chip->cport_addr); return -ENOMEM; } if (!strcmp(card->driver, "NM256AV")) { /* Ok, try to see if this is a non-AC97 version of the hardware. */ pval = snd_nm256_readw(chip, NM_MIXER_PRESENCE); if ((pval & NM_PRESENCE_MASK) != NM_PRESENCE_VALUE) { if (! force_ac97) { dev_err(card->dev, "no ac97 is found!\n"); dev_err(card->dev, "force the driver to load by passing in the module parameter\n"); dev_err(card->dev, " force_ac97=1\n"); dev_err(card->dev, "or try sb16, opl3sa2, or cs423x drivers instead.\n"); return -ENXIO; } } chip->buffer_end = 2560 * 1024; chip->interrupt = snd_nm256_interrupt; chip->mixer_status_offset = NM_MIXER_STATUS_OFFSET; chip->mixer_status_mask = NM_MIXER_READY_MASK; } else { /* Not sure if there is any relevant detect for the ZX or not. */ if (snd_nm256_readb(chip, 0xa0b) != 0) chip->buffer_end = 6144 * 1024; else chip->buffer_end = 4096 * 1024; chip->interrupt = snd_nm256_interrupt_zx; chip->mixer_status_offset = NM2_MIXER_STATUS_OFFSET; chip->mixer_status_mask = NM2_MIXER_READY_MASK; } chip->buffer_size = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize + chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize; if (chip->use_cache) chip->buffer_size += NM_TOTAL_COEFF_COUNT * 4; else chip->buffer_size += NM_MAX_PLAYBACK_COEF_SIZE + NM_MAX_RECORD_COEF_SIZE; if (buffer_top >= chip->buffer_size && buffer_top < chip->buffer_end) chip->buffer_end = buffer_top; else { /* get buffer end pointer from signature */ err = snd_nm256_peek_for_sig(chip); if (err < 0) return err; } chip->buffer_start = chip->buffer_end - chip->buffer_size; chip->buffer_addr += chip->buffer_start; dev_info(card->dev, "Mapping port 1 from 0x%x - 0x%x\n", chip->buffer_start, chip->buffer_end); chip->buffer = devm_ioremap(&pci->dev, chip->buffer_addr, chip->buffer_size); if (!chip->buffer) { dev_err(card->dev, "unable to map ring buffer at %lx\n", chip->buffer_addr); return -ENOMEM; } /* set offsets */ addr = chip->buffer_start; chip->streams[SNDRV_PCM_STREAM_PLAYBACK].buf = addr; addr += chip->streams[SNDRV_PCM_STREAM_PLAYBACK].bufsize; chip->streams[SNDRV_PCM_STREAM_CAPTURE].buf = addr; addr += chip->streams[SNDRV_PCM_STREAM_CAPTURE].bufsize; if (chip->use_cache) { chip->all_coeff_buf = addr; } else { chip->coeff_buf[SNDRV_PCM_STREAM_PLAYBACK] = addr; addr += NM_MAX_PLAYBACK_COEF_SIZE; chip->coeff_buf[SNDRV_PCM_STREAM_CAPTURE] = addr; } /* Fixed setting. */ chip->mixer_base = NM_MIXER_OFFSET; chip->coeffs_current = 0; snd_nm256_init_chip(chip); // pci_set_master(pci); /* needed? */ return 0; } enum { NM_IGNORED, NM_RESET_WORKAROUND, NM_RESET_WORKAROUND_2 }; static const struct snd_pci_quirk nm256_quirks[] = { /* HP omnibook 4150 has cs4232 codec internally */ SND_PCI_QUIRK(0x103c, 0x0007, "HP omnibook 4150", NM_IGNORED), /* Reset workarounds to avoid lock-ups */ SND_PCI_QUIRK(0x104d, 0x8041, "Sony PCG-F305", NM_RESET_WORKAROUND), SND_PCI_QUIRK(0x1028, 0x0080, "Dell Latitude LS", NM_RESET_WORKAROUND), SND_PCI_QUIRK(0x1028, 0x0091, "Dell Latitude CSx", NM_RESET_WORKAROUND_2), { } /* terminator */ }; static int snd_nm256_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { struct snd_card *card; struct nm256 *chip; int err; const struct snd_pci_quirk *q; q = snd_pci_quirk_lookup(pci, nm256_quirks); if (q) { dev_dbg(&pci->dev, "Enabled quirk for %s.\n", snd_pci_quirk_name(q)); switch (q->value) { case NM_IGNORED: dev_info(&pci->dev, "The device is on the denylist. Loading stopped\n"); return -ENODEV; case NM_RESET_WORKAROUND_2: reset_workaround_2 = 1; fallthrough; case NM_RESET_WORKAROUND: reset_workaround = 1; break; } } err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, sizeof(*chip), &card); if (err < 0) return err; chip = card->private_data; switch (pci->device) { case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO: strcpy(card->driver, "NM256AV"); break; case PCI_DEVICE_ID_NEOMAGIC_NM256ZX_AUDIO: strcpy(card->driver, "NM256ZX"); break; case PCI_DEVICE_ID_NEOMAGIC_NM256XL_PLUS_AUDIO: strcpy(card->driver, "NM256XL+"); break; default: dev_err(&pci->dev, "invalid device id 0x%x\n", pci->device); return -EINVAL; } if (vaio_hack) buffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */ if (playback_bufsize < 4) playback_bufsize = 4; if (playback_bufsize > 128) playback_bufsize = 128; if (capture_bufsize < 4) capture_bufsize = 4; if (capture_bufsize > 128) capture_bufsize = 128; err = snd_nm256_create(card, pci); if (err < 0) return err; if (reset_workaround) { dev_dbg(&pci->dev, "reset_workaround activated\n"); chip->reset_workaround = 1; } if (reset_workaround_2) { dev_dbg(&pci->dev, "reset_workaround_2 activated\n"); chip->reset_workaround_2 = 1; } err = snd_nm256_pcm(chip, 0); if (err < 0) return err; err = snd_nm256_mixer(chip); if (err < 0) return err; sprintf(card->shortname, "NeoMagic %s", card->driver); sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %d", card->shortname, chip->buffer_addr, chip->cport_addr, chip->irq); err = snd_card_register(card); if (err < 0) return err; card->private_free = snd_nm256_free; pci_set_drvdata(pci, card); return 0; } static struct pci_driver nm256_driver = { .name = KBUILD_MODNAME, .id_table = snd_nm256_ids, .probe = snd_nm256_probe, .driver = { .pm = NM256_PM_OPS, }, }; module_pci_driver(nm256_driver);
linux-master
sound/pci/nm256/nm256.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]> * Copyright (c) by Takashi Iwai <[email protected]> * Copyright (c) by Scott McNab <[email protected]> * * Trident 4DWave-NX memory page allocation (TLB area) * Trident chip can handle only 16MByte of the memory at the same time. */ #include <linux/io.h> #include <linux/pci.h> #include <linux/time.h> #include <linux/mutex.h> #include <sound/core.h> #include "trident.h" /* page arguments of these two macros are Trident page (4096 bytes), not like * aligned pages in others */ #define __set_tlb_bus(trident,page,addr) \ (trident)->tlb.entries[page] = cpu_to_le32((addr) & ~(SNDRV_TRIDENT_PAGE_SIZE-1)) #define __tlb_to_addr(trident,page) \ (dma_addr_t)le32_to_cpu((trident->tlb.entries[page]) & ~(SNDRV_TRIDENT_PAGE_SIZE - 1)) #if PAGE_SIZE == 4096 /* page size == SNDRV_TRIDENT_PAGE_SIZE */ #define ALIGN_PAGE_SIZE PAGE_SIZE /* minimum page size for allocation */ #define MAX_ALIGN_PAGES SNDRV_TRIDENT_MAX_PAGES /* maxmium aligned pages */ /* fill TLB entrie(s) corresponding to page with ptr */ #define set_tlb_bus(trident,page,addr) __set_tlb_bus(trident,page,addr) /* fill TLB entrie(s) corresponding to page with silence pointer */ #define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, trident->tlb.silent_page->addr) /* get aligned page from offset address */ #define get_aligned_page(offset) ((offset) >> 12) /* get offset address from aligned page */ #define aligned_page_offset(page) ((page) << 12) /* get PCI physical address from aligned page */ #define page_to_addr(trident,page) __tlb_to_addr(trident, page) #elif PAGE_SIZE == 8192 /* page size == SNDRV_TRIDENT_PAGE_SIZE x 2*/ #define ALIGN_PAGE_SIZE PAGE_SIZE #define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / 2) #define get_aligned_page(offset) ((offset) >> 13) #define aligned_page_offset(page) ((page) << 13) #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) << 1) /* fill TLB entries -- we need to fill two entries */ static inline void set_tlb_bus(struct snd_trident *trident, int page, dma_addr_t addr) { page <<= 1; __set_tlb_bus(trident, page, addr); __set_tlb_bus(trident, page+1, addr + SNDRV_TRIDENT_PAGE_SIZE); } static inline void set_silent_tlb(struct snd_trident *trident, int page) { page <<= 1; __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); __set_tlb_bus(trident, page+1, trident->tlb.silent_page->addr); } #else /* arbitrary size */ #define UNIT_PAGES (PAGE_SIZE / SNDRV_TRIDENT_PAGE_SIZE) #define ALIGN_PAGE_SIZE (SNDRV_TRIDENT_PAGE_SIZE * UNIT_PAGES) #define MAX_ALIGN_PAGES (SNDRV_TRIDENT_MAX_PAGES / UNIT_PAGES) /* Note: if alignment doesn't match to the maximum size, the last few blocks * become unusable. To use such blocks, you'll need to check the validity * of accessing page in set_tlb_bus and set_silent_tlb. search_empty() * should also check it, too. */ #define get_aligned_page(offset) ((offset) / ALIGN_PAGE_SIZE) #define aligned_page_offset(page) ((page) * ALIGN_PAGE_SIZE) #define page_to_addr(trident,page) __tlb_to_addr(trident, (page) * UNIT_PAGES) /* fill TLB entries -- UNIT_PAGES entries must be filled */ static inline void set_tlb_bus(struct snd_trident *trident, int page, dma_addr_t addr) { int i; page *= UNIT_PAGES; for (i = 0; i < UNIT_PAGES; i++, page++) { __set_tlb_bus(trident, page, addr); addr += SNDRV_TRIDENT_PAGE_SIZE; } } static inline void set_silent_tlb(struct snd_trident *trident, int page) { int i; page *= UNIT_PAGES; for (i = 0; i < UNIT_PAGES; i++, page++) __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); } #endif /* PAGE_SIZE */ /* first and last (aligned) pages of memory block */ #define firstpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->first_page) #define lastpg(blk) (((struct snd_trident_memblk_arg *)snd_util_memblk_argptr(blk))->last_page) /* * search empty pages which may contain given size */ static struct snd_util_memblk * search_empty(struct snd_util_memhdr *hdr, int size) { struct snd_util_memblk *blk; int page, psize; struct list_head *p; psize = get_aligned_page(size + ALIGN_PAGE_SIZE -1); page = 0; list_for_each(p, &hdr->block) { blk = list_entry(p, struct snd_util_memblk, list); if (page + psize <= firstpg(blk)) goto __found_pages; page = lastpg(blk) + 1; } if (page + psize > MAX_ALIGN_PAGES) return NULL; __found_pages: /* create a new memory block */ blk = __snd_util_memblk_new(hdr, psize * ALIGN_PAGE_SIZE, p->prev); if (blk == NULL) return NULL; blk->offset = aligned_page_offset(page); /* set aligned offset */ firstpg(blk) = page; lastpg(blk) = page + psize - 1; return blk; } /* * check if the given pointer is valid for pages */ static int is_valid_page(unsigned long ptr) { if (ptr & ~0x3fffffffUL) { snd_printk(KERN_ERR "max memory size is 1GB!!\n"); return 0; } if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { snd_printk(KERN_ERR "page is not aligned\n"); return 0; } return 1; } /* * page allocation for DMA (Scatter-Gather version) */ static struct snd_util_memblk * snd_trident_alloc_sg_pages(struct snd_trident *trident, struct snd_pcm_substream *substream) { struct snd_util_memhdr *hdr; struct snd_util_memblk *blk; struct snd_pcm_runtime *runtime = substream->runtime; int idx, page; if (snd_BUG_ON(runtime->dma_bytes <= 0 || runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE)) return NULL; hdr = trident->tlb.memhdr; if (snd_BUG_ON(!hdr)) return NULL; mutex_lock(&hdr->block_mutex); blk = search_empty(hdr, runtime->dma_bytes); if (blk == NULL) { mutex_unlock(&hdr->block_mutex); return NULL; } /* set TLB entries */ idx = 0; for (page = firstpg(blk); page <= lastpg(blk); page++, idx++) { unsigned long ofs = idx << PAGE_SHIFT; dma_addr_t addr = snd_pcm_sgbuf_get_addr(substream, ofs); if (! is_valid_page(addr)) { __snd_util_mem_free(hdr, blk); mutex_unlock(&hdr->block_mutex); return NULL; } set_tlb_bus(trident, page, addr); } mutex_unlock(&hdr->block_mutex); return blk; } /* * page allocation for DMA (contiguous version) */ static struct snd_util_memblk * snd_trident_alloc_cont_pages(struct snd_trident *trident, struct snd_pcm_substream *substream) { struct snd_util_memhdr *hdr; struct snd_util_memblk *blk; int page; struct snd_pcm_runtime *runtime = substream->runtime; dma_addr_t addr; if (snd_BUG_ON(runtime->dma_bytes <= 0 || runtime->dma_bytes > SNDRV_TRIDENT_MAX_PAGES * SNDRV_TRIDENT_PAGE_SIZE)) return NULL; hdr = trident->tlb.memhdr; if (snd_BUG_ON(!hdr)) return NULL; mutex_lock(&hdr->block_mutex); blk = search_empty(hdr, runtime->dma_bytes); if (blk == NULL) { mutex_unlock(&hdr->block_mutex); return NULL; } /* set TLB entries */ addr = runtime->dma_addr; for (page = firstpg(blk); page <= lastpg(blk); page++, addr += SNDRV_TRIDENT_PAGE_SIZE) { if (! is_valid_page(addr)) { __snd_util_mem_free(hdr, blk); mutex_unlock(&hdr->block_mutex); return NULL; } set_tlb_bus(trident, page, addr); } mutex_unlock(&hdr->block_mutex); return blk; } /* * page allocation for DMA */ struct snd_util_memblk * snd_trident_alloc_pages(struct snd_trident *trident, struct snd_pcm_substream *substream) { if (snd_BUG_ON(!trident || !substream)) return NULL; if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV_SG) return snd_trident_alloc_sg_pages(trident, substream); else return snd_trident_alloc_cont_pages(trident, substream); } /* * release DMA buffer from page table */ int snd_trident_free_pages(struct snd_trident *trident, struct snd_util_memblk *blk) { struct snd_util_memhdr *hdr; int page; if (snd_BUG_ON(!trident || !blk)) return -EINVAL; hdr = trident->tlb.memhdr; mutex_lock(&hdr->block_mutex); /* reset TLB entries */ for (page = firstpg(blk); page <= lastpg(blk); page++) set_silent_tlb(trident, page); /* free memory block */ __snd_util_mem_free(hdr, blk); mutex_unlock(&hdr->block_mutex); return 0; }
linux-master
sound/pci/trident/trident_memory.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Maintained by Jaroslav Kysela <[email protected]> * Originated by [email protected] * Fri Feb 19 15:55:28 MST 1999 * Routines for control of Trident 4DWave (DX and NX) chip * * BUGS: * * TODO: * --- * * SiS7018 S/PDIF support by Thomas Winischhofer <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/gameport.h> #include <linux/dma-mapping.h> #include <linux/export.h> #include <linux/io.h> #include <sound/core.h> #include <sound/info.h> #include <sound/control.h> #include <sound/tlv.h> #include "trident.h" #include <sound/asoundef.h> static int snd_trident_pcm_mixer_build(struct snd_trident *trident, struct snd_trident_voice * voice, struct snd_pcm_substream *substream); static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_trident_voice * voice, struct snd_pcm_substream *substream); static irqreturn_t snd_trident_interrupt(int irq, void *dev_id); static int snd_trident_sis_reset(struct snd_trident *trident); static void snd_trident_clear_voices(struct snd_trident * trident, unsigned short v_min, unsigned short v_max); static void snd_trident_free(struct snd_card *card); /* * common I/O routines */ #if 0 static void snd_trident_print_voice_regs(struct snd_trident *trident, int voice) { unsigned int val, tmp; dev_dbg(trident->card->dev, "Trident voice %i:\n", voice); outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR)); val = inl(TRID_REG(trident, CH_LBA)); dev_dbg(trident->card->dev, "LBA: 0x%x\n", val); val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); dev_dbg(trident->card->dev, "GVSel: %i\n", val >> 31); dev_dbg(trident->card->dev, "Pan: 0x%x\n", (val >> 24) & 0x7f); dev_dbg(trident->card->dev, "Vol: 0x%x\n", (val >> 16) & 0xff); dev_dbg(trident->card->dev, "CTRL: 0x%x\n", (val >> 12) & 0x0f); dev_dbg(trident->card->dev, "EC: 0x%x\n", val & 0x0fff); if (trident->device != TRIDENT_DEVICE_ID_NX) { val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS)); dev_dbg(trident->card->dev, "CSO: 0x%x\n", val >> 16); dev_dbg(trident->card->dev, "Alpha: 0x%x\n", (val >> 4) & 0x0fff); dev_dbg(trident->card->dev, "FMS: 0x%x\n", val & 0x0f); val = inl(TRID_REG(trident, CH_DX_ESO_DELTA)); dev_dbg(trident->card->dev, "ESO: 0x%x\n", val >> 16); dev_dbg(trident->card->dev, "Delta: 0x%x\n", val & 0xffff); val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL)); } else { // TRIDENT_DEVICE_ID_NX val = inl(TRID_REG(trident, CH_NX_DELTA_CSO)); tmp = (val >> 24) & 0xff; dev_dbg(trident->card->dev, "CSO: 0x%x\n", val & 0x00ffffff); val = inl(TRID_REG(trident, CH_NX_DELTA_ESO)); tmp |= (val >> 16) & 0xff00; dev_dbg(trident->card->dev, "Delta: 0x%x\n", tmp); dev_dbg(trident->card->dev, "ESO: 0x%x\n", val & 0x00ffffff); val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL)); dev_dbg(trident->card->dev, "Alpha: 0x%x\n", val >> 20); dev_dbg(trident->card->dev, "FMS: 0x%x\n", (val >> 16) & 0x0f); } dev_dbg(trident->card->dev, "FMC: 0x%x\n", (val >> 14) & 3); dev_dbg(trident->card->dev, "RVol: 0x%x\n", (val >> 7) & 0x7f); dev_dbg(trident->card->dev, "CVol: 0x%x\n", val & 0x7f); } #endif /*--------------------------------------------------------------------------- unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg) Description: This routine will do all of the reading from the external CODEC (AC97). Parameters: ac97 - ac97 codec structure reg - CODEC register index, from AC97 Hal. returns: 16 bit value read from the AC97. ---------------------------------------------------------------------------*/ static unsigned short snd_trident_codec_read(struct snd_ac97 *ac97, unsigned short reg) { unsigned int data = 0, treg; unsigned short count = 0xffff; unsigned long flags; struct snd_trident *trident = ac97->private_data; spin_lock_irqsave(&trident->reg_lock, flags); if (trident->device == TRIDENT_DEVICE_ID_DX) { data = (DX_AC97_BUSY_READ | (reg & 0x000000ff)); outl(data, TRID_REG(trident, DX_ACR1_AC97_R)); do { data = inl(TRID_REG(trident, DX_ACR1_AC97_R)); if ((data & DX_AC97_BUSY_READ) == 0) break; } while (--count); } else if (trident->device == TRIDENT_DEVICE_ID_NX) { data = (NX_AC97_BUSY_READ | (reg & 0x000000ff)); treg = ac97->num == 0 ? NX_ACR2_AC97_R_PRIMARY : NX_ACR3_AC97_R_SECONDARY; outl(data, TRID_REG(trident, treg)); do { data = inl(TRID_REG(trident, treg)); if ((data & 0x00000C00) == 0) break; } while (--count); } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { data = SI_AC97_BUSY_READ | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff); if (ac97->num == 1) data |= SI_AC97_SECONDARY; outl(data, TRID_REG(trident, SI_AC97_READ)); do { data = inl(TRID_REG(trident, SI_AC97_READ)); if ((data & (SI_AC97_BUSY_READ)) == 0) break; } while (--count); } if (count == 0 && !trident->ac97_detect) { dev_err(trident->card->dev, "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data); data = 0; } spin_unlock_irqrestore(&trident->reg_lock, flags); return ((unsigned short) (data >> 16)); } /*--------------------------------------------------------------------------- void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short wdata) Description: This routine will do all of the writing to the external CODEC (AC97). Parameters: ac97 - ac97 codec structure reg - CODEC register index, from AC97 Hal. data - Lower 16 bits are the data to write to CODEC. returns: TRUE if everything went ok, else FALSE. ---------------------------------------------------------------------------*/ static void snd_trident_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short wdata) { unsigned int address, data; unsigned short count = 0xffff; unsigned long flags; struct snd_trident *trident = ac97->private_data; data = ((unsigned long) wdata) << 16; spin_lock_irqsave(&trident->reg_lock, flags); if (trident->device == TRIDENT_DEVICE_ID_DX) { address = DX_ACR0_AC97_W; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & DX_AC97_BUSY_WRITE) == 0) break; } while (--count); data |= (DX_AC97_BUSY_WRITE | (reg & 0x000000ff)); } else if (trident->device == TRIDENT_DEVICE_ID_NX) { address = NX_ACR1_AC97_W; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & NX_AC97_BUSY_WRITE) == 0) break; } while (--count); data |= (NX_AC97_BUSY_WRITE | (ac97->num << 8) | (reg & 0x000000ff)); } else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { address = SI_AC97_WRITE; /* read AC-97 write register status */ do { if ((inw(TRID_REG(trident, address)) & (SI_AC97_BUSY_WRITE)) == 0) break; } while (--count); data |= SI_AC97_BUSY_WRITE | SI_AC97_AUDIO_BUSY | (reg & 0x000000ff); if (ac97->num == 1) data |= SI_AC97_SECONDARY; } else { address = 0; /* keep GCC happy */ count = 0; /* return */ } if (count == 0) { spin_unlock_irqrestore(&trident->reg_lock, flags); return; } outl(data, TRID_REG(trident, address)); spin_unlock_irqrestore(&trident->reg_lock, flags); } /*--------------------------------------------------------------------------- void snd_trident_enable_eso(struct snd_trident *trident) Description: This routine will enable end of loop interrupts. End of loop interrupts will occur when a running channel reaches ESO. Also enables middle of loop interrupts. Parameters: trident - pointer to target device class for 4DWave. ---------------------------------------------------------------------------*/ static void snd_trident_enable_eso(struct snd_trident * trident) { unsigned int val; val = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); val |= ENDLP_IE; val |= MIDLP_IE; if (trident->device == TRIDENT_DEVICE_ID_SI7018) val |= BANK_B_EN; outl(val, TRID_REG(trident, T4D_LFO_GC_CIR)); } /*--------------------------------------------------------------------------- void snd_trident_disable_eso(struct snd_trident *trident) Description: This routine will disable end of loop interrupts. End of loop interrupts will occur when a running channel reaches ESO. Also disables middle of loop interrupts. Parameters: trident - pointer to target device class for 4DWave. returns: TRUE if everything went ok, else FALSE. ---------------------------------------------------------------------------*/ static void snd_trident_disable_eso(struct snd_trident * trident) { unsigned int tmp; tmp = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); tmp &= ~ENDLP_IE; tmp &= ~MIDLP_IE; outl(tmp, TRID_REG(trident, T4D_LFO_GC_CIR)); } /*--------------------------------------------------------------------------- void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice) Description: Start a voice, any channel 0 thru 63. This routine automatically handles the fact that there are more than 32 channels available. Parameters : voice - Voice number 0 thru n. trident - pointer to target device class for 4DWave. Return Value: None. ---------------------------------------------------------------------------*/ void snd_trident_start_voice(struct snd_trident * trident, unsigned int voice) { unsigned int mask = 1 << (voice & 0x1f); unsigned int reg = (voice & 0x20) ? T4D_START_B : T4D_START_A; outl(mask, TRID_REG(trident, reg)); } EXPORT_SYMBOL(snd_trident_start_voice); /*--------------------------------------------------------------------------- void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice) Description: Stop a voice, any channel 0 thru 63. This routine automatically handles the fact that there are more than 32 channels available. Parameters : voice - Voice number 0 thru n. trident - pointer to target device class for 4DWave. Return Value: None. ---------------------------------------------------------------------------*/ void snd_trident_stop_voice(struct snd_trident * trident, unsigned int voice) { unsigned int mask = 1 << (voice & 0x1f); unsigned int reg = (voice & 0x20) ? T4D_STOP_B : T4D_STOP_A; outl(mask, TRID_REG(trident, reg)); } EXPORT_SYMBOL(snd_trident_stop_voice); /*--------------------------------------------------------------------------- int snd_trident_allocate_pcm_channel(struct snd_trident *trident) Description: Allocate hardware channel in Bank B (32-63). Parameters : trident - pointer to target device class for 4DWave. Return Value: hardware channel - 32-63 or -1 when no channel is available ---------------------------------------------------------------------------*/ static int snd_trident_allocate_pcm_channel(struct snd_trident * trident) { int idx; if (trident->ChanPCMcnt >= trident->ChanPCM) return -1; for (idx = 31; idx >= 0; idx--) { if (!(trident->ChanMap[T4D_BANK_B] & (1 << idx))) { trident->ChanMap[T4D_BANK_B] |= 1 << idx; trident->ChanPCMcnt++; return idx + 32; } } return -1; } /*--------------------------------------------------------------------------- void snd_trident_free_pcm_channel(int channel) Description: Free hardware channel in Bank B (32-63) Parameters : trident - pointer to target device class for 4DWave. channel - hardware channel number 0-63 Return Value: none ---------------------------------------------------------------------------*/ static void snd_trident_free_pcm_channel(struct snd_trident *trident, int channel) { if (channel < 32 || channel > 63) return; channel &= 0x1f; if (trident->ChanMap[T4D_BANK_B] & (1 << channel)) { trident->ChanMap[T4D_BANK_B] &= ~(1 << channel); trident->ChanPCMcnt--; } } /*--------------------------------------------------------------------------- unsigned int snd_trident_allocate_synth_channel(void) Description: Allocate hardware channel in Bank A (0-31). Parameters : trident - pointer to target device class for 4DWave. Return Value: hardware channel - 0-31 or -1 when no channel is available ---------------------------------------------------------------------------*/ static int snd_trident_allocate_synth_channel(struct snd_trident * trident) { int idx; for (idx = 31; idx >= 0; idx--) { if (!(trident->ChanMap[T4D_BANK_A] & (1 << idx))) { trident->ChanMap[T4D_BANK_A] |= 1 << idx; trident->synth.ChanSynthCount++; return idx; } } return -1; } /*--------------------------------------------------------------------------- void snd_trident_free_synth_channel( int channel ) Description: Free hardware channel in Bank B (0-31). Parameters : trident - pointer to target device class for 4DWave. channel - hardware channel number 0-63 Return Value: none ---------------------------------------------------------------------------*/ static void snd_trident_free_synth_channel(struct snd_trident *trident, int channel) { if (channel < 0 || channel > 31) return; channel &= 0x1f; if (trident->ChanMap[T4D_BANK_A] & (1 << channel)) { trident->ChanMap[T4D_BANK_A] &= ~(1 << channel); trident->synth.ChanSynthCount--; } } /*--------------------------------------------------------------------------- snd_trident_write_voice_regs Description: This routine will complete and write the 5 hardware channel registers to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Each register field. ---------------------------------------------------------------------------*/ void snd_trident_write_voice_regs(struct snd_trident * trident, struct snd_trident_voice * voice) { unsigned int FmcRvolCvol; unsigned int regs[5]; regs[1] = voice->LBA; regs[4] = (voice->GVSel << 31) | ((voice->Pan & 0x0000007f) << 24) | ((voice->CTRL & 0x0000000f) << 12); FmcRvolCvol = ((voice->FMC & 3) << 14) | ((voice->RVol & 0x7f) << 7) | (voice->CVol & 0x7f); switch (trident->device) { case TRIDENT_DEVICE_ID_SI7018: regs[4] |= voice->number > 31 ? (voice->Vol & 0x000003ff) : ((voice->Vol & 0x00003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) | (voice->FMS & 0x0000000f); regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff); regs[3] = (voice->Attribute << 16) | FmcRvolCvol; break; case TRIDENT_DEVICE_ID_DX: regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->CSO << 16) | ((voice->Alpha & 0x00000fff) << 4) | (voice->FMS & 0x0000000f); regs[2] = (voice->ESO << 16) | (voice->Delta & 0x0ffff); regs[3] = FmcRvolCvol; break; case TRIDENT_DEVICE_ID_NX: regs[4] |= ((voice->Vol & 0x000003fc) << (16-2)) | (voice->EC & 0x00000fff); regs[0] = (voice->Delta << 24) | (voice->CSO & 0x00ffffff); regs[2] = ((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff); regs[3] = (voice->Alpha << 20) | ((voice->FMS & 0x0000000f) << 16) | FmcRvolCvol; break; default: snd_BUG(); return; } outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outl(regs[0], TRID_REG(trident, CH_START + 0)); outl(regs[1], TRID_REG(trident, CH_START + 4)); outl(regs[2], TRID_REG(trident, CH_START + 8)); outl(regs[3], TRID_REG(trident, CH_START + 12)); outl(regs[4], TRID_REG(trident, CH_START + 16)); #if 0 dev_dbg(trident->card->dev, "written %i channel:\n", voice->number); dev_dbg(trident->card->dev, " regs[0] = 0x%x/0x%x\n", regs[0], inl(TRID_REG(trident, CH_START + 0))); dev_dbg(trident->card->dev, " regs[1] = 0x%x/0x%x\n", regs[1], inl(TRID_REG(trident, CH_START + 4))); dev_dbg(trident->card->dev, " regs[2] = 0x%x/0x%x\n", regs[2], inl(TRID_REG(trident, CH_START + 8))); dev_dbg(trident->card->dev, " regs[3] = 0x%x/0x%x\n", regs[3], inl(TRID_REG(trident, CH_START + 12))); dev_dbg(trident->card->dev, " regs[4] = 0x%x/0x%x\n", regs[4], inl(TRID_REG(trident, CH_START + 16))); #endif } EXPORT_SYMBOL(snd_trident_write_voice_regs); /*--------------------------------------------------------------------------- snd_trident_write_cso_reg Description: This routine will write the new CSO offset register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure CSO - new CSO value ---------------------------------------------------------------------------*/ static void snd_trident_write_cso_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int CSO) { voice->CSO = CSO; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { outw(voice->CSO, TRID_REG(trident, CH_DX_CSO_ALPHA_FMS) + 2); } else { outl((voice->Delta << 24) | (voice->CSO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_CSO)); } } /*--------------------------------------------------------------------------- snd_trident_write_eso_reg Description: This routine will write the new ESO offset register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure ESO - new ESO value ---------------------------------------------------------------------------*/ static void snd_trident_write_eso_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int ESO) { voice->ESO = ESO; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { outw(voice->ESO, TRID_REG(trident, CH_DX_ESO_DELTA) + 2); } else { outl(((voice->Delta << 16) & 0xff000000) | (voice->ESO & 0x00ffffff), TRID_REG(trident, CH_NX_DELTA_ESO)); } } /*--------------------------------------------------------------------------- snd_trident_write_vol_reg Description: This routine will write the new voice volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Vol - new voice volume ---------------------------------------------------------------------------*/ static void snd_trident_write_vol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int Vol) { voice->Vol = Vol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); switch (trident->device) { case TRIDENT_DEVICE_ID_DX: case TRIDENT_DEVICE_ID_NX: outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2)); break; case TRIDENT_DEVICE_ID_SI7018: /* dev_dbg(trident->card->dev, "voice->Vol = 0x%x\n", voice->Vol); */ outw((voice->CTRL << 12) | voice->Vol, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); break; } } /*--------------------------------------------------------------------------- snd_trident_write_pan_reg Description: This routine will write the new voice pan register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure Pan - new pan value ---------------------------------------------------------------------------*/ static void snd_trident_write_pan_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int Pan) { voice->Pan = Pan; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outb(((voice->GVSel & 0x01) << 7) | (voice->Pan & 0x7f), TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 3)); } /*--------------------------------------------------------------------------- snd_trident_write_rvol_reg Description: This routine will write the new reverb volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure RVol - new reverb volume ---------------------------------------------------------------------------*/ static void snd_trident_write_rvol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int RVol) { voice->RVol = RVol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) | (voice->CVol & 0x007f), TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL)); } /*--------------------------------------------------------------------------- snd_trident_write_cvol_reg Description: This routine will write the new chorus volume register to hardware. Parameters: trident - pointer to target device class for 4DWave. voice - synthesizer voice structure CVol - new chorus volume ---------------------------------------------------------------------------*/ static void snd_trident_write_cvol_reg(struct snd_trident * trident, struct snd_trident_voice * voice, unsigned int CVol) { voice->CVol = CVol; outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); outw(((voice->FMC & 0x0003) << 14) | ((voice->RVol & 0x007f) << 7) | (voice->CVol & 0x007f), TRID_REG(trident, trident->device == TRIDENT_DEVICE_ID_NX ? CH_NX_ALPHA_FMS_FMC_RVOL_CVOL : CH_DX_FMC_RVOL_CVOL)); } /*--------------------------------------------------------------------------- snd_trident_convert_rate Description: This routine converts rate in HZ to hardware delta value. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/ static unsigned int snd_trident_convert_rate(unsigned int rate) { unsigned 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 = DIV_ROUND_CLOSEST(rate << 12, 48000) & 0x0000ffff; return delta; } /*--------------------------------------------------------------------------- snd_trident_convert_adc_rate Description: This routine converts rate in HZ to hardware delta value. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/ static unsigned int snd_trident_convert_adc_rate(unsigned int rate) { unsigned 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 = 0x116a; else if (rate == 8000) delta = 0x6000; else if (rate == 48000) delta = 0x1000; else delta = ((48000 << 12) / rate) & 0x0000ffff; return delta; } /*--------------------------------------------------------------------------- snd_trident_spurious_threshold Description: This routine converts rate in HZ to spurious threshold. Parameters: trident - pointer to target device class for 4DWave. rate - Real or Virtual channel number. Returns: Delta value. ---------------------------------------------------------------------------*/ static unsigned int snd_trident_spurious_threshold(unsigned int rate, unsigned int period_size) { unsigned int res = (rate * period_size) / 48000; if (res < 64) res = res / 2; else res -= 32; return res; } /*--------------------------------------------------------------------------- snd_trident_control_mode Description: This routine returns a control mode for a PCM channel. Parameters: trident - pointer to target device class for 4DWave. substream - PCM substream Returns: Control value. ---------------------------------------------------------------------------*/ static unsigned int snd_trident_control_mode(struct snd_pcm_substream *substream) { unsigned int CTRL; struct snd_pcm_runtime *runtime = substream->runtime; /* set ctrl mode CTRL default: 8-bit (unsigned) mono, loop mode enabled */ CTRL = 0x00000001; if (snd_pcm_format_width(runtime->format) == 16) CTRL |= 0x00000008; // 16-bit data if (snd_pcm_format_signed(runtime->format)) CTRL |= 0x00000002; // signed data if (runtime->channels > 1) CTRL |= 0x00000004; // stereo data return CTRL; } /* * PCM part */ /*--------------------------------------------------------------------------- snd_trident_allocate_pcm_mem Description: Allocate PCM ring buffer for given substream Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_allocate_pcm_mem(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; if (trident->tlb.entries) { if (runtime->buffer_changed) { if (voice->memblk) snd_trident_free_pages(trident, voice->memblk); voice->memblk = snd_trident_alloc_pages(trident, substream); if (voice->memblk == NULL) return -ENOMEM; } } return 0; } /*--------------------------------------------------------------------------- snd_trident_allocate_evoice Description: Allocate extra voice as interrupt generator Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_allocate_evoice(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; /* voice management */ if (params_buffer_size(hw_params) / 2 != params_period_size(hw_params)) { if (evoice == NULL) { evoice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (evoice == NULL) return -ENOMEM; voice->extra = evoice; evoice->substream = substream; } } else { if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = evoice = NULL; } } return 0; } /*--------------------------------------------------------------------------- snd_trident_hw_params Description: Set the hardware parameters for the playback device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { int err; err = snd_trident_allocate_pcm_mem(substream, hw_params); if (err >= 0) err = snd_trident_allocate_evoice(substream, hw_params); return err; } /*--------------------------------------------------------------------------- snd_trident_playback_hw_free Description: Release the hardware resources for the playback device. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_hw_free(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice ? voice->extra : NULL; if (trident->tlb.entries) { if (voice && voice->memblk) { snd_trident_free_pages(trident, voice->memblk); voice->memblk = NULL; } } if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = NULL; } return 0; } /*--------------------------------------------------------------------------- snd_trident_playback_prepare Description: Prepare playback device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_playback_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number]; spin_lock_irq(&trident->reg_lock); /* set delta (rate) value */ voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); /* set Loop Begin Address */ if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->GVSel = 1; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Vol = mix->vol; voice->RVol = mix->rvol; voice->CVol = mix->cvol; voice->Pan = mix->pan; voice->Attribute = 0; #if 0 voice->Attribute = (1<<(30-16))|(2<<(26-16))| (0<<(24-16))|(0x1f<<(19-16)); #else voice->Attribute = 0; #endif snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ #if 0 evoice->Attribute = (1<<(30-16))|(2<<(26-16))| (0<<(24-16))|(0x1f<<(19-16)); #else evoice->Attribute = 0; #endif snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_capture_hw_params Description: Set the hardware parameters for the capture device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { return snd_trident_allocate_pcm_mem(substream, hw_params); } /*--------------------------------------------------------------------------- snd_trident_capture_prepare Description: Prepare capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_capture_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int val, ESO_bytes; spin_lock_irq(&trident->reg_lock); // Initialize the channel and set channel Mode outb(0, TRID_REG(trident, LEGACY_DMAR15)); // Set DMA channel operation mode register outb(0x54, TRID_REG(trident, LEGACY_DMAR11)); // Set channel buffer Address, DMAR0 expects contiguous PCI memory area voice->LBA = runtime->dma_addr; outl(voice->LBA, TRID_REG(trident, LEGACY_DMAR0)); if (voice->memblk) voice->LBA = voice->memblk->offset; // set ESO ESO_bytes = snd_pcm_lib_buffer_bytes(substream) - 1; outb((ESO_bytes & 0x00ff0000) >> 16, TRID_REG(trident, LEGACY_DMAR6)); outw((ESO_bytes & 0x0000ffff), TRID_REG(trident, LEGACY_DMAR4)); ESO_bytes++; // Set channel sample rate, 4.12 format val = DIV_ROUND_CLOSEST(48000U << 12, runtime->rate); outw(val, TRID_REG(trident, T4D_SBDELTA_DELTA_R)); // Set channel interrupt blk length if (snd_pcm_format_width(runtime->format) == 16) { val = (unsigned short) ((ESO_bytes >> 1) - 1); } else { val = (unsigned short) (ESO_bytes - 1); } outl((val << 16) | val, TRID_REG(trident, T4D_SBBL_SBCL)); // Right now, set format and start to run captureing, // continuous run loop enable. trident->bDMAStart = 0x19; // 0001 1001b if (snd_pcm_format_width(runtime->format) == 16) trident->bDMAStart |= 0x80; if (snd_pcm_format_signed(runtime->format)) trident->bDMAStart |= 0x20; if (runtime->channels > 1) trident->bDMAStart |= 0x40; // Prepare capture intr channel voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); voice->isync = 1; voice->isync_mark = runtime->period_size; voice->isync_max = runtime->buffer_size; // Set voice parameters voice->CSO = 0; voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1; voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; /* mute */ voice->Vol = 0x3ff; /* mute */ voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; snd_trident_write_voice_regs(trident, voice); spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_si7018_capture_hw_params Description: Set the hardware parameters for the capture device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_si7018_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { return snd_trident_allocate_evoice(substream, hw_params); } /*--------------------------------------------------------------------------- snd_trident_si7018_capture_hw_free Description: Release the hardware resources for the capture device. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_si7018_capture_hw_free(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice ? voice->extra : NULL; if (evoice != NULL) { snd_trident_free_voice(trident, evoice); voice->extra = NULL; } return 0; } /*--------------------------------------------------------------------------- snd_trident_si7018_capture_prepare Description: Prepare capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_si7018_capture_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; spin_lock_irq(&trident->reg_lock); voice->LBA = runtime->dma_addr; voice->Delta = snd_trident_convert_adc_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); // Set voice parameters voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 0; voice->RVol = 0; voice->CVol = 0; voice->GVSel = 1; voice->Pan = T4D_DEFAULT_PCM_PAN; voice->Vol = 0; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = (2 << (30-16)) | (2 << (26-16)) | (2 << (24-16)) | (1 << (23-16)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = snd_trident_convert_rate(runtime->rate); evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 20 - 1; /* in samples, 20 means correction */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = 0; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_foldback_prepare Description: Prepare foldback capture device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_foldback_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; spin_lock_irq(&trident->reg_lock); /* Set channel buffer Address */ if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; /* set target ESO for channel */ voice->ESO = runtime->buffer_size - 1; /* in samples */ /* set sample rate */ voice->Delta = 0x1000; voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size); voice->CSO = 0; voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; /* mute */ voice->Vol = 0x3ff; /* mute */ voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; /* set up capture channel */ outb(((voice->number & 0x3f) | 0x80), TRID_REG(trident, T4D_RCI + voice->foldback_chan)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_spdif_hw_params Description: Set the hardware parameters for the spdif device. Parameters: substream - PCM substream class hw_params - hardware parameters Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_spdif_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_trident *trident = snd_pcm_substream_chip(substream); unsigned int old_bits = 0, change = 0; int err; err = snd_trident_allocate_pcm_mem(substream, hw_params); if (err < 0) return err; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_allocate_evoice(substream, hw_params); if (err < 0) return err; } /* prepare SPDIF channel */ spin_lock_irq(&trident->reg_lock); old_bits = trident->spdif_pcm_bits; if (old_bits & IEC958_AES0_PROFESSIONAL) trident->spdif_pcm_bits &= ~IEC958_AES0_PRO_FS; else trident->spdif_pcm_bits &= ~(IEC958_AES3_CON_FS << 24); if (params_rate(hw_params) >= 48000) { trident->spdif_pcm_ctrl = 0x3c; // 48000 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_48000 : (IEC958_AES3_CON_FS_48000 << 24); } else if (params_rate(hw_params) >= 44100) { trident->spdif_pcm_ctrl = 0x3e; // 44100 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_44100 : (IEC958_AES3_CON_FS_44100 << 24); } else { trident->spdif_pcm_ctrl = 0x3d; // 32000 Hz trident->spdif_pcm_bits |= trident->spdif_bits & IEC958_AES0_PROFESSIONAL ? IEC958_AES0_PRO_FS_32000 : (IEC958_AES3_CON_FS_32000 << 24); } change = old_bits != trident->spdif_pcm_bits; spin_unlock_irq(&trident->reg_lock); if (change) snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE, &trident->spdif_pcm_ctl->id); return 0; } /*--------------------------------------------------------------------------- snd_trident_spdif_prepare Description: Prepare SPDIF device for playback. Parameters: substream - PCM substream class Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_spdif_prepare(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; struct snd_trident_voice *evoice = voice->extra; struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[substream->number]; unsigned int RESO, LBAO; unsigned int temp; spin_lock_irq(&trident->reg_lock); if (trident->device != TRIDENT_DEVICE_ID_SI7018) { /* set delta (rate) value */ voice->Delta = snd_trident_convert_rate(runtime->rate); voice->spurious_threshold = snd_trident_spurious_threshold(runtime->rate, runtime->period_size); /* set Loop Back Address */ LBAO = runtime->dma_addr; if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = LBAO; voice->isync = 1; voice->isync3 = 1; voice->isync_mark = runtime->period_size; voice->isync_max = runtime->buffer_size; /* set target ESO for channel */ RESO = runtime->buffer_size - 1; voice->ESO = voice->isync_ESO = (runtime->period_size * 2) + 6 - 1; /* set ctrl mode */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->RVol = 0x7f; voice->CVol = 0x7f; voice->GVSel = 1; voice->Pan = 0x7f; voice->Vol = 0x3ff; voice->EC = 0; voice->CSO = 0; voice->Alpha = 0; voice->FMS = 0; voice->Attribute = 0; /* prepare surrogate IRQ channel */ snd_trident_write_voice_regs(trident, voice); outw((RESO & 0xffff), TRID_REG(trident, NX_SPESO)); outb((RESO >> 16), TRID_REG(trident, NX_SPESO + 2)); outl((LBAO & 0xfffffffc), TRID_REG(trident, NX_SPLBA)); outw((voice->CSO & 0xffff), TRID_REG(trident, NX_SPCTRL_SPCSO)); outb((voice->CSO >> 16), TRID_REG(trident, NX_SPCTRL_SPCSO + 2)); /* set SPDIF setting */ outb(trident->spdif_pcm_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { /* SiS */ /* set delta (rate) value */ voice->Delta = 0x800; voice->spurious_threshold = snd_trident_spurious_threshold(48000, runtime->period_size); /* set Loop Begin Address */ if (voice->memblk) voice->LBA = voice->memblk->offset; else voice->LBA = runtime->dma_addr; voice->CSO = 0; voice->ESO = runtime->buffer_size - 1; /* in samples */ voice->CTRL = snd_trident_control_mode(substream); voice->FMC = 3; voice->GVSel = 1; voice->EC = 0; voice->Alpha = 0; voice->FMS = 0; voice->Vol = mix->vol; voice->RVol = mix->rvol; voice->CVol = mix->cvol; voice->Pan = mix->pan; voice->Attribute = (1<<(30-16))|(7<<(26-16))| (0<<(24-16))|(0<<(19-16)); snd_trident_write_voice_regs(trident, voice); if (evoice != NULL) { evoice->Delta = voice->Delta; evoice->spurious_threshold = voice->spurious_threshold; evoice->LBA = voice->LBA; evoice->CSO = 0; evoice->ESO = (runtime->period_size * 2) + 4 - 1; /* in samples */ evoice->CTRL = voice->CTRL; evoice->FMC = 3; evoice->GVSel = trident->device == TRIDENT_DEVICE_ID_SI7018 ? 0 : 1; evoice->EC = 0; evoice->Alpha = 0; evoice->FMS = 0; evoice->Vol = 0x3ff; /* mute */ evoice->RVol = evoice->CVol = 0x7f; /* mute */ evoice->Pan = 0x7f; /* mute */ evoice->Attribute = 0; snd_trident_write_voice_regs(trident, evoice); evoice->isync2 = 1; evoice->isync_mark = runtime->period_size; evoice->ESO = (runtime->period_size * 2) - 1; } outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS)); temp = inl(TRID_REG(trident, T4D_LFO_GC_CIR)); temp &= ~(1<<19); outl(temp, TRID_REG(trident, T4D_LFO_GC_CIR)); temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)); temp |= SPDIF_EN; outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_trigger Description: Start/stop devices Parameters: substream - PCM substream class cmd - trigger command (STOP, GO) Returns: Error status ---------------------------------------------------------------------------*/ static int snd_trident_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_substream *s; unsigned int what, whati, capture_flag, spdif_flag; struct snd_trident_voice *voice, *evoice; unsigned int val, go; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: go = 1; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: go = 0; break; default: return -EINVAL; } what = whati = capture_flag = spdif_flag = 0; spin_lock(&trident->reg_lock); val = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff; snd_pcm_group_for_each_entry(s, substream) { if ((struct snd_trident *) snd_pcm_substream_chip(s) == trident) { voice = s->runtime->private_data; evoice = voice->extra; what |= 1 << (voice->number & 0x1f); if (evoice == NULL) { whati |= 1 << (voice->number & 0x1f); } else { what |= 1 << (evoice->number & 0x1f); whati |= 1 << (evoice->number & 0x1f); if (go) evoice->stimer = val; } if (go) { voice->running = 1; voice->stimer = val; } else { voice->running = 0; } snd_pcm_trigger_done(s, substream); if (voice->capture) capture_flag = 1; if (voice->spdif) spdif_flag = 1; } } if (spdif_flag) { if (trident->device != TRIDENT_DEVICE_ID_SI7018) { outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS)); val = trident->spdif_pcm_ctrl; if (!go) val &= ~(0x28); outb(val, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); } else { outl(trident->spdif_pcm_bits, TRID_REG(trident, SI_SPDIF_CS)); val = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) | SPDIF_EN; outl(val, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } } if (!go) outl(what, TRID_REG(trident, T4D_STOP_B)); val = inl(TRID_REG(trident, T4D_AINTEN_B)); if (go) { val |= whati; } else { val &= ~whati; } outl(val, TRID_REG(trident, T4D_AINTEN_B)); if (go) { outl(what, TRID_REG(trident, T4D_START_B)); if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018) outb(trident->bDMAStart, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD)); } else { if (capture_flag && trident->device != TRIDENT_DEVICE_ID_SI7018) outb(0x00, TRID_REG(trident, T4D_SBCTRL_SBE2R_SBDD)); } spin_unlock(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- snd_trident_playback_pointer Description: This routine return the playback position Parameters: substream - PCM substream class Returns: position of buffer ---------------------------------------------------------------------------*/ static snd_pcm_uframes_t snd_trident_playback_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int cso; if (!voice->running) return 0; spin_lock(&trident->reg_lock); outb(voice->number, TRID_REG(trident, T4D_LFO_GC_CIR)); if (trident->device != TRIDENT_DEVICE_ID_NX) { cso = inw(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS + 2)); } else { // ID_4DWAVE_NX cso = (unsigned int) inl(TRID_REG(trident, CH_NX_DELTA_CSO)) & 0x00ffffff; } spin_unlock(&trident->reg_lock); if (cso >= runtime->buffer_size) cso = 0; return cso; } /*--------------------------------------------------------------------------- snd_trident_capture_pointer Description: This routine return the capture position Parameters: pcm1 - PCM device class Returns: position of buffer ---------------------------------------------------------------------------*/ static snd_pcm_uframes_t snd_trident_capture_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int result; if (!voice->running) return 0; result = inw(TRID_REG(trident, T4D_SBBL_SBCL)); if (runtime->channels > 1) result >>= 1; if (result > 0) result = runtime->buffer_size - result; return result; } /*--------------------------------------------------------------------------- snd_trident_spdif_pointer Description: This routine return the SPDIF playback position Parameters: substream - PCM substream class Returns: position of buffer ---------------------------------------------------------------------------*/ static snd_pcm_uframes_t snd_trident_spdif_pointer(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; unsigned int result; if (!voice->running) return 0; result = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff; return result; } /* * Playback support device description */ static const struct snd_pcm_hardware snd_trident_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */), .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 4000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (256*1024), .period_bytes_min = 64, .period_bytes_max = (256*1024), .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; /* * Capture support device description */ static const struct snd_pcm_hardware snd_trident_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */), .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 4000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (128*1024), .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; /* * Foldback capture support device description */ static const struct snd_pcm_hardware snd_trident_foldback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_48000, .rate_min = 48000, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (128*1024), .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; /* * SPDIF playback support device description */ static const struct snd_pcm_hardware snd_trident_spdif = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000), .rate_min = 32000, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (128*1024), .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_trident_spdif_7018 = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_PAUSE /* | SNDRV_PCM_INFO_RESUME */), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_48000, .rate_min = 48000, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 64, .period_bytes_max = (128*1024), .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; static void snd_trident_pcm_free_substream(struct snd_pcm_runtime *runtime) { struct snd_trident_voice *voice = runtime->private_data; struct snd_trident *trident; if (voice) { trident = voice->trident; snd_trident_free_voice(trident, voice); } } static int snd_trident_playback_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; snd_trident_pcm_mixer_build(trident, voice, substream); voice->substream = substream; runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; runtime->hw = snd_trident_playback; snd_pcm_set_sync(substream); snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); return 0; } /*--------------------------------------------------------------------------- snd_trident_playback_close Description: This routine will close the 4DWave playback device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/ static int snd_trident_playback_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_trident_voice *voice = runtime->private_data; snd_trident_pcm_mixer_free(trident, voice, substream); return 0; } /*--------------------------------------------------------------------------- snd_trident_spdif_open Description: This routine will open the 4DWave SPDIF device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/ static int snd_trident_spdif_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->spdif = 1; voice->substream = substream; spin_lock_irq(&trident->reg_lock); trident->spdif_pcm_bits = trident->spdif_bits; spin_unlock_irq(&trident->reg_lock); runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { runtime->hw = snd_trident_spdif; } else { runtime->hw = snd_trident_spdif_7018; } trident->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id); snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); return 0; } /*--------------------------------------------------------------------------- snd_trident_spdif_close Description: This routine will close the 4DWave SPDIF device. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/ static int snd_trident_spdif_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); unsigned int temp; spin_lock_irq(&trident->reg_lock); // restore default SPDIF setting if (trident->device != TRIDENT_DEVICE_ID_SI7018) { outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)); if (trident->spdif_ctrl) { temp |= SPDIF_EN; } else { temp &= ~SPDIF_EN; } outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } spin_unlock_irq(&trident->reg_lock); trident->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(trident->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &trident->spdif_pcm_ctl->id); return 0; } /*--------------------------------------------------------------------------- snd_trident_capture_open Description: This routine will open the 4DWave capture device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/ static int snd_trident_capture_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->capture = 1; voice->substream = substream; runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; runtime->hw = snd_trident_capture; snd_pcm_set_sync(substream); snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); return 0; } /*--------------------------------------------------------------------------- snd_trident_capture_close Description: This routine will close the 4DWave capture device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/ static int snd_trident_capture_close(struct snd_pcm_substream *substream) { return 0; } /*--------------------------------------------------------------------------- snd_trident_foldback_open Description: This routine will open the 4DWave foldback capture device. Parameters: substream - PCM substream class Returns: status - success or failure flag ---------------------------------------------------------------------------*/ static int snd_trident_foldback_open(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = snd_trident_alloc_voice(trident, SNDRV_TRIDENT_VOICE_TYPE_PCM, 0, 0); if (voice == NULL) return -EAGAIN; voice->foldback_chan = substream->number; voice->substream = substream; runtime->private_data = voice; runtime->private_free = snd_trident_pcm_free_substream; runtime->hw = snd_trident_foldback; snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024); return 0; } /*--------------------------------------------------------------------------- snd_trident_foldback_close Description: This routine will close the 4DWave foldback capture device. For now we will simply free the dma transfer buffer. Parameters: substream - PCM substream class ---------------------------------------------------------------------------*/ static int snd_trident_foldback_close(struct snd_pcm_substream *substream) { struct snd_trident *trident = snd_pcm_substream_chip(substream); struct snd_trident_voice *voice; struct snd_pcm_runtime *runtime = substream->runtime; voice = runtime->private_data; /* stop capture channel */ spin_lock_irq(&trident->reg_lock); outb(0x00, TRID_REG(trident, T4D_RCI + voice->foldback_chan)); spin_unlock_irq(&trident->reg_lock); return 0; } /*--------------------------------------------------------------------------- PCM operations ---------------------------------------------------------------------------*/ static const struct snd_pcm_ops snd_trident_playback_ops = { .open = snd_trident_playback_open, .close = snd_trident_playback_close, .hw_params = snd_trident_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_playback_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; static const struct snd_pcm_ops snd_trident_nx_playback_ops = { .open = snd_trident_playback_open, .close = snd_trident_playback_close, .hw_params = snd_trident_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_playback_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; static const struct snd_pcm_ops snd_trident_capture_ops = { .open = snd_trident_capture_open, .close = snd_trident_capture_close, .hw_params = snd_trident_capture_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_capture_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_capture_pointer, }; static const struct snd_pcm_ops snd_trident_si7018_capture_ops = { .open = snd_trident_capture_open, .close = snd_trident_capture_close, .hw_params = snd_trident_si7018_capture_hw_params, .hw_free = snd_trident_si7018_capture_hw_free, .prepare = snd_trident_si7018_capture_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; static const struct snd_pcm_ops snd_trident_foldback_ops = { .open = snd_trident_foldback_open, .close = snd_trident_foldback_close, .hw_params = snd_trident_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_foldback_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; static const struct snd_pcm_ops snd_trident_nx_foldback_ops = { .open = snd_trident_foldback_open, .close = snd_trident_foldback_close, .hw_params = snd_trident_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_foldback_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; static const struct snd_pcm_ops snd_trident_spdif_ops = { .open = snd_trident_spdif_open, .close = snd_trident_spdif_close, .hw_params = snd_trident_spdif_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_spdif_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_spdif_pointer, }; static const struct snd_pcm_ops snd_trident_spdif_7018_ops = { .open = snd_trident_spdif_open, .close = snd_trident_spdif_close, .hw_params = snd_trident_spdif_hw_params, .hw_free = snd_trident_hw_free, .prepare = snd_trident_spdif_prepare, .trigger = snd_trident_trigger, .pointer = snd_trident_playback_pointer, }; /*--------------------------------------------------------------------------- snd_trident_pcm Description: This routine registers the 4DWave device for PCM support. Parameters: trident - pointer to target device class for 4DWave. Returns: None ---------------------------------------------------------------------------*/ int snd_trident_pcm(struct snd_trident *trident, int device) { struct snd_pcm *pcm; int err; err = snd_pcm_new(trident->card, "trident_dx_nx", device, trident->ChanPCM, 1, &pcm); if (err < 0) return err; pcm->private_data = trident; if (trident->tlb.entries) { snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_nx_playback_ops); } else { snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_playback_ops); } snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, trident->device != TRIDENT_DEVICE_ID_SI7018 ? &snd_trident_capture_ops : &snd_trident_si7018_capture_ops); pcm->info_flags = 0; pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; strcpy(pcm->name, "Trident 4DWave"); trident->pcm = pcm; if (trident->tlb.entries) { struct snd_pcm_substream *substream; for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV_SG, &trident->pci->dev, 64*1024, 128*1024); snd_pcm_set_managed_buffer(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, SNDRV_DMA_TYPE_DEV, &trident->pci->dev, 64*1024, 128*1024); } else { snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &trident->pci->dev, 64*1024, 128*1024); } return 0; } /*--------------------------------------------------------------------------- snd_trident_foldback_pcm Description: This routine registers the 4DWave device for foldback PCM support. Parameters: trident - pointer to target device class for 4DWave. Returns: None ---------------------------------------------------------------------------*/ int snd_trident_foldback_pcm(struct snd_trident *trident, int device) { struct snd_pcm *foldback; int err; int num_chan = 3; struct snd_pcm_substream *substream; if (trident->device == TRIDENT_DEVICE_ID_NX) num_chan = 4; err = snd_pcm_new(trident->card, "trident_dx_nx", device, 0, num_chan, &foldback); if (err < 0) return err; foldback->private_data = trident; if (trident->tlb.entries) snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_nx_foldback_ops); else snd_pcm_set_ops(foldback, SNDRV_PCM_STREAM_CAPTURE, &snd_trident_foldback_ops); foldback->info_flags = 0; strcpy(foldback->name, "Trident 4DWave"); substream = foldback->streams[SNDRV_PCM_STREAM_CAPTURE].substream; strcpy(substream->name, "Front Mixer"); substream = substream->next; strcpy(substream->name, "Reverb Mixer"); substream = substream->next; strcpy(substream->name, "Chorus Mixer"); if (num_chan == 4) { substream = substream->next; strcpy(substream->name, "Second AC'97 ADC"); } trident->foldback = foldback; if (trident->tlb.entries) snd_pcm_set_managed_buffer_all(foldback, SNDRV_DMA_TYPE_DEV_SG, &trident->pci->dev, 0, 128*1024); else snd_pcm_set_managed_buffer_all(foldback, SNDRV_DMA_TYPE_DEV, &trident->pci->dev, 64*1024, 128*1024); return 0; } /*--------------------------------------------------------------------------- snd_trident_spdif Description: This routine registers the 4DWave-NX device for SPDIF support. Parameters: trident - pointer to target device class for 4DWave-NX. Returns: None ---------------------------------------------------------------------------*/ int snd_trident_spdif_pcm(struct snd_trident *trident, int device) { struct snd_pcm *spdif; int err; err = snd_pcm_new(trident->card, "trident_dx_nx IEC958", device, 1, 0, &spdif); if (err < 0) return err; spdif->private_data = trident; if (trident->device != TRIDENT_DEVICE_ID_SI7018) { snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_ops); } else { snd_pcm_set_ops(spdif, SNDRV_PCM_STREAM_PLAYBACK, &snd_trident_spdif_7018_ops); } spdif->info_flags = 0; strcpy(spdif->name, "Trident 4DWave IEC958"); trident->spdif = spdif; snd_pcm_set_managed_buffer_all(spdif, SNDRV_DMA_TYPE_DEV, &trident->pci->dev, 64*1024, 128*1024); return 0; } /* * Mixer part */ /*--------------------------------------------------------------------------- snd_trident_spdif_control Description: enable/disable S/PDIF out from ac97 mixer ---------------------------------------------------------------------------*/ #define snd_trident_spdif_control_info snd_ctl_boolean_mono_info static int snd_trident_spdif_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned char val; spin_lock_irq(&trident->reg_lock); val = trident->spdif_ctrl; ucontrol->value.integer.value[0] = val == kcontrol->private_value; spin_unlock_irq(&trident->reg_lock); return 0; } static int snd_trident_spdif_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned char val; int change; val = ucontrol->value.integer.value[0] ? (unsigned char) kcontrol->private_value : 0x00; spin_lock_irq(&trident->reg_lock); /* S/PDIF C Channel bits 0-31 : 48khz, SCMS disabled */ change = trident->spdif_ctrl != val; trident->spdif_ctrl = val; if (trident->device != TRIDENT_DEVICE_ID_SI7018) { if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) { outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS)); outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); } } else { if (trident->spdif == NULL) { unsigned int temp; outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); temp = inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & ~SPDIF_EN; if (val) temp |= SPDIF_EN; outl(temp, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } } spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_spdif_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), .info = snd_trident_spdif_control_info, .get = snd_trident_spdif_control_get, .put = snd_trident_spdif_control_put, .private_value = 0x28, }; /*--------------------------------------------------------------------------- snd_trident_spdif_default Description: put/get the S/PDIF default settings ---------------------------------------------------------------------------*/ static int snd_trident_spdif_default_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_trident_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); spin_lock_irq(&trident->reg_lock); ucontrol->value.iec958.status[0] = (trident->spdif_bits >> 0) & 0xff; ucontrol->value.iec958.status[1] = (trident->spdif_bits >> 8) & 0xff; ucontrol->value.iec958.status[2] = (trident->spdif_bits >> 16) & 0xff; ucontrol->value.iec958.status[3] = (trident->spdif_bits >> 24) & 0xff; spin_unlock_irq(&trident->reg_lock); return 0; } static int snd_trident_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = (ucontrol->value.iec958.status[0] << 0) | (ucontrol->value.iec958.status[1] << 8) | (ucontrol->value.iec958.status[2] << 16) | (ucontrol->value.iec958.status[3] << 24); spin_lock_irq(&trident->reg_lock); change = trident->spdif_bits != val; trident->spdif_bits = val; if (trident->device != TRIDENT_DEVICE_ID_SI7018) { if ((inb(TRID_REG(trident, NX_SPCTRL_SPCSO + 3)) & 0x10) == 0) outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { if (trident->spdif == NULL) outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); } spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_spdif_default = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .info = snd_trident_spdif_default_info, .get = snd_trident_spdif_default_get, .put = snd_trident_spdif_default_put }; /*--------------------------------------------------------------------------- snd_trident_spdif_mask Description: put/get the S/PDIF mask ---------------------------------------------------------------------------*/ static int snd_trident_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_trident_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = 0xff; ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[2] = 0xff; ucontrol->value.iec958.status[3] = 0xff; return 0; } static const struct snd_kcontrol_new snd_trident_spdif_mask = { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), .info = snd_trident_spdif_mask_info, .get = snd_trident_spdif_mask_get, }; /*--------------------------------------------------------------------------- snd_trident_spdif_stream Description: put/get the S/PDIF stream settings ---------------------------------------------------------------------------*/ static int snd_trident_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_trident_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); spin_lock_irq(&trident->reg_lock); ucontrol->value.iec958.status[0] = (trident->spdif_pcm_bits >> 0) & 0xff; ucontrol->value.iec958.status[1] = (trident->spdif_pcm_bits >> 8) & 0xff; ucontrol->value.iec958.status[2] = (trident->spdif_pcm_bits >> 16) & 0xff; ucontrol->value.iec958.status[3] = (trident->spdif_pcm_bits >> 24) & 0xff; spin_unlock_irq(&trident->reg_lock); return 0; } static int snd_trident_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = (ucontrol->value.iec958.status[0] << 0) | (ucontrol->value.iec958.status[1] << 8) | (ucontrol->value.iec958.status[2] << 16) | (ucontrol->value.iec958.status[3] << 24); spin_lock_irq(&trident->reg_lock); change = trident->spdif_pcm_bits != val; trident->spdif_pcm_bits = val; if (trident->spdif != NULL) { if (trident->device != TRIDENT_DEVICE_ID_SI7018) { outl(trident->spdif_pcm_bits, TRID_REG(trident, NX_SPCSTATUS)); } else { outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); } } spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_spdif_stream = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), .info = snd_trident_spdif_stream_info, .get = snd_trident_spdif_stream_get, .put = snd_trident_spdif_stream_put }; /*--------------------------------------------------------------------------- snd_trident_ac97_control Description: enable/disable rear path for ac97 ---------------------------------------------------------------------------*/ #define snd_trident_ac97_control_info snd_ctl_boolean_mono_info static int snd_trident_ac97_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned char val; spin_lock_irq(&trident->reg_lock); val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); ucontrol->value.integer.value[0] = (val & (1 << kcontrol->private_value)) ? 1 : 0; spin_unlock_irq(&trident->reg_lock); return 0; } static int snd_trident_ac97_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned char val; int change = 0; spin_lock_irq(&trident->reg_lock); val = trident->ac97_ctrl = inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); val &= ~(1 << kcontrol->private_value); if (ucontrol->value.integer.value[0]) val |= 1 << kcontrol->private_value; change = val != trident->ac97_ctrl; trident->ac97_ctrl = val; outl(trident->ac97_ctrl = val, TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_ac97_rear_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Rear Path", .info = snd_trident_ac97_control_info, .get = snd_trident_ac97_control_get, .put = snd_trident_ac97_control_put, .private_value = 4, }; /*--------------------------------------------------------------------------- snd_trident_vol_control Description: wave & music volume control ---------------------------------------------------------------------------*/ static int snd_trident_vol_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_trident_vol_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned int val; val = trident->musicvol_wavevol; ucontrol->value.integer.value[0] = 255 - ((val >> kcontrol->private_value) & 0xff); ucontrol->value.integer.value[1] = 255 - ((val >> (kcontrol->private_value + 8)) & 0xff); return 0; } static const DECLARE_TLV_DB_SCALE(db_scale_gvol, -6375, 25, 0); static int snd_trident_vol_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; spin_lock_irq(&trident->reg_lock); val = trident->musicvol_wavevol; val &= ~(0xffff << kcontrol->private_value); val |= ((255 - (ucontrol->value.integer.value[0] & 0xff)) | ((255 - (ucontrol->value.integer.value[1] & 0xff)) << 8)) << kcontrol->private_value; change = val != trident->musicvol_wavevol; outl(trident->musicvol_wavevol = val, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL)); spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_vol_music_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Music Playback Volume", .info = snd_trident_vol_control_info, .get = snd_trident_vol_control_get, .put = snd_trident_vol_control_put, .private_value = 16, .tlv = { .p = db_scale_gvol }, }; static const struct snd_kcontrol_new snd_trident_vol_wave_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Wave Playback Volume", .info = snd_trident_vol_control_info, .get = snd_trident_vol_control_get, .put = snd_trident_vol_control_put, .private_value = 0, .tlv = { .p = db_scale_gvol }, }; /*--------------------------------------------------------------------------- snd_trident_pcm_vol_control Description: PCM front volume control ---------------------------------------------------------------------------*/ static int snd_trident_pcm_vol_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; if (trident->device == TRIDENT_DEVICE_ID_SI7018) uinfo->value.integer.max = 1023; return 0; } static int snd_trident_pcm_vol_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { ucontrol->value.integer.value[0] = 1023 - mix->vol; } else { ucontrol->value.integer.value[0] = 255 - (mix->vol>>2); } return 0; } static int snd_trident_pcm_vol_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; unsigned int val; int change = 0; if (trident->device == TRIDENT_DEVICE_ID_SI7018) { val = 1023 - (ucontrol->value.integer.value[0] & 1023); } else { val = (255 - (ucontrol->value.integer.value[0] & 255)) << 2; } spin_lock_irq(&trident->reg_lock); change = val != mix->vol; mix->vol = val; if (mix->voice != NULL) snd_trident_write_vol_reg(trident, mix->voice, val); spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_pcm_vol_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Front Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .count = 32, .info = snd_trident_pcm_vol_control_info, .get = snd_trident_pcm_vol_control_get, .put = snd_trident_pcm_vol_control_put, /* FIXME: no tlv yet */ }; /*--------------------------------------------------------------------------- snd_trident_pcm_pan_control Description: PCM front pan control ---------------------------------------------------------------------------*/ static int snd_trident_pcm_pan_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 127; return 0; } static int snd_trident_pcm_pan_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; ucontrol->value.integer.value[0] = mix->pan; if (ucontrol->value.integer.value[0] & 0x40) { ucontrol->value.integer.value[0] = (0x3f - (ucontrol->value.integer.value[0] & 0x3f)); } else { ucontrol->value.integer.value[0] |= 0x40; } return 0; } static int snd_trident_pcm_pan_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; unsigned char val; int change = 0; if (ucontrol->value.integer.value[0] & 0x40) val = ucontrol->value.integer.value[0] & 0x3f; else val = (0x3f - (ucontrol->value.integer.value[0] & 0x3f)) | 0x40; spin_lock_irq(&trident->reg_lock); change = val != mix->pan; mix->pan = val; if (mix->voice != NULL) snd_trident_write_pan_reg(trident, mix->voice, val); spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_pcm_pan_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Pan Playback Control", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .count = 32, .info = snd_trident_pcm_pan_control_info, .get = snd_trident_pcm_pan_control_get, .put = snd_trident_pcm_pan_control_put, }; /*--------------------------------------------------------------------------- snd_trident_pcm_rvol_control Description: PCM reverb volume control ---------------------------------------------------------------------------*/ static int snd_trident_pcm_rvol_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 127; return 0; } static int snd_trident_pcm_rvol_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; ucontrol->value.integer.value[0] = 127 - mix->rvol; return 0; } static int snd_trident_pcm_rvol_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; unsigned short val; int change = 0; val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f); spin_lock_irq(&trident->reg_lock); change = val != mix->rvol; mix->rvol = val; if (mix->voice != NULL) snd_trident_write_rvol_reg(trident, mix->voice, val); spin_unlock_irq(&trident->reg_lock); return change; } static const DECLARE_TLV_DB_SCALE(db_scale_crvol, -3175, 25, 1); static const struct snd_kcontrol_new snd_trident_pcm_rvol_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Reverb Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .count = 32, .info = snd_trident_pcm_rvol_control_info, .get = snd_trident_pcm_rvol_control_get, .put = snd_trident_pcm_rvol_control_put, .tlv = { .p = db_scale_crvol }, }; /*--------------------------------------------------------------------------- snd_trident_pcm_cvol_control Description: PCM chorus volume control ---------------------------------------------------------------------------*/ static int snd_trident_pcm_cvol_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 127; return 0; } static int snd_trident_pcm_cvol_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; ucontrol->value.integer.value[0] = 127 - mix->cvol; return 0; } static int snd_trident_pcm_cvol_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_trident *trident = snd_kcontrol_chip(kcontrol); struct snd_trident_pcm_mixer *mix = &trident->pcm_mixer[snd_ctl_get_ioffnum(kcontrol, &ucontrol->id)]; unsigned short val; int change = 0; val = 0x7f - (ucontrol->value.integer.value[0] & 0x7f); spin_lock_irq(&trident->reg_lock); change = val != mix->cvol; mix->cvol = val; if (mix->voice != NULL) snd_trident_write_cvol_reg(trident, mix->voice, val); spin_unlock_irq(&trident->reg_lock); return change; } static const struct snd_kcontrol_new snd_trident_pcm_cvol_control = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Chorus Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .count = 32, .info = snd_trident_pcm_cvol_control_info, .get = snd_trident_pcm_cvol_control_get, .put = snd_trident_pcm_cvol_control_put, .tlv = { .p = db_scale_crvol }, }; static void snd_trident_notify_pcm_change1(struct snd_card *card, struct snd_kcontrol *kctl, int num, int activate) { struct snd_ctl_elem_id id; if (! kctl) return; if (activate) kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; else kctl->vd[num].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, snd_ctl_build_ioff(&id, kctl, num)); } static void snd_trident_notify_pcm_change(struct snd_trident *trident, struct snd_trident_pcm_mixer *tmix, int num, int activate) { snd_trident_notify_pcm_change1(trident->card, trident->ctl_vol, num, activate); snd_trident_notify_pcm_change1(trident->card, trident->ctl_pan, num, activate); snd_trident_notify_pcm_change1(trident->card, trident->ctl_rvol, num, activate); snd_trident_notify_pcm_change1(trident->card, trident->ctl_cvol, num, activate); } static int snd_trident_pcm_mixer_build(struct snd_trident *trident, struct snd_trident_voice *voice, struct snd_pcm_substream *substream) { struct snd_trident_pcm_mixer *tmix; if (snd_BUG_ON(!trident || !voice || !substream)) return -EINVAL; tmix = &trident->pcm_mixer[substream->number]; tmix->voice = voice; tmix->vol = T4D_DEFAULT_PCM_VOL; tmix->pan = T4D_DEFAULT_PCM_PAN; tmix->rvol = T4D_DEFAULT_PCM_RVOL; tmix->cvol = T4D_DEFAULT_PCM_CVOL; snd_trident_notify_pcm_change(trident, tmix, substream->number, 1); return 0; } static int snd_trident_pcm_mixer_free(struct snd_trident *trident, struct snd_trident_voice *voice, struct snd_pcm_substream *substream) { struct snd_trident_pcm_mixer *tmix; if (snd_BUG_ON(!trident || !substream)) return -EINVAL; tmix = &trident->pcm_mixer[substream->number]; tmix->voice = NULL; snd_trident_notify_pcm_change(trident, tmix, substream->number, 0); return 0; } /*--------------------------------------------------------------------------- snd_trident_mixer Description: This routine registers the 4DWave device for mixer support. Parameters: trident - pointer to target device class for 4DWave. Returns: None ---------------------------------------------------------------------------*/ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device) { struct snd_ac97_template _ac97; struct snd_card *card = trident->card; struct snd_kcontrol *kctl; struct snd_ctl_elem_value *uctl; int idx, err, retries = 2; static const struct snd_ac97_bus_ops ops = { .write = snd_trident_codec_write, .read = snd_trident_codec_read, }; uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (!uctl) return -ENOMEM; err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus); if (err < 0) goto __out; memset(&_ac97, 0, sizeof(_ac97)); _ac97.private_data = trident; trident->ac97_detect = 1; __again: err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97); if (err < 0) { if (trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_sis_reset(trident); if (err < 0) goto __out; if (retries-- > 0) goto __again; err = -EIO; } goto __out; } /* secondary codec? */ if (trident->device == TRIDENT_DEVICE_ID_SI7018 && (inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0) { _ac97.num = 1; err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec); if (err < 0) dev_err(trident->card->dev, "SI7018: the secondary codec - invalid access\n"); #if 0 // only for my testing purpose --jk { struct snd_ac97 *mc97; err = snd_ac97_modem(trident->card, &_ac97, &mc97); if (err < 0) dev_err(trident->card->dev, "snd_ac97_modem returned error %i\n", err); } #endif } trident->ac97_detect = 0; if (trident->device != TRIDENT_DEVICE_ID_SI7018) { kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident); err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl->put(kctl, uctl); kctl = snd_ctl_new1(&snd_trident_vol_music_control, trident); err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl->put(kctl, uctl); outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL)); } else { outl(trident->musicvol_wavevol = 0xffff0000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL)); } for (idx = 0; idx < 32; idx++) { struct snd_trident_pcm_mixer *tmix; tmix = &trident->pcm_mixer[idx]; tmix->voice = NULL; } trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident); if (!trident->ctl_vol) goto __nomem; err = snd_ctl_add(card, trident->ctl_vol); if (err) goto __out; trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident); if (!trident->ctl_pan) goto __nomem; err = snd_ctl_add(card, trident->ctl_pan); if (err) goto __out; trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control, trident); if (!trident->ctl_rvol) goto __nomem; err = snd_ctl_add(card, trident->ctl_rvol); if (err) goto __out; trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control, trident); if (!trident->ctl_cvol) goto __nomem; err = snd_ctl_add(card, trident->ctl_cvol); if (err) goto __out; if (trident->device == TRIDENT_DEVICE_ID_NX) { kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident); err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl->put(kctl, uctl); } if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) { kctl = snd_ctl_new1(&snd_trident_spdif_control, trident); if (kctl == NULL) { err = -ENOMEM; goto __out; } if (trident->ac97->ext_id & AC97_EI_SPDIF) kctl->id.index++; if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF)) kctl->id.index++; idx = kctl->id.index; err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl->put(kctl, uctl); kctl = snd_ctl_new1(&snd_trident_spdif_default, trident); if (kctl == NULL) { err = -ENOMEM; goto __out; } kctl->id.index = idx; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl = snd_ctl_new1(&snd_trident_spdif_mask, trident); if (kctl == NULL) { err = -ENOMEM; goto __out; } kctl->id.index = idx; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) goto __out; kctl = snd_ctl_new1(&snd_trident_spdif_stream, trident); if (kctl == NULL) { err = -ENOMEM; goto __out; } kctl->id.index = idx; kctl->id.device = pcm_spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) goto __out; trident->spdif_pcm_ctl = kctl; } err = 0; goto __out; __nomem: err = -ENOMEM; __out: kfree(uctl); return err; } /* * gameport interface */ #if IS_REACHABLE(CONFIG_GAMEPORT) static unsigned char snd_trident_gameport_read(struct gameport *gameport) { struct snd_trident *chip = gameport_get_port_data(gameport); if (snd_BUG_ON(!chip)) return 0; return inb(TRID_REG(chip, GAMEPORT_LEGACY)); } static void snd_trident_gameport_trigger(struct gameport *gameport) { struct snd_trident *chip = gameport_get_port_data(gameport); if (snd_BUG_ON(!chip)) return; outb(0xff, TRID_REG(chip, GAMEPORT_LEGACY)); } static int snd_trident_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons) { struct snd_trident *chip = gameport_get_port_data(gameport); int i; if (snd_BUG_ON(!chip)) return 0; *buttons = (~inb(TRID_REG(chip, GAMEPORT_LEGACY)) >> 4) & 0xf; for (i = 0; i < 4; i++) { axes[i] = inw(TRID_REG(chip, GAMEPORT_AXES + i * 2)); if (axes[i] == 0xffff) axes[i] = -1; } return 0; } static int snd_trident_gameport_open(struct gameport *gameport, int mode) { struct snd_trident *chip = gameport_get_port_data(gameport); if (snd_BUG_ON(!chip)) return 0; switch (mode) { case GAMEPORT_MODE_COOKED: outb(GAMEPORT_MODE_ADC, TRID_REG(chip, GAMEPORT_GCR)); msleep(20); return 0; case GAMEPORT_MODE_RAW: outb(0, TRID_REG(chip, GAMEPORT_GCR)); return 0; default: return -1; } } int snd_trident_create_gameport(struct snd_trident *chip) { struct gameport *gp; chip->gameport = gp = gameport_allocate_port(); if (!gp) { dev_err(chip->card->dev, "cannot allocate memory for gameport\n"); return -ENOMEM; } gameport_set_name(gp, "Trident 4DWave"); gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); gameport_set_dev_parent(gp, &chip->pci->dev); gameport_set_port_data(gp, chip); gp->fuzz = 64; gp->read = snd_trident_gameport_read; gp->trigger = snd_trident_gameport_trigger; gp->cooked_read = snd_trident_gameport_cooked_read; gp->open = snd_trident_gameport_open; gameport_register_port(gp); return 0; } static inline void snd_trident_free_gameport(struct snd_trident *chip) { if (chip->gameport) { gameport_unregister_port(chip->gameport); chip->gameport = NULL; } } #else int snd_trident_create_gameport(struct snd_trident *chip) { return -ENOSYS; } static inline void snd_trident_free_gameport(struct snd_trident *chip) { } #endif /* CONFIG_GAMEPORT */ /* * delay for 1 tick */ static inline void do_delay(struct snd_trident *chip) { schedule_timeout_uninterruptible(1); } /* * SiS reset routine */ static int snd_trident_sis_reset(struct snd_trident *trident) { unsigned long end_time; unsigned int i; int r; r = trident->in_suspend ? 0 : 2; /* count of retries */ __si7018_retry: pci_write_config_byte(trident->pci, 0x46, 0x04); /* SOFTWARE RESET */ udelay(100); pci_write_config_byte(trident->pci, 0x46, 0x00); udelay(100); /* disable AC97 GPIO interrupt */ outb(0x00, TRID_REG(trident, SI_AC97_GPIO)); /* initialize serial interface, force cold reset */ i = PCMOUT|SURROUT|CENTEROUT|LFEOUT|SECONDARY_ID|COLD_RESET; outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); udelay(1000); /* remove cold reset */ i &= ~COLD_RESET; outl(i, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); udelay(2000); /* wait, until the codec is ready */ end_time = (jiffies + (HZ * 3) / 4) + 1; do { if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_PRIMARY_READY) != 0) goto __si7018_ok; do_delay(trident); } while (time_after_eq(end_time, jiffies)); dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL))); if (r-- > 0) { end_time = jiffies + HZ; do { do_delay(trident); } while (time_after_eq(end_time, jiffies)); goto __si7018_retry; } __si7018_ok: /* wait for the second codec */ do { if ((inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)) & SI_AC97_SECONDARY_READY) != 0) break; do_delay(trident); } while (time_after_eq(end_time, jiffies)); /* enable 64 channel mode */ outl(BANK_B_EN, TRID_REG(trident, T4D_LFO_GC_CIR)); return 0; } /* * /proc interface */ static void snd_trident_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_trident *trident = entry->private_data; char *s; switch (trident->device) { case TRIDENT_DEVICE_ID_SI7018: s = "SiS 7018 Audio"; break; case TRIDENT_DEVICE_ID_DX: s = "Trident 4DWave PCI DX"; break; case TRIDENT_DEVICE_ID_NX: s = "Trident 4DWave PCI NX"; break; default: s = "???"; } snd_iprintf(buffer, "%s\n\n", s); snd_iprintf(buffer, "Spurious IRQs : %d\n", trident->spurious_irq_count); snd_iprintf(buffer, "Spurious IRQ dlta: %d\n", trident->spurious_irq_max_delta); if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) snd_iprintf(buffer, "IEC958 Mixer Out : %s\n", trident->spdif_ctrl == 0x28 ? "on" : "off"); if (trident->device == TRIDENT_DEVICE_ID_NX) { snd_iprintf(buffer, "Rear Speakers : %s\n", trident->ac97_ctrl & 0x00000010 ? "on" : "off"); if (trident->tlb.entries) { snd_iprintf(buffer,"\nVirtual Memory\n"); snd_iprintf(buffer, "Memory Maximum : %d\n", trident->tlb.memhdr->size); snd_iprintf(buffer, "Memory Used : %d\n", trident->tlb.memhdr->used); snd_iprintf(buffer, "Memory Free : %d\n", snd_util_mem_avail(trident->tlb.memhdr)); } } } static void snd_trident_proc_init(struct snd_trident *trident) { const char *s = "trident"; if (trident->device == TRIDENT_DEVICE_ID_SI7018) s = "sis7018"; snd_card_ro_proc_new(trident->card, s, trident, snd_trident_proc_read); } /*--------------------------------------------------------------------------- snd_trident_tlb_alloc Description: Allocate and set up the TLB page table on 4D NX. Each entry has 4 bytes (physical PCI address). Parameters: trident - pointer to target device class for 4DWave. Returns: 0 or negative error code ---------------------------------------------------------------------------*/ static int snd_trident_tlb_alloc(struct snd_trident *trident) { int i; /* TLB array must be aligned to 16kB !!! so we allocate 32kB region and correct offset when necessary */ trident->tlb.buffer = snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV, 2 * SNDRV_TRIDENT_MAX_PAGES * 4); if (!trident->tlb.buffer) { dev_err(trident->card->dev, "unable to allocate TLB buffer\n"); return -ENOMEM; } trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer->area, SNDRV_TRIDENT_MAX_PAGES * 4); trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer->addr, SNDRV_TRIDENT_MAX_PAGES * 4); /* allocate and setup silent page and initialise TLB entries */ trident->tlb.silent_page = snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV, SNDRV_TRIDENT_PAGE_SIZE); if (!trident->tlb.silent_page) { dev_err(trident->card->dev, "unable to allocate silent page\n"); return -ENOMEM; } memset(trident->tlb.silent_page->area, 0, SNDRV_TRIDENT_PAGE_SIZE); for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page->addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1)); /* use emu memory block manager code to manage tlb page allocation */ trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES); if (trident->tlb.memhdr == NULL) return -ENOMEM; trident->tlb.memhdr->block_extra_size = sizeof(struct snd_trident_memblk_arg); return 0; } /* * initialize 4D DX chip */ static void snd_trident_stop_all_voices(struct snd_trident *trident) { outl(0xffffffff, TRID_REG(trident, T4D_STOP_A)); outl(0xffffffff, TRID_REG(trident, T4D_STOP_B)); outl(0, TRID_REG(trident, T4D_AINTEN_A)); outl(0, TRID_REG(trident, T4D_AINTEN_B)); } static int snd_trident_4d_dx_init(struct snd_trident *trident) { struct pci_dev *pci = trident->pci; unsigned long end_time; /* reset the legacy configuration and whole audio/wavetable block */ pci_write_config_dword(pci, 0x40, 0); /* DDMA */ pci_write_config_byte(pci, 0x44, 0); /* ports */ pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */ pci_write_config_byte(pci, 0x46, 4); /* reset */ udelay(100); pci_write_config_byte(pci, 0x46, 0); /* release reset */ udelay(100); /* warm reset of the AC'97 codec */ outl(0x00000001, TRID_REG(trident, DX_ACR2_AC97_COM_STAT)); udelay(100); outl(0x00000000, TRID_REG(trident, DX_ACR2_AC97_COM_STAT)); /* DAC on, disable SB IRQ and try to force ADC valid signal */ trident->ac97_ctrl = 0x0000004a; outl(trident->ac97_ctrl, TRID_REG(trident, DX_ACR2_AC97_COM_STAT)); /* wait, until the codec is ready */ end_time = (jiffies + (HZ * 3) / 4) + 1; do { if ((inl(TRID_REG(trident, DX_ACR2_AC97_COM_STAT)) & 0x0010) != 0) goto __dx_ok; do_delay(trident); } while (time_after_eq(end_time, jiffies)); dev_err(trident->card->dev, "AC'97 codec ready error\n"); return -EIO; __dx_ok: snd_trident_stop_all_voices(trident); return 0; } /* * initialize 4D NX chip */ static int snd_trident_4d_nx_init(struct snd_trident *trident) { struct pci_dev *pci = trident->pci; unsigned long end_time; /* reset the legacy configuration and whole audio/wavetable block */ pci_write_config_dword(pci, 0x40, 0); /* DDMA */ pci_write_config_byte(pci, 0x44, 0); /* ports */ pci_write_config_byte(pci, 0x45, 0); /* Legacy DMA */ pci_write_config_byte(pci, 0x46, 1); /* reset */ udelay(100); pci_write_config_byte(pci, 0x46, 0); /* release reset */ udelay(100); /* warm reset of the AC'97 codec */ outl(0x00000001, TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); udelay(100); outl(0x00000000, TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); /* wait, until the codec is ready */ end_time = (jiffies + (HZ * 3) / 4) + 1; do { if ((inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT)) & 0x0008) != 0) goto __nx_ok; do_delay(trident); } while (time_after_eq(end_time, jiffies)); dev_err(trident->card->dev, "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, NX_ACR0_AC97_COM_STAT))); return -EIO; __nx_ok: /* DAC on */ trident->ac97_ctrl = 0x00000002; outl(trident->ac97_ctrl, TRID_REG(trident, NX_ACR0_AC97_COM_STAT)); /* disable SB IRQ */ outl(NX_SB_IRQ_DISABLE, TRID_REG(trident, T4D_MISCINT)); snd_trident_stop_all_voices(trident); if (trident->tlb.entries != NULL) { unsigned int i; /* enable virtual addressing via TLB */ i = trident->tlb.entries_dmaaddr; i |= 0x00000001; outl(i, TRID_REG(trident, NX_TLBC)); } else { outl(0, TRID_REG(trident, NX_TLBC)); } /* initialize S/PDIF */ outl(trident->spdif_bits, TRID_REG(trident, NX_SPCSTATUS)); outb(trident->spdif_ctrl, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); return 0; } /* * initialize sis7018 chip */ static int snd_trident_sis_init(struct snd_trident *trident) { int err; err = snd_trident_sis_reset(trident); if (err < 0) return err; snd_trident_stop_all_voices(trident); /* initialize S/PDIF */ outl(trident->spdif_bits, TRID_REG(trident, SI_SPDIF_CS)); return 0; } /*--------------------------------------------------------------------------- snd_trident_create Description: This routine will create the device specific class for the 4DWave card. It will also perform basic initialization. Parameters: card - which card to create pci - interface to PCI bus resource info dma1ptr - playback dma buffer dma2ptr - capture dma buffer irqptr - interrupt resource info Returns: 4DWave device class private data ---------------------------------------------------------------------------*/ int snd_trident_create(struct snd_card *card, struct pci_dev *pci, int pcm_streams, int pcm_spdif_device, int max_wavetable_size) { struct snd_trident *trident = card->private_data; int i, err; struct snd_trident_voice *voice; struct snd_trident_pcm_mixer *tmix; /* enable PCI device */ err = pcim_enable_device(pci); if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 30 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(30))) { dev_err(card->dev, "architecture does not support 30bit PCI busmaster DMA\n"); return -ENXIO; } trident->device = (pci->vendor << 16) | pci->device; trident->card = card; trident->pci = pci; spin_lock_init(&trident->reg_lock); spin_lock_init(&trident->event_lock); spin_lock_init(&trident->voice_alloc); if (pcm_streams < 1) pcm_streams = 1; if (pcm_streams > 32) pcm_streams = 32; trident->ChanPCM = pcm_streams; if (max_wavetable_size < 0 ) max_wavetable_size = 0; trident->synth.max_size = max_wavetable_size * 1024; trident->irq = -1; card->private_free = snd_trident_free; trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE); pci_set_master(pci); err = pci_request_regions(pci, "Trident Audio"); if (err < 0) return err; trident->port = pci_resource_start(pci, 0); if (devm_request_irq(&pci->dev, pci->irq, snd_trident_interrupt, IRQF_SHARED, KBUILD_MODNAME, trident)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } trident->irq = pci->irq; card->sync_irq = trident->irq; /* allocate 16k-aligned TLB for NX cards */ trident->tlb.entries = NULL; if (trident->device == TRIDENT_DEVICE_ID_NX) { err = snd_trident_tlb_alloc(trident); if (err < 0) return err; } trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; /* initialize chip */ switch (trident->device) { case TRIDENT_DEVICE_ID_DX: err = snd_trident_4d_dx_init(trident); break; case TRIDENT_DEVICE_ID_NX: err = snd_trident_4d_nx_init(trident); break; case TRIDENT_DEVICE_ID_SI7018: err = snd_trident_sis_init(trident); break; default: snd_BUG(); break; } if (err < 0) return err; err = snd_trident_mixer(trident, pcm_spdif_device); if (err < 0) return err; /* initialise synth voices */ for (i = 0; i < 64; i++) { voice = &trident->synth.voices[i]; voice->number = i; voice->trident = trident; } /* initialize pcm mixer entries */ for (i = 0; i < 32; i++) { tmix = &trident->pcm_mixer[i]; tmix->vol = T4D_DEFAULT_PCM_VOL; tmix->pan = T4D_DEFAULT_PCM_PAN; tmix->rvol = T4D_DEFAULT_PCM_RVOL; tmix->cvol = T4D_DEFAULT_PCM_CVOL; } snd_trident_enable_eso(trident); snd_trident_proc_init(trident); return 0; } /*--------------------------------------------------------------------------- snd_trident_free Description: This routine will free the device specific class for the 4DWave card. Parameters: card - card to release Returns: None. ---------------------------------------------------------------------------*/ static void snd_trident_free(struct snd_card *card) { struct snd_trident *trident = card->private_data; snd_trident_free_gameport(trident); snd_trident_disable_eso(trident); // Disable S/PDIF out if (trident->device == TRIDENT_DEVICE_ID_NX) outb(0x00, TRID_REG(trident, NX_SPCTRL_SPCSO + 3)); else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } if (trident->tlb.buffer) { outl(0, TRID_REG(trident, NX_TLBC)); snd_util_memhdr_free(trident->tlb.memhdr); } } /*--------------------------------------------------------------------------- snd_trident_interrupt Description: ISR for Trident 4DWave device Parameters: trident - device specific private data for 4DWave card Problems: It seems that Trident chips generates interrupts more than one time in special cases. The spurious interrupts are detected via sample timer (T4D_STIMER) and computing corresponding delta value. The limits are detected with the method try & fail so it is possible that it won't work on all computers. [jaroslav] Returns: None. ---------------------------------------------------------------------------*/ static irqreturn_t snd_trident_interrupt(int irq, void *dev_id) { struct snd_trident *trident = dev_id; unsigned int audio_int, chn_int, stimer, channel, mask, tmp; int delta; struct snd_trident_voice *voice; audio_int = inl(TRID_REG(trident, T4D_MISCINT)); if ((audio_int & (ADDRESS_IRQ|MPU401_IRQ)) == 0) return IRQ_NONE; if (audio_int & ADDRESS_IRQ) { // get interrupt status for all channels spin_lock(&trident->reg_lock); stimer = inl(TRID_REG(trident, T4D_STIMER)) & 0x00ffffff; chn_int = inl(TRID_REG(trident, T4D_AINT_A)); if (chn_int == 0) goto __skip1; outl(chn_int, TRID_REG(trident, T4D_AINT_A)); /* ack */ __skip1: chn_int = inl(TRID_REG(trident, T4D_AINT_B)); if (chn_int == 0) goto __skip2; for (channel = 63; channel >= 32; channel--) { mask = 1 << (channel&0x1f); if ((chn_int & mask) == 0) continue; voice = &trident->synth.voices[channel]; if (!voice->pcm || voice->substream == NULL) { outl(mask, TRID_REG(trident, T4D_STOP_B)); continue; } delta = (int)stimer - (int)voice->stimer; if (delta < 0) delta = -delta; if ((unsigned int)delta < voice->spurious_threshold) { /* do some statistics here */ trident->spurious_irq_count++; if (trident->spurious_irq_max_delta < (unsigned int)delta) trident->spurious_irq_max_delta = delta; continue; } voice->stimer = stimer; if (voice->isync) { if (!voice->isync3) { tmp = inw(TRID_REG(trident, T4D_SBBL_SBCL)); if (trident->bDMAStart & 0x40) tmp >>= 1; if (tmp > 0) tmp = voice->isync_max - tmp; } else { tmp = inl(TRID_REG(trident, NX_SPCTRL_SPCSO)) & 0x00ffffff; } if (tmp < voice->isync_mark) { if (tmp > 0x10) tmp = voice->isync_ESO - 7; else tmp = voice->isync_ESO + 2; /* update ESO for IRQ voice to preserve sync */ snd_trident_stop_voice(trident, voice->number); snd_trident_write_eso_reg(trident, voice, tmp); snd_trident_start_voice(trident, voice->number); } } else if (voice->isync2) { voice->isync2 = 0; /* write original ESO and update CSO for IRQ voice to preserve sync */ snd_trident_stop_voice(trident, voice->number); snd_trident_write_cso_reg(trident, voice, voice->isync_mark); snd_trident_write_eso_reg(trident, voice, voice->ESO); snd_trident_start_voice(trident, voice->number); } #if 0 if (voice->extra) { /* update CSO for extra voice to preserve sync */ snd_trident_stop_voice(trident, voice->extra->number); snd_trident_write_cso_reg(trident, voice->extra, 0); snd_trident_start_voice(trident, voice->extra->number); } #endif spin_unlock(&trident->reg_lock); snd_pcm_period_elapsed(voice->substream); spin_lock(&trident->reg_lock); } outl(chn_int, TRID_REG(trident, T4D_AINT_B)); /* ack */ __skip2: spin_unlock(&trident->reg_lock); } if (audio_int & MPU401_IRQ) { if (trident->rmidi) { snd_mpu401_uart_interrupt(irq, trident->rmidi->private_data); } else { inb(TRID_REG(trident, T4D_MPUR0)); } } // outl((ST_TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), TRID_REG(trident, T4D_MISCINT)); return IRQ_HANDLED; } struct snd_trident_voice *snd_trident_alloc_voice(struct snd_trident * trident, int type, int client, int port) { struct snd_trident_voice *pvoice; unsigned long flags; int idx; spin_lock_irqsave(&trident->voice_alloc, flags); if (type == SNDRV_TRIDENT_VOICE_TYPE_PCM) { idx = snd_trident_allocate_pcm_channel(trident); if(idx < 0) { spin_unlock_irqrestore(&trident->voice_alloc, flags); return NULL; } pvoice = &trident->synth.voices[idx]; pvoice->use = 1; pvoice->pcm = 1; pvoice->capture = 0; pvoice->spdif = 0; pvoice->memblk = NULL; pvoice->substream = NULL; spin_unlock_irqrestore(&trident->voice_alloc, flags); return pvoice; } if (type == SNDRV_TRIDENT_VOICE_TYPE_SYNTH) { idx = snd_trident_allocate_synth_channel(trident); if(idx < 0) { spin_unlock_irqrestore(&trident->voice_alloc, flags); return NULL; } pvoice = &trident->synth.voices[idx]; pvoice->use = 1; pvoice->synth = 1; pvoice->client = client; pvoice->port = port; pvoice->memblk = NULL; spin_unlock_irqrestore(&trident->voice_alloc, flags); return pvoice; } if (type == SNDRV_TRIDENT_VOICE_TYPE_MIDI) { } spin_unlock_irqrestore(&trident->voice_alloc, flags); return NULL; } EXPORT_SYMBOL(snd_trident_alloc_voice); void snd_trident_free_voice(struct snd_trident * trident, struct snd_trident_voice *voice) { unsigned long flags; void (*private_free)(struct snd_trident_voice *); if (voice == NULL || !voice->use) return; snd_trident_clear_voices(trident, voice->number, voice->number); spin_lock_irqsave(&trident->voice_alloc, flags); private_free = voice->private_free; voice->private_free = NULL; voice->private_data = NULL; if (voice->pcm) snd_trident_free_pcm_channel(trident, voice->number); if (voice->synth) snd_trident_free_synth_channel(trident, voice->number); voice->use = voice->pcm = voice->synth = voice->midi = 0; voice->capture = voice->spdif = 0; voice->sample_ops = NULL; voice->substream = NULL; voice->extra = NULL; spin_unlock_irqrestore(&trident->voice_alloc, flags); if (private_free) private_free(voice); } EXPORT_SYMBOL(snd_trident_free_voice); static void snd_trident_clear_voices(struct snd_trident * trident, unsigned short v_min, unsigned short v_max) { unsigned int i, val, mask[2] = { 0, 0 }; if (snd_BUG_ON(v_min > 63 || v_max > 63)) return; for (i = v_min; i <= v_max; i++) mask[i >> 5] |= 1 << (i & 0x1f); if (mask[0]) { outl(mask[0], TRID_REG(trident, T4D_STOP_A)); val = inl(TRID_REG(trident, T4D_AINTEN_A)); outl(val & ~mask[0], TRID_REG(trident, T4D_AINTEN_A)); } if (mask[1]) { outl(mask[1], TRID_REG(trident, T4D_STOP_B)); val = inl(TRID_REG(trident, T4D_AINTEN_B)); outl(val & ~mask[1], TRID_REG(trident, T4D_AINTEN_B)); } } #ifdef CONFIG_PM_SLEEP static int snd_trident_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_trident *trident = card->private_data; trident->in_suspend = 1; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_ac97_suspend(trident->ac97); snd_ac97_suspend(trident->ac97_sec); return 0; } static int snd_trident_resume(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_trident *trident = card->private_data; switch (trident->device) { case TRIDENT_DEVICE_ID_DX: snd_trident_4d_dx_init(trident); break; case TRIDENT_DEVICE_ID_NX: snd_trident_4d_nx_init(trident); break; case TRIDENT_DEVICE_ID_SI7018: snd_trident_sis_init(trident); break; } snd_ac97_resume(trident->ac97); snd_ac97_resume(trident->ac97_sec); /* restore some registers */ outl(trident->musicvol_wavevol, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL)); snd_trident_enable_eso(trident); snd_power_change_state(card, SNDRV_CTL_POWER_D0); trident->in_suspend = 0; return 0; } SIMPLE_DEV_PM_OPS(snd_trident_pm, snd_trident_suspend, snd_trident_resume); #endif /* CONFIG_PM_SLEEP */
linux-master
sound/pci/trident/trident_main.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Trident 4DWave DX/NX & SiS SI7018 Audio PCI soundcard * * Driver was originated by Trident <[email protected]> * Fri Feb 19 15:55:28 MST 1999 */ #include <linux/init.h> #include <linux/pci.h> #include <linux/time.h> #include <linux/module.h> #include <sound/core.h> #include "trident.h" #include <sound/initval.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>, <[email protected]>"); MODULE_DESCRIPTION("Trident 4D-WaveDX/NX & SiS SI7018"); MODULE_LICENSE("GPL"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32}; static int wavetable_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8192}; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Trident 4DWave PCI soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Trident 4DWave PCI soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Trident 4DWave PCI soundcard."); module_param_array(pcm_channels, int, NULL, 0444); MODULE_PARM_DESC(pcm_channels, "Number of hardware channels assigned for PCM."); module_param_array(wavetable_size, int, NULL, 0444); MODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth."); static const struct pci_device_id snd_trident_ids[] = { {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_DX), PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0}, {PCI_DEVICE(PCI_VENDOR_ID_TRIDENT, PCI_DEVICE_ID_TRIDENT_4DWAVE_NX), 0, 0, 0}, {PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7018), 0, 0, 0}, { 0, } }; MODULE_DEVICE_TABLE(pci, snd_trident_ids); static int snd_trident_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct snd_trident *trident; const char *str; int err, pcm_dev = 0; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*trident), &card); if (err < 0) return err; trident = card->private_data; err = snd_trident_create(card, pci, pcm_channels[dev], ((pci->vendor << 16) | pci->device) == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2, wavetable_size[dev]); if (err < 0) return err; switch (trident->device) { case TRIDENT_DEVICE_ID_DX: str = "TRID4DWAVEDX"; break; case TRIDENT_DEVICE_ID_NX: str = "TRID4DWAVENX"; break; case TRIDENT_DEVICE_ID_SI7018: str = "SI7018"; break; default: str = "Unknown"; } strcpy(card->driver, str); if (trident->device == TRIDENT_DEVICE_ID_SI7018) { strcpy(card->shortname, "SiS "); } else { strcpy(card->shortname, "Trident "); } strcat(card->shortname, str); sprintf(card->longname, "%s PCI Audio at 0x%lx, irq %d", card->shortname, trident->port, trident->irq); err = snd_trident_pcm(trident, pcm_dev++); if (err < 0) return err; switch (trident->device) { case TRIDENT_DEVICE_ID_DX: case TRIDENT_DEVICE_ID_NX: err = snd_trident_foldback_pcm(trident, pcm_dev++); if (err < 0) return err; break; } if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_spdif_pcm(trident, pcm_dev++); if (err < 0) return err; } if (trident->device != TRIDENT_DEVICE_ID_SI7018) { err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, trident->midi_port, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &trident->rmidi); if (err < 0) return err; } snd_trident_create_gameport(trident); err = snd_card_register(card); if (err < 0) return err; pci_set_drvdata(pci, card); dev++; return 0; } static struct pci_driver trident_driver = { .name = KBUILD_MODNAME, .id_table = snd_trident_ids, .probe = snd_trident_probe, #ifdef CONFIG_PM_SLEEP .driver = { .pm = &snd_trident_pm, }, #endif }; module_pci_driver(trident_driver);
linux-master
sound/pci/trident/trident.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA driver for RME Hammerfall DSP MADI audio interface(s) * * Copyright (c) 2003 Winfried Ritsch (IEM) * code based on hdsp.c Paul Davis * Marcus Andersson * Thomas Charbonnel * Modified 2006-06-01 for AES32 support by Remy Bruno * <[email protected]> * * Modified 2009-04-13 for proper metering by Florian Faber * <[email protected]> * * Modified 2009-04-14 for native float support by Florian Faber * <[email protected]> * * Modified 2009-04-26 fixed bug in rms metering by Florian Faber * <[email protected]> * * Modified 2009-04-30 added hw serial number support by Florian Faber * * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth * * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth * * Modified 2019-05-23 fix AIO single speed ADAT capture and playback * by [email protected] */ /* ************* Register Documentation ******************************************************* * * Work in progress! Documentation is based on the code in this file. * * --------- HDSPM_controlRegister --------- * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte * :||||.||||:||||.||||:||||.||||:||||.||||: * :3322.2222:2222.1111:1111.1100:0000.0000: bit number * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31 * :||||.||||:||||.||||:||||.||||:||||.||||: * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit * : . : . : . : x . : HDSPM_AudioInterruptEnable \_ setting both bits * : . : . : . : . x: HDSPM_Start / enables audio IO * : . : . : . : x. : HDSPM_ClockModeMaster - 1: Master, 0: Slave * : . : . : . : .210 : HDSPM_LatencyMask - 3 Bit value for latency * : . : . : . : . : 0:64, 1:128, 2:256, 3:512, * : . : . : . : . : 4:1024, 5:2048, 6:4096, 7:8192 * :x . : . : . x:xx . : HDSPM_FrequencyMask * : . : . : . :10 . : HDSPM_Frequency1|HDSPM_Frequency0: 1=32K,2=44.1K,3=48K,0=?? * : . : . : . x: . : <MADI> HDSPM_DoubleSpeed * :x . : . : . : . : <MADI> HDSPM_QuadSpeed * : . 3 : . 10: 2 . : . : HDSPM_SyncRefMask : * : . : . x: . : . : HDSPM_SyncRef0 * : . : . x : . : . : HDSPM_SyncRef1 * : . : . : x . : . : <AES32> HDSPM_SyncRef2 * : . x : . : . : . : <AES32> HDSPM_SyncRef3 * : . : . 10: . : . : <MADI> sync ref: 0:WC, 1:Madi, 2:TCO, 3:SyncIn * : . 3 : . 10: 2 . : . : <AES32> 0:WC, 1:AES1 ... 8:AES8, 9: TCO, 10:SyncIn? * : . x : . : . : . : <MADIe> HDSPe_FLOAT_FORMAT * : . : . : x . : . : <MADI> HDSPM_InputSelect0 : 0=optical,1=coax * : . : . :x . : . : <MADI> HDSPM_InputSelect1 * : . : .x : . : . : <MADI> HDSPM_clr_tms * : . : . : . x : . : <MADI> HDSPM_TX_64ch * : . : . : . x : . : <AES32> HDSPM_Emphasis * : . : . : .x : . : <MADI> HDSPM_AutoInp * : . : . x : . : . : <MADI> HDSPM_SMUX * : . : .x : . : . : <MADI> HDSPM_clr_tms * : . : x. : . : . : <MADI> HDSPM_taxi_reset * : . x: . : . : . : <MADI> HDSPM_LineOut * : . x: . : . : . : <AES32> ?????????????????? * : . : x. : . : . : <AES32> HDSPM_WCK48 * : . : . : .x : . : <AES32> HDSPM_Dolby * : . : x . : . : . : HDSPM_Midi0InterruptEnable * : . :x . : . : . : HDSPM_Midi1InterruptEnable * : . : x . : . : . : HDSPM_Midi2InterruptEnable * : . x : . : . : . : <MADI> HDSPM_Midi3InterruptEnable * : . x : . : . : . : <AES32> HDSPM_DS_DoubleWire * : .x : . : . : . : <AES32> HDSPM_QS_DoubleWire * : x. : . : . : . : <AES32> HDSPM_QS_QuadWire * : . : . : . x : . : <AES32> HDSPM_Professional * : x . : . : . : . : HDSPM_wclk_sel * : . : . : . : . : * :7654.3210:7654.3210:7654.3210:7654.3210: bit number per byte * :||||.||||:||||.||||:||||.||||:||||.||||: * :3322.2222:2222.1111:1111.1100:0000.0000: bit number * :1098.7654:3210.9876:5432.1098:7654.3210: 0..31 * :||||.||||:||||.||||:||||.||||:||||.||||: * :8421.8421:8421.8421:8421.8421:8421.8421:hex digit * * * * AIO / RayDAT only * * ------------ HDSPM_WR_SETTINGS ---------- * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte * :1098.7654:3210.9876:5432.1098:7654.3210: * :||||.||||:||||.||||:||||.||||:||||.||||: bit number * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31 * :||||.||||:||||.||||:||||.||||:||||.||||: * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit * : . : . : . : . x: HDSPM_c0Master 1: Master, 0: Slave * : . : . : . : . x : HDSPM_c0_SyncRef0 * : . : . : . : . x : HDSPM_c0_SyncRef1 * : . : . : . : .x : HDSPM_c0_SyncRef2 * : . : . : . : x. : HDSPM_c0_SyncRef3 * : . : . : . : 3.210 : HDSPM_c0_SyncRefMask: * : . : . : . : . : RayDat: 0:WC, 1:AES, 2:SPDIF, 3..6: ADAT1..4, * : . : . : . : . : 9:TCO, 10:SyncIn * : . : . : . : . : AIO: 0:WC, 1:AES, 2: SPDIF, 3: ATAT, * : . : . : . : . : 9:TCO, 10:SyncIn * : . : . : . : . : * : . : . : . : . : * :3322.2222:2222.1111:1111.1100:0000.0000: bit number per byte * :1098.7654:3210.9876:5432.1098:7654.3210: * :||||.||||:||||.||||:||||.||||:||||.||||: bit number * :7654.3210:7654.3210:7654.3210:7654.3210: 0..31 * :||||.||||:||||.||||:||||.||||:||||.||||: * :8421.8421:8421.8421:8421.8421:8421.8421: hex digit * */ #include <linux/init.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/pci.h> #include <linux/math64.h> #include <linux/io.h> #include <linux/nospec.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/info.h> #include <sound/asoundef.h> #include <sound/rawmidi.h> #include <sound/hwdep.h> #include <sound/initval.h> #include <sound/hdspm.h> static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for RME HDSPM interface."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for RME HDSPM interface."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards."); MODULE_AUTHOR ( "Winfried Ritsch <ritsch_AT_iem.at>, " "Paul Davis <[email protected]>, " "Marcus Andersson, Thomas Charbonnel <[email protected]>, " "Remy Bruno <[email protected]>, " "Florian Faber <[email protected]>, " "Adrian Knoth <[email protected]>" ); MODULE_DESCRIPTION("RME HDSPM"); MODULE_LICENSE("GPL"); /* --- Write registers. --- These are defined as byte-offsets from the iobase value. */ #define HDSPM_WR_SETTINGS 0 #define HDSPM_outputBufferAddress 32 #define HDSPM_inputBufferAddress 36 #define HDSPM_controlRegister 64 #define HDSPM_interruptConfirmation 96 #define HDSPM_control2Reg 256 /* not in specs ???????? */ #define HDSPM_freqReg 256 /* for setting arbitrary clock values (DDS feature) */ #define HDSPM_midiDataOut0 352 /* just believe in old code */ #define HDSPM_midiDataOut1 356 #define HDSPM_eeprom_wr 384 /* for AES32 */ /* DMA enable for 64 channels, only Bit 0 is relevant */ #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */ #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */ /* 16 page addresses for each of the 64 channels DMA buffer in and out (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */ #define HDSPM_pageAddressBufferOut 8192 #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4) #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */ #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */ /* --- Read registers. --- These are defined as byte-offsets from the iobase value */ #define HDSPM_statusRegister 0 /*#define HDSPM_statusRegister2 96 */ /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at * offset 192, for AES32 *and* MADI * => need to check that offset 192 is working on MADI */ #define HDSPM_statusRegister2 192 #define HDSPM_timecodeRegister 128 /* AIO, RayDAT */ #define HDSPM_RD_STATUS_0 0 #define HDSPM_RD_STATUS_1 64 #define HDSPM_RD_STATUS_2 128 #define HDSPM_RD_STATUS_3 192 #define HDSPM_RD_TCO 256 #define HDSPM_RD_PLL_FREQ 512 #define HDSPM_WR_TCO 128 #define HDSPM_TCO1_TCO_lock 0x00000001 #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002 #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004 #define HDSPM_TCO1_LTC_Input_valid 0x00000008 #define HDSPM_TCO1_WCK_Input_valid 0x00000010 #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020 #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040 #define HDSPM_TCO1_set_TC 0x00000100 #define HDSPM_TCO1_set_drop_frame_flag 0x00000200 #define HDSPM_TCO1_LTC_Format_LSB 0x00000400 #define HDSPM_TCO1_LTC_Format_MSB 0x00000800 #define HDSPM_TCO2_TC_run 0x00010000 #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000 #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000 #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000 #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000 #define HDSPM_TCO2_set_jam_sync 0x00200000 #define HDSPM_TCO2_set_flywheel 0x00400000 #define HDSPM_TCO2_set_01_4 0x01000000 #define HDSPM_TCO2_set_pull_down 0x02000000 #define HDSPM_TCO2_set_pull_up 0x04000000 #define HDSPM_TCO2_set_freq 0x08000000 #define HDSPM_TCO2_set_term_75R 0x10000000 #define HDSPM_TCO2_set_input_LSB 0x20000000 #define HDSPM_TCO2_set_input_MSB 0x40000000 #define HDSPM_TCO2_set_freq_from_app 0x80000000 #define HDSPM_midiDataOut0 352 #define HDSPM_midiDataOut1 356 #define HDSPM_midiDataOut2 368 #define HDSPM_midiDataIn0 360 #define HDSPM_midiDataIn1 364 #define HDSPM_midiDataIn2 372 #define HDSPM_midiDataIn3 376 /* status is data bytes in MIDI-FIFO (0-128) */ #define HDSPM_midiStatusOut0 384 #define HDSPM_midiStatusOut1 388 #define HDSPM_midiStatusOut2 400 #define HDSPM_midiStatusIn0 392 #define HDSPM_midiStatusIn1 396 #define HDSPM_midiStatusIn2 404 #define HDSPM_midiStatusIn3 408 /* the meters are regular i/o-mapped registers, but offset considerably from the rest. the peak registers are reset when read; the least-significant 4 bits are full-scale counters; the actual peak value is in the most-significant 24 bits. */ #define HDSPM_MADI_INPUT_PEAK 4096 #define HDSPM_MADI_PLAYBACK_PEAK 4352 #define HDSPM_MADI_OUTPUT_PEAK 4608 #define HDSPM_MADI_INPUT_RMS_L 6144 #define HDSPM_MADI_PLAYBACK_RMS_L 6400 #define HDSPM_MADI_OUTPUT_RMS_L 6656 #define HDSPM_MADI_INPUT_RMS_H 7168 #define HDSPM_MADI_PLAYBACK_RMS_H 7424 #define HDSPM_MADI_OUTPUT_RMS_H 7680 /* --- Control Register bits --------- */ #define HDSPM_Start (1<<0) /* start engine */ #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */ #define HDSPM_Latency1 (1<<2) /* where n is defined */ #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */ #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */ #define HDSPM_c0Master 0x1 /* Master clock bit in settings register [RayDAT, AIO] */ #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */ #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */ #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */ #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */ #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */ #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */ #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1, 56channelMODE=0 */ /* MADI ONLY*/ #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */ #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode, 0=off, 1=on */ /* MADI ONLY */ #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax * -- MADI ONLY */ #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ #define HDSPM_SyncRef2 (1<<13) #define HDSPM_SyncRef3 (1<<25) #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */ #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use AES additional bits in lower 5 Audiodatabits ??? */ #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */ #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */ #define HDSPM_Midi0InterruptEnable 0x0400000 #define HDSPM_Midi1InterruptEnable 0x0800000 #define HDSPM_Midi2InterruptEnable 0x0200000 #define HDSPM_Midi3InterruptEnable 0x4000000 #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */ #define HDSPe_FLOAT_FORMAT 0x2000000 #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */ #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */ #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */ #define HDSPM_wclk_sel (1<<30) /* additional control register bits for AIO*/ #define HDSPM_c0_Wck48 0x20 /* also RayDAT */ #define HDSPM_c0_Input0 0x1000 #define HDSPM_c0_Input1 0x2000 #define HDSPM_c0_Spdif_Opt 0x4000 #define HDSPM_c0_Pro 0x8000 #define HDSPM_c0_clr_tms 0x10000 #define HDSPM_c0_AEB1 0x20000 #define HDSPM_c0_AEB2 0x40000 #define HDSPM_c0_LineOut 0x80000 #define HDSPM_c0_AD_GAIN0 0x100000 #define HDSPM_c0_AD_GAIN1 0x200000 #define HDSPM_c0_DA_GAIN0 0x400000 #define HDSPM_c0_DA_GAIN1 0x800000 #define HDSPM_c0_PH_GAIN0 0x1000000 #define HDSPM_c0_PH_GAIN1 0x2000000 #define HDSPM_c0_Sym6db 0x4000000 /* --- bit helper defines */ #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\ HDSPM_DoubleSpeed|HDSPM_QuadSpeed) #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) #define HDSPM_InputOptical 0 #define HDSPM_InputCoaxial (HDSPM_InputSelect0) #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\ HDSPM_SyncRef2|HDSPM_SyncRef3) #define HDSPM_c0_SyncRef0 0x2 #define HDSPM_c0_SyncRef1 0x4 #define HDSPM_c0_SyncRef2 0x8 #define HDSPM_c0_SyncRef3 0x10 #define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\ HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3) #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */ #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */ #define HDSPM_SYNC_FROM_TCO 2 #define HDSPM_SYNC_FROM_SYNC_IN 3 #define HDSPM_Frequency32KHz HDSPM_Frequency0 #define HDSPM_Frequency44_1KHz HDSPM_Frequency1 #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0) #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0) #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1) #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\ HDSPM_Frequency0) #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\ HDSPM_Frequency0) /* Synccheck Status */ #define HDSPM_SYNC_CHECK_NO_LOCK 0 #define HDSPM_SYNC_CHECK_LOCK 1 #define HDSPM_SYNC_CHECK_SYNC 2 /* AutoSync References - used by "autosync_ref" control switch */ #define HDSPM_AUTOSYNC_FROM_WORD 0 #define HDSPM_AUTOSYNC_FROM_MADI 1 #define HDSPM_AUTOSYNC_FROM_TCO 2 #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3 #define HDSPM_AUTOSYNC_FROM_NONE 4 /* Possible sources of MADI input */ #define HDSPM_OPTICAL 0 /* optical */ #define HDSPM_COAXIAL 1 /* BNC */ #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask) #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1)) #define hdspm_encode_in(x) (((x)&0x3)<<14) #define hdspm_decode_in(x) (((x)>>14)&0x3) /* --- control2 register bits --- */ #define HDSPM_TMS (1<<0) #define HDSPM_TCK (1<<1) #define HDSPM_TDI (1<<2) #define HDSPM_JTAG (1<<3) #define HDSPM_PWDN (1<<4) #define HDSPM_PROGRAM (1<<5) #define HDSPM_CONFIG_MODE_0 (1<<6) #define HDSPM_CONFIG_MODE_1 (1<<7) /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/ #define HDSPM_BIGENDIAN_MODE (1<<9) #define HDSPM_RD_MULTIPLE (1<<10) /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and that do not conflict with specific bits for AES32 seem to be valid also for the AES32 */ #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */ #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 * (like inp0) */ #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ #define HDSPM_madiSync (1<<18) /* MADI is in sync */ #define HDSPM_tcoLockMadi 0x00000020 /* Optional TCO locked status for HDSPe MADI*/ #define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status for HDSPe MADI and AES32!*/ #define HDSPM_syncInLock 0x00010000 /* Sync In lock status for HDSPe MADI! */ #define HDSPM_syncInSync 0x00020000 /* Sync In sync status for HDSPe MADI! */ #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ /* since 64byte accurate, last 6 bits are not used */ #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */ #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */ #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */ #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */ #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */ #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with * Interrupt */ #define HDSPM_tco_detect 0x08000000 #define HDSPM_tcoLockAes 0x20000000 /* Optional TCO locked status for HDSPe AES */ #define HDSPM_s2_tco_detect 0x00000040 #define HDSPM_s2_AEBO_D 0x00000080 #define HDSPM_s2_AEBI_D 0x00000100 #define HDSPM_midi0IRQPending 0x40000000 #define HDSPM_midi1IRQPending 0x80000000 #define HDSPM_midi2IRQPending 0x20000000 #define HDSPM_midi2IRQPendingAES 0x00000020 #define HDSPM_midi3IRQPending 0x00200000 /* --- status bit helpers */ #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\ HDSPM_madiFreq2|HDSPM_madiFreq3) #define HDSPM_madiFreq32 (HDSPM_madiFreq0) #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1) #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1) #define HDSPM_madiFreq64 (HDSPM_madiFreq2) #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2) #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2) #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2) #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3) #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0) /* Status2 Register bits */ /* MADI ONLY */ #define HDSPM_version0 (1<<0) /* not really defined but I guess */ #define HDSPM_version1 (1<<1) /* in former cards it was ??? */ #define HDSPM_version2 (1<<2) #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */ #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */ #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */ #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */ #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, 111=128 */ #define HDSPM_wc_freq3 0x800 /* 1000=176.4, 1001=192 */ #define HDSPM_SyncRef0 0x10000 /* Sync Reference */ #define HDSPM_SyncRef1 0x20000 #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */ #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */ #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */ #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync) #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\ HDSPM_wc_freq3) #define HDSPM_wcFreq32 (HDSPM_wc_freq0) #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1) #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1) #define HDSPM_wcFreq64 (HDSPM_wc_freq2) #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2) #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2) #define HDSPM_wcFreq128 (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2) #define HDSPM_wcFreq176_4 (HDSPM_wc_freq3) #define HDSPM_wcFreq192 (HDSPM_wc_freq0|HDSPM_wc_freq3) #define HDSPM_status1_F_0 0x0400000 #define HDSPM_status1_F_1 0x0800000 #define HDSPM_status1_F_2 0x1000000 #define HDSPM_status1_F_3 0x2000000 #define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3) #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ HDSPM_SelSyncRef2) #define HDSPM_SelSyncRef_WORD 0 #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1) #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1) #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ HDSPM_SelSyncRef2) /* For AES32, bits for status, status2 and timecode are different */ /* status */ #define HDSPM_AES32_wcLock 0x0200000 #define HDSPM_AES32_wcSync 0x0100000 #define HDSPM_AES32_wcFreq_bit 22 /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function HDSPM_bit2freq */ #define HDSPM_AES32_syncref_bit 16 /* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */ #define HDSPM_AES32_AUTOSYNC_FROM_WORD 0 #define HDSPM_AES32_AUTOSYNC_FROM_AES1 1 #define HDSPM_AES32_AUTOSYNC_FROM_AES2 2 #define HDSPM_AES32_AUTOSYNC_FROM_AES3 3 #define HDSPM_AES32_AUTOSYNC_FROM_AES4 4 #define HDSPM_AES32_AUTOSYNC_FROM_AES5 5 #define HDSPM_AES32_AUTOSYNC_FROM_AES6 6 #define HDSPM_AES32_AUTOSYNC_FROM_AES7 7 #define HDSPM_AES32_AUTOSYNC_FROM_AES8 8 #define HDSPM_AES32_AUTOSYNC_FROM_TCO 9 #define HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN 10 #define HDSPM_AES32_AUTOSYNC_FROM_NONE 11 /* status2 */ /* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */ #define HDSPM_LockAES 0x80 #define HDSPM_LockAES1 0x80 #define HDSPM_LockAES2 0x40 #define HDSPM_LockAES3 0x20 #define HDSPM_LockAES4 0x10 #define HDSPM_LockAES5 0x8 #define HDSPM_LockAES6 0x4 #define HDSPM_LockAES7 0x2 #define HDSPM_LockAES8 0x1 /* Timecode After windows driver sources, bits 4*i to 4*i+3 give the input frequency on AES i+1 bits 3210 0001 32kHz 0010 44.1kHz 0011 48kHz 0100 64kHz 0101 88.2kHz 0110 96kHz 0111 128kHz 1000 176.4kHz 1001 192kHz NB: Timecode register doesn't seem to work on AES32 card revision 230 */ /* Mixer Values */ #define UNITY_GAIN 32768 /* = 65536/2 */ #define MINUS_INFINITY_GAIN 0 /* Number of channels for different Speed Modes */ #define MADI_SS_CHANNELS 64 #define MADI_DS_CHANNELS 32 #define MADI_QS_CHANNELS 16 #define RAYDAT_SS_CHANNELS 36 #define RAYDAT_DS_CHANNELS 20 #define RAYDAT_QS_CHANNELS 12 #define AIO_IN_SS_CHANNELS 14 #define AIO_IN_DS_CHANNELS 10 #define AIO_IN_QS_CHANNELS 8 #define AIO_OUT_SS_CHANNELS 16 #define AIO_OUT_DS_CHANNELS 12 #define AIO_OUT_QS_CHANNELS 10 #define AES32_CHANNELS 16 /* the size of a substream (1 mono data stream) */ #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024) #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES) /* the size of the area we need to allocate for DMA transfers. the size is the same regardless of the number of channels, and also the latency to use. for one direction !!! */ #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES) #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024) #define HDSPM_RAYDAT_REV 211 #define HDSPM_AIO_REV 212 #define HDSPM_MADIFACE_REV 213 /* speed factor modes */ #define HDSPM_SPEED_SINGLE 0 #define HDSPM_SPEED_DOUBLE 1 #define HDSPM_SPEED_QUAD 2 /* names for speed modes */ static const char * const hdspm_speed_names[] = { "single", "double", "quad" }; static const char *const texts_autosync_aes_tco[] = { "Word Clock", "AES1", "AES2", "AES3", "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In" }; static const char *const texts_autosync_aes[] = { "Word Clock", "AES1", "AES2", "AES3", "AES4", "AES5", "AES6", "AES7", "AES8", "Sync In" }; static const char *const texts_autosync_madi_tco[] = { "Word Clock", "MADI", "TCO", "Sync In" }; static const char *const texts_autosync_madi[] = { "Word Clock", "MADI", "Sync In" }; static const char *const texts_autosync_raydat_tco[] = { "Word Clock", "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", "AES", "SPDIF", "TCO", "Sync In" }; static const char *const texts_autosync_raydat[] = { "Word Clock", "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", "AES", "SPDIF", "Sync In" }; static const char *const texts_autosync_aio_tco[] = { "Word Clock", "ADAT", "AES", "SPDIF", "TCO", "Sync In" }; static const char *const texts_autosync_aio[] = { "Word Clock", "ADAT", "AES", "SPDIF", "Sync In" }; static const char *const texts_freq[] = { "No Lock", "32 kHz", "44.1 kHz", "48 kHz", "64 kHz", "88.2 kHz", "96 kHz", "128 kHz", "176.4 kHz", "192 kHz" }; static const char * const texts_ports_madi[] = { "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6", "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12", "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18", "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24", "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30", "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36", "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42", "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48", "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54", "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60", "MADI.61", "MADI.62", "MADI.63", "MADI.64", }; static const char * const texts_ports_raydat_ss[] = { "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6", "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8", "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6", "ADAT4.7", "ADAT4.8", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R" }; static const char * const texts_ports_raydat_ds[] = { "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R" }; static const char * const texts_ports_raydat_qs[] = { "ADAT1.1", "ADAT1.2", "ADAT2.1", "ADAT2.2", "ADAT3.1", "ADAT3.2", "ADAT4.1", "ADAT4.2", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R" }; static const char * const texts_ports_aio_in_ss[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", "ADAT.7", "ADAT.8", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aio_out_ss[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", "ADAT.7", "ADAT.8", "Phone.L", "Phone.R", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aio_in_ds[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aio_out_ds[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "Phone.L", "Phone.R", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aio_in_qs[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aio_out_qs[] = { "Analogue.L", "Analogue.R", "AES.L", "AES.R", "SPDIF.L", "SPDIF.R", "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "Phone.L", "Phone.R", "AEB.1", "AEB.2", "AEB.3", "AEB.4" }; static const char * const texts_ports_aes32[] = { "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7", "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14", "AES.15", "AES.16" }; /* These tables map the ALSA channels 1..N to the channels that we need to use in order to find the relevant channel buffer. RME refers to this kind of mapping as between "the ADAT channel and the DMA channel." We index it using the logical audio channel, and the value is the DMA channel (i.e. channel buffer number) where the data for that channel can be read/written from/to. */ static const char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 }; static const char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */ 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */ 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */ 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */ 0, 1, /* AES */ 2, 3, /* SPDIF */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { 4, 5, 6, 7, /* ADAT 1 */ 8, 9, 10, 11, /* ADAT 2 */ 12, 13, 14, 15, /* ADAT 3 */ 16, 17, 18, 19, /* ADAT 4 */ 0, 1, /* AES */ 2, 3, /* SPDIF */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { 4, 5, /* ADAT 1 */ 6, 7, /* ADAT 2 */ 8, 9, /* ADAT 3 */ 10, 11, /* ADAT 4 */ 0, 1, /* AES */ 2, 3, /* SPDIF */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in, */ 10, 11, /* spdif in */ 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */ 6, 7, /* phone out */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static const char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in */ 10, 11, /* spdif in */ 12, 14, 16, 18, /* adat in */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ 12, 14, 16, 18, /* adat out */ 6, 7, /* phone out */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { 0, 1, /* line in */ 8, 9, /* aes in */ 10, 11, /* spdif in */ 12, 16, /* adat in */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { 0, 1, /* line out */ 8, 9, /* aes out */ 10, 11, /* spdif out */ 12, 16, /* adat out */ 6, 7, /* phone out */ 2, 3, 4, 5, /* AEB */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const char channel_map_aes32[HDSPM_MAX_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; struct hdspm_midi { struct hdspm *hdspm; int id; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *input; struct snd_rawmidi_substream *output; char istimer; /* timer in use */ struct timer_list timer; spinlock_t lock; int pending; int dataIn; int statusIn; int dataOut; int statusOut; int ie; int irq; }; struct hdspm_tco { int input; /* 0: LTC, 1:Video, 2: WC*/ int framerate; /* 0=24, 1=25, 2=29.97, 3=29.97d, 4=30, 5=30d */ int wordclock; /* 0=1:1, 1=44.1->48, 2=48->44.1 */ int samplerate; /* 0=44.1, 1=48, 2= freq from app */ int pull; /* 0=0, 1=+0.1%, 2=-0.1%, 3=+4%, 4=-4%*/ int term; /* 0 = off, 1 = on */ }; struct hdspm { spinlock_t lock; /* only one playback and/or capture stream */ struct snd_pcm_substream *capture_substream; struct snd_pcm_substream *playback_substream; char *card_name; /* for procinfo */ unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ uint8_t io_type; int monitor_outs; /* set up monitoring outs init flag */ u32 control_register; /* cached value */ u32 control2_register; /* cached value */ u32 settings_register; /* cached value for AIO / RayDat (sync reference, master/slave) */ struct hdspm_midi midi[4]; struct work_struct midi_work; size_t period_bytes; unsigned char ss_in_channels; unsigned char ds_in_channels; unsigned char qs_in_channels; unsigned char ss_out_channels; unsigned char ds_out_channels; unsigned char qs_out_channels; unsigned char max_channels_in; unsigned char max_channels_out; const signed char *channel_map_in; const signed char *channel_map_out; const signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; const signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; const char * const *port_names_in; const char * const *port_names_out; const char * const *port_names_in_ss; const char * const *port_names_in_ds; const char * const *port_names_in_qs; const char * const *port_names_out_ss; const char * const *port_names_out_ds; const char * const *port_names_out_qs; unsigned char *playback_buffer; /* suitably aligned address */ unsigned char *capture_buffer; /* suitably aligned address */ pid_t capture_pid; /* process id which uses capture */ pid_t playback_pid; /* process id which uses capture */ int running; /* running status */ int last_external_sample_rate; /* samplerate mystic ... */ int last_internal_sample_rate; int system_sample_rate; int dev; /* Hardware vars... */ int irq; unsigned long port; void __iomem *iobase; int irq_count; /* for debug */ int midiPorts; struct snd_card *card; /* one card */ struct snd_pcm *pcm; /* has one pcm */ struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */ struct pci_dev *pci; /* and an pci info */ /* Mixer vars */ /* fast alsa mixer */ struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; /* but input to much, so not used */ struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; /* full mixer accessible over mixer ioctl or hwdep-device */ struct hdspm_mixer *mixer; struct hdspm_tco *tco; /* NULL if no TCO detected */ const char *const *texts_autosync; int texts_autosync_items; cycles_t last_interrupt; unsigned int serial; struct hdspm_peak_rms peak_rms; }; static const struct pci_device_id snd_hdspm_ids[] = { { .vendor = PCI_VENDOR_ID_XILINX, .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, .class = 0, .class_mask = 0, .driver_data = 0}, {0,} }; MODULE_DEVICE_TABLE(pci, snd_hdspm_ids); /* prototypes */ static int snd_hdspm_create_alsa_devices(struct snd_card *card, struct hdspm *hdspm); static int snd_hdspm_create_pcm(struct snd_card *card, struct hdspm *hdspm); static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm); static inline int hdspm_get_pll_freq(struct hdspm *hdspm); static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm); static int hdspm_autosync_ref(struct hdspm *hdspm); static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out); static int snd_hdspm_set_defaults(struct hdspm *hdspm); static int hdspm_system_clock_mode(struct hdspm *hdspm); static void hdspm_set_channel_dma_addr(struct hdspm *hdspm, struct snd_pcm_substream *substream, unsigned int reg, int channels); static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx); static int hdspm_wc_sync_check(struct hdspm *hdspm); static int hdspm_tco_sync_check(struct hdspm *hdspm); static int hdspm_sync_in_sync_check(struct hdspm *hdspm); static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index); static int hdspm_get_tco_sample_rate(struct hdspm *hdspm); static int hdspm_get_wc_sample_rate(struct hdspm *hdspm); static inline int HDSPM_bit2freq(int n) { static const int bit2freq_tab[] = { 0, 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 }; if (n < 1 || n > 9) return 0; return bit2freq_tab[n]; } static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm) { return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type)); } /* Write/read to/from HDSPM with Adresses in Bytes not words but only 32Bit writes are allowed */ static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg, unsigned int val) { writel(val, hdspm->iobase + reg); } static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg) { return readl(hdspm->iobase + reg); } /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader mixer is write only on hardware so we have to cache him for read each fader is a u32, but uses only the first 16 bit */ static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan, unsigned int in) { if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) return 0; return hdspm->mixer->ch[chan].in[in]; } static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan, unsigned int pb) { if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) return 0; return hdspm->mixer->ch[chan].pb[pb]; } static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan, unsigned int in, unsigned short data) { if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) return -1; hdspm_write(hdspm, HDSPM_MADI_mixerBase + ((in + 128 * chan) * sizeof(u32)), (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF)); return 0; } static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan, unsigned int pb, unsigned short data) { if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) return -1; hdspm_write(hdspm, HDSPM_MADI_mixerBase + ((64 + pb + 128 * chan) * sizeof(u32)), (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF)); return 0; } /* enable DMA for specific channels, now available for DSP-MADI */ static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v) { hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v); } static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v) { hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v); } /* check if same process is writing and reading */ static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm) { unsigned long flags; int ret = 1; spin_lock_irqsave(&hdspm->lock, flags); if ((hdspm->playback_pid != hdspm->capture_pid) && (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) { ret = 0; } spin_unlock_irqrestore(&hdspm->lock, flags); return ret; } /* round arbitrary sample rates to commonly known rates */ static int hdspm_round_frequency(int rate) { if (rate < 38050) return 32000; if (rate < 46008) return 44100; else return 48000; } /* QS and DS rates normally can not be detected * automatically by the card. Only exception is MADI * in 96k frame mode. * * So if we read SS values (32 .. 48k), check for * user-provided DS/QS bits in the control register * and multiply the base frequency accordingly. */ static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate) { if (rate <= 48000) { if (hdspm->control_register & HDSPM_QuadSpeed) return rate * 4; else if (hdspm->control_register & HDSPM_DoubleSpeed) return rate * 2; } return rate; } /* check for external sample rate, returns the sample rate in Hz*/ static int hdspm_external_sample_rate(struct hdspm *hdspm) { unsigned int status, status2; int syncref, rate = 0, rate_bits; switch (hdspm->io_type) { case AES32: status2 = hdspm_read(hdspm, HDSPM_statusRegister2); status = hdspm_read(hdspm, HDSPM_statusRegister); syncref = hdspm_autosync_ref(hdspm); switch (syncref) { case HDSPM_AES32_AUTOSYNC_FROM_WORD: /* Check WC sync and get sample rate */ if (hdspm_wc_sync_check(hdspm)) return HDSPM_bit2freq(hdspm_get_wc_sample_rate(hdspm)); break; case HDSPM_AES32_AUTOSYNC_FROM_AES1: case HDSPM_AES32_AUTOSYNC_FROM_AES2: case HDSPM_AES32_AUTOSYNC_FROM_AES3: case HDSPM_AES32_AUTOSYNC_FROM_AES4: case HDSPM_AES32_AUTOSYNC_FROM_AES5: case HDSPM_AES32_AUTOSYNC_FROM_AES6: case HDSPM_AES32_AUTOSYNC_FROM_AES7: case HDSPM_AES32_AUTOSYNC_FROM_AES8: /* Check AES sync and get sample rate */ if (hdspm_aes_sync_check(hdspm, syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1)) return HDSPM_bit2freq(hdspm_get_aes_sample_rate(hdspm, syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1)); break; case HDSPM_AES32_AUTOSYNC_FROM_TCO: /* Check TCO sync and get sample rate */ if (hdspm_tco_sync_check(hdspm)) return HDSPM_bit2freq(hdspm_get_tco_sample_rate(hdspm)); break; default: return 0; } /* end switch(syncref) */ break; case MADIface: status = hdspm_read(hdspm, HDSPM_statusRegister); if (!(status & HDSPM_madiLock)) { rate = 0; /* no lock */ } else { switch (status & (HDSPM_status1_freqMask)) { case HDSPM_status1_F_0*1: rate = 32000; break; case HDSPM_status1_F_0*2: rate = 44100; break; case HDSPM_status1_F_0*3: rate = 48000; break; case HDSPM_status1_F_0*4: rate = 64000; break; case HDSPM_status1_F_0*5: rate = 88200; break; case HDSPM_status1_F_0*6: rate = 96000; break; case HDSPM_status1_F_0*7: rate = 128000; break; case HDSPM_status1_F_0*8: rate = 176400; break; case HDSPM_status1_F_0*9: rate = 192000; break; default: rate = 0; break; } } break; case MADI: case AIO: case RayDAT: status2 = hdspm_read(hdspm, HDSPM_statusRegister2); status = hdspm_read(hdspm, HDSPM_statusRegister); rate = 0; /* if wordclock has synced freq and wordclock is valid */ if ((status2 & HDSPM_wcLock) != 0 && (status2 & HDSPM_SelSyncRef0) == 0) { rate_bits = status2 & HDSPM_wcFreqMask; switch (rate_bits) { case HDSPM_wcFreq32: rate = 32000; break; case HDSPM_wcFreq44_1: rate = 44100; break; case HDSPM_wcFreq48: rate = 48000; break; case HDSPM_wcFreq64: rate = 64000; break; case HDSPM_wcFreq88_2: rate = 88200; break; case HDSPM_wcFreq96: rate = 96000; break; case HDSPM_wcFreq128: rate = 128000; break; case HDSPM_wcFreq176_4: rate = 176400; break; case HDSPM_wcFreq192: rate = 192000; break; default: rate = 0; break; } } /* if rate detected and Syncref is Word than have it, * word has priority to MADI */ if (rate != 0 && (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) return hdspm_rate_multiplier(hdspm, rate); /* maybe a madi input (which is taken if sel sync is madi) */ if (status & HDSPM_madiLock) { rate_bits = status & HDSPM_madiFreqMask; switch (rate_bits) { case HDSPM_madiFreq32: rate = 32000; break; case HDSPM_madiFreq44_1: rate = 44100; break; case HDSPM_madiFreq48: rate = 48000; break; case HDSPM_madiFreq64: rate = 64000; break; case HDSPM_madiFreq88_2: rate = 88200; break; case HDSPM_madiFreq96: rate = 96000; break; case HDSPM_madiFreq128: rate = 128000; break; case HDSPM_madiFreq176_4: rate = 176400; break; case HDSPM_madiFreq192: rate = 192000; break; default: rate = 0; break; } } /* endif HDSPM_madiLock */ /* check sample rate from TCO or SYNC_IN */ { bool is_valid_input = 0; bool has_sync = 0; syncref = hdspm_autosync_ref(hdspm); if (HDSPM_AUTOSYNC_FROM_TCO == syncref) { is_valid_input = 1; has_sync = (HDSPM_SYNC_CHECK_SYNC == hdspm_tco_sync_check(hdspm)); } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) { is_valid_input = 1; has_sync = (HDSPM_SYNC_CHECK_SYNC == hdspm_sync_in_sync_check(hdspm)); } if (is_valid_input && has_sync) { rate = hdspm_round_frequency( hdspm_get_pll_freq(hdspm)); } } rate = hdspm_rate_multiplier(hdspm, rate); break; } return rate; } /* return latency in samples per period */ static int hdspm_get_latency(struct hdspm *hdspm) { int n; n = hdspm_decode_latency(hdspm->control_register); /* Special case for new RME cards with 32 samples period size. * The three latency bits in the control register * (HDSP_LatencyMask) encode latency values of 64 samples as * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7 * denotes 8192 samples, but on new cards like RayDAT or AIO, * it corresponds to 32 samples. */ if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type)) n = -1; return 1 << (n + 6); } /* Latency function */ static inline void hdspm_compute_period_size(struct hdspm *hdspm) { hdspm->period_bytes = 4 * hdspm_get_latency(hdspm); } static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm) { int position; position = hdspm_read(hdspm, HDSPM_statusRegister); switch (hdspm->io_type) { case RayDAT: case AIO: position &= HDSPM_BufferPositionMask; position /= 4; /* Bytes per sample */ break; default: position = (position & HDSPM_BufferID) ? (hdspm->period_bytes / 4) : 0; } return position; } static inline void hdspm_start_audio(struct hdspm * s) { s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start); hdspm_write(s, HDSPM_controlRegister, s->control_register); } static inline void hdspm_stop_audio(struct hdspm * s) { s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable); hdspm_write(s, HDSPM_controlRegister, s->control_register); } /* should I silence all or only opened ones ? doit all for first even is 4MB*/ static void hdspm_silence_playback(struct hdspm *hdspm) { int i; int n = hdspm->period_bytes; void *buf = hdspm->playback_buffer; if (!buf) return; for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { memset(buf, 0, n); buf += HDSPM_CHANNEL_BUFFER_BYTES; } } static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) { int n; spin_lock_irq(&s->lock); if (32 == frames) { /* Special case for new RME cards like RayDAT/AIO which * support period sizes of 32 samples. Since latency is * encoded in the three bits of HDSP_LatencyMask, we can only * have values from 0 .. 7. While 0 still means 64 samples and * 6 represents 4096 samples on all cards, 7 represents 8192 * on older cards and 32 samples on new cards. * * In other words, period size in samples is calculated by * 2^(n+6) with n ranging from 0 .. 7. */ n = 7; } else { frames >>= 7; n = 0; while (frames) { n++; frames >>= 1; } } s->control_register &= ~HDSPM_LatencyMask; s->control_register |= hdspm_encode_latency(n); hdspm_write(s, HDSPM_controlRegister, s->control_register); hdspm_compute_period_size(s); spin_unlock_irq(&s->lock); return 0; } static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period) { u64 freq_const; if (period == 0) return 0; switch (hdspm->io_type) { case MADI: case AES32: freq_const = 110069313433624ULL; break; case RayDAT: case AIO: freq_const = 104857600000000ULL; break; case MADIface: freq_const = 131072000000000ULL; break; default: snd_BUG(); return 0; } return div_u64(freq_const, period); } static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) { u64 n; if (snd_BUG_ON(rate <= 0)) return; if (rate >= 112000) rate /= 4; else if (rate >= 56000) rate /= 2; switch (hdspm->io_type) { case MADIface: n = 131072000000000ULL; /* 125 MHz */ break; case MADI: case AES32: n = 110069313433624ULL; /* 105 MHz */ break; case RayDAT: case AIO: n = 104857600000000ULL; /* 100 MHz */ break; default: snd_BUG(); return; } n = div_u64(n, rate); /* n should be less than 2^32 for being written to FREQ register */ snd_BUG_ON(n >> 32); hdspm_write(hdspm, HDSPM_freqReg, (u32)n); } /* dummy set rate lets see what happens */ static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) { int current_rate; int rate_bits; int not_set = 0; int current_speed, target_speed; /* ASSUMPTION: hdspm->lock is either set, or there is no need for it (e.g. during module initialization). */ if (!(hdspm->control_register & HDSPM_ClockModeMaster)) { /* SLAVE --- */ if (called_internally) { /* request from ctl or card initialization just make a warning an remember setting for future master mode switching */ dev_warn(hdspm->card->dev, "Warning: device is not running as a clock master.\n"); not_set = 1; } else { /* hw_param request while in AutoSync mode */ int external_freq = hdspm_external_sample_rate(hdspm); if (hdspm_autosync_ref(hdspm) == HDSPM_AUTOSYNC_FROM_NONE) { dev_warn(hdspm->card->dev, "Detected no External Sync\n"); not_set = 1; } else if (rate != external_freq) { dev_warn(hdspm->card->dev, "Warning: No AutoSync source for requested rate\n"); not_set = 1; } } } current_rate = hdspm->system_sample_rate; /* Changing between Singe, Double and Quad speed is not allowed if any substreams are open. This is because such a change causes a shift in the location of the DMA buffers and a reduction in the number of available buffers. Note that a similar but essentially insoluble problem exists for externally-driven rate changes. All we can do is to flag rate changes in the read/write routines. */ if (current_rate <= 48000) current_speed = HDSPM_SPEED_SINGLE; else if (current_rate <= 96000) current_speed = HDSPM_SPEED_DOUBLE; else current_speed = HDSPM_SPEED_QUAD; if (rate <= 48000) target_speed = HDSPM_SPEED_SINGLE; else if (rate <= 96000) target_speed = HDSPM_SPEED_DOUBLE; else target_speed = HDSPM_SPEED_QUAD; switch (rate) { case 32000: rate_bits = HDSPM_Frequency32KHz; break; case 44100: rate_bits = HDSPM_Frequency44_1KHz; break; case 48000: rate_bits = HDSPM_Frequency48KHz; break; case 64000: rate_bits = HDSPM_Frequency64KHz; break; case 88200: rate_bits = HDSPM_Frequency88_2KHz; break; case 96000: rate_bits = HDSPM_Frequency96KHz; break; case 128000: rate_bits = HDSPM_Frequency128KHz; break; case 176400: rate_bits = HDSPM_Frequency176_4KHz; break; case 192000: rate_bits = HDSPM_Frequency192KHz; break; default: return -EINVAL; } if (current_speed != target_speed && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { dev_err(hdspm->card->dev, "cannot change from %s speed to %s speed mode (capture PID = %d, playback PID = %d)\n", hdspm_speed_names[current_speed], hdspm_speed_names[target_speed], hdspm->capture_pid, hdspm->playback_pid); return -EBUSY; } hdspm->control_register &= ~HDSPM_FrequencyMask; hdspm->control_register |= rate_bits; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); /* For AES32, need to set DDS value in FREQ register For MADI, also apparently */ hdspm_set_dds_value(hdspm, rate); if (AES32 == hdspm->io_type && rate != current_rate) hdspm_write(hdspm, HDSPM_eeprom_wr, 0); hdspm->system_sample_rate = rate; if (rate <= 48000) { hdspm->channel_map_in = hdspm->channel_map_in_ss; hdspm->channel_map_out = hdspm->channel_map_out_ss; hdspm->max_channels_in = hdspm->ss_in_channels; hdspm->max_channels_out = hdspm->ss_out_channels; hdspm->port_names_in = hdspm->port_names_in_ss; hdspm->port_names_out = hdspm->port_names_out_ss; } else if (rate <= 96000) { hdspm->channel_map_in = hdspm->channel_map_in_ds; hdspm->channel_map_out = hdspm->channel_map_out_ds; hdspm->max_channels_in = hdspm->ds_in_channels; hdspm->max_channels_out = hdspm->ds_out_channels; hdspm->port_names_in = hdspm->port_names_in_ds; hdspm->port_names_out = hdspm->port_names_out_ds; } else { hdspm->channel_map_in = hdspm->channel_map_in_qs; hdspm->channel_map_out = hdspm->channel_map_out_qs; hdspm->max_channels_in = hdspm->qs_in_channels; hdspm->max_channels_out = hdspm->qs_out_channels; hdspm->port_names_in = hdspm->port_names_in_qs; hdspm->port_names_out = hdspm->port_names_out_qs; } if (not_set != 0) return -1; return 0; } /* mainly for init to 0 on load */ static void all_in_all_mixer(struct hdspm * hdspm, int sgain) { int i, j; unsigned int gain; if (sgain > UNITY_GAIN) gain = UNITY_GAIN; else if (sgain < 0) gain = 0; else gain = sgain; for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { hdspm_write_in_gain(hdspm, i, j, gain); hdspm_write_pb_gain(hdspm, i, j, gain); } } /*---------------------------------------------------------------------------- MIDI ----------------------------------------------------------------------------*/ static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, int id) { /* the hardware already does the relevant bit-mask with 0xff */ return hdspm_read(hdspm, hdspm->midi[id].dataIn); } static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, int val) { /* the hardware already does the relevant bit-mask with 0xff */ return hdspm_write(hdspm, hdspm->midi[id].dataOut, val); } static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) { return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF; } static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) { int fifo_bytes_used; fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF; if (fifo_bytes_used < 128) return 128 - fifo_bytes_used; else return 0; } static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) { while (snd_hdspm_midi_input_available (hdspm, id)) snd_hdspm_midi_read_byte (hdspm, id); } static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) { unsigned long flags; int n_pending; int to_write; int i; unsigned char buf[128]; /* Output is not interrupt driven */ spin_lock_irqsave (&hmidi->lock, flags); if (hmidi->output && !snd_rawmidi_transmit_empty (hmidi->output)) { n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, hmidi->id); if (n_pending > 0) { if (n_pending > (int)sizeof (buf)) n_pending = sizeof (buf); to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending); if (to_write > 0) { for (i = 0; i < to_write; ++i) snd_hdspm_midi_write_byte (hmidi->hdspm, hmidi->id, buf[i]); } } } spin_unlock_irqrestore (&hmidi->lock, flags); return 0; } static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) { unsigned char buf[128]; /* this buffer is designed to match the MIDI * input FIFO size */ unsigned long flags; int n_pending; int i; spin_lock_irqsave (&hmidi->lock, flags); n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); if (n_pending > 0) { if (hmidi->input) { if (n_pending > (int)sizeof (buf)) n_pending = sizeof (buf); for (i = 0; i < n_pending; ++i) buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id); if (n_pending) snd_rawmidi_receive (hmidi->input, buf, n_pending); } else { /* flush the MIDI input FIFO */ while (n_pending--) snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id); } } hmidi->pending = 0; spin_unlock_irqrestore(&hmidi->lock, flags); spin_lock_irqsave(&hmidi->hdspm->lock, flags); hmidi->hdspm->control_register |= hmidi->ie; hdspm_write(hmidi->hdspm, HDSPM_controlRegister, hmidi->hdspm->control_register); spin_unlock_irqrestore(&hmidi->hdspm->lock, flags); return snd_hdspm_midi_output_write (hmidi); } static void snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdspm *hdspm; struct hdspm_midi *hmidi; unsigned long flags; hmidi = substream->rmidi->private_data; hdspm = hmidi->hdspm; spin_lock_irqsave (&hdspm->lock, flags); if (up) { if (!(hdspm->control_register & hmidi->ie)) { snd_hdspm_flush_midi_input (hdspm, hmidi->id); hdspm->control_register |= hmidi->ie; } } else { hdspm->control_register &= ~hmidi->ie; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); spin_unlock_irqrestore (&hdspm->lock, flags); } static void snd_hdspm_midi_output_timer(struct timer_list *t) { struct hdspm_midi *hmidi = from_timer(hmidi, t, timer); unsigned long flags; snd_hdspm_midi_output_write(hmidi); spin_lock_irqsave (&hmidi->lock, flags); /* this does not bump hmidi->istimer, because the kernel automatically removed the timer when it expired, and we are now adding it back, thus leaving istimer wherever it was set before. */ if (hmidi->istimer) mod_timer(&hmidi->timer, 1 + jiffies); spin_unlock_irqrestore (&hmidi->lock, flags); } static void snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdspm_midi *hmidi; unsigned long flags; hmidi = substream->rmidi->private_data; spin_lock_irqsave (&hmidi->lock, flags); if (up) { if (!hmidi->istimer) { timer_setup(&hmidi->timer, snd_hdspm_midi_output_timer, 0); mod_timer(&hmidi->timer, 1 + jiffies); hmidi->istimer++; } } else { if (hmidi->istimer && --hmidi->istimer <= 0) del_timer (&hmidi->timer); } spin_unlock_irqrestore (&hmidi->lock, flags); if (up) snd_hdspm_midi_output_write(hmidi); } static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) { struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); hmidi->input = substream; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) { struct hdspm_midi *hmidi; hmidi = substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->output = substream; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) { struct hdspm_midi *hmidi; snd_hdspm_midi_input_trigger (substream, 0); hmidi = substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->input = NULL; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) { struct hdspm_midi *hmidi; snd_hdspm_midi_output_trigger (substream, 0); hmidi = substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->output = NULL; spin_unlock_irq (&hmidi->lock); return 0; } static const struct snd_rawmidi_ops snd_hdspm_midi_output = { .open = snd_hdspm_midi_output_open, .close = snd_hdspm_midi_output_close, .trigger = snd_hdspm_midi_output_trigger, }; static const struct snd_rawmidi_ops snd_hdspm_midi_input = { .open = snd_hdspm_midi_input_open, .close = snd_hdspm_midi_input_close, .trigger = snd_hdspm_midi_input_trigger, }; static int snd_hdspm_create_midi(struct snd_card *card, struct hdspm *hdspm, int id) { int err; char buf[64]; hdspm->midi[id].id = id; hdspm->midi[id].hdspm = hdspm; spin_lock_init (&hdspm->midi[id].lock); if (0 == id) { if (MADIface == hdspm->io_type) { /* MIDI-over-MADI on HDSPe MADIface */ hdspm->midi[0].dataIn = HDSPM_midiDataIn2; hdspm->midi[0].statusIn = HDSPM_midiStatusIn2; hdspm->midi[0].dataOut = HDSPM_midiDataOut2; hdspm->midi[0].statusOut = HDSPM_midiStatusOut2; hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable; hdspm->midi[0].irq = HDSPM_midi2IRQPending; } else { hdspm->midi[0].dataIn = HDSPM_midiDataIn0; hdspm->midi[0].statusIn = HDSPM_midiStatusIn0; hdspm->midi[0].dataOut = HDSPM_midiDataOut0; hdspm->midi[0].statusOut = HDSPM_midiStatusOut0; hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable; hdspm->midi[0].irq = HDSPM_midi0IRQPending; } } else if (1 == id) { hdspm->midi[1].dataIn = HDSPM_midiDataIn1; hdspm->midi[1].statusIn = HDSPM_midiStatusIn1; hdspm->midi[1].dataOut = HDSPM_midiDataOut1; hdspm->midi[1].statusOut = HDSPM_midiStatusOut1; hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable; hdspm->midi[1].irq = HDSPM_midi1IRQPending; } else if ((2 == id) && (MADI == hdspm->io_type)) { /* MIDI-over-MADI on HDSPe MADI */ hdspm->midi[2].dataIn = HDSPM_midiDataIn2; hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; hdspm->midi[2].dataOut = HDSPM_midiDataOut2; hdspm->midi[2].statusOut = HDSPM_midiStatusOut2; hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; hdspm->midi[2].irq = HDSPM_midi2IRQPending; } else if (2 == id) { /* TCO MTC, read only */ hdspm->midi[2].dataIn = HDSPM_midiDataIn2; hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; hdspm->midi[2].dataOut = -1; hdspm->midi[2].statusOut = -1; hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES; } else if (3 == id) { /* TCO MTC on HDSPe MADI */ hdspm->midi[3].dataIn = HDSPM_midiDataIn3; hdspm->midi[3].statusIn = HDSPM_midiStatusIn3; hdspm->midi[3].dataOut = -1; hdspm->midi[3].statusOut = -1; hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable; hdspm->midi[3].irq = HDSPM_midi3IRQPending; } if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) || (MADIface == hdspm->io_type)))) { if ((id == 0) && (MADIface == hdspm->io_type)) { snprintf(buf, sizeof(buf), "%s MIDIoverMADI", card->shortname); } else if ((id == 2) && (MADI == hdspm->io_type)) { snprintf(buf, sizeof(buf), "%s MIDIoverMADI", card->shortname); } else { snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id+1); } err = snd_rawmidi_new(card, buf, id, 1, 1, &hdspm->midi[id].rmidi); if (err < 0) return err; snprintf(hdspm->midi[id].rmidi->name, sizeof(hdspm->midi[id].rmidi->name), "%s MIDI %d", card->id, id+1); hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdspm_midi_output); snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdspm_midi_input); hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; } else { /* TCO MTC, read only */ snprintf(buf, sizeof(buf), "%s MTC %d", card->shortname, id+1); err = snd_rawmidi_new(card, buf, id, 1, 1, &hdspm->midi[id].rmidi); if (err < 0) return err; snprintf(hdspm->midi[id].rmidi->name, sizeof(hdspm->midi[id].rmidi->name), "%s MTC %d", card->id, id+1); hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; snd_rawmidi_set_ops(hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdspm_midi_input); hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; } return 0; } static void hdspm_midi_work(struct work_struct *work) { struct hdspm *hdspm = container_of(work, struct hdspm, midi_work); int i = 0; while (i < hdspm->midiPorts) { if (hdspm->midi[i].pending) snd_hdspm_midi_input_read(&hdspm->midi[i]); i++; } } /*----------------------------------------------------------------------------- Status Interface ----------------------------------------------------------------------------*/ /* get the system sample rate which is set */ static inline int hdspm_get_pll_freq(struct hdspm *hdspm) { unsigned int period, rate; period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); rate = hdspm_calc_dds_value(hdspm, period); return rate; } /* * Calculate the real sample rate from the * current DDS value. */ static int hdspm_get_system_sample_rate(struct hdspm *hdspm) { unsigned int rate; rate = hdspm_get_pll_freq(hdspm); if (rate > 207000) { /* Unreasonable high sample rate as seen on PCI MADI cards. */ if (0 == hdspm_system_clock_mode(hdspm)) { /* master mode, return internal sample rate */ rate = hdspm->system_sample_rate; } else { /* slave mode, return external sample rate */ rate = hdspm_external_sample_rate(hdspm); if (!rate) rate = hdspm->system_sample_rate; } } return rate; } #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_system_sample_rate, \ .put = snd_hdspm_put_system_sample_rate, \ .get = snd_hdspm_get_system_sample_rate \ } static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 27000; uinfo->value.integer.max = 207000; uinfo->value.integer.step = 1; return 0; } static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm); return 0; } static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int rate = ucontrol->value.integer.value[0]; if (rate < 27000 || rate > 207000) return -EINVAL; hdspm_set_dds_value(hdspm, ucontrol->value.integer.value[0]); return 0; } /* * Returns the WordClock sample rate class for the given card. */ static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) { int status; switch (hdspm->io_type) { case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); return (status >> 16) & 0xF; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); return (status >> HDSPM_AES32_wcFreq_bit) & 0xF; default: break; } return 0; } /* * Returns the TCO sample rate class for the given card. */ static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) { int status; if (hdspm->tco) { switch (hdspm->io_type) { case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); return (status >> 20) & 0xF; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); return (status >> 1) & 0xF; default: break; } } return 0; } /* * Returns the SYNC_IN sample rate class for the given card. */ static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) { int status; if (hdspm->tco) { switch (hdspm->io_type) { case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); return (status >> 12) & 0xF; default: break; } } return 0; } /* * Returns the AES sample rate class for the given card. */ static int hdspm_get_aes_sample_rate(struct hdspm *hdspm, int index) { int timecode; switch (hdspm->io_type) { case AES32: timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); return (timecode >> (4*index)) & 0xF; default: break; } return 0; } /* * Returns the sample rate class for input source <idx> for * 'new style' cards like the AIO and RayDAT. */ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) { int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); return (status >> (idx*4)) & 0xF; } #define ENUMERATED_CTL_INFO(info, texts) \ snd_ctl_enum_info(info, 1, ARRAY_SIZE(texts), texts) /* Helper function to query the external sample rate and return the * corresponding enum to be returned to userspace. */ static int hdspm_external_rate_to_enum(struct hdspm *hdspm) { int rate = hdspm_external_sample_rate(hdspm); int i, selected_rate = 0; for (i = 1; i < 10; i++) if (HDSPM_bit2freq(i) == rate) { selected_rate = i; break; } return selected_rate; } #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdspm_info_autosync_sample_rate, \ .get = snd_hdspm_get_autosync_sample_rate \ } static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { ENUMERATED_CTL_INFO(uinfo, texts_freq); return 0; } static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value * ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); switch (hdspm->io_type) { case RayDAT: switch (kcontrol->private_value) { case 0: ucontrol->value.enumerated.item[0] = hdspm_get_wc_sample_rate(hdspm); break; case 7: ucontrol->value.enumerated.item[0] = hdspm_get_tco_sample_rate(hdspm); break; case 8: ucontrol->value.enumerated.item[0] = hdspm_get_sync_in_sample_rate(hdspm); break; default: ucontrol->value.enumerated.item[0] = hdspm_get_s1_sample_rate(hdspm, kcontrol->private_value-1); } break; case AIO: switch (kcontrol->private_value) { case 0: /* WC */ ucontrol->value.enumerated.item[0] = hdspm_get_wc_sample_rate(hdspm); break; case 4: /* TCO */ ucontrol->value.enumerated.item[0] = hdspm_get_tco_sample_rate(hdspm); break; case 5: /* SYNC_IN */ ucontrol->value.enumerated.item[0] = hdspm_get_sync_in_sample_rate(hdspm); break; default: ucontrol->value.enumerated.item[0] = hdspm_get_s1_sample_rate(hdspm, kcontrol->private_value-1); } break; case AES32: switch (kcontrol->private_value) { case 0: /* WC */ ucontrol->value.enumerated.item[0] = hdspm_get_wc_sample_rate(hdspm); break; case 9: /* TCO */ ucontrol->value.enumerated.item[0] = hdspm_get_tco_sample_rate(hdspm); break; case 10: /* SYNC_IN */ ucontrol->value.enumerated.item[0] = hdspm_get_sync_in_sample_rate(hdspm); break; case 11: /* External Rate */ ucontrol->value.enumerated.item[0] = hdspm_external_rate_to_enum(hdspm); break; default: /* AES1 to AES8 */ ucontrol->value.enumerated.item[0] = hdspm_get_aes_sample_rate(hdspm, kcontrol->private_value - HDSPM_AES32_AUTOSYNC_FROM_AES1); break; } break; case MADI: case MADIface: ucontrol->value.enumerated.item[0] = hdspm_external_rate_to_enum(hdspm); break; default: break; } return 0; } #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_system_clock_mode, \ .get = snd_hdspm_get_system_clock_mode, \ .put = snd_hdspm_put_system_clock_mode, \ } /* * Returns the system clock mode for the given card. * @returns 0 - master, 1 - slave */ static int hdspm_system_clock_mode(struct hdspm *hdspm) { switch (hdspm->io_type) { case AIO: case RayDAT: if (hdspm->settings_register & HDSPM_c0Master) return 0; break; default: if (hdspm->control_register & HDSPM_ClockModeMaster) return 0; } return 1; } /* * Sets the system clock mode. * @param mode 0 - master, 1 - slave */ static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode) { hdspm_set_toggle_setting(hdspm, (hdspm_is_raydat_or_aio(hdspm)) ? HDSPM_c0Master : HDSPM_ClockModeMaster, (0 == mode)); } static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "Master", "AutoSync" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm); return 0; } static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; else if (val > 1) val = 1; hdspm_set_system_clock_mode(hdspm, val); return 0; } #define HDSPM_INTERNAL_CLOCK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_clock_source, \ .get = snd_hdspm_get_clock_source, \ .put = snd_hdspm_put_clock_source \ } static int hdspm_clock_source(struct hdspm * hdspm) { switch (hdspm->system_sample_rate) { case 32000: return 0; case 44100: return 1; case 48000: return 2; case 64000: return 3; case 88200: return 4; case 96000: return 5; case 128000: return 6; case 176400: return 7; case 192000: return 8; } return -1; } static int hdspm_set_clock_source(struct hdspm * hdspm, int mode) { int rate; switch (mode) { case 0: rate = 32000; break; case 1: rate = 44100; break; case 2: rate = 48000; break; case 3: rate = 64000; break; case 4: rate = 88200; break; case 5: rate = 96000; break; case 6: rate = 128000; break; case 7: rate = 176400; break; case 8: rate = 192000; break; default: rate = 48000; } hdspm_set_rate(hdspm, rate, 1); return 0; } static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_ctl_enum_info(uinfo, 1, 9, texts_freq + 1); } static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm); return 0; } static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 9) val = 9; spin_lock_irq(&hdspm->lock); if (val != hdspm_clock_source(hdspm)) change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_PREF_SYNC_REF(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_pref_sync_ref, \ .get = snd_hdspm_get_pref_sync_ref, \ .put = snd_hdspm_put_pref_sync_ref \ } /* * Returns the current preferred sync reference setting. * The semantics of the return value are depending on the * card, please see the comments for clarification. */ static int hdspm_pref_sync_ref(struct hdspm * hdspm) { switch (hdspm->io_type) { case AES32: switch (hdspm->control_register & HDSPM_SyncRefMask) { case 0: return 0; /* WC */ case HDSPM_SyncRef0: return 1; /* AES 1 */ case HDSPM_SyncRef1: return 2; /* AES 2 */ case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */ case HDSPM_SyncRef2: return 4; /* AES 4 */ case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */ case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */ case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0: return 7; /* AES 7 */ case HDSPM_SyncRef3: return 8; /* AES 8 */ case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */ } break; case MADI: case MADIface: if (hdspm->tco) { switch (hdspm->control_register & HDSPM_SyncRefMask) { case 0: return 0; /* WC */ case HDSPM_SyncRef0: return 1; /* MADI */ case HDSPM_SyncRef1: return 2; /* TCO */ case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* SYNC_IN */ } } else { switch (hdspm->control_register & HDSPM_SyncRefMask) { case 0: return 0; /* WC */ case HDSPM_SyncRef0: return 1; /* MADI */ case HDSPM_SyncRef1+HDSPM_SyncRef0: return 2; /* SYNC_IN */ } } break; case RayDAT: if (hdspm->tco) { switch ((hdspm->settings_register & HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { case 0: return 0; /* WC */ case 3: return 1; /* ADAT 1 */ case 4: return 2; /* ADAT 2 */ case 5: return 3; /* ADAT 3 */ case 6: return 4; /* ADAT 4 */ case 1: return 5; /* AES */ case 2: return 6; /* SPDIF */ case 9: return 7; /* TCO */ case 10: return 8; /* SYNC_IN */ } } else { switch ((hdspm->settings_register & HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { case 0: return 0; /* WC */ case 3: return 1; /* ADAT 1 */ case 4: return 2; /* ADAT 2 */ case 5: return 3; /* ADAT 3 */ case 6: return 4; /* ADAT 4 */ case 1: return 5; /* AES */ case 2: return 6; /* SPDIF */ case 10: return 7; /* SYNC_IN */ } } break; case AIO: if (hdspm->tco) { switch ((hdspm->settings_register & HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { case 0: return 0; /* WC */ case 3: return 1; /* ADAT */ case 1: return 2; /* AES */ case 2: return 3; /* SPDIF */ case 9: return 4; /* TCO */ case 10: return 5; /* SYNC_IN */ } } else { switch ((hdspm->settings_register & HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { case 0: return 0; /* WC */ case 3: return 1; /* ADAT */ case 1: return 2; /* AES */ case 2: return 3; /* SPDIF */ case 10: return 4; /* SYNC_IN */ } } break; } return -1; } /* * Set the preferred sync reference to <pref>. The semantics * of <pref> are depending on the card type, see the comments * for clarification. */ static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) { int p = 0; switch (hdspm->io_type) { case AES32: hdspm->control_register &= ~HDSPM_SyncRefMask; switch (pref) { case 0: /* WC */ break; case 1: /* AES 1 */ hdspm->control_register |= HDSPM_SyncRef0; break; case 2: /* AES 2 */ hdspm->control_register |= HDSPM_SyncRef1; break; case 3: /* AES 3 */ hdspm->control_register |= HDSPM_SyncRef1+HDSPM_SyncRef0; break; case 4: /* AES 4 */ hdspm->control_register |= HDSPM_SyncRef2; break; case 5: /* AES 5 */ hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef0; break; case 6: /* AES 6 */ hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1; break; case 7: /* AES 7 */ hdspm->control_register |= HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; break; case 8: /* AES 8 */ hdspm->control_register |= HDSPM_SyncRef3; break; case 9: /* TCO */ hdspm->control_register |= HDSPM_SyncRef3+HDSPM_SyncRef0; break; default: return -1; } break; case MADI: case MADIface: hdspm->control_register &= ~HDSPM_SyncRefMask; if (hdspm->tco) { switch (pref) { case 0: /* WC */ break; case 1: /* MADI */ hdspm->control_register |= HDSPM_SyncRef0; break; case 2: /* TCO */ hdspm->control_register |= HDSPM_SyncRef1; break; case 3: /* SYNC_IN */ hdspm->control_register |= HDSPM_SyncRef0+HDSPM_SyncRef1; break; default: return -1; } } else { switch (pref) { case 0: /* WC */ break; case 1: /* MADI */ hdspm->control_register |= HDSPM_SyncRef0; break; case 2: /* SYNC_IN */ hdspm->control_register |= HDSPM_SyncRef0+HDSPM_SyncRef1; break; default: return -1; } } break; case RayDAT: if (hdspm->tco) { switch (pref) { case 0: p = 0; break; /* WC */ case 1: p = 3; break; /* ADAT 1 */ case 2: p = 4; break; /* ADAT 2 */ case 3: p = 5; break; /* ADAT 3 */ case 4: p = 6; break; /* ADAT 4 */ case 5: p = 1; break; /* AES */ case 6: p = 2; break; /* SPDIF */ case 7: p = 9; break; /* TCO */ case 8: p = 10; break; /* SYNC_IN */ default: return -1; } } else { switch (pref) { case 0: p = 0; break; /* WC */ case 1: p = 3; break; /* ADAT 1 */ case 2: p = 4; break; /* ADAT 2 */ case 3: p = 5; break; /* ADAT 3 */ case 4: p = 6; break; /* ADAT 4 */ case 5: p = 1; break; /* AES */ case 6: p = 2; break; /* SPDIF */ case 7: p = 10; break; /* SYNC_IN */ default: return -1; } } break; case AIO: if (hdspm->tco) { switch (pref) { case 0: p = 0; break; /* WC */ case 1: p = 3; break; /* ADAT */ case 2: p = 1; break; /* AES */ case 3: p = 2; break; /* SPDIF */ case 4: p = 9; break; /* TCO */ case 5: p = 10; break; /* SYNC_IN */ default: return -1; } } else { switch (pref) { case 0: p = 0; break; /* WC */ case 1: p = 3; break; /* ADAT */ case 2: p = 1; break; /* AES */ case 3: p = 2; break; /* SPDIF */ case 4: p = 10; break; /* SYNC_IN */ default: return -1; } } break; } switch (hdspm->io_type) { case RayDAT: case AIO: hdspm->settings_register &= ~HDSPM_c0_SyncRefMask; hdspm->settings_register |= HDSPM_c0_SyncRef0 * p; hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); break; case MADI: case MADIface: case AES32: hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); } return 0; } static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); snd_ctl_enum_info(uinfo, 1, hdspm->texts_autosync_items, hdspm->texts_autosync); return 0; } static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int psf = hdspm_pref_sync_ref(hdspm); if (psf >= 0) { ucontrol->value.enumerated.item[0] = psf; return 0; } return -1; } static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int val, change = 0; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; else if (val >= hdspm->texts_autosync_items) val = hdspm->texts_autosync_items-1; spin_lock_irq(&hdspm->lock); if (val != hdspm_pref_sync_ref(hdspm)) change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0; spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_AUTOSYNC_REF(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdspm_info_autosync_ref, \ .get = snd_hdspm_get_autosync_ref, \ } static int hdspm_autosync_ref(struct hdspm *hdspm) { /* This looks at the autosync selected sync reference */ if (AES32 == hdspm->io_type) { unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); unsigned int syncref = (status >> HDSPM_AES32_syncref_bit) & 0xF; /* syncref >= HDSPM_AES32_AUTOSYNC_FROM_WORD is always true */ if (syncref <= HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN) { return syncref; } return HDSPM_AES32_AUTOSYNC_FROM_NONE; } else if (MADI == hdspm->io_type) { unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); switch (status2 & HDSPM_SelSyncRefMask) { case HDSPM_SelSyncRef_WORD: return HDSPM_AUTOSYNC_FROM_WORD; case HDSPM_SelSyncRef_MADI: return HDSPM_AUTOSYNC_FROM_MADI; case HDSPM_SelSyncRef_TCO: return HDSPM_AUTOSYNC_FROM_TCO; case HDSPM_SelSyncRef_SyncIn: return HDSPM_AUTOSYNC_FROM_SYNC_IN; case HDSPM_SelSyncRef_NVALID: return HDSPM_AUTOSYNC_FROM_NONE; default: return HDSPM_AUTOSYNC_FROM_NONE; } } return 0; } static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (AES32 == hdspm->io_type) { static const char *const texts[] = { "WordClock", "AES1", "AES2", "AES3", "AES4", "AES5", "AES6", "AES7", "AES8", "TCO", "Sync In", "None"}; ENUMERATED_CTL_INFO(uinfo, texts); } else if (MADI == hdspm->io_type) { static const char *const texts[] = {"Word Clock", "MADI", "TCO", "Sync In", "None" }; ENUMERATED_CTL_INFO(uinfo, texts); } return 0; } static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm); return 0; } #define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READ |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_video_input_format, \ .get = snd_hdspm_get_tco_video_input_format, \ } static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = {"No video", "NTSC", "PAL"}; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { u32 status; int ret = 0; struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC | HDSPM_TCO1_Video_Input_Format_PAL)) { case HDSPM_TCO1_Video_Input_Format_NTSC: /* ntsc */ ret = 1; break; case HDSPM_TCO1_Video_Input_Format_PAL: /* pal */ ret = 2; break; default: /* no video */ ret = 0; break; } ucontrol->value.enumerated.item[0] = ret; return 0; } #define HDSPM_TCO_LTC_FRAMES(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READ |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_ltc_frames, \ .get = snd_hdspm_get_tco_ltc_frames, \ } static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps", "30 fps"}; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int hdspm_tco_ltc_frames(struct hdspm *hdspm) { u32 status; int ret = 0; status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); if (status & HDSPM_TCO1_LTC_Input_valid) { switch (status & (HDSPM_TCO1_LTC_Format_LSB | HDSPM_TCO1_LTC_Format_MSB)) { case 0: /* 24 fps */ ret = fps_24; break; case HDSPM_TCO1_LTC_Format_LSB: /* 25 fps */ ret = fps_25; break; case HDSPM_TCO1_LTC_Format_MSB: /* 29.97 fps */ ret = fps_2997; break; default: /* 30 fps */ ret = fps_30; break; } } return ret; } static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm); return 0; } #define HDSPM_TOGGLE_SETTING(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .info = snd_hdspm_info_toggle_setting, \ .get = snd_hdspm_get_toggle_setting, \ .put = snd_hdspm_put_toggle_setting \ } static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask) { u32 reg; if (hdspm_is_raydat_or_aio(hdspm)) reg = hdspm->settings_register; else reg = hdspm->control_register; return (reg & regmask) ? 1 : 0; } static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out) { u32 *reg; u32 target_reg; if (hdspm_is_raydat_or_aio(hdspm)) { reg = &(hdspm->settings_register); target_reg = HDSPM_WR_SETTINGS; } else { reg = &(hdspm->control_register); target_reg = HDSPM_controlRegister; } if (out) *reg |= regmask; else *reg &= ~regmask; hdspm_write(hdspm, target_reg, *reg); return 0; } #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_toggle_setting(hdspm, regmask); hdspm_set_toggle_setting(hdspm, regmask, val); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_INPUT_SELECT(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_input_select, \ .get = snd_hdspm_get_input_select, \ .put = snd_hdspm_put_input_select \ } static int hdspm_input_select(struct hdspm * hdspm) { return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0; } static int hdspm_set_input_select(struct hdspm * hdspm, int out) { if (out) hdspm->control_register |= HDSPM_InputSelect0; else hdspm->control_register &= ~HDSPM_InputSelect0; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0; } static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "optical", "coaxial" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_input_select(hdspm); hdspm_set_input_select(hdspm, val); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_DS_WIRE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_ds_wire, \ .get = snd_hdspm_get_ds_wire, \ .put = snd_hdspm_put_ds_wire \ } static int hdspm_ds_wire(struct hdspm * hdspm) { return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0; } static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds) { if (ds) hdspm->control_register |= HDSPM_DS_DoubleWire; else hdspm->control_register &= ~HDSPM_DS_DoubleWire; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0; } static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "Single", "Double" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdspm->lock); change = (int) val != hdspm_ds_wire(hdspm); hdspm_set_ds_wire(hdspm, val); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_QS_WIRE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_qs_wire, \ .get = snd_hdspm_get_qs_wire, \ .put = snd_hdspm_put_qs_wire \ } static int hdspm_qs_wire(struct hdspm * hdspm) { if (hdspm->control_register & HDSPM_QS_DoubleWire) return 1; if (hdspm->control_register & HDSPM_QS_QuadWire) return 2; return 0; } static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode) { hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire); switch (mode) { case 0: break; case 1: hdspm->control_register |= HDSPM_QS_DoubleWire; break; case 2: hdspm->control_register |= HDSPM_QS_QuadWire; break; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0; } static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "Single", "Double", "Quad" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdspm->lock); change = val != hdspm_qs_wire(hdspm); hdspm_set_qs_wire(hdspm, val); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_CONTROL_TRISTATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .info = snd_hdspm_info_tristate, \ .get = snd_hdspm_get_tristate, \ .put = snd_hdspm_put_tristate \ } static int hdspm_tristate(struct hdspm *hdspm, u32 regmask) { u32 reg = hdspm->settings_register & (regmask * 3); return reg / regmask; } static int hdspm_set_tristate(struct hdspm *hdspm, int mode, u32 regmask) { hdspm->settings_register &= ~(regmask * 3); hdspm->settings_register |= (regmask * mode); hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); return 0; } static int snd_hdspm_info_tristate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { u32 regmask = kcontrol->private_value; static const char *const texts_spdif[] = { "Optical", "Coaxial", "Internal" }; static const char *const texts_levels[] = { "Hi Gain", "+4 dBu", "-10 dBV" }; switch (regmask) { case HDSPM_c0_Input0: ENUMERATED_CTL_INFO(uinfo, texts_spdif); break; default: ENUMERATED_CTL_INFO(uinfo, texts_levels); break; } return 0; } static int snd_hdspm_get_tristate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; spin_lock_irq(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_tristate(hdspm, regmask); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_tristate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; int change; int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdspm->lock); change = val != hdspm_tristate(hdspm, regmask); hdspm_set_tristate(hdspm, val, regmask); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_MADI_SPEEDMODE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdspm_info_madi_speedmode, \ .get = snd_hdspm_get_madi_speedmode, \ .put = snd_hdspm_put_madi_speedmode \ } static int hdspm_madi_speedmode(struct hdspm *hdspm) { if (hdspm->control_register & HDSPM_QuadSpeed) return 2; if (hdspm->control_register & HDSPM_DoubleSpeed) return 1; return 0; } static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode) { hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed); switch (mode) { case 0: break; case 1: hdspm->control_register |= HDSPM_DoubleSpeed; break; case 2: hdspm->control_register |= HDSPM_QuadSpeed; break; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0; } static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "Single", "Double", "Quad" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdspm->lock); ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; val = ucontrol->value.integer.value[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdspm->lock); change = val != hdspm_madi_speedmode(hdspm); hdspm_set_madi_speedmode(hdspm, val); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_MIXER(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \ .name = xname, \ .index = xindex, \ .device = 0, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_mixer, \ .get = snd_hdspm_get_mixer, \ .put = snd_hdspm_put_mixer \ } static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 3; uinfo->value.integer.min = 0; uinfo->value.integer.max = 65535; uinfo->value.integer.step = 1; return 0; } static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int source; int destination; source = ucontrol->value.integer.value[0]; if (source < 0) source = 0; else if (source >= 2 * HDSPM_MAX_CHANNELS) source = 2 * HDSPM_MAX_CHANNELS - 1; destination = ucontrol->value.integer.value[1]; if (destination < 0) destination = 0; else if (destination >= HDSPM_MAX_CHANNELS) destination = HDSPM_MAX_CHANNELS - 1; spin_lock_irq(&hdspm->lock); if (source >= HDSPM_MAX_CHANNELS) ucontrol->value.integer.value[2] = hdspm_read_pb_gain(hdspm, destination, source - HDSPM_MAX_CHANNELS); else ucontrol->value.integer.value[2] = hdspm_read_in_gain(hdspm, destination, source); spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; int source; int destination; int gain; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; source = ucontrol->value.integer.value[0]; destination = ucontrol->value.integer.value[1]; if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS) return -1; if (destination < 0 || destination >= HDSPM_MAX_CHANNELS) return -1; gain = ucontrol->value.integer.value[2]; spin_lock_irq(&hdspm->lock); if (source >= HDSPM_MAX_CHANNELS) change = gain != hdspm_read_pb_gain(hdspm, destination, source - HDSPM_MAX_CHANNELS); else change = gain != hdspm_read_in_gain(hdspm, destination, source); if (change) { if (source >= HDSPM_MAX_CHANNELS) hdspm_write_pb_gain(hdspm, destination, source - HDSPM_MAX_CHANNELS, gain); else hdspm_write_in_gain(hdspm, destination, source, gain); } spin_unlock_irq(&hdspm->lock); return change; } /* The simple mixer control(s) provide gain control for the basic 1:1 mappings of playback streams to output streams. */ #define HDSPM_PLAYBACK_MIXER \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_playback_mixer, \ .get = snd_hdspm_get_playback_mixer, \ .put = snd_hdspm_put_playback_mixer \ } static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 64; uinfo->value.integer.step = 1; return 0; } static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int channel; channel = ucontrol->id.index - 1; if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) return -EINVAL; spin_lock_irq(&hdspm->lock); ucontrol->value.integer.value[0] = (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN; spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int change; int channel; int gain; if (!snd_hdspm_use_is_exclusive(hdspm)) return -EBUSY; channel = ucontrol->id.index - 1; if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) return -EINVAL; gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64; spin_lock_irq(&hdspm->lock); change = gain != hdspm_read_pb_gain(hdspm, channel, channel); if (change) hdspm_write_pb_gain(hdspm, channel, channel, gain); spin_unlock_irq(&hdspm->lock); return change; } #define HDSPM_SYNC_CHECK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_sync_check, \ .get = snd_hdspm_get_sync_check \ } #define HDSPM_TCO_LOCK_CHECK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_tco_info_lock_check, \ .get = snd_hdspm_get_sync_check \ } static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "No Lock", "Lock", "Sync", "N/A" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "No Lock", "Lock" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int hdspm_wc_sync_check(struct hdspm *hdspm) { int status, status2; switch (hdspm->io_type) { case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); if (status & HDSPM_AES32_wcLock) { if (status & HDSPM_AES32_wcSync) return 2; else return 1; } return 0; case MADI: status2 = hdspm_read(hdspm, HDSPM_statusRegister2); if (status2 & HDSPM_wcLock) { if (status2 & HDSPM_wcSync) return 2; else return 1; } return 0; case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_statusRegister); if (status & 0x2000000) return 2; else if (status & 0x1000000) return 1; return 0; case MADIface: break; } return 3; } static int hdspm_madi_sync_check(struct hdspm *hdspm) { int status = hdspm_read(hdspm, HDSPM_statusRegister); if (status & HDSPM_madiLock) { if (status & HDSPM_madiSync) return 2; else return 1; } return 0; } static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx) { int status, lock, sync; status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); lock = (status & (0x1<<idx)) ? 1 : 0; sync = (status & (0x100<<idx)) ? 1 : 0; if (lock && sync) return 2; else if (lock) return 1; return 0; } static int hdspm_sync_in_sync_check(struct hdspm *hdspm) { int status, lock = 0, sync = 0; switch (hdspm->io_type) { case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_3); lock = (status & 0x400) ? 1 : 0; sync = (status & 0x800) ? 1 : 0; break; case MADI: status = hdspm_read(hdspm, HDSPM_statusRegister); lock = (status & HDSPM_syncInLock) ? 1 : 0; sync = (status & HDSPM_syncInSync) ? 1 : 0; break; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister2); lock = (status & 0x100000) ? 1 : 0; sync = (status & 0x200000) ? 1 : 0; break; case MADIface: break; } if (lock && sync) return 2; else if (lock) return 1; return 0; } static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx) { int status2, lock, sync; status2 = hdspm_read(hdspm, HDSPM_statusRegister2); lock = (status2 & (0x0080 >> idx)) ? 1 : 0; sync = (status2 & (0x8000 >> idx)) ? 1 : 0; if (sync) return 2; else if (lock) return 1; return 0; } static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask) { u32 status; status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); return (status & mask) ? 1 : 0; } static int hdspm_tco_sync_check(struct hdspm *hdspm) { int status; if (hdspm->tco) { switch (hdspm->io_type) { case MADI: status = hdspm_read(hdspm, HDSPM_statusRegister); if (status & HDSPM_tcoLockMadi) { if (status & HDSPM_tcoSync) return 2; else return 1; } return 0; case AES32: status = hdspm_read(hdspm, HDSPM_statusRegister); if (status & HDSPM_tcoLockAes) { if (status & HDSPM_tcoSync) return 2; else return 1; } return 0; case RayDAT: case AIO: status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); if (status & 0x8000000) return 2; /* Sync */ if (status & 0x4000000) return 1; /* Lock */ return 0; /* No signal */ default: break; } } return 3; /* N/A */ } static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); int val = -1; switch (hdspm->io_type) { case RayDAT: switch (kcontrol->private_value) { case 0: /* WC */ val = hdspm_wc_sync_check(hdspm); break; case 7: /* TCO */ val = hdspm_tco_sync_check(hdspm); break; case 8: /* SYNC IN */ val = hdspm_sync_in_sync_check(hdspm); break; default: val = hdspm_s1_sync_check(hdspm, kcontrol->private_value-1); } break; case AIO: switch (kcontrol->private_value) { case 0: /* WC */ val = hdspm_wc_sync_check(hdspm); break; case 4: /* TCO */ val = hdspm_tco_sync_check(hdspm); break; case 5: /* SYNC IN */ val = hdspm_sync_in_sync_check(hdspm); break; default: val = hdspm_s1_sync_check(hdspm, kcontrol->private_value-1); } break; case MADI: switch (kcontrol->private_value) { case 0: /* WC */ val = hdspm_wc_sync_check(hdspm); break; case 1: /* MADI */ val = hdspm_madi_sync_check(hdspm); break; case 2: /* TCO */ val = hdspm_tco_sync_check(hdspm); break; case 3: /* SYNC_IN */ val = hdspm_sync_in_sync_check(hdspm); break; } break; case MADIface: val = hdspm_madi_sync_check(hdspm); /* MADI */ break; case AES32: switch (kcontrol->private_value) { case 0: /* WC */ val = hdspm_wc_sync_check(hdspm); break; case 9: /* TCO */ val = hdspm_tco_sync_check(hdspm); break; case 10 /* SYNC IN */: val = hdspm_sync_in_sync_check(hdspm); break; default: /* AES1 to AES8 */ val = hdspm_aes_sync_check(hdspm, kcontrol->private_value-1); } break; } if (hdspm->tco) { switch (kcontrol->private_value) { case 11: /* Check TCO for lock state of its current input */ val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock); break; case 12: /* Check TCO for valid time code on LTC input. */ val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_LTC_Input_valid); break; default: break; } } if (-1 == val) val = 3; ucontrol->value.enumerated.item[0] = val; return 0; } /* * TCO controls */ static void hdspm_tco_write(struct hdspm *hdspm) { unsigned int tc[4] = { 0, 0, 0, 0}; switch (hdspm->tco->input) { case 0: tc[2] |= HDSPM_TCO2_set_input_MSB; break; case 1: tc[2] |= HDSPM_TCO2_set_input_LSB; break; default: break; } switch (hdspm->tco->framerate) { case 1: tc[1] |= HDSPM_TCO1_LTC_Format_LSB; break; case 2: tc[1] |= HDSPM_TCO1_LTC_Format_MSB; break; case 3: tc[1] |= HDSPM_TCO1_LTC_Format_MSB + HDSPM_TCO1_set_drop_frame_flag; break; case 4: tc[1] |= HDSPM_TCO1_LTC_Format_LSB + HDSPM_TCO1_LTC_Format_MSB; break; case 5: tc[1] |= HDSPM_TCO1_LTC_Format_LSB + HDSPM_TCO1_LTC_Format_MSB + HDSPM_TCO1_set_drop_frame_flag; break; default: break; } switch (hdspm->tco->wordclock) { case 1: tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB; break; case 2: tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB; break; default: break; } switch (hdspm->tco->samplerate) { case 1: tc[2] |= HDSPM_TCO2_set_freq; break; case 2: tc[2] |= HDSPM_TCO2_set_freq_from_app; break; default: break; } switch (hdspm->tco->pull) { case 1: tc[2] |= HDSPM_TCO2_set_pull_up; break; case 2: tc[2] |= HDSPM_TCO2_set_pull_down; break; case 3: tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4; break; case 4: tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4; break; default: break; } if (1 == hdspm->tco->term) { tc[2] |= HDSPM_TCO2_set_term_75R; } hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]); hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]); hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]); hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]); } #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_sample_rate, \ .get = snd_hdspm_get_tco_sample_rate, \ .put = snd_hdspm_put_tco_sample_rate \ } static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { /* TODO freq from app could be supported here, see tco->samplerate */ static const char *const texts[] = { "44.1 kHz", "48 kHz" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate; return 0; } static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) { hdspm->tco->samplerate = ucontrol->value.enumerated.item[0]; hdspm_tco_write(hdspm); return 1; } return 0; } #define HDSPM_TCO_PULL(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_pull, \ .get = snd_hdspm_get_tco_pull, \ .put = snd_hdspm_put_tco_pull \ } static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm->tco->pull; return 0; } static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) { hdspm->tco->pull = ucontrol->value.enumerated.item[0]; hdspm_tco_write(hdspm); return 1; } return 0; } #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_wck_conversion, \ .get = snd_hdspm_get_tco_wck_conversion, \ .put = snd_hdspm_put_tco_wck_conversion \ } static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock; return 0; } static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) { hdspm->tco->wordclock = ucontrol->value.enumerated.item[0]; hdspm_tco_write(hdspm); return 1; } return 0; } #define HDSPM_TCO_FRAME_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_frame_rate, \ .get = snd_hdspm_get_tco_frame_rate, \ .put = snd_hdspm_put_tco_frame_rate \ } static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "24 fps", "25 fps", "29.97fps", "29.97 dfps", "30 fps", "30 dfps" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm->tco->framerate; return 0; } static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) { hdspm->tco->framerate = ucontrol->value.enumerated.item[0]; hdspm_tco_write(hdspm); return 1; } return 0; } #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_sync_source, \ .get = snd_hdspm_get_tco_sync_source, \ .put = snd_hdspm_put_tco_sync_source \ } static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char *const texts[] = { "LTC", "Video", "WCK" }; ENUMERATED_CTL_INFO(uinfo, texts); return 0; } static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdspm->tco->input; return 0; } static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) { hdspm->tco->input = ucontrol->value.enumerated.item[0]; hdspm_tco_write(hdspm); return 1; } return 0; } #define HDSPM_TCO_WORD_TERM(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdspm_info_tco_word_term, \ .get = snd_hdspm_get_tco_word_term, \ .put = snd_hdspm_put_tco_word_term \ } static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdspm->tco->term; return 0; } static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); if (hdspm->tco->term != ucontrol->value.integer.value[0]) { hdspm->tco->term = ucontrol->value.integer.value[0]; hdspm_tco_write(hdspm); return 1; } return 0; } static const struct snd_kcontrol_new snd_hdspm_controls_madi[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), HDSPM_SYNC_CHECK("WC SyncCheck", 0), HDSPM_SYNC_CHECK("MADI SyncCheck", 1), HDSPM_SYNC_CHECK("TCO SyncCheck", 2), HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3), HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX), HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), HDSPM_INPUT_SELECT("Input Select", 0), HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) }; static const struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), HDSPM_SYNC_CHECK("MADI SyncCheck", 0), HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) }; static const struct snd_kcontrol_new snd_hdspm_controls_aio[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), HDSPM_SYNC_CHECK("WC SyncCheck", 0), HDSPM_SYNC_CHECK("AES SyncCheck", 1), HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), HDSPM_SYNC_CHECK("ADAT SyncCheck", 3), HDSPM_SYNC_CHECK("TCO SyncCheck", 4), HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5), HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3), HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4), HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5), HDSPM_CONTROL_TRISTATE("S/PDIF Input", HDSPM_c0_Input0), HDSPM_TOGGLE_SETTING("S/PDIF Out Optical", HDSPM_c0_Spdif_Opt), HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro), HDSPM_TOGGLE_SETTING("ADAT internal (AEB/TEB)", HDSPM_c0_AEB1), HDSPM_TOGGLE_SETTING("XLR Breakout Cable", HDSPM_c0_Sym6db), HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48), HDSPM_CONTROL_TRISTATE("Input Level", HDSPM_c0_AD_GAIN0), HDSPM_CONTROL_TRISTATE("Output Level", HDSPM_c0_DA_GAIN0), HDSPM_CONTROL_TRISTATE("Phones Level", HDSPM_c0_PH_GAIN0) /* HDSPM_INPUT_SELECT("Input Select", 0), HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0), HDSPM_PROFESSIONAL("SPDIF Out Professional", 0); HDSPM_SPDIF_IN("SPDIF In", 0); HDSPM_BREAKOUT_CABLE("Breakout Cable", 0); HDSPM_INPUT_LEVEL("Input Level", 0); HDSPM_OUTPUT_LEVEL("Output Level", 0); HDSPM_PHONES("Phones", 0); */ }; static const struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0), HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0), HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSPM_SYNC_CHECK("WC SyncCheck", 0), HDSPM_SYNC_CHECK("AES SyncCheck", 1), HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3), HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4), HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5), HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6), HDSPM_SYNC_CHECK("TCO SyncCheck", 7), HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8), HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3), HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4), HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5), HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6), HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7), HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8), HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro), HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48) }; static const struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { HDSPM_MIXER("Mixer", 0), HDSPM_INTERNAL_CLOCK("Internal Clock", 0), HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 11), HDSPM_SYNC_CHECK("WC Sync Check", 0), HDSPM_SYNC_CHECK("AES1 Sync Check", 1), HDSPM_SYNC_CHECK("AES2 Sync Check", 2), HDSPM_SYNC_CHECK("AES3 Sync Check", 3), HDSPM_SYNC_CHECK("AES4 Sync Check", 4), HDSPM_SYNC_CHECK("AES5 Sync Check", 5), HDSPM_SYNC_CHECK("AES6 Sync Check", 6), HDSPM_SYNC_CHECK("AES7 Sync Check", 7), HDSPM_SYNC_CHECK("AES8 Sync Check", 8), HDSPM_SYNC_CHECK("TCO Sync Check", 9), HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10), HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1), HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2), HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3), HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4), HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5), HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6), HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7), HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8), HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9), HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10), HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis), HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby), HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional), HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), HDSPM_DS_WIRE("Double Speed Wire Mode", 0), HDSPM_QS_WIRE("Quad Speed Wire Mode", 0), }; /* Control elements for the optional TCO module */ static const struct snd_kcontrol_new snd_hdspm_controls_tco[] = { HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0), HDSPM_TCO_PULL("TCO Pull", 0), HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0), HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0), HDSPM_TCO_WORD_TERM("TCO Word Term", 0), HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11), HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12), HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0), HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0) }; static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER; static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm) { int i; for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) { if (hdspm->system_sample_rate > 48000) { hdspm->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_INACTIVE | SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE; } else { hdspm->playback_mixer_ctls[i]->vd[0].access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_VOLATILE; } snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &hdspm->playback_mixer_ctls[i]->id); } return 0; } static int snd_hdspm_create_controls(struct snd_card *card, struct hdspm *hdspm) { unsigned int idx, limit; int err; struct snd_kcontrol *kctl; const struct snd_kcontrol_new *list = NULL; switch (hdspm->io_type) { case MADI: list = snd_hdspm_controls_madi; limit = ARRAY_SIZE(snd_hdspm_controls_madi); break; case MADIface: list = snd_hdspm_controls_madiface; limit = ARRAY_SIZE(snd_hdspm_controls_madiface); break; case AIO: list = snd_hdspm_controls_aio; limit = ARRAY_SIZE(snd_hdspm_controls_aio); break; case RayDAT: list = snd_hdspm_controls_raydat; limit = ARRAY_SIZE(snd_hdspm_controls_raydat); break; case AES32: list = snd_hdspm_controls_aes32; limit = ARRAY_SIZE(snd_hdspm_controls_aes32); break; } if (list) { for (idx = 0; idx < limit; idx++) { err = snd_ctl_add(card, snd_ctl_new1(&list[idx], hdspm)); if (err < 0) return err; } } /* create simple 1:1 playback mixer controls */ snd_hdspm_playback_mixer.name = "Chn"; if (hdspm->system_sample_rate >= 128000) { limit = hdspm->qs_out_channels; } else if (hdspm->system_sample_rate >= 64000) { limit = hdspm->ds_out_channels; } else { limit = hdspm->ss_out_channels; } for (idx = 0; idx < limit; ++idx) { snd_hdspm_playback_mixer.index = idx + 1; kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm); err = snd_ctl_add(card, kctl); if (err < 0) return err; hdspm->playback_mixer_ctls[idx] = kctl; } if (hdspm->tco) { /* add tco control elements */ list = snd_hdspm_controls_tco; limit = ARRAY_SIZE(snd_hdspm_controls_tco); for (idx = 0; idx < limit; idx++) { err = snd_ctl_add(card, snd_ctl_new1(&list[idx], hdspm)); if (err < 0) return err; } } return 0; } /*------------------------------------------------------------ /proc interface ------------------------------------------------------------*/ static void snd_hdspm_proc_read_tco(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; unsigned int status, control; int a, ltc, frames, seconds, minutes, hours; unsigned int period; u64 freq_const = 0; u32 rate; snd_iprintf(buffer, "--- TCO ---\n"); status = hdspm_read(hdspm, HDSPM_statusRegister); control = hdspm->control_register; if (status & HDSPM_tco_detect) { snd_iprintf(buffer, "TCO module detected.\n"); a = hdspm_read(hdspm, HDSPM_RD_TCO+4); if (a & HDSPM_TCO1_LTC_Input_valid) { snd_iprintf(buffer, " LTC valid, "); switch (a & (HDSPM_TCO1_LTC_Format_LSB | HDSPM_TCO1_LTC_Format_MSB)) { case 0: snd_iprintf(buffer, "24 fps, "); break; case HDSPM_TCO1_LTC_Format_LSB: snd_iprintf(buffer, "25 fps, "); break; case HDSPM_TCO1_LTC_Format_MSB: snd_iprintf(buffer, "29.97 fps, "); break; default: snd_iprintf(buffer, "30 fps, "); break; } if (a & HDSPM_TCO1_set_drop_frame_flag) { snd_iprintf(buffer, "drop frame\n"); } else { snd_iprintf(buffer, "full frame\n"); } } else { snd_iprintf(buffer, " no LTC\n"); } if (a & HDSPM_TCO1_Video_Input_Format_NTSC) { snd_iprintf(buffer, " Video: NTSC\n"); } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) { snd_iprintf(buffer, " Video: PAL\n"); } else { snd_iprintf(buffer, " No video\n"); } if (a & HDSPM_TCO1_TCO_lock) { snd_iprintf(buffer, " Sync: lock\n"); } else { snd_iprintf(buffer, " Sync: no lock\n"); } switch (hdspm->io_type) { case MADI: case AES32: freq_const = 110069313433624ULL; break; case RayDAT: case AIO: freq_const = 104857600000000ULL; break; case MADIface: break; /* no TCO possible */ } period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); snd_iprintf(buffer, " period: %u\n", period); /* rate = freq_const/period; */ rate = div_u64(freq_const, period); if (control & HDSPM_QuadSpeed) { rate *= 4; } else if (control & HDSPM_DoubleSpeed) { rate *= 2; } snd_iprintf(buffer, " Frequency: %u Hz\n", (unsigned int) rate); ltc = hdspm_read(hdspm, HDSPM_RD_TCO); frames = ltc & 0xF; ltc >>= 4; frames += (ltc & 0x3) * 10; ltc >>= 4; seconds = ltc & 0xF; ltc >>= 4; seconds += (ltc & 0x7) * 10; ltc >>= 4; minutes = ltc & 0xF; ltc >>= 4; minutes += (ltc & 0x7) * 10; ltc >>= 4; hours = ltc & 0xF; ltc >>= 4; hours += (ltc & 0x3) * 10; snd_iprintf(buffer, " LTC In: %02d:%02d:%02d:%02d\n", hours, minutes, seconds, frames); } else { snd_iprintf(buffer, "No TCO module detected.\n"); } } static void snd_hdspm_proc_read_madi(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; unsigned int status, status2; char *pref_sync_ref; char *autosync_ref; char *system_clock_mode; int x, x2; status = hdspm_read(hdspm, HDSPM_statusRegister); status2 = hdspm_read(hdspm, HDSPM_statusRegister2); snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n", hdspm->card_name, hdspm->card->number + 1, hdspm->firmware_rev, (status2 & HDSPM_version0) | (status2 & HDSPM_version1) | (status2 & HDSPM_version2)); snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n", (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF, hdspm->serial); snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); snd_iprintf(buffer, "--- System ---\n"); snd_iprintf(buffer, "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", status & HDSPM_audioIRQPending, (status & HDSPM_midi0IRQPending) ? 1 : 0, (status & HDSPM_midi1IRQPending) ? 1 : 0, hdspm->irq_count); snd_iprintf(buffer, "HW pointer: id = %d, rawptr = %d (%d->%d) " "estimated= %ld (bytes)\n", ((status & HDSPM_BufferID) ? 1 : 0), (status & HDSPM_BufferPositionMask), (status & HDSPM_BufferPositionMask) % (2 * (int)hdspm->period_bytes), ((status & HDSPM_BufferPositionMask) - 64) % (2 * (int)hdspm->period_bytes), (long) hdspm_hw_pointer(hdspm) * 4); snd_iprintf(buffer, "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); snd_iprintf(buffer, "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); snd_iprintf(buffer, "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " "status2=0x%x\n", hdspm->control_register, hdspm->control2_register, status, status2); snd_iprintf(buffer, "--- Settings ---\n"); x = hdspm_get_latency(hdspm); snd_iprintf(buffer, "Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdspm->period_bytes); snd_iprintf(buffer, "Line out: %s\n", (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); snd_iprintf(buffer, "ClearTrackMarker = %s, Transmit in %s Channel Mode, " "Auto Input %s\n", (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off", (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56", (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off"); if (!(hdspm->control_register & HDSPM_ClockModeMaster)) system_clock_mode = "AutoSync"; else system_clock_mode = "Master"; snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode); switch (hdspm_pref_sync_ref(hdspm)) { case HDSPM_SYNC_FROM_WORD: pref_sync_ref = "Word Clock"; break; case HDSPM_SYNC_FROM_MADI: pref_sync_ref = "MADI Sync"; break; case HDSPM_SYNC_FROM_TCO: pref_sync_ref = "TCO"; break; case HDSPM_SYNC_FROM_SYNC_IN: pref_sync_ref = "Sync In"; break; default: pref_sync_ref = "XXXX Clock"; break; } snd_iprintf(buffer, "Preferred Sync Reference: %s\n", pref_sync_ref); snd_iprintf(buffer, "System Clock Frequency: %d\n", hdspm->system_sample_rate); snd_iprintf(buffer, "--- Status:\n"); x = status & HDSPM_madiSync; x2 = status2 & HDSPM_wcSync; snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n", (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") : "NoLock", (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") : "NoLock"); switch (hdspm_autosync_ref(hdspm)) { case HDSPM_AUTOSYNC_FROM_SYNC_IN: autosync_ref = "Sync In"; break; case HDSPM_AUTOSYNC_FROM_TCO: autosync_ref = "TCO"; break; case HDSPM_AUTOSYNC_FROM_WORD: autosync_ref = "Word Clock"; break; case HDSPM_AUTOSYNC_FROM_MADI: autosync_ref = "MADI Sync"; break; case HDSPM_AUTOSYNC_FROM_NONE: autosync_ref = "Input not valid"; break; default: autosync_ref = "---"; break; } snd_iprintf(buffer, "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n", autosync_ref, hdspm_external_sample_rate(hdspm), (status & HDSPM_madiFreqMask) >> 22, (status2 & HDSPM_wcFreqMask) >> 5); snd_iprintf(buffer, "Input: %s, Mode=%s\n", (status & HDSPM_AB_int) ? "Coax" : "Optical", (status & HDSPM_RX_64ch) ? "64 channels" : "56 channels"); /* call readout function for TCO specific status */ snd_hdspm_proc_read_tco(entry, buffer); snd_iprintf(buffer, "\n"); } static void snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; unsigned int status; unsigned int status2; unsigned int timecode; unsigned int wcLock, wcSync; int pref_syncref; char *autosync_ref; int x; status = hdspm_read(hdspm, HDSPM_statusRegister); status2 = hdspm_read(hdspm, HDSPM_statusRegister2); timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n", hdspm->card_name, hdspm->card->number + 1, hdspm->firmware_rev); snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); snd_iprintf(buffer, "--- System ---\n"); snd_iprintf(buffer, "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", status & HDSPM_audioIRQPending, (status & HDSPM_midi0IRQPending) ? 1 : 0, (status & HDSPM_midi1IRQPending) ? 1 : 0, hdspm->irq_count); snd_iprintf(buffer, "HW pointer: id = %d, rawptr = %d (%d->%d) " "estimated= %ld (bytes)\n", ((status & HDSPM_BufferID) ? 1 : 0), (status & HDSPM_BufferPositionMask), (status & HDSPM_BufferPositionMask) % (2 * (int)hdspm->period_bytes), ((status & HDSPM_BufferPositionMask) - 64) % (2 * (int)hdspm->period_bytes), (long) hdspm_hw_pointer(hdspm) * 4); snd_iprintf(buffer, "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); snd_iprintf(buffer, "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); snd_iprintf(buffer, "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " "status2=0x%x\n", hdspm->control_register, hdspm->control2_register, status, status2); snd_iprintf(buffer, "--- Settings ---\n"); x = hdspm_get_latency(hdspm); snd_iprintf(buffer, "Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdspm->period_bytes); snd_iprintf(buffer, "Line out: %s\n", (hdspm-> control_register & HDSPM_LineOut) ? "on " : "off"); snd_iprintf(buffer, "ClearTrackMarker %s, Emphasis %s, Dolby %s\n", (hdspm-> control_register & HDSPM_clr_tms) ? "on" : "off", (hdspm-> control_register & HDSPM_Emphasis) ? "on" : "off", (hdspm-> control_register & HDSPM_Dolby) ? "on" : "off"); pref_syncref = hdspm_pref_sync_ref(hdspm); if (pref_syncref == 0) snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n"); else snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n", pref_syncref); snd_iprintf(buffer, "System Clock Frequency: %d\n", hdspm->system_sample_rate); snd_iprintf(buffer, "Double speed: %s\n", hdspm->control_register & HDSPM_DS_DoubleWire? "Double wire" : "Single wire"); snd_iprintf(buffer, "Quad speed: %s\n", hdspm->control_register & HDSPM_QS_DoubleWire? "Double wire" : hdspm->control_register & HDSPM_QS_QuadWire? "Quad wire" : "Single wire"); snd_iprintf(buffer, "--- Status:\n"); wcLock = status & HDSPM_AES32_wcLock; wcSync = wcLock && (status & HDSPM_AES32_wcSync); snd_iprintf(buffer, "Word: %s Frequency: %d\n", (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock", HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); for (x = 0; x < 8; x++) { snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", x+1, (status2 & (HDSPM_LockAES >> x)) ? "Sync " : "No Lock", HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); } switch (hdspm_autosync_ref(hdspm)) { case HDSPM_AES32_AUTOSYNC_FROM_NONE: autosync_ref = "None"; break; case HDSPM_AES32_AUTOSYNC_FROM_WORD: autosync_ref = "Word Clock"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES1: autosync_ref = "AES1"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES2: autosync_ref = "AES2"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES3: autosync_ref = "AES3"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES4: autosync_ref = "AES4"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES5: autosync_ref = "AES5"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES6: autosync_ref = "AES6"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES7: autosync_ref = "AES7"; break; case HDSPM_AES32_AUTOSYNC_FROM_AES8: autosync_ref = "AES8"; break; case HDSPM_AES32_AUTOSYNC_FROM_TCO: autosync_ref = "TCO"; break; case HDSPM_AES32_AUTOSYNC_FROM_SYNC_IN: autosync_ref = "Sync In"; break; default: autosync_ref = "---"; break; } snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref); /* call readout function for TCO specific status */ snd_hdspm_proc_read_tco(entry, buffer); snd_iprintf(buffer, "\n"); } static void snd_hdspm_proc_read_raydat(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; unsigned int status1, status2, status3, i; unsigned int lock, sync; status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */ status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */ status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */ snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1); snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2); snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3); snd_iprintf(buffer, "\n*** CLOCK MODE\n\n"); snd_iprintf(buffer, "Clock mode : %s\n", (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave"); snd_iprintf(buffer, "System frequency: %d Hz\n", hdspm_get_system_sample_rate(hdspm)); snd_iprintf(buffer, "\n*** INPUT STATUS\n\n"); lock = 0x1; sync = 0x100; for (i = 0; i < 8; i++) { snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n", i, (status1 & lock) ? 1 : 0, (status1 & sync) ? 1 : 0, texts_freq[(status2 >> (i * 4)) & 0xF]); lock = lock<<1; sync = sync<<1; } snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n", (status1 & 0x1000000) ? 1 : 0, (status1 & 0x2000000) ? 1 : 0, texts_freq[(status1 >> 16) & 0xF]); snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n", (status1 & 0x4000000) ? 1 : 0, (status1 & 0x8000000) ? 1 : 0, texts_freq[(status1 >> 20) & 0xF]); snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n", (status3 & 0x400) ? 1 : 0, (status3 & 0x800) ? 1 : 0, texts_freq[(status2 >> 12) & 0xF]); } #ifdef CONFIG_SND_DEBUG static void snd_hdspm_proc_read_debug(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; int j,i; for (i = 0; i < 256 /* 1024*64 */; i += j) { snd_iprintf(buffer, "0x%08X: ", i); for (j = 0; j < 16; j += 4) snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); snd_iprintf(buffer, "\n"); } } #endif static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; int i; snd_iprintf(buffer, "# generated by hdspm\n"); for (i = 0; i < hdspm->max_channels_in; i++) { snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]); } } static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdspm *hdspm = entry->private_data; int i; snd_iprintf(buffer, "# generated by hdspm\n"); for (i = 0; i < hdspm->max_channels_out; i++) { snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]); } } static void snd_hdspm_proc_init(struct hdspm *hdspm) { void (*read)(struct snd_info_entry *, struct snd_info_buffer *) = NULL; switch (hdspm->io_type) { case AES32: read = snd_hdspm_proc_read_aes32; break; case MADI: read = snd_hdspm_proc_read_madi; break; case MADIface: /* read = snd_hdspm_proc_read_madiface; */ break; case RayDAT: read = snd_hdspm_proc_read_raydat; break; case AIO: break; } snd_card_ro_proc_new(hdspm->card, "hdspm", hdspm, read); snd_card_ro_proc_new(hdspm->card, "ports.in", hdspm, snd_hdspm_proc_ports_in); snd_card_ro_proc_new(hdspm->card, "ports.out", hdspm, snd_hdspm_proc_ports_out); #ifdef CONFIG_SND_DEBUG /* debug file to read all hdspm registers */ snd_card_ro_proc_new(hdspm->card, "debug", hdspm, snd_hdspm_proc_read_debug); #endif } /*------------------------------------------------------------ hdspm intitialize ------------------------------------------------------------*/ static int snd_hdspm_set_defaults(struct hdspm * hdspm) { /* ASSUMPTION: hdspm->lock is either held, or there is no need to hold it (e.g. during module initialization). */ /* set defaults: */ hdspm->settings_register = 0; switch (hdspm->io_type) { case MADI: case MADIface: hdspm->control_register = 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; break; case RayDAT: case AIO: hdspm->settings_register = 0x1 + 0x1000; /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0, * line_out */ hdspm->control_register = 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; break; case AES32: hdspm->control_register = HDSPM_ClockModeMaster | /* Master Clock Mode on */ hdspm_encode_latency(7) | /* latency max=8192samples */ HDSPM_SyncRef0 | /* AES1 is syncclock */ HDSPM_LineOut | /* Analog output in */ HDSPM_Professional; /* Professional mode */ break; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); if (AES32 == hdspm->io_type) { /* No control2 register for AES32 */ #ifdef SNDRV_BIG_ENDIAN hdspm->control2_register = HDSPM_BIGENDIAN_MODE; #else hdspm->control2_register = 0; #endif hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register); } hdspm_compute_period_size(hdspm); /* silence everything */ all_in_all_mixer(hdspm, 0 * UNITY_GAIN); if (hdspm_is_raydat_or_aio(hdspm)) hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); /* set a default rate so that the channel map is set up. */ hdspm_set_rate(hdspm, 48000, 1); return 0; } /*------------------------------------------------------------ interrupt ------------------------------------------------------------*/ static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) { struct hdspm *hdspm = (struct hdspm *) dev_id; unsigned int status; int i, audio, midi, schedule = 0; /* cycles_t now; */ status = hdspm_read(hdspm, HDSPM_statusRegister); audio = status & HDSPM_audioIRQPending; midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending | HDSPM_midi2IRQPending | HDSPM_midi3IRQPending); /* now = get_cycles(); */ /* * LAT_2..LAT_0 period counter (win) counter (mac) * 6 4096 ~256053425 ~514672358 * 5 2048 ~128024983 ~257373821 * 4 1024 ~64023706 ~128718089 * 3 512 ~32005945 ~64385999 * 2 256 ~16003039 ~32260176 * 1 128 ~7998738 ~16194507 * 0 64 ~3998231 ~8191558 */ /* dev_info(hdspm->card->dev, "snd_hdspm_interrupt %llu @ %llx\n", now-hdspm->last_interrupt, status & 0xFFC0); hdspm->last_interrupt = now; */ if (!audio && !midi) return IRQ_NONE; hdspm_write(hdspm, HDSPM_interruptConfirmation, 0); hdspm->irq_count++; if (audio) { if (hdspm->capture_substream) snd_pcm_period_elapsed(hdspm->capture_substream); if (hdspm->playback_substream) snd_pcm_period_elapsed(hdspm->playback_substream); } if (midi) { i = 0; while (i < hdspm->midiPorts) { if ((hdspm_read(hdspm, hdspm->midi[i].statusIn) & 0xff) && (status & hdspm->midi[i].irq)) { /* we disable interrupts for this input until * processing is done */ hdspm->control_register &= ~hdspm->midi[i].ie; hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); hdspm->midi[i].pending = 1; schedule = 1; } i++; } if (schedule) queue_work(system_highpri_wq, &hdspm->midi_work); } return IRQ_HANDLED; } /*------------------------------------------------------------ pcm interface ------------------------------------------------------------*/ static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); return hdspm_hw_pointer(hdspm); } static int snd_hdspm_reset(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = hdspm->capture_substream; else other = hdspm->playback_substream; if (hdspm->running) runtime->status->hw_ptr = hdspm_hw_pointer(hdspm); else runtime->status->hw_ptr = 0; if (other) { struct snd_pcm_substream *s; struct snd_pcm_runtime *oruntime = other->runtime; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { oruntime->status->hw_ptr = runtime->status->hw_ptr; break; } } } return 0; } static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); int err; int i; pid_t this_pid; pid_t other_pid; spin_lock_irq(&hdspm->lock); if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { this_pid = hdspm->playback_pid; other_pid = hdspm->capture_pid; } else { this_pid = hdspm->capture_pid; other_pid = hdspm->playback_pid; } if (other_pid > 0 && this_pid != other_pid) { /* The other stream is open, and not by the same task as this one. Make sure that the parameters that matter are the same. */ if (params_rate(params) != hdspm->system_sample_rate) { spin_unlock_irq(&hdspm->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return -EBUSY; } if (params_period_size(params) != hdspm->period_bytes / 4) { spin_unlock_irq(&hdspm->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return -EBUSY; } } /* We're fine. */ spin_unlock_irq(&hdspm->lock); /* how to make sure that the rate matches an externally-set one ? */ spin_lock_irq(&hdspm->lock); err = hdspm_set_rate(hdspm, params_rate(params), 0); if (err < 0) { dev_info(hdspm->card->dev, "err on hdspm_set_rate: %d\n", err); spin_unlock_irq(&hdspm->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return err; } spin_unlock_irq(&hdspm->lock); err = hdspm_set_interrupt_interval(hdspm, params_period_size(params)); if (err < 0) { dev_info(hdspm->card->dev, "err on hdspm_set_interrupt_interval: %d\n", err); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return err; } /* Memory allocation, takashi's method, dont know if we should * spinlock */ /* malloc all buffer even if not enabled to get sure */ /* Update for MADI rev 204: we need to allocate for all channels, * otherwise it doesn't work at 96kHz */ err = snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES); if (err < 0) { dev_info(hdspm->card->dev, "err on snd_pcm_lib_malloc_pages: %d\n", err); return err; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { for (i = 0; i < params_channels(params); ++i) { int c = hdspm->channel_map_out[i]; if (c < 0) continue; /* just make sure */ hdspm_set_channel_dma_addr(hdspm, substream, HDSPM_pageAddressBufferOut, c); snd_hdspm_enable_out(hdspm, c, 1); } hdspm->playback_buffer = (unsigned char *) substream->runtime->dma_area; dev_dbg(hdspm->card->dev, "Allocated sample buffer for playback at %p\n", hdspm->playback_buffer); } else { for (i = 0; i < params_channels(params); ++i) { int c = hdspm->channel_map_in[i]; if (c < 0) continue; hdspm_set_channel_dma_addr(hdspm, substream, HDSPM_pageAddressBufferIn, c); snd_hdspm_enable_in(hdspm, c, 1); } hdspm->capture_buffer = (unsigned char *) substream->runtime->dma_area; dev_dbg(hdspm->card->dev, "Allocated sample buffer for capture at %p\n", hdspm->capture_buffer); } /* dev_dbg(hdspm->card->dev, "Allocated sample buffer for %s at 0x%08X\n", substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? "playback" : "capture", snd_pcm_sgbuf_get_addr(substream, 0)); */ /* dev_dbg(hdspm->card->dev, "set_hwparams: %s %d Hz, %d channels, bs = %d\n", substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? "playback" : "capture", params_rate(params), params_channels(params), params_buffer_size(params)); */ /* For AES cards, the float format bit is the same as the * preferred sync reference. Since we don't want to break * sync settings, we have to skip the remaining part of this * function. */ if (hdspm->io_type == AES32) { return 0; } /* Switch to native float format if requested */ if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) { if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT)) dev_info(hdspm->card->dev, "Switching to native 32bit LE float format.\n"); hdspm->control_register |= HDSPe_FLOAT_FORMAT; } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) { if (hdspm->control_register & HDSPe_FLOAT_FORMAT) dev_info(hdspm->card->dev, "Switching to native 32bit LE integer format.\n"); hdspm->control_register &= ~HDSPe_FLOAT_FORMAT; } hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); return 0; } static int snd_hdspm_hw_free(struct snd_pcm_substream *substream) { int i; struct hdspm *hdspm = snd_pcm_substream_chip(substream); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { /* Just disable all channels. The saving when disabling a */ /* smaller set is not worth the trouble. */ for (i = 0; i < HDSPM_MAX_CHANNELS; ++i) snd_hdspm_enable_out(hdspm, i, 0); hdspm->playback_buffer = NULL; } else { for (i = 0; i < HDSPM_MAX_CHANNELS; ++i) snd_hdspm_enable_in(hdspm, i, 0); hdspm->capture_buffer = NULL; } snd_pcm_lib_free_pages(substream); return 0; } static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info *info) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); unsigned int channel = info->channel; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (snd_BUG_ON(channel >= hdspm->max_channels_out)) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: output channel out of range (%d)\n", channel); return -EINVAL; } channel = array_index_nospec(channel, hdspm->max_channels_out); if (hdspm->channel_map_out[channel] < 0) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: output channel %d mapped out\n", channel); return -EINVAL; } info->offset = hdspm->channel_map_out[channel] * HDSPM_CHANNEL_BUFFER_BYTES; } else { if (snd_BUG_ON(channel >= hdspm->max_channels_in)) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: input channel out of range (%d)\n", channel); return -EINVAL; } channel = array_index_nospec(channel, hdspm->max_channels_in); if (hdspm->channel_map_in[channel] < 0) { dev_info(hdspm->card->dev, "snd_hdspm_channel_info: input channel %d mapped out\n", channel); return -EINVAL; } info->offset = hdspm->channel_map_in[channel] * HDSPM_CHANNEL_BUFFER_BYTES; } info->first = 0; info->step = 32; return 0; } static int snd_hdspm_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { switch (cmd) { case SNDRV_PCM_IOCTL1_RESET: return snd_hdspm_reset(substream); case SNDRV_PCM_IOCTL1_CHANNEL_INFO: { struct snd_pcm_channel_info *info = arg; return snd_hdspm_channel_info(substream, info); } default: break; } return snd_pcm_lib_ioctl(substream, cmd, arg); } static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; int running; spin_lock(&hdspm->lock); running = hdspm->running; switch (cmd) { case SNDRV_PCM_TRIGGER_START: running |= 1 << substream->stream; break; case SNDRV_PCM_TRIGGER_STOP: running &= ~(1 << substream->stream); break; default: snd_BUG(); spin_unlock(&hdspm->lock); return -EINVAL; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = hdspm->capture_substream; else other = hdspm->playback_substream; if (other) { struct snd_pcm_substream *s; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { snd_pcm_trigger_done(s, substream); if (cmd == SNDRV_PCM_TRIGGER_START) running |= 1 << s->stream; else running &= ~(1 << s->stream); goto _ok; } } if (cmd == SNDRV_PCM_TRIGGER_START) { if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) && substream->stream == SNDRV_PCM_STREAM_CAPTURE) hdspm_silence_playback(hdspm); } else { if (running && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) hdspm_silence_playback(hdspm); } } else { if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) hdspm_silence_playback(hdspm); } _ok: snd_pcm_trigger_done(substream, substream); if (!hdspm->running && running) hdspm_start_audio(hdspm); else if (hdspm->running && !running) hdspm_stop_audio(hdspm); hdspm->running = running; spin_unlock(&hdspm->lock); return 0; } static int snd_hdspm_prepare(struct snd_pcm_substream *substream) { return 0; } static const struct snd_pcm_hardware snd_hdspm_playback_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), .formats = SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ), .rate_min = 32000, .rate_max = 192000, .channels_min = 1, .channels_max = HDSPM_MAX_CHANNELS, .buffer_bytes_max = HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, .period_bytes_min = (32 * 4), .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, .periods_min = 2, .periods_max = 512, .fifo_size = 0 }; static const struct snd_pcm_hardware snd_hdspm_capture_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START), .formats = SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000), .rate_min = 32000, .rate_max = 192000, .channels_min = 1, .channels_max = HDSPM_MAX_CHANNELS, .buffer_bytes_max = HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, .period_bytes_min = (32 * 4), .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, .periods_min = 2, .periods_max = 512, .fifo_size = 0 }; static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (r->min > 96000 && r->max <= 192000) { struct snd_interval t = { .min = hdspm->qs_in_channels, .max = hdspm->qs_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->min > 48000 && r->max <= 96000) { struct snd_interval t = { .min = hdspm->ds_in_channels, .max = hdspm->ds_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->max < 64000) { struct snd_interval t = { .min = hdspm->ss_in_channels, .max = hdspm->ss_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } return 0; } static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule * rule) { struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (r->min > 96000 && r->max <= 192000) { struct snd_interval t = { .min = hdspm->qs_out_channels, .max = hdspm->qs_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->min > 48000 && r->max <= 96000) { struct snd_interval t = { .min = hdspm->ds_out_channels, .max = hdspm->ds_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->max < 64000) { struct snd_interval t = { .min = hdspm->ss_out_channels, .max = hdspm->ss_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else { } return 0; } static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule * rule) { struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (c->min >= hdspm->ss_in_channels) { struct snd_interval t = { .min = 32000, .max = 48000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdspm->qs_in_channels) { struct snd_interval t = { .min = 128000, .max = 192000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdspm->ds_in_channels) { struct snd_interval t = { .min = 64000, .max = 96000, .integer = 1, }; return snd_interval_refine(r, &t); } return 0; } static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (c->min >= hdspm->ss_out_channels) { struct snd_interval t = { .min = 32000, .max = 48000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdspm->qs_out_channels) { struct snd_interval t = { .min = 128000, .max = 192000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdspm->ds_out_channels) { struct snd_interval t = { .min = 64000, .max = 96000, .integer = 1, }; return snd_interval_refine(r, &t); } return 0; } static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned int list[3]; struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); list[0] = hdspm->qs_in_channels; list[1] = hdspm->ds_in_channels; list[2] = hdspm->ss_in_channels; return snd_interval_list(c, 3, list, 0); } static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned int list[3]; struct hdspm *hdspm = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); list[0] = hdspm->qs_out_channels; list[1] = hdspm->ds_out_channels; list[2] = hdspm->ss_out_channels; return snd_interval_list(c, 3, list, 0); } static const unsigned int hdspm_aes32_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 }; static const struct snd_pcm_hw_constraint_list hdspm_hw_constraints_aes32_sample_rates = { .count = ARRAY_SIZE(hdspm_aes32_sample_rates), .list = hdspm_aes32_sample_rates, .mask = 0 }; static int snd_hdspm_open(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); spin_lock_irq(&hdspm->lock); snd_pcm_set_sync(substream); runtime->hw = (playback) ? snd_hdspm_playback_subinfo : snd_hdspm_capture_subinfo; if (playback) { if (!hdspm->capture_substream) hdspm_stop_audio(hdspm); hdspm->playback_pid = current->pid; hdspm->playback_substream = substream; } else { if (!hdspm->playback_substream) hdspm_stop_audio(hdspm); hdspm->capture_pid = current->pid; hdspm->capture_substream = substream; } spin_unlock_irq(&hdspm->lock); snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); switch (hdspm->io_type) { case AIO: case RayDAT: snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32, 4096); /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */ snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 16384); break; default: snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 64, 8192); snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIODS, 2); break; } if (AES32 == hdspm->io_type) { runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdspm_hw_constraints_aes32_sample_rates); } else { snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, (playback ? snd_hdspm_hw_rule_rate_out_channels : snd_hdspm_hw_rule_rate_in_channels), hdspm, SNDRV_PCM_HW_PARAM_CHANNELS, -1); } snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, (playback ? snd_hdspm_hw_rule_out_channels : snd_hdspm_hw_rule_in_channels), hdspm, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, (playback ? snd_hdspm_hw_rule_out_channels_rate : snd_hdspm_hw_rule_in_channels_rate), hdspm, SNDRV_PCM_HW_PARAM_RATE, -1); return 0; } static int snd_hdspm_release(struct snd_pcm_substream *substream) { struct hdspm *hdspm = snd_pcm_substream_chip(substream); bool playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); spin_lock_irq(&hdspm->lock); if (playback) { hdspm->playback_pid = -1; hdspm->playback_substream = NULL; } else { hdspm->capture_pid = -1; hdspm->capture_substream = NULL; } spin_unlock_irq(&hdspm->lock); return 0; } static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) { /* we have nothing to initialize but the call is required */ return 0; } static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; struct hdspm *hdspm = hw->private_data; struct hdspm_mixer_ioctl mixer; struct hdspm_config info; struct hdspm_status status; struct hdspm_version hdspm_version; struct hdspm_peak_rms *levels; struct hdspm_ltc ltc; unsigned int statusregister; long unsigned int s; int i = 0; switch (cmd) { case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: levels = &hdspm->peak_rms; for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { levels->input_peaks[i] = readl(hdspm->iobase + HDSPM_MADI_INPUT_PEAK + i*4); levels->playback_peaks[i] = readl(hdspm->iobase + HDSPM_MADI_PLAYBACK_PEAK + i*4); levels->output_peaks[i] = readl(hdspm->iobase + HDSPM_MADI_OUTPUT_PEAK + i*4); levels->input_rms[i] = ((uint64_t) readl(hdspm->iobase + HDSPM_MADI_INPUT_RMS_H + i*4) << 32) | (uint64_t) readl(hdspm->iobase + HDSPM_MADI_INPUT_RMS_L + i*4); levels->playback_rms[i] = ((uint64_t)readl(hdspm->iobase + HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) | (uint64_t)readl(hdspm->iobase + HDSPM_MADI_PLAYBACK_RMS_L + i*4); levels->output_rms[i] = ((uint64_t)readl(hdspm->iobase + HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) | (uint64_t)readl(hdspm->iobase + HDSPM_MADI_OUTPUT_RMS_L + i*4); } if (hdspm->system_sample_rate > 96000) { levels->speed = qs; } else if (hdspm->system_sample_rate > 48000) { levels->speed = ds; } else { levels->speed = ss; } levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2); s = copy_to_user(argp, levels, sizeof(*levels)); if (0 != s) { /* dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu [Levels]\n", sizeof(struct hdspm_peak_rms), s); */ return -EFAULT; } break; case SNDRV_HDSPM_IOCTL_GET_LTC: ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO); i = hdspm_read(hdspm, HDSPM_RD_TCO + 4); if (i & HDSPM_TCO1_LTC_Input_valid) { switch (i & (HDSPM_TCO1_LTC_Format_LSB | HDSPM_TCO1_LTC_Format_MSB)) { case 0: ltc.format = fps_24; break; case HDSPM_TCO1_LTC_Format_LSB: ltc.format = fps_25; break; case HDSPM_TCO1_LTC_Format_MSB: ltc.format = fps_2997; break; default: ltc.format = fps_30; break; } if (i & HDSPM_TCO1_set_drop_frame_flag) { ltc.frame = drop_frame; } else { ltc.frame = full_frame; } } else { ltc.format = format_invalid; ltc.frame = frame_invalid; } if (i & HDSPM_TCO1_Video_Input_Format_NTSC) { ltc.input_format = ntsc; } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) { ltc.input_format = pal; } else { ltc.input_format = no_video; } s = copy_to_user(argp, &ltc, sizeof(ltc)); if (0 != s) { /* dev_err(hdspm->card->dev, "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */ return -EFAULT; } break; case SNDRV_HDSPM_IOCTL_GET_CONFIG: memset(&info, 0, sizeof(info)); spin_lock_irq(&hdspm->lock); info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); info.system_sample_rate = hdspm->system_sample_rate; info.autosync_sample_rate = hdspm_external_sample_rate(hdspm); info.system_clock_mode = hdspm_system_clock_mode(hdspm); info.clock_source = hdspm_clock_source(hdspm); info.autosync_ref = hdspm_autosync_ref(hdspm); info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut); info.passthru = 0; spin_unlock_irq(&hdspm->lock); if (copy_to_user(argp, &info, sizeof(info))) return -EFAULT; break; case SNDRV_HDSPM_IOCTL_GET_STATUS: memset(&status, 0, sizeof(status)); status.card_type = hdspm->io_type; status.autosync_source = hdspm_autosync_ref(hdspm); status.card_clock = 110069313433624ULL; status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); switch (hdspm->io_type) { case MADI: case MADIface: status.card_specific.madi.sync_wc = hdspm_wc_sync_check(hdspm); status.card_specific.madi.sync_madi = hdspm_madi_sync_check(hdspm); status.card_specific.madi.sync_tco = hdspm_tco_sync_check(hdspm); status.card_specific.madi.sync_in = hdspm_sync_in_sync_check(hdspm); statusregister = hdspm_read(hdspm, HDSPM_statusRegister); status.card_specific.madi.madi_input = (statusregister & HDSPM_AB_int) ? 1 : 0; status.card_specific.madi.channel_format = (statusregister & HDSPM_RX_64ch) ? 1 : 0; /* TODO: Mac driver sets it when f_s>48kHz */ status.card_specific.madi.frame_format = 0; break; default: break; } if (copy_to_user(argp, &status, sizeof(status))) return -EFAULT; break; case SNDRV_HDSPM_IOCTL_GET_VERSION: memset(&hdspm_version, 0, sizeof(hdspm_version)); hdspm_version.card_type = hdspm->io_type; strscpy(hdspm_version.cardname, hdspm->card_name, sizeof(hdspm_version.cardname)); hdspm_version.serial = hdspm->serial; hdspm_version.firmware_rev = hdspm->firmware_rev; hdspm_version.addons = 0; if (hdspm->tco) hdspm_version.addons |= HDSPM_ADDON_TCO; if (copy_to_user(argp, &hdspm_version, sizeof(hdspm_version))) return -EFAULT; break; case SNDRV_HDSPM_IOCTL_GET_MIXER: if (copy_from_user(&mixer, argp, sizeof(mixer))) return -EFAULT; if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, sizeof(*mixer.mixer))) return -EFAULT; break; default: return -EINVAL; } return 0; } static const struct snd_pcm_ops snd_hdspm_ops = { .open = snd_hdspm_open, .close = snd_hdspm_release, .ioctl = snd_hdspm_ioctl, .hw_params = snd_hdspm_hw_params, .hw_free = snd_hdspm_hw_free, .prepare = snd_hdspm_prepare, .trigger = snd_hdspm_trigger, .pointer = snd_hdspm_hw_pointer, }; static int snd_hdspm_create_hwdep(struct snd_card *card, struct hdspm *hdspm) { struct snd_hwdep *hw; int err; err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw); if (err < 0) return err; hdspm->hwdep = hw; hw->private_data = hdspm; strcpy(hw->name, "HDSPM hwdep interface"); hw->ops.open = snd_hdspm_hwdep_dummy_op; hw->ops.ioctl = snd_hdspm_hwdep_ioctl; hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl; hw->ops.release = snd_hdspm_hwdep_dummy_op; return 0; } /*------------------------------------------------------------ memory interface ------------------------------------------------------------*/ static int snd_hdspm_preallocate_memory(struct hdspm *hdspm) { struct snd_pcm *pcm; size_t wanted; pcm = hdspm->pcm; wanted = HDSPM_DMA_AREA_BYTES; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, &hdspm->pci->dev, wanted, wanted); dev_dbg(hdspm->card->dev, " Preallocated %zd Bytes\n", wanted); return 0; } /* Inform the card what DMA addresses to use for the indicated channel. */ /* Each channel got 16 4K pages allocated for DMA transfers. */ static void hdspm_set_channel_dma_addr(struct hdspm *hdspm, struct snd_pcm_substream *substream, unsigned int reg, int channel) { int i; for (i = channel * 16; i < channel * 16 + 16; i++) hdspm_write(hdspm, reg + 4 * i, snd_pcm_sgbuf_get_addr(substream, 4096 * i)); } /* ------------- ALSA Devices ---------------------------- */ static int snd_hdspm_create_pcm(struct snd_card *card, struct hdspm *hdspm) { struct snd_pcm *pcm; int err; err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm); if (err < 0) return err; hdspm->pcm = pcm; pcm->private_data = hdspm; strcpy(pcm->name, hdspm->card_name); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdspm_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdspm_ops); pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; err = snd_hdspm_preallocate_memory(hdspm); if (err < 0) return err; return 0; } static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm) { int i; for (i = 0; i < hdspm->midiPorts; i++) snd_hdspm_flush_midi_input(hdspm, i); } static int snd_hdspm_create_alsa_devices(struct snd_card *card, struct hdspm *hdspm) { int err, i; dev_dbg(card->dev, "Create card...\n"); err = snd_hdspm_create_pcm(card, hdspm); if (err < 0) return err; i = 0; while (i < hdspm->midiPorts) { err = snd_hdspm_create_midi(card, hdspm, i); if (err < 0) { return err; } i++; } err = snd_hdspm_create_controls(card, hdspm); if (err < 0) return err; err = snd_hdspm_create_hwdep(card, hdspm); if (err < 0) return err; dev_dbg(card->dev, "proc init...\n"); snd_hdspm_proc_init(hdspm); hdspm->system_sample_rate = -1; hdspm->last_external_sample_rate = -1; hdspm->last_internal_sample_rate = -1; hdspm->playback_pid = -1; hdspm->capture_pid = -1; hdspm->capture_substream = NULL; hdspm->playback_substream = NULL; dev_dbg(card->dev, "Set defaults...\n"); err = snd_hdspm_set_defaults(hdspm); if (err < 0) return err; dev_dbg(card->dev, "Update mixer controls...\n"); hdspm_update_simple_mixer_controls(hdspm); dev_dbg(card->dev, "Initializing complete?\n"); err = snd_card_register(card); if (err < 0) { dev_err(card->dev, "error registering card\n"); return err; } dev_dbg(card->dev, "... yes now\n"); return 0; } static int snd_hdspm_create(struct snd_card *card, struct hdspm *hdspm) { struct pci_dev *pci = hdspm->pci; int err; unsigned long io_extent; hdspm->irq = -1; hdspm->card = card; spin_lock_init(&hdspm->lock); INIT_WORK(&hdspm->midi_work, hdspm_midi_work); pci_read_config_word(hdspm->pci, PCI_CLASS_REVISION, &hdspm->firmware_rev); strcpy(card->mixername, "Xilinx FPGA"); strcpy(card->driver, "HDSPM"); switch (hdspm->firmware_rev) { case HDSPM_RAYDAT_REV: hdspm->io_type = RayDAT; hdspm->card_name = "RME RayDAT"; hdspm->midiPorts = 2; break; case HDSPM_AIO_REV: hdspm->io_type = AIO; hdspm->card_name = "RME AIO"; hdspm->midiPorts = 1; break; case HDSPM_MADIFACE_REV: hdspm->io_type = MADIface; hdspm->card_name = "RME MADIface"; hdspm->midiPorts = 1; break; default: if ((hdspm->firmware_rev == 0xf0) || ((hdspm->firmware_rev >= 0xe6) && (hdspm->firmware_rev <= 0xea))) { hdspm->io_type = AES32; hdspm->card_name = "RME AES32"; hdspm->midiPorts = 2; } else if ((hdspm->firmware_rev == 0xd2) || ((hdspm->firmware_rev >= 0xc8) && (hdspm->firmware_rev <= 0xcf))) { hdspm->io_type = MADI; hdspm->card_name = "RME MADI"; hdspm->midiPorts = 3; } else { dev_err(card->dev, "unknown firmware revision %x\n", hdspm->firmware_rev); return -ENODEV; } } err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(hdspm->pci); err = pcim_iomap_regions(pci, 1 << 0, "hdspm"); if (err < 0) return err; hdspm->port = pci_resource_start(pci, 0); io_extent = pci_resource_len(pci, 0); hdspm->iobase = pcim_iomap_table(pci)[0]; dev_dbg(card->dev, "remapped region (0x%lx) 0x%lx-0x%lx\n", (unsigned long)hdspm->iobase, hdspm->port, hdspm->port + io_extent - 1); if (devm_request_irq(&pci->dev, pci->irq, snd_hdspm_interrupt, IRQF_SHARED, KBUILD_MODNAME, hdspm)) { dev_err(card->dev, "unable to use IRQ %d\n", pci->irq); return -EBUSY; } dev_dbg(card->dev, "use IRQ %d\n", pci->irq); hdspm->irq = pci->irq; card->sync_irq = hdspm->irq; dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n", sizeof(*hdspm->mixer)); hdspm->mixer = devm_kzalloc(&pci->dev, sizeof(*hdspm->mixer), GFP_KERNEL); if (!hdspm->mixer) return -ENOMEM; hdspm->port_names_in = NULL; hdspm->port_names_out = NULL; switch (hdspm->io_type) { case AES32: hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS; hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS; hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS; hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = channel_map_aes32; hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = channel_map_aes32; hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = channel_map_aes32; hdspm->port_names_in_ss = hdspm->port_names_out_ss = texts_ports_aes32; hdspm->port_names_in_ds = hdspm->port_names_out_ds = texts_ports_aes32; hdspm->port_names_in_qs = hdspm->port_names_out_qs = texts_ports_aes32; hdspm->max_channels_out = hdspm->max_channels_in = AES32_CHANNELS; hdspm->port_names_in = hdspm->port_names_out = texts_ports_aes32; hdspm->channel_map_in = hdspm->channel_map_out = channel_map_aes32; break; case MADI: case MADIface: hdspm->ss_in_channels = hdspm->ss_out_channels = MADI_SS_CHANNELS; hdspm->ds_in_channels = hdspm->ds_out_channels = MADI_DS_CHANNELS; hdspm->qs_in_channels = hdspm->qs_out_channels = MADI_QS_CHANNELS; hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = channel_map_unity_ss; hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = channel_map_unity_ss; hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = channel_map_unity_ss; hdspm->port_names_in_ss = hdspm->port_names_out_ss = texts_ports_madi; hdspm->port_names_in_ds = hdspm->port_names_out_ds = texts_ports_madi; hdspm->port_names_in_qs = hdspm->port_names_out_qs = texts_ports_madi; break; case AIO: hdspm->ss_in_channels = AIO_IN_SS_CHANNELS; hdspm->ds_in_channels = AIO_IN_DS_CHANNELS; hdspm->qs_in_channels = AIO_IN_QS_CHANNELS; hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS; hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS; hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS; if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) { dev_info(card->dev, "AEB input board found\n"); hdspm->ss_in_channels += 4; hdspm->ds_in_channels += 4; hdspm->qs_in_channels += 4; } if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBO_D)) { dev_info(card->dev, "AEB output board found\n"); hdspm->ss_out_channels += 4; hdspm->ds_out_channels += 4; hdspm->qs_out_channels += 4; } hdspm->channel_map_out_ss = channel_map_aio_out_ss; hdspm->channel_map_out_ds = channel_map_aio_out_ds; hdspm->channel_map_out_qs = channel_map_aio_out_qs; hdspm->channel_map_in_ss = channel_map_aio_in_ss; hdspm->channel_map_in_ds = channel_map_aio_in_ds; hdspm->channel_map_in_qs = channel_map_aio_in_qs; hdspm->port_names_in_ss = texts_ports_aio_in_ss; hdspm->port_names_out_ss = texts_ports_aio_out_ss; hdspm->port_names_in_ds = texts_ports_aio_in_ds; hdspm->port_names_out_ds = texts_ports_aio_out_ds; hdspm->port_names_in_qs = texts_ports_aio_in_qs; hdspm->port_names_out_qs = texts_ports_aio_out_qs; break; case RayDAT: hdspm->ss_in_channels = hdspm->ss_out_channels = RAYDAT_SS_CHANNELS; hdspm->ds_in_channels = hdspm->ds_out_channels = RAYDAT_DS_CHANNELS; hdspm->qs_in_channels = hdspm->qs_out_channels = RAYDAT_QS_CHANNELS; hdspm->max_channels_in = RAYDAT_SS_CHANNELS; hdspm->max_channels_out = RAYDAT_SS_CHANNELS; hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = channel_map_raydat_ss; hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = channel_map_raydat_ds; hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = channel_map_raydat_qs; hdspm->channel_map_in = hdspm->channel_map_out = channel_map_raydat_ss; hdspm->port_names_in_ss = hdspm->port_names_out_ss = texts_ports_raydat_ss; hdspm->port_names_in_ds = hdspm->port_names_out_ds = texts_ports_raydat_ds; hdspm->port_names_in_qs = hdspm->port_names_out_qs = texts_ports_raydat_qs; break; } /* TCO detection */ switch (hdspm->io_type) { case AIO: case RayDAT: if (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_tco_detect) { hdspm->midiPorts++; hdspm->tco = kzalloc(sizeof(*hdspm->tco), GFP_KERNEL); if (hdspm->tco) hdspm_tco_write(hdspm); dev_info(card->dev, "AIO/RayDAT TCO module found\n"); } else { hdspm->tco = NULL; } break; case MADI: case AES32: if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) { hdspm->midiPorts++; hdspm->tco = kzalloc(sizeof(*hdspm->tco), GFP_KERNEL); if (hdspm->tco) hdspm_tco_write(hdspm); dev_info(card->dev, "MADI/AES TCO module found\n"); } else { hdspm->tco = NULL; } break; default: hdspm->tco = NULL; } /* texts */ switch (hdspm->io_type) { case AES32: if (hdspm->tco) { hdspm->texts_autosync = texts_autosync_aes_tco; hdspm->texts_autosync_items = ARRAY_SIZE(texts_autosync_aes_tco); } else { hdspm->texts_autosync = texts_autosync_aes; hdspm->texts_autosync_items = ARRAY_SIZE(texts_autosync_aes); } break; case MADI: if (hdspm->tco) { hdspm->texts_autosync = texts_autosync_madi_tco; hdspm->texts_autosync_items = 4; } else { hdspm->texts_autosync = texts_autosync_madi; hdspm->texts_autosync_items = 3; } break; case MADIface: break; case RayDAT: if (hdspm->tco) { hdspm->texts_autosync = texts_autosync_raydat_tco; hdspm->texts_autosync_items = 9; } else { hdspm->texts_autosync = texts_autosync_raydat; hdspm->texts_autosync_items = 8; } break; case AIO: if (hdspm->tco) { hdspm->texts_autosync = texts_autosync_aio_tco; hdspm->texts_autosync_items = 6; } else { hdspm->texts_autosync = texts_autosync_aio; hdspm->texts_autosync_items = 5; } break; } if (hdspm->io_type != MADIface) { hdspm->serial = (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF; /* id contains either a user-provided value or the default * NULL. If it's the default, we're safe to * fill card->id with the serial number. * * If the serial number is 0xFFFFFF, then we're dealing with * an old PCI revision that comes without a sane number. In * this case, we don't set card->id to avoid collisions * when running with multiple cards. */ if (!id[hdspm->dev] && hdspm->serial != 0xFFFFFF) { snprintf(card->id, sizeof(card->id), "HDSPMx%06x", hdspm->serial); snd_card_set_id(card, card->id); } } dev_dbg(card->dev, "create alsa devices.\n"); err = snd_hdspm_create_alsa_devices(card, hdspm); if (err < 0) return err; snd_hdspm_initialize_midi_flush(hdspm); return 0; } static void snd_hdspm_card_free(struct snd_card *card) { struct hdspm *hdspm = card->private_data; if (hdspm->port) { cancel_work_sync(&hdspm->midi_work); /* stop th audio, and cancel all interrupts */ hdspm->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable | HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable | HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable); hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); } } static int snd_hdspm_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct hdspm *hdspm; struct snd_card *card; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*hdspm), &card); if (err < 0) return err; hdspm = card->private_data; card->private_free = snd_hdspm_card_free; hdspm->dev = dev; hdspm->pci = pci; err = snd_hdspm_create(card, hdspm); if (err < 0) goto error; if (hdspm->io_type != MADIface) { snprintf(card->shortname, sizeof(card->shortname), "%s_%x", hdspm->card_name, hdspm->serial); snprintf(card->longname, sizeof(card->longname), "%s S/N 0x%x at 0x%lx, irq %d", hdspm->card_name, hdspm->serial, hdspm->port, hdspm->irq); } else { snprintf(card->shortname, sizeof(card->shortname), "%s", hdspm->card_name); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx, irq %d", hdspm->card_name, hdspm->port, hdspm->irq); } err = snd_card_register(card); if (err < 0) goto error; pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver hdspm_driver = { .name = KBUILD_MODNAME, .id_table = snd_hdspm_ids, .probe = snd_hdspm_probe, }; module_pci_driver(hdspm_driver);
linux-master
sound/pci/rme9652/hdspm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA driver for RME Hammerfall DSP audio interface(s) * * Copyright (c) 2002 Paul Davis * Marcus Andersson * Thomas Charbonnel */ #include <linux/init.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/firmware.h> #include <linux/module.h> #include <linux/math64.h> #include <linux/vmalloc.h> #include <linux/io.h> #include <linux/nospec.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/info.h> #include <sound/asoundef.h> #include <sound/rawmidi.h> #include <sound/hwdep.h> #include <sound/initval.h> #include <sound/hdsp.h> #include <asm/byteorder.h> #include <asm/current.h> static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards."); MODULE_AUTHOR("Paul Davis <[email protected]>, Marcus Andersson, Thomas Charbonnel <[email protected]>"); MODULE_DESCRIPTION("RME Hammerfall DSP"); MODULE_LICENSE("GPL"); MODULE_FIRMWARE("rpm_firmware.bin"); MODULE_FIRMWARE("multiface_firmware.bin"); MODULE_FIRMWARE("multiface_firmware_rev11.bin"); MODULE_FIRMWARE("digiface_firmware.bin"); MODULE_FIRMWARE("digiface_firmware_rev11.bin"); #define HDSP_MAX_CHANNELS 26 #define HDSP_MAX_DS_CHANNELS 14 #define HDSP_MAX_QS_CHANNELS 8 #define DIGIFACE_SS_CHANNELS 26 #define DIGIFACE_DS_CHANNELS 14 #define MULTIFACE_SS_CHANNELS 18 #define MULTIFACE_DS_CHANNELS 14 #define H9652_SS_CHANNELS 26 #define H9652_DS_CHANNELS 14 /* This does not include possible Analog Extension Boards AEBs are detected at card initialization */ #define H9632_SS_CHANNELS 12 #define H9632_DS_CHANNELS 8 #define H9632_QS_CHANNELS 4 #define RPM_CHANNELS 6 /* Write registers. These are defined as byte-offsets from the iobase value. */ #define HDSP_resetPointer 0 #define HDSP_freqReg 0 #define HDSP_outputBufferAddress 32 #define HDSP_inputBufferAddress 36 #define HDSP_controlRegister 64 #define HDSP_interruptConfirmation 96 #define HDSP_outputEnable 128 #define HDSP_control2Reg 256 #define HDSP_midiDataOut0 352 #define HDSP_midiDataOut1 356 #define HDSP_fifoData 368 #define HDSP_inputEnable 384 /* Read registers. These are defined as byte-offsets from the iobase value */ #define HDSP_statusRegister 0 #define HDSP_timecode 128 #define HDSP_status2Register 192 #define HDSP_midiDataIn0 360 #define HDSP_midiDataIn1 364 #define HDSP_midiStatusOut0 384 #define HDSP_midiStatusOut1 388 #define HDSP_midiStatusIn0 392 #define HDSP_midiStatusIn1 396 #define HDSP_fifoStatus 400 /* the meters are regular i/o-mapped registers, but offset considerably from the rest. the peak registers are reset when read; the least-significant 4 bits are full-scale counters; the actual peak value is in the most-significant 24 bits. */ #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */ #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */ #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */ #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */ #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */ /* This is for H9652 cards Peak values are read downward from the base Rms values are read upward There are rms values for the outputs too 26*3 values are read in ss mode 14*3 in ds mode, with no gap between values */ #define HDSP_9652_peakBase 7164 #define HDSP_9652_rmsBase 4096 /* c.f. the hdsp_9632_meters_t struct */ #define HDSP_9632_metersBase 4096 #define HDSP_IO_EXTENT 7168 /* control2 register bits */ #define HDSP_TMS 0x01 #define HDSP_TCK 0x02 #define HDSP_TDI 0x04 #define HDSP_JTAG 0x08 #define HDSP_PWDN 0x10 #define HDSP_PROGRAM 0x020 #define HDSP_CONFIG_MODE_0 0x040 #define HDSP_CONFIG_MODE_1 0x080 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD) #define HDSP_BIGENDIAN_MODE 0x200 #define HDSP_RD_MULTIPLE 0x400 #define HDSP_9652_ENABLE_MIXER 0x800 #define HDSP_S200 0x800 #define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */ #define HDSP_CYCLIC_MODE 0x1000 #define HDSP_TDO 0x10000000 #define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0) #define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1) /* Control Register bits */ #define HDSP_Start (1<<0) /* start engine */ #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */ #define HDSP_Latency1 (1<<2) /* [ see above ] */ #define HDSP_Latency2 (1<<3) /* [ see above ] */ #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */ #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */ #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */ #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */ #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */ #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */ #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */ #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */ #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */ #define HDSP_SyncRef2 (1<<13) #define HDSP_SPDIFInputSelect0 (1<<14) #define HDSP_SPDIFInputSelect1 (1<<15) #define HDSP_SyncRef0 (1<<16) #define HDSP_SyncRef1 (1<<17) #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */ #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */ #define HDSP_Midi0InterruptEnable (1<<22) #define HDSP_Midi1InterruptEnable (1<<23) #define HDSP_LineOut (1<<24) #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */ #define HDSP_ADGain1 (1<<26) #define HDSP_DAGain0 (1<<27) #define HDSP_DAGain1 (1<<28) #define HDSP_PhoneGain0 (1<<29) #define HDSP_PhoneGain1 (1<<30) #define HDSP_QuadSpeed (1<<31) /* RPM uses some of the registers for special purposes */ #define HDSP_RPM_Inp12 0x04A00 #define HDSP_RPM_Inp12_Phon_6dB 0x00800 /* Dolby */ #define HDSP_RPM_Inp12_Phon_0dB 0x00000 /* .. */ #define HDSP_RPM_Inp12_Phon_n6dB 0x04000 /* inp_0 */ #define HDSP_RPM_Inp12_Line_0dB 0x04200 /* Dolby+PRO */ #define HDSP_RPM_Inp12_Line_n6dB 0x00200 /* PRO */ #define HDSP_RPM_Inp34 0x32000 #define HDSP_RPM_Inp34_Phon_6dB 0x20000 /* SyncRef1 */ #define HDSP_RPM_Inp34_Phon_0dB 0x00000 /* .. */ #define HDSP_RPM_Inp34_Phon_n6dB 0x02000 /* SyncRef2 */ #define HDSP_RPM_Inp34_Line_0dB 0x30000 /* SyncRef1+SyncRef0 */ #define HDSP_RPM_Inp34_Line_n6dB 0x10000 /* SyncRef0 */ #define HDSP_RPM_Bypass 0x01000 #define HDSP_RPM_Disconnect 0x00001 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1) #define HDSP_ADGainMinus10dBV HDSP_ADGainMask #define HDSP_ADGainPlus4dBu (HDSP_ADGain0) #define HDSP_ADGainLowGain 0 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1) #define HDSP_DAGainHighGain HDSP_DAGainMask #define HDSP_DAGainPlus4dBu (HDSP_DAGain0) #define HDSP_DAGainMinus10dBV 0 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1) #define HDSP_PhoneGain0dB HDSP_PhoneGainMask #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0) #define HDSP_PhoneGainMinus12dB 0 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2) #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed) #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1) #define HDSP_SPDIFInputADAT1 0 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0) #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1) #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1) #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2) #define HDSP_SyncRef_ADAT1 0 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0) #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1) #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1) #define HDSP_SyncRef_WORD (HDSP_SyncRef2) #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2) /* Sample Clock Sources */ #define HDSP_CLOCK_SOURCE_AUTOSYNC 0 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */ #define HDSP_SYNC_FROM_WORD 0 #define HDSP_SYNC_FROM_SPDIF 1 #define HDSP_SYNC_FROM_ADAT1 2 #define HDSP_SYNC_FROM_ADAT_SYNC 3 #define HDSP_SYNC_FROM_ADAT2 4 #define HDSP_SYNC_FROM_ADAT3 5 /* SyncCheck status */ #define HDSP_SYNC_CHECK_NO_LOCK 0 #define HDSP_SYNC_CHECK_LOCK 1 #define HDSP_SYNC_CHECK_SYNC 2 /* AutoSync references - used by "autosync_ref" control switch */ #define HDSP_AUTOSYNC_FROM_WORD 0 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1 #define HDSP_AUTOSYNC_FROM_SPDIF 2 #define HDSP_AUTOSYNC_FROM_NONE 3 #define HDSP_AUTOSYNC_FROM_ADAT1 4 #define HDSP_AUTOSYNC_FROM_ADAT2 5 #define HDSP_AUTOSYNC_FROM_ADAT3 6 /* Possible sources of S/PDIF input */ #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */ #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */ #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */ #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/ #define HDSP_Frequency32KHz HDSP_Frequency0 #define HDSP_Frequency44_1KHz HDSP_Frequency1 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0) #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0) #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1) #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0) /* For H9632 cards */ #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0) #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1) #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0) /* RME says n = 104857600000000, but in the windows MADI driver, I see: return 104857600000000 / rate; // 100 MHz return 110100480000000 / rate; // 105 MHz */ #define DDS_NUMERATOR 104857600000000ULL /* = 2^20 * 10^8 */ #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask) #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1) #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14) #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3) /* Status Register bits */ #define HDSP_audioIRQPending (1<<0) #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */ #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */ #define HDSP_Lock1 (1<<2) #define HDSP_Lock0 (1<<3) #define HDSP_SPDIFSync (1<<4) #define HDSP_TimecodeLock (1<<5) #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ #define HDSP_Sync2 (1<<16) #define HDSP_Sync1 (1<<17) #define HDSP_Sync0 (1<<18) #define HDSP_DoubleSpeedStatus (1<<19) #define HDSP_ConfigError (1<<20) #define HDSP_DllError (1<<21) #define HDSP_spdifFrequency0 (1<<22) #define HDSP_spdifFrequency1 (1<<23) #define HDSP_spdifFrequency2 (1<<24) #define HDSP_SPDIFErrorFlag (1<<25) #define HDSP_BufferID (1<<26) #define HDSP_TimecodeSync (1<<27) #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */ #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */ #define HDSP_midi0IRQPending (1<<30) #define HDSP_midi1IRQPending (1<<31) #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2) #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\ HDSP_spdifFrequency1|\ HDSP_spdifFrequency2|\ HDSP_spdifFrequency3) #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0) #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1) #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1) #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2) #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2) #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1) /* This is for H9632 cards */ #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\ HDSP_spdifFrequency1|\ HDSP_spdifFrequency2) #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0) /* Status2 Register bits */ #define HDSP_version0 (1<<0) #define HDSP_version1 (1<<1) #define HDSP_version2 (1<<2) #define HDSP_wc_lock (1<<3) #define HDSP_wc_sync (1<<4) #define HDSP_inp_freq0 (1<<5) #define HDSP_inp_freq1 (1<<6) #define HDSP_inp_freq2 (1<<7) #define HDSP_SelSyncRef0 (1<<8) #define HDSP_SelSyncRef1 (1<<9) #define HDSP_SelSyncRef2 (1<<10) #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync) #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2) #define HDSP_systemFrequency32 (HDSP_inp_freq0) #define HDSP_systemFrequency44_1 (HDSP_inp_freq1) #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1) #define HDSP_systemFrequency64 (HDSP_inp_freq2) #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2) #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2) /* FIXME : more values for 9632 cards ? */ #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2) #define HDSP_SelSyncRef_ADAT1 0 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0) #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1) #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1) #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2) #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2) /* Card state flags */ #define HDSP_InitializationComplete (1<<0) #define HDSP_FirmwareLoaded (1<<1) #define HDSP_FirmwareCached (1<<2) /* FIFO wait times, defined in terms of 1/10ths of msecs */ #define HDSP_LONG_WAIT 5000 #define HDSP_SHORT_WAIT 30 #define UNITY_GAIN 32768 #define MINUS_INFINITY_GAIN 0 /* the size of a substream (1 mono data stream) */ #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024) #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES) /* the size of the area we need to allocate for DMA transfers. the size is the same regardless of the number of channels - the Multiface still uses the same memory area. Note that we allocate 1 more channel than is apparently needed because the h/w seems to write 1 byte beyond the end of the last page. Sigh. */ #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES) #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024) #define HDSP_FIRMWARE_SIZE (24413 * 4) struct hdsp_9632_meters { u32 input_peak[16]; u32 playback_peak[16]; u32 output_peak[16]; u32 xxx_peak[16]; u32 padding[64]; u32 input_rms_low[16]; u32 playback_rms_low[16]; u32 output_rms_low[16]; u32 xxx_rms_low[16]; u32 input_rms_high[16]; u32 playback_rms_high[16]; u32 output_rms_high[16]; u32 xxx_rms_high[16]; }; struct hdsp_midi { struct hdsp *hdsp; int id; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *input; struct snd_rawmidi_substream *output; signed char istimer; /* timer in use */ struct timer_list timer; spinlock_t lock; int pending; }; struct hdsp { spinlock_t lock; struct snd_pcm_substream *capture_substream; struct snd_pcm_substream *playback_substream; struct hdsp_midi midi[2]; struct work_struct midi_work; int use_midi_work; int precise_ptr; u32 control_register; /* cached value */ u32 control2_register; /* cached value */ u32 creg_spdif; u32 creg_spdif_stream; int clock_source_locked; char *card_name; /* digiface/multiface/rpm */ enum HDSP_IO_Type io_type; /* ditto, but for code use */ unsigned short firmware_rev; unsigned short state; /* stores state bits */ const struct firmware *firmware; u32 *fw_uploaded; size_t period_bytes; /* guess what this is */ unsigned char max_channels; unsigned char qs_in_channels; /* quad speed mode for H9632 */ unsigned char ds_in_channels; unsigned char ss_in_channels; /* different for multiface/digiface */ unsigned char qs_out_channels; unsigned char ds_out_channels; unsigned char ss_out_channels; u32 io_loopback; /* output loopback channel states*/ /* DMA buffers; those are copied instances from the original snd_dma_buf * objects (which are managed via devres) for the address alignments */ struct snd_dma_buffer capture_dma_buf; struct snd_dma_buffer playback_dma_buf; unsigned char *capture_buffer; /* suitably aligned address */ unsigned char *playback_buffer; /* suitably aligned address */ pid_t capture_pid; pid_t playback_pid; int running; int system_sample_rate; const signed char *channel_map; int dev; int irq; unsigned long port; void __iomem *iobase; struct snd_card *card; struct snd_pcm *pcm; struct snd_hwdep *hwdep; struct pci_dev *pci; struct snd_kcontrol *spdif_ctl; unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE]; unsigned int dds_value; /* last value written to freq register */ }; /* These tables map the ALSA channels 1..N to the channels that we need to use in order to find the relevant channel buffer. RME refer to this kind of mapping as between "the ADAT channel and the DMA channel." We index it using the logical audio channel, and the value is the DMA channel (i.e. channel buffer number) where the data for that channel can be read/written from/to. */ static const signed char channel_map_df_ss[HDSP_MAX_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; static const char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */ /* Analog */ 0, 1, 2, 3, 4, 5, 6, 7, /* ADAT 2 */ 16, 17, 18, 19, 20, 21, 22, 23, /* SPDIF */ 24, 25, -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_ds[HDSP_MAX_CHANNELS] = { /* ADAT channels are remapped */ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, /* channels 12 and 13 are S/PDIF */ 24, 25, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = { /* ADAT channels */ 0, 1, 2, 3, 4, 5, 6, 7, /* SPDIF */ 8, 9, /* Analog */ 10, 11, /* AO4S-192 and AI4S-192 extension boards */ 12, 13, 14, 15, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = { /* ADAT */ 1, 3, 5, 7, /* SPDIF */ 8, 9, /* Analog */ 10, 11, /* AO4S-192 and AI4S-192 extension boards */ 12, 13, 14, 15, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = { /* ADAT is disabled in this mode */ /* SPDIF */ 8, 9, /* Analog */ 10, 11, /* AO4S-192 and AI4S-192 extension boards */ 12, 13, 14, 15, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static struct snd_dma_buffer * snd_hammerfall_get_buffer(struct pci_dev *pci, size_t size) { return snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, size); } static const struct pci_device_id snd_hdsp_ids[] = { { .vendor = PCI_VENDOR_ID_XILINX, .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, }, /* RME Hammerfall-DSP */ { 0, }, }; MODULE_DEVICE_TABLE(pci, snd_hdsp_ids); /* prototypes */ static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp); static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp); static int snd_hdsp_enable_io (struct hdsp *hdsp); static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp); static void snd_hdsp_initialize_channels (struct hdsp *hdsp); static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout); static int hdsp_autosync_ref(struct hdsp *hdsp); static int snd_hdsp_set_defaults(struct hdsp *hdsp); static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp); static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out) { switch (hdsp->io_type) { case Multiface: case Digiface: case RPM: default: if (hdsp->firmware_rev == 0xa) return (64 * out) + (32 + (in)); else return (52 * out) + (26 + (in)); case H9632: return (32 * out) + (16 + (in)); case H9652: return (52 * out) + (26 + (in)); } } static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out) { switch (hdsp->io_type) { case Multiface: case Digiface: case RPM: default: if (hdsp->firmware_rev == 0xa) return (64 * out) + in; else return (52 * out) + in; case H9632: return (32 * out) + in; case H9652: return (52 * out) + in; } } static void hdsp_write(struct hdsp *hdsp, int reg, int val) { writel(val, hdsp->iobase + reg); } static unsigned int hdsp_read(struct hdsp *hdsp, int reg) { return readl (hdsp->iobase + reg); } static int hdsp_check_for_iobox (struct hdsp *hdsp) { int i; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; for (i = 0; i < 500; i++) { if (0 == (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)) { if (i) { dev_dbg(hdsp->card->dev, "IO box found after %d ms\n", (20 * i)); } return 0; } msleep(20); } dev_err(hdsp->card->dev, "no IO box connected!\n"); hdsp->state &= ~HDSP_FirmwareLoaded; return -EIO; } static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops, unsigned int delay) { unsigned int i; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; for (i = 0; i != loops; ++i) { if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError) msleep(delay); else { dev_dbg(hdsp->card->dev, "iobox found after %ums!\n", i * delay); return 0; } } dev_info(hdsp->card->dev, "no IO box connected!\n"); hdsp->state &= ~HDSP_FirmwareLoaded; return -EIO; } static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) { int i; unsigned long flags; const u32 *cache; if (hdsp->fw_uploaded) cache = hdsp->fw_uploaded; else { if (!hdsp->firmware) return -ENODEV; cache = (u32 *)hdsp->firmware->data; if (!cache) return -ENODEV; } if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { dev_info(hdsp->card->dev, "loading firmware\n"); hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM); hdsp_write (hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { dev_info(hdsp->card->dev, "timeout waiting for download preparation\n"); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); return -EIO; } hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) { hdsp_write(hdsp, HDSP_fifoData, cache[i]); if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) { dev_info(hdsp->card->dev, "timeout during firmware loading\n"); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); return -EIO; } } hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200); ssleep(3); #ifdef SNDRV_BIG_ENDIAN hdsp->control2_register = HDSP_BIGENDIAN_MODE; #else hdsp->control2_register = 0; #endif hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); dev_info(hdsp->card->dev, "finished firmware loading\n"); } if (hdsp->state & HDSP_InitializationComplete) { dev_info(hdsp->card->dev, "firmware loaded from cache, restoring defaults\n"); spin_lock_irqsave(&hdsp->lock, flags); snd_hdsp_set_defaults(hdsp); spin_unlock_irqrestore(&hdsp->lock, flags); } hdsp->state |= HDSP_FirmwareLoaded; return 0; } static int hdsp_get_iobox_version (struct hdsp *hdsp) { if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); hdsp_write(hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) { hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); } hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM); hdsp_write (hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) goto set_multi; hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); hdsp_write(hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) { hdsp->io_type = Digiface; dev_info(hdsp->card->dev, "Digiface found\n"); return 0; } hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); hdsp_write(hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) goto set_multi; hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300); hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD); hdsp_write(hdsp, HDSP_fifoData, 0); if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) goto set_multi; hdsp->io_type = RPM; dev_info(hdsp->card->dev, "RPM found\n"); return 0; } else { /* firmware was already loaded, get iobox type */ if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2) hdsp->io_type = RPM; else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) hdsp->io_type = Multiface; else hdsp->io_type = Digiface; } return 0; set_multi: hdsp->io_type = Multiface; dev_info(hdsp->card->dev, "Multiface found\n"); return 0; } static int hdsp_request_fw_loader(struct hdsp *hdsp); static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand) { if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { hdsp->state &= ~HDSP_FirmwareLoaded; if (! load_on_demand) return -EIO; dev_err(hdsp->card->dev, "firmware not present.\n"); /* try to load firmware */ if (! (hdsp->state & HDSP_FirmwareCached)) { if (! hdsp_request_fw_loader(hdsp)) return 0; dev_err(hdsp->card->dev, "No firmware loaded nor cached, please upload firmware.\n"); return -EIO; } if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { dev_err(hdsp->card->dev, "Firmware loading from cache failed, please upload manually.\n"); return -EIO; } } return 0; } static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout) { int i; /* the fifoStatus registers reports on how many words are available in the command FIFO. */ for (i = 0; i < timeout; i++) { if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count) return 0; /* not very friendly, but we only do this during a firmware load and changing the mixer, so we just put up with it. */ udelay (100); } dev_warn(hdsp->card->dev, "wait for FIFO status <= %d failed after %d iterations\n", count, timeout); return -1; } static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr) { if (addr >= HDSP_MATRIX_MIXER_SIZE) return 0; return hdsp->mixer_matrix[addr]; } static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data) { unsigned int ad; if (addr >= HDSP_MATRIX_MIXER_SIZE) return -1; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) { /* from martin bjornsen: "You can only write dwords to the mixer memory which contain two mixer values in the low and high word. So if you want to change value 0 you have to read value 1 from the cache and write both to the first dword in the mixer memory." */ if (hdsp->io_type == H9632 && addr >= 512) return 0; if (hdsp->io_type == H9652 && addr >= 1352) return 0; hdsp->mixer_matrix[addr] = data; /* `addr' addresses a 16-bit wide address, but the address space accessed via hdsp_write uses byte offsets. put another way, addr varies from 0 to 1351, but to access the corresponding memory location, we need to access 0 to 2703 ... */ ad = addr/2; hdsp_write (hdsp, 4096 + (ad*4), (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) + hdsp->mixer_matrix[addr&0x7fe]); return 0; } else { ad = (addr << 16) + data; if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) return -1; hdsp_write (hdsp, HDSP_fifoData, ad); hdsp->mixer_matrix[addr] = data; } return 0; } static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp) { unsigned long flags; int ret = 1; spin_lock_irqsave(&hdsp->lock, flags); if ((hdsp->playback_pid != hdsp->capture_pid) && (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) ret = 0; spin_unlock_irqrestore(&hdsp->lock, flags); return ret; } static int hdsp_spdif_sample_rate(struct hdsp *hdsp) { unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); /* For the 9632, the mask is different */ if (hdsp->io_type == H9632) rate_bits = (status & HDSP_spdifFrequencyMask_9632); if (status & HDSP_SPDIFErrorFlag) return 0; switch (rate_bits) { case HDSP_spdifFrequency32KHz: return 32000; case HDSP_spdifFrequency44_1KHz: return 44100; case HDSP_spdifFrequency48KHz: return 48000; case HDSP_spdifFrequency64KHz: return 64000; case HDSP_spdifFrequency88_2KHz: return 88200; case HDSP_spdifFrequency96KHz: return 96000; case HDSP_spdifFrequency128KHz: if (hdsp->io_type == H9632) return 128000; break; case HDSP_spdifFrequency176_4KHz: if (hdsp->io_type == H9632) return 176400; break; case HDSP_spdifFrequency192KHz: if (hdsp->io_type == H9632) return 192000; break; default: break; } dev_warn(hdsp->card->dev, "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status); return 0; } static int hdsp_external_sample_rate(struct hdsp *hdsp) { unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register); unsigned int rate_bits = status2 & HDSP_systemFrequencyMask; /* For the 9632 card, there seems to be no bit for indicating external * sample rate greater than 96kHz. The card reports the corresponding * single speed. So the best means seems to get spdif rate when * autosync reference is spdif */ if (hdsp->io_type == H9632 && hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF) return hdsp_spdif_sample_rate(hdsp); switch (rate_bits) { case HDSP_systemFrequency32: return 32000; case HDSP_systemFrequency44_1: return 44100; case HDSP_systemFrequency48: return 48000; case HDSP_systemFrequency64: return 64000; case HDSP_systemFrequency88_2: return 88200; case HDSP_systemFrequency96: return 96000; default: return 0; } } static void hdsp_compute_period_size(struct hdsp *hdsp) { hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8)); } static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp) { int position; position = hdsp_read(hdsp, HDSP_statusRegister); if (!hdsp->precise_ptr) return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0; position &= HDSP_BufferPositionMask; position /= 4; position &= (hdsp->period_bytes/2) - 1; return position; } static void hdsp_reset_hw_pointer(struct hdsp *hdsp) { hdsp_write (hdsp, HDSP_resetPointer, 0); if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152) /* HDSP_resetPointer = HDSP_freqReg, which is strange and * requires (?) to write again DDS value after a reset pointer * (at least, it works like this) */ hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value); } static void hdsp_start_audio(struct hdsp *s) { s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start); hdsp_write(s, HDSP_controlRegister, s->control_register); } static void hdsp_stop_audio(struct hdsp *s) { s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable); hdsp_write(s, HDSP_controlRegister, s->control_register); } static void hdsp_silence_playback(struct hdsp *hdsp) { memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES); } static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames) { int n; spin_lock_irq(&s->lock); frames >>= 7; n = 0; while (frames) { n++; frames >>= 1; } s->control_register &= ~HDSP_LatencyMask; s->control_register |= hdsp_encode_latency(n); hdsp_write(s, HDSP_controlRegister, s->control_register); hdsp_compute_period_size(s); spin_unlock_irq(&s->lock); return 0; } static void hdsp_set_dds_value(struct hdsp *hdsp, int rate) { u64 n; if (rate >= 112000) rate /= 4; else if (rate >= 56000) rate /= 2; n = DDS_NUMERATOR; n = div_u64(n, rate); /* n should be less than 2^32 for being written to FREQ register */ snd_BUG_ON(n >> 32); /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS value to write it after a reset */ hdsp->dds_value = n; hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value); } static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally) { int reject_if_open = 0; int current_rate; int rate_bits; /* ASSUMPTION: hdsp->lock is either held, or there is no need for it (e.g. during module initialization). */ if (!(hdsp->control_register & HDSP_ClockModeMaster)) { if (called_internally) { /* request from ctl or card initialization */ dev_err(hdsp->card->dev, "device is not running as a clock master: cannot set sample rate.\n"); return -1; } else { /* hw_param request while in AutoSync mode */ int external_freq = hdsp_external_sample_rate(hdsp); int spdif_freq = hdsp_spdif_sample_rate(hdsp); if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) dev_info(hdsp->card->dev, "Detected ADAT in double speed mode\n"); else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) dev_info(hdsp->card->dev, "Detected ADAT in quad speed mode\n"); else if (rate != external_freq) { dev_info(hdsp->card->dev, "No AutoSync source for requested rate\n"); return -1; } } } current_rate = hdsp->system_sample_rate; /* Changing from a "single speed" to a "double speed" rate is not allowed if any substreams are open. This is because such a change causes a shift in the location of the DMA buffers and a reduction in the number of available buffers. Note that a similar but essentially insoluble problem exists for externally-driven rate changes. All we can do is to flag rate changes in the read/write routines. */ if (rate > 96000 && hdsp->io_type != H9632) return -EINVAL; switch (rate) { case 32000: if (current_rate > 48000) reject_if_open = 1; rate_bits = HDSP_Frequency32KHz; break; case 44100: if (current_rate > 48000) reject_if_open = 1; rate_bits = HDSP_Frequency44_1KHz; break; case 48000: if (current_rate > 48000) reject_if_open = 1; rate_bits = HDSP_Frequency48KHz; break; case 64000: if (current_rate <= 48000 || current_rate > 96000) reject_if_open = 1; rate_bits = HDSP_Frequency64KHz; break; case 88200: if (current_rate <= 48000 || current_rate > 96000) reject_if_open = 1; rate_bits = HDSP_Frequency88_2KHz; break; case 96000: if (current_rate <= 48000 || current_rate > 96000) reject_if_open = 1; rate_bits = HDSP_Frequency96KHz; break; case 128000: if (current_rate < 128000) reject_if_open = 1; rate_bits = HDSP_Frequency128KHz; break; case 176400: if (current_rate < 128000) reject_if_open = 1; rate_bits = HDSP_Frequency176_4KHz; break; case 192000: if (current_rate < 128000) reject_if_open = 1; rate_bits = HDSP_Frequency192KHz; break; default: return -EINVAL; } if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) { dev_warn(hdsp->card->dev, "cannot change speed mode (capture PID = %d, playback PID = %d)\n", hdsp->capture_pid, hdsp->playback_pid); return -EBUSY; } hdsp->control_register &= ~HDSP_FrequencyMask; hdsp->control_register |= rate_bits; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); /* For HDSP9632 rev 152, need to set DDS value in FREQ register */ if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152) hdsp_set_dds_value(hdsp, rate); if (rate >= 128000) { hdsp->channel_map = channel_map_H9632_qs; } else if (rate > 48000) { if (hdsp->io_type == H9632) hdsp->channel_map = channel_map_H9632_ds; else hdsp->channel_map = channel_map_ds; } else { switch (hdsp->io_type) { case RPM: case Multiface: hdsp->channel_map = channel_map_mf_ss; break; case Digiface: case H9652: hdsp->channel_map = channel_map_df_ss; break; case H9632: hdsp->channel_map = channel_map_H9632_ss; break; default: /* should never happen */ break; } } hdsp->system_sample_rate = rate; return 0; } /*---------------------------------------------------------------------------- MIDI ----------------------------------------------------------------------------*/ static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id) { /* the hardware already does the relevant bit-mask with 0xff */ if (id) return hdsp_read(hdsp, HDSP_midiDataIn1); else return hdsp_read(hdsp, HDSP_midiDataIn0); } static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val) { /* the hardware already does the relevant bit-mask with 0xff */ if (id) hdsp_write(hdsp, HDSP_midiDataOut1, val); else hdsp_write(hdsp, HDSP_midiDataOut0, val); } static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id) { if (id) return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff); else return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff); } static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id) { int fifo_bytes_used; if (id) fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff; else fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff; if (fifo_bytes_used < 128) return 128 - fifo_bytes_used; else return 0; } static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id) { while (snd_hdsp_midi_input_available (hdsp, id)) snd_hdsp_midi_read_byte (hdsp, id); } static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi) { unsigned long flags; int n_pending; int to_write; int i; unsigned char buf[128]; /* Output is not interrupt driven */ spin_lock_irqsave (&hmidi->lock, flags); if (hmidi->output) { if (!snd_rawmidi_transmit_empty (hmidi->output)) { n_pending = snd_hdsp_midi_output_possible(hmidi->hdsp, hmidi->id); if (n_pending > 0) { if (n_pending > (int)sizeof (buf)) n_pending = sizeof (buf); to_write = snd_rawmidi_transmit(hmidi->output, buf, n_pending); if (to_write > 0) { for (i = 0; i < to_write; ++i) snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]); } } } } spin_unlock_irqrestore (&hmidi->lock, flags); return 0; } static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi) { unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */ unsigned long flags; int n_pending; int i; spin_lock_irqsave (&hmidi->lock, flags); n_pending = snd_hdsp_midi_input_available(hmidi->hdsp, hmidi->id); if (n_pending > 0) { if (hmidi->input) { if (n_pending > (int)sizeof (buf)) n_pending = sizeof (buf); for (i = 0; i < n_pending; ++i) buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); if (n_pending) snd_rawmidi_receive (hmidi->input, buf, n_pending); } else { /* flush the MIDI input FIFO */ while (--n_pending) snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); } } hmidi->pending = 0; if (hmidi->id) hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; else hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); spin_unlock_irqrestore (&hmidi->lock, flags); return snd_hdsp_midi_output_write (hmidi); } static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdsp *hdsp; struct hdsp_midi *hmidi; unsigned long flags; u32 ie; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; hdsp = hmidi->hdsp; ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable; spin_lock_irqsave (&hdsp->lock, flags); if (up) { if (!(hdsp->control_register & ie)) { snd_hdsp_flush_midi_input (hdsp, hmidi->id); hdsp->control_register |= ie; } } else { hdsp->control_register &= ~ie; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); spin_unlock_irqrestore (&hdsp->lock, flags); } static void snd_hdsp_midi_output_timer(struct timer_list *t) { struct hdsp_midi *hmidi = from_timer(hmidi, t, timer); unsigned long flags; snd_hdsp_midi_output_write(hmidi); spin_lock_irqsave (&hmidi->lock, flags); /* this does not bump hmidi->istimer, because the kernel automatically removed the timer when it expired, and we are now adding it back, thus leaving istimer wherever it was set before. */ if (hmidi->istimer) mod_timer(&hmidi->timer, 1 + jiffies); spin_unlock_irqrestore (&hmidi->lock, flags); } static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct hdsp_midi *hmidi; unsigned long flags; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; spin_lock_irqsave (&hmidi->lock, flags); if (up) { if (!hmidi->istimer) { timer_setup(&hmidi->timer, snd_hdsp_midi_output_timer, 0); mod_timer(&hmidi->timer, 1 + jiffies); hmidi->istimer++; } } else { if (hmidi->istimer && --hmidi->istimer <= 0) del_timer (&hmidi->timer); } spin_unlock_irqrestore (&hmidi->lock, flags); if (up) snd_hdsp_midi_output_write(hmidi); } static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream) { struct hdsp_midi *hmidi; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id); hmidi->input = substream; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream) { struct hdsp_midi *hmidi; hmidi = (struct hdsp_midi *) substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->output = substream; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream) { struct hdsp_midi *hmidi; snd_hdsp_midi_input_trigger (substream, 0); hmidi = (struct hdsp_midi *) substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->input = NULL; spin_unlock_irq (&hmidi->lock); return 0; } static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream) { struct hdsp_midi *hmidi; snd_hdsp_midi_output_trigger (substream, 0); hmidi = (struct hdsp_midi *) substream->rmidi->private_data; spin_lock_irq (&hmidi->lock); hmidi->output = NULL; spin_unlock_irq (&hmidi->lock); return 0; } static const struct snd_rawmidi_ops snd_hdsp_midi_output = { .open = snd_hdsp_midi_output_open, .close = snd_hdsp_midi_output_close, .trigger = snd_hdsp_midi_output_trigger, }; static const struct snd_rawmidi_ops snd_hdsp_midi_input = { .open = snd_hdsp_midi_input_open, .close = snd_hdsp_midi_input_close, .trigger = snd_hdsp_midi_input_trigger, }; static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id) { char buf[40]; hdsp->midi[id].id = id; hdsp->midi[id].rmidi = NULL; hdsp->midi[id].input = NULL; hdsp->midi[id].output = NULL; hdsp->midi[id].hdsp = hdsp; hdsp->midi[id].istimer = 0; hdsp->midi[id].pending = 0; spin_lock_init (&hdsp->midi[id].lock); snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id + 1); if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) return -1; sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1); hdsp->midi[id].rmidi->private_data = &hdsp->midi[id]; snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output); snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input); hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; return 0; } /*----------------------------------------------------------------------------- Control Interface ----------------------------------------------------------------------------*/ static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes) { u32 val = 0; val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0; val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0; if (val & HDSP_SPDIFProfessional) val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0; else val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0; return val; } static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val) { aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) | ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0); if (val & HDSP_SPDIFProfessional) aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0; else aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0; } static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif); return 0; } static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; u32 val; val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958); spin_lock_irq(&hdsp->lock); change = val != hdsp->creg_spdif; hdsp->creg_spdif = val; spin_unlock_irq(&hdsp->lock); return change; } static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream); return 0; } static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; u32 val; val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958); spin_lock_irq(&hdsp->lock); change = val != hdsp->creg_spdif_stream; hdsp->creg_spdif_stream = val; hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis); hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val); spin_unlock_irq(&hdsp->lock); return change; } static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = kcontrol->private_value; return 0; } #define HDSP_SPDIF_IN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_spdif_in, \ .get = snd_hdsp_get_spdif_in, \ .put = snd_hdsp_put_spdif_in } static unsigned int hdsp_spdif_in(struct hdsp *hdsp) { return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask); } static int hdsp_set_spdif_input(struct hdsp *hdsp, int in) { hdsp->control_register &= ~HDSP_SPDIFInputMask; hdsp->control_register |= hdsp_encode_spdif_in(in); hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[4] = { "Optical", "Coaxial", "Internal", "AES" }; struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3, texts); } static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp); return 0; } static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3); spin_lock_irq(&hdsp->lock); change = val != hdsp_spdif_in(hdsp); if (change) hdsp_set_spdif_input(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_TOGGLE_SETTING(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .private_value = xindex, \ .info = snd_hdsp_info_toggle_setting, \ .get = snd_hdsp_get_toggle_setting, \ .put = snd_hdsp_put_toggle_setting \ } static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask) { return (hdsp->control_register & regmask) ? 1 : 0; } static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out) { if (out) hdsp->control_register |= regmask; else hdsp->control_register &= ~regmask; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } #define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; spin_lock_irq(&hdsp->lock); ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask); spin_unlock_irq(&hdsp->lock); return 0; } static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); u32 regmask = kcontrol->private_value; int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdsp->lock); change = (int) val != hdsp_toggle_setting(hdsp, regmask); if (change) hdsp_set_toggle_setting(hdsp, regmask, val); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdsp_info_spdif_sample_rate, \ .get = snd_hdsp_get_spdif_sample_rate \ } static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = { "32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000" }; struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, texts); } static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); switch (hdsp_spdif_sample_rate(hdsp)) { case 32000: ucontrol->value.enumerated.item[0] = 0; break; case 44100: ucontrol->value.enumerated.item[0] = 1; break; case 48000: ucontrol->value.enumerated.item[0] = 2; break; case 64000: ucontrol->value.enumerated.item[0] = 3; break; case 88200: ucontrol->value.enumerated.item[0] = 4; break; case 96000: ucontrol->value.enumerated.item[0] = 5; break; case 128000: ucontrol->value.enumerated.item[0] = 7; break; case 176400: ucontrol->value.enumerated.item[0] = 8; break; case 192000: ucontrol->value.enumerated.item[0] = 9; break; default: ucontrol->value.enumerated.item[0] = 6; } return 0; } #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdsp_info_system_sample_rate, \ .get = snd_hdsp_get_system_sample_rate \ } static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; return 0; } static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate; return 0; } #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdsp_info_autosync_sample_rate, \ .get = snd_hdsp_get_autosync_sample_rate \ } static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); static const char * const texts[] = { "32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000" }; return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, texts); } static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); switch (hdsp_external_sample_rate(hdsp)) { case 32000: ucontrol->value.enumerated.item[0] = 0; break; case 44100: ucontrol->value.enumerated.item[0] = 1; break; case 48000: ucontrol->value.enumerated.item[0] = 2; break; case 64000: ucontrol->value.enumerated.item[0] = 3; break; case 88200: ucontrol->value.enumerated.item[0] = 4; break; case 96000: ucontrol->value.enumerated.item[0] = 5; break; case 128000: ucontrol->value.enumerated.item[0] = 7; break; case 176400: ucontrol->value.enumerated.item[0] = 8; break; case 192000: ucontrol->value.enumerated.item[0] = 9; break; default: ucontrol->value.enumerated.item[0] = 6; } return 0; } #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdsp_info_system_clock_mode, \ .get = snd_hdsp_get_system_clock_mode \ } static int hdsp_system_clock_mode(struct hdsp *hdsp) { if (hdsp->control_register & HDSP_ClockModeMaster) return 0; else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) return 0; return 1; } static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"Master", "Slave" }; return snd_ctl_enum_info(uinfo, 1, 2, texts); } static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp); return 0; } #define HDSP_CLOCK_SOURCE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_clock_source, \ .get = snd_hdsp_get_clock_source, \ .put = snd_hdsp_put_clock_source \ } static int hdsp_clock_source(struct hdsp *hdsp) { if (hdsp->control_register & HDSP_ClockModeMaster) { switch (hdsp->system_sample_rate) { case 32000: return 1; case 44100: return 2; case 48000: return 3; case 64000: return 4; case 88200: return 5; case 96000: return 6; case 128000: return 7; case 176400: return 8; case 192000: return 9; default: return 3; } } else { return 0; } } static int hdsp_set_clock_source(struct hdsp *hdsp, int mode) { int rate; switch (mode) { case HDSP_CLOCK_SOURCE_AUTOSYNC: if (hdsp_external_sample_rate(hdsp) != 0) { if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) { hdsp->control_register &= ~HDSP_ClockModeMaster; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } } return -1; case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ: rate = 32000; break; case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ: rate = 44100; break; case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ: rate = 48000; break; case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ: rate = 64000; break; case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ: rate = 88200; break; case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ: rate = 96000; break; case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ: rate = 128000; break; case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ: rate = 176400; break; case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ: rate = 192000; break; default: rate = 48000; } hdsp->control_register |= HDSP_ClockModeMaster; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); hdsp_set_rate(hdsp, rate, 1); return 0; } static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = { "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" }; struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7, texts); } static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp); return 0; } static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (hdsp->io_type == H9632) { if (val > 9) val = 9; } else { if (val > 6) val = 6; } spin_lock_irq(&hdsp->lock); if (val != hdsp_clock_source(hdsp)) change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdsp->clock_source_locked; return 0; } static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked; if (change) hdsp->clock_source_locked = !!ucontrol->value.integer.value[0]; return change; } #define HDSP_DA_GAIN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_da_gain, \ .get = snd_hdsp_get_da_gain, \ .put = snd_hdsp_put_da_gain \ } static int hdsp_da_gain(struct hdsp *hdsp) { switch (hdsp->control_register & HDSP_DAGainMask) { case HDSP_DAGainHighGain: return 0; case HDSP_DAGainPlus4dBu: return 1; case HDSP_DAGainMinus10dBV: return 2; default: return 1; } } static int hdsp_set_da_gain(struct hdsp *hdsp, int mode) { hdsp->control_register &= ~HDSP_DAGainMask; switch (mode) { case 0: hdsp->control_register |= HDSP_DAGainHighGain; break; case 1: hdsp->control_register |= HDSP_DAGainPlus4dBu; break; case 2: hdsp->control_register |= HDSP_DAGainMinus10dBV; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"}; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp); return 0; } static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdsp->lock); if (val != hdsp_da_gain(hdsp)) change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_AD_GAIN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_ad_gain, \ .get = snd_hdsp_get_ad_gain, \ .put = snd_hdsp_put_ad_gain \ } static int hdsp_ad_gain(struct hdsp *hdsp) { switch (hdsp->control_register & HDSP_ADGainMask) { case HDSP_ADGainMinus10dBV: return 0; case HDSP_ADGainPlus4dBu: return 1; case HDSP_ADGainLowGain: return 2; default: return 1; } } static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode) { hdsp->control_register &= ~HDSP_ADGainMask; switch (mode) { case 0: hdsp->control_register |= HDSP_ADGainMinus10dBV; break; case 1: hdsp->control_register |= HDSP_ADGainPlus4dBu; break; case 2: hdsp->control_register |= HDSP_ADGainLowGain; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"}; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp); return 0; } static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdsp->lock); if (val != hdsp_ad_gain(hdsp)) change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_PHONE_GAIN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_phone_gain, \ .get = snd_hdsp_get_phone_gain, \ .put = snd_hdsp_put_phone_gain \ } static int hdsp_phone_gain(struct hdsp *hdsp) { switch (hdsp->control_register & HDSP_PhoneGainMask) { case HDSP_PhoneGain0dB: return 0; case HDSP_PhoneGainMinus6dB: return 1; case HDSP_PhoneGainMinus12dB: return 2; default: return 0; } } static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode) { hdsp->control_register &= ~HDSP_PhoneGainMask; switch (mode) { case 0: hdsp->control_register |= HDSP_PhoneGain0dB; break; case 1: hdsp->control_register |= HDSP_PhoneGainMinus6dB; break; case 2: hdsp->control_register |= HDSP_PhoneGainMinus12dB; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"}; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp); return 0; } static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 2) val = 2; spin_lock_irq(&hdsp->lock); if (val != hdsp_phone_gain(hdsp)) change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_PREF_SYNC_REF(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_pref_sync_ref, \ .get = snd_hdsp_get_pref_sync_ref, \ .put = snd_hdsp_put_pref_sync_ref \ } static int hdsp_pref_sync_ref(struct hdsp *hdsp) { /* Notice that this looks at the requested sync source, not the one actually in use. */ switch (hdsp->control_register & HDSP_SyncRefMask) { case HDSP_SyncRef_ADAT1: return HDSP_SYNC_FROM_ADAT1; case HDSP_SyncRef_ADAT2: return HDSP_SYNC_FROM_ADAT2; case HDSP_SyncRef_ADAT3: return HDSP_SYNC_FROM_ADAT3; case HDSP_SyncRef_SPDIF: return HDSP_SYNC_FROM_SPDIF; case HDSP_SyncRef_WORD: return HDSP_SYNC_FROM_WORD; case HDSP_SyncRef_ADAT_SYNC: return HDSP_SYNC_FROM_ADAT_SYNC; default: return HDSP_SYNC_FROM_WORD; } return 0; } static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref) { hdsp->control_register &= ~HDSP_SyncRefMask; switch (pref) { case HDSP_SYNC_FROM_ADAT1: hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */ break; case HDSP_SYNC_FROM_ADAT2: hdsp->control_register |= HDSP_SyncRef_ADAT2; break; case HDSP_SYNC_FROM_ADAT3: hdsp->control_register |= HDSP_SyncRef_ADAT3; break; case HDSP_SYNC_FROM_SPDIF: hdsp->control_register |= HDSP_SyncRef_SPDIF; break; case HDSP_SYNC_FROM_WORD: hdsp->control_register |= HDSP_SyncRef_WORD; break; case HDSP_SYNC_FROM_ADAT_SYNC: hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = { "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" }; struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int num_items; switch (hdsp->io_type) { case Digiface: case H9652: num_items = 6; break; case Multiface: num_items = 4; break; case H9632: num_items = 3; break; default: return -EINVAL; } return snd_ctl_enum_info(uinfo, 1, num_items, texts); } static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp); return 0; } static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change, max; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; switch (hdsp->io_type) { case Digiface: case H9652: max = 6; break; case Multiface: max = 4; break; case H9632: max = 3; break; default: return -EIO; } val = ucontrol->value.enumerated.item[0] % max; spin_lock_irq(&hdsp->lock); change = (int)val != hdsp_pref_sync_ref(hdsp); hdsp_set_pref_sync_ref(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_AUTOSYNC_REF(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ, \ .info = snd_hdsp_info_autosync_ref, \ .get = snd_hdsp_get_autosync_ref, \ } static int hdsp_autosync_ref(struct hdsp *hdsp) { /* This looks at the autosync selected sync reference */ unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register); switch (status2 & HDSP_SelSyncRefMask) { case HDSP_SelSyncRef_WORD: return HDSP_AUTOSYNC_FROM_WORD; case HDSP_SelSyncRef_ADAT_SYNC: return HDSP_AUTOSYNC_FROM_ADAT_SYNC; case HDSP_SelSyncRef_SPDIF: return HDSP_AUTOSYNC_FROM_SPDIF; case HDSP_SelSyncRefMask: return HDSP_AUTOSYNC_FROM_NONE; case HDSP_SelSyncRef_ADAT1: return HDSP_AUTOSYNC_FROM_ADAT1; case HDSP_SelSyncRef_ADAT2: return HDSP_AUTOSYNC_FROM_ADAT2; case HDSP_SelSyncRef_ADAT3: return HDSP_AUTOSYNC_FROM_ADAT3; default: return HDSP_AUTOSYNC_FROM_WORD; } return 0; } static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = { "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" }; return snd_ctl_enum_info(uinfo, 1, 7, texts); } static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp); return 0; } #define HDSP_PRECISE_POINTER(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_precise_pointer, \ .get = snd_hdsp_get_precise_pointer, \ .put = snd_hdsp_put_precise_pointer \ } static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise) { if (precise) hdsp->precise_ptr = 1; else hdsp->precise_ptr = 0; return 0; } #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdsp->lock); ucontrol->value.integer.value[0] = hdsp->precise_ptr; spin_unlock_irq(&hdsp->lock); return 0; } static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdsp->lock); change = (int)val != hdsp->precise_ptr; hdsp_set_precise_pointer(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_USE_MIDI_WORK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_use_midi_work, \ .get = snd_hdsp_get_use_midi_work, \ .put = snd_hdsp_put_use_midi_work \ } static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work) { if (use_work) hdsp->use_midi_work = 1; else hdsp->use_midi_work = 0; return 0; } #define snd_hdsp_info_use_midi_work snd_ctl_boolean_mono_info static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); spin_lock_irq(&hdsp->lock); ucontrol->value.integer.value[0] = hdsp->use_midi_work; spin_unlock_irq(&hdsp->lock); return 0; } static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdsp->lock); change = (int)val != hdsp->use_midi_work; hdsp_set_use_midi_work(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_MIXER(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \ .name = xname, \ .index = xindex, \ .device = 0, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdsp_info_mixer, \ .get = snd_hdsp_get_mixer, \ .put = snd_hdsp_put_mixer \ } static int snd_hdsp_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 3; uinfo->value.integer.min = 0; uinfo->value.integer.max = 65536; uinfo->value.integer.step = 1; return 0; } static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int source; int destination; int addr; source = ucontrol->value.integer.value[0]; destination = ucontrol->value.integer.value[1]; if (source >= hdsp->max_channels) addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination); else addr = hdsp_input_to_output_key(hdsp,source, destination); spin_lock_irq(&hdsp->lock); ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr); spin_unlock_irq(&hdsp->lock); return 0; } static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int source; int destination; int gain; int addr; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; source = ucontrol->value.integer.value[0]; destination = ucontrol->value.integer.value[1]; if (source >= hdsp->max_channels) addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination); else addr = hdsp_input_to_output_key(hdsp,source, destination); gain = ucontrol->value.integer.value[2]; spin_lock_irq(&hdsp->lock); change = gain != hdsp_read_gain(hdsp, addr); if (change) hdsp_write_gain(hdsp, addr, gain); spin_unlock_irq(&hdsp->lock); return change; } #define HDSP_WC_SYNC_CHECK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdsp_info_sync_check, \ .get = snd_hdsp_get_wc_sync_check \ } static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"No Lock", "Lock", "Sync" }; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int hdsp_wc_sync_check(struct hdsp *hdsp) { int status2 = hdsp_read(hdsp, HDSP_status2Register); if (status2 & HDSP_wc_lock) { if (status2 & HDSP_wc_sync) return 2; else return 1; } else return 0; return 0; } static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp); return 0; } #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdsp_info_sync_check, \ .get = snd_hdsp_get_spdif_sync_check \ } static int hdsp_spdif_sync_check(struct hdsp *hdsp) { int status = hdsp_read(hdsp, HDSP_statusRegister); if (status & HDSP_SPDIFErrorFlag) return 0; else { if (status & HDSP_SPDIFSync) return 2; else return 1; } return 0; } static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp); return 0; } #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdsp_info_sync_check, \ .get = snd_hdsp_get_adatsync_sync_check \ } static int hdsp_adatsync_sync_check(struct hdsp *hdsp) { int status = hdsp_read(hdsp, HDSP_statusRegister); if (status & HDSP_TimecodeLock) { if (status & HDSP_TimecodeSync) return 2; else return 1; } else return 0; } static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp); return 0; } #define HDSP_ADAT_SYNC_CHECK \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_hdsp_info_sync_check, \ .get = snd_hdsp_get_adat_sync_check \ } static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx) { int status = hdsp_read(hdsp, HDSP_statusRegister); if (status & (HDSP_Lock0>>idx)) { if (status & (HDSP_Sync0>>idx)) return 2; else return 1; } else return 0; } static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int offset; struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); offset = ucontrol->id.index - 1; if (snd_BUG_ON(offset < 0)) return -EINVAL; switch (hdsp->io_type) { case Digiface: case H9652: if (offset >= 3) return -EINVAL; break; case Multiface: case H9632: if (offset >= 1) return -EINVAL; break; default: return -EIO; } ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset); return 0; } #define HDSP_DDS_OFFSET(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = xname, \ .index = xindex, \ .info = snd_hdsp_info_dds_offset, \ .get = snd_hdsp_get_dds_offset, \ .put = snd_hdsp_put_dds_offset \ } static int hdsp_dds_offset(struct hdsp *hdsp) { u64 n; unsigned int dds_value = hdsp->dds_value; int system_sample_rate = hdsp->system_sample_rate; if (!dds_value) return 0; n = DDS_NUMERATOR; /* * dds_value = n / rate * rate = n / dds_value */ n = div_u64(n, dds_value); if (system_sample_rate >= 112000) n *= 4; else if (system_sample_rate >= 56000) n *= 2; return ((int)n) - system_sample_rate; } static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz) { int rate = hdsp->system_sample_rate + offset_hz; hdsp_set_dds_value(hdsp, rate); return 0; } static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = -5000; uinfo->value.integer.max = 5000; return 0; } static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp); return 0; } static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0]; spin_lock_irq(&hdsp->lock); if (val != hdsp_dds_offset(hdsp)) change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } static const struct snd_kcontrol_new snd_hdsp_9632_controls[] = { HDSP_DA_GAIN("DA Gain", 0), HDSP_AD_GAIN("AD Gain", 0), HDSP_PHONE_GAIN("Phones Gain", 0), HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable), HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0) }; static const struct snd_kcontrol_new snd_hdsp_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .info = snd_hdsp_control_spdif_info, .get = snd_hdsp_control_spdif_get, .put = snd_hdsp_control_spdif_put, }, { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), .info = snd_hdsp_control_spdif_stream_info, .get = snd_hdsp_control_spdif_stream_get, .put = snd_hdsp_control_spdif_stream_put, }, { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), .info = snd_hdsp_control_spdif_mask_info, .get = snd_hdsp_control_spdif_mask_get, .private_value = IEC958_AES0_NONAUDIO | IEC958_AES0_PROFESSIONAL | IEC958_AES0_CON_EMPHASIS, }, { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), .info = snd_hdsp_control_spdif_mask_info, .get = snd_hdsp_control_spdif_mask_get, .private_value = IEC958_AES0_NONAUDIO | IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_EMPHASIS, }, HDSP_MIXER("Mixer", 0), HDSP_SPDIF_IN("IEC958 Input Connector", 0), HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut), HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional), HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis), HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio), /* 'Sample Clock Source' complies with the alsa control naming scheme */ HDSP_CLOCK_SOURCE("Sample Clock Source", 0), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Sample Clock Source Locking", .info = snd_hdsp_info_clock_source_lock, .get = snd_hdsp_get_clock_source_lock, .put = snd_hdsp_put_clock_source_lock, }, HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0), HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0), HDSP_AUTOSYNC_REF("AutoSync Reference", 0), HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0), HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), /* 'External Rate' complies with the alsa control naming scheme */ HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0), HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0), HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0), HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0), HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut), HDSP_PRECISE_POINTER("Precise Pointer", 0), HDSP_USE_MIDI_WORK("Use Midi Tasklet", 0), }; static int hdsp_rpm_input12(struct hdsp *hdsp) { switch (hdsp->control_register & HDSP_RPM_Inp12) { case HDSP_RPM_Inp12_Phon_6dB: return 0; case HDSP_RPM_Inp12_Phon_n6dB: return 2; case HDSP_RPM_Inp12_Line_0dB: return 3; case HDSP_RPM_Inp12_Line_n6dB: return 4; } return 1; } static int snd_hdsp_get_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_rpm_input12(hdsp); return 0; } static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode) { hdsp->control_register &= ~HDSP_RPM_Inp12; switch (mode) { case 0: hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB; break; case 1: break; case 2: hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB; break; case 3: hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB; break; case 4: hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 4) val = 4; spin_lock_irq(&hdsp->lock); if (val != hdsp_rpm_input12(hdsp)) change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = { "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB" }; return snd_ctl_enum_info(uinfo, 1, 5, texts); } static int hdsp_rpm_input34(struct hdsp *hdsp) { switch (hdsp->control_register & HDSP_RPM_Inp34) { case HDSP_RPM_Inp34_Phon_6dB: return 0; case HDSP_RPM_Inp34_Phon_n6dB: return 2; case HDSP_RPM_Inp34_Line_0dB: return 3; case HDSP_RPM_Inp34_Line_n6dB: return 4; } return 1; } static int snd_hdsp_get_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp); return 0; } static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode) { hdsp->control_register &= ~HDSP_RPM_Inp34; switch (mode) { case 0: hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB; break; case 1: break; case 2: hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB; break; case 3: hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB; break; case 4: hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB; break; default: return -1; } hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_put_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.enumerated.item[0]; if (val < 0) val = 0; if (val > 4) val = 4; spin_lock_irq(&hdsp->lock); if (val != hdsp_rpm_input34(hdsp)) change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0; else change = 0; spin_unlock_irq(&hdsp->lock); return change; } /* RPM Bypass switch */ static int hdsp_rpm_bypass(struct hdsp *hdsp) { return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0; } static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp); return 0; } static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on) { if (on) hdsp->control_register |= HDSP_RPM_Bypass; else hdsp->control_register &= ~HDSP_RPM_Bypass; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdsp->lock); change = (int)val != hdsp_rpm_bypass(hdsp); hdsp_set_rpm_bypass(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"On", "Off"}; return snd_ctl_enum_info(uinfo, 1, 2, texts); } /* RPM Disconnect switch */ static int hdsp_rpm_disconnect(struct hdsp *hdsp) { return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0; } static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp); return 0; } static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on) { if (on) hdsp->control_register |= HDSP_RPM_Disconnect; else hdsp->control_register &= ~HDSP_RPM_Disconnect; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); return 0; } static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_hdsp_use_is_exclusive(hdsp)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&hdsp->lock); change = (int)val != hdsp_rpm_disconnect(hdsp); hdsp_set_rpm_disconnect(hdsp, val); spin_unlock_irq(&hdsp->lock); return change; } static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[] = {"On", "Off"}; return snd_ctl_enum_info(uinfo, 1, 2, texts); } static const struct snd_kcontrol_new snd_hdsp_rpm_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "RPM Bypass", .get = snd_hdsp_get_rpm_bypass, .put = snd_hdsp_put_rpm_bypass, .info = snd_hdsp_info_rpm_bypass }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "RPM Disconnect", .get = snd_hdsp_get_rpm_disconnect, .put = snd_hdsp_put_rpm_disconnect, .info = snd_hdsp_info_rpm_disconnect }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input 1/2", .get = snd_hdsp_get_rpm_input12, .put = snd_hdsp_put_rpm_input12, .info = snd_hdsp_info_rpm_input }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input 3/4", .get = snd_hdsp_get_rpm_input34, .put = snd_hdsp_put_rpm_input34, .info = snd_hdsp_info_rpm_input }, HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), HDSP_MIXER("Mixer", 0) }; static const struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_TOGGLE_SETTING("Analog Extension Board", HDSP_AnalogExtensionBoard); static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK; static bool hdsp_loopback_get(struct hdsp *const hdsp, const u8 channel) { return hdsp->io_loopback & (1 << channel); } static int hdsp_loopback_set(struct hdsp *const hdsp, const u8 channel, const bool enable) { if (hdsp_loopback_get(hdsp, channel) == enable) return 0; hdsp->io_loopback ^= (1 << channel); hdsp_write(hdsp, HDSP_inputEnable + (4 * (hdsp->max_channels + channel)), enable); return 1; } static int snd_hdsp_loopback_get(struct snd_kcontrol *const kcontrol, struct snd_ctl_elem_value *const ucontrol) { struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol); const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id); if (channel >= hdsp->max_channels) return -ENOENT; ucontrol->value.integer.value[0] = hdsp_loopback_get(hdsp, channel); return 0; } static int snd_hdsp_loopback_put(struct snd_kcontrol *const kcontrol, struct snd_ctl_elem_value *const ucontrol) { struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol); const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id); const bool enable = ucontrol->value.integer.value[0] & 1; if (channel >= hdsp->max_channels) return -ENOENT; return hdsp_loopback_set(hdsp, channel, enable); } static struct snd_kcontrol_new snd_hdsp_loopback_control = { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = "Output Loopback", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = snd_ctl_boolean_mono_info, .get = snd_hdsp_loopback_get, .put = snd_hdsp_loopback_put }; static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp) { unsigned int idx; int err; struct snd_kcontrol *kctl; if (hdsp->io_type == RPM) { /* RPM Bypass, Disconnect and Input switches */ for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_rpm_controls); idx++) { err = snd_ctl_add(card, snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp)); if (err < 0) return err; } return 0; } for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) { kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp); err = snd_ctl_add(card, kctl); if (err < 0) return err; if (idx == 1) /* IEC958 (S/PDIF) Stream */ hdsp->spdif_ctl = kctl; } /* ADAT SyncCheck status */ snd_hdsp_adat_sync_check.name = "ADAT Lock Status"; snd_hdsp_adat_sync_check.index = 1; kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp); err = snd_ctl_add(card, kctl); if (err < 0) return err; if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { for (idx = 1; idx < 3; ++idx) { snd_hdsp_adat_sync_check.index = idx+1; kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp); err = snd_ctl_add(card, kctl); if (err < 0) return err; } } /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */ if (hdsp->io_type == H9632) { for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) { kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp); err = snd_ctl_add(card, kctl); if (err < 0) return err; } } /* Output loopback controls for H9632 cards */ if (hdsp->io_type == H9632) { snd_hdsp_loopback_control.count = hdsp->max_channels; kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp); if (kctl == NULL) return -ENOMEM; err = snd_ctl_add(card, kctl); if (err < 0) return err; } /* AEB control for H96xx card */ if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp); err = snd_ctl_add(card, kctl); if (err < 0) return err; } return 0; } /*------------------------------------------------------------ /proc interface ------------------------------------------------------------*/ static void snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdsp *hdsp = entry->private_data; unsigned int status; unsigned int status2; char *pref_sync_ref; char *autosync_ref; char *system_clock_mode; char *clock_source; int x; status = hdsp_read(hdsp, HDSP_statusRegister); status2 = hdsp_read(hdsp, HDSP_status2Register); snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1); snd_iprintf(buffer, "Buffers: capture %p playback %p\n", hdsp->capture_buffer, hdsp->playback_buffer); snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase); snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register); snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register); snd_iprintf(buffer, "Status register: 0x%x\n", status); snd_iprintf(buffer, "Status2 register: 0x%x\n", status2); if (hdsp_check_for_iobox(hdsp)) { snd_iprintf(buffer, "No I/O box connected.\n" "Please connect one and upload firmware.\n"); return; } if (hdsp_check_for_firmware(hdsp, 0)) { if (hdsp->state & HDSP_FirmwareCached) { if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { snd_iprintf(buffer, "Firmware loading from " "cache failed, " "please upload manually.\n"); return; } } else { int err; err = hdsp_request_fw_loader(hdsp); if (err < 0) { snd_iprintf(buffer, "No firmware loaded nor cached, " "please upload firmware.\n"); return; } } } snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff); snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0)); snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0)); snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1)); snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1)); snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off"); snd_iprintf(buffer, "\n"); x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask)); snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes); snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp)); snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off"); snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off"); snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2); snd_iprintf(buffer, "\n"); switch (hdsp_clock_source(hdsp)) { case HDSP_CLOCK_SOURCE_AUTOSYNC: clock_source = "AutoSync"; break; case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ: clock_source = "Internal 32 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ: clock_source = "Internal 44.1 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ: clock_source = "Internal 48 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ: clock_source = "Internal 64 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ: clock_source = "Internal 88.2 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ: clock_source = "Internal 96 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ: clock_source = "Internal 128 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ: clock_source = "Internal 176.4 kHz"; break; case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ: clock_source = "Internal 192 kHz"; break; default: clock_source = "Error"; } snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source); if (hdsp_system_clock_mode(hdsp)) system_clock_mode = "Slave"; else system_clock_mode = "Master"; switch (hdsp_pref_sync_ref (hdsp)) { case HDSP_SYNC_FROM_WORD: pref_sync_ref = "Word Clock"; break; case HDSP_SYNC_FROM_ADAT_SYNC: pref_sync_ref = "ADAT Sync"; break; case HDSP_SYNC_FROM_SPDIF: pref_sync_ref = "SPDIF"; break; case HDSP_SYNC_FROM_ADAT1: pref_sync_ref = "ADAT1"; break; case HDSP_SYNC_FROM_ADAT2: pref_sync_ref = "ADAT2"; break; case HDSP_SYNC_FROM_ADAT3: pref_sync_ref = "ADAT3"; break; default: pref_sync_ref = "Word Clock"; break; } snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref); switch (hdsp_autosync_ref (hdsp)) { case HDSP_AUTOSYNC_FROM_WORD: autosync_ref = "Word Clock"; break; case HDSP_AUTOSYNC_FROM_ADAT_SYNC: autosync_ref = "ADAT Sync"; break; case HDSP_AUTOSYNC_FROM_SPDIF: autosync_ref = "SPDIF"; break; case HDSP_AUTOSYNC_FROM_NONE: autosync_ref = "None"; break; case HDSP_AUTOSYNC_FROM_ADAT1: autosync_ref = "ADAT1"; break; case HDSP_AUTOSYNC_FROM_ADAT2: autosync_ref = "ADAT2"; break; case HDSP_AUTOSYNC_FROM_ADAT3: autosync_ref = "ADAT3"; break; default: autosync_ref = "---"; break; } snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref); snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp)); snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode); snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate); snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No"); snd_iprintf(buffer, "\n"); if (hdsp->io_type != RPM) { switch (hdsp_spdif_in(hdsp)) { case HDSP_SPDIFIN_OPTICAL: snd_iprintf(buffer, "IEC958 input: Optical\n"); break; case HDSP_SPDIFIN_COAXIAL: snd_iprintf(buffer, "IEC958 input: Coaxial\n"); break; case HDSP_SPDIFIN_INTERNAL: snd_iprintf(buffer, "IEC958 input: Internal\n"); break; case HDSP_SPDIFIN_AES: snd_iprintf(buffer, "IEC958 input: AES\n"); break; default: snd_iprintf(buffer, "IEC958 input: ???\n"); break; } } if (RPM == hdsp->io_type) { if (hdsp->control_register & HDSP_RPM_Bypass) snd_iprintf(buffer, "RPM Bypass: disabled\n"); else snd_iprintf(buffer, "RPM Bypass: enabled\n"); if (hdsp->control_register & HDSP_RPM_Disconnect) snd_iprintf(buffer, "RPM disconnected\n"); else snd_iprintf(buffer, "RPM connected\n"); switch (hdsp->control_register & HDSP_RPM_Inp12) { case HDSP_RPM_Inp12_Phon_6dB: snd_iprintf(buffer, "Input 1/2: Phono, 6dB\n"); break; case HDSP_RPM_Inp12_Phon_0dB: snd_iprintf(buffer, "Input 1/2: Phono, 0dB\n"); break; case HDSP_RPM_Inp12_Phon_n6dB: snd_iprintf(buffer, "Input 1/2: Phono, -6dB\n"); break; case HDSP_RPM_Inp12_Line_0dB: snd_iprintf(buffer, "Input 1/2: Line, 0dB\n"); break; case HDSP_RPM_Inp12_Line_n6dB: snd_iprintf(buffer, "Input 1/2: Line, -6dB\n"); break; default: snd_iprintf(buffer, "Input 1/2: ???\n"); } switch (hdsp->control_register & HDSP_RPM_Inp34) { case HDSP_RPM_Inp34_Phon_6dB: snd_iprintf(buffer, "Input 3/4: Phono, 6dB\n"); break; case HDSP_RPM_Inp34_Phon_0dB: snd_iprintf(buffer, "Input 3/4: Phono, 0dB\n"); break; case HDSP_RPM_Inp34_Phon_n6dB: snd_iprintf(buffer, "Input 3/4: Phono, -6dB\n"); break; case HDSP_RPM_Inp34_Line_0dB: snd_iprintf(buffer, "Input 3/4: Line, 0dB\n"); break; case HDSP_RPM_Inp34_Line_n6dB: snd_iprintf(buffer, "Input 3/4: Line, -6dB\n"); break; default: snd_iprintf(buffer, "Input 3/4: ???\n"); } } else { if (hdsp->control_register & HDSP_SPDIFOpticalOut) snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); else snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); if (hdsp->control_register & HDSP_SPDIFProfessional) snd_iprintf(buffer, "IEC958 quality: Professional\n"); else snd_iprintf(buffer, "IEC958 quality: Consumer\n"); if (hdsp->control_register & HDSP_SPDIFEmphasis) snd_iprintf(buffer, "IEC958 emphasis: on\n"); else snd_iprintf(buffer, "IEC958 emphasis: off\n"); if (hdsp->control_register & HDSP_SPDIFNonAudio) snd_iprintf(buffer, "IEC958 NonAudio: on\n"); else snd_iprintf(buffer, "IEC958 NonAudio: off\n"); x = hdsp_spdif_sample_rate(hdsp); if (x != 0) snd_iprintf(buffer, "IEC958 sample rate: %d\n", x); else snd_iprintf(buffer, "IEC958 sample rate: Error flag set\n"); } snd_iprintf(buffer, "\n"); /* Sync Check */ x = status & HDSP_Sync0; if (status & HDSP_Lock0) snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock"); else snd_iprintf(buffer, "ADAT1: No Lock\n"); switch (hdsp->io_type) { case Digiface: case H9652: x = status & HDSP_Sync1; if (status & HDSP_Lock1) snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock"); else snd_iprintf(buffer, "ADAT2: No Lock\n"); x = status & HDSP_Sync2; if (status & HDSP_Lock2) snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock"); else snd_iprintf(buffer, "ADAT3: No Lock\n"); break; default: /* relax */ break; } x = status & HDSP_SPDIFSync; if (status & HDSP_SPDIFErrorFlag) snd_iprintf (buffer, "SPDIF: No Lock\n"); else snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock"); x = status2 & HDSP_wc_sync; if (status2 & HDSP_wc_lock) snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock"); else snd_iprintf (buffer, "Word Clock: No Lock\n"); x = status & HDSP_TimecodeSync; if (status & HDSP_TimecodeLock) snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock"); else snd_iprintf(buffer, "ADAT Sync: No Lock\n"); snd_iprintf(buffer, "\n"); /* Informations about H9632 specific controls */ if (hdsp->io_type == H9632) { char *tmp; switch (hdsp_ad_gain(hdsp)) { case 0: tmp = "-10 dBV"; break; case 1: tmp = "+4 dBu"; break; default: tmp = "Lo Gain"; break; } snd_iprintf(buffer, "AD Gain : %s\n", tmp); switch (hdsp_da_gain(hdsp)) { case 0: tmp = "Hi Gain"; break; case 1: tmp = "+4 dBu"; break; default: tmp = "-10 dBV"; break; } snd_iprintf(buffer, "DA Gain : %s\n", tmp); switch (hdsp_phone_gain(hdsp)) { case 0: tmp = "0 dB"; break; case 1: tmp = "-6 dB"; break; default: tmp = "-12 dB"; break; } snd_iprintf(buffer, "Phones Gain : %s\n", tmp); snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ? "yes" : "no"); if (hdsp->control_register & HDSP_AnalogExtensionBoard) snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); else snd_iprintf(buffer, "AEB : off (ADAT1 external)\n"); snd_iprintf(buffer, "\n"); } } static void snd_hdsp_proc_init(struct hdsp *hdsp) { snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read); } static int snd_hdsp_initialize_memory(struct hdsp *hdsp) { struct snd_dma_buffer *capture_dma, *playback_dma; capture_dma = snd_hammerfall_get_buffer(hdsp->pci, HDSP_DMA_AREA_BYTES); playback_dma = snd_hammerfall_get_buffer(hdsp->pci, HDSP_DMA_AREA_BYTES); if (!capture_dma || !playback_dma) { dev_err(hdsp->card->dev, "%s: no buffers available\n", hdsp->card_name); return -ENOMEM; } /* copy to the own data for alignment */ hdsp->capture_dma_buf = *capture_dma; hdsp->playback_dma_buf = *playback_dma; /* Align to bus-space 64K boundary */ hdsp->capture_dma_buf.addr = ALIGN(capture_dma->addr, 0x10000ul); hdsp->playback_dma_buf.addr = ALIGN(playback_dma->addr, 0x10000ul); /* Tell the card where it is */ hdsp_write(hdsp, HDSP_inputBufferAddress, hdsp->capture_dma_buf.addr); hdsp_write(hdsp, HDSP_outputBufferAddress, hdsp->playback_dma_buf.addr); hdsp->capture_dma_buf.area += hdsp->capture_dma_buf.addr - capture_dma->addr; hdsp->playback_dma_buf.area += hdsp->playback_dma_buf.addr - playback_dma->addr; hdsp->capture_buffer = hdsp->capture_dma_buf.area; hdsp->playback_buffer = hdsp->playback_dma_buf.area; return 0; } static int snd_hdsp_set_defaults(struct hdsp *hdsp) { unsigned int i; /* ASSUMPTION: hdsp->lock is either held, or there is no need to hold it (e.g. during module initialization). */ /* set defaults: SPDIF Input via Coax Master clock mode maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer, which implies 2 4096 sample, 32Kbyte periods). Enable line out. */ hdsp->control_register = HDSP_ClockModeMaster | HDSP_SPDIFInputCoaxial | hdsp_encode_latency(7) | HDSP_LineOut; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); #ifdef SNDRV_BIG_ENDIAN hdsp->control2_register = HDSP_BIGENDIAN_MODE; #else hdsp->control2_register = 0; #endif if (hdsp->io_type == H9652) snd_hdsp_9652_enable_mixer (hdsp); else hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); hdsp_reset_hw_pointer(hdsp); hdsp_compute_period_size(hdsp); /* silence everything */ for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN; for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) { if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) return -EIO; } /* H9632 specific defaults */ if (hdsp->io_type == H9632) { hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB); hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); } /* set a default rate so that the channel map is set up. */ hdsp_set_rate(hdsp, 48000, 1); return 0; } static void hdsp_midi_work(struct work_struct *work) { struct hdsp *hdsp = container_of(work, struct hdsp, midi_work); if (hdsp->midi[0].pending) snd_hdsp_midi_input_read (&hdsp->midi[0]); if (hdsp->midi[1].pending) snd_hdsp_midi_input_read (&hdsp->midi[1]); } static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id) { struct hdsp *hdsp = (struct hdsp *) dev_id; unsigned int status; int audio; int midi0; int midi1; unsigned int midi0status; unsigned int midi1status; int schedule = 0; status = hdsp_read(hdsp, HDSP_statusRegister); audio = status & HDSP_audioIRQPending; midi0 = status & HDSP_midi0IRQPending; midi1 = status & HDSP_midi1IRQPending; if (!audio && !midi0 && !midi1) return IRQ_NONE; hdsp_write(hdsp, HDSP_interruptConfirmation, 0); midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff; midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff; if (!(hdsp->state & HDSP_InitializationComplete)) return IRQ_HANDLED; if (audio) { if (hdsp->capture_substream) snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); if (hdsp->playback_substream) snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); } if (midi0 && midi0status) { if (hdsp->use_midi_work) { /* we disable interrupts for this input until processing is done */ hdsp->control_register &= ~HDSP_Midi0InterruptEnable; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); hdsp->midi[0].pending = 1; schedule = 1; } else { snd_hdsp_midi_input_read (&hdsp->midi[0]); } } if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) { if (hdsp->use_midi_work) { /* we disable interrupts for this input until processing is done */ hdsp->control_register &= ~HDSP_Midi1InterruptEnable; hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); hdsp->midi[1].pending = 1; schedule = 1; } else { snd_hdsp_midi_input_read (&hdsp->midi[1]); } } if (hdsp->use_midi_work && schedule) queue_work(system_highpri_wq, &hdsp->midi_work); return IRQ_HANDLED; } static snd_pcm_uframes_t snd_hdsp_hw_pointer(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); return hdsp_hw_pointer(hdsp); } static signed char *hdsp_channel_buffer_location(struct hdsp *hdsp, int stream, int channel) { int mapped_channel; if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels)) return NULL; mapped_channel = hdsp->channel_map[channel]; if (mapped_channel < 0) return NULL; if (stream == SNDRV_PCM_STREAM_CAPTURE) return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); else return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); } static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *src, unsigned long count) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); signed char *channel_buf; if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES)) return -EINVAL; channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; if (copy_from_iter(channel_buf + pos, count, src) != count) return -EFAULT; return 0; } static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *dst, unsigned long count) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); signed char *channel_buf; if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES)) return -EINVAL; channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; if (copy_to_iter(channel_buf + pos, count, dst) != count) return -EFAULT; return 0; } static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); signed char *channel_buf; channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; memset(channel_buf + pos, 0, count); return 0; } static int snd_hdsp_reset(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct hdsp *hdsp = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = hdsp->capture_substream; else other = hdsp->playback_substream; if (hdsp->running) runtime->status->hw_ptr = hdsp_hw_pointer(hdsp); else runtime->status->hw_ptr = 0; if (other) { struct snd_pcm_substream *s; struct snd_pcm_runtime *oruntime = other->runtime; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { oruntime->status->hw_ptr = runtime->status->hw_ptr; break; } } } return 0; } static int snd_hdsp_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); int err; pid_t this_pid; pid_t other_pid; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (hdsp_check_for_firmware(hdsp, 1)) return -EIO; spin_lock_irq(&hdsp->lock); if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis); hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream); this_pid = hdsp->playback_pid; other_pid = hdsp->capture_pid; } else { this_pid = hdsp->capture_pid; other_pid = hdsp->playback_pid; } if ((other_pid > 0) && (this_pid != other_pid)) { /* The other stream is open, and not by the same task as this one. Make sure that the parameters that matter are the same. */ if (params_rate(params) != hdsp->system_sample_rate) { spin_unlock_irq(&hdsp->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return -EBUSY; } if (params_period_size(params) != hdsp->period_bytes / 4) { spin_unlock_irq(&hdsp->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return -EBUSY; } /* We're fine. */ spin_unlock_irq(&hdsp->lock); return 0; } else { spin_unlock_irq(&hdsp->lock); } /* how to make sure that the rate matches an externally-set one ? */ spin_lock_irq(&hdsp->lock); if (! hdsp->clock_source_locked) { err = hdsp_set_rate(hdsp, params_rate(params), 0); if (err < 0) { spin_unlock_irq(&hdsp->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return err; } } spin_unlock_irq(&hdsp->lock); err = hdsp_set_interrupt_interval(hdsp, params_period_size(params)); if (err < 0) { _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return err; } return 0; } static int snd_hdsp_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info *info) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); unsigned int channel = info->channel; if (snd_BUG_ON(channel >= hdsp->max_channels)) return -EINVAL; channel = array_index_nospec(channel, hdsp->max_channels); if (hdsp->channel_map[channel] < 0) return -EINVAL; info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES; info->first = 0; info->step = 32; return 0; } static int snd_hdsp_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { switch (cmd) { case SNDRV_PCM_IOCTL1_RESET: return snd_hdsp_reset(substream); case SNDRV_PCM_IOCTL1_CHANNEL_INFO: return snd_hdsp_channel_info(substream, arg); default: break; } return snd_pcm_lib_ioctl(substream, cmd, arg); } static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; int running; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */ return -EIO; spin_lock(&hdsp->lock); running = hdsp->running; switch (cmd) { case SNDRV_PCM_TRIGGER_START: running |= 1 << substream->stream; break; case SNDRV_PCM_TRIGGER_STOP: running &= ~(1 << substream->stream); break; default: snd_BUG(); spin_unlock(&hdsp->lock); return -EINVAL; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = hdsp->capture_substream; else other = hdsp->playback_substream; if (other) { struct snd_pcm_substream *s; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { snd_pcm_trigger_done(s, substream); if (cmd == SNDRV_PCM_TRIGGER_START) running |= 1 << s->stream; else running &= ~(1 << s->stream); goto _ok; } } if (cmd == SNDRV_PCM_TRIGGER_START) { if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) && substream->stream == SNDRV_PCM_STREAM_CAPTURE) hdsp_silence_playback(hdsp); } else { if (running && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) hdsp_silence_playback(hdsp); } } else { if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) hdsp_silence_playback(hdsp); } _ok: snd_pcm_trigger_done(substream, substream); if (!hdsp->running && running) hdsp_start_audio(hdsp); else if (hdsp->running && !running) hdsp_stop_audio(hdsp); hdsp->running = running; spin_unlock(&hdsp->lock); return 0; } static int snd_hdsp_prepare(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); int result = 0; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (hdsp_check_for_firmware(hdsp, 1)) return -EIO; spin_lock_irq(&hdsp->lock); if (!hdsp->running) hdsp_reset_hw_pointer(hdsp); spin_unlock_irq(&hdsp->lock); return result; } static const struct snd_pcm_hardware snd_hdsp_playback_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), #ifdef SNDRV_BIG_ENDIAN .formats = SNDRV_PCM_FMTBIT_S32_BE, #else .formats = SNDRV_PCM_FMTBIT_S32_LE, #endif .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000), .rate_min = 32000, .rate_max = 96000, .channels_min = 6, .channels_max = HDSP_MAX_CHANNELS, .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS, .period_bytes_min = (64 * 4) * 10, .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS, .periods_min = 2, .periods_max = 2, .fifo_size = 0 }; static const struct snd_pcm_hardware snd_hdsp_capture_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START), #ifdef SNDRV_BIG_ENDIAN .formats = SNDRV_PCM_FMTBIT_S32_BE, #else .formats = SNDRV_PCM_FMTBIT_S32_LE, #endif .rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000), .rate_min = 32000, .rate_max = 96000, .channels_min = 5, .channels_max = HDSP_MAX_CHANNELS, .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS, .period_bytes_min = (64 * 4) * 10, .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS, .periods_min = 2, .periods_max = 2, .fifo_size = 0 }; static const unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 }; static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = { .count = ARRAY_SIZE(hdsp_period_sizes), .list = hdsp_period_sizes, .mask = 0 }; static const unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 }; static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = { .count = ARRAY_SIZE(hdsp_9632_sample_rates), .list = hdsp_9632_sample_rates, .mask = 0 }; static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); if (hdsp->io_type == H9632) { unsigned int list[3]; list[0] = hdsp->qs_in_channels; list[1] = hdsp->ds_in_channels; list[2] = hdsp->ss_in_channels; return snd_interval_list(c, 3, list, 0); } else { unsigned int list[2]; list[0] = hdsp->ds_in_channels; list[1] = hdsp->ss_in_channels; return snd_interval_list(c, 2, list, 0); } } static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned int list[3]; struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); if (hdsp->io_type == H9632) { list[0] = hdsp->qs_out_channels; list[1] = hdsp->ds_out_channels; list[2] = hdsp->ss_out_channels; return snd_interval_list(c, 3, list, 0); } else { list[0] = hdsp->ds_out_channels; list[1] = hdsp->ss_out_channels; } return snd_interval_list(c, 2, list, 0); } static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (r->min > 96000 && hdsp->io_type == H9632) { struct snd_interval t = { .min = hdsp->qs_in_channels, .max = hdsp->qs_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->min > 48000 && r->max <= 96000) { struct snd_interval t = { .min = hdsp->ds_in_channels, .max = hdsp->ds_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->max < 64000) { struct snd_interval t = { .min = hdsp->ss_in_channels, .max = hdsp->ss_in_channels, .integer = 1, }; return snd_interval_refine(c, &t); } return 0; } static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (r->min > 96000 && hdsp->io_type == H9632) { struct snd_interval t = { .min = hdsp->qs_out_channels, .max = hdsp->qs_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->min > 48000 && r->max <= 96000) { struct snd_interval t = { .min = hdsp->ds_out_channels, .max = hdsp->ds_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->max < 64000) { struct snd_interval t = { .min = hdsp->ss_out_channels, .max = hdsp->ss_out_channels, .integer = 1, }; return snd_interval_refine(c, &t); } return 0; } static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (c->min >= hdsp->ss_out_channels) { struct snd_interval t = { .min = 32000, .max = 48000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) { struct snd_interval t = { .min = 128000, .max = 192000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdsp->ds_out_channels) { struct snd_interval t = { .min = 64000, .max = 96000, .integer = 1, }; return snd_interval_refine(r, &t); } return 0; } static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct hdsp *hdsp = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (c->min >= hdsp->ss_in_channels) { struct snd_interval t = { .min = 32000, .max = 48000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) { struct snd_interval t = { .min = 128000, .max = 192000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= hdsp->ds_in_channels) { struct snd_interval t = { .min = 64000, .max = 96000, .integer = 1, }; return snd_interval_refine(r, &t); } return 0; } static int snd_hdsp_playback_open(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (hdsp_check_for_firmware(hdsp, 1)) return -EIO; spin_lock_irq(&hdsp->lock); snd_pcm_set_sync(substream); runtime->hw = snd_hdsp_playback_subinfo; snd_pcm_set_runtime_buffer(substream, &hdsp->playback_dma_buf); hdsp->playback_pid = current->pid; hdsp->playback_substream = substream; spin_unlock_irq(&hdsp->lock); snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes); if (hdsp->clock_source_locked) { runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate; } else if (hdsp->io_type == H9632) { runtime->hw.rate_max = 192000; runtime->hw.rates = SNDRV_PCM_RATE_KNOT; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates); } if (hdsp->io_type == H9632) { runtime->hw.channels_min = hdsp->qs_out_channels; runtime->hw.channels_max = hdsp->ss_out_channels; } snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_hdsp_hw_rule_out_channels, hdsp, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_hdsp_hw_rule_out_channels_rate, hdsp, SNDRV_PCM_HW_PARAM_RATE, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_hdsp_hw_rule_rate_out_channels, hdsp, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (RPM != hdsp->io_type) { hdsp->creg_spdif_stream = hdsp->creg_spdif; hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id); } return 0; } static int snd_hdsp_playback_release(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); spin_lock_irq(&hdsp->lock); hdsp->playback_pid = -1; hdsp->playback_substream = NULL; spin_unlock_irq(&hdsp->lock); if (RPM != hdsp->io_type) { hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id); } return 0; } static int snd_hdsp_capture_open(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (hdsp_check_for_firmware(hdsp, 1)) return -EIO; spin_lock_irq(&hdsp->lock); snd_pcm_set_sync(substream); runtime->hw = snd_hdsp_capture_subinfo; snd_pcm_set_runtime_buffer(substream, &hdsp->capture_dma_buf); hdsp->capture_pid = current->pid; hdsp->capture_substream = substream; spin_unlock_irq(&hdsp->lock); snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes); if (hdsp->io_type == H9632) { runtime->hw.channels_min = hdsp->qs_in_channels; runtime->hw.channels_max = hdsp->ss_in_channels; runtime->hw.rate_max = 192000; runtime->hw.rates = SNDRV_PCM_RATE_KNOT; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates); } snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_hdsp_hw_rule_in_channels, hdsp, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_hdsp_hw_rule_in_channels_rate, hdsp, SNDRV_PCM_HW_PARAM_RATE, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_hdsp_hw_rule_rate_in_channels, hdsp, SNDRV_PCM_HW_PARAM_CHANNELS, -1); return 0; } static int snd_hdsp_capture_release(struct snd_pcm_substream *substream) { struct hdsp *hdsp = snd_pcm_substream_chip(substream); spin_lock_irq(&hdsp->lock); hdsp->capture_pid = -1; hdsp->capture_substream = NULL; spin_unlock_irq(&hdsp->lock); return 0; } /* helper functions for copying meter values */ static inline int copy_u32_le(void __user *dest, void __iomem *src) { u32 val = readl(src); return copy_to_user(dest, &val, 4); } static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high) { u32 rms_low, rms_high; u64 rms; rms_low = readl(src_low); rms_high = readl(src_high); rms = ((u64)rms_high << 32) | rms_low; return copy_to_user(dest, &rms, 8); } static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high) { u32 rms_low, rms_high; u64 rms; rms_low = readl(src_low) & 0xffffff00; rms_high = readl(src_high) & 0xffffff00; rms = ((u64)rms_high << 32) | rms_low; return copy_to_user(dest, &rms, 8); } static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms) { int doublespeed = 0; int i, j, channels, ofs; if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus) doublespeed = 1; channels = doublespeed ? 14 : 26; for (i = 0, j = 0; i < 26; ++i) { if (doublespeed && (i & 4)) continue; ofs = HDSP_9652_peakBase - j * 4; if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs)) return -EFAULT; ofs -= channels * 4; if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs)) return -EFAULT; ofs -= channels * 4; if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs)) return -EFAULT; ofs = HDSP_9652_rmsBase + j * 8; if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs, hdsp->iobase + ofs + 4)) return -EFAULT; ofs += channels * 8; if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs, hdsp->iobase + ofs + 4)) return -EFAULT; ofs += channels * 8; if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs, hdsp->iobase + ofs + 4)) return -EFAULT; j++; } return 0; } static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms) { int i, j; struct hdsp_9632_meters __iomem *m; int doublespeed = 0; if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus) doublespeed = 1; m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase); for (i = 0, j = 0; i < 16; ++i, ++j) { if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j])) return -EFAULT; if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j])) return -EFAULT; if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j])) return -EFAULT; if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j], &m->input_rms_high[j])) return -EFAULT; if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j], &m->playback_rms_high[j])) return -EFAULT; if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j], &m->output_rms_high[j])) return -EFAULT; if (doublespeed && i == 3) i += 4; } return 0; } static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms) { int i; for (i = 0; i < 26; i++) { if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + HDSP_playbackPeakLevel + i * 4)) return -EFAULT; if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + HDSP_inputPeakLevel + i * 4)) return -EFAULT; } for (i = 0; i < 28; i++) { if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + HDSP_outputPeakLevel + i * 4)) return -EFAULT; } for (i = 0; i < 26; ++i) { if (copy_u64_le(&peak_rms->playback_rms[i], hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4, hdsp->iobase + HDSP_playbackRmsLevel + i * 8)) return -EFAULT; if (copy_u64_le(&peak_rms->input_rms[i], hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4, hdsp->iobase + HDSP_inputRmsLevel + i * 8)) return -EFAULT; } return 0; } static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) { struct hdsp *hdsp = hw->private_data; void __user *argp = (void __user *)arg; int err; switch (cmd) { case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: { struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg; err = hdsp_check_for_iobox(hdsp); if (err < 0) return err; err = hdsp_check_for_firmware(hdsp, 1); if (err < 0) return err; if (!(hdsp->state & HDSP_FirmwareLoaded)) { dev_err(hdsp->card->dev, "firmware needs to be uploaded to the card.\n"); return -EINVAL; } switch (hdsp->io_type) { case H9652: return hdsp_9652_get_peak(hdsp, peak_rms); case H9632: return hdsp_9632_get_peak(hdsp, peak_rms); default: return hdsp_get_peak(hdsp, peak_rms); } } case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: { struct hdsp_config_info info; unsigned long flags; int i; err = hdsp_check_for_iobox(hdsp); if (err < 0) return err; err = hdsp_check_for_firmware(hdsp, 1); if (err < 0) return err; memset(&info, 0, sizeof(info)); spin_lock_irqsave(&hdsp->lock, flags); info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); if (hdsp->io_type != H9632) info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i) info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp, HDSP_SPDIFOpticalOut); info.spdif_professional = (unsigned char) hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional); info.spdif_emphasis = (unsigned char) hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis); info.spdif_nonaudio = (unsigned char) hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio); info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp); info.system_sample_rate = hdsp->system_sample_rate; info.autosync_sample_rate = hdsp_external_sample_rate(hdsp); info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp); info.clock_source = (unsigned char)hdsp_clock_source(hdsp); info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp); info.line_out = (unsigned char) hdsp_toggle_setting(hdsp, HDSP_LineOut); if (hdsp->io_type == H9632) { info.da_gain = (unsigned char)hdsp_da_gain(hdsp); info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); info.xlr_breakout_cable = (unsigned char)hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable); } else if (hdsp->io_type == RPM) { info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp); info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp); } if (hdsp->io_type == H9632 || hdsp->io_type == H9652) info.analog_extension_board = (unsigned char)hdsp_toggle_setting(hdsp, HDSP_AnalogExtensionBoard); spin_unlock_irqrestore(&hdsp->lock, flags); if (copy_to_user(argp, &info, sizeof(info))) return -EFAULT; break; } case SNDRV_HDSP_IOCTL_GET_9632_AEB: { struct hdsp_9632_aeb h9632_aeb; if (hdsp->io_type != H9632) return -EINVAL; h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS; h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS; if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb))) return -EFAULT; break; } case SNDRV_HDSP_IOCTL_GET_VERSION: { struct hdsp_version hdsp_version; int err; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; if (hdsp->io_type == Undefined) { err = hdsp_get_iobox_version(hdsp); if (err < 0) return err; } memset(&hdsp_version, 0, sizeof(hdsp_version)); hdsp_version.io_type = hdsp->io_type; hdsp_version.firmware_rev = hdsp->firmware_rev; if (copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))) return -EFAULT; break; } case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { struct hdsp_firmware firmware; u32 __user *firmware_data; int err; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */ if (hdsp->io_type == Undefined) return -EINVAL; if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) return -EBUSY; dev_info(hdsp->card->dev, "initializing firmware upload\n"); if (copy_from_user(&firmware, argp, sizeof(firmware))) return -EFAULT; firmware_data = (u32 __user *)firmware.firmware_data; if (hdsp_check_for_iobox (hdsp)) return -EIO; if (!hdsp->fw_uploaded) { hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE); if (!hdsp->fw_uploaded) return -ENOMEM; } if (copy_from_user(hdsp->fw_uploaded, firmware_data, HDSP_FIRMWARE_SIZE)) { vfree(hdsp->fw_uploaded); hdsp->fw_uploaded = NULL; return -EFAULT; } hdsp->state |= HDSP_FirmwareCached; err = snd_hdsp_load_firmware_from_cache(hdsp); if (err < 0) return err; if (!(hdsp->state & HDSP_InitializationComplete)) { err = snd_hdsp_enable_io(hdsp); if (err < 0) return err; snd_hdsp_initialize_channels(hdsp); snd_hdsp_initialize_midi_flush(hdsp); err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp); if (err < 0) { dev_err(hdsp->card->dev, "error creating alsa devices\n"); return err; } } break; } case SNDRV_HDSP_IOCTL_GET_MIXER: { struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp; if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE)) return -EFAULT; break; } default: return -EINVAL; } return 0; } static const struct snd_pcm_ops snd_hdsp_playback_ops = { .open = snd_hdsp_playback_open, .close = snd_hdsp_playback_release, .ioctl = snd_hdsp_ioctl, .hw_params = snd_hdsp_hw_params, .prepare = snd_hdsp_prepare, .trigger = snd_hdsp_trigger, .pointer = snd_hdsp_hw_pointer, .copy = snd_hdsp_playback_copy, .fill_silence = snd_hdsp_hw_silence, }; static const struct snd_pcm_ops snd_hdsp_capture_ops = { .open = snd_hdsp_capture_open, .close = snd_hdsp_capture_release, .ioctl = snd_hdsp_ioctl, .hw_params = snd_hdsp_hw_params, .prepare = snd_hdsp_prepare, .trigger = snd_hdsp_trigger, .pointer = snd_hdsp_hw_pointer, .copy = snd_hdsp_capture_copy, }; static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp) { struct snd_hwdep *hw; int err; err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw); if (err < 0) return err; hdsp->hwdep = hw; hw->private_data = hdsp; strcpy(hw->name, "HDSP hwdep interface"); hw->ops.ioctl = snd_hdsp_hwdep_ioctl; hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl; return 0; } static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp) { struct snd_pcm *pcm; int err; err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm); if (err < 0) return err; hdsp->pcm = pcm; pcm->private_data = hdsp; strcpy(pcm->name, hdsp->card_name); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops); pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; return 0; } static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp) { hdsp->control2_register |= HDSP_9652_ENABLE_MIXER; hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); } static int snd_hdsp_enable_io (struct hdsp *hdsp) { int i; if (hdsp_fifo_wait (hdsp, 0, 100)) { dev_err(hdsp->card->dev, "enable_io fifo_wait failed\n"); return -EIO; } for (i = 0; i < hdsp->max_channels; ++i) { hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1); hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1); } return 0; } static void snd_hdsp_initialize_channels(struct hdsp *hdsp) { int status, aebi_channels, aebo_channels, i; switch (hdsp->io_type) { case Digiface: hdsp->card_name = "RME Hammerfall DSP + Digiface"; hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS; hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS; break; case H9652: hdsp->card_name = "RME Hammerfall HDSP 9652"; hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS; hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS; break; case H9632: status = hdsp_read(hdsp, HDSP_statusRegister); /* HDSP_AEBx bits are low when AEB are connected */ aebi_channels = (status & HDSP_AEBI) ? 0 : 4; aebo_channels = (status & HDSP_AEBO) ? 0 : 4; hdsp->card_name = "RME Hammerfall HDSP 9632"; hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels; hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels; hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels; hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels; hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels; hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels; /* Disable loopback of output channels, as the set function * only sets on a change we fake all bits (channels) as enabled. */ hdsp->io_loopback = 0xffffffff; for (i = 0; i < hdsp->max_channels; ++i) hdsp_loopback_set(hdsp, i, false); break; case Multiface: hdsp->card_name = "RME Hammerfall DSP + Multiface"; hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS; hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS; break; case RPM: hdsp->card_name = "RME Hammerfall DSP + RPM"; hdsp->ss_in_channels = RPM_CHANNELS-1; hdsp->ss_out_channels = RPM_CHANNELS; hdsp->ds_in_channels = RPM_CHANNELS-1; hdsp->ds_out_channels = RPM_CHANNELS; break; default: /* should never get here */ break; } } static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp) { snd_hdsp_flush_midi_input (hdsp, 0); snd_hdsp_flush_midi_input (hdsp, 1); } static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp) { int err; err = snd_hdsp_create_pcm(card, hdsp); if (err < 0) { dev_err(card->dev, "Error creating pcm interface\n"); return err; } err = snd_hdsp_create_midi(card, hdsp, 0); if (err < 0) { dev_err(card->dev, "Error creating first midi interface\n"); return err; } if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { err = snd_hdsp_create_midi(card, hdsp, 1); if (err < 0) { dev_err(card->dev, "Error creating second midi interface\n"); return err; } } err = snd_hdsp_create_controls(card, hdsp); if (err < 0) { dev_err(card->dev, "Error creating ctl interface\n"); return err; } snd_hdsp_proc_init(hdsp); hdsp->system_sample_rate = -1; hdsp->playback_pid = -1; hdsp->capture_pid = -1; hdsp->capture_substream = NULL; hdsp->playback_substream = NULL; err = snd_hdsp_set_defaults(hdsp); if (err < 0) { dev_err(card->dev, "Error setting default values\n"); return err; } if (!(hdsp->state & HDSP_InitializationComplete)) { strcpy(card->shortname, "Hammerfall DSP"); sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name, hdsp->port, hdsp->irq); err = snd_card_register(card); if (err < 0) { dev_err(card->dev, "error registering card\n"); return err; } hdsp->state |= HDSP_InitializationComplete; } return 0; } /* load firmware via hotplug fw loader */ static int hdsp_request_fw_loader(struct hdsp *hdsp) { const char *fwfile; const struct firmware *fw; int err; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; if (hdsp->io_type == Undefined) { err = hdsp_get_iobox_version(hdsp); if (err < 0) return err; if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; } /* caution: max length of firmware filename is 30! */ switch (hdsp->io_type) { case RPM: fwfile = "rpm_firmware.bin"; break; case Multiface: if (hdsp->firmware_rev == 0xa) fwfile = "multiface_firmware.bin"; else fwfile = "multiface_firmware_rev11.bin"; break; case Digiface: if (hdsp->firmware_rev == 0xa) fwfile = "digiface_firmware.bin"; else fwfile = "digiface_firmware_rev11.bin"; break; default: dev_err(hdsp->card->dev, "invalid io_type %d\n", hdsp->io_type); return -EINVAL; } if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) { dev_err(hdsp->card->dev, "cannot load firmware %s\n", fwfile); return -ENOENT; } if (fw->size < HDSP_FIRMWARE_SIZE) { dev_err(hdsp->card->dev, "too short firmware size %d (expected %d)\n", (int)fw->size, HDSP_FIRMWARE_SIZE); release_firmware(fw); return -EINVAL; } hdsp->firmware = fw; hdsp->state |= HDSP_FirmwareCached; err = snd_hdsp_load_firmware_from_cache(hdsp); if (err < 0) return err; if (!(hdsp->state & HDSP_InitializationComplete)) { err = snd_hdsp_enable_io(hdsp); if (err < 0) return err; err = snd_hdsp_create_hwdep(hdsp->card, hdsp); if (err < 0) { dev_err(hdsp->card->dev, "error creating hwdep device\n"); return err; } snd_hdsp_initialize_channels(hdsp); snd_hdsp_initialize_midi_flush(hdsp); err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp); if (err < 0) { dev_err(hdsp->card->dev, "error creating alsa devices\n"); return err; } } return 0; } static int snd_hdsp_create(struct snd_card *card, struct hdsp *hdsp) { struct pci_dev *pci = hdsp->pci; int err; int is_9652 = 0; int is_9632 = 0; hdsp->irq = -1; hdsp->state = 0; hdsp->midi[0].rmidi = NULL; hdsp->midi[1].rmidi = NULL; hdsp->midi[0].input = NULL; hdsp->midi[1].input = NULL; hdsp->midi[0].output = NULL; hdsp->midi[1].output = NULL; hdsp->midi[0].pending = 0; hdsp->midi[1].pending = 0; spin_lock_init(&hdsp->midi[0].lock); spin_lock_init(&hdsp->midi[1].lock); hdsp->iobase = NULL; hdsp->control_register = 0; hdsp->control2_register = 0; hdsp->io_type = Undefined; hdsp->max_channels = 26; hdsp->card = card; spin_lock_init(&hdsp->lock); INIT_WORK(&hdsp->midi_work, hdsp_midi_work); pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev); hdsp->firmware_rev &= 0xff; /* From Martin Bjoernsen : "It is important that the card's latency timer register in the PCI configuration space is set to a value much larger than 0 by the computer's BIOS or the driver. The windows driver always sets this 8 bit register [...] to its maximum 255 to avoid problems with some computers." */ pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF); strcpy(card->driver, "H-DSP"); strcpy(card->mixername, "Xilinx FPGA"); if (hdsp->firmware_rev < 0xa) return -ENODEV; else if (hdsp->firmware_rev < 0x64) hdsp->card_name = "RME Hammerfall DSP"; else if (hdsp->firmware_rev < 0x96) { hdsp->card_name = "RME HDSP 9652"; is_9652 = 1; } else { hdsp->card_name = "RME HDSP 9632"; hdsp->max_channels = 16; is_9632 = 1; } err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(hdsp->pci); err = pci_request_regions(pci, "hdsp"); if (err < 0) return err; hdsp->port = pci_resource_start(pci, 0); hdsp->iobase = devm_ioremap(&pci->dev, hdsp->port, HDSP_IO_EXTENT); if (!hdsp->iobase) { dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); return -EBUSY; } if (devm_request_irq(&pci->dev, pci->irq, snd_hdsp_interrupt, IRQF_SHARED, KBUILD_MODNAME, hdsp)) { dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq); return -EBUSY; } hdsp->irq = pci->irq; card->sync_irq = hdsp->irq; hdsp->precise_ptr = 0; hdsp->use_midi_work = 1; hdsp->dds_value = 0; err = snd_hdsp_initialize_memory(hdsp); if (err < 0) return err; if (!is_9652 && !is_9632) { /* we wait a maximum of 10 seconds to let freshly * inserted cardbus cards do their hardware init */ err = hdsp_wait_for_iobox(hdsp, 1000, 10); if (err < 0) return err; if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { err = hdsp_request_fw_loader(hdsp); if (err < 0) /* we don't fail as this can happen if userspace is not ready for firmware upload */ dev_err(hdsp->card->dev, "couldn't get firmware from userspace. try using hdsploader\n"); else /* init is complete, we return */ return 0; /* we defer initialization */ dev_info(hdsp->card->dev, "card initialization pending : waiting for firmware\n"); err = snd_hdsp_create_hwdep(card, hdsp); if (err < 0) return err; return 0; } else { dev_info(hdsp->card->dev, "Firmware already present, initializing card.\n"); if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2) hdsp->io_type = RPM; else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) hdsp->io_type = Multiface; else hdsp->io_type = Digiface; } } err = snd_hdsp_enable_io(hdsp); if (err) return err; if (is_9652) hdsp->io_type = H9652; if (is_9632) hdsp->io_type = H9632; err = snd_hdsp_create_hwdep(card, hdsp); if (err < 0) return err; snd_hdsp_initialize_channels(hdsp); snd_hdsp_initialize_midi_flush(hdsp); hdsp->state |= HDSP_FirmwareLoaded; err = snd_hdsp_create_alsa_devices(card, hdsp); if (err < 0) return err; return 0; } static void snd_hdsp_card_free(struct snd_card *card) { struct hdsp *hdsp = card->private_data; if (hdsp->port) { /* stop the audio, and cancel all interrupts */ cancel_work_sync(&hdsp->midi_work); hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable); hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register); } release_firmware(hdsp->firmware); vfree(hdsp->fw_uploaded); } static int snd_hdsp_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct hdsp *hdsp; struct snd_card *card; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(struct hdsp), &card); if (err < 0) return err; hdsp = card->private_data; card->private_free = snd_hdsp_card_free; hdsp->dev = dev; hdsp->pci = pci; err = snd_hdsp_create(card, hdsp); if (err) goto error; strcpy(card->shortname, "Hammerfall DSP"); sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name, hdsp->port, hdsp->irq); err = snd_card_register(card); if (err) goto error; pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver hdsp_driver = { .name = KBUILD_MODNAME, .id_table = snd_hdsp_ids, .probe = snd_hdsp_probe, }; module_pci_driver(hdsp_driver);
linux-master
sound/pci/rme9652/hdsp.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA driver for RME Digi9652 audio interfaces * * Copyright (c) 1999 IEM - Winfried Ritsch * Copyright (c) 1999-2001 Paul Davis */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/module.h> #include <linux/io.h> #include <linux/nospec.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/info.h> #include <sound/asoundef.h> #include <sound/initval.h> #include <asm/current.h> static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ static bool precise_ptr[SNDRV_CARDS]; /* Enable precise pointer */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for RME Digi9652 (Hammerfall) soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for RME Digi9652 (Hammerfall) soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable/disable specific RME96{52,36} soundcards."); module_param_array(precise_ptr, bool, NULL, 0444); MODULE_PARM_DESC(precise_ptr, "Enable precise pointer (doesn't work reliably)."); MODULE_AUTHOR("Paul Davis <[email protected]>, Winfried Ritsch"); MODULE_DESCRIPTION("RME Digi9652/Digi9636"); MODULE_LICENSE("GPL"); /* The Hammerfall has two sets of 24 ADAT + 2 S/PDIF channels, one for capture, one for playback. Both the ADAT and S/PDIF channels appear to the host CPU in the same block of memory. There is no functional difference between them in terms of access. The Hammerfall Light is identical to the Hammerfall, except that it has 2 sets 18 channels (16 ADAT + 2 S/PDIF) for capture and playback. */ #define RME9652_NCHANNELS 26 #define RME9636_NCHANNELS 18 /* Preferred sync source choices - used by "sync_pref" control switch */ #define RME9652_SYNC_FROM_SPDIF 0 #define RME9652_SYNC_FROM_ADAT1 1 #define RME9652_SYNC_FROM_ADAT2 2 #define RME9652_SYNC_FROM_ADAT3 3 /* Possible sources of S/PDIF input */ #define RME9652_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */ #define RME9652_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */ #define RME9652_SPDIFIN_INTERN 2 /* internal (CDROM) */ /* ------------- Status-Register bits --------------------- */ #define RME9652_IRQ (1<<0) /* IRQ is High if not reset by irq_clear */ #define RME9652_lock_2 (1<<1) /* ADAT 3-PLL: 1=locked, 0=unlocked */ #define RME9652_lock_1 (1<<2) /* ADAT 2-PLL: 1=locked, 0=unlocked */ #define RME9652_lock_0 (1<<3) /* ADAT 1-PLL: 1=locked, 0=unlocked */ #define RME9652_fs48 (1<<4) /* sample rate is 0=44.1/88.2,1=48/96 Khz */ #define RME9652_wsel_rd (1<<5) /* if Word-Clock is used and valid then 1 */ /* bits 6-15 encode h/w buffer pointer position */ #define RME9652_sync_2 (1<<16) /* if ADAT-IN 3 in sync to system clock */ #define RME9652_sync_1 (1<<17) /* if ADAT-IN 2 in sync to system clock */ #define RME9652_sync_0 (1<<18) /* if ADAT-IN 1 in sync to system clock */ #define RME9652_DS_rd (1<<19) /* 1=Double Speed Mode, 0=Normal Speed */ #define RME9652_tc_busy (1<<20) /* 1=time-code copy in progress (960ms) */ #define RME9652_tc_out (1<<21) /* time-code out bit */ #define RME9652_F_0 (1<<22) /* 000=64kHz, 100=88.2kHz, 011=96kHz */ #define RME9652_F_1 (1<<23) /* 111=32kHz, 110=44.1kHz, 101=48kHz, */ #define RME9652_F_2 (1<<24) /* external Crystal Chip if ERF=1 */ #define RME9652_ERF (1<<25) /* Error-Flag of SDPIF Receiver (1=No Lock) */ #define RME9652_buffer_id (1<<26) /* toggles by each interrupt on rec/play */ #define RME9652_tc_valid (1<<27) /* 1 = a signal is detected on time-code input */ #define RME9652_SPDIF_READ (1<<28) /* byte available from Rev 1.5+ S/PDIF interface */ #define RME9652_sync (RME9652_sync_0|RME9652_sync_1|RME9652_sync_2) #define RME9652_lock (RME9652_lock_0|RME9652_lock_1|RME9652_lock_2) #define RME9652_F (RME9652_F_0|RME9652_F_1|RME9652_F_2) #define rme9652_decode_spdif_rate(x) ((x)>>22) /* Bit 6..15 : h/w buffer pointer */ #define RME9652_buf_pos 0x000FFC0 /* Bits 31,30,29 are bits 5,4,3 of h/w pointer position on later Rev G EEPROMS and Rev 1.5 cards or later. */ #define RME9652_REV15_buf_pos(x) ((((x)&0xE0000000)>>26)|((x)&RME9652_buf_pos)) /* amount of io space we remap for register access. i'm not sure we even need this much, but 1K is nice round number :) */ #define RME9652_IO_EXTENT 1024 #define RME9652_init_buffer 0 #define RME9652_play_buffer 32 /* holds ptr to 26x64kBit host RAM */ #define RME9652_rec_buffer 36 /* holds ptr to 26x64kBit host RAM */ #define RME9652_control_register 64 #define RME9652_irq_clear 96 #define RME9652_time_code 100 /* useful if used with alesis adat */ #define RME9652_thru_base 128 /* 132...228 Thru for 26 channels */ /* Read-only registers */ /* Writing to any of the register locations writes to the status register. We'll use the first location as our point of access. */ #define RME9652_status_register 0 /* --------- Control-Register Bits ---------------- */ #define RME9652_start_bit (1<<0) /* start record/play */ /* bits 1-3 encode buffersize/latency */ #define RME9652_Master (1<<4) /* Clock Mode Master=1,Slave/Auto=0 */ #define RME9652_IE (1<<5) /* Interrupt Enable */ #define RME9652_freq (1<<6) /* samplerate 0=44.1/88.2, 1=48/96 kHz */ #define RME9652_freq1 (1<<7) /* if 0, 32kHz, else always 1 */ #define RME9652_DS (1<<8) /* Doule Speed 0=44.1/48, 1=88.2/96 Khz */ #define RME9652_PRO (1<<9) /* S/PDIF out: 0=consumer, 1=professional */ #define RME9652_EMP (1<<10) /* Emphasis 0=None, 1=ON */ #define RME9652_Dolby (1<<11) /* Non-audio bit 1=set, 0=unset */ #define RME9652_opt_out (1<<12) /* Use 1st optical OUT as SPDIF: 1=yes,0=no */ #define RME9652_wsel (1<<13) /* use Wordclock as sync (overwrites master) */ #define RME9652_inp_0 (1<<14) /* SPDIF-IN: 00=optical (ADAT1), */ #define RME9652_inp_1 (1<<15) /* 01=koaxial (Cinch), 10=Internal CDROM */ #define RME9652_SyncPref_ADAT2 (1<<16) #define RME9652_SyncPref_ADAT3 (1<<17) #define RME9652_SPDIF_RESET (1<<18) /* Rev 1.5+: h/w S/PDIF receiver */ #define RME9652_SPDIF_SELECT (1<<19) #define RME9652_SPDIF_CLOCK (1<<20) #define RME9652_SPDIF_WRITE (1<<21) #define RME9652_ADAT1_INTERNAL (1<<22) /* Rev 1.5+: if set, internal CD connector carries ADAT */ /* buffersize = 512Bytes * 2^n, where n is made from Bit2 ... Bit0 */ #define RME9652_latency 0x0e #define rme9652_encode_latency(x) (((x)&0x7)<<1) #define rme9652_decode_latency(x) (((x)>>1)&0x7) #define rme9652_running_double_speed(s) ((s)->control_register & RME9652_DS) #define RME9652_inp (RME9652_inp_0|RME9652_inp_1) #define rme9652_encode_spdif_in(x) (((x)&0x3)<<14) #define rme9652_decode_spdif_in(x) (((x)>>14)&0x3) #define RME9652_SyncPref_Mask (RME9652_SyncPref_ADAT2|RME9652_SyncPref_ADAT3) #define RME9652_SyncPref_ADAT1 0 #define RME9652_SyncPref_SPDIF (RME9652_SyncPref_ADAT2|RME9652_SyncPref_ADAT3) /* the size of a substream (1 mono data stream) */ #define RME9652_CHANNEL_BUFFER_SAMPLES (16*1024) #define RME9652_CHANNEL_BUFFER_BYTES (4*RME9652_CHANNEL_BUFFER_SAMPLES) /* the size of the area we need to allocate for DMA transfers. the size is the same regardless of the number of channels - the 9636 still uses the same memory area. Note that we allocate 1 more channel than is apparently needed because the h/w seems to write 1 byte beyond the end of the last page. Sigh. */ #define RME9652_DMA_AREA_BYTES ((RME9652_NCHANNELS+1) * RME9652_CHANNEL_BUFFER_BYTES) #define RME9652_DMA_AREA_KILOBYTES (RME9652_DMA_AREA_BYTES/1024) struct snd_rme9652 { int dev; spinlock_t lock; int irq; unsigned long port; void __iomem *iobase; int precise_ptr; u32 control_register; /* cached value */ u32 thru_bits; /* thru 1=on, 0=off channel 1=Bit1... channel 26= Bit26 */ u32 creg_spdif; u32 creg_spdif_stream; char *card_name; /* hammerfall or hammerfall light names */ size_t hw_offsetmask; /* &-with status register to get real hw_offset */ size_t prev_hw_offset; /* previous hw offset */ size_t max_jitter; /* maximum jitter in frames for hw pointer */ size_t period_bytes; /* guess what this is */ unsigned char ds_channels; unsigned char ss_channels; /* different for hammerfall/hammerfall-light */ /* DMA buffers; those are copied instances from the original snd_dma_buf * objects (which are managed via devres) for the address alignments */ struct snd_dma_buffer playback_dma_buf; struct snd_dma_buffer capture_dma_buf; unsigned char *capture_buffer; /* suitably aligned address */ unsigned char *playback_buffer; /* suitably aligned address */ pid_t capture_pid; pid_t playback_pid; struct snd_pcm_substream *capture_substream; struct snd_pcm_substream *playback_substream; int running; int passthru; /* non-zero if doing pass-thru */ int hw_rev; /* h/w rev * 10 (i.e. 1.5 has hw_rev = 15) */ int last_spdif_sample_rate; /* so that we can catch externally ... */ int last_adat_sample_rate; /* ... induced rate changes */ const signed char *channel_map; struct snd_card *card; struct snd_pcm *pcm; struct pci_dev *pci; struct snd_kcontrol *spdif_ctl; }; /* These tables map the ALSA channels 1..N to the channels that we need to use in order to find the relevant channel buffer. RME refer to this kind of mapping as between "the ADAT channel and the DMA channel." We index it using the logical audio channel, and the value is the DMA channel (i.e. channel buffer number) where the data for that channel can be read/written from/to. */ static const signed char channel_map_9652_ss[26] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; static const signed char channel_map_9636_ss[26] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* channels 16 and 17 are S/PDIF */ 24, 25, /* channels 18-25 don't exist */ -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_9652_ds[26] = { /* ADAT channels are remapped */ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, /* channels 12 and 13 are S/PDIF */ 24, 25, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static const signed char channel_map_9636_ds[26] = { /* ADAT channels are remapped */ 1, 3, 5, 7, 9, 11, 13, 15, /* channels 8 and 9 are S/PDIF */ 24, 25, /* others don't exist */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; static struct snd_dma_buffer * snd_hammerfall_get_buffer(struct pci_dev *pci, size_t size) { return snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, size); } static const struct pci_device_id snd_rme9652_ids[] = { { .vendor = 0x10ee, .device = 0x3fc4, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, }, /* RME Digi9652 */ { 0, }, }; MODULE_DEVICE_TABLE(pci, snd_rme9652_ids); static inline void rme9652_write(struct snd_rme9652 *rme9652, int reg, int val) { writel(val, rme9652->iobase + reg); } static inline unsigned int rme9652_read(struct snd_rme9652 *rme9652, int reg) { return readl(rme9652->iobase + reg); } static inline int snd_rme9652_use_is_exclusive(struct snd_rme9652 *rme9652) { unsigned long flags; int ret = 1; spin_lock_irqsave(&rme9652->lock, flags); if ((rme9652->playback_pid != rme9652->capture_pid) && (rme9652->playback_pid >= 0) && (rme9652->capture_pid >= 0)) { ret = 0; } spin_unlock_irqrestore(&rme9652->lock, flags); return ret; } static inline int rme9652_adat_sample_rate(struct snd_rme9652 *rme9652) { if (rme9652_running_double_speed(rme9652)) { return (rme9652_read(rme9652, RME9652_status_register) & RME9652_fs48) ? 96000 : 88200; } else { return (rme9652_read(rme9652, RME9652_status_register) & RME9652_fs48) ? 48000 : 44100; } } static inline void rme9652_compute_period_size(struct snd_rme9652 *rme9652) { unsigned int i; i = rme9652->control_register & RME9652_latency; rme9652->period_bytes = 1 << ((rme9652_decode_latency(i) + 8)); rme9652->hw_offsetmask = (rme9652->period_bytes * 2 - 1) & RME9652_buf_pos; rme9652->max_jitter = 80; } static snd_pcm_uframes_t rme9652_hw_pointer(struct snd_rme9652 *rme9652) { int status; unsigned int offset, frag; snd_pcm_uframes_t period_size = rme9652->period_bytes / 4; snd_pcm_sframes_t delta; status = rme9652_read(rme9652, RME9652_status_register); if (!rme9652->precise_ptr) return (status & RME9652_buffer_id) ? period_size : 0; offset = status & RME9652_buf_pos; /* The hardware may give a backward movement for up to 80 frames Martin Kirst <[email protected]> knows the details. */ delta = rme9652->prev_hw_offset - offset; delta &= 0xffff; if (delta <= (snd_pcm_sframes_t)rme9652->max_jitter * 4) offset = rme9652->prev_hw_offset; else rme9652->prev_hw_offset = offset; offset &= rme9652->hw_offsetmask; offset /= 4; frag = status & RME9652_buffer_id; if (offset < period_size) { if (offset > rme9652->max_jitter) { if (frag) dev_err(rme9652->card->dev, "Unexpected hw_pointer position (bufid == 0): status: %x offset: %d\n", status, offset); } else if (!frag) return 0; offset -= rme9652->max_jitter; if ((int)offset < 0) offset += period_size * 2; } else { if (offset > period_size + rme9652->max_jitter) { if (!frag) dev_err(rme9652->card->dev, "Unexpected hw_pointer position (bufid == 1): status: %x offset: %d\n", status, offset); } else if (frag) return period_size; offset -= rme9652->max_jitter; } return offset; } static inline void rme9652_reset_hw_pointer(struct snd_rme9652 *rme9652) { int i; /* reset the FIFO pointer to zero. We do this by writing to 8 registers, each of which is a 32bit wide register, and set them all to zero. Note that s->iobase is a pointer to int32, not pointer to char. */ for (i = 0; i < 8; i++) { rme9652_write(rme9652, i * 4, 0); udelay(10); } rme9652->prev_hw_offset = 0; } static inline void rme9652_start(struct snd_rme9652 *s) { s->control_register |= (RME9652_IE | RME9652_start_bit); rme9652_write(s, RME9652_control_register, s->control_register); } static inline void rme9652_stop(struct snd_rme9652 *s) { s->control_register &= ~(RME9652_start_bit | RME9652_IE); rme9652_write(s, RME9652_control_register, s->control_register); } static int rme9652_set_interrupt_interval(struct snd_rme9652 *s, unsigned int frames) { int restart = 0; int n; spin_lock_irq(&s->lock); restart = s->running; if (restart) rme9652_stop(s); frames >>= 7; n = 0; while (frames) { n++; frames >>= 1; } s->control_register &= ~RME9652_latency; s->control_register |= rme9652_encode_latency(n); rme9652_write(s, RME9652_control_register, s->control_register); rme9652_compute_period_size(s); if (restart) rme9652_start(s); spin_unlock_irq(&s->lock); return 0; } static int rme9652_set_rate(struct snd_rme9652 *rme9652, int rate) { int restart; int reject_if_open = 0; int xrate; if (!snd_rme9652_use_is_exclusive (rme9652)) { return -EBUSY; } /* Changing from a "single speed" to a "double speed" rate is not allowed if any substreams are open. This is because such a change causes a shift in the location of the DMA buffers and a reduction in the number of available buffers. Note that a similar but essentially insoluble problem exists for externally-driven rate changes. All we can do is to flag rate changes in the read/write routines. */ spin_lock_irq(&rme9652->lock); xrate = rme9652_adat_sample_rate(rme9652); switch (rate) { case 44100: if (xrate > 48000) { reject_if_open = 1; } rate = 0; break; case 48000: if (xrate > 48000) { reject_if_open = 1; } rate = RME9652_freq; break; case 88200: if (xrate < 48000) { reject_if_open = 1; } rate = RME9652_DS; break; case 96000: if (xrate < 48000) { reject_if_open = 1; } rate = RME9652_DS | RME9652_freq; break; default: spin_unlock_irq(&rme9652->lock); return -EINVAL; } if (reject_if_open && (rme9652->capture_pid >= 0 || rme9652->playback_pid >= 0)) { spin_unlock_irq(&rme9652->lock); return -EBUSY; } restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652->control_register &= ~(RME9652_freq | RME9652_DS); rme9652->control_register |= rate; rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); if (rate & RME9652_DS) { if (rme9652->ss_channels == RME9652_NCHANNELS) { rme9652->channel_map = channel_map_9652_ds; } else { rme9652->channel_map = channel_map_9636_ds; } } else { if (rme9652->ss_channels == RME9652_NCHANNELS) { rme9652->channel_map = channel_map_9652_ss; } else { rme9652->channel_map = channel_map_9636_ss; } } spin_unlock_irq(&rme9652->lock); return 0; } static void rme9652_set_thru(struct snd_rme9652 *rme9652, int channel, int enable) { int i; rme9652->passthru = 0; if (channel < 0) { /* set thru for all channels */ if (enable) { for (i = 0; i < RME9652_NCHANNELS; i++) { rme9652->thru_bits |= (1 << i); rme9652_write(rme9652, RME9652_thru_base + i * 4, 1); } } else { for (i = 0; i < RME9652_NCHANNELS; i++) { rme9652->thru_bits &= ~(1 << i); rme9652_write(rme9652, RME9652_thru_base + i * 4, 0); } } } else { int mapped_channel; mapped_channel = rme9652->channel_map[channel]; if (enable) { rme9652->thru_bits |= (1 << mapped_channel); } else { rme9652->thru_bits &= ~(1 << mapped_channel); } rme9652_write(rme9652, RME9652_thru_base + mapped_channel * 4, enable ? 1 : 0); } } static int rme9652_set_passthru(struct snd_rme9652 *rme9652, int onoff) { if (onoff) { rme9652_set_thru(rme9652, -1, 1); /* we don't want interrupts, so do a custom version of rme9652_start(). */ rme9652->control_register = RME9652_inp_0 | rme9652_encode_latency(7) | RME9652_start_bit; rme9652_reset_hw_pointer(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); rme9652->passthru = 1; } else { rme9652_set_thru(rme9652, -1, 0); rme9652_stop(rme9652); rme9652->passthru = 0; } return 0; } static void rme9652_spdif_set_bit (struct snd_rme9652 *rme9652, int mask, int onoff) { if (onoff) rme9652->control_register |= mask; else rme9652->control_register &= ~mask; rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); } static void rme9652_spdif_write_byte (struct snd_rme9652 *rme9652, const int val) { long mask; long i; for (i = 0, mask = 0x80; i < 8; i++, mask >>= 1) { if (val & mask) rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_WRITE, 1); else rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_WRITE, 0); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_CLOCK, 1); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_CLOCK, 0); } } static int rme9652_spdif_read_byte (struct snd_rme9652 *rme9652) { long mask; long val; long i; val = 0; for (i = 0, mask = 0x80; i < 8; i++, mask >>= 1) { rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_CLOCK, 1); if (rme9652_read (rme9652, RME9652_status_register) & RME9652_SPDIF_READ) val |= mask; rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_CLOCK, 0); } return val; } static void rme9652_write_spdif_codec (struct snd_rme9652 *rme9652, const int address, const int data) { rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 1); rme9652_spdif_write_byte (rme9652, 0x20); rme9652_spdif_write_byte (rme9652, address); rme9652_spdif_write_byte (rme9652, data); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 0); } static int rme9652_spdif_read_codec (struct snd_rme9652 *rme9652, const int address) { int ret; rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 1); rme9652_spdif_write_byte (rme9652, 0x20); rme9652_spdif_write_byte (rme9652, address); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 0); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 1); rme9652_spdif_write_byte (rme9652, 0x21); ret = rme9652_spdif_read_byte (rme9652); rme9652_spdif_set_bit (rme9652, RME9652_SPDIF_SELECT, 0); return ret; } static void rme9652_initialize_spdif_receiver (struct snd_rme9652 *rme9652) { /* XXX what unsets this ? */ rme9652->control_register |= RME9652_SPDIF_RESET; rme9652_write_spdif_codec (rme9652, 4, 0x40); rme9652_write_spdif_codec (rme9652, 17, 0x13); rme9652_write_spdif_codec (rme9652, 6, 0x02); } static inline int rme9652_spdif_sample_rate(struct snd_rme9652 *s) { unsigned int rate_bits; if (rme9652_read(s, RME9652_status_register) & RME9652_ERF) { return -1; /* error condition */ } if (s->hw_rev == 15) { int x, y, ret; x = rme9652_spdif_read_codec (s, 30); if (x != 0) y = 48000 * 64 / x; else y = 0; if (y > 30400 && y < 33600) ret = 32000; else if (y > 41900 && y < 46000) ret = 44100; else if (y > 46000 && y < 50400) ret = 48000; else if (y > 60800 && y < 67200) ret = 64000; else if (y > 83700 && y < 92000) ret = 88200; else if (y > 92000 && y < 100000) ret = 96000; else ret = 0; return ret; } rate_bits = rme9652_read(s, RME9652_status_register) & RME9652_F; switch (rme9652_decode_spdif_rate(rate_bits)) { case 0x7: return 32000; case 0x6: return 44100; case 0x5: return 48000; case 0x4: return 88200; case 0x3: return 96000; case 0x0: return 64000; default: dev_err(s->card->dev, "%s: unknown S/PDIF input rate (bits = 0x%x)\n", s->card_name, rate_bits); return 0; } } /*----------------------------------------------------------------------------- Control Interface ----------------------------------------------------------------------------*/ static u32 snd_rme9652_convert_from_aes(struct snd_aes_iec958 *aes) { u32 val = 0; val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? RME9652_PRO : 0; val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? RME9652_Dolby : 0; if (val & RME9652_PRO) val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? RME9652_EMP : 0; else val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? RME9652_EMP : 0; return val; } static void snd_rme9652_convert_to_aes(struct snd_aes_iec958 *aes, u32 val) { aes->status[0] = ((val & RME9652_PRO) ? IEC958_AES0_PROFESSIONAL : 0) | ((val & RME9652_Dolby) ? IEC958_AES0_NONAUDIO : 0); if (val & RME9652_PRO) aes->status[0] |= (val & RME9652_EMP) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0; else aes->status[0] |= (val & RME9652_EMP) ? IEC958_AES0_CON_EMPHASIS_5015 : 0; } static int snd_rme9652_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_rme9652_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); snd_rme9652_convert_to_aes(&ucontrol->value.iec958, rme9652->creg_spdif); return 0; } static int snd_rme9652_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; u32 val; val = snd_rme9652_convert_from_aes(&ucontrol->value.iec958); spin_lock_irq(&rme9652->lock); change = val != rme9652->creg_spdif; rme9652->creg_spdif = val; spin_unlock_irq(&rme9652->lock); return change; } static int snd_rme9652_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_rme9652_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); snd_rme9652_convert_to_aes(&ucontrol->value.iec958, rme9652->creg_spdif_stream); return 0; } static int snd_rme9652_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; u32 val; val = snd_rme9652_convert_from_aes(&ucontrol->value.iec958); spin_lock_irq(&rme9652->lock); change = val != rme9652->creg_spdif_stream; rme9652->creg_spdif_stream = val; rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby | RME9652_EMP); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register |= val); spin_unlock_irq(&rme9652->lock); return change; } static int snd_rme9652_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_rme9652_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = kcontrol->private_value; return 0; } #define RME9652_ADAT1_IN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_adat1_in, \ .get = snd_rme9652_get_adat1_in, \ .put = snd_rme9652_put_adat1_in } static unsigned int rme9652_adat1_in(struct snd_rme9652 *rme9652) { if (rme9652->control_register & RME9652_ADAT1_INTERNAL) return 1; return 0; } static int rme9652_set_adat1_input(struct snd_rme9652 *rme9652, int internal) { int restart = 0; if (internal) { rme9652->control_register |= RME9652_ADAT1_INTERNAL; } else { rme9652->control_register &= ~RME9652_ADAT1_INTERNAL; } /* XXX do we actually need to stop the card when we do this ? */ restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); return 0; } static int snd_rme9652_info_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[2] = {"ADAT1", "Internal"}; return snd_ctl_enum_info(uinfo, 1, 2, texts); } static int snd_rme9652_get_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.enumerated.item[0] = rme9652_adat1_in(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_adat1_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; val = ucontrol->value.enumerated.item[0] % 2; spin_lock_irq(&rme9652->lock); change = val != rme9652_adat1_in(rme9652); if (change) rme9652_set_adat1_input(rme9652, val); spin_unlock_irq(&rme9652->lock); return change; } #define RME9652_SPDIF_IN(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_spdif_in, \ .get = snd_rme9652_get_spdif_in, .put = snd_rme9652_put_spdif_in } static unsigned int rme9652_spdif_in(struct snd_rme9652 *rme9652) { return rme9652_decode_spdif_in(rme9652->control_register & RME9652_inp); } static int rme9652_set_spdif_input(struct snd_rme9652 *rme9652, int in) { int restart = 0; rme9652->control_register &= ~RME9652_inp; rme9652->control_register |= rme9652_encode_spdif_in(in); restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); return 0; } static int snd_rme9652_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[3] = {"ADAT1", "Coaxial", "Internal"}; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int snd_rme9652_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.enumerated.item[0] = rme9652_spdif_in(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; val = ucontrol->value.enumerated.item[0] % 3; spin_lock_irq(&rme9652->lock); change = val != rme9652_spdif_in(rme9652); if (change) rme9652_set_spdif_input(rme9652, val); spin_unlock_irq(&rme9652->lock); return change; } #define RME9652_SPDIF_OUT(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_spdif_out, \ .get = snd_rme9652_get_spdif_out, .put = snd_rme9652_put_spdif_out } static int rme9652_spdif_out(struct snd_rme9652 *rme9652) { return (rme9652->control_register & RME9652_opt_out) ? 1 : 0; } static int rme9652_set_spdif_output(struct snd_rme9652 *rme9652, int out) { int restart = 0; if (out) { rme9652->control_register |= RME9652_opt_out; } else { rme9652->control_register &= ~RME9652_opt_out; } restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); return 0; } #define snd_rme9652_info_spdif_out snd_ctl_boolean_mono_info static int snd_rme9652_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.integer.value[0] = rme9652_spdif_out(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int val; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&rme9652->lock); change = (int)val != rme9652_spdif_out(rme9652); rme9652_set_spdif_output(rme9652, val); spin_unlock_irq(&rme9652->lock); return change; } #define RME9652_SYNC_MODE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_sync_mode, \ .get = snd_rme9652_get_sync_mode, .put = snd_rme9652_put_sync_mode } static int rme9652_sync_mode(struct snd_rme9652 *rme9652) { if (rme9652->control_register & RME9652_wsel) { return 2; } else if (rme9652->control_register & RME9652_Master) { return 1; } else { return 0; } } static int rme9652_set_sync_mode(struct snd_rme9652 *rme9652, int mode) { int restart = 0; switch (mode) { case 0: rme9652->control_register &= ~(RME9652_Master | RME9652_wsel); break; case 1: rme9652->control_register = (rme9652->control_register & ~RME9652_wsel) | RME9652_Master; break; case 2: rme9652->control_register |= (RME9652_Master | RME9652_wsel); break; } restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); return 0; } static int snd_rme9652_info_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[3] = { "AutoSync", "Master", "Word Clock" }; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int snd_rme9652_get_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.enumerated.item[0] = rme9652_sync_mode(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_sync_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int val; val = ucontrol->value.enumerated.item[0] % 3; spin_lock_irq(&rme9652->lock); change = (int)val != rme9652_sync_mode(rme9652); rme9652_set_sync_mode(rme9652, val); spin_unlock_irq(&rme9652->lock); return change; } #define RME9652_SYNC_PREF(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_sync_pref, \ .get = snd_rme9652_get_sync_pref, .put = snd_rme9652_put_sync_pref } static int rme9652_sync_pref(struct snd_rme9652 *rme9652) { switch (rme9652->control_register & RME9652_SyncPref_Mask) { case RME9652_SyncPref_ADAT1: return RME9652_SYNC_FROM_ADAT1; case RME9652_SyncPref_ADAT2: return RME9652_SYNC_FROM_ADAT2; case RME9652_SyncPref_ADAT3: return RME9652_SYNC_FROM_ADAT3; case RME9652_SyncPref_SPDIF: return RME9652_SYNC_FROM_SPDIF; } /* Not reachable */ return 0; } static int rme9652_set_sync_pref(struct snd_rme9652 *rme9652, int pref) { int restart; rme9652->control_register &= ~RME9652_SyncPref_Mask; switch (pref) { case RME9652_SYNC_FROM_ADAT1: rme9652->control_register |= RME9652_SyncPref_ADAT1; break; case RME9652_SYNC_FROM_ADAT2: rme9652->control_register |= RME9652_SyncPref_ADAT2; break; case RME9652_SYNC_FROM_ADAT3: rme9652->control_register |= RME9652_SyncPref_ADAT3; break; case RME9652_SYNC_FROM_SPDIF: rme9652->control_register |= RME9652_SyncPref_SPDIF; break; } restart = rme9652->running; if (restart) rme9652_stop(rme9652); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); if (restart) rme9652_start(rme9652); return 0; } static int snd_rme9652_info_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[4] = { "IEC958 In", "ADAT1 In", "ADAT2 In", "ADAT3 In" }; struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); return snd_ctl_enum_info(uinfo, 1, rme9652->ss_channels == RME9652_NCHANNELS ? 4 : 3, texts); } static int snd_rme9652_get_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.enumerated.item[0] = rme9652_sync_pref(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_sync_pref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change, max; unsigned int val; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; max = rme9652->ss_channels == RME9652_NCHANNELS ? 4 : 3; val = ucontrol->value.enumerated.item[0] % max; spin_lock_irq(&rme9652->lock); change = (int)val != rme9652_sync_pref(rme9652); rme9652_set_sync_pref(rme9652, val); spin_unlock_irq(&rme9652->lock); return change; } static int snd_rme9652_info_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = rme9652->ss_channels; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int snd_rme9652_get_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); unsigned int k; u32 thru_bits = rme9652->thru_bits; for (k = 0; k < rme9652->ss_channels; ++k) { ucontrol->value.integer.value[k] = !!(thru_bits & (1 << k)); } return 0; } static int snd_rme9652_put_thru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int chn; u32 thru_bits = 0; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; for (chn = 0; chn < rme9652->ss_channels; ++chn) { if (ucontrol->value.integer.value[chn]) thru_bits |= 1 << chn; } spin_lock_irq(&rme9652->lock); change = thru_bits ^ rme9652->thru_bits; if (change) { for (chn = 0; chn < rme9652->ss_channels; ++chn) { if (!(change & (1 << chn))) continue; rme9652_set_thru(rme9652,chn,thru_bits&(1<<chn)); } } spin_unlock_irq(&rme9652->lock); return !!change; } #define RME9652_PASSTHRU(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_rme9652_info_passthru, \ .put = snd_rme9652_put_passthru, \ .get = snd_rme9652_get_passthru } #define snd_rme9652_info_passthru snd_ctl_boolean_mono_info static int snd_rme9652_get_passthru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.integer.value[0] = rme9652->passthru; spin_unlock_irq(&rme9652->lock); return 0; } static int snd_rme9652_put_passthru(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); int change; unsigned int val; int err = 0; if (!snd_rme9652_use_is_exclusive(rme9652)) return -EBUSY; val = ucontrol->value.integer.value[0] & 1; spin_lock_irq(&rme9652->lock); change = (ucontrol->value.integer.value[0] != rme9652->passthru); if (change) err = rme9652_set_passthru(rme9652, val); spin_unlock_irq(&rme9652->lock); return err ? err : change; } /* Read-only switches */ #define RME9652_SPDIF_RATE(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_rme9652_info_spdif_rate, \ .get = snd_rme9652_get_spdif_rate } static int snd_rme9652_info_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 96000; return 0; } static int snd_rme9652_get_spdif_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&rme9652->lock); ucontrol->value.integer.value[0] = rme9652_spdif_sample_rate(rme9652); spin_unlock_irq(&rme9652->lock); return 0; } #define RME9652_ADAT_SYNC(xname, xindex, xidx) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_rme9652_info_adat_sync, \ .get = snd_rme9652_get_adat_sync, .private_value = xidx } static int snd_rme9652_info_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[4] = { "No Lock", "Lock", "No Lock Sync", "Lock Sync" }; return snd_ctl_enum_info(uinfo, 1, 4, texts); } static int snd_rme9652_get_adat_sync(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); unsigned int mask1, mask2, val; switch (kcontrol->private_value) { case 0: mask1 = RME9652_lock_0; mask2 = RME9652_sync_0; break; case 1: mask1 = RME9652_lock_1; mask2 = RME9652_sync_1; break; case 2: mask1 = RME9652_lock_2; mask2 = RME9652_sync_2; break; default: return -EINVAL; } val = rme9652_read(rme9652, RME9652_status_register); ucontrol->value.enumerated.item[0] = (val & mask1) ? 1 : 0; ucontrol->value.enumerated.item[0] |= (val & mask2) ? 2 : 0; return 0; } #define RME9652_TC_VALID(xname, xindex) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ .info = snd_rme9652_info_tc_valid, \ .get = snd_rme9652_get_tc_valid } #define snd_rme9652_info_tc_valid snd_ctl_boolean_mono_info static int snd_rme9652_get_tc_valid(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = (rme9652_read(rme9652, RME9652_status_register) & RME9652_tc_valid) ? 1 : 0; return 0; } #ifdef ALSA_HAS_STANDARD_WAY_OF_RETURNING_TIMECODE /* FIXME: this routine needs a port to the new control API --jk */ static int snd_rme9652_get_tc_value(void *private_data, snd_kswitch_t *kswitch, snd_switch_t *uswitch) { struct snd_rme9652 *s = (struct snd_rme9652 *) private_data; u32 value; int i; uswitch->type = SNDRV_SW_TYPE_DWORD; if ((rme9652_read(s, RME9652_status_register) & RME9652_tc_valid) == 0) { uswitch->value.data32[0] = 0; return 0; } /* timecode request */ rme9652_write(s, RME9652_time_code, 0); /* XXX bug alert: loop-based timing !!!! */ for (i = 0; i < 50; i++) { if (!(rme9652_read(s, i * 4) & RME9652_tc_busy)) break; } if (!(rme9652_read(s, i * 4) & RME9652_tc_busy)) { return -EIO; } value = 0; for (i = 0; i < 32; i++) { value >>= 1; if (rme9652_read(s, i * 4) & RME9652_tc_out) value |= 0x80000000; } if (value > 2 * 60 * 48000) { value -= 2 * 60 * 48000; } else { value = 0; } uswitch->value.data32[0] = value; return 0; } #endif /* ALSA_HAS_STANDARD_WAY_OF_RETURNING_TIMECODE */ static const struct snd_kcontrol_new snd_rme9652_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .info = snd_rme9652_control_spdif_info, .get = snd_rme9652_control_spdif_get, .put = snd_rme9652_control_spdif_put, }, { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), .info = snd_rme9652_control_spdif_stream_info, .get = snd_rme9652_control_spdif_stream_get, .put = snd_rme9652_control_spdif_stream_put, }, { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), .info = snd_rme9652_control_spdif_mask_info, .get = snd_rme9652_control_spdif_mask_get, .private_value = IEC958_AES0_NONAUDIO | IEC958_AES0_PROFESSIONAL | IEC958_AES0_CON_EMPHASIS, }, { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK), .info = snd_rme9652_control_spdif_mask_info, .get = snd_rme9652_control_spdif_mask_get, .private_value = IEC958_AES0_NONAUDIO | IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_EMPHASIS, }, RME9652_SPDIF_IN("IEC958 Input Connector", 0), RME9652_SPDIF_OUT("IEC958 Output also on ADAT1", 0), RME9652_SYNC_MODE("Sync Mode", 0), RME9652_SYNC_PREF("Preferred Sync Source", 0), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Channels Thru", .index = 0, .info = snd_rme9652_info_thru, .get = snd_rme9652_get_thru, .put = snd_rme9652_put_thru, }, RME9652_SPDIF_RATE("IEC958 Sample Rate", 0), RME9652_ADAT_SYNC("ADAT1 Sync Check", 0, 0), RME9652_ADAT_SYNC("ADAT2 Sync Check", 0, 1), RME9652_TC_VALID("Timecode Valid", 0), RME9652_PASSTHRU("Passthru", 0) }; static const struct snd_kcontrol_new snd_rme9652_adat3_check = RME9652_ADAT_SYNC("ADAT3 Sync Check", 0, 2); static const struct snd_kcontrol_new snd_rme9652_adat1_input = RME9652_ADAT1_IN("ADAT1 Input Source", 0); static int snd_rme9652_create_controls(struct snd_card *card, struct snd_rme9652 *rme9652) { unsigned int idx; int err; struct snd_kcontrol *kctl; for (idx = 0; idx < ARRAY_SIZE(snd_rme9652_controls); idx++) { kctl = snd_ctl_new1(&snd_rme9652_controls[idx], rme9652); err = snd_ctl_add(card, kctl); if (err < 0) return err; if (idx == 1) /* IEC958 (S/PDIF) Stream */ rme9652->spdif_ctl = kctl; } if (rme9652->ss_channels == RME9652_NCHANNELS) { kctl = snd_ctl_new1(&snd_rme9652_adat3_check, rme9652); err = snd_ctl_add(card, kctl); if (err < 0) return err; } if (rme9652->hw_rev >= 15) { kctl = snd_ctl_new1(&snd_rme9652_adat1_input, rme9652); err = snd_ctl_add(card, kctl); if (err < 0) return err; } return 0; } /*------------------------------------------------------------ /proc interface ------------------------------------------------------------*/ static void snd_rme9652_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_rme9652 *rme9652 = (struct snd_rme9652 *) entry->private_data; u32 thru_bits = rme9652->thru_bits; int show_auto_sync_source = 0; int i; unsigned int status; int x; status = rme9652_read(rme9652, RME9652_status_register); snd_iprintf(buffer, "%s (Card #%d)\n", rme9652->card_name, rme9652->card->number + 1); snd_iprintf(buffer, "Buffers: capture %p playback %p\n", rme9652->capture_buffer, rme9652->playback_buffer); snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", rme9652->irq, rme9652->port, (unsigned long)rme9652->iobase); snd_iprintf(buffer, "Control register: %x\n", rme9652->control_register); snd_iprintf(buffer, "\n"); x = 1 << (6 + rme9652_decode_latency(rme9652->control_register & RME9652_latency)); snd_iprintf(buffer, "Latency: %d samples (2 periods of %lu bytes)\n", x, (unsigned long) rme9652->period_bytes); snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", rme9652_hw_pointer(rme9652)); snd_iprintf(buffer, "Passthru: %s\n", rme9652->passthru ? "yes" : "no"); if ((rme9652->control_register & (RME9652_Master | RME9652_wsel)) == 0) { snd_iprintf(buffer, "Clock mode: autosync\n"); show_auto_sync_source = 1; } else if (rme9652->control_register & RME9652_wsel) { if (status & RME9652_wsel_rd) { snd_iprintf(buffer, "Clock mode: word clock\n"); } else { snd_iprintf(buffer, "Clock mode: word clock (no signal)\n"); } } else { snd_iprintf(buffer, "Clock mode: master\n"); } if (show_auto_sync_source) { switch (rme9652->control_register & RME9652_SyncPref_Mask) { case RME9652_SyncPref_ADAT1: snd_iprintf(buffer, "Pref. sync source: ADAT1\n"); break; case RME9652_SyncPref_ADAT2: snd_iprintf(buffer, "Pref. sync source: ADAT2\n"); break; case RME9652_SyncPref_ADAT3: snd_iprintf(buffer, "Pref. sync source: ADAT3\n"); break; case RME9652_SyncPref_SPDIF: snd_iprintf(buffer, "Pref. sync source: IEC958\n"); break; default: snd_iprintf(buffer, "Pref. sync source: ???\n"); } } if (rme9652->hw_rev >= 15) snd_iprintf(buffer, "\nADAT1 Input source: %s\n", (rme9652->control_register & RME9652_ADAT1_INTERNAL) ? "Internal" : "ADAT1 optical"); snd_iprintf(buffer, "\n"); switch (rme9652_decode_spdif_in(rme9652->control_register & RME9652_inp)) { case RME9652_SPDIFIN_OPTICAL: snd_iprintf(buffer, "IEC958 input: ADAT1\n"); break; case RME9652_SPDIFIN_COAXIAL: snd_iprintf(buffer, "IEC958 input: Coaxial\n"); break; case RME9652_SPDIFIN_INTERN: snd_iprintf(buffer, "IEC958 input: Internal\n"); break; default: snd_iprintf(buffer, "IEC958 input: ???\n"); break; } if (rme9652->control_register & RME9652_opt_out) { snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); } else { snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); } if (rme9652->control_register & RME9652_PRO) { snd_iprintf(buffer, "IEC958 quality: Professional\n"); } else { snd_iprintf(buffer, "IEC958 quality: Consumer\n"); } if (rme9652->control_register & RME9652_EMP) { snd_iprintf(buffer, "IEC958 emphasis: on\n"); } else { snd_iprintf(buffer, "IEC958 emphasis: off\n"); } if (rme9652->control_register & RME9652_Dolby) { snd_iprintf(buffer, "IEC958 Dolby: on\n"); } else { snd_iprintf(buffer, "IEC958 Dolby: off\n"); } i = rme9652_spdif_sample_rate(rme9652); if (i < 0) { snd_iprintf(buffer, "IEC958 sample rate: error flag set\n"); } else if (i == 0) { snd_iprintf(buffer, "IEC958 sample rate: undetermined\n"); } else { snd_iprintf(buffer, "IEC958 sample rate: %d\n", i); } snd_iprintf(buffer, "\n"); snd_iprintf(buffer, "ADAT Sample rate: %dHz\n", rme9652_adat_sample_rate(rme9652)); /* Sync Check */ x = status & RME9652_sync_0; if (status & RME9652_lock_0) { snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock"); } else { snd_iprintf(buffer, "ADAT1: No Lock\n"); } x = status & RME9652_sync_1; if (status & RME9652_lock_1) { snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock"); } else { snd_iprintf(buffer, "ADAT2: No Lock\n"); } x = status & RME9652_sync_2; if (status & RME9652_lock_2) { snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock"); } else { snd_iprintf(buffer, "ADAT3: No Lock\n"); } snd_iprintf(buffer, "\n"); snd_iprintf(buffer, "Timecode signal: %s\n", (status & RME9652_tc_valid) ? "yes" : "no"); /* thru modes */ snd_iprintf(buffer, "Punch Status:\n\n"); for (i = 0; i < rme9652->ss_channels; i++) { if (thru_bits & (1 << i)) { snd_iprintf(buffer, "%2d: on ", i + 1); } else { snd_iprintf(buffer, "%2d: off ", i + 1); } if (((i + 1) % 8) == 0) { snd_iprintf(buffer, "\n"); } } snd_iprintf(buffer, "\n"); } static void snd_rme9652_proc_init(struct snd_rme9652 *rme9652) { snd_card_ro_proc_new(rme9652->card, "rme9652", rme9652, snd_rme9652_proc_read); } static void snd_rme9652_card_free(struct snd_card *card) { struct snd_rme9652 *rme9652 = (struct snd_rme9652 *) card->private_data; if (rme9652->irq >= 0) rme9652_stop(rme9652); } static int snd_rme9652_initialize_memory(struct snd_rme9652 *rme9652) { struct snd_dma_buffer *capture_dma, *playback_dma; capture_dma = snd_hammerfall_get_buffer(rme9652->pci, RME9652_DMA_AREA_BYTES); playback_dma = snd_hammerfall_get_buffer(rme9652->pci, RME9652_DMA_AREA_BYTES); if (!capture_dma || !playback_dma) { dev_err(rme9652->card->dev, "%s: no buffers available\n", rme9652->card_name); return -ENOMEM; } /* copy to the own data for alignment */ rme9652->capture_dma_buf = *capture_dma; rme9652->playback_dma_buf = *playback_dma; /* Align to bus-space 64K boundary */ rme9652->capture_dma_buf.addr = ALIGN(capture_dma->addr, 0x10000ul); rme9652->playback_dma_buf.addr = ALIGN(playback_dma->addr, 0x10000ul); /* Tell the card where it is */ rme9652_write(rme9652, RME9652_rec_buffer, rme9652->capture_dma_buf.addr); rme9652_write(rme9652, RME9652_play_buffer, rme9652->playback_dma_buf.addr); rme9652->capture_dma_buf.area += rme9652->capture_dma_buf.addr - capture_dma->addr; rme9652->playback_dma_buf.area += rme9652->playback_dma_buf.addr - playback_dma->addr; rme9652->capture_buffer = rme9652->capture_dma_buf.area; rme9652->playback_buffer = rme9652->playback_dma_buf.area; return 0; } static void snd_rme9652_set_defaults(struct snd_rme9652 *rme9652) { unsigned int k; /* ASSUMPTION: rme9652->lock is either held, or there is no need to hold it (e.g. during module initialization). */ /* set defaults: SPDIF Input via Coax autosync clock mode maximum latency (7 = 8192 samples, 64Kbyte buffer, which implies 2 4096 sample, 32Kbyte periods). if rev 1.5, initialize the S/PDIF receiver. */ rme9652->control_register = RME9652_inp_0 | rme9652_encode_latency(7); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register); rme9652_reset_hw_pointer(rme9652); rme9652_compute_period_size(rme9652); /* default: thru off for all channels */ for (k = 0; k < RME9652_NCHANNELS; ++k) rme9652_write(rme9652, RME9652_thru_base + k * 4, 0); rme9652->thru_bits = 0; rme9652->passthru = 0; /* set a default rate so that the channel map is set up */ rme9652_set_rate(rme9652, 48000); } static irqreturn_t snd_rme9652_interrupt(int irq, void *dev_id) { struct snd_rme9652 *rme9652 = (struct snd_rme9652 *) dev_id; if (!(rme9652_read(rme9652, RME9652_status_register) & RME9652_IRQ)) { return IRQ_NONE; } rme9652_write(rme9652, RME9652_irq_clear, 0); if (rme9652->capture_substream) { snd_pcm_period_elapsed(rme9652->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); } if (rme9652->playback_substream) { snd_pcm_period_elapsed(rme9652->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); } return IRQ_HANDLED; } static snd_pcm_uframes_t snd_rme9652_hw_pointer(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); return rme9652_hw_pointer(rme9652); } static signed char *rme9652_channel_buffer_location(struct snd_rme9652 *rme9652, int stream, int channel) { int mapped_channel; if (snd_BUG_ON(channel < 0 || channel >= RME9652_NCHANNELS)) return NULL; mapped_channel = rme9652->channel_map[channel]; if (mapped_channel < 0) return NULL; if (stream == SNDRV_PCM_STREAM_CAPTURE) { return rme9652->capture_buffer + (mapped_channel * RME9652_CHANNEL_BUFFER_BYTES); } else { return rme9652->playback_buffer + (mapped_channel * RME9652_CHANNEL_BUFFER_BYTES); } } static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *src, unsigned long count) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); signed char *channel_buf; if (snd_BUG_ON(pos + count > RME9652_CHANNEL_BUFFER_BYTES)) return -EINVAL; channel_buf = rme9652_channel_buffer_location (rme9652, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; if (copy_from_iter(channel_buf + pos, count, src) != count) return -EFAULT; return 0; } static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *dst, unsigned long count) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); signed char *channel_buf; if (snd_BUG_ON(pos + count > RME9652_CHANNEL_BUFFER_BYTES)) return -EINVAL; channel_buf = rme9652_channel_buffer_location (rme9652, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; if (copy_to_iter(channel_buf + pos, count, dst) != count) return -EFAULT; return 0; } static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); signed char *channel_buf; channel_buf = rme9652_channel_buffer_location (rme9652, substream->pstr->stream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; memset(channel_buf + pos, 0, count); return 0; } static int snd_rme9652_reset(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = rme9652->capture_substream; else other = rme9652->playback_substream; if (rme9652->running) runtime->status->hw_ptr = rme9652_hw_pointer(rme9652); else runtime->status->hw_ptr = 0; if (other) { struct snd_pcm_substream *s; struct snd_pcm_runtime *oruntime = other->runtime; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { oruntime->status->hw_ptr = runtime->status->hw_ptr; break; } } } return 0; } static int snd_rme9652_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); int err; pid_t this_pid; pid_t other_pid; spin_lock_irq(&rme9652->lock); if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby | RME9652_EMP); rme9652_write(rme9652, RME9652_control_register, rme9652->control_register |= rme9652->creg_spdif_stream); this_pid = rme9652->playback_pid; other_pid = rme9652->capture_pid; } else { this_pid = rme9652->capture_pid; other_pid = rme9652->playback_pid; } if ((other_pid > 0) && (this_pid != other_pid)) { /* The other stream is open, and not by the same task as this one. Make sure that the parameters that matter are the same. */ if ((int)params_rate(params) != rme9652_adat_sample_rate(rme9652)) { spin_unlock_irq(&rme9652->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return -EBUSY; } if (params_period_size(params) != rme9652->period_bytes / 4) { spin_unlock_irq(&rme9652->lock); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return -EBUSY; } /* We're fine. */ spin_unlock_irq(&rme9652->lock); return 0; } else { spin_unlock_irq(&rme9652->lock); } /* how to make sure that the rate matches an externally-set one ? */ err = rme9652_set_rate(rme9652, params_rate(params)); if (err < 0) { _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return err; } err = rme9652_set_interrupt_interval(rme9652, params_period_size(params)); if (err < 0) { _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return err; } return 0; } static int snd_rme9652_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info *info) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); int chn; if (snd_BUG_ON(info->channel >= RME9652_NCHANNELS)) return -EINVAL; chn = rme9652->channel_map[array_index_nospec(info->channel, RME9652_NCHANNELS)]; if (chn < 0) return -EINVAL; info->offset = chn * RME9652_CHANNEL_BUFFER_BYTES; info->first = 0; info->step = 32; return 0; } static int snd_rme9652_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { switch (cmd) { case SNDRV_PCM_IOCTL1_RESET: { return snd_rme9652_reset(substream); } case SNDRV_PCM_IOCTL1_CHANNEL_INFO: { struct snd_pcm_channel_info *info = arg; return snd_rme9652_channel_info(substream, info); } default: break; } return snd_pcm_lib_ioctl(substream, cmd, arg); } static void rme9652_silence_playback(struct snd_rme9652 *rme9652) { memset(rme9652->playback_buffer, 0, RME9652_DMA_AREA_BYTES); } static int snd_rme9652_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); struct snd_pcm_substream *other; int running; spin_lock(&rme9652->lock); running = rme9652->running; switch (cmd) { case SNDRV_PCM_TRIGGER_START: running |= 1 << substream->stream; break; case SNDRV_PCM_TRIGGER_STOP: running &= ~(1 << substream->stream); break; default: snd_BUG(); spin_unlock(&rme9652->lock); return -EINVAL; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) other = rme9652->capture_substream; else other = rme9652->playback_substream; if (other) { struct snd_pcm_substream *s; snd_pcm_group_for_each_entry(s, substream) { if (s == other) { snd_pcm_trigger_done(s, substream); if (cmd == SNDRV_PCM_TRIGGER_START) running |= 1 << s->stream; else running &= ~(1 << s->stream); goto _ok; } } if (cmd == SNDRV_PCM_TRIGGER_START) { if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) && substream->stream == SNDRV_PCM_STREAM_CAPTURE) rme9652_silence_playback(rme9652); } else { if (running && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) rme9652_silence_playback(rme9652); } } else { if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) rme9652_silence_playback(rme9652); } _ok: snd_pcm_trigger_done(substream, substream); if (!rme9652->running && running) rme9652_start(rme9652); else if (rme9652->running && !running) rme9652_stop(rme9652); rme9652->running = running; spin_unlock(&rme9652->lock); return 0; } static int snd_rme9652_prepare(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); unsigned long flags; spin_lock_irqsave(&rme9652->lock, flags); if (!rme9652->running) rme9652_reset_hw_pointer(rme9652); spin_unlock_irqrestore(&rme9652->lock, flags); return 0; } static const struct snd_pcm_hardware snd_rme9652_playback_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), .formats = SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000), .rate_min = 44100, .rate_max = 96000, .channels_min = 10, .channels_max = 26, .buffer_bytes_max = RME9652_CHANNEL_BUFFER_BYTES * 26, .period_bytes_min = (64 * 4) * 10, .period_bytes_max = (8192 * 4) * 26, .periods_min = 2, .periods_max = 2, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_rme9652_capture_subinfo = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_SYNC_START), .formats = SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000), .rate_min = 44100, .rate_max = 96000, .channels_min = 10, .channels_max = 26, .buffer_bytes_max = RME9652_CHANNEL_BUFFER_BYTES *26, .period_bytes_min = (64 * 4) * 10, .period_bytes_max = (8192 * 4) * 26, .periods_min = 2, .periods_max = 2, .fifo_size = 0, }; static const unsigned int period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 }; static const struct snd_pcm_hw_constraint_list hw_constraints_period_sizes = { .count = ARRAY_SIZE(period_sizes), .list = period_sizes, .mask = 0 }; static int snd_rme9652_hw_rule_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_rme9652 *rme9652 = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); unsigned int list[2] = { rme9652->ds_channels, rme9652->ss_channels }; return snd_interval_list(c, 2, list, 0); } static int snd_rme9652_hw_rule_channels_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_rme9652 *rme9652 = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (r->min > 48000) { struct snd_interval t = { .min = rme9652->ds_channels, .max = rme9652->ds_channels, .integer = 1, }; return snd_interval_refine(c, &t); } else if (r->max < 88200) { struct snd_interval t = { .min = rme9652->ss_channels, .max = rme9652->ss_channels, .integer = 1, }; return snd_interval_refine(c, &t); } return 0; } static int snd_rme9652_hw_rule_rate_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_rme9652 *rme9652 = rule->private; struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); if (c->min >= rme9652->ss_channels) { struct snd_interval t = { .min = 44100, .max = 48000, .integer = 1, }; return snd_interval_refine(r, &t); } else if (c->max <= rme9652->ds_channels) { struct snd_interval t = { .min = 88200, .max = 96000, .integer = 1, }; return snd_interval_refine(r, &t); } return 0; } static int snd_rme9652_playback_open(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; spin_lock_irq(&rme9652->lock); snd_pcm_set_sync(substream); runtime->hw = snd_rme9652_playback_subinfo; snd_pcm_set_runtime_buffer(substream, &rme9652->playback_dma_buf); if (rme9652->capture_substream == NULL) { rme9652_stop(rme9652); rme9652_set_thru(rme9652, -1, 0); } rme9652->playback_pid = current->pid; rme9652->playback_substream = substream; spin_unlock_irq(&rme9652->lock); snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_period_sizes); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_rme9652_hw_rule_channels, rme9652, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_rme9652_hw_rule_channels_rate, rme9652, SNDRV_PCM_HW_PARAM_RATE, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_rme9652_hw_rule_rate_channels, rme9652, SNDRV_PCM_HW_PARAM_CHANNELS, -1); rme9652->creg_spdif_stream = rme9652->creg_spdif; rme9652->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id); return 0; } static int snd_rme9652_playback_release(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); spin_lock_irq(&rme9652->lock); rme9652->playback_pid = -1; rme9652->playback_substream = NULL; spin_unlock_irq(&rme9652->lock); rme9652->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &rme9652->spdif_ctl->id); return 0; } static int snd_rme9652_capture_open(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; spin_lock_irq(&rme9652->lock); snd_pcm_set_sync(substream); runtime->hw = snd_rme9652_capture_subinfo; snd_pcm_set_runtime_buffer(substream, &rme9652->capture_dma_buf); if (rme9652->playback_substream == NULL) { rme9652_stop(rme9652); rme9652_set_thru(rme9652, -1, 0); } rme9652->capture_pid = current->pid; rme9652->capture_substream = substream; spin_unlock_irq(&rme9652->lock); snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_period_sizes); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_rme9652_hw_rule_channels, rme9652, SNDRV_PCM_HW_PARAM_CHANNELS, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_rme9652_hw_rule_channels_rate, rme9652, SNDRV_PCM_HW_PARAM_RATE, -1); snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_rme9652_hw_rule_rate_channels, rme9652, SNDRV_PCM_HW_PARAM_CHANNELS, -1); return 0; } static int snd_rme9652_capture_release(struct snd_pcm_substream *substream) { struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream); spin_lock_irq(&rme9652->lock); rme9652->capture_pid = -1; rme9652->capture_substream = NULL; spin_unlock_irq(&rme9652->lock); return 0; } static const struct snd_pcm_ops snd_rme9652_playback_ops = { .open = snd_rme9652_playback_open, .close = snd_rme9652_playback_release, .ioctl = snd_rme9652_ioctl, .hw_params = snd_rme9652_hw_params, .prepare = snd_rme9652_prepare, .trigger = snd_rme9652_trigger, .pointer = snd_rme9652_hw_pointer, .copy = snd_rme9652_playback_copy, .fill_silence = snd_rme9652_hw_silence, }; static const struct snd_pcm_ops snd_rme9652_capture_ops = { .open = snd_rme9652_capture_open, .close = snd_rme9652_capture_release, .ioctl = snd_rme9652_ioctl, .hw_params = snd_rme9652_hw_params, .prepare = snd_rme9652_prepare, .trigger = snd_rme9652_trigger, .pointer = snd_rme9652_hw_pointer, .copy = snd_rme9652_capture_copy, }; static int snd_rme9652_create_pcm(struct snd_card *card, struct snd_rme9652 *rme9652) { struct snd_pcm *pcm; int err; err = snd_pcm_new(card, rme9652->card_name, 0, 1, 1, &pcm); if (err < 0) return err; rme9652->pcm = pcm; pcm->private_data = rme9652; strcpy(pcm->name, rme9652->card_name); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rme9652_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rme9652_capture_ops); pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; return 0; } static int snd_rme9652_create(struct snd_card *card, struct snd_rme9652 *rme9652, int precise_ptr) { struct pci_dev *pci = rme9652->pci; int err; int status; unsigned short rev; rme9652->irq = -1; rme9652->card = card; pci_read_config_word(rme9652->pci, PCI_CLASS_REVISION, &rev); switch (rev & 0xff) { case 3: case 4: case 8: case 9: break; default: /* who knows? */ return -ENODEV; } err = pcim_enable_device(pci); if (err < 0) return err; spin_lock_init(&rme9652->lock); err = pci_request_regions(pci, "rme9652"); if (err < 0) return err; rme9652->port = pci_resource_start(pci, 0); rme9652->iobase = devm_ioremap(&pci->dev, rme9652->port, RME9652_IO_EXTENT); if (rme9652->iobase == NULL) { dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1); return -EBUSY; } if (devm_request_irq(&pci->dev, pci->irq, snd_rme9652_interrupt, IRQF_SHARED, KBUILD_MODNAME, rme9652)) { dev_err(card->dev, "unable to request IRQ %d\n", pci->irq); return -EBUSY; } rme9652->irq = pci->irq; card->sync_irq = rme9652->irq; rme9652->precise_ptr = precise_ptr; /* Determine the h/w rev level of the card. This seems like a particularly kludgy way to encode it, but its what RME chose to do, so we follow them ... */ status = rme9652_read(rme9652, RME9652_status_register); if (rme9652_decode_spdif_rate(status&RME9652_F) == 1) { rme9652->hw_rev = 15; } else { rme9652->hw_rev = 11; } /* Differentiate between the standard Hammerfall, and the "Light", which does not have the expansion board. This method comes from information received from Mathhias Clausen at RME. Display the EEPROM and h/w revID where relevant. */ switch (rev) { case 8: /* original eprom */ strcpy(card->driver, "RME9636"); if (rme9652->hw_rev == 15) { rme9652->card_name = "RME Digi9636 (Rev 1.5)"; } else { rme9652->card_name = "RME Digi9636"; } rme9652->ss_channels = RME9636_NCHANNELS; break; case 9: /* W36_G EPROM */ strcpy(card->driver, "RME9636"); rme9652->card_name = "RME Digi9636 (Rev G)"; rme9652->ss_channels = RME9636_NCHANNELS; break; case 4: /* W52_G EPROM */ strcpy(card->driver, "RME9652"); rme9652->card_name = "RME Digi9652 (Rev G)"; rme9652->ss_channels = RME9652_NCHANNELS; break; case 3: /* original eprom */ strcpy(card->driver, "RME9652"); if (rme9652->hw_rev == 15) { rme9652->card_name = "RME Digi9652 (Rev 1.5)"; } else { rme9652->card_name = "RME Digi9652"; } rme9652->ss_channels = RME9652_NCHANNELS; break; } rme9652->ds_channels = (rme9652->ss_channels - 2) / 2 + 2; pci_set_master(rme9652->pci); err = snd_rme9652_initialize_memory(rme9652); if (err < 0) return err; err = snd_rme9652_create_pcm(card, rme9652); if (err < 0) return err; err = snd_rme9652_create_controls(card, rme9652); if (err < 0) return err; snd_rme9652_proc_init(rme9652); rme9652->last_spdif_sample_rate = -1; rme9652->last_adat_sample_rate = -1; rme9652->playback_pid = -1; rme9652->capture_pid = -1; rme9652->capture_substream = NULL; rme9652->playback_substream = NULL; snd_rme9652_set_defaults(rme9652); if (rme9652->hw_rev == 15) { rme9652_initialize_spdif_receiver (rme9652); } return 0; } static int snd_rme9652_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_rme9652 *rme9652; struct snd_card *card; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(struct snd_rme9652), &card); if (err < 0) return err; rme9652 = (struct snd_rme9652 *) card->private_data; card->private_free = snd_rme9652_card_free; rme9652->dev = dev; rme9652->pci = pci; err = snd_rme9652_create(card, rme9652, precise_ptr[dev]); if (err) goto error; strcpy(card->shortname, rme9652->card_name); sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, rme9652->port, rme9652->irq); err = snd_card_register(card); if (err) goto error; pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver rme9652_driver = { .name = KBUILD_MODNAME, .id_table = snd_rme9652_ids, .probe = snd_rme9652_probe, }; module_pci_driver(rme9652_driver);
linux-master
sound/pci/rme9652/rme9652.c
// SPDX-License-Identifier: GPL-2.0-or-later /* -*- linux-c -*- * * * ALSA driver for the digigram lx6464es interface * low-level interface * * Copyright (c) 2009 Tim Blechmann <[email protected]> */ /* #define RMH_DEBUG 1 */ #include <linux/bitops.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/delay.h> #include "lx6464es.h" #include "lx_core.h" /* low-level register access */ static const unsigned long dsp_port_offsets[] = { 0, 0x400, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40a, 0x40b, 0x40c, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x420, 0x430, 0x431, 0x432, 0x433, 0x434, 0x440 }; static void __iomem *lx_dsp_register(struct lx6464es *chip, int port) { void __iomem *base_address = chip->port_dsp_bar; return base_address + dsp_port_offsets[port]*4; } unsigned long lx_dsp_reg_read(struct lx6464es *chip, int port) { void __iomem *address = lx_dsp_register(chip, port); return ioread32(address); } static void lx_dsp_reg_readbuf(struct lx6464es *chip, int port, u32 *data, u32 len) { u32 __iomem *address = lx_dsp_register(chip, port); int i; /* we cannot use memcpy_fromio */ for (i = 0; i != len; ++i) data[i] = ioread32(address + i); } void lx_dsp_reg_write(struct lx6464es *chip, int port, unsigned data) { void __iomem *address = lx_dsp_register(chip, port); iowrite32(data, address); } static void lx_dsp_reg_writebuf(struct lx6464es *chip, int port, const u32 *data, u32 len) { u32 __iomem *address = lx_dsp_register(chip, port); int i; /* we cannot use memcpy_to */ for (i = 0; i != len; ++i) iowrite32(data[i], address + i); } static const unsigned long plx_port_offsets[] = { 0x04, 0x40, 0x44, 0x48, 0x4c, 0x50, 0x54, 0x58, 0x5c, 0x64, 0x68, 0x6C }; static void __iomem *lx_plx_register(struct lx6464es *chip, int port) { void __iomem *base_address = chip->port_plx_remapped; return base_address + plx_port_offsets[port]; } unsigned long lx_plx_reg_read(struct lx6464es *chip, int port) { void __iomem *address = lx_plx_register(chip, port); return ioread32(address); } void lx_plx_reg_write(struct lx6464es *chip, int port, u32 data) { void __iomem *address = lx_plx_register(chip, port); iowrite32(data, address); } /* rmh */ #ifdef CONFIG_SND_DEBUG #define CMD_NAME(a) a #else #define CMD_NAME(a) NULL #endif #define Reg_CSM_MR 0x00000002 #define Reg_CSM_MC 0x00000001 struct dsp_cmd_info { u32 dcCodeOp; /* Op Code of the command (usually 1st 24-bits * word).*/ u16 dcCmdLength; /* Command length in words of 24 bits.*/ u16 dcStatusType; /* Status type: 0 for fixed length, 1 for * random. */ u16 dcStatusLength; /* Status length (if fixed).*/ char *dcOpName; }; /* Initialization and control data for the Microblaze interface - OpCode: the opcode field of the command set at the proper offset - CmdLength the number of command words - StatusType offset in the status registers: 0 means that the return value may be different from 0, and must be read - StatusLength the number of status words (in addition to the return value) */ static const struct dsp_cmd_info dsp_commands[] = { { (CMD_00_INFO_DEBUG << OPCODE_OFFSET) , 1 /*custom*/ , 1 , 0 /**/ , CMD_NAME("INFO_DEBUG") }, { (CMD_01_GET_SYS_CFG << OPCODE_OFFSET) , 1 /**/ , 1 , 2 /**/ , CMD_NAME("GET_SYS_CFG") }, { (CMD_02_SET_GRANULARITY << OPCODE_OFFSET) , 1 /**/ , 1 , 0 /**/ , CMD_NAME("SET_GRANULARITY") }, { (CMD_03_SET_TIMER_IRQ << OPCODE_OFFSET) , 1 /**/ , 1 , 0 /**/ , CMD_NAME("SET_TIMER_IRQ") }, { (CMD_04_GET_EVENT << OPCODE_OFFSET) , 1 /**/ , 1 , 0 /*up to 10*/ , CMD_NAME("GET_EVENT") }, { (CMD_05_GET_PIPES << OPCODE_OFFSET) , 1 /**/ , 1 , 2 /*up to 4*/ , CMD_NAME("GET_PIPES") }, { (CMD_06_ALLOCATE_PIPE << OPCODE_OFFSET) , 1 /**/ , 0 , 0 /**/ , CMD_NAME("ALLOCATE_PIPE") }, { (CMD_07_RELEASE_PIPE << OPCODE_OFFSET) , 1 /**/ , 0 , 0 /**/ , CMD_NAME("RELEASE_PIPE") }, { (CMD_08_ASK_BUFFERS << OPCODE_OFFSET) , 1 /**/ , 1 , MAX_STREAM_BUFFER , CMD_NAME("ASK_BUFFERS") }, { (CMD_09_STOP_PIPE << OPCODE_OFFSET) , 1 /**/ , 0 , 0 /*up to 2*/ , CMD_NAME("STOP_PIPE") }, { (CMD_0A_GET_PIPE_SPL_COUNT << OPCODE_OFFSET) , 1 /**/ , 1 , 1 /*up to 2*/ , CMD_NAME("GET_PIPE_SPL_COUNT") }, { (CMD_0B_TOGGLE_PIPE_STATE << OPCODE_OFFSET) , 1 /*up to 5*/ , 1 , 0 /**/ , CMD_NAME("TOGGLE_PIPE_STATE") }, { (CMD_0C_DEF_STREAM << OPCODE_OFFSET) , 1 /*up to 4*/ , 1 , 0 /**/ , CMD_NAME("DEF_STREAM") }, { (CMD_0D_SET_MUTE << OPCODE_OFFSET) , 3 /**/ , 1 , 0 /**/ , CMD_NAME("SET_MUTE") }, { (CMD_0E_GET_STREAM_SPL_COUNT << OPCODE_OFFSET) , 1/**/ , 1 , 2 /**/ , CMD_NAME("GET_STREAM_SPL_COUNT") }, { (CMD_0F_UPDATE_BUFFER << OPCODE_OFFSET) , 3 /*up to 4*/ , 0 , 1 /**/ , CMD_NAME("UPDATE_BUFFER") }, { (CMD_10_GET_BUFFER << OPCODE_OFFSET) , 1 /**/ , 1 , 4 /**/ , CMD_NAME("GET_BUFFER") }, { (CMD_11_CANCEL_BUFFER << OPCODE_OFFSET) , 1 /**/ , 1 , 1 /*up to 4*/ , CMD_NAME("CANCEL_BUFFER") }, { (CMD_12_GET_PEAK << OPCODE_OFFSET) , 1 /**/ , 1 , 1 /**/ , CMD_NAME("GET_PEAK") }, { (CMD_13_SET_STREAM_STATE << OPCODE_OFFSET) , 1 /**/ , 1 , 0 /**/ , CMD_NAME("SET_STREAM_STATE") }, }; static void lx_message_init(struct lx_rmh *rmh, enum cmd_mb_opcodes cmd) { snd_BUG_ON(cmd >= CMD_14_INVALID); rmh->cmd[0] = dsp_commands[cmd].dcCodeOp; rmh->cmd_len = dsp_commands[cmd].dcCmdLength; rmh->stat_len = dsp_commands[cmd].dcStatusLength; rmh->dsp_stat = dsp_commands[cmd].dcStatusType; rmh->cmd_idx = cmd; memset(&rmh->cmd[1], 0, (REG_CRM_NUMBER - 1) * sizeof(u32)); #ifdef CONFIG_SND_DEBUG memset(rmh->stat, 0, REG_CRM_NUMBER * sizeof(u32)); #endif #ifdef RMH_DEBUG rmh->cmd_idx = cmd; #endif } #ifdef RMH_DEBUG #define LXRMH "lx6464es rmh: " static void lx_message_dump(struct lx_rmh *rmh) { u8 idx = rmh->cmd_idx; int i; snd_printk(LXRMH "command %s\n", dsp_commands[idx].dcOpName); for (i = 0; i != rmh->cmd_len; ++i) snd_printk(LXRMH "\tcmd[%d] %08x\n", i, rmh->cmd[i]); for (i = 0; i != rmh->stat_len; ++i) snd_printk(LXRMH "\tstat[%d]: %08x\n", i, rmh->stat[i]); snd_printk("\n"); } #else static inline void lx_message_dump(struct lx_rmh *rmh) {} #endif /* sleep 500 - 100 = 400 times 100us -> the timeout is >= 40 ms */ #define XILINX_TIMEOUT_MS 40 #define XILINX_POLL_NO_SLEEP 100 #define XILINX_POLL_ITERATIONS 150 static int lx_message_send_atomic(struct lx6464es *chip, struct lx_rmh *rmh) { u32 reg = ED_DSP_TIMED_OUT; int dwloop; if (lx_dsp_reg_read(chip, eReg_CSM) & (Reg_CSM_MC | Reg_CSM_MR)) { dev_err(chip->card->dev, "PIOSendMessage eReg_CSM %x\n", reg); return -EBUSY; } /* write command */ lx_dsp_reg_writebuf(chip, eReg_CRM1, rmh->cmd, rmh->cmd_len); /* MicoBlaze gogogo */ lx_dsp_reg_write(chip, eReg_CSM, Reg_CSM_MC); /* wait for device to answer */ for (dwloop = 0; dwloop != XILINX_TIMEOUT_MS * 1000; ++dwloop) { if (lx_dsp_reg_read(chip, eReg_CSM) & Reg_CSM_MR) { if (rmh->dsp_stat == 0) reg = lx_dsp_reg_read(chip, eReg_CRM1); else reg = 0; goto polling_successful; } else udelay(1); } dev_warn(chip->card->dev, "TIMEOUT lx_message_send_atomic! " "polling failed\n"); polling_successful: if ((reg & ERROR_VALUE) == 0) { /* read response */ if (rmh->stat_len) { snd_BUG_ON(rmh->stat_len >= (REG_CRM_NUMBER-1)); lx_dsp_reg_readbuf(chip, eReg_CRM2, rmh->stat, rmh->stat_len); } } else dev_err(chip->card->dev, "rmh error: %08x\n", reg); /* clear Reg_CSM_MR */ lx_dsp_reg_write(chip, eReg_CSM, 0); switch (reg) { case ED_DSP_TIMED_OUT: dev_warn(chip->card->dev, "lx_message_send: dsp timeout\n"); return -ETIMEDOUT; case ED_DSP_CRASHED: dev_warn(chip->card->dev, "lx_message_send: dsp crashed\n"); return -EAGAIN; } lx_message_dump(rmh); return reg; } /* low-level dsp access */ int lx_dsp_get_version(struct lx6464es *chip, u32 *rdsp_version) { u16 ret; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_01_GET_SYS_CFG); ret = lx_message_send_atomic(chip, &chip->rmh); *rdsp_version = chip->rmh.stat[1]; mutex_unlock(&chip->msg_lock); return ret; } int lx_dsp_get_clock_frequency(struct lx6464es *chip, u32 *rfreq) { u16 ret = 0; u32 freq_raw = 0; u32 freq = 0; u32 frequency = 0; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_01_GET_SYS_CFG); ret = lx_message_send_atomic(chip, &chip->rmh); if (ret == 0) { freq_raw = chip->rmh.stat[0] >> FREQ_FIELD_OFFSET; freq = freq_raw & XES_FREQ_COUNT8_MASK; if ((freq < XES_FREQ_COUNT8_48_MAX) || (freq > XES_FREQ_COUNT8_44_MIN)) frequency = 0; /* unknown */ else if (freq >= XES_FREQ_COUNT8_44_MAX) frequency = 44100; else frequency = 48000; } mutex_unlock(&chip->msg_lock); *rfreq = frequency * chip->freq_ratio; return ret; } int lx_dsp_get_mac(struct lx6464es *chip) { u32 macmsb, maclsb; macmsb = lx_dsp_reg_read(chip, eReg_ADMACESMSB) & 0x00FFFFFF; maclsb = lx_dsp_reg_read(chip, eReg_ADMACESLSB) & 0x00FFFFFF; /* todo: endianess handling */ chip->mac_address[5] = ((u8 *)(&maclsb))[0]; chip->mac_address[4] = ((u8 *)(&maclsb))[1]; chip->mac_address[3] = ((u8 *)(&maclsb))[2]; chip->mac_address[2] = ((u8 *)(&macmsb))[0]; chip->mac_address[1] = ((u8 *)(&macmsb))[1]; chip->mac_address[0] = ((u8 *)(&macmsb))[2]; return 0; } int lx_dsp_set_granularity(struct lx6464es *chip, u32 gran) { int ret; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_02_SET_GRANULARITY); chip->rmh.cmd[0] |= gran; ret = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return ret; } int lx_dsp_read_async_events(struct lx6464es *chip, u32 *data) { int ret; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_04_GET_EVENT); chip->rmh.stat_len = 9; /* we don't necessarily need the full length */ ret = lx_message_send_atomic(chip, &chip->rmh); if (!ret) memcpy(data, chip->rmh.stat, chip->rmh.stat_len * sizeof(u32)); mutex_unlock(&chip->msg_lock); return ret; } #define PIPE_INFO_TO_CMD(capture, pipe) \ ((u32)((u32)(pipe) | ((capture) ? ID_IS_CAPTURE : 0L)) << ID_OFFSET) /* low-level pipe handling */ int lx_pipe_allocate(struct lx6464es *chip, u32 pipe, int is_capture, int channels) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_06_ALLOCATE_PIPE); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.cmd[0] |= channels; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); if (err != 0) dev_err(chip->card->dev, "could not allocate pipe\n"); return err; } int lx_pipe_release(struct lx6464es *chip, u32 pipe, int is_capture) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_07_RELEASE_PIPE); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture, u32 *r_needed, u32 *r_freed, u32 *size_array) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); #ifdef CONFIG_SND_DEBUG if (size_array) memset(size_array, 0, sizeof(u32)*MAX_STREAM_BUFFER); #endif *r_needed = 0; *r_freed = 0; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_08_ASK_BUFFERS); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); if (!err) { int i; for (i = 0; i < MAX_STREAM_BUFFER; ++i) { u32 stat = chip->rmh.stat[i]; if (stat & (BF_EOB << BUFF_FLAGS_OFFSET)) { /* finished */ *r_freed += 1; if (size_array) size_array[i] = stat & MASK_DATA_SIZE; } else if ((stat & (BF_VALID << BUFF_FLAGS_OFFSET)) == 0) /* free */ *r_needed += 1; } dev_dbg(chip->card->dev, "CMD_08_ASK_BUFFERS: needed %d, freed %d\n", *r_needed, *r_freed); for (i = 0; i < MAX_STREAM_BUFFER && i < chip->rmh.stat_len; ++i) { dev_dbg(chip->card->dev, " stat[%d]: %x, %x\n", i, chip->rmh.stat[i], chip->rmh.stat[i] & MASK_DATA_SIZE); } } mutex_unlock(&chip->msg_lock); return err; } int lx_pipe_stop(struct lx6464es *chip, u32 pipe, int is_capture) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_09_STOP_PIPE); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } static int lx_pipe_toggle_state(struct lx6464es *chip, u32 pipe, int is_capture) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0B_TOGGLE_PIPE_STATE); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } int lx_pipe_start(struct lx6464es *chip, u32 pipe, int is_capture) { int err; err = lx_pipe_wait_for_idle(chip, pipe, is_capture); if (err < 0) return err; err = lx_pipe_toggle_state(chip, pipe, is_capture); return err; } int lx_pipe_pause(struct lx6464es *chip, u32 pipe, int is_capture) { int err = 0; err = lx_pipe_wait_for_start(chip, pipe, is_capture); if (err < 0) return err; err = lx_pipe_toggle_state(chip, pipe, is_capture); return err; } int lx_pipe_sample_count(struct lx6464es *chip, u32 pipe, int is_capture, u64 *rsample_count) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0A_GET_PIPE_SPL_COUNT); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.stat_len = 2; /* need all words here! */ err = lx_message_send_atomic(chip, &chip->rmh); /* don't sleep! */ if (err != 0) dev_err(chip->card->dev, "could not query pipe's sample count\n"); else { *rsample_count = ((u64)(chip->rmh.stat[0] & MASK_SPL_COUNT_HI) << 24) /* hi part */ + chip->rmh.stat[1]; /* lo part */ } mutex_unlock(&chip->msg_lock); return err; } int lx_pipe_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 *rstate) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0A_GET_PIPE_SPL_COUNT); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); if (err != 0) dev_err(chip->card->dev, "could not query pipe's state\n"); else *rstate = (chip->rmh.stat[0] >> PSTATE_OFFSET) & 0x0F; mutex_unlock(&chip->msg_lock); return err; } static int lx_pipe_wait_for_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 state) { int i; /* max 2*PCMOnlyGranularity = 2*1024 at 44100 = < 50 ms: * timeout 50 ms */ for (i = 0; i != 50; ++i) { u16 current_state; int err = lx_pipe_state(chip, pipe, is_capture, &current_state); if (err < 0) return err; if (!err && current_state == state) return 0; mdelay(1); } return -ETIMEDOUT; } int lx_pipe_wait_for_start(struct lx6464es *chip, u32 pipe, int is_capture) { return lx_pipe_wait_for_state(chip, pipe, is_capture, PSTATE_RUN); } int lx_pipe_wait_for_idle(struct lx6464es *chip, u32 pipe, int is_capture) { return lx_pipe_wait_for_state(chip, pipe, is_capture, PSTATE_IDLE); } /* low-level stream handling */ int lx_stream_set_state(struct lx6464es *chip, u32 pipe, int is_capture, enum stream_state_t state) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_13_SET_STREAM_STATE); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.cmd[0] |= state; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } int lx_stream_set_format(struct lx6464es *chip, struct snd_pcm_runtime *runtime, u32 pipe, int is_capture) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); u32 channels = runtime->channels; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0C_DEF_STREAM); chip->rmh.cmd[0] |= pipe_cmd; if (runtime->sample_bits == 16) /* 16 bit format */ chip->rmh.cmd[0] |= (STREAM_FMT_16b << STREAM_FMT_OFFSET); if (snd_pcm_format_little_endian(runtime->format)) /* little endian/intel format */ chip->rmh.cmd[0] |= (STREAM_FMT_intel << STREAM_FMT_OFFSET); chip->rmh.cmd[0] |= channels-1; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } int lx_stream_state(struct lx6464es *chip, u32 pipe, int is_capture, int *rstate) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0E_GET_STREAM_SPL_COUNT); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); *rstate = (chip->rmh.stat[0] & SF_START) ? START_STATE : PAUSE_STATE; mutex_unlock(&chip->msg_lock); return err; } int lx_stream_sample_position(struct lx6464es *chip, u32 pipe, int is_capture, u64 *r_bytepos) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0E_GET_STREAM_SPL_COUNT); chip->rmh.cmd[0] |= pipe_cmd; err = lx_message_send_atomic(chip, &chip->rmh); *r_bytepos = ((u64) (chip->rmh.stat[0] & MASK_SPL_COUNT_HI) << 32) /* hi part */ + chip->rmh.stat[1]; /* lo part */ mutex_unlock(&chip->msg_lock); return err; } /* low-level buffer handling */ int lx_buffer_give(struct lx6464es *chip, u32 pipe, int is_capture, u32 buffer_size, u32 buf_address_lo, u32 buf_address_hi, u32 *r_buffer_index) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0F_UPDATE_BUFFER); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.cmd[0] |= BF_NOTIFY_EOB; /* request interrupt notification */ /* todo: pause request, circular buffer */ chip->rmh.cmd[1] = buffer_size & MASK_DATA_SIZE; chip->rmh.cmd[2] = buf_address_lo; if (buf_address_hi) { chip->rmh.cmd_len = 4; chip->rmh.cmd[3] = buf_address_hi; chip->rmh.cmd[0] |= BF_64BITS_ADR; } err = lx_message_send_atomic(chip, &chip->rmh); if (err == 0) { *r_buffer_index = chip->rmh.stat[0]; goto done; } if (err == EB_RBUFFERS_TABLE_OVERFLOW) dev_err(chip->card->dev, "lx_buffer_give EB_RBUFFERS_TABLE_OVERFLOW\n"); if (err == EB_INVALID_STREAM) dev_err(chip->card->dev, "lx_buffer_give EB_INVALID_STREAM\n"); if (err == EB_CMD_REFUSED) dev_err(chip->card->dev, "lx_buffer_give EB_CMD_REFUSED\n"); done: mutex_unlock(&chip->msg_lock); return err; } int lx_buffer_free(struct lx6464es *chip, u32 pipe, int is_capture, u32 *r_buffer_size) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_11_CANCEL_BUFFER); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.cmd[0] |= MASK_BUFFER_ID; /* ask for the current buffer: the * microblaze will seek for it */ err = lx_message_send_atomic(chip, &chip->rmh); if (err == 0) *r_buffer_size = chip->rmh.stat[0] & MASK_DATA_SIZE; mutex_unlock(&chip->msg_lock); return err; } int lx_buffer_cancel(struct lx6464es *chip, u32 pipe, int is_capture, u32 buffer_index) { int err; u32 pipe_cmd = PIPE_INFO_TO_CMD(is_capture, pipe); mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_11_CANCEL_BUFFER); chip->rmh.cmd[0] |= pipe_cmd; chip->rmh.cmd[0] |= buffer_index; err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } /* low-level gain/peak handling * * \todo: can we unmute capture/playback channels independently? * * */ int lx_level_unmute(struct lx6464es *chip, int is_capture, int unmute) { int err; /* bit set to 1: channel muted */ u64 mute_mask = unmute ? 0 : 0xFFFFFFFFFFFFFFFFLLU; mutex_lock(&chip->msg_lock); lx_message_init(&chip->rmh, CMD_0D_SET_MUTE); chip->rmh.cmd[0] |= PIPE_INFO_TO_CMD(is_capture, 0); chip->rmh.cmd[1] = (u32)(mute_mask >> (u64)32); /* hi part */ chip->rmh.cmd[2] = (u32)(mute_mask & (u64)0xFFFFFFFF); /* lo part */ dev_dbg(chip->card->dev, "mute %x %x %x\n", chip->rmh.cmd[0], chip->rmh.cmd[1], chip->rmh.cmd[2]); err = lx_message_send_atomic(chip, &chip->rmh); mutex_unlock(&chip->msg_lock); return err; } static const u32 peak_map[] = { 0x00000109, /* -90.308dB */ 0x0000083B, /* -72.247dB */ 0x000020C4, /* -60.205dB */ 0x00008273, /* -48.030dB */ 0x00020756, /* -36.005dB */ 0x00040C37, /* -30.001dB */ 0x00081385, /* -24.002dB */ 0x00101D3F, /* -18.000dB */ 0x0016C310, /* -15.000dB */ 0x002026F2, /* -12.001dB */ 0x002D6A86, /* -9.000dB */ 0x004026E6, /* -6.004dB */ 0x005A9DF6, /* -3.000dB */ 0x0065AC8B, /* -2.000dB */ 0x00721481, /* -1.000dB */ 0x007FFFFF, /* FS */ }; int lx_level_peaks(struct lx6464es *chip, int is_capture, int channels, u32 *r_levels) { int err = 0; int i; mutex_lock(&chip->msg_lock); for (i = 0; i < channels; i += 4) { u32 s0, s1, s2, s3; lx_message_init(&chip->rmh, CMD_12_GET_PEAK); chip->rmh.cmd[0] |= PIPE_INFO_TO_CMD(is_capture, i); err = lx_message_send_atomic(chip, &chip->rmh); if (err == 0) { s0 = peak_map[chip->rmh.stat[0] & 0x0F]; s1 = peak_map[(chip->rmh.stat[0] >> 4) & 0xf]; s2 = peak_map[(chip->rmh.stat[0] >> 8) & 0xf]; s3 = peak_map[(chip->rmh.stat[0] >> 12) & 0xf]; } else s0 = s1 = s2 = s3 = 0; r_levels[0] = s0; r_levels[1] = s1; r_levels[2] = s2; r_levels[3] = s3; r_levels += 4; } mutex_unlock(&chip->msg_lock); return err; } /* interrupt handling */ #define PCX_IRQ_NONE 0 #define IRQCS_ACTIVE_PCIDB BIT(13) #define IRQCS_ENABLE_PCIIRQ BIT(8) #define IRQCS_ENABLE_PCIDB BIT(9) static u32 lx_interrupt_test_ack(struct lx6464es *chip) { u32 irqcs = lx_plx_reg_read(chip, ePLX_IRQCS); /* Test if PCI Doorbell interrupt is active */ if (irqcs & IRQCS_ACTIVE_PCIDB) { u32 temp; irqcs = PCX_IRQ_NONE; while ((temp = lx_plx_reg_read(chip, ePLX_L2PCIDB))) { /* RAZ interrupt */ irqcs |= temp; lx_plx_reg_write(chip, ePLX_L2PCIDB, temp); } return irqcs; } return PCX_IRQ_NONE; } static int lx_interrupt_ack(struct lx6464es *chip, u32 *r_irqsrc, int *r_async_pending, int *r_async_escmd) { u32 irq_async; u32 irqsrc = lx_interrupt_test_ack(chip); if (irqsrc == PCX_IRQ_NONE) return 0; *r_irqsrc = irqsrc; irq_async = irqsrc & MASK_SYS_ASYNC_EVENTS; /* + EtherSound response * (set by xilinx) + EOB */ if (irq_async & MASK_SYS_STATUS_ESA) { irq_async &= ~MASK_SYS_STATUS_ESA; *r_async_escmd = 1; } if (irq_async) { /* dev_dbg(chip->card->dev, "interrupt: async event pending\n"); */ *r_async_pending = 1; } return 1; } static int lx_interrupt_handle_async_events(struct lx6464es *chip, u32 irqsrc, int *r_freq_changed, u64 *r_notified_in_pipe_mask, u64 *r_notified_out_pipe_mask) { int err; u32 stat[9]; /* answer from CMD_04_GET_EVENT */ /* We can optimize this to not read dumb events. * Answer words are in the following order: * Stat[0] general status * Stat[1] end of buffer OUT pF * Stat[2] end of buffer OUT pf * Stat[3] end of buffer IN pF * Stat[4] end of buffer IN pf * Stat[5] MSB underrun * Stat[6] LSB underrun * Stat[7] MSB overrun * Stat[8] LSB overrun * */ int eb_pending_out = (irqsrc & MASK_SYS_STATUS_EOBO) ? 1 : 0; int eb_pending_in = (irqsrc & MASK_SYS_STATUS_EOBI) ? 1 : 0; *r_freq_changed = (irqsrc & MASK_SYS_STATUS_FREQ) ? 1 : 0; err = lx_dsp_read_async_events(chip, stat); if (err < 0) return err; if (eb_pending_in) { *r_notified_in_pipe_mask = ((u64)stat[3] << 32) + stat[4]; dev_dbg(chip->card->dev, "interrupt: EOBI pending %llx\n", *r_notified_in_pipe_mask); } if (eb_pending_out) { *r_notified_out_pipe_mask = ((u64)stat[1] << 32) + stat[2]; dev_dbg(chip->card->dev, "interrupt: EOBO pending %llx\n", *r_notified_out_pipe_mask); } /* todo: handle xrun notification */ return err; } static int lx_interrupt_request_new_buffer(struct lx6464es *chip, struct lx_stream *lx_stream) { struct snd_pcm_substream *substream = lx_stream->stream; const unsigned int is_capture = lx_stream->is_capture; int err; const u32 channels = substream->runtime->channels; const u32 bytes_per_frame = channels * 3; const u32 period_size = substream->runtime->period_size; const u32 period_bytes = period_size * bytes_per_frame; const u32 pos = lx_stream->frame_pos; const u32 next_pos = ((pos+1) == substream->runtime->periods) ? 0 : pos + 1; dma_addr_t buf = substream->dma_buffer.addr + pos * period_bytes; u32 buf_hi = 0; u32 buf_lo = 0; u32 buffer_index = 0; u32 needed, freed; u32 size_array[MAX_STREAM_BUFFER]; dev_dbg(chip->card->dev, "->lx_interrupt_request_new_buffer\n"); mutex_lock(&chip->lock); err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array); dev_dbg(chip->card->dev, "interrupt: needed %d, freed %d\n", needed, freed); unpack_pointer(buf, &buf_lo, &buf_hi); err = lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi, &buffer_index); dev_dbg(chip->card->dev, "interrupt: gave buffer index %x on 0x%lx (%d bytes)\n", buffer_index, (unsigned long)buf, period_bytes); lx_stream->frame_pos = next_pos; mutex_unlock(&chip->lock); return err; } irqreturn_t lx_interrupt(int irq, void *dev_id) { struct lx6464es *chip = dev_id; int async_pending, async_escmd; u32 irqsrc; bool wake_thread = false; dev_dbg(chip->card->dev, "**************************************************\n"); if (!lx_interrupt_ack(chip, &irqsrc, &async_pending, &async_escmd)) { dev_dbg(chip->card->dev, "IRQ_NONE\n"); return IRQ_NONE; /* this device did not cause the interrupt */ } if (irqsrc & MASK_SYS_STATUS_CMD_DONE) return IRQ_HANDLED; if (irqsrc & MASK_SYS_STATUS_EOBI) dev_dbg(chip->card->dev, "interrupt: EOBI\n"); if (irqsrc & MASK_SYS_STATUS_EOBO) dev_dbg(chip->card->dev, "interrupt: EOBO\n"); if (irqsrc & MASK_SYS_STATUS_URUN) dev_dbg(chip->card->dev, "interrupt: URUN\n"); if (irqsrc & MASK_SYS_STATUS_ORUN) dev_dbg(chip->card->dev, "interrupt: ORUN\n"); if (async_pending) { wake_thread = true; chip->irqsrc = irqsrc; } if (async_escmd) { /* backdoor for ethersound commands * * for now, we do not need this * * */ dev_dbg(chip->card->dev, "interrupt requests escmd handling\n"); } return wake_thread ? IRQ_WAKE_THREAD : IRQ_HANDLED; } irqreturn_t lx_threaded_irq(int irq, void *dev_id) { struct lx6464es *chip = dev_id; u64 notified_in_pipe_mask = 0; u64 notified_out_pipe_mask = 0; int freq_changed; int err; /* handle async events */ err = lx_interrupt_handle_async_events(chip, chip->irqsrc, &freq_changed, &notified_in_pipe_mask, &notified_out_pipe_mask); if (err) dev_err(chip->card->dev, "error handling async events\n"); if (notified_in_pipe_mask) { struct lx_stream *lx_stream = &chip->capture_stream; dev_dbg(chip->card->dev, "requesting audio transfer for capture\n"); err = lx_interrupt_request_new_buffer(chip, lx_stream); if (err < 0) dev_err(chip->card->dev, "cannot request new buffer for capture\n"); snd_pcm_period_elapsed(lx_stream->stream); } if (notified_out_pipe_mask) { struct lx_stream *lx_stream = &chip->playback_stream; dev_dbg(chip->card->dev, "requesting audio transfer for playback\n"); err = lx_interrupt_request_new_buffer(chip, lx_stream); if (err < 0) dev_err(chip->card->dev, "cannot request new buffer for playback\n"); snd_pcm_period_elapsed(lx_stream->stream); } return IRQ_HANDLED; } static void lx_irq_set(struct lx6464es *chip, int enable) { u32 reg = lx_plx_reg_read(chip, ePLX_IRQCS); /* enable/disable interrupts * * Set the Doorbell and PCI interrupt enable bits * * */ if (enable) reg |= (IRQCS_ENABLE_PCIIRQ | IRQCS_ENABLE_PCIDB); else reg &= ~(IRQCS_ENABLE_PCIIRQ | IRQCS_ENABLE_PCIDB); lx_plx_reg_write(chip, ePLX_IRQCS, reg); } void lx_irq_enable(struct lx6464es *chip) { dev_dbg(chip->card->dev, "->lx_irq_enable\n"); lx_irq_set(chip, 1); } void lx_irq_disable(struct lx6464es *chip) { dev_dbg(chip->card->dev, "->lx_irq_disable\n"); lx_irq_set(chip, 0); }
linux-master
sound/pci/lx6464es/lx_core.c
// SPDX-License-Identifier: GPL-2.0-or-later /* -*- linux-c -*- * * * ALSA driver for the digigram lx6464es interface * * Copyright (c) 2008, 2009 Tim Blechmann <[email protected]> */ #include <linux/module.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/delay.h> #include <linux/slab.h> #include <sound/initval.h> #include <sound/control.h> #include <sound/info.h> #include "lx6464es.h" MODULE_AUTHOR("Tim Blechmann"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("digigram lx6464es"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Digigram LX6464ES interface."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Digigram LX6464ES interface."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable/disable specific Digigram LX6464ES soundcards."); static const char card_name[] = "LX6464ES"; #define PCI_DEVICE_ID_PLX_LX6464ES PCI_DEVICE_ID_PLX_9056 static const struct pci_device_id snd_lx6464es_ids[] = { { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES, PCI_VENDOR_ID_DIGIGRAM, PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_SERIAL_SUBSYSTEM), }, /* LX6464ES */ { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES, PCI_VENDOR_ID_DIGIGRAM, PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ES_CAE_SERIAL_SUBSYSTEM), }, /* LX6464ES-CAE */ { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES, PCI_VENDOR_ID_DIGIGRAM, PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_SERIAL_SUBSYSTEM), }, /* LX6464ESe */ { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_LX6464ES, PCI_VENDOR_ID_DIGIGRAM, PCI_SUBDEVICE_ID_DIGIGRAM_LX6464ESE_CAE_SERIAL_SUBSYSTEM), }, /* LX6464ESe-CAE */ { 0, }, }; MODULE_DEVICE_TABLE(pci, snd_lx6464es_ids); /* PGO pour USERo dans le registre pci_0x06/loc_0xEC */ #define CHIPSC_RESET_XILINX (1L<<16) /* alsa callbacks */ static const struct snd_pcm_hardware lx_caps = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START), .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE), .rates = (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_192000), .rate_min = 8000, .rate_max = 192000, .channels_min = 2, .channels_max = 64, .buffer_bytes_max = 64*2*3*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER, .period_bytes_min = (2*2*MICROBLAZE_IBL_MIN*2), .period_bytes_max = (4*64*MICROBLAZE_IBL_MAX*MAX_STREAM_BUFFER), .periods_min = 2, .periods_max = MAX_STREAM_BUFFER, }; static int lx_set_granularity(struct lx6464es *chip, u32 gran); static int lx_hardware_open(struct lx6464es *chip, struct snd_pcm_substream *substream) { int err = 0; struct snd_pcm_runtime *runtime = substream->runtime; int channels = runtime->channels; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); snd_pcm_uframes_t period_size = runtime->period_size; dev_dbg(chip->card->dev, "allocating pipe for %d channels\n", channels); err = lx_pipe_allocate(chip, 0, is_capture, channels); if (err < 0) { dev_err(chip->card->dev, LXP "allocating pipe failed\n"); return err; } err = lx_set_granularity(chip, period_size); if (err < 0) { dev_err(chip->card->dev, "setting granularity to %ld failed\n", period_size); return err; } return 0; } static int lx_hardware_start(struct lx6464es *chip, struct snd_pcm_substream *substream) { int err = 0; struct snd_pcm_runtime *runtime = substream->runtime; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); dev_dbg(chip->card->dev, "setting stream format\n"); err = lx_stream_set_format(chip, runtime, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "setting stream format failed\n"); return err; } dev_dbg(chip->card->dev, "starting pipe\n"); err = lx_pipe_start(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "starting pipe failed\n"); return err; } dev_dbg(chip->card->dev, "waiting for pipe to start\n"); err = lx_pipe_wait_for_start(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "waiting for pipe failed\n"); return err; } return err; } static int lx_hardware_stop(struct lx6464es *chip, struct snd_pcm_substream *substream) { int err = 0; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); dev_dbg(chip->card->dev, "pausing pipe\n"); err = lx_pipe_pause(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "pausing pipe failed\n"); return err; } dev_dbg(chip->card->dev, "waiting for pipe to become idle\n"); err = lx_pipe_wait_for_idle(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "waiting for pipe failed\n"); return err; } dev_dbg(chip->card->dev, "stopping pipe\n"); err = lx_pipe_stop(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "stopping pipe failed\n"); return err; } return err; } static int lx_hardware_close(struct lx6464es *chip, struct snd_pcm_substream *substream) { int err = 0; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); dev_dbg(chip->card->dev, "releasing pipe\n"); err = lx_pipe_release(chip, 0, is_capture); if (err < 0) { dev_err(chip->card->dev, "releasing pipe failed\n"); return err; } return err; } static int lx_pcm_open(struct snd_pcm_substream *substream) { struct lx6464es *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int err = 0; int board_rate; dev_dbg(chip->card->dev, "->lx_pcm_open\n"); mutex_lock(&chip->setup_mutex); /* copy the struct snd_pcm_hardware struct */ runtime->hw = lx_caps; #if 0 /* buffer-size should better be multiple of period-size */ err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) { dev_warn(chip->card->dev, "could not constrain periods\n"); goto exit; } #endif /* the clock rate cannot be changed */ board_rate = chip->board_sample_rate; err = snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_RATE, board_rate); if (err < 0) { dev_warn(chip->card->dev, "could not constrain periods\n"); goto exit; } /* constrain period size */ err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, MICROBLAZE_IBL_MIN, MICROBLAZE_IBL_MAX); if (err < 0) { dev_warn(chip->card->dev, "could not constrain period size\n"); goto exit; } snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32); snd_pcm_set_sync(substream); err = 0; exit: runtime->private_data = chip; mutex_unlock(&chip->setup_mutex); dev_dbg(chip->card->dev, "<-lx_pcm_open, %d\n", err); return err; } static int lx_pcm_close(struct snd_pcm_substream *substream) { dev_dbg(substream->pcm->card->dev, "->lx_pcm_close\n"); return 0; } static snd_pcm_uframes_t lx_pcm_stream_pointer(struct snd_pcm_substream *substream) { struct lx6464es *chip = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); struct lx_stream *lx_stream = is_capture ? &chip->capture_stream : &chip->playback_stream; dev_dbg(chip->card->dev, "->lx_pcm_stream_pointer\n"); mutex_lock(&chip->lock); pos = lx_stream->frame_pos * substream->runtime->period_size; mutex_unlock(&chip->lock); dev_dbg(chip->card->dev, "stream_pointer at %ld\n", pos); return pos; } static int lx_pcm_prepare(struct snd_pcm_substream *substream) { struct lx6464es *chip = snd_pcm_substream_chip(substream); int err = 0; const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); dev_dbg(chip->card->dev, "->lx_pcm_prepare\n"); mutex_lock(&chip->setup_mutex); if (chip->hardware_running[is_capture]) { err = lx_hardware_stop(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to stop hardware. " "Error code %d\n", err); goto exit; } err = lx_hardware_close(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to close hardware. " "Error code %d\n", err); goto exit; } } dev_dbg(chip->card->dev, "opening hardware\n"); err = lx_hardware_open(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to open hardware. " "Error code %d\n", err); goto exit; } err = lx_hardware_start(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to start hardware. " "Error code %d\n", err); goto exit; } chip->hardware_running[is_capture] = 1; if (chip->board_sample_rate != substream->runtime->rate) { if (!err) chip->board_sample_rate = substream->runtime->rate; } exit: mutex_unlock(&chip->setup_mutex); return err; } static int lx_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params, int is_capture) { struct lx6464es *chip = snd_pcm_substream_chip(substream); dev_dbg(chip->card->dev, "->lx_pcm_hw_params\n"); mutex_lock(&chip->setup_mutex); if (is_capture) chip->capture_stream.stream = substream; else chip->playback_stream.stream = substream; mutex_unlock(&chip->setup_mutex); return 0; } static int lx_pcm_hw_params_playback(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { return lx_pcm_hw_params(substream, hw_params, 0); } static int lx_pcm_hw_params_capture(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { return lx_pcm_hw_params(substream, hw_params, 1); } static int lx_pcm_hw_free(struct snd_pcm_substream *substream) { struct lx6464es *chip = snd_pcm_substream_chip(substream); int err = 0; int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); dev_dbg(chip->card->dev, "->lx_pcm_hw_free\n"); mutex_lock(&chip->setup_mutex); if (chip->hardware_running[is_capture]) { err = lx_hardware_stop(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to stop hardware. " "Error code %d\n", err); goto exit; } err = lx_hardware_close(chip, substream); if (err < 0) { dev_err(chip->card->dev, "failed to close hardware. " "Error code %d\n", err); goto exit; } chip->hardware_running[is_capture] = 0; } if (is_capture) chip->capture_stream.stream = NULL; else chip->playback_stream.stream = NULL; exit: mutex_unlock(&chip->setup_mutex); return err; } static void lx_trigger_start(struct lx6464es *chip, struct lx_stream *lx_stream) { struct snd_pcm_substream *substream = lx_stream->stream; const unsigned int is_capture = lx_stream->is_capture; int err; const u32 channels = substream->runtime->channels; const u32 bytes_per_frame = channels * 3; const u32 period_size = substream->runtime->period_size; const u32 periods = substream->runtime->periods; const u32 period_bytes = period_size * bytes_per_frame; dma_addr_t buf = substream->dma_buffer.addr; int i; u32 needed, freed; u32 size_array[5]; for (i = 0; i != periods; ++i) { u32 buffer_index = 0; err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array); dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed); err = lx_buffer_give(chip, 0, is_capture, period_bytes, lower_32_bits(buf), upper_32_bits(buf), &buffer_index); dev_dbg(chip->card->dev, "starting: buffer index %x on 0x%lx (%d bytes)\n", buffer_index, (unsigned long)buf, period_bytes); buf += period_bytes; } err = lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array); dev_dbg(chip->card->dev, "starting: needed %d, freed %d\n", needed, freed); dev_dbg(chip->card->dev, "starting: starting stream\n"); err = lx_stream_start(chip, 0, is_capture); if (err < 0) dev_err(chip->card->dev, "couldn't start stream\n"); else lx_stream->status = LX_STREAM_STATUS_RUNNING; lx_stream->frame_pos = 0; } static void lx_trigger_stop(struct lx6464es *chip, struct lx_stream *lx_stream) { const unsigned int is_capture = lx_stream->is_capture; int err; dev_dbg(chip->card->dev, "stopping: stopping stream\n"); err = lx_stream_stop(chip, 0, is_capture); if (err < 0) dev_err(chip->card->dev, "couldn't stop stream\n"); else lx_stream->status = LX_STREAM_STATUS_FREE; } static void lx_trigger_dispatch_stream(struct lx6464es *chip, struct lx_stream *lx_stream) { switch (lx_stream->status) { case LX_STREAM_STATUS_SCHEDULE_RUN: lx_trigger_start(chip, lx_stream); break; case LX_STREAM_STATUS_SCHEDULE_STOP: lx_trigger_stop(chip, lx_stream); break; default: break; } } static int lx_pcm_trigger_dispatch(struct lx6464es *chip, struct lx_stream *lx_stream, int cmd) { int err = 0; mutex_lock(&chip->lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: lx_stream->status = LX_STREAM_STATUS_SCHEDULE_RUN; break; case SNDRV_PCM_TRIGGER_STOP: lx_stream->status = LX_STREAM_STATUS_SCHEDULE_STOP; break; default: err = -EINVAL; goto exit; } lx_trigger_dispatch_stream(chip, &chip->capture_stream); lx_trigger_dispatch_stream(chip, &chip->playback_stream); exit: mutex_unlock(&chip->lock); return err; } static int lx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct lx6464es *chip = snd_pcm_substream_chip(substream); const int is_capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); struct lx_stream *stream = is_capture ? &chip->capture_stream : &chip->playback_stream; dev_dbg(chip->card->dev, "->lx_pcm_trigger\n"); return lx_pcm_trigger_dispatch(chip, stream, cmd); } static void snd_lx6464es_free(struct snd_card *card) { struct lx6464es *chip = card->private_data; lx_irq_disable(chip); } /* reset the dsp during initialization */ static int lx_init_xilinx_reset(struct lx6464es *chip) { int i; u32 plx_reg = lx_plx_reg_read(chip, ePLX_CHIPSC); dev_dbg(chip->card->dev, "->lx_init_xilinx_reset\n"); /* activate reset of xilinx */ plx_reg &= ~CHIPSC_RESET_XILINX; lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg); msleep(1); lx_plx_reg_write(chip, ePLX_MBOX3, 0); msleep(1); plx_reg |= CHIPSC_RESET_XILINX; lx_plx_reg_write(chip, ePLX_CHIPSC, plx_reg); /* deactivate reset of xilinx */ for (i = 0; i != 100; ++i) { u32 reg_mbox3; msleep(10); reg_mbox3 = lx_plx_reg_read(chip, ePLX_MBOX3); if (reg_mbox3) { dev_dbg(chip->card->dev, "xilinx reset done\n"); dev_dbg(chip->card->dev, "xilinx took %d loops\n", i); break; } } /* todo: add some error handling? */ /* clear mr */ lx_dsp_reg_write(chip, eReg_CSM, 0); /* le xilinx ES peut ne pas etre encore pret, on attend. */ msleep(600); return 0; } static int lx_init_xilinx_test(struct lx6464es *chip) { u32 reg; dev_dbg(chip->card->dev, "->lx_init_xilinx_test\n"); /* TEST if we have access to Xilinx/MicroBlaze */ lx_dsp_reg_write(chip, eReg_CSM, 0); reg = lx_dsp_reg_read(chip, eReg_CSM); if (reg) { dev_err(chip->card->dev, "Problem: Reg_CSM %x.\n", reg); /* PCI9056_SPACE0_REMAP */ lx_plx_reg_write(chip, ePLX_PCICR, 1); reg = lx_dsp_reg_read(chip, eReg_CSM); if (reg) { dev_err(chip->card->dev, "Error: Reg_CSM %x.\n", reg); return -EAGAIN; /* seems to be appropriate */ } } dev_dbg(chip->card->dev, "Xilinx/MicroBlaze access test successful\n"); return 0; } /* initialize ethersound */ static int lx_init_ethersound_config(struct lx6464es *chip) { int i; u32 orig_conf_es = lx_dsp_reg_read(chip, eReg_CONFES); /* configure 64 io channels */ u32 conf_es = (orig_conf_es & CONFES_READ_PART_MASK) | (64 << IOCR_INPUTS_OFFSET) | (64 << IOCR_OUTPUTS_OFFSET) | (FREQ_RATIO_SINGLE_MODE << FREQ_RATIO_OFFSET); dev_dbg(chip->card->dev, "->lx_init_ethersound\n"); chip->freq_ratio = FREQ_RATIO_SINGLE_MODE; /* * write it to the card ! * this actually kicks the ES xilinx, the first time since poweron. * the MAC address in the Reg_ADMACESMSB Reg_ADMACESLSB registers * is not ready before this is done, and the bit 2 in Reg_CSES is set. * */ lx_dsp_reg_write(chip, eReg_CONFES, conf_es); for (i = 0; i != 1000; ++i) { if (lx_dsp_reg_read(chip, eReg_CSES) & 4) { dev_dbg(chip->card->dev, "ethersound initialized after %dms\n", i); goto ethersound_initialized; } msleep(1); } dev_warn(chip->card->dev, "ethersound could not be initialized after %dms\n", i); return -ETIMEDOUT; ethersound_initialized: dev_dbg(chip->card->dev, "ethersound initialized\n"); return 0; } static int lx_init_get_version_features(struct lx6464es *chip) { u32 dsp_version; int err; dev_dbg(chip->card->dev, "->lx_init_get_version_features\n"); err = lx_dsp_get_version(chip, &dsp_version); if (err == 0) { u32 freq; dev_info(chip->card->dev, "DSP version: V%02d.%02d #%d\n", (dsp_version>>16) & 0xff, (dsp_version>>8) & 0xff, dsp_version & 0xff); /* later: what firmware version do we expect? */ /* retrieve Play/Rec features */ /* done here because we may have to handle alternate * DSP files. */ /* later */ /* init the EtherSound sample rate */ err = lx_dsp_get_clock_frequency(chip, &freq); if (err == 0) chip->board_sample_rate = freq; dev_dbg(chip->card->dev, "actual clock frequency %d\n", freq); } else { dev_err(chip->card->dev, "DSP corrupted \n"); err = -EAGAIN; } return err; } static int lx_set_granularity(struct lx6464es *chip, u32 gran) { int err = 0; u32 snapped_gran = MICROBLAZE_IBL_MIN; dev_dbg(chip->card->dev, "->lx_set_granularity\n"); /* blocksize is a power of 2 */ while ((snapped_gran < gran) && (snapped_gran < MICROBLAZE_IBL_MAX)) { snapped_gran *= 2; } if (snapped_gran == chip->pcm_granularity) return 0; err = lx_dsp_set_granularity(chip, snapped_gran); if (err < 0) { dev_warn(chip->card->dev, "could not set granularity\n"); err = -EAGAIN; } if (snapped_gran != gran) dev_err(chip->card->dev, "snapped blocksize to %d\n", snapped_gran); dev_dbg(chip->card->dev, "set blocksize on board %d\n", snapped_gran); chip->pcm_granularity = snapped_gran; return err; } /* initialize and test the xilinx dsp chip */ static int lx_init_dsp(struct lx6464es *chip) { int err; int i; dev_dbg(chip->card->dev, "->lx_init_dsp\n"); dev_dbg(chip->card->dev, "initialize board\n"); err = lx_init_xilinx_reset(chip); if (err) return err; dev_dbg(chip->card->dev, "testing board\n"); err = lx_init_xilinx_test(chip); if (err) return err; dev_dbg(chip->card->dev, "initialize ethersound configuration\n"); err = lx_init_ethersound_config(chip); if (err) return err; lx_irq_enable(chip); /** \todo the mac address should be ready by not, but it isn't, * so we wait for it */ for (i = 0; i != 1000; ++i) { err = lx_dsp_get_mac(chip); if (err) return err; if (chip->mac_address[0] || chip->mac_address[1] || chip->mac_address[2] || chip->mac_address[3] || chip->mac_address[4] || chip->mac_address[5]) goto mac_ready; msleep(1); } return -ETIMEDOUT; mac_ready: dev_dbg(chip->card->dev, "mac address ready read after: %dms\n", i); dev_info(chip->card->dev, "mac address: %02X.%02X.%02X.%02X.%02X.%02X\n", chip->mac_address[0], chip->mac_address[1], chip->mac_address[2], chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]); err = lx_init_get_version_features(chip); if (err) return err; lx_set_granularity(chip, MICROBLAZE_IBL_DEFAULT); chip->playback_mute = 0; return err; } static const struct snd_pcm_ops lx_ops_playback = { .open = lx_pcm_open, .close = lx_pcm_close, .prepare = lx_pcm_prepare, .hw_params = lx_pcm_hw_params_playback, .hw_free = lx_pcm_hw_free, .trigger = lx_pcm_trigger, .pointer = lx_pcm_stream_pointer, }; static const struct snd_pcm_ops lx_ops_capture = { .open = lx_pcm_open, .close = lx_pcm_close, .prepare = lx_pcm_prepare, .hw_params = lx_pcm_hw_params_capture, .hw_free = lx_pcm_hw_free, .trigger = lx_pcm_trigger, .pointer = lx_pcm_stream_pointer, }; static int lx_pcm_create(struct lx6464es *chip) { int err; struct snd_pcm *pcm; u32 size = 64 * /* channels */ 3 * /* 24 bit samples */ MAX_STREAM_BUFFER * /* periods */ MICROBLAZE_IBL_MAX * /* frames per period */ 2; /* duplex */ size = PAGE_ALIGN(size); /* hardcoded device name & channel count */ err = snd_pcm_new(chip->card, (char *)card_name, 0, 1, 1, &pcm); if (err < 0) return err; pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &lx_ops_playback); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &lx_ops_capture); pcm->info_flags = 0; pcm->nonatomic = true; strcpy(pcm->name, card_name); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev, size, size); chip->pcm = pcm; chip->capture_stream.is_capture = 1; return 0; } static int lx_control_playback_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int lx_control_playback_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lx6464es *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->playback_mute; return 0; } static int lx_control_playback_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct lx6464es *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int current_value = chip->playback_mute; if (current_value != ucontrol->value.integer.value[0]) { lx_level_unmute(chip, 0, !current_value); chip->playback_mute = !current_value; changed = 1; } return changed; } static const struct snd_kcontrol_new lx_control_playback_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Switch", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = lx_control_playback_info, .get = lx_control_playback_get, .put = lx_control_playback_put }; static void lx_proc_levels_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { u32 levels[64]; int err; int i, j; struct lx6464es *chip = entry->private_data; snd_iprintf(buffer, "capture levels:\n"); err = lx_level_peaks(chip, 1, 64, levels); if (err < 0) return; for (i = 0; i != 8; ++i) { for (j = 0; j != 8; ++j) snd_iprintf(buffer, "%08x ", levels[i*8+j]); snd_iprintf(buffer, "\n"); } snd_iprintf(buffer, "\nplayback levels:\n"); err = lx_level_peaks(chip, 0, 64, levels); if (err < 0) return; for (i = 0; i != 8; ++i) { for (j = 0; j != 8; ++j) snd_iprintf(buffer, "%08x ", levels[i*8+j]); snd_iprintf(buffer, "\n"); } snd_iprintf(buffer, "\n"); } static int lx_proc_create(struct snd_card *card, struct lx6464es *chip) { return snd_card_ro_proc_new(card, "levels", chip, lx_proc_levels_read); } static int snd_lx6464es_create(struct snd_card *card, struct pci_dev *pci) { struct lx6464es *chip = card->private_data; int err; dev_dbg(card->dev, "->snd_lx6464es_create\n"); /* enable PCI device */ err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(pci); /* check if we can restrict PCI DMA transfers to 32 bits */ err = dma_set_mask(&pci->dev, DMA_BIT_MASK(32)); if (err < 0) { dev_err(card->dev, "architecture does not support 32bit PCI busmaster DMA\n"); return -ENXIO; } chip->card = card; chip->pci = pci; chip->irq = -1; /* initialize synchronization structs */ mutex_init(&chip->lock); mutex_init(&chip->msg_lock); mutex_init(&chip->setup_mutex); /* request resources */ err = pci_request_regions(pci, card_name); if (err < 0) return err; /* plx port */ chip->port_plx = pci_resource_start(pci, 1); chip->port_plx_remapped = devm_ioport_map(&pci->dev, chip->port_plx, pci_resource_len(pci, 1)); if (!chip->port_plx_remapped) return -ENOMEM; /* dsp port */ chip->port_dsp_bar = pcim_iomap(pci, 2, 0); if (!chip->port_dsp_bar) return -ENOMEM; err = devm_request_threaded_irq(&pci->dev, pci->irq, lx_interrupt, lx_threaded_irq, IRQF_SHARED, KBUILD_MODNAME, chip); if (err) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); return err; } chip->irq = pci->irq; card->sync_irq = chip->irq; card->private_free = snd_lx6464es_free; err = lx_init_dsp(chip); if (err < 0) { dev_err(card->dev, "error during DSP initialization\n"); return err; } err = lx_pcm_create(chip); if (err < 0) return err; err = lx_proc_create(card, chip); if (err < 0) return err; err = snd_ctl_add(card, snd_ctl_new1(&lx_control_playback_switch, chip)); if (err < 0) return err; return 0; } static int snd_lx6464es_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct lx6464es *chip; int err; dev_dbg(&pci->dev, "->snd_lx6464es_probe\n"); if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) return err; chip = card->private_data; err = snd_lx6464es_create(card, pci); if (err < 0) { dev_err(card->dev, "error during snd_lx6464es_create\n"); goto error; } strcpy(card->driver, "LX6464ES"); sprintf(card->id, "LX6464ES_%02X%02X%02X", chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]); sprintf(card->shortname, "LX6464ES %02X.%02X.%02X.%02X.%02X.%02X", chip->mac_address[0], chip->mac_address[1], chip->mac_address[2], chip->mac_address[3], chip->mac_address[4], chip->mac_address[5]); sprintf(card->longname, "%s at 0x%lx, 0x%p, irq %i", card->shortname, chip->port_plx, chip->port_dsp_bar, chip->irq); err = snd_card_register(card); if (err < 0) goto error; dev_dbg(chip->card->dev, "initialization successful\n"); pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver lx6464es_driver = { .name = KBUILD_MODNAME, .id_table = snd_lx6464es_ids, .probe = snd_lx6464es_probe, }; module_pci_driver(lx6464es_driver);
linux-master
sound/pci/lx6464es/lx6464es.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for the Korg 1212 IO PCI card * * Copyright (c) 2001 Haroldo Gamal <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/wait.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/firmware.h> #include <linux/io.h> #include <sound/core.h> #include <sound/info.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/initval.h> // ---------------------------------------------------------------------------- // Debug Stuff // ---------------------------------------------------------------------------- #define K1212_DEBUG_LEVEL 0 #if K1212_DEBUG_LEVEL > 0 #define K1212_DEBUG_PRINTK(fmt,args...) printk(KERN_DEBUG fmt,##args) #else #define K1212_DEBUG_PRINTK(fmt,...) do { } while (0) #endif #if K1212_DEBUG_LEVEL > 1 #define K1212_DEBUG_PRINTK_VERBOSE(fmt,args...) printk(KERN_DEBUG fmt,##args) #else #define K1212_DEBUG_PRINTK_VERBOSE(fmt,...) #endif // ---------------------------------------------------------------------------- // Record/Play Buffer Allocation Method. If K1212_LARGEALLOC is defined all // buffers are alocated as a large piece inside KorgSharedBuffer. // ---------------------------------------------------------------------------- //#define K1212_LARGEALLOC 1 // ---------------------------------------------------------------------------- // Valid states of the Korg 1212 I/O card. // ---------------------------------------------------------------------------- enum CardState { K1212_STATE_NONEXISTENT, // there is no card here K1212_STATE_UNINITIALIZED, // the card is awaiting DSP download K1212_STATE_DSP_IN_PROCESS, // the card is currently downloading its DSP code K1212_STATE_DSP_COMPLETE, // the card has finished the DSP download K1212_STATE_READY, // the card can be opened by an application. Any application // requests prior to this state should fail. Only an open // request can be made at this state. K1212_STATE_OPEN, // an application has opened the card K1212_STATE_SETUP, // the card has been setup for play K1212_STATE_PLAYING, // the card is playing K1212_STATE_MONITOR, // the card is in the monitor mode K1212_STATE_CALIBRATING, // the card is currently calibrating K1212_STATE_ERRORSTOP, // the card has stopped itself because of an error and we // are in the process of cleaning things up. K1212_STATE_MAX_STATE // state values of this and beyond are invalid }; // ---------------------------------------------------------------------------- // The following enumeration defines the constants written to the card's // host-to-card doorbell to initiate a command. // ---------------------------------------------------------------------------- enum korg1212_dbcnst { K1212_DB_RequestForData = 0, // sent by the card to request a buffer fill. K1212_DB_TriggerPlay = 1, // starts playback/record on the card. K1212_DB_SelectPlayMode = 2, // select monitor, playback setup, or stop. K1212_DB_ConfigureBufferMemory = 3, // tells card where the host audio buffers are. K1212_DB_RequestAdatTimecode = 4, // asks the card for the latest ADAT timecode value. K1212_DB_SetClockSourceRate = 5, // sets the clock source and rate for the card. K1212_DB_ConfigureMiscMemory = 6, // tells card where other buffers are. K1212_DB_TriggerFromAdat = 7, // tells card to trigger from Adat at a specific // timecode value. K1212_DB_DMAERROR = 0x80, // DMA Error - the PCI bus is congestioned. K1212_DB_CARDSTOPPED = 0x81, // Card has stopped by user request. K1212_DB_RebootCard = 0xA0, // instructs the card to reboot. K1212_DB_BootFromDSPPage4 = 0xA4, // instructs the card to boot from the DSP microcode // on page 4 (local page to card). K1212_DB_DSPDownloadDone = 0xAE, // sent by the card to indicate the download has // completed. K1212_DB_StartDSPDownload = 0xAF // tells the card to download its DSP firmware. }; // ---------------------------------------------------------------------------- // The following enumeration defines return codes // to the Korg 1212 I/O driver. // ---------------------------------------------------------------------------- enum snd_korg1212rc { K1212_CMDRET_Success = 0, // command was successfully placed K1212_CMDRET_DIOCFailure, // the DeviceIoControl call failed K1212_CMDRET_PMFailure, // the protected mode call failed K1212_CMDRET_FailUnspecified, // unspecified failure K1212_CMDRET_FailBadState, // the specified command can not be given in // the card's current state. (or the wave device's // state) K1212_CMDRET_CardUninitialized, // the card is uninitialized and cannot be used K1212_CMDRET_BadIndex, // an out of range card index was specified K1212_CMDRET_BadHandle, // an invalid card handle was specified K1212_CMDRET_NoFillRoutine, // a play request has been made before a fill routine set K1212_CMDRET_FillRoutineInUse, // can't set a new fill routine while one is in use K1212_CMDRET_NoAckFromCard, // the card never acknowledged a command K1212_CMDRET_BadParams, // bad parameters were provided by the caller K1212_CMDRET_BadDevice, // the specified wave device was out of range K1212_CMDRET_BadFormat // the specified wave format is unsupported }; // ---------------------------------------------------------------------------- // The following enumeration defines the constants used to select the play // mode for the card in the SelectPlayMode command. // ---------------------------------------------------------------------------- enum PlayModeSelector { K1212_MODE_SetupPlay = 0x00000001, // provides card with pre-play information K1212_MODE_MonitorOn = 0x00000002, // tells card to turn on monitor mode K1212_MODE_MonitorOff = 0x00000004, // tells card to turn off monitor mode K1212_MODE_StopPlay = 0x00000008 // stops playback on the card }; // ---------------------------------------------------------------------------- // The following enumeration defines the constants used to select the monitor // mode for the card in the SetMonitorMode command. // ---------------------------------------------------------------------------- enum MonitorModeSelector { K1212_MONMODE_Off = 0, // tells card to turn off monitor mode K1212_MONMODE_On // tells card to turn on monitor mode }; #define MAILBOX0_OFFSET 0x40 // location of mailbox 0 relative to base address #define MAILBOX1_OFFSET 0x44 // location of mailbox 1 relative to base address #define MAILBOX2_OFFSET 0x48 // location of mailbox 2 relative to base address #define MAILBOX3_OFFSET 0x4c // location of mailbox 3 relative to base address #define OUT_DOORBELL_OFFSET 0x60 // location of PCI to local doorbell #define IN_DOORBELL_OFFSET 0x64 // location of local to PCI doorbell #define STATUS_REG_OFFSET 0x68 // location of interrupt control/status register #define PCI_CONTROL_OFFSET 0x6c // location of the EEPROM, PCI, User I/O, init control // register #define SENS_CONTROL_OFFSET 0x6e // location of the input sensitivity setting register. // this is the upper word of the PCI control reg. #define DEV_VEND_ID_OFFSET 0x70 // location of the device and vendor ID register #define MAX_COMMAND_RETRIES 5 // maximum number of times the driver will attempt // to send a command before giving up. #define COMMAND_ACK_MASK 0x8000 // the MSB is set in the command acknowledgment from // the card. #define DOORBELL_VAL_MASK 0x00FF // the doorbell value is one byte #define CARD_BOOT_DELAY_IN_MS 10 #define CARD_BOOT_TIMEOUT 10 #define DSP_BOOT_DELAY_IN_MS 200 #define kNumBuffers 8 #define k1212MaxCards 4 #define k1212NumWaveDevices 6 #define k16BitChannels 10 #define k32BitChannels 2 #define kAudioChannels (k16BitChannels + k32BitChannels) #define kPlayBufferFrames 1024 #define K1212_ANALOG_CHANNELS 2 #define K1212_SPDIF_CHANNELS 2 #define K1212_ADAT_CHANNELS 8 #define K1212_CHANNELS (K1212_ADAT_CHANNELS + K1212_ANALOG_CHANNELS) #define K1212_MIN_CHANNELS 1 #define K1212_MAX_CHANNELS K1212_CHANNELS #define K1212_FRAME_SIZE (sizeof(struct KorgAudioFrame)) #define K1212_MAX_SAMPLES (kPlayBufferFrames*kNumBuffers) #define K1212_PERIODS (kNumBuffers) #define K1212_PERIOD_BYTES (K1212_FRAME_SIZE*kPlayBufferFrames) #define K1212_BUF_SIZE (K1212_PERIOD_BYTES*kNumBuffers) #define K1212_ANALOG_BUF_SIZE (K1212_ANALOG_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers) #define K1212_SPDIF_BUF_SIZE (K1212_SPDIF_CHANNELS * 3 * kPlayBufferFrames * kNumBuffers) #define K1212_ADAT_BUF_SIZE (K1212_ADAT_CHANNELS * 2 * kPlayBufferFrames * kNumBuffers) #define K1212_MAX_BUF_SIZE (K1212_ANALOG_BUF_SIZE + K1212_ADAT_BUF_SIZE) #define k1212MinADCSens 0x00 #define k1212MaxADCSens 0x7f #define k1212MaxVolume 0x7fff #define k1212MaxWaveVolume 0xffff #define k1212MinVolume 0x0000 #define k1212MaxVolInverted 0x8000 // ----------------------------------------------------------------- // the following bits are used for controlling interrupts in the // interrupt control/status reg // ----------------------------------------------------------------- #define PCI_INT_ENABLE_BIT 0x00000100 #define PCI_DOORBELL_INT_ENABLE_BIT 0x00000200 #define LOCAL_INT_ENABLE_BIT 0x00010000 #define LOCAL_DOORBELL_INT_ENABLE_BIT 0x00020000 #define LOCAL_DMA1_INT_ENABLE_BIT 0x00080000 // ----------------------------------------------------------------- // the following bits are defined for the PCI command register // ----------------------------------------------------------------- #define PCI_CMD_MEM_SPACE_ENABLE_BIT 0x0002 #define PCI_CMD_IO_SPACE_ENABLE_BIT 0x0001 #define PCI_CMD_BUS_MASTER_ENABLE_BIT 0x0004 // ----------------------------------------------------------------- // the following bits are defined for the PCI status register // ----------------------------------------------------------------- #define PCI_STAT_PARITY_ERROR_BIT 0x8000 #define PCI_STAT_SYSTEM_ERROR_BIT 0x4000 #define PCI_STAT_MASTER_ABORT_RCVD_BIT 0x2000 #define PCI_STAT_TARGET_ABORT_RCVD_BIT 0x1000 #define PCI_STAT_TARGET_ABORT_SENT_BIT 0x0800 // ------------------------------------------------------------------------ // the following constants are used in setting the 1212 I/O card's input // sensitivity. // ------------------------------------------------------------------------ #define SET_SENS_LOCALINIT_BITPOS 15 #define SET_SENS_DATA_BITPOS 10 #define SET_SENS_CLOCK_BITPOS 8 #define SET_SENS_LOADSHIFT_BITPOS 0 #define SET_SENS_LEFTCHANID 0x00 #define SET_SENS_RIGHTCHANID 0x01 #define K1212SENSUPDATE_DELAY_IN_MS 50 // -------------------------------------------------------------------------- // WaitRTCTicks // // This function waits the specified number of real time clock ticks. // According to the DDK, each tick is ~0.8 microseconds. // The defines following the function declaration can be used for the // numTicksToWait parameter. // -------------------------------------------------------------------------- #define ONE_RTC_TICK 1 #define SENSCLKPULSE_WIDTH 4 #define LOADSHIFT_DELAY 4 #define INTERCOMMAND_DELAY 40 #define STOPCARD_DELAY 300 // max # RTC ticks for the card to stop once we write // the command register. (could be up to 180 us) #define COMMAND_ACK_DELAY 13 // number of RTC ticks to wait for an acknowledgement // from the card after sending a command. enum ClockSourceIndex { K1212_CLKIDX_AdatAt44_1K = 0, // selects source as ADAT at 44.1 kHz K1212_CLKIDX_AdatAt48K, // selects source as ADAT at 48 kHz K1212_CLKIDX_WordAt44_1K, // selects source as S/PDIF at 44.1 kHz K1212_CLKIDX_WordAt48K, // selects source as S/PDIF at 48 kHz K1212_CLKIDX_LocalAt44_1K, // selects source as local clock at 44.1 kHz K1212_CLKIDX_LocalAt48K, // selects source as local clock at 48 kHz K1212_CLKIDX_Invalid // used to check validity of the index }; enum ClockSourceType { K1212_CLKIDX_Adat = 0, // selects source as ADAT K1212_CLKIDX_Word, // selects source as S/PDIF K1212_CLKIDX_Local // selects source as local clock }; struct KorgAudioFrame { u16 frameData16[k16BitChannels]; /* channels 0-9 use 16 bit samples */ u32 frameData32[k32BitChannels]; /* channels 10-11 use 32 bits - only 20 are sent across S/PDIF */ u32 timeCodeVal; /* holds the ADAT timecode value */ }; struct KorgAudioBuffer { struct KorgAudioFrame bufferData[kPlayBufferFrames]; /* buffer definition */ }; struct KorgSharedBuffer { #ifdef K1212_LARGEALLOC struct KorgAudioBuffer playDataBufs[kNumBuffers]; struct KorgAudioBuffer recordDataBufs[kNumBuffers]; #endif short volumeData[kAudioChannels]; u32 cardCommand; u16 routeData [kAudioChannels]; u32 AdatTimeCode; // ADAT timecode value }; struct SensBits { union { struct { unsigned int leftChanVal:8; unsigned int leftChanId:8; } v; u16 leftSensBits; } l; union { struct { unsigned int rightChanVal:8; unsigned int rightChanId:8; } v; u16 rightSensBits; } r; }; struct snd_korg1212 { struct snd_card *card; struct pci_dev *pci; struct snd_pcm *pcm; int irq; spinlock_t lock; struct mutex open_mutex; struct timer_list timer; /* timer callback for checking ack of stop request */ int stop_pending_cnt; /* counter for stop pending check */ wait_queue_head_t wait; unsigned long iomem; unsigned long ioport; unsigned long iomem2; unsigned long irqcount; unsigned long inIRQ; void __iomem *iobase; struct snd_dma_buffer *dma_dsp; struct snd_dma_buffer *dma_play; struct snd_dma_buffer *dma_rec; struct snd_dma_buffer *dma_shared; u32 DataBufsSize; struct KorgAudioBuffer * playDataBufsPtr; struct KorgAudioBuffer * recordDataBufsPtr; struct KorgSharedBuffer * sharedBufferPtr; u32 RecDataPhy; u32 PlayDataPhy; unsigned long sharedBufferPhy; u32 VolumeTablePhy; u32 RoutingTablePhy; u32 AdatTimeCodePhy; u32 __iomem * statusRegPtr; // address of the interrupt status/control register u32 __iomem * outDoorbellPtr; // address of the host->card doorbell register u32 __iomem * inDoorbellPtr; // address of the card->host doorbell register u32 __iomem * mailbox0Ptr; // address of mailbox 0 on the card u32 __iomem * mailbox1Ptr; // address of mailbox 1 on the card u32 __iomem * mailbox2Ptr; // address of mailbox 2 on the card u32 __iomem * mailbox3Ptr; // address of mailbox 3 on the card u32 __iomem * controlRegPtr; // address of the EEPROM, PCI, I/O, Init ctrl reg u16 __iomem * sensRegPtr; // address of the sensitivity setting register u32 __iomem * idRegPtr; // address of the device and vendor ID registers size_t periodsize; int channels; int currentBuffer; struct snd_pcm_substream *playback_substream; struct snd_pcm_substream *capture_substream; pid_t capture_pid; pid_t playback_pid; enum CardState cardState; int running; int idleMonitorOn; // indicates whether the card is in idle monitor mode. u32 cmdRetryCount; // tracks how many times we have retried sending to the card. enum ClockSourceIndex clkSrcRate; // sample rate and clock source enum ClockSourceType clkSource; // clock source int clkRate; // clock rate int volumePhase[kAudioChannels]; u16 leftADCInSens; // ADC left channel input sensitivity u16 rightADCInSens; // ADC right channel input sensitivity int opencnt; // Open/Close count int setcnt; // SetupForPlay count int playcnt; // TriggerPlay count int errorcnt; // Error Count unsigned long totalerrorcnt; // Total Error Count int dsp_is_loaded; int dsp_stop_is_processed; }; MODULE_DESCRIPTION("korg1212"); MODULE_LICENSE("GPL"); MODULE_FIRMWARE("korg/k1212.dsp"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Korg 1212 soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Korg 1212 soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Korg 1212 soundcard."); MODULE_AUTHOR("Haroldo Gamal <[email protected]>"); static const struct pci_device_id snd_korg1212_ids[] = { { .vendor = 0x10b5, .device = 0x906d, .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, }, { 0, }, }; MODULE_DEVICE_TABLE(pci, snd_korg1212_ids); static const char * const stateName[] = { "Non-existent", "Uninitialized", "DSP download in process", "DSP download complete", "Ready", "Open", "Setup for play", "Playing", "Monitor mode on", "Calibrating", "Invalid" }; static const char * const clockSourceTypeName[] = { "ADAT", "S/PDIF", "local" }; static const char * const clockSourceName[] = { "ADAT at 44.1 kHz", "ADAT at 48 kHz", "S/PDIF at 44.1 kHz", "S/PDIF at 48 kHz", "local clock at 44.1 kHz", "local clock at 48 kHz" }; static const char * const channelName[] = { "ADAT-1", "ADAT-2", "ADAT-3", "ADAT-4", "ADAT-5", "ADAT-6", "ADAT-7", "ADAT-8", "Analog-L", "Analog-R", "SPDIF-L", "SPDIF-R", }; static const u16 ClockSourceSelector[] = { 0x8000, // selects source as ADAT at 44.1 kHz 0x0000, // selects source as ADAT at 48 kHz 0x8001, // selects source as S/PDIF at 44.1 kHz 0x0001, // selects source as S/PDIF at 48 kHz 0x8002, // selects source as local clock at 44.1 kHz 0x0002 // selects source as local clock at 48 kHz }; union swap_u32 { unsigned char c[4]; u32 i; }; #ifdef SNDRV_BIG_ENDIAN static u32 LowerWordSwap(u32 swappee) #else static u32 UpperWordSwap(u32 swappee) #endif { union swap_u32 retVal, swapper; swapper.i = swappee; retVal.c[2] = swapper.c[3]; retVal.c[3] = swapper.c[2]; retVal.c[1] = swapper.c[1]; retVal.c[0] = swapper.c[0]; return retVal.i; } #ifdef SNDRV_BIG_ENDIAN static u32 UpperWordSwap(u32 swappee) #else static u32 LowerWordSwap(u32 swappee) #endif { union swap_u32 retVal, swapper; swapper.i = swappee; retVal.c[2] = swapper.c[2]; retVal.c[3] = swapper.c[3]; retVal.c[1] = swapper.c[0]; retVal.c[0] = swapper.c[1]; return retVal.i; } #define SetBitInWord(theWord,bitPosition) (*theWord) |= (0x0001 << bitPosition) #define SetBitInDWord(theWord,bitPosition) (*theWord) |= (0x00000001 << bitPosition) #define ClearBitInWord(theWord,bitPosition) (*theWord) &= ~(0x0001 << bitPosition) #define ClearBitInDWord(theWord,bitPosition) (*theWord) &= ~(0x00000001 << bitPosition) static int snd_korg1212_Send1212Command(struct snd_korg1212 *korg1212, enum korg1212_dbcnst doorbellVal, u32 mailBox0Val, u32 mailBox1Val, u32 mailBox2Val, u32 mailBox3Val) { u32 retryCount; u16 mailBox3Lo; int rc = K1212_CMDRET_Success; if (!korg1212->outDoorbellPtr) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: CardUninitialized\n"); return K1212_CMDRET_CardUninitialized; } K1212_DEBUG_PRINTK("K1212_DEBUG: Card <- 0x%08x 0x%08x [%s]\n", doorbellVal, mailBox0Val, stateName[korg1212->cardState]); for (retryCount = 0; retryCount < MAX_COMMAND_RETRIES; retryCount++) { writel(mailBox3Val, korg1212->mailbox3Ptr); writel(mailBox2Val, korg1212->mailbox2Ptr); writel(mailBox1Val, korg1212->mailbox1Ptr); writel(mailBox0Val, korg1212->mailbox0Ptr); writel(doorbellVal, korg1212->outDoorbellPtr); // interrupt the card // -------------------------------------------------------------- // the reboot command will not give an acknowledgement. // -------------------------------------------------------------- if ( doorbellVal == K1212_DB_RebootCard || doorbellVal == K1212_DB_BootFromDSPPage4 || doorbellVal == K1212_DB_StartDSPDownload ) { rc = K1212_CMDRET_Success; break; } // -------------------------------------------------------------- // See if the card acknowledged the command. Wait a bit, then // read in the low word of mailbox3. If the MSB is set and the // low byte is equal to the doorbell value, then it ack'd. // -------------------------------------------------------------- udelay(COMMAND_ACK_DELAY); mailBox3Lo = readl(korg1212->mailbox3Ptr); if (mailBox3Lo & COMMAND_ACK_MASK) { if ((mailBox3Lo & DOORBELL_VAL_MASK) == (doorbellVal & DOORBELL_VAL_MASK)) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- Success\n"); rc = K1212_CMDRET_Success; break; } } } korg1212->cmdRetryCount += retryCount; if (retryCount >= MAX_COMMAND_RETRIES) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Card <- NoAckFromCard\n"); rc = K1212_CMDRET_NoAckFromCard; } return rc; } /* spinlock already held */ static void snd_korg1212_SendStop(struct snd_korg1212 *korg1212) { if (! korg1212->stop_pending_cnt) { korg1212->sharedBufferPtr->cardCommand = 0xffffffff; /* program the timer */ korg1212->stop_pending_cnt = HZ; mod_timer(&korg1212->timer, jiffies + 1); } } static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212) { unsigned long flags; spin_lock_irqsave(&korg1212->lock, flags); korg1212->dsp_stop_is_processed = 0; snd_korg1212_SendStop(korg1212); spin_unlock_irqrestore(&korg1212->lock, flags); wait_event_timeout(korg1212->wait, korg1212->dsp_stop_is_processed, (HZ * 3) / 2); } /* timer callback for checking the ack of stop request */ static void snd_korg1212_timer_func(struct timer_list *t) { struct snd_korg1212 *korg1212 = from_timer(korg1212, t, timer); unsigned long flags; spin_lock_irqsave(&korg1212->lock, flags); if (korg1212->sharedBufferPtr->cardCommand == 0) { /* ack'ed */ korg1212->stop_pending_cnt = 0; korg1212->dsp_stop_is_processed = 1; wake_up(&korg1212->wait); K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: Stop ack'ed [%s]\n", stateName[korg1212->cardState]); } else { if (--korg1212->stop_pending_cnt > 0) { /* reprogram timer */ mod_timer(&korg1212->timer, jiffies + 1); } else { snd_printd("korg1212_timer_func timeout\n"); korg1212->sharedBufferPtr->cardCommand = 0; korg1212->dsp_stop_is_processed = 1; wake_up(&korg1212->wait); K1212_DEBUG_PRINTK("K1212_DEBUG: Stop timeout [%s]\n", stateName[korg1212->cardState]); } } spin_unlock_irqrestore(&korg1212->lock, flags); } static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212 *korg1212) { unsigned long flags; int rc; udelay(INTERCOMMAND_DELAY); spin_lock_irqsave(&korg1212->lock, flags); korg1212->idleMonitorOn = 1; rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0); spin_unlock_irqrestore(&korg1212->lock, flags); return rc; } static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212 *korg1212) { if (korg1212->idleMonitorOn) { snd_korg1212_SendStopAndWait(korg1212); korg1212->idleMonitorOn = 0; } } static inline void snd_korg1212_setCardState(struct snd_korg1212 * korg1212, enum CardState csState) { korg1212->cardState = csState; } static int snd_korg1212_OpenCard(struct snd_korg1212 * korg1212) { K1212_DEBUG_PRINTK("K1212_DEBUG: OpenCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt); mutex_lock(&korg1212->open_mutex); if (korg1212->opencnt++ == 0) { snd_korg1212_TurnOffIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); } mutex_unlock(&korg1212->open_mutex); return 1; } static int snd_korg1212_CloseCard(struct snd_korg1212 * korg1212) { K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard [%s] %d\n", stateName[korg1212->cardState], korg1212->opencnt); mutex_lock(&korg1212->open_mutex); if (--(korg1212->opencnt)) { mutex_unlock(&korg1212->open_mutex); return 0; } if (korg1212->cardState == K1212_STATE_SETUP) { int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_StopPlay, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: CloseCard - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { mutex_unlock(&korg1212->open_mutex); return 0; } } else if (korg1212->cardState > K1212_STATE_SETUP) { snd_korg1212_SendStopAndWait(korg1212); } if (korg1212->cardState > K1212_STATE_READY) { snd_korg1212_TurnOnIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_READY); } mutex_unlock(&korg1212->open_mutex); return 0; } /* spinlock already held */ static int snd_korg1212_SetupForPlay(struct snd_korg1212 * korg1212) { int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->setcnt); if (korg1212->setcnt++) return 0; snd_korg1212_setCardState(korg1212, K1212_STATE_SETUP); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_SetupPlay, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: SetupForPlay - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { return 1; } return 0; } /* spinlock already held */ static int snd_korg1212_TriggerPlay(struct snd_korg1212 * korg1212) { int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt); if (korg1212->playcnt++) return 0; snd_korg1212_setCardState(korg1212, K1212_STATE_PLAYING); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_TriggerPlay, 0, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: TriggerPlay - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); if (rc != K1212_CMDRET_Success) { return 1; } return 0; } /* spinlock already held */ static int snd_korg1212_StopPlay(struct snd_korg1212 * korg1212) { K1212_DEBUG_PRINTK("K1212_DEBUG: StopPlay [%s] %d\n", stateName[korg1212->cardState], korg1212->playcnt); if (--(korg1212->playcnt)) return 0; korg1212->setcnt = 0; if (korg1212->cardState != K1212_STATE_ERRORSTOP) snd_korg1212_SendStop(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); return 0; } static void snd_korg1212_EnableCardInterrupts(struct snd_korg1212 * korg1212) { writel(PCI_INT_ENABLE_BIT | PCI_DOORBELL_INT_ENABLE_BIT | LOCAL_INT_ENABLE_BIT | LOCAL_DOORBELL_INT_ENABLE_BIT | LOCAL_DMA1_INT_ENABLE_BIT, korg1212->statusRegPtr); } #if 0 /* not used */ static int snd_korg1212_SetMonitorMode(struct snd_korg1212 *korg1212, enum MonitorModeSelector mode) { K1212_DEBUG_PRINTK("K1212_DEBUG: SetMonitorMode [%s]\n", stateName[korg1212->cardState]); switch (mode) { case K1212_MONMODE_Off: if (korg1212->cardState != K1212_STATE_MONITOR) return 0; else { snd_korg1212_SendStopAndWait(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_OPEN); } break; case K1212_MONMODE_On: if (korg1212->cardState != K1212_STATE_OPEN) return 0; else { int rc; snd_korg1212_setCardState(korg1212, K1212_STATE_MONITOR); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0); if (rc != K1212_CMDRET_Success) return 0; } break; default: return 0; } return 1; } #endif /* not used */ static inline int snd_korg1212_use_is_exclusive(struct snd_korg1212 *korg1212) { if (korg1212->playback_pid != korg1212->capture_pid && korg1212->playback_pid >= 0 && korg1212->capture_pid >= 0) return 0; return 1; } static int snd_korg1212_SetRate(struct snd_korg1212 *korg1212, int rate) { static const enum ClockSourceIndex s44[] = { K1212_CLKIDX_AdatAt44_1K, K1212_CLKIDX_WordAt44_1K, K1212_CLKIDX_LocalAt44_1K }; static const enum ClockSourceIndex s48[] = { K1212_CLKIDX_AdatAt48K, K1212_CLKIDX_WordAt48K, K1212_CLKIDX_LocalAt48K }; int parm, rc; if (!snd_korg1212_use_is_exclusive (korg1212)) return -EBUSY; switch (rate) { case 44100: parm = s44[korg1212->clkSource]; break; case 48000: parm = s48[korg1212->clkSource]; break; default: return -EINVAL; } korg1212->clkSrcRate = parm; korg1212->clkRate = rate; udelay(INTERCOMMAND_DELAY); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, ClockSourceSelector[korg1212->clkSrcRate], 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); return 0; } static int snd_korg1212_SetClockSource(struct snd_korg1212 *korg1212, int source) { if (source < 0 || source > 2) return -EINVAL; korg1212->clkSource = source; snd_korg1212_SetRate(korg1212, korg1212->clkRate); return 0; } static void snd_korg1212_DisableCardInterrupts(struct snd_korg1212 *korg1212) { writel(0, korg1212->statusRegPtr); } static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212) { struct SensBits sensVals; int bitPosition; int channel; int clkIs48K; int monModeSet; u16 controlValue; // this keeps the current value to be written to // the card's eeprom control register. u16 count; unsigned long flags; K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n", stateName[korg1212->cardState]); // ---------------------------------------------------------------------------- // initialize things. The local init bit is always set when writing to the // card's control register. // ---------------------------------------------------------------------------- controlValue = 0; SetBitInWord(&controlValue, SET_SENS_LOCALINIT_BITPOS); // init the control value // ---------------------------------------------------------------------------- // make sure the card is not in monitor mode when we do this update. // ---------------------------------------------------------------------------- if (korg1212->cardState == K1212_STATE_MONITOR || korg1212->idleMonitorOn) { monModeSet = 1; snd_korg1212_SendStopAndWait(korg1212); } else monModeSet = 0; spin_lock_irqsave(&korg1212->lock, flags); // ---------------------------------------------------------------------------- // we are about to send new values to the card, so clear the new values queued // flag. Also, clear out mailbox 3, so we don't lockup. // ---------------------------------------------------------------------------- writel(0, korg1212->mailbox3Ptr); udelay(LOADSHIFT_DELAY); // ---------------------------------------------------------------------------- // determine whether we are running a 48K or 44.1K clock. This info is used // later when setting the SPDIF FF after the volume has been shifted in. // ---------------------------------------------------------------------------- switch (korg1212->clkSrcRate) { case K1212_CLKIDX_AdatAt44_1K: case K1212_CLKIDX_WordAt44_1K: case K1212_CLKIDX_LocalAt44_1K: clkIs48K = 0; break; case K1212_CLKIDX_WordAt48K: case K1212_CLKIDX_AdatAt48K: case K1212_CLKIDX_LocalAt48K: default: clkIs48K = 1; break; } // ---------------------------------------------------------------------------- // start the update. Setup the bit structure and then shift the bits. // ---------------------------------------------------------------------------- sensVals.l.v.leftChanId = SET_SENS_LEFTCHANID; sensVals.r.v.rightChanId = SET_SENS_RIGHTCHANID; sensVals.l.v.leftChanVal = korg1212->leftADCInSens; sensVals.r.v.rightChanVal = korg1212->rightADCInSens; // ---------------------------------------------------------------------------- // now start shifting the bits in. Start with the left channel then the right. // ---------------------------------------------------------------------------- for (channel = 0; channel < 2; channel++) { // ---------------------------------------------------------------------------- // Bring the load/shift line low, then wait - the spec says >150ns from load/ // shift low to the first rising edge of the clock. // ---------------------------------------------------------------------------- ClearBitInWord(&controlValue, SET_SENS_LOADSHIFT_BITPOS); ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); writew(controlValue, korg1212->sensRegPtr); // load/shift goes low udelay(LOADSHIFT_DELAY); for (bitPosition = 15; bitPosition >= 0; bitPosition--) { // for all the bits if (channel == 0) { if (sensVals.l.leftSensBits & (0x0001 << bitPosition)) SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high else ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low } else { if (sensVals.r.rightSensBits & (0x0001 << bitPosition)) SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set high else ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); // data bit set low } ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); writew(controlValue, korg1212->sensRegPtr); // clock goes low udelay(SENSCLKPULSE_WIDTH); SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); writew(controlValue, korg1212->sensRegPtr); // clock goes high udelay(SENSCLKPULSE_WIDTH); } // ---------------------------------------------------------------------------- // finish up SPDIF for left. Bring the load/shift line high, then write a one // bit if the clock rate is 48K otherwise write 0. // ---------------------------------------------------------------------------- ClearBitInWord(&controlValue, SET_SENS_DATA_BITPOS); ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); SetBitInWord(&controlValue, SET_SENS_LOADSHIFT_BITPOS); writew(controlValue, korg1212->sensRegPtr); // load shift goes high - clk low udelay(SENSCLKPULSE_WIDTH); if (clkIs48K) SetBitInWord(&controlValue, SET_SENS_DATA_BITPOS); writew(controlValue, korg1212->sensRegPtr); // set/clear data bit udelay(ONE_RTC_TICK); SetBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); writew(controlValue, korg1212->sensRegPtr); // clock goes high udelay(SENSCLKPULSE_WIDTH); ClearBitInWord(&controlValue, SET_SENS_CLOCK_BITPOS); writew(controlValue, korg1212->sensRegPtr); // clock goes low udelay(SENSCLKPULSE_WIDTH); } // ---------------------------------------------------------------------------- // The update is complete. Set a timeout. This is the inter-update delay. // Also, if the card was in monitor mode, restore it. // ---------------------------------------------------------------------------- for (count = 0; count < 10; count++) udelay(SENSCLKPULSE_WIDTH); if (monModeSet) { int rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode, K1212_MODE_MonitorOn, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); } spin_unlock_irqrestore(&korg1212->lock, flags); return 1; } static void snd_korg1212_OnDSPDownloadComplete(struct snd_korg1212 *korg1212) { int channel, rc; K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is complete. [%s]\n", stateName[korg1212->cardState]); // ---------------------------------------------------- // tell the card to boot // ---------------------------------------------------- rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_BootFromDSPPage4, 0, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Boot from Page 4 - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); msleep(DSP_BOOT_DELAY_IN_MS); // -------------------------------------------------------------------------------- // Let the card know where all the buffers are. // -------------------------------------------------------------------------------- rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_ConfigureBufferMemory, LowerWordSwap(korg1212->PlayDataPhy), LowerWordSwap(korg1212->RecDataPhy), ((kNumBuffers * kPlayBufferFrames) / 2), // size given to the card // is based on 2 buffers 0 ); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Buffer Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); udelay(INTERCOMMAND_DELAY); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_ConfigureMiscMemory, LowerWordSwap(korg1212->VolumeTablePhy), LowerWordSwap(korg1212->RoutingTablePhy), LowerWordSwap(korg1212->AdatTimeCodePhy), 0 ); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Configure Misc Memory - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); // -------------------------------------------------------------------------------- // Initialize the routing and volume tables, then update the card's state. // -------------------------------------------------------------------------------- udelay(INTERCOMMAND_DELAY); for (channel = 0; channel < kAudioChannels; channel++) { korg1212->sharedBufferPtr->volumeData[channel] = k1212MaxVolume; //korg1212->sharedBufferPtr->routeData[channel] = channel; korg1212->sharedBufferPtr->routeData[channel] = 8 + (channel & 1); } snd_korg1212_WriteADCSensitivity(korg1212); udelay(INTERCOMMAND_DELAY); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SetClockSourceRate, ClockSourceSelector[korg1212->clkSrcRate], 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Clock Source Selector - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); rc = snd_korg1212_TurnOnIdleMonitor(korg1212); snd_korg1212_setCardState(korg1212, K1212_STATE_READY); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Set Monitor On - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_COMPLETE); } static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id) { u32 doorbellValue; struct snd_korg1212 *korg1212 = dev_id; doorbellValue = readl(korg1212->inDoorbellPtr); if (!doorbellValue) return IRQ_NONE; spin_lock(&korg1212->lock); writel(doorbellValue, korg1212->inDoorbellPtr); korg1212->irqcount++; korg1212->inIRQ++; switch (doorbellValue) { case K1212_DB_DSPDownloadDone: K1212_DEBUG_PRINTK("K1212_DEBUG: IRQ DNLD count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); if (korg1212->cardState == K1212_STATE_DSP_IN_PROCESS) { korg1212->dsp_is_loaded = 1; wake_up(&korg1212->wait); } break; // ------------------------------------------------------------------------ // an error occurred - stop the card // ------------------------------------------------------------------------ case K1212_DB_DMAERROR: K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DMAE count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); snd_printk(KERN_ERR "korg1212: DMA Error\n"); korg1212->errorcnt++; korg1212->totalerrorcnt++; korg1212->sharedBufferPtr->cardCommand = 0; snd_korg1212_setCardState(korg1212, K1212_STATE_ERRORSTOP); break; // ------------------------------------------------------------------------ // the card has stopped by our request. Clear the command word and signal // the semaphore in case someone is waiting for this. // ------------------------------------------------------------------------ case K1212_DB_CARDSTOPPED: K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ CSTP count - %ld, %x, [%s].\n", korg1212->irqcount, doorbellValue, stateName[korg1212->cardState]); korg1212->sharedBufferPtr->cardCommand = 0; break; default: K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: IRQ DFLT count - %ld, %x, cpos=%d [%s].\n", korg1212->irqcount, doorbellValue, korg1212->currentBuffer, stateName[korg1212->cardState]); if ((korg1212->cardState > K1212_STATE_SETUP) || korg1212->idleMonitorOn) { korg1212->currentBuffer++; if (korg1212->currentBuffer >= kNumBuffers) korg1212->currentBuffer = 0; if (!korg1212->running) break; if (korg1212->capture_substream) { spin_unlock(&korg1212->lock); snd_pcm_period_elapsed(korg1212->capture_substream); spin_lock(&korg1212->lock); } if (korg1212->playback_substream) { spin_unlock(&korg1212->lock); snd_pcm_period_elapsed(korg1212->playback_substream); spin_lock(&korg1212->lock); } } break; } korg1212->inIRQ--; spin_unlock(&korg1212->lock); return IRQ_HANDLED; } static int snd_korg1212_downloadDSPCode(struct snd_korg1212 *korg1212) { int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: DSP download is starting... [%s]\n", stateName[korg1212->cardState]); // --------------------------------------------------------------- // verify the state of the card before proceeding. // --------------------------------------------------------------- if (korg1212->cardState >= K1212_STATE_DSP_IN_PROCESS) return 1; snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_IN_PROCESS); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_StartDSPDownload, UpperWordSwap(korg1212->dma_dsp->addr), 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", rc, stateName[korg1212->cardState]); korg1212->dsp_is_loaded = 0; wait_event_timeout(korg1212->wait, korg1212->dsp_is_loaded, HZ * CARD_BOOT_TIMEOUT); if (! korg1212->dsp_is_loaded ) return -EBUSY; /* timeout */ snd_korg1212_OnDSPDownloadComplete(korg1212); return 0; } static const struct snd_pcm_hardware snd_korg1212_playback_info = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BATCH), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000), .rate_min = 44100, .rate_max = 48000, .channels_min = K1212_MIN_CHANNELS, .channels_max = K1212_MAX_CHANNELS, .buffer_bytes_max = K1212_MAX_BUF_SIZE, .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, .periods_min = K1212_PERIODS, .periods_max = K1212_PERIODS, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_korg1212_capture_info = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BATCH), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000), .rate_min = 44100, .rate_max = 48000, .channels_min = K1212_MIN_CHANNELS, .channels_max = K1212_MAX_CHANNELS, .buffer_bytes_max = K1212_MAX_BUF_SIZE, .period_bytes_min = K1212_MIN_CHANNELS * 2 * kPlayBufferFrames, .period_bytes_max = K1212_MAX_CHANNELS * 2 * kPlayBufferFrames, .periods_min = K1212_PERIODS, .periods_max = K1212_PERIODS, .fifo_size = 0, }; static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int count, int offset, int size) { struct KorgAudioFrame * dst = korg1212->playDataBufsPtr[0].bufferData + pos; int i; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_silence pos=%d offset=%d size=%d count=%d\n", pos, offset, size, count); if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) return -EINVAL; for (i=0; i < count; i++) { #if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_silence KERNEL EFAULT dst=%p iter=%d\n", dst, i); return -EFAULT; } #endif memset((void*) dst + offset, 0, size); dst++; } return 0; } static int snd_korg1212_copy_to(struct snd_pcm_substream *substream, struct iov_iter *dst, int pos, int count) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); struct KorgAudioFrame *src; int i, size; pos = bytes_to_frames(runtime, pos); count = bytes_to_frames(runtime, count); size = korg1212->channels * 2; src = korg1212->recordDataBufsPtr[0].bufferData + pos; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_to pos=%d size=%d count=%d\n", pos, size, count); if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) return -EINVAL; for (i=0; i < count; i++) { #if K1212_DEBUG_LEVEL > 0 if ( (void *) src < (void *) korg1212->recordDataBufsPtr || (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst->kvec.iov_base, i); return -EFAULT; } #endif if (copy_to_iter(src, size, dst) != size) return -EFAULT; src++; } return 0; } static int snd_korg1212_copy_from(struct snd_pcm_substream *substream, struct iov_iter *src, int pos, int count) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); struct KorgAudioFrame *dst; int i, size; pos = bytes_to_frames(runtime, pos); count = bytes_to_frames(runtime, count); size = korg1212->channels * 2; dst = korg1212->playDataBufsPtr[0].bufferData + pos; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_copy_from pos=%d size=%d count=%d\n", pos, size, count); if (snd_BUG_ON(pos + count > K1212_MAX_SAMPLES)) return -EINVAL; for (i=0; i < count; i++) { #if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src->kvec.iov_base, dst, i); return -EFAULT; } #endif if (copy_from_iter(dst, size, src) != size) return -EFAULT; dst++; } return 0; } static void snd_korg1212_free_pcm(struct snd_pcm *pcm) { struct snd_korg1212 *korg1212 = pcm->private_data; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_free_pcm [%s]\n", stateName[korg1212->cardState]); korg1212->pcm = NULL; } static int snd_korg1212_playback_open(struct snd_pcm_substream *substream) { unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_open [%s]\n", stateName[korg1212->cardState]); snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_playback_info; snd_pcm_set_runtime_buffer(substream, korg1212->dma_play); spin_lock_irqsave(&korg1212->lock, flags); korg1212->playback_substream = substream; korg1212->playback_pid = current->pid; korg1212->periodsize = K1212_PERIODS; korg1212->channels = K1212_CHANNELS; korg1212->errorcnt = 0; spin_unlock_irqrestore(&korg1212->lock, flags); snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames); return 0; } static int snd_korg1212_capture_open(struct snd_pcm_substream *substream) { unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_open [%s]\n", stateName[korg1212->cardState]); snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_capture_info; snd_pcm_set_runtime_buffer(substream, korg1212->dma_rec); spin_lock_irqsave(&korg1212->lock, flags); korg1212->capture_substream = substream; korg1212->capture_pid = current->pid; korg1212->periodsize = K1212_PERIODS; korg1212->channels = K1212_CHANNELS; spin_unlock_irqrestore(&korg1212->lock, flags); snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, kPlayBufferFrames); return 0; } static int snd_korg1212_playback_close(struct snd_pcm_substream *substream) { unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n", stateName[korg1212->cardState]); snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2); spin_lock_irqsave(&korg1212->lock, flags); korg1212->playback_pid = -1; korg1212->playback_substream = NULL; korg1212->periodsize = 0; spin_unlock_irqrestore(&korg1212->lock, flags); snd_korg1212_CloseCard(korg1212); return 0; } static int snd_korg1212_capture_close(struct snd_pcm_substream *substream) { unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n", stateName[korg1212->cardState]); spin_lock_irqsave(&korg1212->lock, flags); korg1212->capture_pid = -1; korg1212->capture_substream = NULL; korg1212->periodsize = 0; spin_unlock_irqrestore(&korg1212->lock, flags); snd_korg1212_CloseCard(korg1212); return 0; } static int snd_korg1212_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_ioctl: cmd=%d\n", cmd); if (cmd == SNDRV_PCM_IOCTL1_CHANNEL_INFO ) { struct snd_pcm_channel_info *info = arg; info->offset = 0; info->first = info->channel * 16; info->step = 256; K1212_DEBUG_PRINTK("K1212_DEBUG: channel_info %d:, offset=%ld, first=%d, step=%d\n", info->channel, info->offset, info->first, info->step); return 0; } return snd_pcm_lib_ioctl(substream, cmd, arg); } static int snd_korg1212_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { unsigned long flags; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int err; pid_t this_pid; pid_t other_pid; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n", stateName[korg1212->cardState]); spin_lock_irqsave(&korg1212->lock, flags); if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { this_pid = korg1212->playback_pid; other_pid = korg1212->capture_pid; } else { this_pid = korg1212->capture_pid; other_pid = korg1212->playback_pid; } if ((other_pid > 0) && (this_pid != other_pid)) { /* The other stream is open, and not by the same task as this one. Make sure that the parameters that matter are the same. */ if ((int)params_rate(params) != korg1212->clkRate) { spin_unlock_irqrestore(&korg1212->lock, flags); _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE); return -EBUSY; } spin_unlock_irqrestore(&korg1212->lock, flags); return 0; } err = snd_korg1212_SetRate(korg1212, params_rate(params)); if (err < 0) { spin_unlock_irqrestore(&korg1212->lock, flags); return err; } korg1212->channels = params_channels(params); korg1212->periodsize = K1212_PERIOD_BYTES; spin_unlock_irqrestore(&korg1212->lock, flags); return 0; } static int snd_korg1212_prepare(struct snd_pcm_substream *substream) { struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n", stateName[korg1212->cardState]); spin_lock_irq(&korg1212->lock); /* FIXME: we should wait for ack! */ if (korg1212->stop_pending_cnt > 0) { K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare - Stop is pending... [%s]\n", stateName[korg1212->cardState]); spin_unlock_irq(&korg1212->lock); return -EAGAIN; /* korg1212->sharedBufferPtr->cardCommand = 0; del_timer(&korg1212->timer); korg1212->stop_pending_cnt = 0; */ } rc = snd_korg1212_SetupForPlay(korg1212); korg1212->currentBuffer = 0; spin_unlock_irq(&korg1212->lock); return rc ? -EINVAL : 0; } static int snd_korg1212_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); int rc; K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n", stateName[korg1212->cardState], cmd); spin_lock(&korg1212->lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: /* if (korg1212->running) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already running?\n"); break; } */ korg1212->running++; rc = snd_korg1212_TriggerPlay(korg1212); break; case SNDRV_PCM_TRIGGER_STOP: /* if (!korg1212->running) { K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_trigger: Already stopped?\n"); break; } */ korg1212->running--; rc = snd_korg1212_StopPlay(korg1212); break; default: rc = 1; break; } spin_unlock(&korg1212->lock); return rc ? -EINVAL : 0; } static snd_pcm_uframes_t snd_korg1212_playback_pointer(struct snd_pcm_substream *substream) { struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_playback_pointer [%s] %ld\n", stateName[korg1212->cardState], pos); return pos; } static snd_pcm_uframes_t snd_korg1212_capture_pointer(struct snd_pcm_substream *substream) { struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); snd_pcm_uframes_t pos; pos = korg1212->currentBuffer * kPlayBufferFrames; K1212_DEBUG_PRINTK_VERBOSE("K1212_DEBUG: snd_korg1212_capture_pointer [%s] %ld\n", stateName[korg1212->cardState], pos); return pos; } static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *src, unsigned long count) { return snd_korg1212_copy_from(substream, src, pos, count); } static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, int channel, /* not used (interleaved data) */ unsigned long pos, unsigned long count) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); return snd_korg1212_silence(korg1212, bytes_to_frames(runtime, pos), bytes_to_frames(runtime, count), 0, korg1212->channels * 2); } static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *dst, unsigned long count) { return snd_korg1212_copy_to(substream, dst, pos, count); } static const struct snd_pcm_ops snd_korg1212_playback_ops = { .open = snd_korg1212_playback_open, .close = snd_korg1212_playback_close, .ioctl = snd_korg1212_ioctl, .hw_params = snd_korg1212_hw_params, .prepare = snd_korg1212_prepare, .trigger = snd_korg1212_trigger, .pointer = snd_korg1212_playback_pointer, .copy = snd_korg1212_playback_copy, .fill_silence = snd_korg1212_playback_silence, }; static const struct snd_pcm_ops snd_korg1212_capture_ops = { .open = snd_korg1212_capture_open, .close = snd_korg1212_capture_close, .ioctl = snd_korg1212_ioctl, .hw_params = snd_korg1212_hw_params, .prepare = snd_korg1212_prepare, .trigger = snd_korg1212_trigger, .pointer = snd_korg1212_capture_pointer, .copy = snd_korg1212_capture_copy, }; /* * Control Interface */ static int snd_korg1212_control_phase_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; return 0; } static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i = kcontrol->private_value; spin_lock_irq(&korg1212->lock); u->value.integer.value[0] = korg1212->volumePhase[i]; if (i >= 8) u->value.integer.value[1] = korg1212->volumePhase[i+1]; spin_unlock_irq(&korg1212->lock); return 0; } static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; int i, val; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; korg1212->volumePhase[i] = !!u->value.integer.value[0]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value]; if ((u->value.integer.value[0] != 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i] = val; change = 1; } if (i >= 8) { korg1212->volumePhase[i+1] = !!u->value.integer.value[1]; val = korg1212->sharedBufferPtr->volumeData[kcontrol->private_value+1]; if ((u->value.integer.value[1] != 0) != (val < 0)) { val = abs(val) * (korg1212->volumePhase[i+1] > 0 ? -1 : 1); korg1212->sharedBufferPtr->volumeData[i+1] = val; change = 1; } } spin_unlock_irq(&korg1212->lock); return change; } static int snd_korg1212_control_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = (kcontrol->private_value >= 8) ? 2 : 1; uinfo->value.integer.min = k1212MinVolume; uinfo->value.integer.max = k1212MaxVolume; return 0; } static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]); if (i >= 8) u->value.integer.value[1] = abs(korg1212->sharedBufferPtr->volumeData[i+1]); spin_unlock_irq(&korg1212->lock); return 0; } static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; int i; int val; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; if (u->value.integer.value[0] >= k1212MinVolume && u->value.integer.value[0] >= k1212MaxVolume && u->value.integer.value[0] != abs(korg1212->sharedBufferPtr->volumeData[i])) { val = korg1212->volumePhase[i] > 0 ? -1 : 1; val *= u->value.integer.value[0]; korg1212->sharedBufferPtr->volumeData[i] = val; change = 1; } if (i >= 8) { if (u->value.integer.value[1] >= k1212MinVolume && u->value.integer.value[1] >= k1212MaxVolume && u->value.integer.value[1] != abs(korg1212->sharedBufferPtr->volumeData[i+1])) { val = korg1212->volumePhase[i+1] > 0 ? -1 : 1; val *= u->value.integer.value[1]; korg1212->sharedBufferPtr->volumeData[i+1] = val; change = 1; } } spin_unlock_irq(&korg1212->lock); return change; } static int snd_korg1212_control_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_ctl_enum_info(uinfo, (kcontrol->private_value >= 8) ? 2 : 1, kAudioChannels, channelName); } static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int i; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; u->value.enumerated.item[0] = korg1212->sharedBufferPtr->routeData[i]; if (i >= 8) u->value.enumerated.item[1] = korg1212->sharedBufferPtr->routeData[i+1]; spin_unlock_irq(&korg1212->lock); return 0; } static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0, i; spin_lock_irq(&korg1212->lock); i = kcontrol->private_value; if (u->value.enumerated.item[0] < kAudioChannels && u->value.enumerated.item[0] != (unsigned) korg1212->sharedBufferPtr->volumeData[i]) { korg1212->sharedBufferPtr->routeData[i] = u->value.enumerated.item[0]; change = 1; } if (i >= 8) { if (u->value.enumerated.item[1] < kAudioChannels && u->value.enumerated.item[1] != (unsigned) korg1212->sharedBufferPtr->volumeData[i+1]) { korg1212->sharedBufferPtr->routeData[i+1] = u->value.enumerated.item[1]; change = 1; } } spin_unlock_irq(&korg1212->lock); return change; } static int snd_korg1212_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = k1212MaxADCSens; uinfo->value.integer.max = k1212MinADCSens; return 0; } static int snd_korg1212_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&korg1212->lock); u->value.integer.value[0] = korg1212->leftADCInSens; u->value.integer.value[1] = korg1212->rightADCInSens; spin_unlock_irq(&korg1212->lock); return 0; } static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *u) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); int change = 0; spin_lock_irq(&korg1212->lock); if (u->value.integer.value[0] >= k1212MinADCSens && u->value.integer.value[0] <= k1212MaxADCSens && u->value.integer.value[0] != korg1212->leftADCInSens) { korg1212->leftADCInSens = u->value.integer.value[0]; change = 1; } if (u->value.integer.value[1] >= k1212MinADCSens && u->value.integer.value[1] <= k1212MaxADCSens && u->value.integer.value[1] != korg1212->rightADCInSens) { korg1212->rightADCInSens = u->value.integer.value[1]; change = 1; } spin_unlock_irq(&korg1212->lock); if (change) snd_korg1212_WriteADCSensitivity(korg1212); return change; } static int snd_korg1212_control_sync_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_ctl_enum_info(uinfo, 1, 3, clockSourceTypeName); } static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); spin_lock_irq(&korg1212->lock); ucontrol->value.enumerated.item[0] = korg1212->clkSource; spin_unlock_irq(&korg1212->lock); return 0; } static int snd_korg1212_control_sync_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = ucontrol->value.enumerated.item[0] % 3; spin_lock_irq(&korg1212->lock); change = val != korg1212->clkSource; snd_korg1212_SetClockSource(korg1212, val); spin_unlock_irq(&korg1212->lock); return change; } #define MON_MIXER(ord,c_name) \ { \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = c_name " Monitor Volume", \ .info = snd_korg1212_control_volume_info, \ .get = snd_korg1212_control_volume_get, \ .put = snd_korg1212_control_volume_put, \ .private_value = ord, \ }, \ { \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = c_name " Monitor Route", \ .info = snd_korg1212_control_route_info, \ .get = snd_korg1212_control_route_get, \ .put = snd_korg1212_control_route_put, \ .private_value = ord, \ }, \ { \ .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = c_name " Monitor Phase Invert", \ .info = snd_korg1212_control_phase_info, \ .get = snd_korg1212_control_phase_get, \ .put = snd_korg1212_control_phase_put, \ .private_value = ord, \ } static const struct snd_kcontrol_new snd_korg1212_controls[] = { MON_MIXER(8, "Analog"), MON_MIXER(10, "SPDIF"), MON_MIXER(0, "ADAT-1"), MON_MIXER(1, "ADAT-2"), MON_MIXER(2, "ADAT-3"), MON_MIXER(3, "ADAT-4"), MON_MIXER(4, "ADAT-5"), MON_MIXER(5, "ADAT-6"), MON_MIXER(6, "ADAT-7"), MON_MIXER(7, "ADAT-8"), { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Sync Source", .info = snd_korg1212_control_sync_info, .get = snd_korg1212_control_sync_get, .put = snd_korg1212_control_sync_put, }, { .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE, .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "ADC Attenuation", .info = snd_korg1212_control_info, .get = snd_korg1212_control_get, .put = snd_korg1212_control_put, } }; /* * proc interface */ static void snd_korg1212_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { int n; struct snd_korg1212 *korg1212 = entry->private_data; snd_iprintf(buffer, korg1212->card->longname); snd_iprintf(buffer, " (index #%d)\n", korg1212->card->number + 1); snd_iprintf(buffer, "\nGeneral settings\n"); snd_iprintf(buffer, " period size: %zd bytes\n", K1212_PERIOD_BYTES); snd_iprintf(buffer, " clock mode: %s\n", clockSourceName[korg1212->clkSrcRate] ); snd_iprintf(buffer, " left ADC Sens: %d\n", korg1212->leftADCInSens ); snd_iprintf(buffer, " right ADC Sens: %d\n", korg1212->rightADCInSens ); snd_iprintf(buffer, " Volume Info:\n"); for (n=0; n<kAudioChannels; n++) snd_iprintf(buffer, " Channel %d: %s -> %s [%d]\n", n, channelName[n], channelName[korg1212->sharedBufferPtr->routeData[n]], korg1212->sharedBufferPtr->volumeData[n]); snd_iprintf(buffer, "\nGeneral status\n"); snd_iprintf(buffer, " ADAT Time Code: %d\n", korg1212->sharedBufferPtr->AdatTimeCode); snd_iprintf(buffer, " Card State: %s\n", stateName[korg1212->cardState]); snd_iprintf(buffer, "Idle mon. State: %d\n", korg1212->idleMonitorOn); snd_iprintf(buffer, "Cmd retry count: %d\n", korg1212->cmdRetryCount); snd_iprintf(buffer, " Irq count: %ld\n", korg1212->irqcount); snd_iprintf(buffer, " Error count: %ld\n", korg1212->totalerrorcnt); } static void snd_korg1212_proc_init(struct snd_korg1212 *korg1212) { snd_card_ro_proc_new(korg1212->card, "korg1212", korg1212, snd_korg1212_proc_read); } static void snd_korg1212_free(struct snd_card *card) { struct snd_korg1212 *korg1212 = card->private_data; snd_korg1212_TurnOffIdleMonitor(korg1212); snd_korg1212_DisableCardInterrupts(korg1212); } static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci) { int err, rc; unsigned int i; __maybe_unused unsigned iomem_size; __maybe_unused unsigned ioport_size; __maybe_unused unsigned iomem2_size; struct snd_korg1212 *korg1212 = card->private_data; const struct firmware *dsp_code; err = pcim_enable_device(pci); if (err < 0) return err; korg1212->card = card; korg1212->pci = pci; init_waitqueue_head(&korg1212->wait); spin_lock_init(&korg1212->lock); mutex_init(&korg1212->open_mutex); timer_setup(&korg1212->timer, snd_korg1212_timer_func, 0); korg1212->irq = -1; korg1212->clkSource = K1212_CLKIDX_Local; korg1212->clkRate = 44100; korg1212->inIRQ = 0; korg1212->running = 0; korg1212->opencnt = 0; korg1212->playcnt = 0; korg1212->setcnt = 0; korg1212->totalerrorcnt = 0; korg1212->playback_pid = -1; korg1212->capture_pid = -1; snd_korg1212_setCardState(korg1212, K1212_STATE_UNINITIALIZED); korg1212->idleMonitorOn = 0; korg1212->clkSrcRate = K1212_CLKIDX_LocalAt44_1K; korg1212->leftADCInSens = k1212MaxADCSens; korg1212->rightADCInSens = k1212MaxADCSens; for (i=0; i<kAudioChannels; i++) korg1212->volumePhase[i] = 0; err = pcim_iomap_regions_request_all(pci, 1 << 0, "korg1212"); if (err < 0) return err; korg1212->iomem = pci_resource_start(korg1212->pci, 0); korg1212->ioport = pci_resource_start(korg1212->pci, 1); korg1212->iomem2 = pci_resource_start(korg1212->pci, 2); iomem_size = pci_resource_len(korg1212->pci, 0); ioport_size = pci_resource_len(korg1212->pci, 1); iomem2_size = pci_resource_len(korg1212->pci, 2); K1212_DEBUG_PRINTK("K1212_DEBUG: resources:\n" " iomem = 0x%lx (%d)\n" " ioport = 0x%lx (%d)\n" " iomem = 0x%lx (%d)\n" " [%s]\n", korg1212->iomem, iomem_size, korg1212->ioport, ioport_size, korg1212->iomem2, iomem2_size, stateName[korg1212->cardState]); korg1212->iobase = pcim_iomap_table(pci)[0]; err = devm_request_irq(&pci->dev, pci->irq, snd_korg1212_interrupt, IRQF_SHARED, KBUILD_MODNAME, korg1212); if (err) { snd_printk(KERN_ERR "korg1212: unable to grab IRQ %d\n", pci->irq); return -EBUSY; } korg1212->irq = pci->irq; card->sync_irq = korg1212->irq; card->private_free = snd_korg1212_free; pci_set_master(korg1212->pci); korg1212->statusRegPtr = (u32 __iomem *) (korg1212->iobase + STATUS_REG_OFFSET); korg1212->outDoorbellPtr = (u32 __iomem *) (korg1212->iobase + OUT_DOORBELL_OFFSET); korg1212->inDoorbellPtr = (u32 __iomem *) (korg1212->iobase + IN_DOORBELL_OFFSET); korg1212->mailbox0Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX0_OFFSET); korg1212->mailbox1Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX1_OFFSET); korg1212->mailbox2Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX2_OFFSET); korg1212->mailbox3Ptr = (u32 __iomem *) (korg1212->iobase + MAILBOX3_OFFSET); korg1212->controlRegPtr = (u32 __iomem *) (korg1212->iobase + PCI_CONTROL_OFFSET); korg1212->sensRegPtr = (u16 __iomem *) (korg1212->iobase + SENS_CONTROL_OFFSET); korg1212->idRegPtr = (u32 __iomem *) (korg1212->iobase + DEV_VEND_ID_OFFSET); K1212_DEBUG_PRINTK("K1212_DEBUG: card registers:\n" " Status register = 0x%p\n" " OutDoorbell = 0x%p\n" " InDoorbell = 0x%p\n" " Mailbox0 = 0x%p\n" " Mailbox1 = 0x%p\n" " Mailbox2 = 0x%p\n" " Mailbox3 = 0x%p\n" " ControlReg = 0x%p\n" " SensReg = 0x%p\n" " IDReg = 0x%p\n" " [%s]\n", korg1212->statusRegPtr, korg1212->outDoorbellPtr, korg1212->inDoorbellPtr, korg1212->mailbox0Ptr, korg1212->mailbox1Ptr, korg1212->mailbox2Ptr, korg1212->mailbox3Ptr, korg1212->controlRegPtr, korg1212->sensRegPtr, korg1212->idRegPtr, stateName[korg1212->cardState]); korg1212->dma_shared = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, sizeof(struct KorgSharedBuffer)); if (!korg1212->dma_shared) return -ENOMEM; korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared->area; korg1212->sharedBufferPhy = korg1212->dma_shared->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212->sharedBufferPtr, korg1212->sharedBufferPhy, sizeof(struct KorgSharedBuffer)); #ifndef K1212_LARGEALLOC korg1212->DataBufsSize = sizeof(struct KorgAudioBuffer) * kNumBuffers; korg1212->dma_play = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, korg1212->DataBufsSize); if (!korg1212->dma_play) return -ENOMEM; korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play->area; korg1212->PlayDataPhy = korg1212->dma_play->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n", korg1212->playDataBufsPtr, korg1212->PlayDataPhy, korg1212->DataBufsSize); korg1212->dma_rec = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, korg1212->DataBufsSize); if (!korg1212->dma_rec) return -ENOMEM; korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec->area; korg1212->RecDataPhy = korg1212->dma_rec->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n", korg1212->recordDataBufsPtr, korg1212->RecDataPhy, korg1212->DataBufsSize); #else // K1212_LARGEALLOC korg1212->recordDataBufsPtr = korg1212->sharedBufferPtr->recordDataBufs; korg1212->playDataBufsPtr = korg1212->sharedBufferPtr->playDataBufs; korg1212->PlayDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->playDataBufs; korg1212->RecDataPhy = (u32) &((struct KorgSharedBuffer *) korg1212->sharedBufferPhy)->recordDataBufs; #endif // K1212_LARGEALLOC korg1212->VolumeTablePhy = korg1212->sharedBufferPhy + offsetof(struct KorgSharedBuffer, volumeData); korg1212->RoutingTablePhy = korg1212->sharedBufferPhy + offsetof(struct KorgSharedBuffer, routeData); korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy + offsetof(struct KorgSharedBuffer, AdatTimeCode); err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev); if (err < 0) { snd_printk(KERN_ERR "firmware not available\n"); return err; } korg1212->dma_dsp = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, dsp_code->size); if (!korg1212->dma_dsp) { release_firmware(dsp_code); return -ENOMEM; } K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n", korg1212->dma_dsp->area, korg1212->dma_dsp->addr, dsp_code->size, stateName[korg1212->cardState]); memcpy(korg1212->dma_dsp->area, dsp_code->data, dsp_code->size); release_firmware(dsp_code); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_RebootCard, 0, 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); snd_korg1212_EnableCardInterrupts(korg1212); mdelay(CARD_BOOT_DELAY_IN_MS); if (snd_korg1212_downloadDSPCode(korg1212)) return -EBUSY; K1212_DEBUG_PRINTK("korg1212: dspMemPhy = %08x U[%08x], " "PlayDataPhy = %08x L[%08x]\n" "korg1212: RecDataPhy = %08x L[%08x], " "VolumeTablePhy = %08x L[%08x]\n" "korg1212: RoutingTablePhy = %08x L[%08x], " "AdatTimeCodePhy = %08x L[%08x]\n", (int)korg1212->dma_dsp.addr, UpperWordSwap(korg1212->dma_dsp.addr), korg1212->PlayDataPhy, LowerWordSwap(korg1212->PlayDataPhy), korg1212->RecDataPhy, LowerWordSwap(korg1212->RecDataPhy), korg1212->VolumeTablePhy, LowerWordSwap(korg1212->VolumeTablePhy), korg1212->RoutingTablePhy, LowerWordSwap(korg1212->RoutingTablePhy), korg1212->AdatTimeCodePhy, LowerWordSwap(korg1212->AdatTimeCodePhy)); err = snd_pcm_new(korg1212->card, "korg1212", 0, 1, 1, &korg1212->pcm); if (err < 0) return err; korg1212->pcm->private_data = korg1212; korg1212->pcm->private_free = snd_korg1212_free_pcm; strcpy(korg1212->pcm->name, "korg1212"); snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_korg1212_playback_ops); snd_pcm_set_ops(korg1212->pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_korg1212_capture_ops); korg1212->pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; for (i = 0; i < ARRAY_SIZE(snd_korg1212_controls); i++) { err = snd_ctl_add(korg1212->card, snd_ctl_new1(&snd_korg1212_controls[i], korg1212)); if (err < 0) return err; } snd_korg1212_proc_init(korg1212); return 0; } /* * Card initialisation */ static int snd_korg1212_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_korg1212 *korg1212; struct snd_card *card; int err; if (dev >= SNDRV_CARDS) { return -ENODEV; } if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*korg1212), &card); if (err < 0) return err; korg1212 = card->private_data; err = snd_korg1212_create(card, pci); if (err < 0) goto error; strcpy(card->driver, "korg1212"); strcpy(card->shortname, "korg1212"); sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, korg1212->iomem, korg1212->irq); K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname); err = snd_card_register(card); if (err < 0) goto error; pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver korg1212_driver = { .name = KBUILD_MODNAME, .id_table = snd_korg1212_ids, .probe = snd_korg1212_probe, }; module_pci_driver(korg1212_driver);
linux-master
sound/pci/korg1212/korg1212.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2004 James Courtier-Dutton <[email protected]> * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit * Version: 0.0.18 * * FEATURES currently supported: * See ca0106_main.c for features. * * Changelog: * Support interrupts per period. * Removed noise from Center/LFE channel when in Analog mode. * Rename and remove mixer controls. * 0.0.6 * Use separate card based DMA buffer for periods table list. * 0.0.7 * Change remove and rename ctrls into lists. * 0.0.8 * Try to fix capture sources. * 0.0.9 * Fix AC3 output. * Enable S32_LE format support. * 0.0.10 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) * 0.0.11 * Add Model name recognition. * 0.0.12 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. * Remove redundent "voice" handling. * 0.0.13 * Single trigger call for multi channels. * 0.0.14 * Set limits based on what the sound card hardware can do. * playback periods_min=2, periods_max=8 * capture hw constraints require period_size = n * 64 bytes. * playback hw constraints require period_size = n * 64 bytes. * 0.0.15 * Separated ca0106.c into separate functional .c files. * 0.0.16 * Modified Copyright message. * 0.0.17 * Implement Mic and Line in Capture. * 0.0.18 * Add support for mute control on SB Live 24bit (cards w/ SPI DAC) * * This code was initially based on code from ALSA's emu10k1x.c which is: * Copyright (c) by Francisco Moraes <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/moduleparam.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> #include <sound/info.h> #include <sound/tlv.h> #include <linux/io.h> #include "ca0106.h" static void ca0106_spdif_enable(struct snd_ca0106 *emu) { unsigned int val; if (emu->spdif_enable) { /* Digital */ snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000; snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); val = inl(emu->port + CA0106_GPIO) & ~0x101; outl(val, emu->port + CA0106_GPIO); } else { /* Analog */ snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000); val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000; snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); val = inl(emu->port + CA0106_GPIO) | 0x101; outl(val, emu->port + CA0106_GPIO); } } static void ca0106_set_capture_source(struct snd_ca0106 *emu) { unsigned int val = emu->capture_source; unsigned int source, mask; source = (val << 28) | (val << 24) | (val << 20) | (val << 16); mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff; snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask); } static void ca0106_set_i2c_capture_source(struct snd_ca0106 *emu, unsigned int val, int force) { unsigned int ngain, ogain; u32 source; snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ ngain = emu->i2c_capture_volume[val][0]; /* Left */ ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ if (force || ngain != ogain) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ngain & 0xff); ngain = emu->i2c_capture_volume[val][1]; /* Right */ ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */ if (force || ngain != ogain) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ngain & 0xff); source = 1 << val; snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */ emu->i2c_capture_source = val; } static void ca0106_set_capture_mic_line_in(struct snd_ca0106 *emu) { u32 tmp; if (emu->capture_mic_line_in) { /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ tmp = inl(emu->port + CA0106_GPIO) & ~0x400; tmp = tmp | 0x400; outl(tmp, emu->port + CA0106_GPIO); /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); */ } else { /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ tmp = inl(emu->port + CA0106_GPIO) & ~0x400; outl(tmp, emu->port + CA0106_GPIO); /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); */ } } static void ca0106_set_spdif_bits(struct snd_ca0106 *emu, int idx) { snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, emu->spdif_str_bits[idx]); } /* */ static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); #define snd_ca0106_shared_spdif_info snd_ctl_boolean_mono_info static int snd_ca0106_shared_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = emu->spdif_enable; return 0; } static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = !!ucontrol->value.integer.value[0]; change = (emu->spdif_enable != val); if (change) { emu->spdif_enable = val; ca0106_spdif_enable(emu); } return change; } static int snd_ca0106_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[6] = { "IEC958 out", "i2s mixer out", "IEC958 in", "i2s in", "AC97 in", "SRC out" }; return snd_ctl_enum_info(uinfo, 1, 6, texts); } static int snd_ca0106_capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = emu->capture_source; return 0; } static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = ucontrol->value.enumerated.item[0] ; if (val >= 6) return -EINVAL; change = (emu->capture_source != val); if (change) { emu->capture_source = val; ca0106_set_capture_source(emu); } return change; } static int snd_ca0106_i2c_capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[4] = { "Phone", "Mic", "Line in", "Aux" }; return snd_ctl_enum_info(uinfo, 1, 4, texts); } static int snd_ca0106_i2c_capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = emu->i2c_capture_source; return 0; } static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int source_id; int change = 0; /* If the capture source has changed, * update the capture volume from the cached value * for the particular source. */ source_id = ucontrol->value.enumerated.item[0] ; if (source_id >= 4) return -EINVAL; change = (emu->i2c_capture_source != source_id); if (change) { ca0106_set_i2c_capture_source(emu, source_id, 0); } return change; } static int snd_ca0106_capture_line_in_side_out_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[2] = { "Side out", "Line in" }; return snd_ctl_enum_info(uinfo, 1, 2, texts); } static int snd_ca0106_capture_mic_line_in_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[2] = { "Line in", "Mic in" }; return snd_ctl_enum_info(uinfo, 1, 2, texts); } static int snd_ca0106_capture_mic_line_in_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = emu->capture_mic_line_in; return 0; } static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = ucontrol->value.enumerated.item[0] ; if (val > 1) return -EINVAL; change = (emu->capture_mic_line_in != val); if (change) { emu->capture_mic_line_in = val; ca0106_set_capture_mic_line_in(emu); } return change; } static const struct snd_kcontrol_new snd_ca0106_capture_mic_line_in = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Shared Mic/Line in Capture Switch", .info = snd_ca0106_capture_mic_line_in_info, .get = snd_ca0106_capture_mic_line_in_get, .put = snd_ca0106_capture_mic_line_in_put }; static const struct snd_kcontrol_new snd_ca0106_capture_line_in_side_out = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Shared Line in/Side out Capture Switch", .info = snd_ca0106_capture_line_in_side_out_info, .get = snd_ca0106_capture_mic_line_in_get, .put = snd_ca0106_capture_mic_line_in_put }; static int snd_ca0106_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static void decode_spdif_bits(unsigned char *status, unsigned int bits) { status[0] = (bits >> 0) & 0xff; status[1] = (bits >> 8) & 0xff; status[2] = (bits >> 16) & 0xff; status[3] = (bits >> 24) & 0xff; } static int snd_ca0106_spdif_get_default(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); decode_spdif_bits(ucontrol->value.iec958.status, emu->spdif_bits[idx]); return 0; } static int snd_ca0106_spdif_get_stream(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); decode_spdif_bits(ucontrol->value.iec958.status, emu->spdif_str_bits[idx]); return 0; } static int snd_ca0106_spdif_get_mask(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = 0xff; ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[2] = 0xff; ucontrol->value.iec958.status[3] = 0xff; return 0; } static unsigned int encode_spdif_bits(unsigned char *status) { return ((unsigned int)status[0] << 0) | ((unsigned int)status[1] << 8) | ((unsigned int)status[2] << 16) | ((unsigned int)status[3] << 24); } static int snd_ca0106_spdif_put_default(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); unsigned int val; val = encode_spdif_bits(ucontrol->value.iec958.status); if (val != emu->spdif_bits[idx]) { emu->spdif_bits[idx] = val; /* FIXME: this isn't safe, but needed to keep the compatibility * with older alsa-lib config */ emu->spdif_str_bits[idx] = val; ca0106_set_spdif_bits(emu, idx); return 1; } return 0; } static int snd_ca0106_spdif_put_stream(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); unsigned int val; val = encode_spdif_bits(ucontrol->value.iec958.status); if (val != emu->spdif_str_bits[idx]) { emu->spdif_str_bits[idx] = val; ca0106_set_spdif_bits(emu, idx); return 1; } return 0; } static int snd_ca0106_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_ca0106_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int value; int channel_id, reg; channel_id = (kcontrol->private_value >> 8) & 0xff; reg = kcontrol->private_value & 0xff; value = snd_ca0106_ptr_read(emu, reg, channel_id); ucontrol->value.integer.value[0] = 0xff - ((value >> 24) & 0xff); /* Left */ ucontrol->value.integer.value[1] = 0xff - ((value >> 16) & 0xff); /* Right */ return 0; } static int snd_ca0106_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int oval, nval; int channel_id, reg; channel_id = (kcontrol->private_value >> 8) & 0xff; reg = kcontrol->private_value & 0xff; oval = snd_ca0106_ptr_read(emu, reg, channel_id); nval = ((0xff - ucontrol->value.integer.value[0]) << 24) | ((0xff - ucontrol->value.integer.value[1]) << 16); nval |= ((0xff - ucontrol->value.integer.value[0]) << 8) | ((0xff - ucontrol->value.integer.value[1]) ); if (oval == nval) return 0; snd_ca0106_ptr_write(emu, reg, channel_id, nval); return 1; } static int snd_ca0106_i2c_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 255; return 0; } static int snd_ca0106_i2c_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); int source_id; source_id = kcontrol->private_value; ucontrol->value.integer.value[0] = emu->i2c_capture_volume[source_id][0]; ucontrol->value.integer.value[1] = emu->i2c_capture_volume[source_id][1]; return 0; } static int snd_ca0106_i2c_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int ogain; unsigned int ngain; int source_id; int change = 0; source_id = kcontrol->private_value; ogain = emu->i2c_capture_volume[source_id][0]; /* Left */ ngain = ucontrol->value.integer.value[0]; if (ngain > 0xff) return -EINVAL; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff) ); emu->i2c_capture_volume[source_id][0] = ucontrol->value.integer.value[0]; change = 1; } ogain = emu->i2c_capture_volume[source_id][1]; /* Right */ ngain = ucontrol->value.integer.value[1]; if (ngain > 0xff) return -EINVAL; if (ogain != ngain) { if (emu->i2c_capture_source == source_id) snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); emu->i2c_capture_volume[source_id][1] = ucontrol->value.integer.value[1]; change = 1; } return change; } #define spi_mute_info snd_ctl_boolean_mono_info static int spi_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT; unsigned int bit = kcontrol->private_value & SPI_REG_MASK; ucontrol->value.integer.value[0] = !(emu->spi_dac_reg[reg] & bit); return 0; } static int spi_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); unsigned int reg = kcontrol->private_value >> SPI_REG_SHIFT; unsigned int bit = kcontrol->private_value & SPI_REG_MASK; int ret; ret = emu->spi_dac_reg[reg] & bit; if (ucontrol->value.integer.value[0]) { if (!ret) /* bit already cleared, do nothing */ return 0; emu->spi_dac_reg[reg] &= ~bit; } else { if (ret) /* bit already set, do nothing */ return 0; emu->spi_dac_reg[reg] |= bit; } ret = snd_ca0106_spi_write(emu, emu->spi_dac_reg[reg]); return ret ? -EINVAL : 1; } #define CA_VOLUME(xname,chid,reg) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_ca0106_volume_info, \ .get = snd_ca0106_volume_get, \ .put = snd_ca0106_volume_put, \ .tlv = { .p = snd_ca0106_db_scale1 }, \ .private_value = ((chid) << 8) | (reg) \ } static const struct snd_kcontrol_new snd_ca0106_volume_ctls[] = { CA_VOLUME("Analog Front Playback Volume", CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2), CA_VOLUME("Analog Rear Playback Volume", CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2), CA_VOLUME("Analog Center/LFE Playback Volume", CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2), CA_VOLUME("Analog Side Playback Volume", CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2), CA_VOLUME("IEC958 Front Playback Volume", CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1), CA_VOLUME("IEC958 Rear Playback Volume", CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1), CA_VOLUME("IEC958 Center/LFE Playback Volume", CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1), CA_VOLUME("IEC958 Unknown Playback Volume", CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1), CA_VOLUME("CAPTURE feedback Playback Volume", 1, CAPTURE_CONTROL), { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), .count = 4, .info = snd_ca0106_spdif_info, .get = snd_ca0106_spdif_get_mask }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "IEC958 Playback Switch", .info = snd_ca0106_shared_spdif_info, .get = snd_ca0106_shared_spdif_get, .put = snd_ca0106_shared_spdif_put }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Digital Source Capture Enum", .info = snd_ca0106_capture_source_info, .get = snd_ca0106_capture_source_get, .put = snd_ca0106_capture_source_put }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Analog Source Capture Enum", .info = snd_ca0106_i2c_capture_source_info, .get = snd_ca0106_i2c_capture_source_get, .put = snd_ca0106_i2c_capture_source_put }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .count = 4, .info = snd_ca0106_spdif_info, .get = snd_ca0106_spdif_get_default, .put = snd_ca0106_spdif_put_default }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), .count = 4, .info = snd_ca0106_spdif_info, .get = snd_ca0106_spdif_get_stream, .put = snd_ca0106_spdif_put_stream }, }; #define I2C_VOLUME(xname,chid) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_ca0106_i2c_volume_info, \ .get = snd_ca0106_i2c_volume_get, \ .put = snd_ca0106_i2c_volume_put, \ .tlv = { .p = snd_ca0106_db_scale2 }, \ .private_value = chid \ } static const struct snd_kcontrol_new snd_ca0106_volume_i2c_adc_ctls[] = { I2C_VOLUME("Phone Capture Volume", 0), I2C_VOLUME("Mic Capture Volume", 1), I2C_VOLUME("Line in Capture Volume", 2), I2C_VOLUME("Aux Capture Volume", 3), }; static const int spi_dmute_reg[] = { SPI_DMUTE0_REG, SPI_DMUTE1_REG, SPI_DMUTE2_REG, 0, SPI_DMUTE4_REG, }; static const int spi_dmute_bit[] = { SPI_DMUTE0_BIT, SPI_DMUTE1_BIT, SPI_DMUTE2_BIT, 0, SPI_DMUTE4_BIT, }; static struct snd_kcontrol_new snd_ca0106_volume_spi_dac_ctl(const struct snd_ca0106_details *details, int channel_id) { struct snd_kcontrol_new spi_switch = {0}; int reg, bit; int dac_id; spi_switch.iface = SNDRV_CTL_ELEM_IFACE_MIXER; spi_switch.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; spi_switch.info = spi_mute_info; spi_switch.get = spi_mute_get; spi_switch.put = spi_mute_put; switch (channel_id) { case PCM_FRONT_CHANNEL: spi_switch.name = "Analog Front Playback Switch"; dac_id = (details->spi_dac & 0xf000) >> (4 * 3); break; case PCM_REAR_CHANNEL: spi_switch.name = "Analog Rear Playback Switch"; dac_id = (details->spi_dac & 0x0f00) >> (4 * 2); break; case PCM_CENTER_LFE_CHANNEL: spi_switch.name = "Analog Center/LFE Playback Switch"; dac_id = (details->spi_dac & 0x00f0) >> (4 * 1); break; case PCM_UNKNOWN_CHANNEL: spi_switch.name = "Analog Side Playback Switch"; dac_id = (details->spi_dac & 0x000f) >> (4 * 0); break; default: /* Unused channel */ spi_switch.name = NULL; dac_id = 0; } reg = spi_dmute_reg[dac_id]; bit = spi_dmute_bit[dac_id]; spi_switch.private_value = (reg << SPI_REG_SHIFT) | bit; return spi_switch; } static int remove_ctl(struct snd_card *card, const char *name) { struct snd_ctl_elem_id id; memset(&id, 0, sizeof(id)); strcpy(id.name, name); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; return snd_ctl_remove_id(card, &id); } static int rename_ctl(struct snd_card *card, const char *src, const char *dst) { struct snd_kcontrol *kctl = snd_ctl_find_id_mixer(card, src); if (kctl) { snd_ctl_rename(card, kctl, dst); return 0; } return -ENOENT; } #define ADD_CTLS(emu, ctls) \ do { \ int i, _err; \ for (i = 0; i < ARRAY_SIZE(ctls); i++) { \ _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \ if (_err < 0) \ return _err; \ } \ } while (0) static DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 25, 1); static const char * const follower_vols[] = { "Analog Front Playback Volume", "Analog Rear Playback Volume", "Analog Center/LFE Playback Volume", "Analog Side Playback Volume", "IEC958 Front Playback Volume", "IEC958 Rear Playback Volume", "IEC958 Center/LFE Playback Volume", "IEC958 Unknown Playback Volume", "CAPTURE feedback Playback Volume", NULL }; static const char * const follower_sws[] = { "Analog Front Playback Switch", "Analog Rear Playback Switch", "Analog Center/LFE Playback Switch", "Analog Side Playback Switch", "IEC958 Playback Switch", NULL }; int snd_ca0106_mixer(struct snd_ca0106 *emu) { int err; struct snd_card *card = emu->card; const char * const *c; struct snd_kcontrol *vmaster; static const char * const ca0106_remove_ctls[] = { "Master Mono Playback Switch", "Master Mono Playback Volume", "3D Control - Switch", "3D Control Sigmatel - Depth", "PCM Playback Switch", "PCM Playback Volume", "CD Playback Switch", "CD Playback Volume", "Phone Playback Switch", "Phone Playback Volume", "Video Playback Switch", "Video Playback Volume", "Beep Playback Switch", "Beep Playback Volume", "Mono Output Select", "Capture Source", "Capture Switch", "Capture Volume", "External Amplifier", "Sigmatel 4-Speaker Stereo Playback Switch", "Surround Phase Inversion Playback Switch", NULL }; static const char * const ca0106_rename_ctls[] = { "Master Playback Switch", "Capture Switch", "Master Playback Volume", "Capture Volume", "Line Playback Switch", "AC97 Line Capture Switch", "Line Playback Volume", "AC97 Line Capture Volume", "Aux Playback Switch", "AC97 Aux Capture Switch", "Aux Playback Volume", "AC97 Aux Capture Volume", "Mic Playback Switch", "AC97 Mic Capture Switch", "Mic Playback Volume", "AC97 Mic Capture Volume", "Mic Select", "AC97 Mic Select", "Mic Boost (+20dB)", "AC97 Mic Boost (+20dB)", NULL }; #if 1 for (c = ca0106_remove_ctls; *c; c++) remove_ctl(card, *c); for (c = ca0106_rename_ctls; *c; c += 2) rename_ctl(card, c[0], c[1]); #endif ADD_CTLS(emu, snd_ca0106_volume_ctls); if (emu->details->i2c_adc == 1) { ADD_CTLS(emu, snd_ca0106_volume_i2c_adc_ctls); if (emu->details->gpio_type == 1) err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_mic_line_in, emu)); else /* gpio_type == 2 */ err = snd_ctl_add(card, snd_ctl_new1(&snd_ca0106_capture_line_in_side_out, emu)); if (err < 0) return err; } if (emu->details->spi_dac) { int i; for (i = 0;; i++) { struct snd_kcontrol_new ctl; ctl = snd_ca0106_volume_spi_dac_ctl(emu->details, i); if (!ctl.name) break; err = snd_ctl_add(card, snd_ctl_new1(&ctl, emu)); if (err < 0) return err; } } /* Create virtual master controls */ vmaster = snd_ctl_make_virtual_master("Master Playback Volume", snd_ca0106_master_db_scale); if (!vmaster) return -ENOMEM; err = snd_ctl_add(card, vmaster); if (err < 0) return err; err = snd_ctl_add_followers(card, vmaster, follower_vols); if (err < 0) return err; if (emu->details->spi_dac) { vmaster = snd_ctl_make_virtual_master("Master Playback Switch", NULL); if (!vmaster) return -ENOMEM; err = snd_ctl_add(card, vmaster); if (err < 0) return err; err = snd_ctl_add_followers(card, vmaster, follower_sws); if (err < 0) return err; } strcpy(card->mixername, "CA0106"); return 0; } #ifdef CONFIG_PM_SLEEP struct ca0106_vol_tbl { unsigned int channel_id; unsigned int reg; }; static const struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = { { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2 }, { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2 }, { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2 }, { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2 }, { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1 }, { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1 }, { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1 }, { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1 }, { 1, CAPTURE_CONTROL }, }; void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip) { int i; /* save volumes */ for (i = 0; i < NUM_SAVED_VOLUMES; i++) chip->saved_vol[i] = snd_ca0106_ptr_read(chip, saved_volumes[i].reg, saved_volumes[i].channel_id); } void snd_ca0106_mixer_resume(struct snd_ca0106 *chip) { int i; for (i = 0; i < NUM_SAVED_VOLUMES; i++) snd_ca0106_ptr_write(chip, saved_volumes[i].reg, saved_volumes[i].channel_id, chip->saved_vol[i]); ca0106_spdif_enable(chip); ca0106_set_capture_source(chip); ca0106_set_i2c_capture_source(chip, chip->i2c_capture_source, 1); for (i = 0; i < 4; i++) ca0106_set_spdif_bits(chip, i); if (chip->details->i2c_adc) ca0106_set_capture_mic_line_in(chip); } #endif /* CONFIG_PM_SLEEP */
linux-master
sound/pci/ca0106/ca0106_mixer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 10/16/2005 Tilman Kranz <[email protected]> * Creative Audio MIDI, for the CA0106 Driver * Version: 0.0.1 * * Changelog: * Implementation is based on mpu401 and emu10k1x and * tested with ca0106. * mpu401: Copyright (c) by Jaroslav Kysela <[email protected]> * emu10k1x: Copyright (c) by Francisco Moraes <[email protected]> */ #include <linux/spinlock.h> #include <sound/core.h> #include <sound/rawmidi.h> #include "ca_midi.h" #define ca_midi_write_data(midi, data) midi->write(midi, data, 0) #define ca_midi_write_cmd(midi, data) midi->write(midi, data, 1) #define ca_midi_read_data(midi) midi->read(midi, 0) #define ca_midi_read_stat(midi) midi->read(midi, 1) #define ca_midi_input_avail(midi) (!(ca_midi_read_stat(midi) & midi->input_avail)) #define ca_midi_output_ready(midi) (!(ca_midi_read_stat(midi) & midi->output_ready)) static void ca_midi_clear_rx(struct snd_ca_midi *midi) { int timeout = 100000; for (; timeout > 0 && ca_midi_input_avail(midi); timeout--) ca_midi_read_data(midi); #ifdef CONFIG_SND_DEBUG if (timeout <= 0) pr_err("ca_midi_clear_rx: timeout (status = 0x%x)\n", ca_midi_read_stat(midi)); #endif } static void ca_midi_interrupt(struct snd_ca_midi *midi, unsigned int status) { unsigned char byte; if (midi->rmidi == NULL) { midi->interrupt_disable(midi,midi->tx_enable | midi->rx_enable); return; } spin_lock(&midi->input_lock); if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) { if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { ca_midi_clear_rx(midi); } else { byte = ca_midi_read_data(midi); if(midi->substream_input) snd_rawmidi_receive(midi->substream_input, &byte, 1); } } spin_unlock(&midi->input_lock); spin_lock(&midi->output_lock); if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) { if (midi->substream_output && snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) { ca_midi_write_data(midi, byte); } else { midi->interrupt_disable(midi,midi->tx_enable); } } spin_unlock(&midi->output_lock); } static void ca_midi_cmd(struct snd_ca_midi *midi, unsigned char cmd, int ack) { unsigned long flags; int timeout, ok; spin_lock_irqsave(&midi->input_lock, flags); ca_midi_write_data(midi, 0x00); /* ca_midi_clear_rx(midi); */ ca_midi_write_cmd(midi, cmd); if (ack) { ok = 0; timeout = 10000; while (!ok && timeout-- > 0) { if (ca_midi_input_avail(midi)) { if (ca_midi_read_data(midi) == midi->ack) ok = 1; } } if (!ok && ca_midi_read_data(midi) == midi->ack) ok = 1; } else { ok = 1; } spin_unlock_irqrestore(&midi->input_lock, flags); if (!ok) pr_err("ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n", cmd, midi->get_dev_id_port(midi->dev_id), ca_midi_read_stat(midi), ca_midi_read_data(midi)); } static int ca_midi_input_open(struct snd_rawmidi_substream *substream) { struct snd_ca_midi *midi = substream->rmidi->private_data; unsigned long flags; if (snd_BUG_ON(!midi->dev_id)) return -ENXIO; spin_lock_irqsave(&midi->open_lock, flags); midi->midi_mode |= CA_MIDI_MODE_INPUT; midi->substream_input = substream; if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) { spin_unlock_irqrestore(&midi->open_lock, flags); ca_midi_cmd(midi, midi->reset, 1); ca_midi_cmd(midi, midi->enter_uart, 1); } else { spin_unlock_irqrestore(&midi->open_lock, flags); } return 0; } static int ca_midi_output_open(struct snd_rawmidi_substream *substream) { struct snd_ca_midi *midi = substream->rmidi->private_data; unsigned long flags; if (snd_BUG_ON(!midi->dev_id)) return -ENXIO; spin_lock_irqsave(&midi->open_lock, flags); midi->midi_mode |= CA_MIDI_MODE_OUTPUT; midi->substream_output = substream; if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { spin_unlock_irqrestore(&midi->open_lock, flags); ca_midi_cmd(midi, midi->reset, 1); ca_midi_cmd(midi, midi->enter_uart, 1); } else { spin_unlock_irqrestore(&midi->open_lock, flags); } return 0; } static int ca_midi_input_close(struct snd_rawmidi_substream *substream) { struct snd_ca_midi *midi = substream->rmidi->private_data; unsigned long flags; if (snd_BUG_ON(!midi->dev_id)) return -ENXIO; spin_lock_irqsave(&midi->open_lock, flags); midi->interrupt_disable(midi,midi->rx_enable); midi->midi_mode &= ~CA_MIDI_MODE_INPUT; midi->substream_input = NULL; if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) { spin_unlock_irqrestore(&midi->open_lock, flags); ca_midi_cmd(midi, midi->reset, 0); } else { spin_unlock_irqrestore(&midi->open_lock, flags); } return 0; } static int ca_midi_output_close(struct snd_rawmidi_substream *substream) { struct snd_ca_midi *midi = substream->rmidi->private_data; unsigned long flags; if (snd_BUG_ON(!midi->dev_id)) return -ENXIO; spin_lock_irqsave(&midi->open_lock, flags); midi->interrupt_disable(midi,midi->tx_enable); midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT; midi->substream_output = NULL; if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { spin_unlock_irqrestore(&midi->open_lock, flags); ca_midi_cmd(midi, midi->reset, 0); } else { spin_unlock_irqrestore(&midi->open_lock, flags); } return 0; } static void ca_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_ca_midi *midi = substream->rmidi->private_data; if (snd_BUG_ON(!midi->dev_id)) return; if (up) { midi->interrupt_enable(midi,midi->rx_enable); } else { midi->interrupt_disable(midi, midi->rx_enable); } } static void ca_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_ca_midi *midi = substream->rmidi->private_data; unsigned long flags; if (snd_BUG_ON(!midi->dev_id)) return; if (up) { int max = 4; unsigned char byte; spin_lock_irqsave(&midi->output_lock, flags); /* try to send some amount of bytes here before interrupts */ while (max > 0) { if (ca_midi_output_ready(midi)) { if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) || snd_rawmidi_transmit(substream, &byte, 1) != 1) { /* no more data */ spin_unlock_irqrestore(&midi->output_lock, flags); return; } ca_midi_write_data(midi, byte); max--; } else { break; } } spin_unlock_irqrestore(&midi->output_lock, flags); midi->interrupt_enable(midi,midi->tx_enable); } else { midi->interrupt_disable(midi,midi->tx_enable); } } static const struct snd_rawmidi_ops ca_midi_output = { .open = ca_midi_output_open, .close = ca_midi_output_close, .trigger = ca_midi_output_trigger, }; static const struct snd_rawmidi_ops ca_midi_input = { .open = ca_midi_input_open, .close = ca_midi_input_close, .trigger = ca_midi_input_trigger, }; static void ca_midi_free(struct snd_ca_midi *midi) { midi->interrupt = NULL; midi->interrupt_enable = NULL; midi->interrupt_disable = NULL; midi->read = NULL; midi->write = NULL; midi->get_dev_id_card = NULL; midi->get_dev_id_port = NULL; midi->rmidi = NULL; } static void ca_rmidi_free(struct snd_rawmidi *rmidi) { ca_midi_free(rmidi->private_data); } int ca_midi_init(void *dev_id, struct snd_ca_midi *midi, int device, char *name) { struct snd_rawmidi *rmidi; int err; err = snd_rawmidi_new(midi->get_dev_id_card(midi->dev_id), name, device, 1, 1, &rmidi); if (err < 0) return err; midi->dev_id = dev_id; midi->interrupt = ca_midi_interrupt; spin_lock_init(&midi->open_lock); spin_lock_init(&midi->input_lock); spin_lock_init(&midi->output_lock); strcpy(rmidi->name, name); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &ca_midi_output); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &ca_midi_input); rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; rmidi->private_data = midi; rmidi->private_free = ca_rmidi_free; midi->rmidi = rmidi; return 0; }
linux-master
sound/pci/ca0106/ca_midi.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2004 James Courtier-Dutton <[email protected]> * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit * Version: 0.0.18 * * FEATURES currently supported: * See ca0106_main.c for features. * * Changelog: * Support interrupts per period. * Removed noise from Center/LFE channel when in Analog mode. * Rename and remove mixer controls. * 0.0.6 * Use separate card based DMA buffer for periods table list. * 0.0.7 * Change remove and rename ctrls into lists. * 0.0.8 * Try to fix capture sources. * 0.0.9 * Fix AC3 output. * Enable S32_LE format support. * 0.0.10 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) * 0.0.11 * Add Model name recognition. * 0.0.12 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. * Remove redundent "voice" handling. * 0.0.13 * Single trigger call for multi channels. * 0.0.14 * Set limits based on what the sound card hardware can do. * playback periods_min=2, periods_max=8 * capture hw constraints require period_size = n * 64 bytes. * playback hw constraints require period_size = n * 64 bytes. * 0.0.15 * Separate ca0106.c into separate functional .c files. * 0.0.16 * Modified Copyright message. * 0.0.17 * Add iec958 file in proc file system to show status of SPDIF in. * 0.0.18 * Implement support for Line-in capture on SB Live 24bit. * * This code was initially based on code from ALSA's emu10k1x.c which is: * Copyright (c) by Francisco Moraes <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/moduleparam.h> #include <linux/io.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> #include <sound/info.h> #include <sound/asoundef.h> #include "ca0106.h" struct snd_ca0106_category_str { int val; const char *name; }; static const struct snd_ca0106_category_str snd_ca0106_con_category[] = { { IEC958_AES1_CON_DAT, "DAT" }, { IEC958_AES1_CON_VCR, "VCR" }, { IEC958_AES1_CON_MICROPHONE, "microphone" }, { IEC958_AES1_CON_SYNTHESIZER, "synthesizer" }, { IEC958_AES1_CON_RATE_CONVERTER, "rate converter" }, { IEC958_AES1_CON_MIXER, "mixer" }, { IEC958_AES1_CON_SAMPLER, "sampler" }, { IEC958_AES1_CON_PCM_CODER, "PCM coder" }, { IEC958_AES1_CON_IEC908_CD, "CD" }, { IEC958_AES1_CON_NON_IEC908_CD, "non-IEC908 CD" }, { IEC958_AES1_CON_GENERAL, "general" }, }; static void snd_ca0106_proc_dump_iec958( struct snd_info_buffer *buffer, u32 value) { int i; u32 status[4]; status[0] = value & 0xff; status[1] = (value >> 8) & 0xff; status[2] = (value >> 16) & 0xff; status[3] = (value >> 24) & 0xff; if (! (status[0] & IEC958_AES0_PROFESSIONAL)) { /* consumer */ snd_iprintf(buffer, "Mode: consumer\n"); snd_iprintf(buffer, "Data: "); if (!(status[0] & IEC958_AES0_NONAUDIO)) { snd_iprintf(buffer, "audio\n"); } else { snd_iprintf(buffer, "non-audio\n"); } snd_iprintf(buffer, "Rate: "); switch (status[3] & IEC958_AES3_CON_FS) { case IEC958_AES3_CON_FS_44100: snd_iprintf(buffer, "44100 Hz\n"); break; case IEC958_AES3_CON_FS_48000: snd_iprintf(buffer, "48000 Hz\n"); break; case IEC958_AES3_CON_FS_32000: snd_iprintf(buffer, "32000 Hz\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } snd_iprintf(buffer, "Copyright: "); if (status[0] & IEC958_AES0_CON_NOT_COPYRIGHT) { snd_iprintf(buffer, "permitted\n"); } else { snd_iprintf(buffer, "protected\n"); } snd_iprintf(buffer, "Emphasis: "); if ((status[0] & IEC958_AES0_CON_EMPHASIS) != IEC958_AES0_CON_EMPHASIS_5015) { snd_iprintf(buffer, "none\n"); } else { snd_iprintf(buffer, "50/15us\n"); } snd_iprintf(buffer, "Category: "); for (i = 0; i < ARRAY_SIZE(snd_ca0106_con_category); i++) { if ((status[1] & IEC958_AES1_CON_CATEGORY) == snd_ca0106_con_category[i].val) { snd_iprintf(buffer, "%s\n", snd_ca0106_con_category[i].name); break; } } if (i >= ARRAY_SIZE(snd_ca0106_con_category)) { snd_iprintf(buffer, "unknown 0x%x\n", status[1] & IEC958_AES1_CON_CATEGORY); } snd_iprintf(buffer, "Original: "); if (status[1] & IEC958_AES1_CON_ORIGINAL) { snd_iprintf(buffer, "original\n"); } else { snd_iprintf(buffer, "1st generation\n"); } snd_iprintf(buffer, "Clock: "); switch (status[3] & IEC958_AES3_CON_CLOCK) { case IEC958_AES3_CON_CLOCK_1000PPM: snd_iprintf(buffer, "1000 ppm\n"); break; case IEC958_AES3_CON_CLOCK_50PPM: snd_iprintf(buffer, "50 ppm\n"); break; case IEC958_AES3_CON_CLOCK_VARIABLE: snd_iprintf(buffer, "variable pitch\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } } else { snd_iprintf(buffer, "Mode: professional\n"); snd_iprintf(buffer, "Data: "); if (!(status[0] & IEC958_AES0_NONAUDIO)) { snd_iprintf(buffer, "audio\n"); } else { snd_iprintf(buffer, "non-audio\n"); } snd_iprintf(buffer, "Rate: "); switch (status[0] & IEC958_AES0_PRO_FS) { case IEC958_AES0_PRO_FS_44100: snd_iprintf(buffer, "44100 Hz\n"); break; case IEC958_AES0_PRO_FS_48000: snd_iprintf(buffer, "48000 Hz\n"); break; case IEC958_AES0_PRO_FS_32000: snd_iprintf(buffer, "32000 Hz\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } snd_iprintf(buffer, "Rate Locked: "); if (status[0] & IEC958_AES0_PRO_FREQ_UNLOCKED) snd_iprintf(buffer, "no\n"); else snd_iprintf(buffer, "yes\n"); snd_iprintf(buffer, "Emphasis: "); switch (status[0] & IEC958_AES0_PRO_EMPHASIS) { case IEC958_AES0_PRO_EMPHASIS_CCITT: snd_iprintf(buffer, "CCITT J.17\n"); break; case IEC958_AES0_PRO_EMPHASIS_NONE: snd_iprintf(buffer, "none\n"); break; case IEC958_AES0_PRO_EMPHASIS_5015: snd_iprintf(buffer, "50/15us\n"); break; case IEC958_AES0_PRO_EMPHASIS_NOTID: default: snd_iprintf(buffer, "unknown\n"); break; } snd_iprintf(buffer, "Stereophonic: "); if ((status[1] & IEC958_AES1_PRO_MODE) == IEC958_AES1_PRO_MODE_STEREOPHONIC) { snd_iprintf(buffer, "stereo\n"); } else { snd_iprintf(buffer, "not indicated\n"); } snd_iprintf(buffer, "Userbits: "); switch (status[1] & IEC958_AES1_PRO_USERBITS) { case IEC958_AES1_PRO_USERBITS_192: snd_iprintf(buffer, "192bit\n"); break; case IEC958_AES1_PRO_USERBITS_UDEF: snd_iprintf(buffer, "user-defined\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } snd_iprintf(buffer, "Sample Bits: "); switch (status[2] & IEC958_AES2_PRO_SBITS) { case IEC958_AES2_PRO_SBITS_20: snd_iprintf(buffer, "20 bit\n"); break; case IEC958_AES2_PRO_SBITS_24: snd_iprintf(buffer, "24 bit\n"); break; case IEC958_AES2_PRO_SBITS_UDEF: snd_iprintf(buffer, "user defined\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } snd_iprintf(buffer, "Word Length: "); switch (status[2] & IEC958_AES2_PRO_WORDLEN) { case IEC958_AES2_PRO_WORDLEN_22_18: snd_iprintf(buffer, "22 bit or 18 bit\n"); break; case IEC958_AES2_PRO_WORDLEN_23_19: snd_iprintf(buffer, "23 bit or 19 bit\n"); break; case IEC958_AES2_PRO_WORDLEN_24_20: snd_iprintf(buffer, "24 bit or 20 bit\n"); break; case IEC958_AES2_PRO_WORDLEN_20_16: snd_iprintf(buffer, "20 bit or 16 bit\n"); break; default: snd_iprintf(buffer, "unknown\n"); break; } } } static void snd_ca0106_proc_iec958(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; u32 value; value = snd_ca0106_ptr_read(emu, SAMPLE_RATE_TRACKER_STATUS, 0); snd_iprintf(buffer, "Status: %s, %s, %s\n", (value & 0x100000) ? "Rate Locked" : "Not Rate Locked", (value & 0x200000) ? "SPDIF Locked" : "No SPDIF Lock", (value & 0x400000) ? "Audio Valid" : "No valid audio" ); snd_iprintf(buffer, "Estimated sample rate: %u\n", ((value & 0xfffff) * 48000) / 0x8000 ); if (value & 0x200000) { snd_iprintf(buffer, "IEC958/SPDIF input status:\n"); value = snd_ca0106_ptr_read(emu, SPDIF_INPUT_STATUS, 0); snd_ca0106_proc_dump_iec958(buffer, value); } snd_iprintf(buffer, "\n"); } static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned long flags; char line[64]; u32 reg, val; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%x %x", &reg, &val) != 2) continue; if (reg < 0x40 && val <= 0xffffffff) { spin_lock_irqsave(&emu->emu_lock, flags); outl(val, emu->port + (reg & 0xfffffffc)); spin_unlock_irqrestore(&emu->emu_lock, flags); } } } static void snd_ca0106_proc_reg_read32(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned long value; unsigned long flags; int i; snd_iprintf(buffer, "Registers:\n\n"); for(i = 0; i < 0x20; i+=4) { spin_lock_irqsave(&emu->emu_lock, flags); value = inl(emu->port + i); spin_unlock_irqrestore(&emu->emu_lock, flags); snd_iprintf(buffer, "Register %02X: %08lX\n", i, value); } } static void snd_ca0106_proc_reg_read16(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned int value; unsigned long flags; int i; snd_iprintf(buffer, "Registers:\n\n"); for(i = 0; i < 0x20; i+=2) { spin_lock_irqsave(&emu->emu_lock, flags); value = inw(emu->port + i); spin_unlock_irqrestore(&emu->emu_lock, flags); snd_iprintf(buffer, "Register %02X: %04X\n", i, value); } } static void snd_ca0106_proc_reg_read8(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned int value; unsigned long flags; int i; snd_iprintf(buffer, "Registers:\n\n"); for(i = 0; i < 0x20; i+=1) { spin_lock_irqsave(&emu->emu_lock, flags); value = inb(emu->port + i); spin_unlock_irqrestore(&emu->emu_lock, flags); snd_iprintf(buffer, "Register %02X: %02X\n", i, value); } } static void snd_ca0106_proc_reg_read1(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned long value; int i,j; snd_iprintf(buffer, "Registers\n"); for(i = 0; i < 0x40; i++) { snd_iprintf(buffer, "%02X: ",i); for (j = 0; j < 4; j++) { value = snd_ca0106_ptr_read(emu, i, j); snd_iprintf(buffer, "%08lX ", value); } snd_iprintf(buffer, "\n"); } } static void snd_ca0106_proc_reg_read2(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; unsigned long value; int i,j; snd_iprintf(buffer, "Registers\n"); for(i = 0x40; i < 0x80; i++) { snd_iprintf(buffer, "%02X: ",i); for (j = 0; j < 4; j++) { value = snd_ca0106_ptr_read(emu, i, j); snd_iprintf(buffer, "%08lX ", value); } snd_iprintf(buffer, "\n"); } } static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; char line[64]; unsigned int reg, channel_id , val; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) continue; if (reg < 0x80 && val <= 0xffffffff && channel_id <= 3) snd_ca0106_ptr_write(emu, reg, channel_id, val); } } static void snd_ca0106_proc_i2c_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_ca0106 *emu = entry->private_data; char line[64]; unsigned int reg, val; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%x %x", &reg, &val) != 2) continue; if ((reg <= 0x7f) || (val <= 0x1ff)) { snd_ca0106_i2c_write(emu, reg, val); } } } int snd_ca0106_proc_init(struct snd_ca0106 *emu) { snd_card_ro_proc_new(emu->card, "iec958", emu, snd_ca0106_proc_iec958); snd_card_rw_proc_new(emu->card, "ca0106_reg32", emu, snd_ca0106_proc_reg_read32, snd_ca0106_proc_reg_write32); snd_card_ro_proc_new(emu->card, "ca0106_reg16", emu, snd_ca0106_proc_reg_read16); snd_card_ro_proc_new(emu->card, "ca0106_reg8", emu, snd_ca0106_proc_reg_read8); snd_card_rw_proc_new(emu->card, "ca0106_regs1", emu, snd_ca0106_proc_reg_read1, snd_ca0106_proc_reg_write); snd_card_rw_proc_new(emu->card, "ca0106_i2c", emu, NULL, snd_ca0106_proc_i2c_write); snd_card_ro_proc_new(emu->card, "ca0106_regs2", emu, snd_ca0106_proc_reg_read2); return 0; }
linux-master
sound/pci/ca0106/ca0106_proc.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2004 James Courtier-Dutton <[email protected]> * Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit * Version: 0.0.25 * * FEATURES currently supported: * Front, Rear and Center/LFE. * Surround40 and Surround51. * Capture from MIC an LINE IN input. * SPDIF digital playback of PCM stereo and AC3/DTS works. * (One can use a standard mono mini-jack to one RCA plugs cable. * or one can use a standard stereo mini-jack to two RCA plugs cable. * Plug one of the RCA plugs into the Coax input of the external decoder/receiver.) * ( In theory one could output 3 different AC3 streams at once, to 3 different SPDIF outputs. ) * Notes on how to capture sound: * The AC97 is used in the PLAYBACK direction. * The output from the AC97 chip, instead of reaching the speakers, is fed into the Philips 1361T ADC. * So, to record from the MIC, set the MIC Playback volume to max, * unmute the MIC and turn up the MASTER Playback volume. * So, to prevent feedback when capturing, minimise the "Capture feedback into Playback" volume. * * The only playback controls that currently do anything are: - * Analog Front * Analog Rear * Analog Center/LFE * SPDIF Front * SPDIF Rear * SPDIF Center/LFE * * For capture from Mic in or Line in. * Digital/Analog ( switch must be in Analog mode for CAPTURE. ) * * CAPTURE feedback into PLAYBACK * * Changelog: * Support interrupts per period. * Removed noise from Center/LFE channel when in Analog mode. * Rename and remove mixer controls. * 0.0.6 * Use separate card based DMA buffer for periods table list. * 0.0.7 * Change remove and rename ctrls into lists. * 0.0.8 * Try to fix capture sources. * 0.0.9 * Fix AC3 output. * Enable S32_LE format support. * 0.0.10 * Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".) * 0.0.11 * Add Model name recognition. * 0.0.12 * Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period. * Remove redundent "voice" handling. * 0.0.13 * Single trigger call for multi channels. * 0.0.14 * Set limits based on what the sound card hardware can do. * playback periods_min=2, periods_max=8 * capture hw constraints require period_size = n * 64 bytes. * playback hw constraints require period_size = n * 64 bytes. * 0.0.15 * Minor updates. * 0.0.16 * Implement 192000 sample rate. * 0.0.17 * Add support for SB0410 and SB0413. * 0.0.18 * Modified Copyright message. * 0.0.19 * Finally fix support for SB Live 24 bit. SB0410 and SB0413. * The output codec needs resetting, otherwise all output is muted. * 0.0.20 * Merge "pci_disable_device(pci);" fixes. * 0.0.21 * Add 4 capture channels. (SPDIF only comes in on channel 0. ) * Add SPDIF capture using optional digital I/O module for SB Live 24bit. (Analog capture does not yet work.) * 0.0.22 * Add support for MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97. From kiksen, bug #901 * 0.0.23 * Implement support for Line-in capture on SB Live 24bit. * 0.0.24 * Add support for mute control on SB Live 24bit (cards w/ SPI DAC) * 0.0.25 * Powerdown SPI DAC channels when not in use * * BUGS: * Some stability problems when unloading the snd-ca0106 kernel module. * -- * * TODO: * 4 Capture channels, only one implemented so far. * Other capture rates apart from 48khz not implemented. * MIDI * -- * GENERAL INFO: * Model: SB0310 * P17 Chip: CA0106-DAT * AC97 Codec: STAC 9721 * ADC: Philips 1361T (Stereo 24bit) * DAC: WM8746EDS (6-channel, 24bit, 192Khz) * * GENERAL INFO: * Model: SB0410 * P17 Chip: CA0106-DAT * AC97 Codec: None * ADC: WM8775EDS (4 Channel) * DAC: CS4382 (114 dB, 24-Bit, 192 kHz, 8-Channel D/A Converter with DSD Support) * SPDIF Out control switches between Mic in and SPDIF out. * No sound out or mic input working yet. * * GENERAL INFO: * Model: SB0413 * P17 Chip: CA0106-DAT * AC97 Codec: None. * ADC: Unknown * DAC: Unknown * Trying to handle it like the SB0410. * * This code was initially based on code from ALSA's emu10k1x.c which is: * Copyright (c) by Francisco Moraes <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/dma-mapping.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/pcm.h> #include <sound/ac97_codec.h> #include <sound/info.h> MODULE_AUTHOR("James Courtier-Dutton <[email protected]>"); MODULE_DESCRIPTION("CA0106"); MODULE_LICENSE("GPL"); // module parameters (see "Module Parameters") static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; static uint subsystem[SNDRV_CARDS]; /* Force card subsystem model */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for the CA0106 soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for the CA0106 soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable the CA0106 soundcard."); module_param_array(subsystem, uint, NULL, 0444); MODULE_PARM_DESC(subsystem, "Force card subsystem model."); #include "ca0106.h" static const struct snd_ca0106_details ca0106_chip_details[] = { /* Sound Blaster X-Fi Extreme Audio. This does not have an AC97. 53SB079000000 */ /* It is really just a normal SB Live 24bit. */ /* Tested: * See ALSA bug#3251 */ { .serial = 0x10131102, .name = "X-Fi Extreme Audio [SBxxxx]", .gpio_type = 1, .i2c_adc = 1 } , /* Sound Blaster X-Fi Extreme Audio. This does not have an AC97. 53SB079000000 */ /* It is really just a normal SB Live 24bit. */ /* * CTRL:CA0111-WTLF * ADC: WM8775SEDS * DAC: CS4382-KQZ */ /* Tested: * Playback on front, rear, center/lfe speakers * Capture from Mic in. * Not-Tested: * Capture from Line in. * Playback to digital out. */ { .serial = 0x10121102, .name = "X-Fi Extreme Audio [SB0790]", .gpio_type = 1, .i2c_adc = 1 } , /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */ /* AudigyLS[SB0310] */ { .serial = 0x10021102, .name = "AudigyLS [SB0310]", .ac97 = 1 } , /* Unknown AudigyLS that also says SB0310 on it */ { .serial = 0x10051102, .name = "AudigyLS [SB0310b]", .ac97 = 1 } , /* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */ { .serial = 0x10061102, .name = "Live! 7.1 24bit [SB0410]", .gpio_type = 1, .i2c_adc = 1 } , /* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */ { .serial = 0x10071102, .name = "Live! 7.1 24bit [SB0413]", .gpio_type = 1, .i2c_adc = 1 } , /* New Audigy SE. Has a different DAC. */ /* SB0570: * CTRL:CA0106-DAT * ADC: WM8775EDS * DAC: WM8768GEDS */ { .serial = 0x100a1102, .name = "Audigy SE [SB0570]", .gpio_type = 1, .i2c_adc = 1, .spi_dac = 0x4021 } , /* New Audigy LS. Has a different DAC. */ /* SB0570: * CTRL:CA0106-DAT * ADC: WM8775EDS * DAC: WM8768GEDS */ { .serial = 0x10111102, .name = "Audigy SE OEM [SB0570a]", .gpio_type = 1, .i2c_adc = 1, .spi_dac = 0x4021 } , /* Sound Blaster 5.1vx * Tested: Playback on front, rear, center/lfe speakers * Not-Tested: Capture */ { .serial = 0x10041102, .name = "Sound Blaster 5.1vx [SB1070]", .gpio_type = 1, .i2c_adc = 0, .spi_dac = 0x0124 } , /* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */ /* SB0438 * CTRL:CA0106-DAT * ADC: WM8775SEDS * DAC: CS4382-KQZ */ { .serial = 0x10091462, .name = "MSI K8N Diamond MB [SB0438]", .gpio_type = 2, .i2c_adc = 1 } , /* MSI K8N Diamond PLUS MB */ { .serial = 0x10091102, .name = "MSI K8N Diamond MB", .gpio_type = 2, .i2c_adc = 1, .spi_dac = 0x4021 } , /* Giga-byte GA-G1975X mobo * Novell bnc#395807 */ /* FIXME: the GPIO and I2C setting aren't tested well */ { .serial = 0x1458a006, .name = "Giga-byte GA-G1975X", .gpio_type = 1, .i2c_adc = 1 }, /* Shuttle XPC SD31P which has an onboard Creative Labs * Sound Blaster Live! 24-bit EAX * high-definition 7.1 audio processor". * Added using info from andrewvegan in alsa bug #1298 */ { .serial = 0x30381297, .name = "Shuttle XPC SD31P [SD31P]", .gpio_type = 1, .i2c_adc = 1 } , /* Shuttle XPC SD11G5 which has an onboard Creative Labs * Sound Blaster Live! 24-bit EAX * high-definition 7.1 audio processor". * Fixes ALSA bug#1600 */ { .serial = 0x30411297, .name = "Shuttle XPC SD11G5 [SD11G5]", .gpio_type = 1, .i2c_adc = 1 } , { .serial = 0, .name = "AudigyLS [Unknown]" } }; /* hardware definition */ static const struct snd_pcm_hardware snd_ca0106_playback_hw = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START, .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, .rates = (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000), .rate_min = 48000, .rate_max = 192000, .channels_min = 2, //1, .channels_max = 2, //6, .buffer_bytes_max = ((65536 - 64) * 8), .period_bytes_min = 64, .period_bytes_max = (65536 - 64), .periods_min = 2, .periods_max = 8, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_ca0106_capture_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID), .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, #if 0 /* FIXME: looks like 44.1kHz capture causes noisy output on 48kHz */ .rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000), .rate_min = 44100, #else .rates = (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000), .rate_min = 48000, #endif /* FIXME */ .rate_max = 192000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = 65536 - 128, .period_bytes_min = 64, .period_bytes_max = 32768 - 64, .periods_min = 2, .periods_max = 2, .fifo_size = 0, }; unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu, unsigned int reg, unsigned int chn) { unsigned long flags; unsigned int regptr, val; regptr = (reg << 16) | chn; spin_lock_irqsave(&emu->emu_lock, flags); outl(regptr, emu->port + CA0106_PTR); val = inl(emu->port + CA0106_DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); return val; } void snd_ca0106_ptr_write(struct snd_ca0106 *emu, unsigned int reg, unsigned int chn, unsigned int data) { unsigned int regptr; unsigned long flags; regptr = (reg << 16) | chn; spin_lock_irqsave(&emu->emu_lock, flags); outl(regptr, emu->port + CA0106_PTR); outl(data, emu->port + CA0106_DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); } int snd_ca0106_spi_write(struct snd_ca0106 * emu, unsigned int data) { unsigned int reset, set; unsigned int reg, tmp; int n, result; reg = SPI; if (data > 0xffff) /* Only 16bit values allowed */ return 1; tmp = snd_ca0106_ptr_read(emu, reg, 0); reset = (tmp & ~0x3ffff) | 0x20000; /* Set xxx20000 */ set = reset | 0x10000; /* Set xxx1xxxx */ snd_ca0106_ptr_write(emu, reg, 0, reset | data); tmp = snd_ca0106_ptr_read(emu, reg, 0); /* write post */ snd_ca0106_ptr_write(emu, reg, 0, set | data); result = 1; /* Wait for status bit to return to 0 */ for (n = 0; n < 100; n++) { udelay(10); tmp = snd_ca0106_ptr_read(emu, reg, 0); if (!(tmp & 0x10000)) { result = 0; break; } } if (result) /* Timed out */ return 1; snd_ca0106_ptr_write(emu, reg, 0, reset | data); tmp = snd_ca0106_ptr_read(emu, reg, 0); /* Write post */ return 0; } /* The ADC does not support i2c read, so only write is implemented */ int snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value) { u32 tmp; int timeout = 0; int status; int retry; if ((reg > 0x7f) || (value > 0x1ff)) { dev_err(emu->card->dev, "i2c_write: invalid values.\n"); return -EINVAL; } tmp = reg << 25 | value << 16; /* dev_dbg(emu->card->dev, "I2C-write:reg=0x%x, value=0x%x\n", reg, value); */ /* Not sure what this I2C channel controls. */ /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */ /* This controls the I2C connected to the WM8775 ADC Codec */ snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp); for (retry = 0; retry < 10; retry++) { /* Send the data to i2c */ //tmp = snd_ca0106_ptr_read(emu, I2C_A, 0); //tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK); tmp = 0; tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD); snd_ca0106_ptr_write(emu, I2C_A, 0, tmp); /* Wait till the transaction ends */ while (1) { status = snd_ca0106_ptr_read(emu, I2C_A, 0); /*dev_dbg(emu->card->dev, "I2C:status=0x%x\n", status);*/ timeout++; if ((status & I2C_A_ADC_START) == 0) break; if (timeout > 1000) break; } //Read back and see if the transaction is successful if ((status & I2C_A_ADC_ABORT) == 0) break; } if (retry == 10) { dev_err(emu->card->dev, "Writing to ADC failed!\n"); return -EINVAL; } return 0; } static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb) { unsigned long flags; unsigned int intr_enable; spin_lock_irqsave(&emu->emu_lock, flags); intr_enable = inl(emu->port + CA0106_INTE) | intrenb; outl(intr_enable, emu->port + CA0106_INTE); spin_unlock_irqrestore(&emu->emu_lock, flags); } static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb) { unsigned long flags; unsigned int intr_enable; spin_lock_irqsave(&emu->emu_lock, flags); intr_enable = inl(emu->port + CA0106_INTE) & ~intrenb; outl(intr_enable, emu->port + CA0106_INTE); spin_unlock_irqrestore(&emu->emu_lock, flags); } static void snd_ca0106_pcm_free_substream(struct snd_pcm_runtime *runtime) { kfree(runtime->private_data); } static const int spi_dacd_reg[] = { SPI_DACD0_REG, SPI_DACD1_REG, SPI_DACD2_REG, 0, SPI_DACD4_REG, }; static const int spi_dacd_bit[] = { SPI_DACD0_BIT, SPI_DACD1_BIT, SPI_DACD2_BIT, 0, SPI_DACD4_BIT, }; static void restore_spdif_bits(struct snd_ca0106 *chip, int idx) { if (chip->spdif_str_bits[idx] != chip->spdif_bits[idx]) { chip->spdif_str_bits[idx] = chip->spdif_bits[idx]; snd_ca0106_ptr_write(chip, SPCS0 + idx, 0, chip->spdif_str_bits[idx]); } } static int snd_ca0106_channel_dac(struct snd_ca0106 *chip, const struct snd_ca0106_details *details, int channel_id) { switch (channel_id) { case PCM_FRONT_CHANNEL: return (details->spi_dac & 0xf000) >> (4 * 3); case PCM_REAR_CHANNEL: return (details->spi_dac & 0x0f00) >> (4 * 2); case PCM_CENTER_LFE_CHANNEL: return (details->spi_dac & 0x00f0) >> (4 * 1); case PCM_UNKNOWN_CHANNEL: return (details->spi_dac & 0x000f) >> (4 * 0); default: dev_dbg(chip->card->dev, "ca0106: unknown channel_id %d\n", channel_id); } return 0; } static int snd_ca0106_pcm_power_dac(struct snd_ca0106 *chip, int channel_id, int power) { if (chip->details->spi_dac) { const int dac = snd_ca0106_channel_dac(chip, chip->details, channel_id); const int reg = spi_dacd_reg[dac]; const int bit = spi_dacd_bit[dac]; if (power) /* Power up */ chip->spi_dac_reg[reg] &= ~bit; else /* Power down */ chip->spi_dac_reg[reg] |= bit; if (snd_ca0106_spi_write(chip, chip->spi_dac_reg[reg]) != 0) return -ENXIO; } return 0; } /* open_playback callback */ static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream, int channel_id) { struct snd_ca0106 *chip = snd_pcm_substream_chip(substream); struct snd_ca0106_channel *channel = &(chip->playback_channels[channel_id]); struct snd_ca0106_pcm *epcm; struct snd_pcm_runtime *runtime = substream->runtime; int err; epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); if (epcm == NULL) return -ENOMEM; epcm->emu = chip; epcm->substream = substream; epcm->channel_id=channel_id; runtime->private_data = epcm; runtime->private_free = snd_ca0106_pcm_free_substream; runtime->hw = snd_ca0106_playback_hw; channel->emu = chip; channel->number = channel_id; channel->use = 1; /* dev_dbg(chip->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n", channel_id, chip, channel); */ //channel->interrupt = snd_ca0106_pcm_channel_interrupt; channel->epcm = epcm; err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); if (err < 0) return err; snd_pcm_set_sync(substream); /* Front channel dac should already be on */ if (channel_id != PCM_FRONT_CHANNEL) { err = snd_ca0106_pcm_power_dac(chip, channel_id, 1); if (err < 0) return err; } restore_spdif_bits(chip, channel_id); return 0; } /* close callback */ static int snd_ca0106_pcm_close_playback(struct snd_pcm_substream *substream) { struct snd_ca0106 *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; chip->playback_channels[epcm->channel_id].use = 0; restore_spdif_bits(chip, epcm->channel_id); /* Front channel dac should stay on */ if (epcm->channel_id != PCM_FRONT_CHANNEL) { int err; err = snd_ca0106_pcm_power_dac(chip, epcm->channel_id, 0); if (err < 0) return err; } /* FIXME: maybe zero others */ return 0; } static int snd_ca0106_pcm_open_playback_front(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL); } static int snd_ca0106_pcm_open_playback_center_lfe(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL); } static int snd_ca0106_pcm_open_playback_unknown(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL); } static int snd_ca0106_pcm_open_playback_rear(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL); } /* open_capture callback */ static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substream, int channel_id) { struct snd_ca0106 *chip = snd_pcm_substream_chip(substream); struct snd_ca0106_channel *channel = &(chip->capture_channels[channel_id]); struct snd_ca0106_pcm *epcm; struct snd_pcm_runtime *runtime = substream->runtime; int err; epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); if (!epcm) return -ENOMEM; epcm->emu = chip; epcm->substream = substream; epcm->channel_id=channel_id; runtime->private_data = epcm; runtime->private_free = snd_ca0106_pcm_free_substream; runtime->hw = snd_ca0106_capture_hw; channel->emu = chip; channel->number = channel_id; channel->use = 1; /* dev_dbg(chip->card->dev, "open:channel_id=%d, chip=%p, channel=%p\n", channel_id, chip, channel); */ //channel->interrupt = snd_ca0106_pcm_channel_interrupt; channel->epcm = epcm; err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; //snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes); err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); if (err < 0) return err; return 0; } /* close callback */ static int snd_ca0106_pcm_close_capture(struct snd_pcm_substream *substream) { struct snd_ca0106 *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; chip->capture_channels[epcm->channel_id].use = 0; /* FIXME: maybe zero others */ return 0; } static int snd_ca0106_pcm_open_0_capture(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_capture_channel(substream, 0); } static int snd_ca0106_pcm_open_1_capture(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_capture_channel(substream, 1); } static int snd_ca0106_pcm_open_2_capture(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_capture_channel(substream, 2); } static int snd_ca0106_pcm_open_3_capture(struct snd_pcm_substream *substream) { return snd_ca0106_pcm_open_capture_channel(substream, 3); } /* prepare playback callback */ static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; int channel = epcm->channel_id; u32 *table_base = (u32 *)(emu->buffer->area+(8*16*channel)); u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size); u32 hcfg_mask = HCFG_PLAYBACK_S32_LE; u32 hcfg_set = 0x00000000; u32 hcfg; u32 reg40_mask = 0x30000 << (channel<<1); u32 reg40_set = 0; u32 reg40; /* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */ u32 reg71_mask = 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */ u32 reg71_set = 0; u32 reg71; int i; #if 0 /* debug */ dev_dbg(emu->card->dev, "prepare:channel_number=%d, rate=%d, format=0x%x, " "channels=%d, buffer_size=%ld, period_size=%ld, " "periods=%u, frames_to_bytes=%d\n", channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); dev_dbg(emu->card->dev, "dma_addr=%x, dma_area=%p, table_base=%p\n", runtime->dma_addr, runtime->dma_area, table_base); dev_dbg(emu->card->dev, "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", emu->buffer->addr, emu->buffer->area, emu->buffer->bytes); #endif /* debug */ /* Rate can be set per channel. */ /* reg40 control host to fifo */ /* reg71 controls DAC rate. */ switch (runtime->rate) { case 44100: reg40_set = 0x10000 << (channel<<1); reg71_set = 0x01010000; break; case 48000: reg40_set = 0; reg71_set = 0; break; case 96000: reg40_set = 0x20000 << (channel<<1); reg71_set = 0x02020000; break; case 192000: reg40_set = 0x30000 << (channel<<1); reg71_set = 0x03030000; break; default: reg40_set = 0; reg71_set = 0; break; } /* Format is a global setting */ /* FIXME: Only let the first channel accessed set this. */ switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: hcfg_set = 0; break; case SNDRV_PCM_FORMAT_S32_LE: hcfg_set = HCFG_PLAYBACK_S32_LE; break; default: hcfg_set = 0; break; } hcfg = inl(emu->port + CA0106_HCFG) ; hcfg = (hcfg & ~hcfg_mask) | hcfg_set; outl(hcfg, emu->port + CA0106_HCFG); reg40 = snd_ca0106_ptr_read(emu, 0x40, 0); reg40 = (reg40 & ~reg40_mask) | reg40_set; snd_ca0106_ptr_write(emu, 0x40, 0, reg40); reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); reg71 = (reg71 & ~reg71_mask) | reg71_set; snd_ca0106_ptr_write(emu, 0x71, 0, reg71); /* FIXME: Check emu->buffer->size before actually writing to it. */ for(i=0; i < runtime->periods; i++) { table_base[i*2] = runtime->dma_addr + (i * period_size_bytes); table_base[i*2+1] = period_size_bytes << 16; } snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer->addr+(8*16*channel)); snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19); snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0); snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr); snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes /* FIXME test what 0 bytes does. */ snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0); snd_ca0106_ptr_write(emu, 0x07, channel, 0x0); snd_ca0106_ptr_write(emu, 0x08, channel, 0); snd_ca0106_ptr_write(emu, PLAYBACK_MUTE, 0x0, 0x0); /* Unmute output */ #if 0 snd_ca0106_ptr_write(emu, SPCS0, 0, SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT ); #endif return 0; } /* prepare capture callback */ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; int channel = epcm->channel_id; u32 hcfg_mask = HCFG_CAPTURE_S32_LE; u32 hcfg_set = 0x00000000; u32 hcfg; u32 over_sampling=0x2; u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */ u32 reg71_set = 0; u32 reg71; #if 0 /* debug */ dev_dbg(emu->card->dev, "prepare:channel_number=%d, rate=%d, format=0x%x, " "channels=%d, buffer_size=%ld, period_size=%ld, " "periods=%u, frames_to_bytes=%d\n", channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); dev_dbg(emu->card->dev, "dma_addr=%x, dma_area=%p, table_base=%p\n", runtime->dma_addr, runtime->dma_area, table_base); dev_dbg(emu->card->dev, "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", emu->buffer->addr, emu->buffer->area, emu->buffer->bytes); #endif /* debug */ /* reg71 controls ADC rate. */ switch (runtime->rate) { case 44100: reg71_set = 0x00004000; break; case 48000: reg71_set = 0; break; case 96000: reg71_set = 0x00008000; over_sampling=0xa; break; case 192000: reg71_set = 0x0000c000; over_sampling=0xa; break; default: reg71_set = 0; break; } /* Format is a global setting */ /* FIXME: Only let the first channel accessed set this. */ switch (runtime->format) { case SNDRV_PCM_FORMAT_S16_LE: hcfg_set = 0; break; case SNDRV_PCM_FORMAT_S32_LE: hcfg_set = HCFG_CAPTURE_S32_LE; break; default: hcfg_set = 0; break; } hcfg = inl(emu->port + CA0106_HCFG) ; hcfg = (hcfg & ~hcfg_mask) | hcfg_set; outl(hcfg, emu->port + CA0106_HCFG); reg71 = snd_ca0106_ptr_read(emu, 0x71, 0); reg71 = (reg71 & ~reg71_mask) | reg71_set; snd_ca0106_ptr_write(emu, 0x71, 0, reg71); if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */ } /* dev_dbg(emu->card->dev, "prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, " "buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n", channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1)); */ snd_ca0106_ptr_write(emu, 0x13, channel, 0); snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr); snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes snd_ca0106_ptr_write(emu, CAPTURE_POINTER, channel, 0); return 0; } /* trigger_playback callback */ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream, int cmd) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime; struct snd_ca0106_pcm *epcm; int channel; int result = 0; struct snd_pcm_substream *s; u32 basic = 0; u32 extended = 0; u32 bits; int running = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: running = 1; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: default: running = 0; break; } snd_pcm_group_for_each_entry(s, substream) { if (snd_pcm_substream_chip(s) != emu || s->stream != SNDRV_PCM_STREAM_PLAYBACK) continue; runtime = s->runtime; epcm = runtime->private_data; channel = epcm->channel_id; /* dev_dbg(emu->card->dev, "channel=%d\n", channel); */ epcm->running = running; basic |= (0x1 << channel); extended |= (0x10 << channel); snd_pcm_trigger_done(s, substream); } /* dev_dbg(emu->card->dev, "basic=0x%x, extended=0x%x\n",basic, extended); */ switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0); bits |= extended; snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits); bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0); bits |= basic; snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0); bits &= ~basic; snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits); bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0); bits &= ~extended; snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits); break; default: result = -EINVAL; break; } return result; } /* trigger_capture callback */ static int snd_ca0106_pcm_trigger_capture(struct snd_pcm_substream *substream, int cmd) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; int channel = epcm->channel_id; int result = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel)); snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel)); epcm->running = 1; break; case SNDRV_PCM_TRIGGER_STOP: snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel)); snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel)); epcm->running = 0; break; default: result = -EINVAL; break; } return result; } /* pointer_playback callback */ static snd_pcm_uframes_t snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; unsigned int ptr, prev_ptr; int channel = epcm->channel_id; int timeout = 10; if (!epcm->running) return 0; prev_ptr = -1; do { ptr = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel); ptr = (ptr >> 3) * runtime->period_size; ptr += bytes_to_frames(runtime, snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel)); if (ptr >= runtime->buffer_size) ptr -= runtime->buffer_size; if (prev_ptr == ptr) return ptr; prev_ptr = ptr; } while (--timeout); dev_warn(emu->card->dev, "ca0106: unstable DMA pointer!\n"); return 0; } /* pointer_capture callback */ static snd_pcm_uframes_t snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream) { struct snd_ca0106 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_ca0106_pcm *epcm = runtime->private_data; snd_pcm_uframes_t ptr, ptr1, ptr2 = 0; int channel = epcm->channel_id; if (!epcm->running) return 0; ptr1 = snd_ca0106_ptr_read(emu, CAPTURE_POINTER, channel); ptr2 = bytes_to_frames(runtime, ptr1); ptr=ptr2; if (ptr >= runtime->buffer_size) ptr -= runtime->buffer_size; /* dev_dbg(emu->card->dev, "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, " "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); */ return ptr; } /* operators */ static const struct snd_pcm_ops snd_ca0106_playback_front_ops = { .open = snd_ca0106_pcm_open_playback_front, .close = snd_ca0106_pcm_close_playback, .prepare = snd_ca0106_pcm_prepare_playback, .trigger = snd_ca0106_pcm_trigger_playback, .pointer = snd_ca0106_pcm_pointer_playback, }; static const struct snd_pcm_ops snd_ca0106_capture_0_ops = { .open = snd_ca0106_pcm_open_0_capture, .close = snd_ca0106_pcm_close_capture, .prepare = snd_ca0106_pcm_prepare_capture, .trigger = snd_ca0106_pcm_trigger_capture, .pointer = snd_ca0106_pcm_pointer_capture, }; static const struct snd_pcm_ops snd_ca0106_capture_1_ops = { .open = snd_ca0106_pcm_open_1_capture, .close = snd_ca0106_pcm_close_capture, .prepare = snd_ca0106_pcm_prepare_capture, .trigger = snd_ca0106_pcm_trigger_capture, .pointer = snd_ca0106_pcm_pointer_capture, }; static const struct snd_pcm_ops snd_ca0106_capture_2_ops = { .open = snd_ca0106_pcm_open_2_capture, .close = snd_ca0106_pcm_close_capture, .prepare = snd_ca0106_pcm_prepare_capture, .trigger = snd_ca0106_pcm_trigger_capture, .pointer = snd_ca0106_pcm_pointer_capture, }; static const struct snd_pcm_ops snd_ca0106_capture_3_ops = { .open = snd_ca0106_pcm_open_3_capture, .close = snd_ca0106_pcm_close_capture, .prepare = snd_ca0106_pcm_prepare_capture, .trigger = snd_ca0106_pcm_trigger_capture, .pointer = snd_ca0106_pcm_pointer_capture, }; static const struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = { .open = snd_ca0106_pcm_open_playback_center_lfe, .close = snd_ca0106_pcm_close_playback, .prepare = snd_ca0106_pcm_prepare_playback, .trigger = snd_ca0106_pcm_trigger_playback, .pointer = snd_ca0106_pcm_pointer_playback, }; static const struct snd_pcm_ops snd_ca0106_playback_unknown_ops = { .open = snd_ca0106_pcm_open_playback_unknown, .close = snd_ca0106_pcm_close_playback, .prepare = snd_ca0106_pcm_prepare_playback, .trigger = snd_ca0106_pcm_trigger_playback, .pointer = snd_ca0106_pcm_pointer_playback, }; static const struct snd_pcm_ops snd_ca0106_playback_rear_ops = { .open = snd_ca0106_pcm_open_playback_rear, .close = snd_ca0106_pcm_close_playback, .prepare = snd_ca0106_pcm_prepare_playback, .trigger = snd_ca0106_pcm_trigger_playback, .pointer = snd_ca0106_pcm_pointer_playback, }; static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97, unsigned short reg) { struct snd_ca0106 *emu = ac97->private_data; unsigned long flags; unsigned short val; spin_lock_irqsave(&emu->emu_lock, flags); outb(reg, emu->port + CA0106_AC97ADDRESS); val = inw(emu->port + CA0106_AC97DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); return val; } static void snd_ca0106_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { struct snd_ca0106 *emu = ac97->private_data; unsigned long flags; spin_lock_irqsave(&emu->emu_lock, flags); outb(reg, emu->port + CA0106_AC97ADDRESS); outw(val, emu->port + CA0106_AC97DATA); spin_unlock_irqrestore(&emu->emu_lock, flags); } static int snd_ca0106_ac97(struct snd_ca0106 *chip) { struct snd_ac97_bus *pbus; struct snd_ac97_template ac97; int err; static const struct snd_ac97_bus_ops ops = { .write = snd_ca0106_ac97_write, .read = snd_ca0106_ac97_read, }; err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus); if (err < 0) return err; pbus->no_vra = 1; /* we don't need VRA */ memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; ac97.scaps = AC97_SCAP_NO_SPDIF; return snd_ac97_mixer(pbus, &ac97, &chip->ac97); } static void ca0106_stop_chip(struct snd_ca0106 *chip); static void snd_ca0106_free(struct snd_card *card) { struct snd_ca0106 *chip = card->private_data; ca0106_stop_chip(chip); } static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id) { unsigned int status; struct snd_ca0106 *chip = dev_id; int i; int mask; unsigned int stat76; struct snd_ca0106_channel *pchannel; status = inl(chip->port + CA0106_IPR); if (! status) return IRQ_NONE; stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0); /* dev_dbg(emu->card->dev, "interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76); dev_dbg(emu->card->dev, "ptr=0x%08x\n", snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0)); */ mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */ for(i = 0; i < 4; i++) { pchannel = &(chip->playback_channels[i]); if (stat76 & mask) { /* FIXME: Select the correct substream for period elapsed */ if(pchannel->use) { snd_pcm_period_elapsed(pchannel->epcm->substream); /* dev_dbg(emu->card->dev, "interrupt [%d] used\n", i); */ } } /* dev_dbg(emu->card->dev, "channel=%p\n", pchannel); dev_dbg(emu->card->dev, "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); */ mask <<= 1; } mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */ for(i = 0; i < 4; i++) { pchannel = &(chip->capture_channels[i]); if (stat76 & mask) { /* FIXME: Select the correct substream for period elapsed */ if(pchannel->use) { snd_pcm_period_elapsed(pchannel->epcm->substream); /* dev_dbg(emu->card->dev, "interrupt [%d] used\n", i); */ } } /* dev_dbg(emu->card->dev, "channel=%p\n", pchannel); dev_dbg(emu->card->dev, "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number); */ mask <<= 1; } snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); if (chip->midi.dev_id && (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) { if (chip->midi.interrupt) chip->midi.interrupt(&chip->midi, status); else chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable); } // acknowledge the interrupt if necessary outl(status, chip->port + CA0106_IPR); return IRQ_HANDLED; } static const struct snd_pcm_chmap_elem surround_map[] = { { .channels = 2, .map = { SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, { } }; static const struct snd_pcm_chmap_elem clfe_map[] = { { .channels = 2, .map = { SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE } }, { } }; static const struct snd_pcm_chmap_elem side_map[] = { { .channels = 2, .map = { SNDRV_CHMAP_SL, SNDRV_CHMAP_SR } }, { } }; static int snd_ca0106_pcm(struct snd_ca0106 *emu, int device) { struct snd_pcm *pcm; struct snd_pcm_substream *substream; const struct snd_pcm_chmap_elem *map = NULL; int err; err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm); if (err < 0) return err; pcm->private_data = emu; switch (device) { case 0: snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_front_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_0_ops); map = snd_pcm_std_chmaps; break; case 1: snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_rear_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_1_ops); map = surround_map; break; case 2: snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_center_lfe_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_2_ops); map = clfe_map; break; case 3: snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_unknown_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_3_ops); map = side_map; break; } pcm->info_flags = 0; strcpy(pcm->name, "CA0106"); for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) { snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV, &emu->pci->dev, 64*1024, 64*1024); } for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) { snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV, &emu->pci->dev, 64*1024, 64*1024); } err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, map, 2, 1 << 2, NULL); if (err < 0) return err; emu->pcm[device] = pcm; return 0; } #define SPI_REG(reg, value) (((reg) << SPI_REG_SHIFT) | (value)) static const unsigned int spi_dac_init[] = { SPI_REG(SPI_LDA1_REG, SPI_DA_BIT_0dB), /* 0dB dig. attenuation */ SPI_REG(SPI_RDA1_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_PL_REG, SPI_PL_BIT_L_L | SPI_PL_BIT_R_R | SPI_IZD_BIT), SPI_REG(SPI_FMT_REG, SPI_FMT_BIT_I2S | SPI_IWL_BIT_24), SPI_REG(SPI_LDA2_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_RDA2_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_LDA3_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_RDA3_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_MASTDA_REG, SPI_DA_BIT_0dB), SPI_REG(9, 0x00), SPI_REG(SPI_MS_REG, SPI_DACD0_BIT | SPI_DACD1_BIT | SPI_DACD2_BIT), SPI_REG(12, 0x00), SPI_REG(SPI_LDA4_REG, SPI_DA_BIT_0dB), SPI_REG(SPI_RDA4_REG, SPI_DA_BIT_0dB | SPI_DA_BIT_UPDATE), SPI_REG(SPI_DACD4_REG, SPI_DACD4_BIT), }; static const unsigned int i2c_adc_init[][2] = { { 0x17, 0x00 }, /* Reset */ { 0x07, 0x00 }, /* Timeout */ { 0x0b, 0x22 }, /* Interface control */ { 0x0c, 0x22 }, /* Master mode control */ { 0x0d, 0x08 }, /* Powerdown control */ { 0x0e, 0xcf }, /* Attenuation Left 0x01 = -103dB, 0xff = 24dB */ { 0x0f, 0xcf }, /* Attenuation Right 0.5dB steps */ { 0x10, 0x7b }, /* ALC Control 1 */ { 0x11, 0x00 }, /* ALC Control 2 */ { 0x12, 0x32 }, /* ALC Control 3 */ { 0x13, 0x00 }, /* Noise gate control */ { 0x14, 0xa6 }, /* Limiter control */ { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */ }; static void ca0106_init_chip(struct snd_ca0106 *chip, int resume) { int ch; unsigned int def_bits; outl(0, chip->port + CA0106_INTE); /* * Init to 0x02109204 : * Clock accuracy = 0 (1000ppm) * Sample Rate = 2 (48kHz) * Audio Channel = 1 (Left of 2) * Source Number = 0 (Unspecified) * Generation Status = 1 (Original for Cat Code 12) * Cat Code = 12 (Digital Signal Mixer) * Mode = 0 (Mode 0) * Emphasis = 0 (None) * CP = 1 (Copyright unasserted) * AN = 0 (Audio data) * P = 0 (Consumer) */ def_bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; if (!resume) { chip->spdif_str_bits[0] = chip->spdif_bits[0] = def_bits; chip->spdif_str_bits[1] = chip->spdif_bits[1] = def_bits; chip->spdif_str_bits[2] = chip->spdif_bits[2] = def_bits; chip->spdif_str_bits[3] = chip->spdif_bits[3] = def_bits; } /* Only SPCS1 has been tested */ snd_ca0106_ptr_write(chip, SPCS1, 0, chip->spdif_str_bits[1]); snd_ca0106_ptr_write(chip, SPCS0, 0, chip->spdif_str_bits[0]); snd_ca0106_ptr_write(chip, SPCS2, 0, chip->spdif_str_bits[2]); snd_ca0106_ptr_write(chip, SPCS3, 0, chip->spdif_str_bits[3]); snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); /* Write 0x8000 to AC97_REC_GAIN to mute it. */ outb(AC97_REC_GAIN, chip->port + CA0106_AC97ADDRESS); outw(0x8000, chip->port + CA0106_AC97DATA); #if 0 /* FIXME: what are these? */ snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); #endif /* OSS drivers set this. */ /* snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); */ /* Analog or Digital output */ snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. * Use 0x000f0000 for surround71 */ snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); chip->spdif_enable = 0; /* Set digital SPDIF output off */ /*snd_ca0106_ptr_write(chip, 0x45, 0, 0);*/ /* Analogue out */ /*snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00);*/ /* Digital out */ /* goes to 0x40c80000 when doing SPDIF IN/OUT */ snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* (Mute) CAPTURE feedback into PLAYBACK volume. * Only lower 16 bits matter. */ snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* SPDIF IN Volume */ snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */ snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); for (ch = 0; ch < 4; ch++) { /* Only high 16 bits matter */ snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); #if 0 /* Mute */ snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); #endif } if (chip->details->i2c_adc == 1) { /* Select MIC, Line in, TAD in, AUX in */ snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Default to CAPTURE_SOURCE to i2s in */ if (!resume) chip->capture_source = 3; } else if (chip->details->ac97 == 1) { /* Default to AC97 in */ snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4); /* Default to CAPTURE_SOURCE to AC97 in */ if (!resume) chip->capture_source = 4; } else { /* Select MIC, Line in, TAD in, AUX in */ snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); /* Default to Set CAPTURE_SOURCE to i2s in */ if (!resume) chip->capture_source = 3; } if (chip->details->gpio_type == 2) { /* The SB0438 use GPIO differently. */ /* FIXME: Still need to find out what the other GPIO bits do. * E.g. For digital spdif out. */ outl(0x0, chip->port + CA0106_GPIO); /* outl(0x00f0e000, chip->port + CA0106_GPIO); */ /* Analog */ outl(0x005f5301, chip->port + CA0106_GPIO); /* Analog */ } else if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */ /* FIXME: Still need to find out what the other GPIO bits do. * E.g. For digital spdif out. */ outl(0x0, chip->port + CA0106_GPIO); /* outl(0x00f0e000, chip->port + CA0106_GPIO); */ /* Analog */ outl(0x005f5301, chip->port + CA0106_GPIO); /* Analog */ } else { outl(0x0, chip->port + CA0106_GPIO); outl(0x005f03a3, chip->port + CA0106_GPIO); /* Analog */ /* outl(0x005f02a2, chip->port + CA0106_GPIO); */ /* SPDIF */ } snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ /* outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); */ /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ /* outl(0x00001409, chip->port + CA0106_HCFG); */ /* outl(0x00000009, chip->port + CA0106_HCFG); */ /* AC97 2.0, Enable outputs. */ outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port + CA0106_HCFG); if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ int size, n; size = ARRAY_SIZE(i2c_adc_init); /* dev_dbg(emu->card->dev, "I2C:array size=0x%x\n", size); */ for (n = 0; n < size; n++) snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], i2c_adc_init[n][1]); for (n = 0; n < 4; n++) { chip->i2c_capture_volume[n][0] = 0xcf; chip->i2c_capture_volume[n][1] = 0xcf; } chip->i2c_capture_source = 2; /* Line in */ /* Enable Line-in capture. MIC in currently untested. */ /* snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); */ } if (chip->details->spi_dac) { /* The SB0570 use SPI to control DAC. */ int size, n; size = ARRAY_SIZE(spi_dac_init); for (n = 0; n < size; n++) { int reg = spi_dac_init[n] >> SPI_REG_SHIFT; snd_ca0106_spi_write(chip, spi_dac_init[n]); if (reg < ARRAY_SIZE(chip->spi_dac_reg)) chip->spi_dac_reg[reg] = spi_dac_init[n]; } /* Enable front dac only */ snd_ca0106_pcm_power_dac(chip, PCM_FRONT_CHANNEL, 1); } } static void ca0106_stop_chip(struct snd_ca0106 *chip) { /* disable interrupts */ snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); outl(0, chip->port + CA0106_INTE); snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0); udelay(1000); /* disable audio */ /* outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); */ outl(0, chip->port + CA0106_HCFG); /* FIXME: We need to stop and DMA transfers here. * But as I am not sure how yet, we cannot from the dma pages. * So we can fix: snd-malloc: Memory leak? pages not freed = 8 */ } static int snd_ca0106_create(int dev, struct snd_card *card, struct pci_dev *pci) { struct snd_ca0106 *chip = card->private_data; const struct snd_ca0106_details *c; int err; err = pcim_enable_device(pci); if (err < 0) return err; if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "error to set 32bit mask DMA\n"); return -ENXIO; } chip->card = card; chip->pci = pci; chip->irq = -1; spin_lock_init(&chip->emu_lock); err = pci_request_regions(pci, "snd_ca0106"); if (err < 0) return err; chip->port = pci_resource_start(pci, 0); if (devm_request_irq(&pci->dev, pci->irq, snd_ca0106_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "cannot grab irq\n"); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; /* This stores the periods table. */ chip->buffer = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, 1024); if (!chip->buffer) return -ENOMEM; pci_set_master(pci); /* read serial */ pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); dev_info(card->dev, "Model %04x Rev %08x Serial %08x\n", chip->model, pci->revision, chip->serial); strcpy(card->driver, "CA0106"); strcpy(card->shortname, "CA0106"); for (c = ca0106_chip_details; c->serial; c++) { if (subsystem[dev]) { if (c->serial == subsystem[dev]) break; } else if (c->serial == chip->serial) break; } chip->details = c; if (subsystem[dev]) { dev_info(card->dev, "Sound card name=%s, " "subsystem=0x%x. Forced to subsystem=0x%x\n", c->name, chip->serial, subsystem[dev]); } sprintf(card->longname, "%s at 0x%lx irq %i", c->name, chip->port, chip->irq); ca0106_init_chip(chip, 0); return 0; } static void ca0106_midi_interrupt_enable(struct snd_ca_midi *midi, int intr) { snd_ca0106_intr_enable((struct snd_ca0106 *)(midi->dev_id), intr); } static void ca0106_midi_interrupt_disable(struct snd_ca_midi *midi, int intr) { snd_ca0106_intr_disable((struct snd_ca0106 *)(midi->dev_id), intr); } static unsigned char ca0106_midi_read(struct snd_ca_midi *midi, int idx) { return (unsigned char)snd_ca0106_ptr_read((struct snd_ca0106 *)(midi->dev_id), midi->port + idx, 0); } static void ca0106_midi_write(struct snd_ca_midi *midi, int data, int idx) { snd_ca0106_ptr_write((struct snd_ca0106 *)(midi->dev_id), midi->port + idx, 0, data); } static struct snd_card *ca0106_dev_id_card(void *dev_id) { return ((struct snd_ca0106 *)dev_id)->card; } static int ca0106_dev_id_port(void *dev_id) { return ((struct snd_ca0106 *)dev_id)->port; } static int snd_ca0106_midi(struct snd_ca0106 *chip, unsigned int channel) { struct snd_ca_midi *midi; char *name; int err; if (channel == CA0106_MIDI_CHAN_B) { name = "CA0106 MPU-401 (UART) B"; midi = &chip->midi2; midi->tx_enable = INTE_MIDI_TX_B; midi->rx_enable = INTE_MIDI_RX_B; midi->ipr_tx = IPR_MIDI_TX_B; midi->ipr_rx = IPR_MIDI_RX_B; midi->port = MIDI_UART_B_DATA; } else { name = "CA0106 MPU-401 (UART)"; midi = &chip->midi; midi->tx_enable = INTE_MIDI_TX_A; midi->rx_enable = INTE_MIDI_TX_B; midi->ipr_tx = IPR_MIDI_TX_A; midi->ipr_rx = IPR_MIDI_RX_A; midi->port = MIDI_UART_A_DATA; } midi->reset = CA0106_MPU401_RESET; midi->enter_uart = CA0106_MPU401_ENTER_UART; midi->ack = CA0106_MPU401_ACK; midi->input_avail = CA0106_MIDI_INPUT_AVAIL; midi->output_ready = CA0106_MIDI_OUTPUT_READY; midi->channel = channel; midi->interrupt_enable = ca0106_midi_interrupt_enable; midi->interrupt_disable = ca0106_midi_interrupt_disable; midi->read = ca0106_midi_read; midi->write = ca0106_midi_write; midi->get_dev_id_card = ca0106_dev_id_card; midi->get_dev_id_port = ca0106_dev_id_port; midi->dev_id = chip; err = ca_midi_init(chip, midi, 0, name); if (err < 0) return err; return 0; } static int __snd_ca0106_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct snd_ca0106 *chip; int i, err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) return err; chip = card->private_data; err = snd_ca0106_create(dev, card, pci); if (err < 0) return err; card->private_free = snd_ca0106_free; for (i = 0; i < 4; i++) { err = snd_ca0106_pcm(chip, i); if (err < 0) return err; } if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */ err = snd_ca0106_ac97(chip); if (err < 0) return err; } err = snd_ca0106_mixer(chip); if (err < 0) return err; dev_dbg(card->dev, "probe for MIDI channel A ..."); err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A); if (err < 0) return err; dev_dbg(card->dev, " done.\n"); #ifdef CONFIG_SND_PROC_FS snd_ca0106_proc_init(chip); #endif err = snd_card_register(card); if (err < 0) return err; pci_set_drvdata(pci, card); dev++; return 0; } static int snd_ca0106_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { return snd_card_free_on_error(&pci->dev, __snd_ca0106_probe(pci, pci_id)); } #ifdef CONFIG_PM_SLEEP static int snd_ca0106_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_ca0106 *chip = card->private_data; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); if (chip->details->ac97) snd_ac97_suspend(chip->ac97); snd_ca0106_mixer_suspend(chip); ca0106_stop_chip(chip); return 0; } static int snd_ca0106_resume(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_ca0106 *chip = card->private_data; int i; ca0106_init_chip(chip, 1); if (chip->details->ac97) snd_ac97_resume(chip->ac97); snd_ca0106_mixer_resume(chip); if (chip->details->spi_dac) { for (i = 0; i < ARRAY_SIZE(chip->spi_dac_reg); i++) snd_ca0106_spi_write(chip, chip->spi_dac_reg[i]); } snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } static SIMPLE_DEV_PM_OPS(snd_ca0106_pm, snd_ca0106_suspend, snd_ca0106_resume); #define SND_CA0106_PM_OPS &snd_ca0106_pm #else #define SND_CA0106_PM_OPS NULL #endif // PCI IDs static const struct pci_device_id snd_ca0106_ids[] = { { PCI_VDEVICE(CREATIVE, 0x0007), 0 }, /* Audigy LS or Live 24bit */ { 0, } }; MODULE_DEVICE_TABLE(pci, snd_ca0106_ids); // pci_driver definition static struct pci_driver ca0106_driver = { .name = KBUILD_MODNAME, .id_table = snd_ca0106_ids, .probe = snd_ca0106_probe, .driver = { .pm = SND_CA0106_PM_OPS, }, }; module_pci_driver(ca0106_driver);
linux-master
sound/pci/ca0106/ca0106_main.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards * Copyright (c) by Jaroslav Kysela <[email protected]> */ /* NOTES: - sometimes the sound is metallic and sibilant, unloading and reloading the module may solve this. */ #include <linux/pci.h> #include <linux/time.h> #include <linux/init.h> #include <linux/module.h> #include <sound/core.h> #include "cs46xx.h" #include <sound/initval.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX"); MODULE_LICENSE("GPL"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ static bool external_amp[SNDRV_CARDS]; static bool thinkpad[SNDRV_CARDS]; static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable CS46xx soundcard."); module_param_array(external_amp, bool, NULL, 0444); MODULE_PARM_DESC(external_amp, "Force to enable external amplifier."); module_param_array(thinkpad, bool, NULL, 0444); MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control."); module_param_array(mmap_valid, bool, NULL, 0444); MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); static const struct pci_device_id snd_cs46xx_ids[] = { { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */ { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */ { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */ { 0, } }; MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids); static int snd_card_cs46xx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct snd_card *card; struct snd_cs46xx *chip; int err; if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) { dev++; return -ENOENT; } err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, sizeof(*chip), &card); if (err < 0) return err; chip = card->private_data; err = snd_cs46xx_create(card, pci, external_amp[dev], thinkpad[dev]); if (err < 0) goto error; card->private_data = chip; chip->accept_valid = mmap_valid[dev]; err = snd_cs46xx_pcm(chip, 0); if (err < 0) goto error; #ifdef CONFIG_SND_CS46XX_NEW_DSP err = snd_cs46xx_pcm_rear(chip, 1); if (err < 0) goto error; err = snd_cs46xx_pcm_iec958(chip, 2); if (err < 0) goto error; #endif err = snd_cs46xx_mixer(chip, 2); if (err < 0) goto error; #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->nr_ac97_codecs ==2) { err = snd_cs46xx_pcm_center_lfe(chip, 3); if (err < 0) goto error; } #endif err = snd_cs46xx_midi(chip, 0); if (err < 0) goto error; err = snd_cs46xx_start_dsp(chip); if (err < 0) goto error; snd_cs46xx_gameport(chip); strcpy(card->driver, "CS46xx"); strcpy(card->shortname, "Sound Fusion CS46xx"); sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i", card->shortname, chip->ba0_addr, chip->ba1_addr, chip->irq); err = snd_card_register(card); if (err < 0) goto error; pci_set_drvdata(pci, card); dev++; return 0; error: snd_card_free(card); return err; } static struct pci_driver cs46xx_driver = { .name = KBUILD_MODNAME, .id_table = snd_cs46xx_ids, .probe = snd_card_cs46xx_probe, #ifdef CONFIG_PM_SLEEP .driver = { .pm = &snd_cs46xx_pm, }, #endif }; module_pci_driver(cs46xx_driver);
linux-master
sound/pci/cs46xx/cs46xx.c
// SPDX-License-Identifier: GPL-2.0-or-later /* */ /* * 2002-07 Benny Sjostrand [email protected] */ #include <linux/io.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/mutex.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> #include <sound/asoundef.h> #include "cs46xx.h" #include "cs46xx_lib.h" #include "dsp_spos.h" static int cs46xx_dsp_async_init (struct snd_cs46xx *chip, struct dsp_scb_descriptor * fg_entry); static const enum wide_opcode wide_opcodes[] = { WIDE_FOR_BEGIN_LOOP, WIDE_FOR_BEGIN_LOOP2, WIDE_COND_GOTO_ADDR, WIDE_COND_GOTO_CALL, WIDE_TBEQ_COND_GOTO_ADDR, WIDE_TBEQ_COND_CALL_ADDR, WIDE_TBEQ_NCOND_GOTO_ADDR, WIDE_TBEQ_NCOND_CALL_ADDR, WIDE_TBEQ_COND_GOTO1_ADDR, WIDE_TBEQ_COND_CALL1_ADDR, WIDE_TBEQ_NCOND_GOTOI_ADDR, WIDE_TBEQ_NCOND_CALL1_ADDR }; static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32 size, u32 overlay_begin_address) { unsigned int i = 0, j, nreallocated = 0; u32 hival,loval,address; u32 mop_operands,mop_type,wide_op; struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(size %2)) return -EINVAL; while (i < size) { loval = data[i++]; hival = data[i++]; if (ins->code.offset > 0) { mop_operands = (hival >> 6) & 0x03fff; mop_type = mop_operands >> 10; /* check for wide type instruction */ if (mop_type == 0 && (mop_operands & WIDE_LADD_INSTR_MASK) == 0 && (mop_operands & WIDE_INSTR_MASK) != 0) { wide_op = loval & 0x7f; for (j = 0;j < ARRAY_SIZE(wide_opcodes); ++j) { if (wide_opcodes[j] == wide_op) { /* need to reallocate instruction */ address = (hival & 0x00FFF) << 5; address |= loval >> 15; dev_dbg(chip->card->dev, "handle_wideop[1]: %05x:%05x addr %04x\n", hival, loval, address); if ( !(address & 0x8000) ) { address += (ins->code.offset / 2) - overlay_begin_address; } else { dev_dbg(chip->card->dev, "handle_wideop[1]: ROM symbol not reallocated\n"); } hival &= 0xFF000; loval &= 0x07FFF; hival |= ( (address >> 5) & 0x00FFF); loval |= ( (address << 15) & 0xF8000); address = (hival & 0x00FFF) << 5; address |= loval >> 15; dev_dbg(chip->card->dev, "handle_wideop:[2] %05x:%05x addr %04x\n", hival, loval, address); nreallocated++; } /* wide_opcodes[j] == wide_op */ } /* for */ } /* mod_type == 0 ... */ } /* ins->code.offset > 0 */ ins->code.data[ins->code.size++] = loval; ins->code.data[ins->code.size++] = hival; } dev_dbg(chip->card->dev, "dsp_spos: %d instructions reallocated\n", nreallocated); return nreallocated; } static struct dsp_segment_desc * get_segment_desc (struct dsp_module_desc * module, int seg_type) { int i; for (i = 0;i < module->nsegments; ++i) { if (module->segments[i].segment_type == seg_type) { return (module->segments + i); } } return NULL; }; static int find_free_symbol_index (struct dsp_spos_instance * ins) { int index = ins->symbol_table.nsymbols,i; for (i = ins->symbol_table.highest_frag_index; i < ins->symbol_table.nsymbols; ++i) { if (ins->symbol_table.symbols[i].deleted) { index = i; break; } } return index; } static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * module) { int i; struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (module->symbol_table.nsymbols > 0) { if (!strcmp(module->symbol_table.symbols[0].symbol_name, "OVERLAYBEGINADDRESS") && module->symbol_table.symbols[0].symbol_type == SYMBOL_CONSTANT ) { module->overlay_begin_address = module->symbol_table.symbols[0].address; } } for (i = 0;i < module->symbol_table.nsymbols; ++i) { if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) { dev_err(chip->card->dev, "dsp_spos: symbol table is full\n"); return -ENOMEM; } if (cs46xx_dsp_lookup_symbol(chip, module->symbol_table.symbols[i].symbol_name, module->symbol_table.symbols[i].symbol_type) == NULL) { ins->symbol_table.symbols[ins->symbol_table.nsymbols] = module->symbol_table.symbols[i]; ins->symbol_table.symbols[ins->symbol_table.nsymbols].address += ((ins->code.offset / 2) - module->overlay_begin_address); ins->symbol_table.symbols[ins->symbol_table.nsymbols].module = module; ins->symbol_table.symbols[ins->symbol_table.nsymbols].deleted = 0; if (ins->symbol_table.nsymbols > ins->symbol_table.highest_frag_index) ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols; ins->symbol_table.nsymbols++; } else { #if 0 dev_dbg(chip->card->dev, "dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n", module->symbol_table.symbols[i].symbol_name); */ #endif } } return 0; } static struct dsp_symbol_entry * add_symbol (struct snd_cs46xx * chip, char * symbol_name, u32 address, int type) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_symbol_entry * symbol = NULL; int index; if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) { dev_err(chip->card->dev, "dsp_spos: symbol table is full\n"); return NULL; } if (cs46xx_dsp_lookup_symbol(chip, symbol_name, type) != NULL) { dev_err(chip->card->dev, "dsp_spos: symbol <%s> duplicated\n", symbol_name); return NULL; } index = find_free_symbol_index (ins); strcpy (ins->symbol_table.symbols[index].symbol_name, symbol_name); ins->symbol_table.symbols[index].address = address; ins->symbol_table.symbols[index].symbol_type = type; ins->symbol_table.symbols[index].module = NULL; ins->symbol_table.symbols[index].deleted = 0; symbol = (ins->symbol_table.symbols + index); if (index > ins->symbol_table.highest_frag_index) ins->symbol_table.highest_frag_index = index; if (index == ins->symbol_table.nsymbols) ins->symbol_table.nsymbols++; /* no frag. in list */ return symbol; } struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip) { struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL); if (ins == NULL) return NULL; /* better to use vmalloc for this big table */ ins->symbol_table.symbols = vmalloc(array_size(DSP_MAX_SYMBOLS, sizeof(struct dsp_symbol_entry))); ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL); ins->modules = kmalloc_array(DSP_MAX_MODULES, sizeof(struct dsp_module_desc), GFP_KERNEL); if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) { cs46xx_dsp_spos_destroy(chip); goto error; } ins->symbol_table.nsymbols = 0; ins->symbol_table.highest_frag_index = 0; ins->code.offset = 0; ins->code.size = 0; ins->nscb = 0; ins->ntask = 0; ins->nmodules = 0; /* default SPDIF input sample rate to 48000 khz */ ins->spdif_in_sample_rate = 48000; /* maximize volume */ ins->dac_volume_right = 0x8000; ins->dac_volume_left = 0x8000; ins->spdif_input_volume_right = 0x8000; ins->spdif_input_volume_left = 0x8000; /* set left and right validity bits and default channel status */ ins->spdif_csuv_default = ins->spdif_csuv_stream = /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) | /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) | /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) | /* left and right validity bits */ (1 << 13) | (1 << 12); return ins; error: kfree(ins->modules); kfree(ins->code.data); vfree(ins->symbol_table.symbols); kfree(ins); return NULL; } void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip) { int i; struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(!ins)) return; mutex_lock(&chip->spos_mutex); for (i = 0; i < ins->nscb; ++i) { if (ins->scbs[i].deleted) continue; cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); #ifdef CONFIG_PM_SLEEP kfree(ins->scbs[i].data); #endif } kfree(ins->code.data); vfree(ins->symbol_table.symbols); kfree(ins->modules); kfree(ins); mutex_unlock(&chip->spos_mutex); } static int dsp_load_parameter(struct snd_cs46xx *chip, struct dsp_segment_desc *parameter) { u32 doffset, dsize; if (!parameter) { dev_dbg(chip->card->dev, "dsp_spos: module got no parameter segment\n"); return 0; } doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET); dsize = parameter->size * 4; dev_dbg(chip->card->dev, "dsp_spos: downloading parameter data to chip (%08x-%08x)\n", doffset,doffset + dsize); if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) { dev_err(chip->card->dev, "dsp_spos: failed to download parameter data to DSP\n"); return -EINVAL; } return 0; } static int dsp_load_sample(struct snd_cs46xx *chip, struct dsp_segment_desc *sample) { u32 doffset, dsize; if (!sample) { dev_dbg(chip->card->dev, "dsp_spos: module got no sample segment\n"); return 0; } doffset = (sample->offset * 4 + DSP_SAMPLE_BYTE_OFFSET); dsize = sample->size * 4; dev_dbg(chip->card->dev, "dsp_spos: downloading sample data to chip (%08x-%08x)\n", doffset,doffset + dsize); if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) { dev_err(chip->card->dev, "dsp_spos: failed to sample data to DSP\n"); return -EINVAL; } return 0; } int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_segment_desc * code = get_segment_desc (module,SEGTYPE_SP_PROGRAM); u32 doffset, dsize; int err; if (ins->nmodules == DSP_MAX_MODULES - 1) { dev_err(chip->card->dev, "dsp_spos: to many modules loaded into DSP\n"); return -ENOMEM; } dev_dbg(chip->card->dev, "dsp_spos: loading module %s into DSP\n", module->module_name); if (ins->nmodules == 0) { dev_dbg(chip->card->dev, "dsp_spos: clearing parameter area\n"); snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE); } err = dsp_load_parameter(chip, get_segment_desc(module, SEGTYPE_SP_PARAMETER)); if (err < 0) return err; if (ins->nmodules == 0) { dev_dbg(chip->card->dev, "dsp_spos: clearing sample area\n"); snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE); } err = dsp_load_sample(chip, get_segment_desc(module, SEGTYPE_SP_SAMPLE)); if (err < 0) return err; if (ins->nmodules == 0) { dev_dbg(chip->card->dev, "dsp_spos: clearing code area\n"); snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE); } if (code == NULL) { dev_dbg(chip->card->dev, "dsp_spos: module got no code segment\n"); } else { if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) { dev_err(chip->card->dev, "dsp_spos: no space available in DSP\n"); return -ENOMEM; } module->load_address = ins->code.offset; module->overlay_begin_address = 0x000; /* if module has a code segment it must have symbol table */ if (snd_BUG_ON(!module->symbol_table.symbols)) return -ENOMEM; if (add_symbols(chip,module)) { dev_err(chip->card->dev, "dsp_spos: failed to load symbol table\n"); return -ENOMEM; } doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET); dsize = code->size * 4; dev_dbg(chip->card->dev, "dsp_spos: downloading code to chip (%08x-%08x)\n", doffset,doffset + dsize); module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address); if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) { dev_err(chip->card->dev, "dsp_spos: failed to download code to DSP\n"); return -EINVAL; } ins->code.offset += code->size; } /* NOTE: module segments and symbol table must be statically allocated. Case that module data is not generated by the ospparser */ ins->modules[ins->nmodules] = *module; ins->nmodules++; return 0; } struct dsp_symbol_entry * cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, int symbol_type) { int i; struct dsp_spos_instance * ins = chip->dsp_spos_instance; for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) { if (ins->symbol_table.symbols[i].deleted) continue; if (!strcmp(ins->symbol_table.symbols[i].symbol_name,symbol_name) && ins->symbol_table.symbols[i].symbol_type == symbol_type) { return (ins->symbol_table.symbols + i); } } #if 0 dev_err(chip->card->dev, "dsp_spos: symbol <%s> type %02x not found\n", symbol_name,symbol_type); #endif return NULL; } #ifdef CONFIG_SND_PROC_FS static struct dsp_symbol_entry * cs46xx_dsp_lookup_symbol_addr (struct snd_cs46xx * chip, u32 address, int symbol_type) { int i; struct dsp_spos_instance * ins = chip->dsp_spos_instance; for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) { if (ins->symbol_table.symbols[i].deleted) continue; if (ins->symbol_table.symbols[i].address == address && ins->symbol_table.symbols[i].symbol_type == symbol_type) { return (ins->symbol_table.symbols + i); } } return NULL; } static void cs46xx_dsp_proc_symbol_table_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i; snd_iprintf(buffer, "SYMBOLS:\n"); for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) { char *module_str = "system"; if (ins->symbol_table.symbols[i].deleted) continue; if (ins->symbol_table.symbols[i].module != NULL) { module_str = ins->symbol_table.symbols[i].module->module_name; } snd_iprintf(buffer, "%04X <%02X> %s [%s]\n", ins->symbol_table.symbols[i].address, ins->symbol_table.symbols[i].symbol_type, ins->symbol_table.symbols[i].symbol_name, module_str); } } static void cs46xx_dsp_proc_modules_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i,j; mutex_lock(&chip->spos_mutex); snd_iprintf(buffer, "MODULES:\n"); for ( i = 0; i < ins->nmodules; ++i ) { snd_iprintf(buffer, "\n%s:\n", ins->modules[i].module_name); snd_iprintf(buffer, " %d symbols\n", ins->modules[i].symbol_table.nsymbols); snd_iprintf(buffer, " %d fixups\n", ins->modules[i].nfixups); for (j = 0; j < ins->modules[i].nsegments; ++ j) { struct dsp_segment_desc * desc = (ins->modules[i].segments + j); snd_iprintf(buffer, " segment %02x offset %08x size %08x\n", desc->segment_type,desc->offset, desc->size); } } mutex_unlock(&chip->spos_mutex); } static void cs46xx_dsp_proc_task_tree_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i, j, col; void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET; mutex_lock(&chip->spos_mutex); snd_iprintf(buffer, "TASK TREES:\n"); for ( i = 0; i < ins->ntask; ++i) { snd_iprintf(buffer,"\n%04x %s:\n",ins->tasks[i].address,ins->tasks[i].task_name); for (col = 0,j = 0;j < ins->tasks[i].size; j++,col++) { u32 val; if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } val = readl(dst + (ins->tasks[i].address + j) * sizeof(u32)); snd_iprintf(buffer,"%08x ",val); } } snd_iprintf(buffer,"\n"); mutex_unlock(&chip->spos_mutex); } static void cs46xx_dsp_proc_scb_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i; mutex_lock(&chip->spos_mutex); snd_iprintf(buffer, "SCB's:\n"); for ( i = 0; i < ins->nscb; ++i) { if (ins->scbs[i].deleted) continue; snd_iprintf(buffer,"\n%04x %s:\n\n",ins->scbs[i].address,ins->scbs[i].scb_name); if (ins->scbs[i].parent_scb_ptr != NULL) { snd_iprintf(buffer,"parent [%s:%04x] ", ins->scbs[i].parent_scb_ptr->scb_name, ins->scbs[i].parent_scb_ptr->address); } else snd_iprintf(buffer,"parent [none] "); snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n", ins->scbs[i].sub_list_ptr->scb_name, ins->scbs[i].sub_list_ptr->address, ins->scbs[i].next_scb_ptr->scb_name, ins->scbs[i].next_scb_ptr->address, ins->scbs[i].task_entry->symbol_name, ins->scbs[i].task_entry->address); } snd_iprintf(buffer,"\n"); mutex_unlock(&chip->spos_mutex); } static void cs46xx_dsp_proc_parameter_dump_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; /*struct dsp_spos_instance * ins = chip->dsp_spos_instance; */ unsigned int i, col = 0; void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET; struct dsp_symbol_entry * symbol; for (i = 0;i < DSP_PARAMETER_BYTE_SIZE; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } symbol = cs46xx_dsp_lookup_symbol_addr(chip, i / sizeof(u32), SYMBOL_PARAMETER); if (symbol) { col = 0; snd_iprintf (buffer,"\n%s:\n",symbol->symbol_name); } if (col == 0) { snd_iprintf(buffer, "%04X ", i / (unsigned int)sizeof(u32)); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } } static void cs46xx_dsp_proc_sample_dump_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_cs46xx *chip = entry->private_data; int i,col = 0; void __iomem *dst = chip->region.idx[2].remap_addr; snd_iprintf(buffer,"PCMREADER:\n"); for (i = PCM_READER_BUF1;i < PCM_READER_BUF1 + 0x30; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\nMIX_SAMPLE_BUF1:\n"); col = 0; for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x40; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\nSRC_TASK_SCB1:\n"); col = 0; for (i = 0x2480 ; i < 0x2480 + 0x40 ; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\nSPDIFO_BUFFER:\n"); col = 0; for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x30; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\n...\n"); col = 0; for (i = SPDIFO_IP_OUTPUT_BUFFER1+0xD0;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x110; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\nOUTPUT_SNOOP:\n"); col = 0; for (i = OUTPUT_SNOOP_BUFFER;i < OUTPUT_SNOOP_BUFFER + 0x40; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\nCODEC_INPUT_BUF1: \n"); col = 0; for (i = CODEC_INPUT_BUF1;i < CODEC_INPUT_BUF1 + 0x40; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } #if 0 snd_iprintf(buffer,"\nWRITE_BACK_BUF1: \n"); col = 0; for (i = WRITE_BACK_BUF1;i < WRITE_BACK_BUF1 + 0x40; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } #endif snd_iprintf(buffer,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n"); col = 0; for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x80; i += sizeof(u32),col ++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } if (col == 0) { snd_iprintf(buffer, "%04X ",i); } snd_iprintf(buffer,"%08X ",readl(dst + i)); } snd_iprintf(buffer,"\n"); } int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip) { struct snd_info_entry *entry; struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i; ins->snd_card = card; entry = snd_info_create_card_entry(card, "dsp", card->proc_root); if (entry) entry->mode = S_IFDIR | 0555; ins->proc_dsp_dir = entry; if (!ins->proc_dsp_dir) return -ENOMEM; entry = snd_info_create_card_entry(card, "spos_symbols", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_symbol_table_read); entry = snd_info_create_card_entry(card, "spos_modules", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_modules_read); entry = snd_info_create_card_entry(card, "parameter", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_parameter_dump_read); entry = snd_info_create_card_entry(card, "sample", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_sample_dump_read); entry = snd_info_create_card_entry(card, "task_tree", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_task_tree_read); entry = snd_info_create_card_entry(card, "scb_info", ins->proc_dsp_dir); if (entry) snd_info_set_text_ops(entry, chip, cs46xx_dsp_proc_scb_read); mutex_lock(&chip->spos_mutex); /* register/update SCB's entries on proc */ for (i = 0; i < ins->nscb; ++i) { if (ins->scbs[i].deleted) continue; cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i)); } mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_proc_done (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i; if (!ins) return 0; mutex_lock(&chip->spos_mutex); for (i = 0; i < ins->nscb; ++i) { if (ins->scbs[i].deleted) continue; cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } mutex_unlock(&chip->spos_mutex); snd_info_free_entry(ins->proc_dsp_dir); ins->proc_dsp_dir = NULL; return 0; } #endif /* CONFIG_SND_PROC_FS */ static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data, u32 dest, int size) { void __iomem *spdst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32); int i; for (i = 0; i < size; ++i) { dev_dbg(chip->card->dev, "addr %p, val %08x\n", spdst, task_data[i]); writel(task_data[i],spdst); spdst += sizeof(u32); } } static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest) { void __iomem *spdst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32); int i; for (i = 0; i < 0x10; ++i) { dev_dbg(chip->card->dev, "addr %p, val %08x\n", spdst, scb_data[i]); writel(scb_data[i],spdst); spdst += sizeof(u32); } } static int find_free_scb_index (struct dsp_spos_instance * ins) { int index = ins->nscb, i; for (i = ins->scb_highest_frag_index; i < ins->nscb; ++i) { if (ins->scbs[i].deleted) { index = i; break; } } return index; } static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * name, u32 dest) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * desc = NULL; int index; if (ins->nscb == DSP_MAX_SCB_DESC - 1) { dev_err(chip->card->dev, "dsp_spos: got no place for other SCB\n"); return NULL; } index = find_free_scb_index (ins); memset(&ins->scbs[index], 0, sizeof(ins->scbs[index])); strcpy(ins->scbs[index].scb_name, name); ins->scbs[index].address = dest; ins->scbs[index].index = index; ins->scbs[index].ref_count = 1; desc = (ins->scbs + index); ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER); if (index > ins->scb_highest_frag_index) ins->scb_highest_frag_index = index; if (index == ins->nscb) ins->nscb++; return desc; } static struct dsp_task_descriptor * _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_task_descriptor * desc = NULL; if (ins->ntask == DSP_MAX_TASK_DESC - 1) { dev_err(chip->card->dev, "dsp_spos: got no place for other TASK\n"); return NULL; } if (name) strcpy(ins->tasks[ins->ntask].task_name, name); else strcpy(ins->tasks[ins->ntask].task_name, "(NULL)"); ins->tasks[ins->ntask].address = dest; ins->tasks[ins->ntask].size = size; /* quick find in list */ ins->tasks[ins->ntask].index = ins->ntask; desc = (ins->tasks + ins->ntask); ins->ntask++; if (name) add_symbol (chip,name,dest,SYMBOL_PARAMETER); return desc; } #define SCB_BYTES (0x10 * 4) struct dsp_scb_descriptor * cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest) { struct dsp_scb_descriptor * desc; #ifdef CONFIG_PM_SLEEP /* copy the data for resume */ scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL); if (!scb_data) return NULL; #endif desc = _map_scb (chip,name,dest); if (desc) { desc->data = scb_data; _dsp_create_scb(chip,scb_data,dest); } else { dev_err(chip->card->dev, "dsp_spos: failed to map SCB\n"); #ifdef CONFIG_PM_SLEEP kfree(scb_data); #endif } return desc; } static struct dsp_task_descriptor * cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_data, u32 dest, int size) { struct dsp_task_descriptor * desc; desc = _map_task_tree (chip,name,dest,size); if (desc) { desc->data = task_data; _dsp_create_task_tree(chip,task_data,dest,size); } else { dev_err(chip->card->dev, "dsp_spos: failed to map TASK\n"); } return desc; } int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_symbol_entry * fg_task_tree_header_code; struct dsp_symbol_entry * task_tree_header_code; struct dsp_symbol_entry * task_tree_thread; struct dsp_symbol_entry * null_algorithm; struct dsp_symbol_entry * magic_snoop_task; struct dsp_scb_descriptor * timing_master_scb; struct dsp_scb_descriptor * codec_out_scb; struct dsp_scb_descriptor * codec_in_scb; struct dsp_scb_descriptor * src_task_scb; struct dsp_scb_descriptor * master_mix_scb; struct dsp_scb_descriptor * rear_mix_scb; struct dsp_scb_descriptor * record_mix_scb; struct dsp_scb_descriptor * write_back_scb; struct dsp_scb_descriptor * vari_decimate_scb; struct dsp_scb_descriptor * rear_codec_out_scb; struct dsp_scb_descriptor * clfe_codec_out_scb; struct dsp_scb_descriptor * magic_snoop_scb; int fifo_addr, fifo_span, valid_slots; static const struct dsp_spos_control_block sposcb = { /* 0 */ HFG_TREE_SCB,HFG_STACK, /* 1 */ SPOSCB_ADDR,BG_TREE_SCB_ADDR, /* 2 */ DSP_SPOS_DC,0, /* 3 */ DSP_SPOS_DC,DSP_SPOS_DC, /* 4 */ 0,0, /* 5 */ DSP_SPOS_UU,0, /* 6 */ FG_TASK_HEADER_ADDR,0, /* 7 */ 0,0, /* 8 */ DSP_SPOS_UU,DSP_SPOS_DC, /* 9 */ 0, /* A */ 0,HFG_FIRST_EXECUTE_MODE, /* B */ DSP_SPOS_UU,DSP_SPOS_UU, /* C */ DSP_SPOS_DC_DC, /* D */ DSP_SPOS_DC_DC, /* E */ DSP_SPOS_DC_DC, /* F */ DSP_SPOS_DC_DC }; cs46xx_dsp_create_task_tree(chip, "sposCB", (u32 *)&sposcb, SPOSCB_ADDR, 0x10); null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE); if (null_algorithm == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol NULLALGORITHM not found\n"); return -EIO; } fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE); if (fg_task_tree_header_code == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n"); return -EIO; } task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE); if (task_tree_header_code == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol TASKTREEHEADERCODE not found\n"); return -EIO; } task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE); if (task_tree_thread == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol TASKTREETHREAD not found\n"); return -EIO; } magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE); if (magic_snoop_task == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol MAGICSNOOPTASK not found\n"); return -EIO; } { /* create the null SCB */ static struct dsp_generic_scb null_scb = { { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, NULL_SCB_ADDR, NULL_SCB_ADDR, 0, 0, 0, 0, 0, { 0,0, 0,0, } }; null_scb.entry_point = null_algorithm->address; ins->the_null_scb = cs46xx_dsp_create_scb(chip, "nullSCB", (u32 *)&null_scb, NULL_SCB_ADDR); ins->the_null_scb->task_entry = null_algorithm; ins->the_null_scb->sub_list_ptr = ins->the_null_scb; ins->the_null_scb->next_scb_ptr = ins->the_null_scb; ins->the_null_scb->parent_scb_ptr = NULL; cs46xx_dsp_proc_register_scb_desc (chip,ins->the_null_scb); } { /* setup foreground task tree */ static struct dsp_task_tree_control_block fg_task_tree_hdr = { { FG_TASK_HEADER_ADDR | (DSP_SPOS_DC << 0x10), DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, 0x0000,DSP_SPOS_DC, DSP_SPOS_DC, DSP_SPOS_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC,DSP_SPOS_DC }, { BG_TREE_SCB_ADDR,TIMINGMASTER_SCB_ADDR, 0, FG_TASK_HEADER_ADDR + TCBData, }, { 4,0, 1,0, 2,SPOSCB_ADDR + HFGFlags, 0,0, FG_TASK_HEADER_ADDR + TCBContextBlk,FG_STACK }, { DSP_SPOS_DC,0, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DCDC, DSP_SPOS_UU,1, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC }, { FG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU, 0,0 } }; fg_task_tree_hdr.links.entry_point = fg_task_tree_header_code->address; fg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address; cs46xx_dsp_create_task_tree(chip,"FGtaskTreeHdr",(u32 *)&fg_task_tree_hdr,FG_TASK_HEADER_ADDR,0x35); } { /* setup foreground task tree */ static struct dsp_task_tree_control_block bg_task_tree_hdr = { { DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC, DSP_SPOS_DC, DSP_SPOS_DC, DSP_SPOS_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC_DC, DSP_SPOS_DC,DSP_SPOS_DC }, { NULL_SCB_ADDR,NULL_SCB_ADDR, /* Set up the background to do nothing */ 0, BG_TREE_SCB_ADDR + TCBData, }, { 9999,0, 0,1, 0,SPOSCB_ADDR + HFGFlags, 0,0, BG_TREE_SCB_ADDR + TCBContextBlk,BG_STACK }, { DSP_SPOS_DC,0, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DC,DSP_SPOS_DC, DSP_SPOS_DCDC, DSP_SPOS_UU,1, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC, DSP_SPOS_DCDC }, { BG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU, 0,0 } }; bg_task_tree_hdr.links.entry_point = task_tree_header_code->address; bg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address; cs46xx_dsp_create_task_tree(chip,"BGtaskTreeHdr",(u32 *)&bg_task_tree_hdr,BG_TREE_SCB_ADDR,0x35); } /* create timing master SCB */ timing_master_scb = cs46xx_dsp_create_timing_master_scb(chip); /* create the CODEC output task */ codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_I",0x0010,0x0000, MASTERMIX_SCB_ADDR, CODECOUT_SCB_ADDR,timing_master_scb, SCB_ON_PARENT_SUBLIST_SCB); if (!codec_out_scb) goto _fail_end; /* create the master mix SCB */ master_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"MasterMixSCB", MIX_SAMPLE_BUF1,MASTERMIX_SCB_ADDR, codec_out_scb, SCB_ON_PARENT_SUBLIST_SCB); ins->master_mix_scb = master_mix_scb; if (!master_mix_scb) goto _fail_end; /* create codec in */ codec_in_scb = cs46xx_dsp_create_codec_in_scb(chip,"CodecInSCB",0x0010,0x00A0, CODEC_INPUT_BUF1, CODECIN_SCB_ADDR,codec_out_scb, SCB_ON_PARENT_NEXT_SCB); if (!codec_in_scb) goto _fail_end; ins->codec_in_scb = codec_in_scb; /* create write back scb */ write_back_scb = cs46xx_dsp_create_mix_to_ostream_scb(chip,"WriteBackSCB", WRITE_BACK_BUF1,WRITE_BACK_SPB, WRITEBACK_SCB_ADDR, timing_master_scb, SCB_ON_PARENT_NEXT_SCB); if (!write_back_scb) goto _fail_end; { static struct dsp_mix2_ostream_spb mix2_ostream_spb = { 0x00020000, 0x0000ffff }; if (!cs46xx_dsp_create_task_tree(chip, NULL, (u32 *)&mix2_ostream_spb, WRITE_BACK_SPB, 2)) goto _fail_end; } /* input sample converter */ vari_decimate_scb = cs46xx_dsp_create_vari_decimate_scb(chip,"VariDecimateSCB", VARI_DECIMATE_BUF0, VARI_DECIMATE_BUF1, VARIDECIMATE_SCB_ADDR, write_back_scb, SCB_ON_PARENT_SUBLIST_SCB); if (!vari_decimate_scb) goto _fail_end; /* create the record mixer SCB */ record_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RecordMixerSCB", MIX_SAMPLE_BUF2, RECORD_MIXER_SCB_ADDR, vari_decimate_scb, SCB_ON_PARENT_SUBLIST_SCB); ins->record_mixer_scb = record_mix_scb; if (!record_mix_scb) goto _fail_end; valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV); if (snd_BUG_ON(chip->nr_ac97_codecs != 1 && chip->nr_ac97_codecs != 2)) goto _fail_end; if (chip->nr_ac97_codecs == 1) { /* output on slot 5 and 11 on primary CODEC */ fifo_addr = 0x20; fifo_span = 0x60; /* enable slot 5 and 11 */ valid_slots |= ACOSV_SLV5 | ACOSV_SLV11; } else { /* output on slot 7 and 8 on secondary CODEC */ fifo_addr = 0x40; fifo_span = 0x10; /* enable slot 7 and 8 */ valid_slots |= ACOSV_SLV7 | ACOSV_SLV8; } /* create CODEC tasklet for rear speakers output*/ rear_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_Rear",fifo_span,fifo_addr, REAR_MIXER_SCB_ADDR, REAR_CODECOUT_SCB_ADDR,codec_in_scb, SCB_ON_PARENT_NEXT_SCB); if (!rear_codec_out_scb) goto _fail_end; /* create the rear PCM channel mixer SCB */ rear_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RearMixerSCB", MIX_SAMPLE_BUF3, REAR_MIXER_SCB_ADDR, rear_codec_out_scb, SCB_ON_PARENT_SUBLIST_SCB); ins->rear_mix_scb = rear_mix_scb; if (!rear_mix_scb) goto _fail_end; if (chip->nr_ac97_codecs == 2) { /* create CODEC tasklet for rear Center/LFE output slot 6 and 9 on secondary CODEC */ clfe_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_CLFE",0x0030,0x0030, CLFE_MIXER_SCB_ADDR, CLFE_CODEC_SCB_ADDR, rear_codec_out_scb, SCB_ON_PARENT_NEXT_SCB); if (!clfe_codec_out_scb) goto _fail_end; /* create the rear PCM channel mixer SCB */ ins->center_lfe_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"CLFEMixerSCB", MIX_SAMPLE_BUF4, CLFE_MIXER_SCB_ADDR, clfe_codec_out_scb, SCB_ON_PARENT_SUBLIST_SCB); if (!ins->center_lfe_mix_scb) goto _fail_end; /* enable slot 6 and 9 */ valid_slots |= ACOSV_SLV6 | ACOSV_SLV9; } else { clfe_codec_out_scb = rear_codec_out_scb; ins->center_lfe_mix_scb = rear_mix_scb; } /* enable slots depending on CODEC configuration */ snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots); /* the magic snooper */ magic_snoop_scb = cs46xx_dsp_create_magic_snoop_scb (chip,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR, OUTPUT_SNOOP_BUFFER, codec_out_scb, clfe_codec_out_scb, SCB_ON_PARENT_NEXT_SCB); if (!magic_snoop_scb) goto _fail_end; ins->ref_snoop_scb = magic_snoop_scb; /* SP IO access */ if (!cs46xx_dsp_create_spio_write_scb(chip,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR, magic_snoop_scb, SCB_ON_PARENT_NEXT_SCB)) goto _fail_end; /* SPDIF input sampel rate converter */ src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI", ins->spdif_in_sample_rate, SRC_OUTPUT_BUF1, SRC_DELAY_BUF1,SRCTASK_SCB_ADDR, master_mix_scb, SCB_ON_PARENT_SUBLIST_SCB,1); if (!src_task_scb) goto _fail_end; cs46xx_src_unlink(chip,src_task_scb); /* NOTE: when we now how to detect the SPDIF input sample rate we will use this SRC to adjust it */ ins->spdif_in_src = src_task_scb; cs46xx_dsp_async_init(chip,timing_master_scb); return 0; _fail_end: dev_err(chip->card->dev, "dsp_spos: failed to setup SCB's in DSP\n"); return -EINVAL; } static int cs46xx_dsp_async_init (struct snd_cs46xx *chip, struct dsp_scb_descriptor * fg_entry) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_symbol_entry * s16_async_codec_input_task; struct dsp_symbol_entry * spdifo_task; struct dsp_symbol_entry * spdifi_task; struct dsp_scb_descriptor * spdifi_scb_desc, * spdifo_scb_desc, * async_codec_scb_desc; s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE); if (s16_async_codec_input_task == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n"); return -EIO; } spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE); if (spdifo_task == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol SPDIFOTASK not found\n"); return -EIO; } spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE); if (spdifi_task == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol SPDIFITASK not found\n"); return -EIO; } { /* 0xBC0 */ struct dsp_spdifoscb spdifo_scb = { /* 0 */ DSP_SPOS_UUUU, { /* 1 */ 0xb0, /* 2 */ 0, /* 3 */ 0, /* 4 */ 0, }, /* NOTE: the SPDIF output task read samples in mono format, the AsynchFGTxSCB task writes to buffer in stereo format */ /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_256, /* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1 << 0x10 ) | 0xFFFC, /* 7 */ 0,0, /* 8 */ 0, /* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR, /* A */ spdifo_task->address, SPDIFO_SCB_INST + SPDIFOFIFOPointer, { /* B */ 0x0040, /*DSP_SPOS_UUUU,*/ /* C */ 0x20ff, /*DSP_SPOS_UUUU,*/ }, /* D */ 0x804c,0, /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */ /* E */ 0x0108,0x0001, /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */ /* F */ DSP_SPOS_UUUU /* SPDIFOFree; */ }; /* 0xBB0 */ struct dsp_spdifiscb spdifi_scb = { /* 0 */ DSP_SPOS_UULO,DSP_SPOS_UUHI, /* 1 */ 0, /* 2 */ 0, /* 3 */ 1,4000, /* SPDIFICountLimit SPDIFICount */ /* 4 */ DSP_SPOS_UUUU, /* SPDIFIStatusData */ /* 5 */ 0,DSP_SPOS_UUHI, /* StatusData, Free4 */ /* 6 */ DSP_SPOS_UUUU, /* Free3 */ /* 7 */ DSP_SPOS_UU,DSP_SPOS_DC, /* Free2 BitCount*/ /* 8 */ DSP_SPOS_UUUU, /* TempStatus */ /* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR, /* A */ spdifi_task->address, SPDIFI_SCB_INST + SPDIFIFIFOPointer, /* NOTE: The SPDIF input task write the sample in mono format from the HW FIFO, the AsynchFGRxSCB task reads them in stereo */ /* B */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_128, /* C */ (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC, /* D */ 0x8048,0, /* E */ 0x01f0,0x0001, /* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */ }; /* 0xBA0 */ struct dsp_async_codec_input_scb async_codec_input_scb = { /* 0 */ DSP_SPOS_UUUU, /* 1 */ 0, /* 2 */ 0, /* 3 */ 1,4000, /* 4 */ 0x0118,0x0001, /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_64, /* 6 */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC, /* 7 */ DSP_SPOS_UU,0x3, /* 8 */ DSP_SPOS_UUUU, /* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR, /* A */ s16_async_codec_input_task->address, HFG_TREE_SCB + AsyncCIOFIFOPointer, /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, /* C */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10), /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/ #ifdef UseASER1Input /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr; Init. 0000:8042: for ASER1 0000:8044: for ASER2 */ /* D */ 0x8042,0, /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr; Init 1 stero:8050 ASER1 Init 0 mono:8070 ASER2 Init 1 Stereo : 0100 ASER1 (Set by script) */ /* E */ 0x0100,0x0001, #endif #ifdef UseASER2Input /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr; Init. 0000:8042: for ASER1 0000:8044: for ASER2 */ /* D */ 0x8044,0, /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr; Init 1 stero:8050 ASER1 Init 0 mono:8070 ASER2 Init 1 Stereo : 0100 ASER1 (Set by script) */ /* E */ 0x0110,0x0001, #endif /* short AsyncCIOutputBufModulo:AsyncCIFree; AsyncCIOutputBufModulo: The modulo size for the output buffer of this task */ /* F */ 0, /* DSP_SPOS_UUUU */ }; spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST); if (snd_BUG_ON(!spdifo_scb_desc)) return -EIO; spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST); if (snd_BUG_ON(!spdifi_scb_desc)) return -EIO; async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB); if (snd_BUG_ON(!async_codec_scb_desc)) return -EIO; async_codec_scb_desc->parent_scb_ptr = NULL; async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc; async_codec_scb_desc->sub_list_ptr = ins->the_null_scb; async_codec_scb_desc->task_entry = s16_async_codec_input_task; spdifi_scb_desc->parent_scb_ptr = async_codec_scb_desc; spdifi_scb_desc->next_scb_ptr = spdifo_scb_desc; spdifi_scb_desc->sub_list_ptr = ins->the_null_scb; spdifi_scb_desc->task_entry = spdifi_task; spdifo_scb_desc->parent_scb_ptr = spdifi_scb_desc; spdifo_scb_desc->next_scb_ptr = fg_entry; spdifo_scb_desc->sub_list_ptr = ins->the_null_scb; spdifo_scb_desc->task_entry = spdifo_task; /* this one is faked, as the parnet of SPDIFO task is the FG task tree */ fg_entry->parent_scb_ptr = spdifo_scb_desc; /* for proc fs */ cs46xx_dsp_proc_register_scb_desc (chip,spdifo_scb_desc); cs46xx_dsp_proc_register_scb_desc (chip,spdifi_scb_desc); cs46xx_dsp_proc_register_scb_desc (chip,async_codec_scb_desc); /* Async MASTER ENABLE, affects both SPDIF input and output */ snd_cs46xx_pokeBA0(chip, BA0_ASER_MASTER, 0x1 ); } return 0; } static void cs46xx_dsp_disable_spdif_hw (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; /* set SPDIF output FIFO slot */ snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, 0); /* SPDIF output MASTER ENABLE */ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0); /* right and left validate bit */ /*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x0); /* clear fifo pointer */ cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0); /* monitor state */ ins->spdif_status_out &= ~DSP_SPDIF_STATUS_HW_ENABLED; } int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; /* if hw-ctrl already enabled, turn off to reset logic ... */ cs46xx_dsp_disable_spdif_hw (chip); udelay(50); /* set SPDIF output FIFO slot */ snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, ( 0x8000 | ((SP_SPDOUT_FIFO >> 4) << 4) )); /* SPDIF output MASTER ENABLE */ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000); /* right and left validate bit */ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default); /* monitor state */ ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED; return 0; } int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; /* turn on amplifier */ chip->active_ctrl(chip, 1); chip->amplifier_ctrl(chip, 1); if (snd_BUG_ON(ins->asynch_rx_scb)) return -EINVAL; if (snd_BUG_ON(!ins->spdif_in_src)) return -EINVAL; mutex_lock(&chip->spos_mutex); if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) { /* time countdown enable */ cs46xx_poke_via_dsp (chip,SP_ASER_COUNTDOWN, 0x80000005); /* NOTE: 80000005 value is just magic. With all values that I've tested this one seem to give the best result. Got no explication why. (Benny) */ /* SPDIF input MASTER ENABLE */ cs46xx_poke_via_dsp (chip,SP_SPDIN_CONTROL, 0x800003ff); ins->spdif_status_out |= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED; } /* create and start the asynchronous receiver SCB */ ins->asynch_rx_scb = cs46xx_dsp_create_asynch_fg_rx_scb(chip,"AsynchFGRxSCB", ASYNCRX_SCB_ADDR, SPDIFI_SCB_INST, SPDIFI_IP_OUTPUT_BUFFER1, ins->spdif_in_src, SCB_ON_PARENT_SUBLIST_SCB); spin_lock_irq(&chip->reg_lock); /* reset SPDIF input sample buffer pointer */ /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2, (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/ /* reset FIFO ptr */ /*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/ cs46xx_src_link(chip,ins->spdif_in_src); /* unmute SRC volume */ cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff); spin_unlock_irq(&chip->reg_lock); /* set SPDIF input sample rate and unmute NOTE: only 48khz support for SPDIF input this time */ /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */ /* monitor state */ ins->spdif_status_in = 1; mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(!ins->asynch_rx_scb)) return -EINVAL; if (snd_BUG_ON(!ins->spdif_in_src)) return -EINVAL; mutex_lock(&chip->spos_mutex); /* Remove the asynchronous receiver SCB */ cs46xx_dsp_remove_scb (chip,ins->asynch_rx_scb); ins->asynch_rx_scb = NULL; cs46xx_src_unlink(chip,ins->spdif_in_src); /* monitor state */ ins->spdif_status_in = 0; mutex_unlock(&chip->spos_mutex); /* restore amplifier */ chip->active_ctrl(chip, -1); chip->amplifier_ctrl(chip, -1); return 0; } int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(ins->pcm_input)) return -EINVAL; if (snd_BUG_ON(!ins->ref_snoop_scb)) return -EINVAL; mutex_lock(&chip->spos_mutex); ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR, "PCMSerialInput_Wave"); mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(!ins->pcm_input)) return -EINVAL; mutex_lock(&chip->spos_mutex); cs46xx_dsp_remove_scb (chip,ins->pcm_input); ins->pcm_input = NULL; mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(ins->adc_input)) return -EINVAL; if (snd_BUG_ON(!ins->codec_in_scb)) return -EINVAL; mutex_lock(&chip->spos_mutex); ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR, "PCMSerialInput_ADC"); mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(!ins->adc_input)) return -EINVAL; mutex_lock(&chip->spos_mutex); cs46xx_dsp_remove_scb (chip,ins->adc_input); ins->adc_input = NULL; mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data) { u32 temp; int i; /* santiy check the parameters. (These numbers are not 100% correct. They are a rough guess from looking at the controller spec.) */ if (address < 0x8000 || address >= 0x9000) return -EINVAL; /* initialize the SP_IO_WRITE SCB with the data. */ temp = ( address << 16 ) | ( address & 0x0000FFFF); /* offset 0 <-- address2 : address1 */ snd_cs46xx_poke(chip,( SPIOWRITE_SCB_ADDR << 2), temp); snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 1) << 2), data); /* offset 1 <-- data1 */ snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 2) << 2), data); /* offset 1 <-- data2 */ /* Poke this location to tell the task to start */ snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 6) << 2), SPIOWRITE_SCB_ADDR << 0x10); /* Verify that the task ran */ for (i=0; i<25; i++) { udelay(125); temp = snd_cs46xx_peek(chip,((SPIOWRITE_SCB_ADDR + 6) << 2)); if (temp == 0x00000000) break; } if (i == 25) { dev_err(chip->card->dev, "dsp_spos: SPIOWriteTask not responding\n"); return -EBUSY; } return 0; } int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb; mutex_lock(&chip->spos_mutex); /* main output */ scb = ins->master_mix_scb->sub_list_ptr; while (scb != ins->the_null_scb) { cs46xx_dsp_scb_set_volume (chip,scb,left,right); scb = scb->next_scb_ptr; } /* rear output */ scb = ins->rear_mix_scb->sub_list_ptr; while (scb != ins->the_null_scb) { cs46xx_dsp_scb_set_volume (chip,scb,left,right); scb = scb->next_scb_ptr; } ins->dac_volume_left = left; ins->dac_volume_right = right; mutex_unlock(&chip->spos_mutex); return 0; } int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; mutex_lock(&chip->spos_mutex); if (ins->asynch_rx_scb != NULL) cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb, left,right); ins->spdif_input_volume_left = left; ins->spdif_input_volume_right = right; mutex_unlock(&chip->spos_mutex); return 0; } #ifdef CONFIG_PM_SLEEP int cs46xx_dsp_resume(struct snd_cs46xx * chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; int i, err; /* clear parameter, sample and code areas */ snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE); snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE); snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE); for (i = 0; i < ins->nmodules; i++) { struct dsp_module_desc *module = &ins->modules[i]; struct dsp_segment_desc *seg; u32 doffset, dsize; seg = get_segment_desc(module, SEGTYPE_SP_PARAMETER); err = dsp_load_parameter(chip, seg); if (err < 0) return err; seg = get_segment_desc(module, SEGTYPE_SP_SAMPLE); err = dsp_load_sample(chip, seg); if (err < 0) return err; seg = get_segment_desc(module, SEGTYPE_SP_PROGRAM); if (!seg) continue; doffset = seg->offset * 4 + module->load_address * 4 + DSP_CODE_BYTE_OFFSET; dsize = seg->size * 4; err = snd_cs46xx_download(chip, ins->code.data + module->load_address, doffset, dsize); if (err < 0) return err; } for (i = 0; i < ins->ntask; i++) { struct dsp_task_descriptor *t = &ins->tasks[i]; _dsp_create_task_tree(chip, t->data, t->address, t->size); } for (i = 0; i < ins->nscb; i++) { struct dsp_scb_descriptor *s = &ins->scbs[i]; if (s->deleted) continue; _dsp_create_scb(chip, s->data, s->address); } for (i = 0; i < ins->nscb; i++) { struct dsp_scb_descriptor *s = &ins->scbs[i]; if (s->deleted) continue; if (s->updated) cs46xx_dsp_spos_update_scb(chip, s); if (s->volume_set) cs46xx_dsp_scb_set_volume(chip, s, s->volume[0], s->volume[1]); } if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) { cs46xx_dsp_enable_spdif_hw(chip); snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2, (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10); if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV, ins->spdif_csuv_stream); } if (chip->dsp_spos_instance->spdif_status_in) { cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005); cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff); } return 0; } #endif
linux-master
sound/pci/cs46xx/dsp_spos.c
// SPDX-License-Identifier: GPL-2.0-or-later /* */ /* * 2002-07 Benny Sjostrand [email protected] */ #include <linux/io.h> #include <linux/delay.h> #include <linux/pm.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/mutex.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> #include "cs46xx.h" #include "cs46xx_lib.h" #include "dsp_spos.h" struct proc_scb_info { struct dsp_scb_descriptor * scb_desc; struct snd_cs46xx *chip; }; static void remove_symbol (struct snd_cs46xx * chip, struct dsp_symbol_entry * symbol) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; int symbol_index = (int)(symbol - ins->symbol_table.symbols); if (snd_BUG_ON(ins->symbol_table.nsymbols <= 0)) return; if (snd_BUG_ON(symbol_index < 0 || symbol_index >= ins->symbol_table.nsymbols)) return; ins->symbol_table.symbols[symbol_index].deleted = 1; if (symbol_index < ins->symbol_table.highest_frag_index) { ins->symbol_table.highest_frag_index = symbol_index; } if (symbol_index == ins->symbol_table.nsymbols - 1) ins->symbol_table.nsymbols --; if (ins->symbol_table.highest_frag_index > ins->symbol_table.nsymbols) { ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols; } } #ifdef CONFIG_SND_PROC_FS static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct proc_scb_info * scb_info = entry->private_data; struct dsp_scb_descriptor * scb = scb_info->scb_desc; struct snd_cs46xx *chip = scb_info->chip; int j,col; void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET; mutex_lock(&chip->spos_mutex); snd_iprintf(buffer,"%04x %s:\n",scb->address,scb->scb_name); for (col = 0,j = 0;j < 0x10; j++,col++) { if (col == 4) { snd_iprintf(buffer,"\n"); col = 0; } snd_iprintf(buffer,"%08x ",readl(dst + (scb->address + j) * sizeof(u32))); } snd_iprintf(buffer,"\n"); if (scb->parent_scb_ptr != NULL) { snd_iprintf(buffer,"parent [%s:%04x] ", scb->parent_scb_ptr->scb_name, scb->parent_scb_ptr->address); } else snd_iprintf(buffer,"parent [none] "); snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n", scb->sub_list_ptr->scb_name, scb->sub_list_ptr->address, scb->next_scb_ptr->scb_name, scb->next_scb_ptr->address, scb->task_entry->symbol_name, scb->task_entry->address); snd_iprintf(buffer,"index [%d] ref_count [%d]\n",scb->index,scb->ref_count); mutex_unlock(&chip->spos_mutex); } #endif static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if ( scb->parent_scb_ptr ) { /* unlink parent SCB */ if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr != scb && scb->parent_scb_ptr->next_scb_ptr != scb)) return; if (scb->parent_scb_ptr->sub_list_ptr == scb) { if (scb->next_scb_ptr == ins->the_null_scb) { /* last and only node in parent sublist */ scb->parent_scb_ptr->sub_list_ptr = scb->sub_list_ptr; if (scb->sub_list_ptr != ins->the_null_scb) { scb->sub_list_ptr->parent_scb_ptr = scb->parent_scb_ptr; } scb->sub_list_ptr = ins->the_null_scb; } else { /* first node in parent sublist */ scb->parent_scb_ptr->sub_list_ptr = scb->next_scb_ptr; if (scb->next_scb_ptr != ins->the_null_scb) { /* update next node parent ptr. */ scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr; } scb->next_scb_ptr = ins->the_null_scb; } } else { scb->parent_scb_ptr->next_scb_ptr = scb->next_scb_ptr; if (scb->next_scb_ptr != ins->the_null_scb) { /* update next node parent ptr. */ scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr; } scb->next_scb_ptr = ins->the_null_scb; } /* update parent first entry in DSP RAM */ cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr); /* then update entry in DSP RAM */ cs46xx_dsp_spos_update_scb(chip,scb); scb->parent_scb_ptr = NULL; } } static void _dsp_clear_sample_buffer (struct snd_cs46xx *chip, u32 sample_buffer_addr, int dword_count) { void __iomem *dst = chip->region.idx[2].remap_addr + sample_buffer_addr; int i; for (i = 0; i < dword_count ; ++i ) { writel(0, dst); dst += 4; } } void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; unsigned long flags; /* check integrety */ if (snd_BUG_ON(scb->index < 0 || scb->index >= ins->nscb || (ins->scbs + scb->index) != scb)) return; #if 0 /* can't remove a SCB with childs before removing childs first */ if (snd_BUG_ON(scb->sub_list_ptr != ins->the_null_scb || scb->next_scb_ptr != ins->the_null_scb)) goto _end; #endif spin_lock_irqsave(&chip->reg_lock, flags); _dsp_unlink_scb (chip,scb); spin_unlock_irqrestore(&chip->reg_lock, flags); cs46xx_dsp_proc_free_scb_desc(scb); if (snd_BUG_ON(!scb->scb_symbol)) return; remove_symbol (chip,scb->scb_symbol); ins->scbs[scb->index].deleted = 1; #ifdef CONFIG_PM_SLEEP kfree(ins->scbs[scb->index].data); ins->scbs[scb->index].data = NULL; #endif if (scb->index < ins->scb_highest_frag_index) ins->scb_highest_frag_index = scb->index; if (scb->index == ins->nscb - 1) { ins->nscb --; } if (ins->scb_highest_frag_index > ins->nscb) { ins->scb_highest_frag_index = ins->nscb; } #if 0 /* !!!! THIS IS A PIECE OF SHIT MADE BY ME !!! */ for(i = scb->index + 1;i < ins->nscb; ++i) { ins->scbs[i - 1].index = i - 1; } #endif } #ifdef CONFIG_SND_PROC_FS void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb) { if (scb->proc_info) { struct proc_scb_info * scb_info = scb->proc_info->private_data; struct snd_cs46xx *chip = scb_info->chip; dev_dbg(chip->card->dev, "cs46xx_dsp_proc_free_scb_desc: freeing %s\n", scb->scb_name); snd_info_free_entry(scb->proc_info); scb->proc_info = NULL; kfree (scb_info); } } void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct snd_info_entry * entry; struct proc_scb_info * scb_info; /* register to proc */ if (ins->snd_card != NULL && ins->proc_dsp_dir != NULL && scb->proc_info == NULL) { entry = snd_info_create_card_entry(ins->snd_card, scb->scb_name, ins->proc_dsp_dir); if (entry) { scb_info = kmalloc(sizeof(struct proc_scb_info), GFP_KERNEL); if (!scb_info) { snd_info_free_entry(entry); entry = NULL; goto out; } scb_info->chip = chip; scb_info->scb_desc = scb; snd_info_set_text_ops(entry, scb_info, cs46xx_dsp_proc_scb_info_read); } out: scb->proc_info = entry; } } #endif /* CONFIG_SND_PROC_FS */ static struct dsp_scb_descriptor * _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest, struct dsp_symbol_entry * task_entry, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb; unsigned long flags; if (snd_BUG_ON(!ins->the_null_scb)) return NULL; /* fill the data that will be wroten to DSP */ scb_data[SCBsubListPtr] = (ins->the_null_scb->address << 0x10) | ins->the_null_scb->address; scb_data[SCBfuncEntryPtr] &= 0xFFFF0000; scb_data[SCBfuncEntryPtr] |= task_entry->address; dev_dbg(chip->card->dev, "dsp_spos: creating SCB <%s>\n", name); scb = cs46xx_dsp_create_scb(chip,name,scb_data,dest); scb->sub_list_ptr = ins->the_null_scb; scb->next_scb_ptr = ins->the_null_scb; scb->parent_scb_ptr = parent_scb; scb->task_entry = task_entry; /* update parent SCB */ if (scb->parent_scb_ptr) { #if 0 dev_dbg(chip->card->dev, "scb->parent_scb_ptr = %s\n", scb->parent_scb_ptr->scb_name); dev_dbg(chip->card->dev, "scb->parent_scb_ptr->next_scb_ptr = %s\n", scb->parent_scb_ptr->next_scb_ptr->scb_name); dev_dbg(chip->card->dev, "scb->parent_scb_ptr->sub_list_ptr = %s\n", scb->parent_scb_ptr->sub_list_ptr->scb_name); #endif /* link to parent SCB */ if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) { if (snd_BUG_ON(scb->parent_scb_ptr->next_scb_ptr != ins->the_null_scb)) return NULL; scb->parent_scb_ptr->next_scb_ptr = scb; } else if (scb_child_type == SCB_ON_PARENT_SUBLIST_SCB) { if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr != ins->the_null_scb)) return NULL; scb->parent_scb_ptr->sub_list_ptr = scb; } else { snd_BUG(); } spin_lock_irqsave(&chip->reg_lock, flags); /* update entry in DSP RAM */ cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr); spin_unlock_irqrestore(&chip->reg_lock, flags); } cs46xx_dsp_proc_register_scb_desc (chip,scb); return scb; } static struct dsp_scb_descriptor * cs46xx_dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest, char * task_entry_name, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_symbol_entry * task_entry; task_entry = cs46xx_dsp_lookup_symbol (chip,task_entry_name, SYMBOL_CODE); if (task_entry == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol %s not found\n", task_entry_name); return NULL; } return _dsp_create_generic_scb (chip,name,scb_data,dest,task_entry, parent_scb,scb_child_type); } struct dsp_scb_descriptor * cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip) { struct dsp_scb_descriptor * scb; struct dsp_timing_master_scb timing_master_scb = { { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, 0,0, 0,NULL_SCB_ADDR, 0,0, /* extraSampleAccum:TMreserved */ 0,0, /* codecFIFOptr:codecFIFOsyncd */ 0x0001,0x8000, /* fracSampAccumQm1:TMfrmsLeftInGroup */ 0x0001,0x0000, /* fracSampCorrectionQm1:TMfrmGroupLength */ 0x00060000 /* nSampPerFrmQ15 */ }; scb = cs46xx_dsp_create_generic_scb(chip,"TimingMasterSCBInst",(u32 *)&timing_master_scb, TIMINGMASTER_SCB_ADDR, "TIMINGMASTER",NULL,SCB_NO_PARENT); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip, char * codec_name, u16 channel_disp, u16 fifo_addr, u16 child_scb_addr, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_codec_output_scb codec_out_scb = { { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, 0,0, 0,NULL_SCB_ADDR, 0, /* COstrmRsConfig */ 0, /* COstrmBufPtr */ channel_disp,fifo_addr, /* leftChanBaseIOaddr:rightChanIOdisp */ 0x0000,0x0080, /* (!AC97!) COexpVolChangeRate:COscaleShiftCount */ 0,child_scb_addr /* COreserved - need child scb to work with rom code */ }; scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_out_scb, dest,"S16_CODECOUTPUTTASK",parent_scb, scb_child_type); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name, u16 channel_disp, u16 fifo_addr, u16 sample_buffer_addr, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_codec_input_scb codec_input_scb = { { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, #if 0 /* cs4620 */ SyncIOSCB,NULL_SCB_ADDR #else 0 , 0, #endif 0,0, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, /* strmRsConfig */ sample_buffer_addr << 0x10, /* strmBufPtr; defined as a dword ptr, used as a byte ptr */ channel_disp,fifo_addr, /* (!AC97!) leftChanBaseINaddr=AC97primary link input slot 3 :rightChanINdisp=""slot 4 */ 0x0000,0x0000, /* (!AC97!) ????:scaleShiftCount; no shift needed because AC97 is already 20 bits */ 0x80008000 /* ??clw cwcgame.scb has 0 */ }; scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_input_scb, dest,"S16_CODECINPUTTASK",parent_scb, scb_child_type); return scb; } static struct dsp_scb_descriptor * cs46xx_dsp_create_pcm_reader_scb(struct snd_cs46xx * chip, char * scb_name, u16 sample_buffer_addr, u32 dest, int virtual_channel, u32 playback_hw_addr, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb; struct dsp_generic_scb pcm_reader_scb = { /* Play DMA Task xfers data from host buffer to SP buffer init/runtime variables: PlayAC: Play Audio Data Conversion - SCB loc: 2nd dword, mask: 0x0000F000L DATA_FMT_16BIT_ST_LTLEND(0x00000000L) from 16-bit stereo, little-endian DATA_FMT_8_BIT_ST_SIGNED(0x00001000L) from 8-bit stereo, signed DATA_FMT_16BIT_MN_LTLEND(0x00002000L) from 16-bit mono, little-endian DATA_FMT_8_BIT_MN_SIGNED(0x00003000L) from 8-bit mono, signed DATA_FMT_16BIT_ST_BIGEND(0x00004000L) from 16-bit stereo, big-endian DATA_FMT_16BIT_MN_BIGEND(0x00006000L) from 16-bit mono, big-endian DATA_FMT_8_BIT_ST_UNSIGNED(0x00009000L) from 8-bit stereo, unsigned DATA_FMT_8_BIT_MN_UNSIGNED(0x0000b000L) from 8-bit mono, unsigned ? Other combinations possible from: DMA_RQ_C2_AUDIO_CONVERT_MASK 0x0000F000L DMA_RQ_C2_AC_NONE 0x00000000L DMA_RQ_C2_AC_8_TO_16_BIT 0x00001000L DMA_RQ_C2_AC_MONO_TO_STEREO 0x00002000L DMA_RQ_C2_AC_ENDIAN_CONVERT 0x00004000L DMA_RQ_C2_AC_SIGNED_CONVERT 0x00008000L HostBuffAddr: Host Buffer Physical Byte Address - SCB loc:3rd dword, Mask: 0xFFFFFFFFL aligned to dword boundary */ /* Basic (non scatter/gather) DMA requestor (4 ints) */ { DMA_RQ_C1_SOURCE_ON_HOST + /* source buffer is on the host */ DMA_RQ_C1_SOURCE_MOD1024 + /* source buffer is 1024 dwords (4096 bytes) */ DMA_RQ_C1_DEST_MOD32 + /* dest buffer(PCMreaderBuf) is 32 dwords*/ DMA_RQ_C1_WRITEBACK_SRC_FLAG + /* ?? */ DMA_RQ_C1_WRITEBACK_DEST_FLAG + /* ?? */ 15, /* DwordCount-1: picked 16 for DwordCount because Jim */ /* Barnette said that is what we should use since */ /* we are not running in optimized mode? */ DMA_RQ_C2_AC_NONE + DMA_RQ_C2_SIGNAL_SOURCE_PINGPONG + /* set play interrupt (bit0) in HISR when source */ /* buffer (on host) crosses half-way point */ virtual_channel, /* Play DMA channel arbitrarily set to 0 */ playback_hw_addr, /* HostBuffAddr (source) */ DMA_RQ_SD_SP_SAMPLE_ADDR + /* destination buffer is in SP Sample Memory */ sample_buffer_addr /* SP Buffer Address (destination) */ }, /* Scatter/gather DMA requestor extension (5 ints) */ { 0, 0, 0, 0, 0 }, /* Sublist pointer & next stream control block (SCB) link. */ NULL_SCB_ADDR,NULL_SCB_ADDR, /* Pointer to this tasks parameter block & stream function pointer */ 0,NULL_SCB_ADDR, /* rsConfig register for stream buffer (rsDMA reg. is loaded from basicReq.daw */ /* for incoming streams, or basicReq.saw, for outgoing streams) */ RSCONFIG_DMA_ENABLE + /* enable DMA */ (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) + /* MAX_DMA_SIZE picked to be 19 since SPUD */ /* uses it for some reason */ ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) + /* stream number = SCBaddr/16 */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32, /* dest buffer(PCMreaderBuf) is 32 dwords (256 bytes) */ /* Stream sample pointer & MAC-unit mode for this stream */ (sample_buffer_addr << 0x10), /* Fractional increment per output sample in the input sample buffer */ 0, { /* Standard stereo volume control default muted */ 0xffff,0xffff, 0xffff,0xffff } }; if (ins->null_algorithm == NULL) { ins->null_algorithm = cs46xx_dsp_lookup_symbol (chip,"NULLALGORITHM", SYMBOL_CODE); if (ins->null_algorithm == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol NULLALGORITHM not found\n"); return NULL; } } scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_reader_scb, dest,ins->null_algorithm,parent_scb, scb_child_type); return scb; } #define GOF_PER_SEC 200 struct dsp_scb_descriptor * cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name, int rate, u16 src_buffer_addr, u16 src_delay_buffer_addr, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type, int pass_through) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb; unsigned int tmp1, tmp2; unsigned int phiIncr; unsigned int correctionPerGOF, correctionPerSec; dev_dbg(chip->card->dev, "dsp_spos: setting %s rate to %u\n", scb_name, rate); /* * Compute the values used to drive the actual sample rate conversion. * The following formulas are being computed, using inline assembly * since we need to use 64 bit arithmetic to compute the values: * * phiIncr = floor((Fs,in * 2^26) / Fs,out) * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) / * GOF_PER_SEC) * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M * GOF_PER_SEC * correctionPerGOF * * i.e. * * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out) * correctionPerGOF:correctionPerSec = * dividend:remainder(ulOther / GOF_PER_SEC) */ tmp1 = rate << 16; phiIncr = tmp1 / 48000; tmp1 -= phiIncr * 48000; tmp1 <<= 10; phiIncr <<= 10; tmp2 = tmp1 / 48000; phiIncr += tmp2; tmp1 -= tmp2 * 48000; correctionPerGOF = tmp1 / GOF_PER_SEC; tmp1 -= correctionPerGOF * GOF_PER_SEC; correctionPerSec = tmp1; { struct dsp_src_task_scb src_task_scb = { 0x0028,0x00c8, 0x5555,0x0000, 0x0000,0x0000, src_buffer_addr,1, correctionPerGOF,correctionPerSec, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32, 0x0000,src_delay_buffer_addr, 0x0, 0x080,(src_delay_buffer_addr + (24 * 4)), 0,0, /* next_scb, sub_list_ptr */ 0,0, /* entry, this_spb */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8, src_buffer_addr << 0x10, phiIncr, { 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left, 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left } }; if (ins->s16_up == NULL) { ins->s16_up = cs46xx_dsp_lookup_symbol (chip,"S16_UPSRC", SYMBOL_CODE); if (ins->s16_up == NULL) { dev_err(chip->card->dev, "dsp_spos: symbol S16_UPSRC not found\n"); return NULL; } } /* clear buffers */ _dsp_clear_sample_buffer (chip,src_buffer_addr,8); _dsp_clear_sample_buffer (chip,src_delay_buffer_addr,32); if (pass_through) { /* wont work with any other rate than the native DSP rate */ snd_BUG_ON(rate != 48000); scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb, dest,"DMAREADER",parent_scb, scb_child_type); } else { scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb, dest,ins->s16_up,parent_scb, scb_child_type); } } return scb; } #if 0 /* not used */ struct dsp_scb_descriptor * cs46xx_dsp_create_filter_scb(struct snd_cs46xx * chip, char * scb_name, u16 buffer_addr, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_filter_scb filter_scb = { .a0_right = 0x41a9, .a0_left = 0x41a9, .a1_right = 0xb8e4, .a1_left = 0xb8e4, .a2_right = 0x3e55, .a2_left = 0x3e55, .filter_unused3 = 0x0000, .filter_unused2 = 0x0000, .output_buf_ptr = buffer_addr, .init = 0x000, .prev_sample_output1 = 0x00000000, .prev_sample_output2 = 0x00000000, .prev_sample_input1 = 0x00000000, .prev_sample_input2 = 0x00000000, .next_scb_ptr = 0x0000, .sub_list_ptr = 0x0000, .entry_point = 0x0000, .spb_ptr = 0x0000, .b0_right = 0x0e38, .b0_left = 0x0e38, .b1_right = 0x1c71, .b1_left = 0x1c71, .b2_right = 0x0e38, .b2_left = 0x0e38, }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&filter_scb, dest,"FILTERTASK",parent_scb, scb_child_type); return scb; } #endif /* not used */ struct dsp_scb_descriptor * cs46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name, u16 mix_buffer_addr, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_mix_only_scb master_mix_scb = { /* 0 */ { 0, /* 1 */ 0, /* 2 */ mix_buffer_addr, /* 3 */ 0 /* */ }, { /* 4 */ 0, /* 5 */ 0, /* 6 */ 0, /* 7 */ 0, /* 8 */ 0x00000080 }, /* 9 */ 0,0, /* A */ 0,0, /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32, /* C */ (mix_buffer_addr + (16 * 4)) << 0x10, /* D */ 0, { /* E */ 0x8000,0x8000, /* F */ 0x8000,0x8000 } }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&master_mix_scb, dest,"S16_MIX",parent_scb, scb_child_type); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name, u16 mix_buffer_addr, u16 writeback_spb, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_mix2_ostream_scb mix2_ostream_scb = { /* Basic (non scatter/gather) DMA requestor (4 ints) */ { DMA_RQ_C1_SOURCE_MOD64 + DMA_RQ_C1_DEST_ON_HOST + DMA_RQ_C1_DEST_MOD1024 + DMA_RQ_C1_WRITEBACK_SRC_FLAG + DMA_RQ_C1_WRITEBACK_DEST_FLAG + 15, DMA_RQ_C2_AC_NONE + DMA_RQ_C2_SIGNAL_DEST_PINGPONG + CS46XX_DSP_CAPTURE_CHANNEL, DMA_RQ_SD_SP_SAMPLE_ADDR + mix_buffer_addr, 0x0 }, { 0, 0, 0, 0, 0, }, 0,0, 0,writeback_spb, RSCONFIG_DMA_ENABLE + (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) + ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) + RSCONFIG_DMA_TO_HOST + RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, (mix_buffer_addr + (32 * 4)) << 0x10, 1,0, 0x0001,0x0080, 0xFFFF,0 }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&mix2_ostream_scb, dest,"S16_MIX_TO_OSTREAM",parent_scb, scb_child_type); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip,char * scb_name, u16 vari_buffer_addr0, u16 vari_buffer_addr1, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_vari_decimate_scb vari_decimate_scb = { 0x0028,0x00c8, 0x5555,0x0000, 0x0000,0x0000, vari_buffer_addr0,vari_buffer_addr1, 0x0028,0x00c8, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256, 0xFF800000, 0, 0x0080,vari_buffer_addr1 + (25 * 4), 0,0, 0,0, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8, vari_buffer_addr0 << 0x10, 0x04000000, { 0x8000,0x8000, 0xFFFF,0xFFFF } }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&vari_decimate_scb, dest,"VARIDECIMATE",parent_scb, scb_child_type); return scb; } static struct dsp_scb_descriptor * cs46xx_dsp_create_pcm_serial_input_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, struct dsp_scb_descriptor * input_scb, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_pcm_serial_input_scb pcm_serial_input_scb = { { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, 0,0, 0,0, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_16, 0, /* 0xD */ 0,input_scb->address, { /* 0xE */ 0x8000,0x8000, /* 0xF */ 0x8000,0x8000 } }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_serial_input_scb, dest,"PCMSERIALINPUTTASK",parent_scb, scb_child_type); return scb; } static struct dsp_scb_descriptor * cs46xx_dsp_create_asynch_fg_tx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, u16 hfg_scb_address, u16 asynch_buffer_address, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_asynch_fg_tx_scb asynch_fg_tx_scb = { 0xfc00,0x03ff, /* Prototype sample buffer size of 256 dwords */ 0x0058,0x0028, /* Min Delta 7 dwords == 28 bytes */ /* : Max delta 25 dwords == 100 bytes */ 0,hfg_scb_address, /* Point to HFG task SCB */ 0,0, /* Initialize current Delta and Consumer ptr adjustment count */ 0, /* Initialize accumulated Phi to 0 */ 0,0x2aab, /* Const 1/3 */ { 0, /* Define the unused elements */ 0, 0 }, 0,0, 0,dest + AFGTxAccumPhi, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256, /* Stereo, 256 dword */ (asynch_buffer_address) << 0x10, /* This should be automagically synchronized to the producer pointer */ /* There is no correct initial value, it will depend upon the detected rate etc */ 0x18000000, /* Phi increment for approx 32k operation */ 0x8000,0x8000, /* Volume controls are unused at this time */ 0x8000,0x8000 }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_tx_scb, dest,"ASYNCHFGTXCODE",parent_scb, scb_child_type); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, u16 hfg_scb_address, u16 asynch_buffer_address, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb; struct dsp_asynch_fg_rx_scb asynch_fg_rx_scb = { 0xfe00,0x01ff, /* Prototype sample buffer size of 128 dwords */ 0x0064,0x001c, /* Min Delta 7 dwords == 28 bytes */ /* : Max delta 25 dwords == 100 bytes */ 0,hfg_scb_address, /* Point to HFG task SCB */ 0,0, /* Initialize current Delta and Consumer ptr adjustment count */ { 0, /* Define the unused elements */ 0, 0, 0, 0 }, 0,0, 0,dest, RSCONFIG_MODULO_128 | RSCONFIG_SAMPLE_16STEREO, /* Stereo, 128 dword */ ( (asynch_buffer_address + (16 * 4)) << 0x10), /* This should be automagically synchrinized to the producer pointer */ /* There is no correct initial value, it will depend upon the detected rate etc */ 0x18000000, /* Set IEC958 input volume */ 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left, 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left, }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_rx_scb, dest,"ASYNCHFGRXCODE",parent_scb, scb_child_type); return scb; } #if 0 /* not used */ struct dsp_scb_descriptor * cs46xx_dsp_create_output_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, u16 snoop_buffer_address, struct dsp_scb_descriptor * snoop_scb, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_output_snoop_scb output_snoop_scb = { { 0, /* not used. Zero */ 0, 0, 0, }, { 0, /* not used. Zero */ 0, 0, 0, 0 }, 0,0, 0,0, RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, snoop_buffer_address << 0x10, 0,0, 0, 0,snoop_scb->address }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&output_snoop_scb, dest,"OUTPUTSNOOP",parent_scb, scb_child_type); return scb; } #endif /* not used */ struct dsp_scb_descriptor * cs46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_spio_write_scb spio_write_scb = { 0,0, /* SPIOWAddress2:SPIOWAddress1; */ 0, /* SPIOWData1; */ 0, /* SPIOWData2; */ 0,0, /* SPIOWAddress4:SPIOWAddress3; */ 0, /* SPIOWData3; */ 0, /* SPIOWData4; */ 0,0, /* SPIOWDataPtr:Unused1; */ { 0,0 }, /* Unused2[2]; */ 0,0, /* SPIOWChildPtr:SPIOWSiblingPtr; */ 0,0, /* SPIOWThisPtr:SPIOWEntryPoint; */ { 0, 0, 0, 0, 0 /* Unused3[5]; */ } }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&spio_write_scb, dest,"SPIOWRITE",parent_scb, scb_child_type); return scb; } struct dsp_scb_descriptor * cs46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, u16 snoop_buffer_address, struct dsp_scb_descriptor * snoop_scb, struct dsp_scb_descriptor * parent_scb, int scb_child_type) { struct dsp_scb_descriptor * scb; struct dsp_magic_snoop_task magic_snoop_scb = { /* 0 */ 0, /* i0 */ /* 1 */ 0, /* i1 */ /* 2 */ snoop_buffer_address << 0x10, /* 3 */ 0,snoop_scb->address, /* 4 */ 0, /* i3 */ /* 5 */ 0, /* i4 */ /* 6 */ 0, /* i5 */ /* 7 */ 0, /* i6 */ /* 8 */ 0, /* i7 */ /* 9 */ 0,0, /* next_scb, sub_list_ptr */ /* A */ 0,0, /* entry_point, this_ptr */ /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, /* C */ snoop_buffer_address << 0x10, /* D */ 0, /* E */ { 0x8000,0x8000, /* F */ 0xffff,0xffff } }; scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&magic_snoop_scb, dest,"MAGICSNOOPTASK",parent_scb, scb_child_type); return scb; } static struct dsp_scb_descriptor * find_next_free_scb (struct snd_cs46xx * chip, struct dsp_scb_descriptor * from) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * scb = from; while (scb->next_scb_ptr != ins->the_null_scb) { if (snd_BUG_ON(!scb->next_scb_ptr)) return NULL; scb = scb->next_scb_ptr; } return scb; } static const u32 pcm_reader_buffer_addr[DSP_MAX_PCM_CHANNELS] = { 0x0600, /* 1 */ 0x1500, /* 2 */ 0x1580, /* 3 */ 0x1600, /* 4 */ 0x1680, /* 5 */ 0x1700, /* 6 */ 0x1780, /* 7 */ 0x1800, /* 8 */ 0x1880, /* 9 */ 0x1900, /* 10 */ 0x1980, /* 11 */ 0x1A00, /* 12 */ 0x1A80, /* 13 */ 0x1B00, /* 14 */ 0x1B80, /* 15 */ 0x1C00, /* 16 */ 0x1C80, /* 17 */ 0x1D00, /* 18 */ 0x1D80, /* 19 */ 0x1E00, /* 20 */ 0x1E80, /* 21 */ 0x1F00, /* 22 */ 0x1F80, /* 23 */ 0x2000, /* 24 */ 0x2080, /* 25 */ 0x2100, /* 26 */ 0x2180, /* 27 */ 0x2200, /* 28 */ 0x2280, /* 29 */ 0x2300, /* 30 */ 0x2380, /* 31 */ 0x2400, /* 32 */ }; static const u32 src_output_buffer_addr[DSP_MAX_SRC_NR] = { 0x2B80, 0x2BA0, 0x2BC0, 0x2BE0, 0x2D00, 0x2D20, 0x2D40, 0x2D60, 0x2D80, 0x2DA0, 0x2DC0, 0x2DE0, 0x2E00, 0x2E20 }; static const u32 src_delay_buffer_addr[DSP_MAX_SRC_NR] = { 0x2480, 0x2500, 0x2580, 0x2600, 0x2680, 0x2700, 0x2780, 0x2800, 0x2880, 0x2900, 0x2980, 0x2A00, 0x2A80, 0x2B00 }; struct dsp_pcm_channel_descriptor * cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip, u32 sample_rate, void * private_data, u32 hw_dma_addr, int pcm_channel_id) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * src_scb = NULL, * pcm_scb, * mixer_scb = NULL; struct dsp_scb_descriptor * src_parent_scb = NULL; /* struct dsp_scb_descriptor * pcm_parent_scb; */ char scb_name[DSP_MAX_SCB_NAME]; int i, pcm_index = -1, insert_point, src_index = -1, pass_through = 0; unsigned long flags; switch (pcm_channel_id) { case DSP_PCM_MAIN_CHANNEL: mixer_scb = ins->master_mix_scb; break; case DSP_PCM_REAR_CHANNEL: mixer_scb = ins->rear_mix_scb; break; case DSP_PCM_CENTER_LFE_CHANNEL: mixer_scb = ins->center_lfe_mix_scb; break; case DSP_PCM_S71_CHANNEL: /* TODO */ snd_BUG(); break; case DSP_IEC958_CHANNEL: if (snd_BUG_ON(!ins->asynch_tx_scb)) return NULL; mixer_scb = ins->asynch_tx_scb; /* if sample rate is set to 48khz we pass the Sample Rate Converted (which could alter the raw data stream ...) */ if (sample_rate == 48000) { dev_dbg(chip->card->dev, "IEC958 pass through\n"); /* Hack to bypass creating a new SRC */ pass_through = 1; } break; default: snd_BUG(); return NULL; } /* default sample rate is 44100 */ if (!sample_rate) sample_rate = 44100; /* search for a already created SRC SCB with the same sample rate */ for (i = 0; i < DSP_MAX_PCM_CHANNELS && (pcm_index == -1 || src_scb == NULL); ++i) { /* virtual channel reserved for capture */ if (i == CS46XX_DSP_CAPTURE_CHANNEL) continue; if (ins->pcm_channels[i].active) { if (!src_scb && ins->pcm_channels[i].sample_rate == sample_rate && ins->pcm_channels[i].mixer_scb == mixer_scb) { src_scb = ins->pcm_channels[i].src_scb; ins->pcm_channels[i].src_scb->ref_count ++; src_index = ins->pcm_channels[i].src_slot; } } else if (pcm_index == -1) { pcm_index = i; } } if (pcm_index == -1) { dev_err(chip->card->dev, "dsp_spos: no free PCM channel\n"); return NULL; } if (src_scb == NULL) { if (ins->nsrc_scb >= DSP_MAX_SRC_NR) { dev_err(chip->card->dev, "dsp_spos: too many SRC instances\n!"); return NULL; } /* find a free slot */ for (i = 0; i < DSP_MAX_SRC_NR; ++i) { if (ins->src_scb_slots[i] == 0) { src_index = i; ins->src_scb_slots[i] = 1; break; } } if (snd_BUG_ON(src_index == -1)) return NULL; /* we need to create a new SRC SCB */ if (mixer_scb->sub_list_ptr == ins->the_null_scb) { src_parent_scb = mixer_scb; insert_point = SCB_ON_PARENT_SUBLIST_SCB; } else { src_parent_scb = find_next_free_scb(chip,mixer_scb->sub_list_ptr); insert_point = SCB_ON_PARENT_NEXT_SCB; } snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index); dev_dbg(chip->card->dev, "dsp_spos: creating SRC \"%s\"\n", scb_name); src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name, sample_rate, src_output_buffer_addr[src_index], src_delay_buffer_addr[src_index], /* 0x400 - 0x600 source SCBs */ 0x400 + (src_index * 0x10) , src_parent_scb, insert_point, pass_through); if (!src_scb) { dev_err(chip->card->dev, "dsp_spos: failed to create SRCtaskSCB\n"); return NULL; } /* cs46xx_dsp_set_src_sample_rate(chip,src_scb,sample_rate); */ ins->nsrc_scb ++; } snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index); dev_dbg(chip->card->dev, "dsp_spos: creating PCM \"%s\" (%d)\n", scb_name, pcm_channel_id); pcm_scb = cs46xx_dsp_create_pcm_reader_scb(chip,scb_name, pcm_reader_buffer_addr[pcm_index], /* 0x200 - 400 PCMreader SCBs */ (pcm_index * 0x10) + 0x200, pcm_index, /* virtual channel 0-31 */ hw_dma_addr, /* pcm hw addr */ NULL, /* parent SCB ptr */ 0 /* insert point */ ); if (!pcm_scb) { dev_err(chip->card->dev, "dsp_spos: failed to create PCMreaderSCB\n"); return NULL; } spin_lock_irqsave(&chip->reg_lock, flags); ins->pcm_channels[pcm_index].sample_rate = sample_rate; ins->pcm_channels[pcm_index].pcm_reader_scb = pcm_scb; ins->pcm_channels[pcm_index].src_scb = src_scb; ins->pcm_channels[pcm_index].unlinked = 1; ins->pcm_channels[pcm_index].private_data = private_data; ins->pcm_channels[pcm_index].src_slot = src_index; ins->pcm_channels[pcm_index].active = 1; ins->pcm_channels[pcm_index].pcm_slot = pcm_index; ins->pcm_channels[pcm_index].mixer_scb = mixer_scb; ins->npcm_channels ++; spin_unlock_irqrestore(&chip->reg_lock, flags); return (ins->pcm_channels + pcm_index); } int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip, struct dsp_pcm_channel_descriptor * pcm_channel, int period_size) { u32 temp = snd_cs46xx_peek (chip,pcm_channel->pcm_reader_scb->address << 2); temp &= ~DMA_RQ_C1_SOURCE_SIZE_MASK; switch (period_size) { case 2048: temp |= DMA_RQ_C1_SOURCE_MOD1024; break; case 1024: temp |= DMA_RQ_C1_SOURCE_MOD512; break; case 512: temp |= DMA_RQ_C1_SOURCE_MOD256; break; case 256: temp |= DMA_RQ_C1_SOURCE_MOD128; break; case 128: temp |= DMA_RQ_C1_SOURCE_MOD64; break; case 64: temp |= DMA_RQ_C1_SOURCE_MOD32; break; case 32: temp |= DMA_RQ_C1_SOURCE_MOD16; break; default: dev_dbg(chip->card->dev, "period size (%d) not supported by HW\n", period_size); return -EINVAL; } snd_cs46xx_poke (chip,pcm_channel->pcm_reader_scb->address << 2,temp); return 0; } int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip, int period_size) { u32 temp = snd_cs46xx_peek (chip,WRITEBACK_SCB_ADDR << 2); temp &= ~DMA_RQ_C1_DEST_SIZE_MASK; switch (period_size) { case 2048: temp |= DMA_RQ_C1_DEST_MOD1024; break; case 1024: temp |= DMA_RQ_C1_DEST_MOD512; break; case 512: temp |= DMA_RQ_C1_DEST_MOD256; break; case 256: temp |= DMA_RQ_C1_DEST_MOD128; break; case 128: temp |= DMA_RQ_C1_DEST_MOD64; break; case 64: temp |= DMA_RQ_C1_DEST_MOD32; break; case 32: temp |= DMA_RQ_C1_DEST_MOD16; break; default: dev_dbg(chip->card->dev, "period size (%d) not supported by HW\n", period_size); return -EINVAL; } snd_cs46xx_poke (chip,WRITEBACK_SCB_ADDR << 2,temp); return 0; } void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip, struct dsp_pcm_channel_descriptor * pcm_channel) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; unsigned long flags; if (snd_BUG_ON(!pcm_channel->active || ins->npcm_channels <= 0 || pcm_channel->src_scb->ref_count <= 0)) return; spin_lock_irqsave(&chip->reg_lock, flags); pcm_channel->unlinked = 1; pcm_channel->active = 0; pcm_channel->private_data = NULL; pcm_channel->src_scb->ref_count --; ins->npcm_channels --; spin_unlock_irqrestore(&chip->reg_lock, flags); cs46xx_dsp_remove_scb(chip,pcm_channel->pcm_reader_scb); if (!pcm_channel->src_scb->ref_count) { cs46xx_dsp_remove_scb(chip,pcm_channel->src_scb); if (snd_BUG_ON(pcm_channel->src_slot < 0 || pcm_channel->src_slot >= DSP_MAX_SRC_NR)) return; ins->src_scb_slots[pcm_channel->src_slot] = 0; ins->nsrc_scb --; } } int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip, struct dsp_pcm_channel_descriptor * pcm_channel) { unsigned long flags; if (snd_BUG_ON(!pcm_channel->active || chip->dsp_spos_instance->npcm_channels <= 0)) return -EIO; spin_lock_irqsave(&chip->reg_lock, flags); if (pcm_channel->unlinked) { spin_unlock_irqrestore(&chip->reg_lock, flags); return -EIO; } pcm_channel->unlinked = 1; _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip, struct dsp_pcm_channel_descriptor * pcm_channel) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * parent_scb; struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb; unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); if (pcm_channel->unlinked == 0) { spin_unlock_irqrestore(&chip->reg_lock, flags); return -EIO; } parent_scb = src_scb; if (src_scb->sub_list_ptr != ins->the_null_scb) { src_scb->sub_list_ptr->parent_scb_ptr = pcm_channel->pcm_reader_scb; pcm_channel->pcm_reader_scb->next_scb_ptr = src_scb->sub_list_ptr; } src_scb->sub_list_ptr = pcm_channel->pcm_reader_scb; snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr); pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb; /* update SCB entry in DSP RAM */ cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb); /* update parent SCB entry */ cs46xx_dsp_spos_update_scb(chip,parent_scb); pcm_channel->unlinked = 0; spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } struct dsp_scb_descriptor * cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source, u16 addr, char * scb_name) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * parent; struct dsp_scb_descriptor * pcm_input; int insert_point; if (snd_BUG_ON(!ins->record_mixer_scb)) return NULL; if (ins->record_mixer_scb->sub_list_ptr != ins->the_null_scb) { parent = find_next_free_scb (chip,ins->record_mixer_scb->sub_list_ptr); insert_point = SCB_ON_PARENT_NEXT_SCB; } else { parent = ins->record_mixer_scb; insert_point = SCB_ON_PARENT_SUBLIST_SCB; } pcm_input = cs46xx_dsp_create_pcm_serial_input_scb(chip,scb_name,addr, source, parent, insert_point); return pcm_input; } int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src) { unsigned long flags; if (snd_BUG_ON(!src->parent_scb_ptr)) return -EINVAL; /* mute SCB */ cs46xx_dsp_scb_set_volume (chip,src,0,0); spin_lock_irqsave(&chip->reg_lock, flags); _dsp_unlink_scb (chip,src); spin_unlock_irqrestore(&chip->reg_lock, flags); return 0; } int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; struct dsp_scb_descriptor * parent_scb; if (snd_BUG_ON(src->parent_scb_ptr)) return -EINVAL; if (snd_BUG_ON(!ins->master_mix_scb)) return -EINVAL; if (ins->master_mix_scb->sub_list_ptr != ins->the_null_scb) { parent_scb = find_next_free_scb (chip,ins->master_mix_scb->sub_list_ptr); parent_scb->next_scb_ptr = src; } else { parent_scb = ins->master_mix_scb; parent_scb->sub_list_ptr = src; } src->parent_scb_ptr = parent_scb; /* update entry in DSP RAM */ cs46xx_dsp_spos_update_scb(chip,parent_scb); return 0; } int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) { cs46xx_dsp_enable_spdif_hw (chip); } /* dont touch anything if SPDIF is open */ if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) { /* when cs46xx_iec958_post_close(...) is called it will call this function if necessary depending on this bit */ ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED; return -EBUSY; } if (snd_BUG_ON(ins->asynch_tx_scb)) return -EINVAL; if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr != ins->the_null_scb)) return -EINVAL; /* reset output snooper sample buffer pointer */ snd_cs46xx_poke (chip, (ins->ref_snoop_scb->address + 2) << 2, (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10 ); /* The asynch. transfer task */ ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR, SPDIFO_SCB_INST, SPDIFO_IP_OUTPUT_BUFFER1, ins->master_mix_scb, SCB_ON_PARENT_NEXT_SCB); if (!ins->asynch_tx_scb) return -ENOMEM; ins->spdif_pcm_input_scb = cs46xx_dsp_create_pcm_serial_input_scb(chip,"PCMSerialInput_II", PCMSERIALINII_SCB_ADDR, ins->ref_snoop_scb, ins->asynch_tx_scb, SCB_ON_PARENT_SUBLIST_SCB); if (!ins->spdif_pcm_input_scb) return -ENOMEM; /* monitor state */ ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED; return 0; } int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; /* dont touch anything if SPDIF is open */ if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) { ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED; return -EBUSY; } /* check integrety */ if (snd_BUG_ON(!ins->asynch_tx_scb)) return -EINVAL; if (snd_BUG_ON(!ins->spdif_pcm_input_scb)) return -EINVAL; if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr != ins->asynch_tx_scb)) return -EINVAL; if (snd_BUG_ON(ins->asynch_tx_scb->parent_scb_ptr != ins->master_mix_scb)) return -EINVAL; cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb); cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb); ins->spdif_pcm_input_scb = NULL; ins->asynch_tx_scb = NULL; /* clear buffer to prevent any undesired noise */ _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256); /* monitor state */ ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED; return 0; } int cs46xx_iec958_pre_open (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) { /* remove AsynchFGTxSCB and PCMSerialInput_II */ cs46xx_dsp_disable_spdif_out (chip); /* save state */ ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED; } /* if not enabled already */ if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) { cs46xx_dsp_enable_spdif_hw (chip); } /* Create the asynch. transfer task for playback */ ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR, SPDIFO_SCB_INST, SPDIFO_IP_OUTPUT_BUFFER1, ins->master_mix_scb, SCB_ON_PARENT_NEXT_SCB); /* set spdif channel status value for streaming */ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_stream); ins->spdif_status_out |= DSP_SPDIF_STATUS_PLAYBACK_OPEN; return 0; } int cs46xx_iec958_post_close (struct snd_cs46xx *chip) { struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (snd_BUG_ON(!ins->asynch_tx_scb)) return -EINVAL; ins->spdif_status_out &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN; /* restore settings */ cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default); /* deallocate stuff */ if (ins->spdif_pcm_input_scb != NULL) { cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb); ins->spdif_pcm_input_scb = NULL; } cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb); ins->asynch_tx_scb = NULL; /* clear buffer to prevent any undesired noise */ _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256); /* restore state */ if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) { cs46xx_dsp_enable_spdif_out (chip); } return 0; }
linux-master
sound/pci/cs46xx/dsp_spos_scb_lib.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]> * Abramo Bagnara <[email protected]> * Cirrus Logic, Inc. * Routines for control of Cirrus Logic CS461x chips * * KNOWN BUGS: * - Sometimes the SPDIF input DSP tasks get's unsynchronized * and the SPDIF get somewhat "distorcionated", or/and left right channel * are swapped. To get around this problem when it happens, mute and unmute * the SPDIF input mixer control. * - On the Hercules Game Theater XP the amplifier are sometimes turned * off on inadecuate moments which causes distorcions on sound. * * TODO: * - Secondary CODEC on some soundcards * - SPDIF input support for other sample rates then 48khz * - Posibility to mix the SPDIF output with analog sources. * - PCM channels for Center and LFE on secondary codec * * NOTE: with CONFIG_SND_CS46XX_NEW_DSP unset uses old DSP image (which * is default configuration), no SPDIF, no secondary codec, no * multi channel PCM. But known to work. * * FINALLY: A credit to the developers Tom and Jordan * at Cirrus for have helping me out with the DSP, however we * still don't have sufficient documentation and technical * references to be able to implement all fancy feutures * supported by the cs46xx DSP's. * Benny <[email protected]> */ #include <linux/delay.h> #include <linux/pci.h> #include <linux/pm.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/slab.h> #include <linux/gameport.h> #include <linux/mutex.h> #include <linux/export.h> #include <linux/module.h> #include <linux/firmware.h> #include <linux/vmalloc.h> #include <linux/io.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include "cs46xx.h" #include "cs46xx_lib.h" #include "dsp_spos.h" static void amp_voyetra(struct snd_cs46xx *chip, int change); #ifdef CONFIG_SND_CS46XX_NEW_DSP static const struct snd_pcm_ops snd_cs46xx_playback_rear_ops; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops; static const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops; static const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops; #endif static const struct snd_pcm_ops snd_cs46xx_playback_ops; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops; static const struct snd_pcm_ops snd_cs46xx_capture_ops; static const struct snd_pcm_ops snd_cs46xx_capture_indirect_ops; static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip, unsigned short reg, int codec_index) { int count; unsigned short result,tmp; u32 offset = 0; if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && codec_index != CS46XX_SECONDARY_CODEC_INDEX)) return 0xffff; chip->active_ctrl(chip, 1); if (codec_index == CS46XX_SECONDARY_CODEC_INDEX) offset = CS46XX_SECONDARY_CODEC_OFFSET; /* * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 * 3. Write ACCTL = Control Register = 460h for initiating the write7---55 * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h * 5. if DCV not cleared, break and return error * 6. Read ACSTS = Status Register = 464h, check VSTS bit */ snd_cs46xx_peekBA0(chip, BA0_ACSDA + offset); tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL); if ((tmp & ACCTL_VFRM) == 0) { dev_warn(chip->card->dev, "ACCTL_VFRM not set 0x%x\n", tmp); snd_cs46xx_pokeBA0(chip, BA0_ACCTL, (tmp & (~ACCTL_ESYN)) | ACCTL_VFRM ); msleep(50); tmp = snd_cs46xx_peekBA0(chip, BA0_ACCTL + offset); snd_cs46xx_pokeBA0(chip, BA0_ACCTL, tmp | ACCTL_ESYN | ACCTL_VFRM ); } /* * Setup the AC97 control registers on the CS461x to send the * appropriate command to the AC97 to perform the read. * ACCAD = Command Address Register = 46Ch * ACCDA = Command Data Register = 470h * ACCTL = Control Register = 460h * set DCV - will clear when process completed * set CRW - Read command * set VFRM - valid frame enabled * set ESYN - ASYNC generation enabled * set RSTN - ARST# inactive, AC97 codec not reset */ snd_cs46xx_pokeBA0(chip, BA0_ACCAD, reg); snd_cs46xx_pokeBA0(chip, BA0_ACCDA, 0); if (codec_index == CS46XX_PRIMARY_CODEC_INDEX) { snd_cs46xx_pokeBA0(chip, BA0_ACCTL,/* clear ACCTL_DCV */ ACCTL_CRW | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_CRW | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); } else { snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_TC | ACCTL_CRW | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); } /* * Wait for the read to occur. */ for (count = 0; count < 1000; count++) { /* * First, we want to wait for a short time. */ udelay(10); /* * Now, check to see if the read has completed. * ACCTL = 460h, DCV should be reset by now and 460h = 17h */ if (!(snd_cs46xx_peekBA0(chip, BA0_ACCTL) & ACCTL_DCV)) goto ok1; } dev_err(chip->card->dev, "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); result = 0xffff; goto end; ok1: /* * Wait for the valid status bit to go active. */ for (count = 0; count < 100; count++) { /* * Read the AC97 status register. * ACSTS = Status Register = 464h * VSTS - Valid Status */ if (snd_cs46xx_peekBA0(chip, BA0_ACSTS + offset) & ACSTS_VSTS) goto ok2; udelay(10); } dev_err(chip->card->dev, "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg); result = 0xffff; goto end; ok2: /* * Read the data returned from the AC97 register. * ACSDA = Status Data Register = 474h */ #if 0 dev_dbg(chip->card->dev, "e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg, snd_cs46xx_peekBA0(chip, BA0_ACSDA), snd_cs46xx_peekBA0(chip, BA0_ACCAD)); #endif //snd_cs46xx_peekBA0(chip, BA0_ACCAD); result = snd_cs46xx_peekBA0(chip, BA0_ACSDA + offset); end: chip->active_ctrl(chip, -1); return result; } static unsigned short snd_cs46xx_ac97_read(struct snd_ac97 * ac97, unsigned short reg) { struct snd_cs46xx *chip = ac97->private_data; unsigned short val; int codec_index = ac97->num; if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && codec_index != CS46XX_SECONDARY_CODEC_INDEX)) return 0xffff; val = snd_cs46xx_codec_read(chip, reg, codec_index); return val; } static void snd_cs46xx_codec_write(struct snd_cs46xx *chip, unsigned short reg, unsigned short val, int codec_index) { int count; if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && codec_index != CS46XX_SECONDARY_CODEC_INDEX)) return; chip->active_ctrl(chip, 1); /* * 1. Write ACCAD = Command Address Register = 46Ch for AC97 register address * 2. Write ACCDA = Command Data Register = 470h for data to write to AC97 * 3. Write ACCTL = Control Register = 460h for initiating the write * 4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h * 5. if DCV not cleared, break and return error */ /* * Setup the AC97 control registers on the CS461x to send the * appropriate command to the AC97 to perform the read. * ACCAD = Command Address Register = 46Ch * ACCDA = Command Data Register = 470h * ACCTL = Control Register = 460h * set DCV - will clear when process completed * reset CRW - Write command * set VFRM - valid frame enabled * set ESYN - ASYNC generation enabled * set RSTN - ARST# inactive, AC97 codec not reset */ snd_cs46xx_pokeBA0(chip, BA0_ACCAD , reg); snd_cs46xx_pokeBA0(chip, BA0_ACCDA , val); snd_cs46xx_peekBA0(chip, BA0_ACCTL); if (codec_index == CS46XX_PRIMARY_CODEC_INDEX) { snd_cs46xx_pokeBA0(chip, BA0_ACCTL, /* clear ACCTL_DCV */ ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); } else { snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_DCV | ACCTL_TC | ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); } for (count = 0; count < 4000; count++) { /* * First, we want to wait for a short time. */ udelay(10); /* * Now, check to see if the write has completed. * ACCTL = 460h, DCV should be reset by now and 460h = 07h */ if (!(snd_cs46xx_peekBA0(chip, BA0_ACCTL) & ACCTL_DCV)) { goto end; } } dev_err(chip->card->dev, "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val); end: chip->active_ctrl(chip, -1); } static void snd_cs46xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { struct snd_cs46xx *chip = ac97->private_data; int codec_index = ac97->num; if (snd_BUG_ON(codec_index != CS46XX_PRIMARY_CODEC_INDEX && codec_index != CS46XX_SECONDARY_CODEC_INDEX)) return; snd_cs46xx_codec_write(chip, reg, val, codec_index); } /* * Chip initialization */ int snd_cs46xx_download(struct snd_cs46xx *chip, u32 *src, unsigned long offset, unsigned long len) { void __iomem *dst; unsigned int bank = offset >> 16; offset = offset & 0xffff; if (snd_BUG_ON((offset & 3) || (len & 3))) return -EINVAL; dst = chip->region.idx[bank+1].remap_addr + offset; len /= sizeof(u32); /* writel already converts 32-bit value to right endianess */ while (len-- > 0) { writel(*src++, dst); dst += sizeof(u32); } return 0; } static inline void memcpy_le32(void *dst, const void *src, unsigned int len) { #ifdef __LITTLE_ENDIAN memcpy(dst, src, len); #else u32 *_dst = dst; const __le32 *_src = src; len /= 4; while (len-- > 0) *_dst++ = le32_to_cpu(*_src++); #endif } #ifdef CONFIG_SND_CS46XX_NEW_DSP static const char *module_names[CS46XX_DSP_MODULES] = { "cwc4630", "cwcasync", "cwcsnoop", "cwcbinhack", "cwcdma" }; MODULE_FIRMWARE("cs46xx/cwc4630"); MODULE_FIRMWARE("cs46xx/cwcasync"); MODULE_FIRMWARE("cs46xx/cwcsnoop"); MODULE_FIRMWARE("cs46xx/cwcbinhack"); MODULE_FIRMWARE("cs46xx/cwcdma"); static void free_module_desc(struct dsp_module_desc *module) { if (!module) return; kfree(module->module_name); kfree(module->symbol_table.symbols); if (module->segments) { int i; for (i = 0; i < module->nsegments; i++) kfree(module->segments[i].data); kfree(module->segments); } kfree(module); } /* firmware binary format: * le32 nsymbols; * struct { * le32 address; * char symbol_name[DSP_MAX_SYMBOL_NAME]; * le32 symbol_type; * } symbols[nsymbols]; * le32 nsegments; * struct { * le32 segment_type; * le32 offset; * le32 size; * le32 data[size]; * } segments[nsegments]; */ static int load_firmware(struct snd_cs46xx *chip, struct dsp_module_desc **module_ret, const char *fw_name) { int i, err; unsigned int nums, fwlen, fwsize; const __le32 *fwdat; struct dsp_module_desc *module = NULL; const struct firmware *fw; char fw_path[32]; sprintf(fw_path, "cs46xx/%s", fw_name); err = request_firmware(&fw, fw_path, &chip->pci->dev); if (err < 0) return err; fwsize = fw->size / 4; if (fwsize < 2) { err = -EINVAL; goto error; } err = -ENOMEM; module = kzalloc(sizeof(*module), GFP_KERNEL); if (!module) goto error; module->module_name = kstrdup(fw_name, GFP_KERNEL); if (!module->module_name) goto error; fwlen = 0; fwdat = (const __le32 *)fw->data; nums = module->symbol_table.nsymbols = le32_to_cpu(fwdat[fwlen++]); if (nums >= 40) goto error_inval; module->symbol_table.symbols = kcalloc(nums, sizeof(struct dsp_symbol_entry), GFP_KERNEL); if (!module->symbol_table.symbols) goto error; for (i = 0; i < nums; i++) { struct dsp_symbol_entry *entry = &module->symbol_table.symbols[i]; if (fwlen + 2 + DSP_MAX_SYMBOL_NAME / 4 > fwsize) goto error_inval; entry->address = le32_to_cpu(fwdat[fwlen++]); memcpy(entry->symbol_name, &fwdat[fwlen], DSP_MAX_SYMBOL_NAME - 1); fwlen += DSP_MAX_SYMBOL_NAME / 4; entry->symbol_type = le32_to_cpu(fwdat[fwlen++]); } if (fwlen >= fwsize) goto error_inval; nums = module->nsegments = le32_to_cpu(fwdat[fwlen++]); if (nums > 10) goto error_inval; module->segments = kcalloc(nums, sizeof(struct dsp_segment_desc), GFP_KERNEL); if (!module->segments) goto error; for (i = 0; i < nums; i++) { struct dsp_segment_desc *entry = &module->segments[i]; if (fwlen + 3 > fwsize) goto error_inval; entry->segment_type = le32_to_cpu(fwdat[fwlen++]); entry->offset = le32_to_cpu(fwdat[fwlen++]); entry->size = le32_to_cpu(fwdat[fwlen++]); if (fwlen + entry->size > fwsize) goto error_inval; entry->data = kmalloc_array(entry->size, 4, GFP_KERNEL); if (!entry->data) goto error; memcpy_le32(entry->data, &fwdat[fwlen], entry->size * 4); fwlen += entry->size; } *module_ret = module; release_firmware(fw); return 0; error_inval: err = -EINVAL; error: free_module_desc(module); release_firmware(fw); return err; } int snd_cs46xx_clear_BA1(struct snd_cs46xx *chip, unsigned long offset, unsigned long len) { void __iomem *dst; unsigned int bank = offset >> 16; offset = offset & 0xffff; if (snd_BUG_ON((offset & 3) || (len & 3))) return -EINVAL; dst = chip->region.idx[bank+1].remap_addr + offset; len /= sizeof(u32); /* writel already converts 32-bit value to right endianess */ while (len-- > 0) { writel(0, dst); dst += sizeof(u32); } return 0; } #else /* old DSP image */ struct ba1_struct { struct { u32 offset; u32 size; } memory[BA1_MEMORY_COUNT]; u32 map[BA1_DWORD_SIZE]; }; MODULE_FIRMWARE("cs46xx/ba1"); static int load_firmware(struct snd_cs46xx *chip) { const struct firmware *fw; int i, size, err; err = request_firmware(&fw, "cs46xx/ba1", &chip->pci->dev); if (err < 0) return err; if (fw->size != sizeof(*chip->ba1)) { err = -EINVAL; goto error; } chip->ba1 = vmalloc(sizeof(*chip->ba1)); if (!chip->ba1) { err = -ENOMEM; goto error; } memcpy_le32(chip->ba1, fw->data, sizeof(*chip->ba1)); /* sanity check */ size = 0; for (i = 0; i < BA1_MEMORY_COUNT; i++) size += chip->ba1->memory[i].size; if (size > BA1_DWORD_SIZE * 4) err = -EINVAL; error: release_firmware(fw); return err; } static __maybe_unused int snd_cs46xx_download_image(struct snd_cs46xx *chip) { int idx, err; unsigned int offset = 0; struct ba1_struct *ba1 = chip->ba1; for (idx = 0; idx < BA1_MEMORY_COUNT; idx++) { err = snd_cs46xx_download(chip, &ba1->map[offset], ba1->memory[idx].offset, ba1->memory[idx].size); if (err < 0) return err; offset += ba1->memory[idx].size >> 2; } return 0; } #endif /* CONFIG_SND_CS46XX_NEW_DSP */ /* * Chip reset */ static void snd_cs46xx_reset(struct snd_cs46xx *chip) { int idx; /* * Write the reset bit of the SP control register. */ snd_cs46xx_poke(chip, BA1_SPCR, SPCR_RSTSP); /* * Write the control register. */ snd_cs46xx_poke(chip, BA1_SPCR, SPCR_DRQEN); /* * Clear the trap registers. */ for (idx = 0; idx < 8; idx++) { snd_cs46xx_poke(chip, BA1_DREG, DREG_REGID_TRAP_SELECT + idx); snd_cs46xx_poke(chip, BA1_TWPR, 0xFFFF); } snd_cs46xx_poke(chip, BA1_DREG, 0); /* * Set the frame timer to reflect the number of cycles per frame. */ snd_cs46xx_poke(chip, BA1_FRMT, 0xadf); } static int cs46xx_wait_for_fifo(struct snd_cs46xx * chip,int retry_timeout) { u32 i, status = 0; /* * Make sure the previous FIFO write operation has completed. */ for(i = 0; i < 50; i++){ status = snd_cs46xx_peekBA0(chip, BA0_SERBST); if( !(status & SERBST_WBSY) ) break; mdelay(retry_timeout); } if(status & SERBST_WBSY) { dev_err(chip->card->dev, "failure waiting for FIFO command to complete\n"); return -EINVAL; } return 0; } static void snd_cs46xx_clear_serial_FIFOs(struct snd_cs46xx *chip) { int idx, powerdown = 0; unsigned int tmp; /* * See if the devices are powered down. If so, we must power them up first * or they will not respond. */ tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1); if (!(tmp & CLKCR1_SWCE)) { snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp | CLKCR1_SWCE); powerdown = 1; } /* * We want to clear out the serial port FIFOs so we don't end up playing * whatever random garbage happens to be in them. We fill the sample FIFOS * with zero (silence). */ snd_cs46xx_pokeBA0(chip, BA0_SERBWP, 0); /* * Fill all 256 sample FIFO locations. */ for (idx = 0; idx < 0xFF; idx++) { /* * Make sure the previous FIFO write operation has completed. */ if (cs46xx_wait_for_fifo(chip,1)) { dev_dbg(chip->card->dev, "failed waiting for FIFO at addr (%02X)\n", idx); if (powerdown) snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); break; } /* * Write the serial port FIFO index. */ snd_cs46xx_pokeBA0(chip, BA0_SERBAD, idx); /* * Tell the serial port to load the new value into the FIFO location. */ snd_cs46xx_pokeBA0(chip, BA0_SERBCM, SERBCM_WRC); } /* * Now, if we powered up the devices, then power them back down again. * This is kinda ugly, but should never happen. */ if (powerdown) snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); } static void snd_cs46xx_proc_start(struct snd_cs46xx *chip) { int cnt; /* * Set the frame timer to reflect the number of cycles per frame. */ snd_cs46xx_poke(chip, BA1_FRMT, 0xadf); /* * Turn on the run, run at frame, and DMA enable bits in the local copy of * the SP control register. */ snd_cs46xx_poke(chip, BA1_SPCR, SPCR_RUN | SPCR_RUNFR | SPCR_DRQEN); /* * Wait until the run at frame bit resets itself in the SP control * register. */ for (cnt = 0; cnt < 25; cnt++) { udelay(50); if (!(snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR)) break; } if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR) dev_err(chip->card->dev, "SPCR_RUNFR never reset\n"); } static void snd_cs46xx_proc_stop(struct snd_cs46xx *chip) { /* * Turn off the run, run at frame, and DMA enable bits in the local copy of * the SP control register. */ snd_cs46xx_poke(chip, BA1_SPCR, 0); } /* * Sample rate routines */ #define GOF_PER_SEC 200 static void snd_cs46xx_set_play_sample_rate(struct snd_cs46xx *chip, unsigned int rate) { unsigned long flags; unsigned int tmp1, tmp2; unsigned int phiIncr; unsigned int correctionPerGOF, correctionPerSec; /* * Compute the values used to drive the actual sample rate conversion. * The following formulas are being computed, using inline assembly * since we need to use 64 bit arithmetic to compute the values: * * phiIncr = floor((Fs,in * 2^26) / Fs,out) * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) / * GOF_PER_SEC) * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M * GOF_PER_SEC * correctionPerGOF * * i.e. * * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out) * correctionPerGOF:correctionPerSec = * dividend:remainder(ulOther / GOF_PER_SEC) */ tmp1 = rate << 16; phiIncr = tmp1 / 48000; tmp1 -= phiIncr * 48000; tmp1 <<= 10; phiIncr <<= 10; tmp2 = tmp1 / 48000; phiIncr += tmp2; tmp1 -= tmp2 * 48000; correctionPerGOF = tmp1 / GOF_PER_SEC; tmp1 -= correctionPerGOF * GOF_PER_SEC; correctionPerSec = tmp1; /* * Fill in the SampleRateConverter control block. */ spin_lock_irqsave(&chip->reg_lock, flags); snd_cs46xx_poke(chip, BA1_PSRC, ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); snd_cs46xx_poke(chip, BA1_PPI, phiIncr); spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs46xx_set_capture_sample_rate(struct snd_cs46xx *chip, unsigned int rate) { unsigned long flags; unsigned int phiIncr, coeffIncr, tmp1, tmp2; unsigned int correctionPerGOF, correctionPerSec, initialDelay; unsigned int frameGroupLength, cnt; /* * We can only decimate by up to a factor of 1/9th the hardware rate. * Correct the value if an attempt is made to stray outside that limit. */ if ((rate * 9) < 48000) rate = 48000 / 9; /* * We can not capture at a rate greater than the Input Rate (48000). * Return an error if an attempt is made to stray outside that limit. */ if (rate > 48000) rate = 48000; /* * Compute the values used to drive the actual sample rate conversion. * The following formulas are being computed, using inline assembly * since we need to use 64 bit arithmetic to compute the values: * * coeffIncr = -floor((Fs,out * 2^23) / Fs,in) * phiIncr = floor((Fs,in * 2^26) / Fs,out) * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) / * GOF_PER_SEC) * correctionPerSec = Fs,in * 2^26 - Fs,out * phiIncr - * GOF_PER_SEC * correctionPerGOF * initialDelay = ceil((24 * Fs,in) / Fs,out) * * i.e. * * coeffIncr = neg(dividend((Fs,out * 2^23) / Fs,in)) * phiIncr:ulOther = dividend:remainder((Fs,in * 2^26) / Fs,out) * correctionPerGOF:correctionPerSec = * dividend:remainder(ulOther / GOF_PER_SEC) * initialDelay = dividend(((24 * Fs,in) + Fs,out - 1) / Fs,out) */ tmp1 = rate << 16; coeffIncr = tmp1 / 48000; tmp1 -= coeffIncr * 48000; tmp1 <<= 7; coeffIncr <<= 7; coeffIncr += tmp1 / 48000; coeffIncr ^= 0xFFFFFFFF; coeffIncr++; tmp1 = 48000 << 16; phiIncr = tmp1 / rate; tmp1 -= phiIncr * rate; tmp1 <<= 10; phiIncr <<= 10; tmp2 = tmp1 / rate; phiIncr += tmp2; tmp1 -= tmp2 * rate; correctionPerGOF = tmp1 / GOF_PER_SEC; tmp1 -= correctionPerGOF * GOF_PER_SEC; correctionPerSec = tmp1; initialDelay = DIV_ROUND_UP(48000 * 24, rate); /* * Fill in the VariDecimate control block. */ spin_lock_irqsave(&chip->reg_lock, flags); snd_cs46xx_poke(chip, BA1_CSRC, ((correctionPerSec << 16) & 0xFFFF0000) | (correctionPerGOF & 0xFFFF)); snd_cs46xx_poke(chip, BA1_CCI, coeffIncr); snd_cs46xx_poke(chip, BA1_CD, (((BA1_VARIDEC_BUF_1 + (initialDelay << 2)) << 16) & 0xFFFF0000) | 0x80); snd_cs46xx_poke(chip, BA1_CPI, phiIncr); spin_unlock_irqrestore(&chip->reg_lock, flags); /* * Figure out the frame group length for the write back task. Basically, * this is just the factors of 24000 (2^6*3*5^3) that are not present in * the output sample rate. */ frameGroupLength = 1; for (cnt = 2; cnt <= 64; cnt *= 2) { if (((rate / cnt) * cnt) != rate) frameGroupLength *= 2; } if (((rate / 3) * 3) != rate) { frameGroupLength *= 3; } for (cnt = 5; cnt <= 125; cnt *= 5) { if (((rate / cnt) * cnt) != rate) frameGroupLength *= 5; } /* * Fill in the WriteBack control block. */ spin_lock_irqsave(&chip->reg_lock, flags); snd_cs46xx_poke(chip, BA1_CFG1, frameGroupLength); snd_cs46xx_poke(chip, BA1_CFG2, (0x00800000 | frameGroupLength)); snd_cs46xx_poke(chip, BA1_CCST, 0x0000FFFF); snd_cs46xx_poke(chip, BA1_CSPB, ((65536 * rate) / 24000)); snd_cs46xx_poke(chip, (BA1_CSPB + 4), 0x0000FFFF); spin_unlock_irqrestore(&chip->reg_lock, flags); } /* * PCM part */ static void snd_cs46xx_pb_trans_copy(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, size_t bytes) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm * cpcm = runtime->private_data; memcpy(cpcm->hw_buf.area + rec->hw_data, runtime->dma_area + rec->sw_data, bytes); } static int snd_cs46xx_playback_transfer(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm * cpcm = runtime->private_data; return snd_pcm_indirect_playback_transfer(substream, &cpcm->pcm_rec, snd_cs46xx_pb_trans_copy); } static void snd_cs46xx_cp_trans_copy(struct snd_pcm_substream *substream, struct snd_pcm_indirect *rec, size_t bytes) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; memcpy(runtime->dma_area + rec->sw_data, chip->capt.hw_buf.area + rec->hw_data, bytes); } static int snd_cs46xx_capture_transfer(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); return snd_pcm_indirect_capture_transfer(substream, &chip->capt.pcm_rec, snd_cs46xx_cp_trans_copy); } static snd_pcm_uframes_t snd_cs46xx_playback_direct_pointer(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); size_t ptr; struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; if (snd_BUG_ON(!cpcm->pcm_channel)) return -ENXIO; #ifdef CONFIG_SND_CS46XX_NEW_DSP ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); #else ptr = snd_cs46xx_peek(chip, BA1_PBA); #endif ptr -= cpcm->hw_buf.addr; return ptr >> cpcm->shift; } static snd_pcm_uframes_t snd_cs46xx_playback_indirect_pointer(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); size_t ptr; struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; #ifdef CONFIG_SND_CS46XX_NEW_DSP if (snd_BUG_ON(!cpcm->pcm_channel)) return -ENXIO; ptr = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 2) << 2); #else ptr = snd_cs46xx_peek(chip, BA1_PBA); #endif ptr -= cpcm->hw_buf.addr; return snd_pcm_indirect_playback_pointer(substream, &cpcm->pcm_rec, ptr); } static snd_pcm_uframes_t snd_cs46xx_capture_direct_pointer(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); size_t ptr = snd_cs46xx_peek(chip, BA1_CBA) - chip->capt.hw_buf.addr; return ptr >> chip->capt.shift; } static snd_pcm_uframes_t snd_cs46xx_capture_indirect_pointer(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); size_t ptr = snd_cs46xx_peek(chip, BA1_CBA) - chip->capt.hw_buf.addr; return snd_pcm_indirect_capture_pointer(substream, &chip->capt.pcm_rec, ptr); } static int snd_cs46xx_playback_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); /*struct snd_pcm_runtime *runtime = substream->runtime;*/ int result = 0; #ifdef CONFIG_SND_CS46XX_NEW_DSP struct snd_cs46xx_pcm *cpcm = substream->runtime->private_data; if (! cpcm->pcm_channel) { return -ENXIO; } #endif switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: #ifdef CONFIG_SND_CS46XX_NEW_DSP /* magic value to unmute PCM stream playback volume */ snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + SCBVolumeCtrl) << 2, 0x80008000); if (cpcm->pcm_channel->unlinked) cs46xx_dsp_pcm_link(chip,cpcm->pcm_channel); if (substream->runtime->periods != CS46XX_FRAGS) snd_cs46xx_playback_transfer(substream); #else spin_lock(&chip->reg_lock); if (substream->runtime->periods != CS46XX_FRAGS) snd_cs46xx_playback_transfer(substream); { unsigned int tmp; tmp = snd_cs46xx_peek(chip, BA1_PCTL); tmp &= 0x0000ffff; snd_cs46xx_poke(chip, BA1_PCTL, chip->play_ctl | tmp); } spin_unlock(&chip->reg_lock); #endif break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: #ifdef CONFIG_SND_CS46XX_NEW_DSP /* magic mute channel */ snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + SCBVolumeCtrl) << 2, 0xffffffff); if (!cpcm->pcm_channel->unlinked) cs46xx_dsp_pcm_unlink(chip,cpcm->pcm_channel); #else spin_lock(&chip->reg_lock); { unsigned int tmp; tmp = snd_cs46xx_peek(chip, BA1_PCTL); tmp &= 0x0000ffff; snd_cs46xx_poke(chip, BA1_PCTL, tmp); } spin_unlock(&chip->reg_lock); #endif break; default: result = -EINVAL; break; } return result; } static int snd_cs46xx_capture_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); unsigned int tmp; int result = 0; spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: tmp = snd_cs46xx_peek(chip, BA1_CCTL); tmp &= 0xffff0000; snd_cs46xx_poke(chip, BA1_CCTL, chip->capt.ctl | tmp); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: tmp = snd_cs46xx_peek(chip, BA1_CCTL); tmp &= 0xffff0000; snd_cs46xx_poke(chip, BA1_CCTL, tmp); break; default: result = -EINVAL; break; } spin_unlock(&chip->reg_lock); return result; } #ifdef CONFIG_SND_CS46XX_NEW_DSP static int _cs46xx_adjust_sample_rate (struct snd_cs46xx *chip, struct snd_cs46xx_pcm *cpcm, int sample_rate) { /* If PCMReaderSCB and SrcTaskSCB not created yet ... */ if ( cpcm->pcm_channel == NULL) { cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel (chip, sample_rate, cpcm, cpcm->hw_buf.addr,cpcm->pcm_channel_id); if (cpcm->pcm_channel == NULL) { dev_err(chip->card->dev, "failed to create virtual PCM channel\n"); return -ENOMEM; } cpcm->pcm_channel->sample_rate = sample_rate; } else /* if sample rate is changed */ if ((int)cpcm->pcm_channel->sample_rate != sample_rate) { int unlinked = cpcm->pcm_channel->unlinked; cs46xx_dsp_destroy_pcm_channel (chip,cpcm->pcm_channel); cpcm->pcm_channel = cs46xx_dsp_create_pcm_channel(chip, sample_rate, cpcm, cpcm->hw_buf.addr, cpcm->pcm_channel_id); if (!cpcm->pcm_channel) { dev_err(chip->card->dev, "failed to re-create virtual PCM channel\n"); return -ENOMEM; } if (!unlinked) cs46xx_dsp_pcm_link (chip,cpcm->pcm_channel); cpcm->pcm_channel->sample_rate = sample_rate; } return 0; } #endif static int snd_cs46xx_playback_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm *cpcm; int err; #ifdef CONFIG_SND_CS46XX_NEW_DSP struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); int sample_rate = params_rate(hw_params); int period_size = params_period_bytes(hw_params); #endif cpcm = runtime->private_data; #ifdef CONFIG_SND_CS46XX_NEW_DSP if (snd_BUG_ON(!sample_rate)) return -ENXIO; mutex_lock(&chip->spos_mutex); if (_cs46xx_adjust_sample_rate (chip,cpcm,sample_rate)) { mutex_unlock(&chip->spos_mutex); return -ENXIO; } snd_BUG_ON(!cpcm->pcm_channel); if (!cpcm->pcm_channel) { mutex_unlock(&chip->spos_mutex); return -ENXIO; } if (cs46xx_dsp_pcm_channel_set_period (chip,cpcm->pcm_channel,period_size)) { mutex_unlock(&chip->spos_mutex); return -EINVAL; } dev_dbg(chip->card->dev, "period_size (%d), periods (%d) buffer_size(%d)\n", period_size, params_periods(hw_params), params_buffer_bytes(hw_params)); #endif if (params_periods(hw_params) == CS46XX_FRAGS) { if (runtime->dma_area != cpcm->hw_buf.area) snd_pcm_lib_free_pages(substream); snd_pcm_set_runtime_buffer(substream, &cpcm->hw_buf); #ifdef CONFIG_SND_CS46XX_NEW_DSP if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) { substream->ops = &snd_cs46xx_playback_ops; } else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) { substream->ops = &snd_cs46xx_playback_rear_ops; } else if (cpcm->pcm_channel_id == DSP_PCM_CENTER_LFE_CHANNEL) { substream->ops = &snd_cs46xx_playback_clfe_ops; } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { substream->ops = &snd_cs46xx_playback_iec958_ops; } else { snd_BUG(); } #else substream->ops = &snd_cs46xx_playback_ops; #endif } else { if (runtime->dma_area == cpcm->hw_buf.area) snd_pcm_set_runtime_buffer(substream, NULL); err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (err < 0) { #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_unlock(&chip->spos_mutex); #endif return err; } #ifdef CONFIG_SND_CS46XX_NEW_DSP if (cpcm->pcm_channel_id == DSP_PCM_MAIN_CHANNEL) { substream->ops = &snd_cs46xx_playback_indirect_ops; } else if (cpcm->pcm_channel_id == DSP_PCM_REAR_CHANNEL) { substream->ops = &snd_cs46xx_playback_indirect_rear_ops; } else if (cpcm->pcm_channel_id == DSP_PCM_CENTER_LFE_CHANNEL) { substream->ops = &snd_cs46xx_playback_indirect_clfe_ops; } else if (cpcm->pcm_channel_id == DSP_IEC958_CHANNEL) { substream->ops = &snd_cs46xx_playback_indirect_iec958_ops; } else { snd_BUG(); } #else substream->ops = &snd_cs46xx_playback_indirect_ops; #endif } #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_unlock(&chip->spos_mutex); #endif return 0; } static int snd_cs46xx_playback_hw_free(struct snd_pcm_substream *substream) { /*struct snd_cs46xx *chip = snd_pcm_substream_chip(substream);*/ struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm *cpcm; cpcm = runtime->private_data; /* if play_back open fails, then this function is called and cpcm can actually be NULL here */ if (!cpcm) return -ENXIO; if (runtime->dma_area != cpcm->hw_buf.area) snd_pcm_lib_free_pages(substream); snd_pcm_set_runtime_buffer(substream, NULL); return 0; } static int snd_cs46xx_playback_prepare(struct snd_pcm_substream *substream) { unsigned int tmp; unsigned int pfie; struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm *cpcm; cpcm = runtime->private_data; #ifdef CONFIG_SND_CS46XX_NEW_DSP if (snd_BUG_ON(!cpcm->pcm_channel)) return -ENXIO; pfie = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2 ); pfie &= ~0x0000f03f; #else /* old dsp */ pfie = snd_cs46xx_peek(chip, BA1_PFIE); pfie &= ~0x0000f03f; #endif cpcm->shift = 2; /* if to convert from stereo to mono */ if (runtime->channels == 1) { cpcm->shift--; pfie |= 0x00002000; } /* if to convert from 8 bit to 16 bit */ if (snd_pcm_format_width(runtime->format) == 8) { cpcm->shift--; pfie |= 0x00001000; } /* if to convert to unsigned */ if (snd_pcm_format_unsigned(runtime->format)) pfie |= 0x00008000; /* Never convert byte order when sample stream is 8 bit */ if (snd_pcm_format_width(runtime->format) != 8) { /* convert from big endian to little endian */ if (snd_pcm_format_big_endian(runtime->format)) pfie |= 0x00004000; } memset(&cpcm->pcm_rec, 0, sizeof(cpcm->pcm_rec)); cpcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); cpcm->pcm_rec.hw_buffer_size = runtime->period_size * CS46XX_FRAGS << cpcm->shift; #ifdef CONFIG_SND_CS46XX_NEW_DSP tmp = snd_cs46xx_peek(chip, (cpcm->pcm_channel->pcm_reader_scb->address) << 2); tmp &= ~0x000003ff; tmp |= (4 << cpcm->shift) - 1; /* playback transaction count register */ snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address) << 2, tmp); /* playback format && interrupt enable */ snd_cs46xx_poke(chip, (cpcm->pcm_channel->pcm_reader_scb->address + 1) << 2, pfie | cpcm->pcm_channel->pcm_slot); #else snd_cs46xx_poke(chip, BA1_PBA, cpcm->hw_buf.addr); tmp = snd_cs46xx_peek(chip, BA1_PDTC); tmp &= ~0x000003ff; tmp |= (4 << cpcm->shift) - 1; snd_cs46xx_poke(chip, BA1_PDTC, tmp); snd_cs46xx_poke(chip, BA1_PFIE, pfie); snd_cs46xx_set_play_sample_rate(chip, runtime->rate); #endif return 0; } static int snd_cs46xx_capture_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int err; #ifdef CONFIG_SND_CS46XX_NEW_DSP cs46xx_dsp_pcm_ostream_set_period (chip, params_period_bytes(hw_params)); #endif if (runtime->periods == CS46XX_FRAGS) { if (runtime->dma_area != chip->capt.hw_buf.area) snd_pcm_lib_free_pages(substream); snd_pcm_set_runtime_buffer(substream, &chip->capt.hw_buf); substream->ops = &snd_cs46xx_capture_ops; } else { if (runtime->dma_area == chip->capt.hw_buf.area) snd_pcm_set_runtime_buffer(substream, NULL); err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (err < 0) return err; substream->ops = &snd_cs46xx_capture_indirect_ops; } return 0; } static int snd_cs46xx_capture_hw_free(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->dma_area != chip->capt.hw_buf.area) snd_pcm_lib_free_pages(substream); snd_pcm_set_runtime_buffer(substream, NULL); return 0; } static int snd_cs46xx_capture_prepare(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; snd_cs46xx_poke(chip, BA1_CBA, chip->capt.hw_buf.addr); chip->capt.shift = 2; memset(&chip->capt.pcm_rec, 0, sizeof(chip->capt.pcm_rec)); chip->capt.pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); chip->capt.pcm_rec.hw_buffer_size = runtime->period_size * CS46XX_FRAGS << 2; snd_cs46xx_set_capture_sample_rate(chip, runtime->rate); return 0; } static irqreturn_t snd_cs46xx_interrupt(int irq, void *dev_id) { struct snd_cs46xx *chip = dev_id; u32 status1; #ifdef CONFIG_SND_CS46XX_NEW_DSP struct dsp_spos_instance * ins = chip->dsp_spos_instance; u32 status2; int i; struct snd_cs46xx_pcm *cpcm = NULL; #endif /* * Read the Interrupt Status Register to clear the interrupt */ status1 = snd_cs46xx_peekBA0(chip, BA0_HISR); if ((status1 & 0x7fffffff) == 0) { snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_CHGM | HICR_IEV); return IRQ_NONE; } #ifdef CONFIG_SND_CS46XX_NEW_DSP status2 = snd_cs46xx_peekBA0(chip, BA0_HSR0); for (i = 0; i < DSP_MAX_PCM_CHANNELS; ++i) { if (i <= 15) { if ( status1 & (1 << i) ) { if (i == CS46XX_DSP_CAPTURE_CHANNEL) { if (chip->capt.substream) snd_pcm_period_elapsed(chip->capt.substream); } else { if (ins->pcm_channels[i].active && ins->pcm_channels[i].private_data && !ins->pcm_channels[i].unlinked) { cpcm = ins->pcm_channels[i].private_data; snd_pcm_period_elapsed(cpcm->substream); } } } } else { if ( status2 & (1 << (i - 16))) { if (ins->pcm_channels[i].active && ins->pcm_channels[i].private_data && !ins->pcm_channels[i].unlinked) { cpcm = ins->pcm_channels[i].private_data; snd_pcm_period_elapsed(cpcm->substream); } } } } #else /* old dsp */ if ((status1 & HISR_VC0) && chip->playback_pcm) { if (chip->playback_pcm->substream) snd_pcm_period_elapsed(chip->playback_pcm->substream); } if ((status1 & HISR_VC1) && chip->pcm) { if (chip->capt.substream) snd_pcm_period_elapsed(chip->capt.substream); } #endif if ((status1 & HISR_MIDI) && chip->rmidi) { unsigned char c; spin_lock(&chip->reg_lock); while ((snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_RBE) == 0) { c = snd_cs46xx_peekBA0(chip, BA0_MIDRP); if ((chip->midcr & MIDCR_RIE) == 0) continue; snd_rawmidi_receive(chip->midi_input, &c, 1); } while ((snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_TBF) == 0) { if ((chip->midcr & MIDCR_TIE) == 0) break; if (snd_rawmidi_transmit(chip->midi_output, &c, 1) != 1) { chip->midcr &= ~MIDCR_TIE; snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); break; } snd_cs46xx_pokeBA0(chip, BA0_MIDWP, c); } spin_unlock(&chip->reg_lock); } /* * EOI to the PCI part....reenables interrupts */ snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_CHGM | HICR_IEV); return IRQ_HANDLED; } static const struct snd_pcm_hardware snd_cs46xx_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER /*|*/ /*SNDRV_PCM_INFO_RESUME*/ | SNDRV_PCM_INFO_SYNC_APPLPTR), .formats = (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 5500, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (256 * 1024), .period_bytes_min = CS46XX_MIN_PERIOD_SIZE, .period_bytes_max = CS46XX_MAX_PERIOD_SIZE, .periods_min = CS46XX_FRAGS, .periods_max = 1024, .fifo_size = 0, }; static const struct snd_pcm_hardware snd_cs46xx_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER /*|*/ /*SNDRV_PCM_INFO_RESUME*/ | SNDRV_PCM_INFO_SYNC_APPLPTR), .formats = SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 5500, .rate_max = 48000, .channels_min = 2, .channels_max = 2, .buffer_bytes_max = (256 * 1024), .period_bytes_min = CS46XX_MIN_PERIOD_SIZE, .period_bytes_max = CS46XX_MAX_PERIOD_SIZE, .periods_min = CS46XX_FRAGS, .periods_max = 1024, .fifo_size = 0, }; #ifdef CONFIG_SND_CS46XX_NEW_DSP static const unsigned int period_sizes[] = { 32, 64, 128, 256, 512, 1024, 2048 }; static const struct snd_pcm_hw_constraint_list hw_constraints_period_sizes = { .count = ARRAY_SIZE(period_sizes), .list = period_sizes, .mask = 0 }; #endif static void snd_cs46xx_pcm_free_substream(struct snd_pcm_runtime *runtime) { kfree(runtime->private_data); } static int _cs46xx_playback_open_channel (struct snd_pcm_substream *substream,int pcm_channel_id) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_cs46xx_pcm * cpcm; struct snd_pcm_runtime *runtime = substream->runtime; cpcm = kzalloc(sizeof(*cpcm), GFP_KERNEL); if (cpcm == NULL) return -ENOMEM; if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, PAGE_SIZE, &cpcm->hw_buf) < 0) { kfree(cpcm); return -ENOMEM; } runtime->hw = snd_cs46xx_playback; runtime->private_data = cpcm; runtime->private_free = snd_cs46xx_pcm_free_substream; cpcm->substream = substream; #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_lock(&chip->spos_mutex); cpcm->pcm_channel = NULL; cpcm->pcm_channel_id = pcm_channel_id; snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_sizes); mutex_unlock(&chip->spos_mutex); #else chip->playback_pcm = cpcm; /* HACK */ #endif if (chip->accept_valid) substream->runtime->hw.info |= SNDRV_PCM_INFO_MMAP_VALID; chip->active_ctrl(chip, 1); return 0; } static int snd_cs46xx_playback_open(struct snd_pcm_substream *substream) { dev_dbg(substream->pcm->card->dev, "open front channel\n"); return _cs46xx_playback_open_channel(substream,DSP_PCM_MAIN_CHANNEL); } #ifdef CONFIG_SND_CS46XX_NEW_DSP static int snd_cs46xx_playback_open_rear(struct snd_pcm_substream *substream) { dev_dbg(substream->pcm->card->dev, "open rear channel\n"); return _cs46xx_playback_open_channel(substream,DSP_PCM_REAR_CHANNEL); } static int snd_cs46xx_playback_open_clfe(struct snd_pcm_substream *substream) { dev_dbg(substream->pcm->card->dev, "open center - LFE channel\n"); return _cs46xx_playback_open_channel(substream,DSP_PCM_CENTER_LFE_CHANNEL); } static int snd_cs46xx_playback_open_iec958(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); dev_dbg(chip->card->dev, "open raw iec958 channel\n"); mutex_lock(&chip->spos_mutex); cs46xx_iec958_pre_open (chip); mutex_unlock(&chip->spos_mutex); return _cs46xx_playback_open_channel(substream,DSP_IEC958_CHANNEL); } static int snd_cs46xx_playback_close(struct snd_pcm_substream *substream); static int snd_cs46xx_playback_close_iec958(struct snd_pcm_substream *substream) { int err; struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); dev_dbg(chip->card->dev, "close raw iec958 channel\n"); err = snd_cs46xx_playback_close(substream); mutex_lock(&chip->spos_mutex); cs46xx_iec958_post_close (chip); mutex_unlock(&chip->spos_mutex); return err; } #endif static int snd_cs46xx_capture_open(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, PAGE_SIZE, &chip->capt.hw_buf) < 0) return -ENOMEM; chip->capt.substream = substream; substream->runtime->hw = snd_cs46xx_capture; if (chip->accept_valid) substream->runtime->hw.info |= SNDRV_PCM_INFO_MMAP_VALID; chip->active_ctrl(chip, 1); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_sizes); #endif return 0; } static int snd_cs46xx_playback_close(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_cs46xx_pcm * cpcm; cpcm = runtime->private_data; /* when playback_open fails, then cpcm can be NULL */ if (!cpcm) return -ENXIO; #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_lock(&chip->spos_mutex); if (cpcm->pcm_channel) { cs46xx_dsp_destroy_pcm_channel(chip,cpcm->pcm_channel); cpcm->pcm_channel = NULL; } mutex_unlock(&chip->spos_mutex); #else chip->playback_pcm = NULL; #endif cpcm->substream = NULL; snd_dma_free_pages(&cpcm->hw_buf); chip->active_ctrl(chip, -1); return 0; } static int snd_cs46xx_capture_close(struct snd_pcm_substream *substream) { struct snd_cs46xx *chip = snd_pcm_substream_chip(substream); chip->capt.substream = NULL; snd_dma_free_pages(&chip->capt.hw_buf); chip->active_ctrl(chip, -1); return 0; } #ifdef CONFIG_SND_CS46XX_NEW_DSP static const struct snd_pcm_ops snd_cs46xx_playback_rear_ops = { .open = snd_cs46xx_playback_open_rear, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_direct_pointer, }; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_rear_ops = { .open = snd_cs46xx_playback_open_rear, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_indirect_pointer, .ack = snd_cs46xx_playback_transfer, }; static const struct snd_pcm_ops snd_cs46xx_playback_clfe_ops = { .open = snd_cs46xx_playback_open_clfe, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_direct_pointer, }; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_clfe_ops = { .open = snd_cs46xx_playback_open_clfe, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_indirect_pointer, .ack = snd_cs46xx_playback_transfer, }; static const struct snd_pcm_ops snd_cs46xx_playback_iec958_ops = { .open = snd_cs46xx_playback_open_iec958, .close = snd_cs46xx_playback_close_iec958, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_direct_pointer, }; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_iec958_ops = { .open = snd_cs46xx_playback_open_iec958, .close = snd_cs46xx_playback_close_iec958, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_indirect_pointer, .ack = snd_cs46xx_playback_transfer, }; #endif static const struct snd_pcm_ops snd_cs46xx_playback_ops = { .open = snd_cs46xx_playback_open, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_direct_pointer, }; static const struct snd_pcm_ops snd_cs46xx_playback_indirect_ops = { .open = snd_cs46xx_playback_open, .close = snd_cs46xx_playback_close, .hw_params = snd_cs46xx_playback_hw_params, .hw_free = snd_cs46xx_playback_hw_free, .prepare = snd_cs46xx_playback_prepare, .trigger = snd_cs46xx_playback_trigger, .pointer = snd_cs46xx_playback_indirect_pointer, .ack = snd_cs46xx_playback_transfer, }; static const struct snd_pcm_ops snd_cs46xx_capture_ops = { .open = snd_cs46xx_capture_open, .close = snd_cs46xx_capture_close, .hw_params = snd_cs46xx_capture_hw_params, .hw_free = snd_cs46xx_capture_hw_free, .prepare = snd_cs46xx_capture_prepare, .trigger = snd_cs46xx_capture_trigger, .pointer = snd_cs46xx_capture_direct_pointer, }; static const struct snd_pcm_ops snd_cs46xx_capture_indirect_ops = { .open = snd_cs46xx_capture_open, .close = snd_cs46xx_capture_close, .hw_params = snd_cs46xx_capture_hw_params, .hw_free = snd_cs46xx_capture_hw_free, .prepare = snd_cs46xx_capture_prepare, .trigger = snd_cs46xx_capture_trigger, .pointer = snd_cs46xx_capture_indirect_pointer, .ack = snd_cs46xx_capture_transfer, }; #ifdef CONFIG_SND_CS46XX_NEW_DSP #define MAX_PLAYBACK_CHANNELS (DSP_MAX_PCM_CHANNELS - 1) #else #define MAX_PLAYBACK_CHANNELS 1 #endif int snd_cs46xx_pcm(struct snd_cs46xx *chip, int device) { struct snd_pcm *pcm; int err; err = snd_pcm_new(chip->card, "CS46xx", device, MAX_PLAYBACK_CHANNELS, 1, &pcm); if (err < 0) return err; pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs46xx_capture_ops); /* global setup */ pcm->info_flags = 0; strcpy(pcm->name, "CS46xx"); chip->pcm = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 64*1024, 256*1024); return 0; } #ifdef CONFIG_SND_CS46XX_NEW_DSP int snd_cs46xx_pcm_rear(struct snd_cs46xx *chip, int device) { struct snd_pcm *pcm; int err; err = snd_pcm_new(chip->card, "CS46xx - Rear", device, MAX_PLAYBACK_CHANNELS, 0, &pcm); if (err < 0) return err; pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_rear_ops); /* global setup */ pcm->info_flags = 0; strcpy(pcm->name, "CS46xx - Rear"); chip->pcm_rear = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 64*1024, 256*1024); return 0; } int snd_cs46xx_pcm_center_lfe(struct snd_cs46xx *chip, int device) { struct snd_pcm *pcm; int err; err = snd_pcm_new(chip->card, "CS46xx - Center LFE", device, MAX_PLAYBACK_CHANNELS, 0, &pcm); if (err < 0) return err; pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_clfe_ops); /* global setup */ pcm->info_flags = 0; strcpy(pcm->name, "CS46xx - Center LFE"); chip->pcm_center_lfe = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 64*1024, 256*1024); return 0; } int snd_cs46xx_pcm_iec958(struct snd_cs46xx *chip, int device) { struct snd_pcm *pcm; int err; err = snd_pcm_new(chip->card, "CS46xx - IEC958", device, 1, 0, &pcm); if (err < 0) return err; pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs46xx_playback_iec958_ops); /* global setup */ pcm->info_flags = 0; strcpy(pcm->name, "CS46xx - IEC958"); chip->pcm_iec958 = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev, 64*1024, 256*1024); return 0; } #endif /* * Mixer routines */ static void snd_cs46xx_mixer_free_ac97(struct snd_ac97 *ac97) { struct snd_cs46xx *chip = ac97->private_data; if (snd_BUG_ON(ac97 != chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] && ac97 != chip->ac97[CS46XX_SECONDARY_CODEC_INDEX])) return; if (ac97 == chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]) { chip->ac97[CS46XX_PRIMARY_CODEC_INDEX] = NULL; chip->eapd_switch = NULL; } else chip->ac97[CS46XX_SECONDARY_CODEC_INDEX] = NULL; } static int snd_cs46xx_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 0x7fff; return 0; } static int snd_cs46xx_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int reg = kcontrol->private_value; unsigned int val = snd_cs46xx_peek(chip, reg); ucontrol->value.integer.value[0] = 0xffff - (val >> 16); ucontrol->value.integer.value[1] = 0xffff - (val & 0xffff); return 0; } static int snd_cs46xx_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int reg = kcontrol->private_value; unsigned int val = ((0xffff - ucontrol->value.integer.value[0]) << 16 | (0xffff - ucontrol->value.integer.value[1])); unsigned int old = snd_cs46xx_peek(chip, reg); int change = (old != val); if (change) { snd_cs46xx_poke(chip, reg, val); } return change; } #ifdef CONFIG_SND_CS46XX_NEW_DSP static int snd_cs46xx_vol_dac_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->dsp_spos_instance->dac_volume_left; ucontrol->value.integer.value[1] = chip->dsp_spos_instance->dac_volume_right; return 0; } static int snd_cs46xx_vol_dac_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int change = 0; if (chip->dsp_spos_instance->dac_volume_right != ucontrol->value.integer.value[0] || chip->dsp_spos_instance->dac_volume_left != ucontrol->value.integer.value[1]) { cs46xx_dsp_set_dac_volume(chip, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1]); change = 1; } return change; } #if 0 static int snd_cs46xx_vol_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_input_volume_left; ucontrol->value.integer.value[1] = chip->dsp_spos_instance->spdif_input_volume_right; return 0; } static int snd_cs46xx_vol_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int change = 0; if (chip->dsp_spos_instance->spdif_input_volume_left != ucontrol->value.integer.value[0] || chip->dsp_spos_instance->spdif_input_volume_right!= ucontrol->value.integer.value[1]) { cs46xx_dsp_set_iec958_volume (chip, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1]); change = 1; } return change; } #endif #define snd_mixer_boolean_info snd_ctl_boolean_mono_info static int snd_cs46xx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int reg = kcontrol->private_value; if (reg == CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT) ucontrol->value.integer.value[0] = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); else ucontrol->value.integer.value[0] = chip->dsp_spos_instance->spdif_status_in; return 0; } static int snd_cs46xx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int change, res; switch (kcontrol->private_value) { case CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT: mutex_lock(&chip->spos_mutex); change = (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED); if (ucontrol->value.integer.value[0] && !change) cs46xx_dsp_enable_spdif_out(chip); else if (change && !ucontrol->value.integer.value[0]) cs46xx_dsp_disable_spdif_out(chip); res = (change != (chip->dsp_spos_instance->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED)); mutex_unlock(&chip->spos_mutex); break; case CS46XX_MIXER_SPDIF_INPUT_ELEMENT: change = chip->dsp_spos_instance->spdif_status_in; if (ucontrol->value.integer.value[0] && !change) { cs46xx_dsp_enable_spdif_in(chip); /* restore volume */ } else if (change && !ucontrol->value.integer.value[0]) cs46xx_dsp_disable_spdif_in(chip); res = (change != chip->dsp_spos_instance->spdif_status_in); break; default: res = -EINVAL; snd_BUG(); /* should never happen ... */ } return res; } static int snd_cs46xx_adc_capture_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (ins->adc_input != NULL) ucontrol->value.integer.value[0] = 1; else ucontrol->value.integer.value[0] = 0; return 0; } static int snd_cs46xx_adc_capture_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; int change = 0; if (ucontrol->value.integer.value[0] && !ins->adc_input) { cs46xx_dsp_enable_adc_capture(chip); change = 1; } else if (!ucontrol->value.integer.value[0] && ins->adc_input) { cs46xx_dsp_disable_adc_capture(chip); change = 1; } return change; } static int snd_cs46xx_pcm_capture_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; if (ins->pcm_input != NULL) ucontrol->value.integer.value[0] = 1; else ucontrol->value.integer.value[0] = 0; return 0; } static int snd_cs46xx_pcm_capture_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; int change = 0; if (ucontrol->value.integer.value[0] && !ins->pcm_input) { cs46xx_dsp_enable_pcm_capture(chip); change = 1; } else if (!ucontrol->value.integer.value[0] && ins->pcm_input) { cs46xx_dsp_disable_pcm_capture(chip); change = 1; } return change; } static int snd_herc_spdif_select_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); if (val1 & EGPIODR_GPOE0) ucontrol->value.integer.value[0] = 1; else ucontrol->value.integer.value[0] = 0; return 0; } /* * Game Theatre XP card - EGPIO[0] is used to select SPDIF input optical or coaxial. */ static int snd_herc_spdif_select_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); int val2 = snd_cs46xx_peekBA0(chip, BA0_EGPIOPTR); if (ucontrol->value.integer.value[0]) { /* optical is default */ snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0 | val1); /* enable EGPIO0 output */ snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIOPTR_GPPT0 | val2); /* open-drain on output */ } else { /* coaxial */ snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE0); /* disable */ snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT0); /* disable */ } /* checking diff from the EGPIO direction register should be enough */ return (val1 != (int)snd_cs46xx_peekBA0(chip, BA0_EGPIODR)); } static int snd_cs46xx_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int snd_cs46xx_spdif_default_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; mutex_lock(&chip->spos_mutex); ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_default >> 24) & 0xff); ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_default >> 16) & 0xff); ucontrol->value.iec958.status[2] = 0; ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_default) & 0xff); mutex_unlock(&chip->spos_mutex); return 0; } static int snd_cs46xx_spdif_default_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx * chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; unsigned int val; int change; mutex_lock(&chip->spos_mutex); val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[2]) << 16) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | /* left and right validity bit */ (1 << 13) | (1 << 12); change = (unsigned int)ins->spdif_csuv_default != val; ins->spdif_csuv_default = val; if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) ) cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); mutex_unlock(&chip->spos_mutex); return change; } static int snd_cs46xx_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = 0xff; ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[2] = 0x00; ucontrol->value.iec958.status[3] = 0xff; return 0; } static int snd_cs46xx_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; mutex_lock(&chip->spos_mutex); ucontrol->value.iec958.status[0] = _wrap_all_bits((ins->spdif_csuv_stream >> 24) & 0xff); ucontrol->value.iec958.status[1] = _wrap_all_bits((ins->spdif_csuv_stream >> 16) & 0xff); ucontrol->value.iec958.status[2] = 0; ucontrol->value.iec958.status[3] = _wrap_all_bits((ins->spdif_csuv_stream) & 0xff); mutex_unlock(&chip->spos_mutex); return 0; } static int snd_cs46xx_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx * chip = snd_kcontrol_chip(kcontrol); struct dsp_spos_instance * ins = chip->dsp_spos_instance; unsigned int val; int change; mutex_lock(&chip->spos_mutex); val = ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[0]) << 24) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[1]) << 16) | ((unsigned int)_wrap_all_bits(ucontrol->value.iec958.status[3])) | /* left and right validity bit */ (1 << 13) | (1 << 12); change = ins->spdif_csuv_stream != val; ins->spdif_csuv_stream = val; if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN ) cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV,val); mutex_unlock(&chip->spos_mutex); return change; } #endif /* CONFIG_SND_CS46XX_NEW_DSP */ static const struct snd_kcontrol_new snd_cs46xx_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DAC Volume", .info = snd_cs46xx_vol_info, #ifndef CONFIG_SND_CS46XX_NEW_DSP .get = snd_cs46xx_vol_get, .put = snd_cs46xx_vol_put, .private_value = BA1_PVOL, #else .get = snd_cs46xx_vol_dac_get, .put = snd_cs46xx_vol_dac_put, #endif }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "ADC Volume", .info = snd_cs46xx_vol_info, .get = snd_cs46xx_vol_get, .put = snd_cs46xx_vol_put, #ifndef CONFIG_SND_CS46XX_NEW_DSP .private_value = BA1_CVOL, #else .private_value = (VARIDECIMATE_SCB_ADDR + 0xE) << 2, #endif }, #ifdef CONFIG_SND_CS46XX_NEW_DSP { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "ADC Capture Switch", .info = snd_mixer_boolean_info, .get = snd_cs46xx_adc_capture_get, .put = snd_cs46xx_adc_capture_put }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "DAC Capture Switch", .info = snd_mixer_boolean_info, .get = snd_cs46xx_pcm_capture_get, .put = snd_cs46xx_pcm_capture_put }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), .info = snd_mixer_boolean_info, .get = snd_cs46xx_iec958_get, .put = snd_cs46xx_iec958_put, .private_value = CS46XX_MIXER_SPDIF_OUTPUT_ELEMENT, }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = SNDRV_CTL_NAME_IEC958("Input ",NONE,SWITCH), .info = snd_mixer_boolean_info, .get = snd_cs46xx_iec958_get, .put = snd_cs46xx_iec958_put, .private_value = CS46XX_MIXER_SPDIF_INPUT_ELEMENT, }, #if 0 /* Input IEC958 volume does not work for the moment. (Benny) */ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = SNDRV_CTL_NAME_IEC958("Input ",NONE,VOLUME), .info = snd_cs46xx_vol_info, .get = snd_cs46xx_vol_iec958_get, .put = snd_cs46xx_vol_iec958_put, .private_value = (ASYNCRX_SCB_ADDR + 0xE) << 2, }, #endif { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .info = snd_cs46xx_spdif_info, .get = snd_cs46xx_spdif_default_get, .put = snd_cs46xx_spdif_default_put, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), .info = snd_cs46xx_spdif_info, .get = snd_cs46xx_spdif_mask_get, .access = SNDRV_CTL_ELEM_ACCESS_READ }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), .info = snd_cs46xx_spdif_info, .get = snd_cs46xx_spdif_stream_get, .put = snd_cs46xx_spdif_stream_put }, #endif }; #ifdef CONFIG_SND_CS46XX_NEW_DSP /* set primary cs4294 codec into Extended Audio Mode */ static int snd_cs46xx_front_dup_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); unsigned short val; val = snd_ac97_read(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], AC97_CSR_ACMODE); ucontrol->value.integer.value[0] = (val & 0x200) ? 0 : 1; return 0; } static int snd_cs46xx_front_dup_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_cs46xx *chip = snd_kcontrol_chip(kcontrol); return snd_ac97_update_bits(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], AC97_CSR_ACMODE, 0x200, ucontrol->value.integer.value[0] ? 0 : 0x200); } static const struct snd_kcontrol_new snd_cs46xx_front_dup_ctl = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Duplicate Front", .info = snd_mixer_boolean_info, .get = snd_cs46xx_front_dup_get, .put = snd_cs46xx_front_dup_put, }; #endif #ifdef CONFIG_SND_CS46XX_NEW_DSP /* Only available on the Hercules Game Theater XP soundcard */ static const struct snd_kcontrol_new snd_hercules_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Optical/Coaxial SPDIF Input Switch", .info = snd_mixer_boolean_info, .get = snd_herc_spdif_select_get, .put = snd_herc_spdif_select_put, }, }; static void snd_cs46xx_codec_reset (struct snd_ac97 * ac97) { unsigned long end_time; int err; /* reset to defaults */ snd_ac97_write(ac97, AC97_RESET, 0); /* set the desired CODEC mode */ if (ac97->num == CS46XX_PRIMARY_CODEC_INDEX) { dev_dbg(ac97->bus->card->dev, "CODEC1 mode %04x\n", 0x0); snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x0); } else if (ac97->num == CS46XX_SECONDARY_CODEC_INDEX) { dev_dbg(ac97->bus->card->dev, "CODEC2 mode %04x\n", 0x3); snd_cs46xx_ac97_write(ac97, AC97_CSR_ACMODE, 0x3); } else { snd_BUG(); /* should never happen ... */ } udelay(50); /* it's necessary to wait awhile until registers are accessible after RESET */ /* because the PCM or MASTER volume registers can be modified, */ /* the REC_GAIN register is used for tests */ end_time = jiffies + HZ; do { unsigned short ext_mid; /* use preliminary reads to settle the communication */ snd_ac97_read(ac97, AC97_RESET); snd_ac97_read(ac97, AC97_VENDOR_ID1); snd_ac97_read(ac97, AC97_VENDOR_ID2); /* modem? */ ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID); if (ext_mid != 0xffff && (ext_mid & 1) != 0) return; /* test if we can write to the record gain volume register */ snd_ac97_write(ac97, AC97_REC_GAIN, 0x8a05); err = snd_ac97_read(ac97, AC97_REC_GAIN); if (err == 0x8a05) return; msleep(10); } while (time_after_eq(end_time, jiffies)); dev_err(ac97->bus->card->dev, "CS46xx secondary codec doesn't respond!\n"); } #endif static int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec) { int idx, err; struct snd_ac97_template ac97; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; ac97.private_free = snd_cs46xx_mixer_free_ac97; ac97.num = codec; if (chip->amplifier_ctrl == amp_voyetra) ac97.scaps = AC97_SCAP_INV_EAPD; if (codec == CS46XX_SECONDARY_CODEC_INDEX) { snd_cs46xx_codec_write(chip, AC97_RESET, 0, codec); udelay(10); if (snd_cs46xx_codec_read(chip, AC97_RESET, codec) & 0x8000) { dev_dbg(chip->card->dev, "secondary codec not present\n"); return -ENXIO; } } snd_cs46xx_codec_write(chip, AC97_MASTER, 0x8000, codec); for (idx = 0; idx < 100; ++idx) { if (snd_cs46xx_codec_read(chip, AC97_MASTER, codec) == 0x8000) { err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97[codec]); return err; } msleep(10); } dev_dbg(chip->card->dev, "codec %d detection timeout\n", codec); return -ENXIO; } int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) { struct snd_card *card = chip->card; int err; unsigned int idx; static const struct snd_ac97_bus_ops ops = { #ifdef CONFIG_SND_CS46XX_NEW_DSP .reset = snd_cs46xx_codec_reset, #endif .write = snd_cs46xx_ac97_write, .read = snd_cs46xx_ac97_read, }; /* detect primary codec */ chip->nr_ac97_codecs = 0; dev_dbg(chip->card->dev, "detecting primary codec\n"); err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus); if (err < 0) return err; if (cs46xx_detect_codec(chip, CS46XX_PRIMARY_CODEC_INDEX) < 0) return -ENXIO; chip->nr_ac97_codecs = 1; #ifdef CONFIG_SND_CS46XX_NEW_DSP dev_dbg(chip->card->dev, "detecting secondary codec\n"); /* try detect a secondary codec */ if (! cs46xx_detect_codec(chip, CS46XX_SECONDARY_CODEC_INDEX)) chip->nr_ac97_codecs = 2; #endif /* CONFIG_SND_CS46XX_NEW_DSP */ /* add cs4630 mixer controls */ for (idx = 0; idx < ARRAY_SIZE(snd_cs46xx_controls); idx++) { struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&snd_cs46xx_controls[idx], chip); if (kctl && kctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM) kctl->id.device = spdif_device; err = snd_ctl_add(card, kctl); if (err < 0) return err; } /* get EAPD mixer switch (for voyetra hack) */ chip->eapd_switch = snd_ctl_find_id_mixer(chip->card, "External Amplifier"); #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->nr_ac97_codecs == 1) { unsigned int id2 = chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]->id & 0xffff; if ((id2 & 0xfff0) == 0x5920) { /* CS4294 and CS4298 */ err = snd_ctl_add(card, snd_ctl_new1(&snd_cs46xx_front_dup_ctl, chip)); if (err < 0) return err; snd_ac97_write_cache(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX], AC97_CSR_ACMODE, 0x200); } } /* do soundcard specific mixer setup */ if (chip->mixer_init) { dev_dbg(chip->card->dev, "calling chip->mixer_init(chip);\n"); chip->mixer_init(chip); } #endif /* turn on amplifier */ chip->amplifier_ctrl(chip, 1); return 0; } /* * RawMIDI interface */ static void snd_cs46xx_midi_reset(struct snd_cs46xx *chip) { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, MIDCR_MRST); udelay(100); snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } static int snd_cs46xx_midi_input_open(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; chip->active_ctrl(chip, 1); spin_lock_irq(&chip->reg_lock); chip->uartm |= CS46XX_MODE_INPUT; chip->midcr |= MIDCR_RXE; chip->midi_input = substream; if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { snd_cs46xx_midi_reset(chip); } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } spin_unlock_irq(&chip->reg_lock); return 0; } static int snd_cs46xx_midi_input_close(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; spin_lock_irq(&chip->reg_lock); chip->midcr &= ~(MIDCR_RXE | MIDCR_RIE); chip->midi_input = NULL; if (!(chip->uartm & CS46XX_MODE_OUTPUT)) { snd_cs46xx_midi_reset(chip); } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } chip->uartm &= ~CS46XX_MODE_INPUT; spin_unlock_irq(&chip->reg_lock); chip->active_ctrl(chip, -1); return 0; } static int snd_cs46xx_midi_output_open(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; chip->active_ctrl(chip, 1); spin_lock_irq(&chip->reg_lock); chip->uartm |= CS46XX_MODE_OUTPUT; chip->midcr |= MIDCR_TXE; chip->midi_output = substream; if (!(chip->uartm & CS46XX_MODE_INPUT)) { snd_cs46xx_midi_reset(chip); } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } spin_unlock_irq(&chip->reg_lock); return 0; } static int snd_cs46xx_midi_output_close(struct snd_rawmidi_substream *substream) { struct snd_cs46xx *chip = substream->rmidi->private_data; spin_lock_irq(&chip->reg_lock); chip->midcr &= ~(MIDCR_TXE | MIDCR_TIE); chip->midi_output = NULL; if (!(chip->uartm & CS46XX_MODE_INPUT)) { snd_cs46xx_midi_reset(chip); } else { snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } chip->uartm &= ~CS46XX_MODE_OUTPUT; spin_unlock_irq(&chip->reg_lock); chip->active_ctrl(chip, -1); return 0; } static void snd_cs46xx_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_cs46xx *chip = substream->rmidi->private_data; spin_lock_irqsave(&chip->reg_lock, flags); if (up) { if ((chip->midcr & MIDCR_RIE) == 0) { chip->midcr |= MIDCR_RIE; snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } else { if (chip->midcr & MIDCR_RIE) { chip->midcr &= ~MIDCR_RIE; snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } spin_unlock_irqrestore(&chip->reg_lock, flags); } static void snd_cs46xx_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_cs46xx *chip = substream->rmidi->private_data; unsigned char byte; spin_lock_irqsave(&chip->reg_lock, flags); if (up) { if ((chip->midcr & MIDCR_TIE) == 0) { chip->midcr |= MIDCR_TIE; /* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */ while ((chip->midcr & MIDCR_TIE) && (snd_cs46xx_peekBA0(chip, BA0_MIDSR) & MIDSR_TBF) == 0) { if (snd_rawmidi_transmit(substream, &byte, 1) != 1) { chip->midcr &= ~MIDCR_TIE; } else { snd_cs46xx_pokeBA0(chip, BA0_MIDWP, byte); } } snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } else { if (chip->midcr & MIDCR_TIE) { chip->midcr &= ~MIDCR_TIE; snd_cs46xx_pokeBA0(chip, BA0_MIDCR, chip->midcr); } } spin_unlock_irqrestore(&chip->reg_lock, flags); } static const struct snd_rawmidi_ops snd_cs46xx_midi_output = { .open = snd_cs46xx_midi_output_open, .close = snd_cs46xx_midi_output_close, .trigger = snd_cs46xx_midi_output_trigger, }; static const struct snd_rawmidi_ops snd_cs46xx_midi_input = { .open = snd_cs46xx_midi_input_open, .close = snd_cs46xx_midi_input_close, .trigger = snd_cs46xx_midi_input_trigger, }; int snd_cs46xx_midi(struct snd_cs46xx *chip, int device) { struct snd_rawmidi *rmidi; int err; err = snd_rawmidi_new(chip->card, "CS46XX", device, 1, 1, &rmidi); if (err < 0) return err; strcpy(rmidi->name, "CS46XX"); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs46xx_midi_output); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs46xx_midi_input); rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; rmidi->private_data = chip; chip->rmidi = rmidi; return 0; } /* * gameport interface */ #if IS_REACHABLE(CONFIG_GAMEPORT) static void snd_cs46xx_gameport_trigger(struct gameport *gameport) { struct snd_cs46xx *chip = gameport_get_port_data(gameport); if (snd_BUG_ON(!chip)) return; snd_cs46xx_pokeBA0(chip, BA0_JSPT, 0xFF); //outb(gameport->io, 0xFF); } static unsigned char snd_cs46xx_gameport_read(struct gameport *gameport) { struct snd_cs46xx *chip = gameport_get_port_data(gameport); if (snd_BUG_ON(!chip)) return 0; return snd_cs46xx_peekBA0(chip, BA0_JSPT); //inb(gameport->io); } static int snd_cs46xx_gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons) { struct snd_cs46xx *chip = gameport_get_port_data(gameport); unsigned js1, js2, jst; if (snd_BUG_ON(!chip)) return 0; js1 = snd_cs46xx_peekBA0(chip, BA0_JSC1); js2 = snd_cs46xx_peekBA0(chip, BA0_JSC2); jst = snd_cs46xx_peekBA0(chip, BA0_JSPT); *buttons = (~jst >> 4) & 0x0F; axes[0] = ((js1 & JSC1_Y1V_MASK) >> JSC1_Y1V_SHIFT) & 0xFFFF; axes[1] = ((js1 & JSC1_X1V_MASK) >> JSC1_X1V_SHIFT) & 0xFFFF; axes[2] = ((js2 & JSC2_Y2V_MASK) >> JSC2_Y2V_SHIFT) & 0xFFFF; axes[3] = ((js2 & JSC2_X2V_MASK) >> JSC2_X2V_SHIFT) & 0xFFFF; for(jst=0;jst<4;++jst) if(axes[jst]==0xFFFF) axes[jst] = -1; return 0; } static int snd_cs46xx_gameport_open(struct gameport *gameport, int mode) { switch (mode) { case GAMEPORT_MODE_COOKED: return 0; case GAMEPORT_MODE_RAW: return 0; default: return -1; } return 0; } int snd_cs46xx_gameport(struct snd_cs46xx *chip) { struct gameport *gp; chip->gameport = gp = gameport_allocate_port(); if (!gp) { dev_err(chip->card->dev, "cannot allocate memory for gameport\n"); return -ENOMEM; } gameport_set_name(gp, "CS46xx Gameport"); gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); gameport_set_dev_parent(gp, &chip->pci->dev); gameport_set_port_data(gp, chip); gp->open = snd_cs46xx_gameport_open; gp->read = snd_cs46xx_gameport_read; gp->trigger = snd_cs46xx_gameport_trigger; gp->cooked_read = snd_cs46xx_gameport_cooked_read; snd_cs46xx_pokeBA0(chip, BA0_JSIO, 0xFF); // ? snd_cs46xx_pokeBA0(chip, BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW); gameport_register_port(gp); return 0; } static inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) { if (chip->gameport) { gameport_unregister_port(chip->gameport); chip->gameport = NULL; } } #else int snd_cs46xx_gameport(struct snd_cs46xx *chip) { return -ENOSYS; } static inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) { } #endif /* CONFIG_GAMEPORT */ #ifdef CONFIG_SND_PROC_FS /* * proc interface */ static ssize_t snd_cs46xx_io_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, char __user *buf, size_t count, loff_t pos) { struct snd_cs46xx_region *region = entry->private_data; if (copy_to_user_fromio(buf, region->remap_addr + pos, count)) return -EFAULT; return count; } static const struct snd_info_entry_ops snd_cs46xx_proc_io_ops = { .read = snd_cs46xx_io_read, }; static int snd_cs46xx_proc_init(struct snd_card *card, struct snd_cs46xx *chip) { struct snd_info_entry *entry; int idx; for (idx = 0; idx < 5; idx++) { struct snd_cs46xx_region *region = &chip->region.idx[idx]; if (! snd_card_proc_new(card, region->name, &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = chip; entry->c.ops = &snd_cs46xx_proc_io_ops; entry->size = region->size; entry->mode = S_IFREG | 0400; } } #ifdef CONFIG_SND_CS46XX_NEW_DSP cs46xx_dsp_proc_init(card, chip); #endif return 0; } static int snd_cs46xx_proc_done(struct snd_cs46xx *chip) { #ifdef CONFIG_SND_CS46XX_NEW_DSP cs46xx_dsp_proc_done(chip); #endif return 0; } #else /* !CONFIG_SND_PROC_FS */ #define snd_cs46xx_proc_init(card, chip) #define snd_cs46xx_proc_done(chip) #endif /* * stop the h/w */ static void snd_cs46xx_hw_stop(struct snd_cs46xx *chip) { unsigned int tmp; tmp = snd_cs46xx_peek(chip, BA1_PFIE); tmp &= ~0x0000f03f; tmp |= 0x00000010; snd_cs46xx_poke(chip, BA1_PFIE, tmp); /* playback interrupt disable */ tmp = snd_cs46xx_peek(chip, BA1_CIE); tmp &= ~0x0000003f; tmp |= 0x00000011; snd_cs46xx_poke(chip, BA1_CIE, tmp); /* capture interrupt disable */ /* * Stop playback DMA. */ tmp = snd_cs46xx_peek(chip, BA1_PCTL); snd_cs46xx_poke(chip, BA1_PCTL, tmp & 0x0000ffff); /* * Stop capture DMA. */ tmp = snd_cs46xx_peek(chip, BA1_CCTL); snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); /* * Reset the processor. */ snd_cs46xx_reset(chip); snd_cs46xx_proc_stop(chip); /* * Power down the PLL. */ snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, 0); /* * Turn off the Processor by turning off the software clock enable flag in * the clock control register. */ tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1) & ~CLKCR1_SWCE; snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); } static void snd_cs46xx_free(struct snd_card *card) { struct snd_cs46xx *chip = card->private_data; #ifdef CONFIG_SND_CS46XX_NEW_DSP int idx; #endif if (chip->active_ctrl) chip->active_ctrl(chip, 1); snd_cs46xx_remove_gameport(chip); if (chip->amplifier_ctrl) chip->amplifier_ctrl(chip, -chip->amplifier); /* force to off */ snd_cs46xx_proc_done(chip); snd_cs46xx_hw_stop(chip); if (chip->active_ctrl) chip->active_ctrl(chip, -chip->amplifier); #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->dsp_spos_instance) { cs46xx_dsp_spos_destroy(chip); chip->dsp_spos_instance = NULL; } for (idx = 0; idx < CS46XX_DSP_MODULES; idx++) free_module_desc(chip->modules[idx]); #else vfree(chip->ba1); #endif } /* * initialize chip */ static int snd_cs46xx_chip_init(struct snd_cs46xx *chip) { int timeout; /* * First, blast the clock control register to zero so that the PLL starts * out in a known state, and blast the master serial port control register * to zero so that the serial ports also start out in a known state. */ snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, 0); snd_cs46xx_pokeBA0(chip, BA0_SERMC1, 0); /* * If we are in AC97 mode, then we must set the part to a host controlled * AC-link. Otherwise, we won't be able to bring up the link. */ #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_2_0 | SERACC_TWO_CODECS); /* 2.00 dual codecs */ /* snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_2_0); */ /* 2.00 codec */ #else snd_cs46xx_pokeBA0(chip, BA0_SERACC, SERACC_HSP | SERACC_CHIP_TYPE_1_03); /* 1.03 codec */ #endif /* * Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97 * spec) and then drive it high. This is done for non AC97 modes since * there might be logic external to the CS461x that uses the ARST# line * for a reset. */ snd_cs46xx_pokeBA0(chip, BA0_ACCTL, 0); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, 0); #endif udelay(50); snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_RSTN); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_RSTN); #endif /* * The first thing we do here is to enable sync generation. As soon * as we start receiving bit clock, we'll start producing the SYNC * signal. */ snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_ESYN | ACCTL_RSTN); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_ESYN | ACCTL_RSTN); #endif /* * Now wait for a short while to allow the AC97 part to start * generating bit clock (so we don't try to start the PLL without an * input clock). */ mdelay(10); /* * Set the serial port timing configuration, so that * the clock control circuit gets its clock from the correct place. */ snd_cs46xx_pokeBA0(chip, BA0_SERMC1, SERMC1_PTC_AC97); /* * Write the selected clock control setup to the hardware. Do not turn on * SWCE yet (if requested), so that the devices clocked by the output of * PLL are not clocked until the PLL is stable. */ snd_cs46xx_pokeBA0(chip, BA0_PLLCC, PLLCC_LPF_1050_2780_KHZ | PLLCC_CDR_73_104_MHZ); snd_cs46xx_pokeBA0(chip, BA0_PLLM, 0x3a); snd_cs46xx_pokeBA0(chip, BA0_CLKCR2, CLKCR2_PDIVS_8); /* * Power up the PLL. */ snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, CLKCR1_PLLP); /* * Wait until the PLL has stabilized. */ msleep(100); /* * Turn on clocking of the core so that we can setup the serial ports. */ snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, CLKCR1_PLLP | CLKCR1_SWCE); /* * Enable FIFO Host Bypass */ snd_cs46xx_pokeBA0(chip, BA0_SERBCF, SERBCF_HBP); /* * Fill the serial port FIFOs with silence. */ snd_cs46xx_clear_serial_FIFOs(chip); /* * Set the serial port FIFO pointer to the first sample in the FIFO. */ /* snd_cs46xx_pokeBA0(chip, BA0_SERBSP, 0); */ /* * Write the serial port configuration to the part. The master * enable bit is not set until all other values have been written. */ snd_cs46xx_pokeBA0(chip, BA0_SERC1, SERC1_SO1F_AC97 | SERC1_SO1EN); snd_cs46xx_pokeBA0(chip, BA0_SERC2, SERC2_SI1F_AC97 | SERC1_SO1EN); snd_cs46xx_pokeBA0(chip, BA0_SERMC1, SERMC1_PTC_AC97 | SERMC1_MSPE); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_SERC7, SERC7_ASDI2EN); snd_cs46xx_pokeBA0(chip, BA0_SERC3, 0); snd_cs46xx_pokeBA0(chip, BA0_SERC4, 0); snd_cs46xx_pokeBA0(chip, BA0_SERC5, 0); snd_cs46xx_pokeBA0(chip, BA0_SERC6, 1); #endif mdelay(5); /* * Wait for the codec ready signal from the AC97 codec. */ timeout = 150; while (timeout-- > 0) { /* * Read the AC97 status register to see if we've seen a CODEC READY * signal from the AC97 codec. */ if (snd_cs46xx_peekBA0(chip, BA0_ACSTS) & ACSTS_CRDY) goto ok1; msleep(10); } dev_err(chip->card->dev, "create - never read codec ready from AC'97\n"); dev_err(chip->card->dev, "it is not probably bug, try to use CS4236 driver\n"); return -EIO; ok1: #ifdef CONFIG_SND_CS46XX_NEW_DSP { int count; for (count = 0; count < 150; count++) { /* First, we want to wait for a short time. */ udelay(25); if (snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY) break; } /* * Make sure CODEC is READY. */ if (!(snd_cs46xx_peekBA0(chip, BA0_ACSTS2) & ACSTS_CRDY)) dev_dbg(chip->card->dev, "never read card ready from secondary AC'97\n"); } #endif /* * Assert the vaid frame signal so that we can start sending commands * to the AC97 codec. */ snd_cs46xx_pokeBA0(chip, BA0_ACCTL, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); #ifdef CONFIG_SND_CS46XX_NEW_DSP snd_cs46xx_pokeBA0(chip, BA0_ACCTL2, ACCTL_VFRM | ACCTL_ESYN | ACCTL_RSTN); #endif /* * Wait until we've sampled input slots 3 and 4 as valid, meaning that * the codec is pumping ADC data across the AC-link. */ timeout = 150; while (timeout-- > 0) { /* * Read the input slot valid register and see if input slots 3 and * 4 are valid yet. */ if ((snd_cs46xx_peekBA0(chip, BA0_ACISV) & (ACISV_ISV3 | ACISV_ISV4)) == (ACISV_ISV3 | ACISV_ISV4)) goto ok2; msleep(10); } #ifndef CONFIG_SND_CS46XX_NEW_DSP dev_err(chip->card->dev, "create - never read ISV3 & ISV4 from AC'97\n"); return -EIO; #else /* This may happen on a cold boot with a Terratec SiXPack 5.1. Reloading the driver may help, if there's other soundcards with the same problem I would like to know. (Benny) */ dev_err(chip->card->dev, "never read ISV3 & ISV4 from AC'97\n"); dev_err(chip->card->dev, "Try reloading the ALSA driver, if you find something\n"); dev_err(chip->card->dev, "broken or not working on your soundcard upon\n"); dev_err(chip->card->dev, "this message please report to [email protected]\n"); return -EIO; #endif ok2: /* * Now, assert valid frame and the slot 3 and 4 valid bits. This will * commense the transfer of digital audio data to the AC97 codec. */ snd_cs46xx_pokeBA0(chip, BA0_ACOSV, ACOSV_SLV3 | ACOSV_SLV4); /* * Power down the DAC and ADC. We will power them up (if) when we need * them. */ /* snd_cs46xx_pokeBA0(chip, BA0_AC97_POWERDOWN, 0x300); */ /* * Turn off the Processor by turning off the software clock enable flag in * the clock control register. */ /* tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1) & ~CLKCR1_SWCE; */ /* snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); */ return 0; } /* * start and load DSP */ static void cs46xx_enable_stream_irqs(struct snd_cs46xx *chip) { unsigned int tmp; snd_cs46xx_pokeBA0(chip, BA0_HICR, HICR_IEV | HICR_CHGM); tmp = snd_cs46xx_peek(chip, BA1_PFIE); tmp &= ~0x0000f03f; snd_cs46xx_poke(chip, BA1_PFIE, tmp); /* playback interrupt enable */ tmp = snd_cs46xx_peek(chip, BA1_CIE); tmp &= ~0x0000003f; tmp |= 0x00000001; snd_cs46xx_poke(chip, BA1_CIE, tmp); /* capture interrupt enable */ } int snd_cs46xx_start_dsp(struct snd_cs46xx *chip) { unsigned int tmp; #ifdef CONFIG_SND_CS46XX_NEW_DSP int i; #endif int err; /* * Reset the processor. */ snd_cs46xx_reset(chip); /* * Download the image to the processor. */ #ifdef CONFIG_SND_CS46XX_NEW_DSP for (i = 0; i < CS46XX_DSP_MODULES; i++) { err = load_firmware(chip, &chip->modules[i], module_names[i]); if (err < 0) { dev_err(chip->card->dev, "firmware load error [%s]\n", module_names[i]); return err; } err = cs46xx_dsp_load_module(chip, chip->modules[i]); if (err < 0) { dev_err(chip->card->dev, "image download error [%s]\n", module_names[i]); return err; } } if (cs46xx_dsp_scb_and_task_init(chip) < 0) return -EIO; #else err = load_firmware(chip); if (err < 0) return err; /* old image */ err = snd_cs46xx_download_image(chip); if (err < 0) { dev_err(chip->card->dev, "image download error\n"); return err; } /* * Stop playback DMA. */ tmp = snd_cs46xx_peek(chip, BA1_PCTL); chip->play_ctl = tmp & 0xffff0000; snd_cs46xx_poke(chip, BA1_PCTL, tmp & 0x0000ffff); #endif /* * Stop capture DMA. */ tmp = snd_cs46xx_peek(chip, BA1_CCTL); chip->capt.ctl = tmp & 0x0000ffff; snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); mdelay(5); snd_cs46xx_set_play_sample_rate(chip, 8000); snd_cs46xx_set_capture_sample_rate(chip, 8000); snd_cs46xx_proc_start(chip); cs46xx_enable_stream_irqs(chip); #ifndef CONFIG_SND_CS46XX_NEW_DSP /* set the attenuation to 0dB */ snd_cs46xx_poke(chip, BA1_PVOL, 0x80008000); snd_cs46xx_poke(chip, BA1_CVOL, 0x80008000); #endif return 0; } /* * AMP control - null AMP */ static void amp_none(struct snd_cs46xx *chip, int change) { } #ifdef CONFIG_SND_CS46XX_NEW_DSP static int voyetra_setup_eapd_slot(struct snd_cs46xx *chip) { u32 idx, valid_slots,tmp,powerdown = 0; u16 modem_power,pin_config,logic_type; dev_dbg(chip->card->dev, "cs46xx_setup_eapd_slot()+\n"); /* * See if the devices are powered down. If so, we must power them up first * or they will not respond. */ tmp = snd_cs46xx_peekBA0(chip, BA0_CLKCR1); if (!(tmp & CLKCR1_SWCE)) { snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp | CLKCR1_SWCE); powerdown = 1; } /* * Clear PRA. The Bonzo chip will be used for GPIO not for modem * stuff. */ if(chip->nr_ac97_codecs != 2) { dev_err(chip->card->dev, "cs46xx_setup_eapd_slot() - no secondary codec configured\n"); return -EINVAL; } modem_power = snd_cs46xx_codec_read (chip, AC97_EXTENDED_MSTATUS, CS46XX_SECONDARY_CODEC_INDEX); modem_power &=0xFEFF; snd_cs46xx_codec_write(chip, AC97_EXTENDED_MSTATUS, modem_power, CS46XX_SECONDARY_CODEC_INDEX); /* * Set GPIO pin's 7 and 8 so that they are configured for output. */ pin_config = snd_cs46xx_codec_read (chip, AC97_GPIO_CFG, CS46XX_SECONDARY_CODEC_INDEX); pin_config &=0x27F; snd_cs46xx_codec_write(chip, AC97_GPIO_CFG, pin_config, CS46XX_SECONDARY_CODEC_INDEX); /* * Set GPIO pin's 7 and 8 so that they are compatible with CMOS logic. */ logic_type = snd_cs46xx_codec_read(chip, AC97_GPIO_POLARITY, CS46XX_SECONDARY_CODEC_INDEX); logic_type &=0x27F; snd_cs46xx_codec_write (chip, AC97_GPIO_POLARITY, logic_type, CS46XX_SECONDARY_CODEC_INDEX); valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV); valid_slots |= 0x200; snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots); if ( cs46xx_wait_for_fifo(chip,1) ) { dev_dbg(chip->card->dev, "FIFO is busy\n"); return -EINVAL; } /* * Fill slots 12 with the correct value for the GPIO pins. */ for(idx = 0x90; idx <= 0x9F; idx++) { /* * Initialize the fifo so that bits 7 and 8 are on. * * Remember that the GPIO pins in bonzo are shifted by 4 bits to * the left. 0x1800 corresponds to bits 7 and 8. */ snd_cs46xx_pokeBA0(chip, BA0_SERBWP, 0x1800); /* * Wait for command to complete */ if ( cs46xx_wait_for_fifo(chip,200) ) { dev_dbg(chip->card->dev, "failed waiting for FIFO at addr (%02X)\n", idx); return -EINVAL; } /* * Write the serial port FIFO index. */ snd_cs46xx_pokeBA0(chip, BA0_SERBAD, idx); /* * Tell the serial port to load the new value into the FIFO location. */ snd_cs46xx_pokeBA0(chip, BA0_SERBCM, SERBCM_WRC); } /* wait for last command to complete */ cs46xx_wait_for_fifo(chip,200); /* * Now, if we powered up the devices, then power them back down again. * This is kinda ugly, but should never happen. */ if (powerdown) snd_cs46xx_pokeBA0(chip, BA0_CLKCR1, tmp); return 0; } #endif /* * Crystal EAPD mode */ static void amp_voyetra(struct snd_cs46xx *chip, int change) { /* Manage the EAPD bit on the Crystal 4297 and the Analog AD1885 */ #ifdef CONFIG_SND_CS46XX_NEW_DSP int old = chip->amplifier; #endif int oval, val; chip->amplifier += change; oval = snd_cs46xx_codec_read(chip, AC97_POWERDOWN, CS46XX_PRIMARY_CODEC_INDEX); val = oval; if (chip->amplifier) { /* Turn the EAPD amp on */ val |= 0x8000; } else { /* Turn the EAPD amp off */ val &= ~0x8000; } if (val != oval) { snd_cs46xx_codec_write(chip, AC97_POWERDOWN, val, CS46XX_PRIMARY_CODEC_INDEX); if (chip->eapd_switch) snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->eapd_switch->id); } #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->amplifier && !old) { voyetra_setup_eapd_slot(chip); } #endif } static void hercules_init(struct snd_cs46xx *chip) { /* default: AMP off, and SPDIF input optical */ snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0); snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIODR_GPOE0); } /* * Game Theatre XP card - EGPIO[2] is used to enable the external amp. */ static void amp_hercules(struct snd_cs46xx *chip, int change) { int old = chip->amplifier; int val1 = snd_cs46xx_peekBA0(chip, BA0_EGPIODR); int val2 = snd_cs46xx_peekBA0(chip, BA0_EGPIOPTR); chip->amplifier += change; if (chip->amplifier && !old) { dev_dbg(chip->card->dev, "Hercules amplifier ON\n"); snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE2 | val1); /* enable EGPIO2 output */ snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIOPTR_GPPT2 | val2); /* open-drain on output */ } else if (old && !chip->amplifier) { dev_dbg(chip->card->dev, "Hercules amplifier OFF\n"); snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, val1 & ~EGPIODR_GPOE2); /* disable */ snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, val2 & ~EGPIOPTR_GPPT2); /* disable */ } } static void voyetra_mixer_init (struct snd_cs46xx *chip) { dev_dbg(chip->card->dev, "initializing Voyetra mixer\n"); /* Enable SPDIF out */ snd_cs46xx_pokeBA0(chip, BA0_EGPIODR, EGPIODR_GPOE0); snd_cs46xx_pokeBA0(chip, BA0_EGPIOPTR, EGPIODR_GPOE0); } static void hercules_mixer_init (struct snd_cs46xx *chip) { #ifdef CONFIG_SND_CS46XX_NEW_DSP unsigned int idx; int err; struct snd_card *card = chip->card; #endif /* set EGPIO to default */ hercules_init(chip); dev_dbg(chip->card->dev, "initializing Hercules mixer\n"); #ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->in_suspend) return; for (idx = 0 ; idx < ARRAY_SIZE(snd_hercules_controls); idx++) { struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&snd_hercules_controls[idx], chip); err = snd_ctl_add(card, kctl); if (err < 0) { dev_err(card->dev, "failed to initialize Hercules mixer (%d)\n", err); break; } } #endif } #if 0 /* * Untested */ static void amp_voyetra_4294(struct snd_cs46xx *chip, int change) { chip->amplifier += change; if (chip->amplifier) { /* Switch the GPIO pins 7 and 8 to open drain */ snd_cs46xx_codec_write(chip, 0x4C, snd_cs46xx_codec_read(chip, 0x4C) & 0xFE7F); snd_cs46xx_codec_write(chip, 0x4E, snd_cs46xx_codec_read(chip, 0x4E) | 0x0180); /* Now wake the AMP (this might be backwards) */ snd_cs46xx_codec_write(chip, 0x54, snd_cs46xx_codec_read(chip, 0x54) & ~0x0180); } else { snd_cs46xx_codec_write(chip, 0x54, snd_cs46xx_codec_read(chip, 0x54) | 0x0180); } } #endif /* * Handle the CLKRUN on a thinkpad. We must disable CLKRUN support * whenever we need to beat on the chip. * * The original idea and code for this hack comes from David Kaiser at * Linuxcare. Perhaps one day Crystal will document their chips well * enough to make them useful. */ static void clkrun_hack(struct snd_cs46xx *chip, int change) { u16 control, nval; if (!chip->acpi_port) return; chip->amplifier += change; /* Read ACPI port */ nval = control = inw(chip->acpi_port + 0x10); /* Flip CLKRUN off while running */ if (! chip->amplifier) nval |= 0x2000; else nval &= ~0x2000; if (nval != control) outw(nval, chip->acpi_port + 0x10); } /* * detect intel piix4 */ static void clkrun_init(struct snd_cs46xx *chip) { struct pci_dev *pdev; u8 pp; chip->acpi_port = 0; pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL); if (pdev == NULL) return; /* Not a thinkpad thats for sure */ /* Find the control port */ pci_read_config_byte(pdev, 0x41, &pp); chip->acpi_port = pp << 8; pci_dev_put(pdev); } /* * Card subid table */ struct cs_card_type { u16 vendor; u16 id; char *name; void (*init)(struct snd_cs46xx *); void (*amp)(struct snd_cs46xx *, int); void (*active)(struct snd_cs46xx *, int); void (*mixer_init)(struct snd_cs46xx *); }; static struct cs_card_type cards[] = { { .vendor = 0x1489, .id = 0x7001, .name = "Genius Soundmaker 128 value", /* nothing special */ }, { .vendor = 0x5053, .id = 0x3357, .name = "Voyetra", .amp = amp_voyetra, .mixer_init = voyetra_mixer_init, }, { .vendor = 0x1071, .id = 0x6003, .name = "Mitac MI6020/21", .amp = amp_voyetra, }, /* Hercules Game Theatre XP */ { .vendor = 0x14af, /* Guillemot Corporation */ .id = 0x0050, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, { .vendor = 0x1681, .id = 0x0050, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, { .vendor = 0x1681, .id = 0x0051, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, { .vendor = 0x1681, .id = 0x0052, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, { .vendor = 0x1681, .id = 0x0053, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, { .vendor = 0x1681, .id = 0x0054, .name = "Hercules Game Theatre XP", .amp = amp_hercules, .mixer_init = hercules_mixer_init, }, /* Herculess Fortissimo */ { .vendor = 0x1681, .id = 0xa010, .name = "Hercules Gamesurround Fortissimo II", }, { .vendor = 0x1681, .id = 0xa011, .name = "Hercules Gamesurround Fortissimo III 7.1", }, /* Teratec */ { .vendor = 0x153b, .id = 0x112e, .name = "Terratec DMX XFire 1024", }, { .vendor = 0x153b, .id = 0x1136, .name = "Terratec SiXPack 5.1", }, /* Not sure if the 570 needs the clkrun hack */ { .vendor = PCI_VENDOR_ID_IBM, .id = 0x0132, .name = "Thinkpad 570", .init = clkrun_init, .active = clkrun_hack, }, { .vendor = PCI_VENDOR_ID_IBM, .id = 0x0153, .name = "Thinkpad 600X/A20/T20", .init = clkrun_init, .active = clkrun_hack, }, { .vendor = PCI_VENDOR_ID_IBM, .id = 0x1010, .name = "Thinkpad 600E (unsupported)", }, {} /* terminator */ }; /* * APM support */ #ifdef CONFIG_PM_SLEEP static const unsigned int saved_regs[] = { BA0_ACOSV, /*BA0_ASER_FADDR,*/ BA0_ASER_MASTER, BA1_PVOL, BA1_CVOL, }; static int snd_cs46xx_suspend(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_cs46xx *chip = card->private_data; int i, amp_saved; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); chip->in_suspend = 1; // chip->ac97_powerdown = snd_cs46xx_codec_read(chip, AC97_POWER_CONTROL); // chip->ac97_general_purpose = snd_cs46xx_codec_read(chip, BA0_AC97_GENERAL_PURPOSE); snd_ac97_suspend(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]); snd_ac97_suspend(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]); /* save some registers */ for (i = 0; i < ARRAY_SIZE(saved_regs); i++) chip->saved_regs[i] = snd_cs46xx_peekBA0(chip, saved_regs[i]); amp_saved = chip->amplifier; /* turn off amp */ chip->amplifier_ctrl(chip, -chip->amplifier); snd_cs46xx_hw_stop(chip); /* disable CLKRUN */ chip->active_ctrl(chip, -chip->amplifier); chip->amplifier = amp_saved; /* restore the status */ return 0; } static int snd_cs46xx_resume(struct device *dev) { struct snd_card *card = dev_get_drvdata(dev); struct snd_cs46xx *chip = card->private_data; int amp_saved; #ifdef CONFIG_SND_CS46XX_NEW_DSP int i; #endif unsigned int tmp; amp_saved = chip->amplifier; chip->amplifier = 0; chip->active_ctrl(chip, 1); /* force to on */ snd_cs46xx_chip_init(chip); snd_cs46xx_reset(chip); #ifdef CONFIG_SND_CS46XX_NEW_DSP cs46xx_dsp_resume(chip); /* restore some registers */ for (i = 0; i < ARRAY_SIZE(saved_regs); i++) snd_cs46xx_pokeBA0(chip, saved_regs[i], chip->saved_regs[i]); #else snd_cs46xx_download_image(chip); #endif #if 0 snd_cs46xx_codec_write(chip, BA0_AC97_GENERAL_PURPOSE, chip->ac97_general_purpose); snd_cs46xx_codec_write(chip, AC97_POWER_CONTROL, chip->ac97_powerdown); mdelay(10); snd_cs46xx_codec_write(chip, BA0_AC97_POWERDOWN, chip->ac97_powerdown); mdelay(5); #endif snd_ac97_resume(chip->ac97[CS46XX_PRIMARY_CODEC_INDEX]); snd_ac97_resume(chip->ac97[CS46XX_SECONDARY_CODEC_INDEX]); /* * Stop capture DMA. */ tmp = snd_cs46xx_peek(chip, BA1_CCTL); chip->capt.ctl = tmp & 0x0000ffff; snd_cs46xx_poke(chip, BA1_CCTL, tmp & 0xffff0000); mdelay(5); /* reset playback/capture */ snd_cs46xx_set_play_sample_rate(chip, 8000); snd_cs46xx_set_capture_sample_rate(chip, 8000); snd_cs46xx_proc_start(chip); cs46xx_enable_stream_irqs(chip); if (amp_saved) chip->amplifier_ctrl(chip, 1); /* turn amp on */ else chip->active_ctrl(chip, -1); /* disable CLKRUN */ chip->amplifier = amp_saved; chip->in_suspend = 0; snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } SIMPLE_DEV_PM_OPS(snd_cs46xx_pm, snd_cs46xx_suspend, snd_cs46xx_resume); #endif /* CONFIG_PM_SLEEP */ /* */ int snd_cs46xx_create(struct snd_card *card, struct pci_dev *pci, int external_amp, int thinkpad) { struct snd_cs46xx *chip = card->private_data; int err, idx; struct snd_cs46xx_region *region; struct cs_card_type *cp; u16 ss_card, ss_vendor; /* enable PCI device */ err = pcim_enable_device(pci); if (err < 0) return err; spin_lock_init(&chip->reg_lock); #ifdef CONFIG_SND_CS46XX_NEW_DSP mutex_init(&chip->spos_mutex); #endif chip->card = card; chip->pci = pci; chip->irq = -1; err = pci_request_regions(pci, "CS46xx"); if (err < 0) return err; chip->ba0_addr = pci_resource_start(pci, 0); chip->ba1_addr = pci_resource_start(pci, 1); if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) { dev_err(chip->card->dev, "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr); return -ENOMEM; } region = &chip->region.name.ba0; strcpy(region->name, "CS46xx_BA0"); region->base = chip->ba0_addr; region->size = CS46XX_BA0_SIZE; region = &chip->region.name.data0; strcpy(region->name, "CS46xx_BA1_data0"); region->base = chip->ba1_addr + BA1_SP_DMEM0; region->size = CS46XX_BA1_DATA0_SIZE; region = &chip->region.name.data1; strcpy(region->name, "CS46xx_BA1_data1"); region->base = chip->ba1_addr + BA1_SP_DMEM1; region->size = CS46XX_BA1_DATA1_SIZE; region = &chip->region.name.pmem; strcpy(region->name, "CS46xx_BA1_pmem"); region->base = chip->ba1_addr + BA1_SP_PMEM; region->size = CS46XX_BA1_PRG_SIZE; region = &chip->region.name.reg; strcpy(region->name, "CS46xx_BA1_reg"); region->base = chip->ba1_addr + BA1_SP_REG; region->size = CS46XX_BA1_REG_SIZE; /* set up amp and clkrun hack */ pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &ss_vendor); pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &ss_card); for (cp = &cards[0]; cp->name; cp++) { if (cp->vendor == ss_vendor && cp->id == ss_card) { dev_dbg(chip->card->dev, "hack for %s enabled\n", cp->name); chip->amplifier_ctrl = cp->amp; chip->active_ctrl = cp->active; chip->mixer_init = cp->mixer_init; if (cp->init) cp->init(chip); break; } } if (external_amp) { dev_info(chip->card->dev, "Crystal EAPD support forced on.\n"); chip->amplifier_ctrl = amp_voyetra; } if (thinkpad) { dev_info(chip->card->dev, "Activating CLKRUN hack for Thinkpad.\n"); chip->active_ctrl = clkrun_hack; clkrun_init(chip); } if (chip->amplifier_ctrl == NULL) chip->amplifier_ctrl = amp_none; if (chip->active_ctrl == NULL) chip->active_ctrl = amp_none; chip->active_ctrl(chip, 1); /* enable CLKRUN */ pci_set_master(pci); for (idx = 0; idx < 5; idx++) { region = &chip->region.idx[idx]; region->remap_addr = devm_ioremap(&pci->dev, region->base, region->size); if (region->remap_addr == NULL) { dev_err(chip->card->dev, "%s ioremap problem\n", region->name); return -ENOMEM; } } if (devm_request_irq(&pci->dev, pci->irq, snd_cs46xx_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; card->private_free = snd_cs46xx_free; #ifdef CONFIG_SND_CS46XX_NEW_DSP chip->dsp_spos_instance = cs46xx_dsp_spos_create(chip); if (!chip->dsp_spos_instance) return -ENOMEM; #endif err = snd_cs46xx_chip_init(chip); if (err < 0) return err; snd_cs46xx_proc_init(card, chip); #ifdef CONFIG_PM_SLEEP chip->saved_regs = devm_kmalloc_array(&pci->dev, ARRAY_SIZE(saved_regs), sizeof(*chip->saved_regs), GFP_KERNEL); if (!chip->saved_regs) return -ENOMEM; #endif chip->active_ctrl(chip, -1); /* disable CLKRUN */ return 0; }
linux-master
sound/pci/cs46xx/cs46xx_lib.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram miXart soundcards * * DSP firmware management * * Copyright (c) 2003 by Digigram <[email protected]> */ #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/firmware.h> #include <linux/vmalloc.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/io.h> #include <sound/core.h> #include "mixart.h" #include "mixart_mixer.h" #include "mixart_core.h" #include "mixart_hwdep.h" /** * mixart_wait_nice_for_register_value - wait for a value on a peudo register, * exit with a timeout * * @mgr: pointer to miXart manager structure * @offset: unsigned pseudo_register base + offset of value * @is_egal: wait for the equal value * @value: value * @timeout: timeout in centisenconds */ static int mixart_wait_nice_for_register_value(struct mixart_mgr *mgr, u32 offset, int is_egal, u32 value, unsigned long timeout) { unsigned long end_time = jiffies + (timeout * HZ / 100); u32 read; do { /* we may take too long time in this loop. * so give controls back to kernel if needed. */ cond_resched(); read = readl_be( MIXART_MEM( mgr, offset )); if(is_egal) { if(read == value) return 0; } else { /* wait for different value */ if(read != value) return 0; } } while ( time_after_eq(end_time, jiffies) ); return -EBUSY; } /* structures needed to upload elf code packets */ struct snd_mixart_elf32_ehdr { u8 e_ident[16]; __be16 e_type; __be16 e_machine; __be32 e_version; __be32 e_entry; __be32 e_phoff; __be32 e_shoff; __be32 e_flags; __be16 e_ehsize; __be16 e_phentsize; __be16 e_phnum; __be16 e_shentsize; __be16 e_shnum; __be16 e_shstrndx; }; struct snd_mixart_elf32_phdr { __be32 p_type; __be32 p_offset; __be32 p_vaddr; __be32 p_paddr; __be32 p_filesz; __be32 p_memsz; __be32 p_flags; __be32 p_align; }; static int mixart_load_elf(struct mixart_mgr *mgr, const struct firmware *dsp ) { char elf32_magic_number[4] = {0x7f,'E','L','F'}; struct snd_mixart_elf32_ehdr *elf_header; int i; elf_header = (struct snd_mixart_elf32_ehdr *)dsp->data; for( i=0; i<4; i++ ) if ( elf32_magic_number[i] != elf_header->e_ident[i] ) return -EINVAL; if( elf_header->e_phoff != 0 ) { struct snd_mixart_elf32_phdr elf_programheader; for( i=0; i < be16_to_cpu(elf_header->e_phnum); i++ ) { u32 pos = be32_to_cpu(elf_header->e_phoff) + (u32)(i * be16_to_cpu(elf_header->e_phentsize)); memcpy( &elf_programheader, dsp->data + pos, sizeof(elf_programheader) ); if(elf_programheader.p_type != 0) { if( elf_programheader.p_filesz != 0 ) { memcpy_toio( MIXART_MEM( mgr, be32_to_cpu(elf_programheader.p_vaddr)), dsp->data + be32_to_cpu( elf_programheader.p_offset ), be32_to_cpu( elf_programheader.p_filesz )); } } } } return 0; } /* * get basic information and init miXart */ /* audio IDs for request to the board */ #define MIXART_FIRST_ANA_AUDIO_ID 0 #define MIXART_FIRST_DIG_AUDIO_ID 8 static int mixart_enum_connectors(struct mixart_mgr *mgr) { u32 k; int err; struct mixart_msg request; struct mixart_enum_connector_resp *connector; struct mixart_audio_info_req *audio_info_req; struct mixart_audio_info_resp *audio_info; connector = kmalloc(sizeof(*connector), GFP_KERNEL); audio_info_req = kmalloc(sizeof(*audio_info_req), GFP_KERNEL); audio_info = kmalloc(sizeof(*audio_info), GFP_KERNEL); if (! connector || ! audio_info_req || ! audio_info) { err = -ENOMEM; goto __error; } audio_info_req->line_max_level = MIXART_FLOAT_P_22_0_TO_HEX; audio_info_req->micro_max_level = MIXART_FLOAT_M_20_0_TO_HEX; audio_info_req->cd_max_level = MIXART_FLOAT____0_0_TO_HEX; request.message_id = MSG_SYSTEM_ENUM_PLAY_CONNECTOR; request.uid = (struct mixart_uid){0,0}; /* board num = 0 */ request.data = NULL; request.size = 0; err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector); if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) { dev_err(&mgr->pci->dev, "error MSG_SYSTEM_ENUM_PLAY_CONNECTOR\n"); err = -EINVAL; goto __error; } for(k=0; k < connector->uid_count; k++) { struct mixart_pipe *pipe; if(k < MIXART_FIRST_DIG_AUDIO_ID) { pipe = &mgr->chip[k/2]->pipe_out_ana; } else { pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_out_dig; } if(k & 1) { pipe->uid_right_connector = connector->uid[k]; /* odd */ } else { pipe->uid_left_connector = connector->uid[k]; /* even */ } /* dev_dbg(&mgr->pci->dev, "playback connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */ /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */ request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO; request.uid = connector->uid[k]; request.data = audio_info_req; request.size = sizeof(*audio_info_req); err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info); if( err < 0 ) { dev_err(&mgr->pci->dev, "error MSG_CONNECTOR_GET_AUDIO_INFO\n"); goto __error; } /*dev_dbg(&mgr->pci->dev, "play analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/ } request.message_id = MSG_SYSTEM_ENUM_RECORD_CONNECTOR; request.uid = (struct mixart_uid){0,0}; /* board num = 0 */ request.data = NULL; request.size = 0; err = snd_mixart_send_msg(mgr, &request, sizeof(*connector), connector); if((err < 0) || (connector->error_code) || (connector->uid_count > MIXART_MAX_PHYS_CONNECTORS)) { dev_err(&mgr->pci->dev, "error MSG_SYSTEM_ENUM_RECORD_CONNECTOR\n"); err = -EINVAL; goto __error; } for(k=0; k < connector->uid_count; k++) { struct mixart_pipe *pipe; if(k < MIXART_FIRST_DIG_AUDIO_ID) { pipe = &mgr->chip[k/2]->pipe_in_ana; } else { pipe = &mgr->chip[(k-MIXART_FIRST_DIG_AUDIO_ID)/2]->pipe_in_dig; } if(k & 1) { pipe->uid_right_connector = connector->uid[k]; /* odd */ } else { pipe->uid_left_connector = connector->uid[k]; /* even */ } /* dev_dbg(&mgr->pci->dev, "capture connector[%d].object_id = %x\n", k, connector->uid[k].object_id); */ /* TODO: really need send_msg MSG_CONNECTOR_GET_AUDIO_INFO for each connector ? perhaps for analog level caps ? */ request.message_id = MSG_CONNECTOR_GET_AUDIO_INFO; request.uid = connector->uid[k]; request.data = audio_info_req; request.size = sizeof(*audio_info_req); err = snd_mixart_send_msg(mgr, &request, sizeof(*audio_info), audio_info); if( err < 0 ) { dev_err(&mgr->pci->dev, "error MSG_CONNECTOR_GET_AUDIO_INFO\n"); goto __error; } /*dev_dbg(&mgr->pci->dev, "rec analog_info.analog_level_present = %x\n", audio_info->info.analog_info.analog_level_present);*/ } err = 0; __error: kfree(connector); kfree(audio_info_req); kfree(audio_info); return err; } static int mixart_enum_physio(struct mixart_mgr *mgr) { u32 k; int err; struct mixart_msg request; struct mixart_uid get_console_mgr; struct mixart_return_uid console_mgr; struct mixart_uid_enumeration phys_io; /* get the uid for the console manager */ get_console_mgr.object_id = 0; get_console_mgr.desc = MSG_CONSOLE_MANAGER | 0; /* cardindex = 0 */ request.message_id = MSG_CONSOLE_GET_CLOCK_UID; request.uid = get_console_mgr; request.data = &get_console_mgr; request.size = sizeof(get_console_mgr); err = snd_mixart_send_msg(mgr, &request, sizeof(console_mgr), &console_mgr); if( (err < 0) || (console_mgr.error_code != 0) ) { dev_dbg(&mgr->pci->dev, "error MSG_CONSOLE_GET_CLOCK_UID : err=%x\n", console_mgr.error_code); return -EINVAL; } /* used later for clock issues ! */ mgr->uid_console_manager = console_mgr.uid; request.message_id = MSG_SYSTEM_ENUM_PHYSICAL_IO; request.uid = (struct mixart_uid){0,0}; request.data = &console_mgr.uid; request.size = sizeof(console_mgr.uid); err = snd_mixart_send_msg(mgr, &request, sizeof(phys_io), &phys_io); if( (err < 0) || ( phys_io.error_code != 0 ) ) { dev_err(&mgr->pci->dev, "error MSG_SYSTEM_ENUM_PHYSICAL_IO err(%x) error_code(%x)\n", err, phys_io.error_code); return -EINVAL; } /* min 2 phys io per card (analog in + analog out) */ if (phys_io.nb_uid < MIXART_MAX_CARDS * 2) return -EINVAL; for(k=0; k<mgr->num_cards; k++) { mgr->chip[k]->uid_in_analog_physio = phys_io.uid[k]; mgr->chip[k]->uid_out_analog_physio = phys_io.uid[phys_io.nb_uid/2 + k]; } return 0; } static int mixart_first_init(struct mixart_mgr *mgr) { u32 k; int err; struct mixart_msg request; err = mixart_enum_connectors(mgr); if (err < 0) return err; err = mixart_enum_physio(mgr); if (err < 0) return err; /* send a synchro command to card (necessary to do this before first MSG_STREAM_START_STREAM_GRP_PACKET) */ /* though why not here */ request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD; request.uid = (struct mixart_uid){0,0}; request.data = NULL; request.size = 0; /* this command has no data. response is a 32 bit status */ err = snd_mixart_send_msg(mgr, &request, sizeof(k), &k); if( (err < 0) || (k != 0) ) { dev_err(&mgr->pci->dev, "error MSG_SYSTEM_SEND_SYNCHRO_CMD\n"); return err == 0 ? -EINVAL : err; } return 0; } /* firmware base addresses (when hard coded) */ #define MIXART_MOTHERBOARD_XLX_BASE_ADDRESS 0x00600000 static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmware *dsp) { int err, card_index; u32 status_xilinx, status_elf, status_daught; u32 val; /* read motherboard xilinx status */ status_xilinx = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_STATUS_OFFSET )); /* read elf status */ status_elf = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_ELF_STATUS_OFFSET )); /* read daughterboard xilinx status */ status_daught = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_DXLX_STATUS_OFFSET )); /* motherboard xilinx status 5 will say that the board is performing a reset */ if (status_xilinx == 5) { dev_err(&mgr->pci->dev, "miXart is resetting !\n"); return -EAGAIN; /* try again later */ } switch (index) { case MIXART_MOTHERBOARD_XLX_INDEX: /* xilinx already loaded ? */ if (status_xilinx == 4) { dev_dbg(&mgr->pci->dev, "xilinx is already loaded !\n"); return 0; } /* the status should be 0 == "idle" */ if (status_xilinx != 0) { dev_err(&mgr->pci->dev, "xilinx load error ! status = %d\n", status_xilinx); return -EIO; /* modprob -r may help ? */ } /* check xilinx validity */ if (((u32*)(dsp->data))[0] == 0xffffffff) return -EINVAL; if (dsp->size % 4) return -EINVAL; /* set xilinx status to copying */ writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET )); /* setup xilinx base address */ writel_be( MIXART_MOTHERBOARD_XLX_BASE_ADDRESS, MIXART_MEM( mgr,MIXART_PSEUDOREG_MXLX_BASE_ADDR_OFFSET )); /* setup code size for xilinx file */ writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_SIZE_OFFSET )); /* copy xilinx code */ memcpy_toio( MIXART_MEM( mgr, MIXART_MOTHERBOARD_XLX_BASE_ADDRESS), dsp->data, dsp->size); /* set xilinx status to copy finished */ writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET )); /* return, because no further processing needed */ return 0; case MIXART_MOTHERBOARD_ELF_INDEX: if (status_elf == 4) { dev_dbg(&mgr->pci->dev, "elf file already loaded !\n"); return 0; } /* the status should be 0 == "idle" */ if (status_elf != 0) { dev_err(&mgr->pci->dev, "elf load error ! status = %d\n", status_elf); return -EIO; /* modprob -r may help ? */ } /* wait for xilinx status == 4 */ err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */ if (err < 0) { dev_err(&mgr->pci->dev, "xilinx was not loaded or " "could not be started\n"); return err; } /* init some data on the card */ writel_be( 0, MIXART_MEM( mgr, MIXART_PSEUDOREG_BOARDNUMBER ) ); /* set miXart boardnumber to 0 */ writel_be( 0, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* reset pointer to flow table on miXart */ /* set elf status to copying */ writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET )); /* process the copying of the elf packets */ err = mixart_load_elf( mgr, dsp ); if (err < 0) return err; /* set elf status to copy finished */ writel_be( 2, MIXART_MEM( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET )); /* wait for elf status == 4 */ err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */ if (err < 0) { dev_err(&mgr->pci->dev, "elf could not be started\n"); return err; } /* miXart waits at this point on the pointer to the flow table */ writel_be( (u32)mgr->flowinfo.addr, MIXART_MEM( mgr, MIXART_FLOWTABLE_PTR ) ); /* give pointer of flow table to miXart */ return 0; /* return, another xilinx file has to be loaded before */ case MIXART_AESEBUBOARD_XLX_INDEX: default: /* elf and xilinx should be loaded */ if (status_elf != 4 || status_xilinx != 4) { dev_err(&mgr->pci->dev, "xilinx or elf not " "successfully loaded\n"); return -EIO; /* modprob -r may help ? */ } /* wait for daughter detection != 0 */ err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */ if (err < 0) { dev_err(&mgr->pci->dev, "error starting elf file\n"); return err; } /* the board type can now be retrieved */ mgr->board_type = (DAUGHTER_TYPE_MASK & readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DBRD_TYPE_OFFSET))); if (mgr->board_type == MIXART_DAUGHTER_TYPE_NONE) break; /* no daughter board; the file does not have to be loaded, continue after the switch */ /* only if aesebu daughter board presence (elf code must run) */ if (mgr->board_type != MIXART_DAUGHTER_TYPE_AES ) return -EINVAL; /* daughter should be idle */ if (status_daught != 0) { dev_err(&mgr->pci->dev, "daughter load error ! status = %d\n", status_daught); return -EIO; /* modprob -r may help ? */ } /* check daughterboard xilinx validity */ if (((u32*)(dsp->data))[0] == 0xffffffff) return -EINVAL; if (dsp->size % 4) return -EINVAL; /* inform mixart about the size of the file */ writel_be( dsp->size, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_SIZE_OFFSET )); /* set daughterboard status to 1 */ writel_be( 1, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET )); /* wait for status == 2 */ err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */ if (err < 0) { dev_err(&mgr->pci->dev, "daughter board load error\n"); return err; } /* get the address where to write the file */ val = readl_be( MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_BASE_ADDR_OFFSET )); if (!val) return -EINVAL; /* copy daughterboard xilinx code */ memcpy_toio( MIXART_MEM( mgr, val), dsp->data, dsp->size); /* set daughterboard status to 4 */ writel_be( 4, MIXART_MEM( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET )); /* continue with init */ break; } /* end of switch file index*/ /* wait for daughter status == 3 */ err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */ if (err < 0) { dev_err(&mgr->pci->dev, "daughter board could not be initialised\n"); return err; } /* init mailbox (communication with embedded) */ snd_mixart_init_mailbox(mgr); /* first communication with embedded */ err = mixart_first_init(mgr); if (err < 0) { dev_err(&mgr->pci->dev, "miXart could not be set up\n"); return err; } /* create devices and mixer in accordance with HW options*/ for (card_index = 0; card_index < mgr->num_cards; card_index++) { struct snd_mixart *chip = mgr->chip[card_index]; err = snd_mixart_create_pcm(chip); if (err < 0) return err; if (card_index == 0) { err = snd_mixart_create_mixer(chip->mgr); if (err < 0) return err; } err = snd_card_register(chip->card); if (err < 0) return err; } dev_dbg(&mgr->pci->dev, "miXart firmware downloaded and successfully set up\n"); return 0; } int snd_mixart_setup_firmware(struct mixart_mgr *mgr) { static const char * const fw_files[3] = { "miXart8.xlx", "miXart8.elf", "miXart8AES.xlx" }; char path[32]; const struct firmware *fw_entry; int i, err; for (i = 0; i < 3; i++) { sprintf(path, "mixart/%s", fw_files[i]); if (request_firmware(&fw_entry, path, &mgr->pci->dev)) { dev_err(&mgr->pci->dev, "miXart: can't load firmware %s\n", path); return -ENOENT; } /* fake hwdep dsp record */ err = mixart_dsp_load(mgr, i, fw_entry); release_firmware(fw_entry); if (err < 0) return err; mgr->dsp_loaded |= 1 << i; } return 0; } MODULE_FIRMWARE("mixart/miXart8.xlx"); MODULE_FIRMWARE("mixart/miXart8.elf"); MODULE_FIRMWARE("mixart/miXart8AES.xlx");
linux-master
sound/pci/mixart/mixart_hwdep.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram miXart soundcards * * low level interface with interrupt handling and mail box implementation * * Copyright (c) 2003 by Digigram <[email protected]> */ #include <linux/interrupt.h> #include <linux/mutex.h> #include <linux/pci.h> #include <linux/io.h> #include <sound/core.h> #include "mixart.h" #include "mixart_hwdep.h" #include "mixart_core.h" #define MSG_TIMEOUT_JIFFIES (400 * HZ) / 1000 /* 400 ms */ #define MSG_DESCRIPTOR_SIZE 0x24 #define MSG_HEADER_SIZE (MSG_DESCRIPTOR_SIZE + 4) #define MSG_TYPE_MASK 0x00000003 /* mask for following types */ #define MSG_TYPE_NOTIFY 0 /* embedded -> driver (only notification, do not get_msg() !) */ #define MSG_TYPE_COMMAND 1 /* driver <-> embedded (a command has no answer) */ #define MSG_TYPE_REQUEST 2 /* driver -> embedded (request will get an answer back) */ #define MSG_TYPE_ANSWER 3 /* embedded -> driver */ #define MSG_CANCEL_NOTIFY_MASK 0x80000000 /* this bit is set for a notification that has been canceled */ static int retrieve_msg_frame(struct mixart_mgr *mgr, u32 *msg_frame) { /* read the message frame fifo */ u32 headptr, tailptr; tailptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_POST_TAIL)); headptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_POST_HEAD)); if (tailptr == headptr) return 0; /* no message posted */ if (tailptr < MSG_OUTBOUND_POST_STACK) return 0; /* error */ if (tailptr >= MSG_OUTBOUND_POST_STACK + MSG_BOUND_STACK_SIZE) return 0; /* error */ *msg_frame = readl_be(MIXART_MEM(mgr, tailptr)); /* increment the tail index */ tailptr += 4; if( tailptr >= (MSG_OUTBOUND_POST_STACK+MSG_BOUND_STACK_SIZE) ) tailptr = MSG_OUTBOUND_POST_STACK; writel_be(tailptr, MIXART_MEM(mgr, MSG_OUTBOUND_POST_TAIL)); return 1; } static int get_msg(struct mixart_mgr *mgr, struct mixart_msg *resp, u32 msg_frame_address ) { u32 headptr; u32 size; int err; #ifndef __BIG_ENDIAN unsigned int i; #endif err = 0; /* copy message descriptor from miXart to driver */ size = readl_be(MIXART_MEM(mgr, msg_frame_address)); /* size of descriptor + response */ resp->message_id = readl_be(MIXART_MEM(mgr, msg_frame_address + 4)); /* dwMessageID */ resp->uid.object_id = readl_be(MIXART_MEM(mgr, msg_frame_address + 8)); /* uidDest */ resp->uid.desc = readl_be(MIXART_MEM(mgr, msg_frame_address + 12)); /* */ if( (size < MSG_DESCRIPTOR_SIZE) || (resp->size < (size - MSG_DESCRIPTOR_SIZE))) { err = -EINVAL; dev_err(&mgr->pci->dev, "problem with response size = %d\n", size); goto _clean_exit; } size -= MSG_DESCRIPTOR_SIZE; memcpy_fromio(resp->data, MIXART_MEM(mgr, msg_frame_address + MSG_HEADER_SIZE ), size); resp->size = size; /* swap if necessary */ #ifndef __BIG_ENDIAN size /= 4; /* u32 size */ for(i=0; i < size; i++) { ((u32*)resp->data)[i] = be32_to_cpu(((__be32*)resp->data)[i]); } #endif /* * free message frame address */ headptr = readl_be(MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD)); if( (headptr < MSG_OUTBOUND_FREE_STACK) || ( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE))) { err = -EINVAL; goto _clean_exit; } /* give address back to outbound fifo */ writel_be(msg_frame_address, MIXART_MEM(mgr, headptr)); /* increment the outbound free head */ headptr += 4; if( headptr >= (MSG_OUTBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE) ) headptr = MSG_OUTBOUND_FREE_STACK; writel_be(headptr, MIXART_MEM(mgr, MSG_OUTBOUND_FREE_HEAD)); _clean_exit: return err; } /* * send a message to miXart. return: the msg_frame used for this message */ /* call with mgr->msg_lock held! */ static int send_msg( struct mixart_mgr *mgr, struct mixart_msg *msg, int max_answersize, int mark_pending, u32 *msg_event) { u32 headptr, tailptr; u32 msg_frame_address; int i; if (snd_BUG_ON(msg->size % 4)) return -EINVAL; /* get message frame address */ tailptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_TAIL)); headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_FREE_HEAD)); if (tailptr == headptr) { dev_err(&mgr->pci->dev, "error: no message frame available\n"); return -EBUSY; } if( (tailptr < MSG_INBOUND_FREE_STACK) || (tailptr >= (MSG_INBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE))) { return -EINVAL; } msg_frame_address = readl_be(MIXART_MEM(mgr, tailptr)); writel(0, MIXART_MEM(mgr, tailptr)); /* set address to zero on this fifo position */ /* increment the inbound free tail */ tailptr += 4; if( tailptr >= (MSG_INBOUND_FREE_STACK+MSG_BOUND_STACK_SIZE) ) tailptr = MSG_INBOUND_FREE_STACK; writel_be(tailptr, MIXART_MEM(mgr, MSG_INBOUND_FREE_TAIL)); /* TODO : use memcpy_toio() with intermediate buffer to copy the message */ /* copy message descriptor to card memory */ writel_be( msg->size + MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address) ); /* size of descriptor + request */ writel_be( msg->message_id , MIXART_MEM(mgr, msg_frame_address + 4) ); /* dwMessageID */ writel_be( msg->uid.object_id, MIXART_MEM(mgr, msg_frame_address + 8) ); /* uidDest */ writel_be( msg->uid.desc, MIXART_MEM(mgr, msg_frame_address + 12) ); /* */ writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 16) ); /* SizeHeader */ writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 20) ); /* OffsetDLL_T16 */ writel_be( msg->size, MIXART_MEM(mgr, msg_frame_address + 24) ); /* SizeDLL_T16 */ writel_be( MSG_DESCRIPTOR_SIZE, MIXART_MEM(mgr, msg_frame_address + 28) ); /* OffsetDLL_DRV */ writel_be( 0, MIXART_MEM(mgr, msg_frame_address + 32) ); /* SizeDLL_DRV */ writel_be( MSG_DESCRIPTOR_SIZE + max_answersize, MIXART_MEM(mgr, msg_frame_address + 36) ); /* dwExpectedAnswerSize */ /* copy message data to card memory */ for( i=0; i < msg->size; i+=4 ) { writel_be( *(u32*)(msg->data + i), MIXART_MEM(mgr, MSG_HEADER_SIZE + msg_frame_address + i) ); } if( mark_pending ) { if( *msg_event ) { /* the pending event is the notification we wait for ! */ mgr->pending_event = *msg_event; } else { /* the pending event is the answer we wait for (same address than the request)! */ mgr->pending_event = msg_frame_address; /* copy address back to caller */ *msg_event = msg_frame_address; } } /* mark the frame as a request (will have an answer) */ msg_frame_address |= MSG_TYPE_REQUEST; /* post the frame */ headptr = readl_be(MIXART_MEM(mgr, MSG_INBOUND_POST_HEAD)); if( (headptr < MSG_INBOUND_POST_STACK) || (headptr >= (MSG_INBOUND_POST_STACK+MSG_BOUND_STACK_SIZE))) { return -EINVAL; } writel_be(msg_frame_address, MIXART_MEM(mgr, headptr)); /* increment the inbound post head */ headptr += 4; if( headptr >= (MSG_INBOUND_POST_STACK+MSG_BOUND_STACK_SIZE) ) headptr = MSG_INBOUND_POST_STACK; writel_be(headptr, MIXART_MEM(mgr, MSG_INBOUND_POST_HEAD)); return 0; } int snd_mixart_send_msg(struct mixart_mgr *mgr, struct mixart_msg *request, int max_resp_size, void *resp_data) { struct mixart_msg resp; u32 msg_frame = 0; /* set to 0, so it's no notification to wait for, but the answer */ int err; wait_queue_entry_t wait; long timeout; init_waitqueue_entry(&wait, current); mutex_lock(&mgr->msg_lock); /* send the message */ err = send_msg(mgr, request, max_resp_size, 1, &msg_frame); /* send and mark the answer pending */ if (err) { mutex_unlock(&mgr->msg_lock); return err; } set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&mgr->msg_sleep, &wait); mutex_unlock(&mgr->msg_lock); timeout = schedule_timeout(MSG_TIMEOUT_JIFFIES); remove_wait_queue(&mgr->msg_sleep, &wait); if (! timeout) { /* error - no ack */ dev_err(&mgr->pci->dev, "error: no response on msg %x\n", msg_frame); return -EIO; } /* retrieve the answer into the same struct mixart_msg */ resp.message_id = 0; resp.uid = (struct mixart_uid){0,0}; resp.data = resp_data; resp.size = max_resp_size; mutex_lock(&mgr->msg_lock); err = get_msg(mgr, &resp, msg_frame); mutex_unlock(&mgr->msg_lock); if( request->message_id != resp.message_id ) dev_err(&mgr->pci->dev, "RESPONSE ERROR!\n"); return err; } int snd_mixart_send_msg_wait_notif(struct mixart_mgr *mgr, struct mixart_msg *request, u32 notif_event) { int err; wait_queue_entry_t wait; long timeout; if (snd_BUG_ON(!notif_event)) return -EINVAL; if (snd_BUG_ON((notif_event & MSG_TYPE_MASK) != MSG_TYPE_NOTIFY)) return -EINVAL; if (snd_BUG_ON(notif_event & MSG_CANCEL_NOTIFY_MASK)) return -EINVAL; init_waitqueue_entry(&wait, current); mutex_lock(&mgr->msg_lock); /* send the message */ err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 1, &notif_event); /* send and mark the notification event pending */ if(err) { mutex_unlock(&mgr->msg_lock); return err; } set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&mgr->msg_sleep, &wait); mutex_unlock(&mgr->msg_lock); timeout = schedule_timeout(MSG_TIMEOUT_JIFFIES); remove_wait_queue(&mgr->msg_sleep, &wait); if (! timeout) { /* error - no ack */ dev_err(&mgr->pci->dev, "error: notification %x not received\n", notif_event); return -EIO; } return 0; } int snd_mixart_send_msg_nonblock(struct mixart_mgr *mgr, struct mixart_msg *request) { u32 message_frame; int err; /* just send the message (do not mark it as a pending one) */ mutex_lock(&mgr->msg_lock); err = send_msg(mgr, request, MSG_DEFAULT_SIZE, 0, &message_frame); mutex_unlock(&mgr->msg_lock); /* the answer will be handled by snd_struct mixart_msgasklet() */ atomic_inc(&mgr->msg_processed); return err; } /* common buffer of interrupt to send/receive messages */ static u32 mixart_msg_data[MSG_DEFAULT_SIZE / 4]; static void snd_mixart_process_msg(struct mixart_mgr *mgr) { struct mixart_msg resp; u32 msg, addr, type; int err; while (mgr->msg_fifo_readptr != mgr->msg_fifo_writeptr) { msg = mgr->msg_fifo[mgr->msg_fifo_readptr]; mgr->msg_fifo_readptr++; mgr->msg_fifo_readptr %= MSG_FIFO_SIZE; /* process the message ... */ addr = msg & ~MSG_TYPE_MASK; type = msg & MSG_TYPE_MASK; switch (type) { case MSG_TYPE_ANSWER: /* answer to a message on that we did not wait for (send_msg_nonblock) */ resp.message_id = 0; resp.data = mixart_msg_data; resp.size = sizeof(mixart_msg_data); err = get_msg(mgr, &resp, addr); if( err < 0 ) { dev_err(&mgr->pci->dev, "error(%d) reading mf %x\n", err, msg); break; } switch(resp.message_id) { case MSG_STREAM_START_INPUT_STAGE_PACKET: case MSG_STREAM_START_OUTPUT_STAGE_PACKET: case MSG_STREAM_STOP_INPUT_STAGE_PACKET: case MSG_STREAM_STOP_OUTPUT_STAGE_PACKET: if(mixart_msg_data[0]) dev_err(&mgr->pci->dev, "error MSG_STREAM_ST***_***PUT_STAGE_PACKET status=%x\n", mixart_msg_data[0]); break; default: dev_dbg(&mgr->pci->dev, "received mf(%x) : msg_id(%x) uid(%x, %x) size(%zd)\n", msg, resp.message_id, resp.uid.object_id, resp.uid.desc, resp.size); break; } break; case MSG_TYPE_NOTIFY: /* msg contains no address ! do not get_msg() ! */ case MSG_TYPE_COMMAND: /* get_msg() necessary */ default: dev_err(&mgr->pci->dev, "doesn't know what to do with message %x\n", msg); } /* switch type */ /* decrement counter */ atomic_dec(&mgr->msg_processed); } /* while there is a msg in fifo */ } irqreturn_t snd_mixart_interrupt(int irq, void *dev_id) { struct mixart_mgr *mgr = dev_id; u32 it_reg; it_reg = readl_le(MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET)); if( !(it_reg & MIXART_OIDI) ) { /* this device did not cause the interrupt */ return IRQ_NONE; } /* mask all interrupts */ writel_le(MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG(mgr, MIXART_PCI_OMIMR_OFFSET)); /* outdoorbell register clear */ it_reg = readl(MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET)); writel(it_reg, MIXART_REG(mgr, MIXART_PCI_ODBR_OFFSET)); /* clear interrupt */ writel_le( MIXART_OIDI, MIXART_REG(mgr, MIXART_PCI_OMISR_OFFSET) ); return IRQ_WAKE_THREAD; } irqreturn_t snd_mixart_threaded_irq(int irq, void *dev_id) { struct mixart_mgr *mgr = dev_id; int err; struct mixart_msg resp; u32 msg; mutex_lock(&mgr->lock); /* process interrupt */ while (retrieve_msg_frame(mgr, &msg)) { switch (msg & MSG_TYPE_MASK) { case MSG_TYPE_COMMAND: resp.message_id = 0; resp.data = mixart_msg_data; resp.size = sizeof(mixart_msg_data); err = get_msg(mgr, &resp, msg & ~MSG_TYPE_MASK); if( err < 0 ) { dev_err(&mgr->pci->dev, "interrupt: error(%d) reading mf %x\n", err, msg); break; } if(resp.message_id == MSG_SERVICES_TIMER_NOTIFY) { int i; struct mixart_timer_notify *notify; notify = (struct mixart_timer_notify *)mixart_msg_data; BUILD_BUG_ON(sizeof(notify) > sizeof(mixart_msg_data)); if (snd_BUG_ON(notify->stream_count > ARRAY_SIZE(notify->streams))) break; for(i=0; i<notify->stream_count; i++) { u32 buffer_id = notify->streams[i].buffer_id; unsigned int chip_number = (buffer_id & MIXART_NOTIFY_CARD_MASK) >> MIXART_NOTIFY_CARD_OFFSET; /* card0 to 3 */ unsigned int pcm_number = (buffer_id & MIXART_NOTIFY_PCM_MASK ) >> MIXART_NOTIFY_PCM_OFFSET; /* pcm0 to 3 */ unsigned int sub_number = buffer_id & MIXART_NOTIFY_SUBS_MASK; /* 0 to MIXART_PLAYBACK_STREAMS */ unsigned int is_capture = ((buffer_id & MIXART_NOTIFY_CAPT_MASK) != 0); /* playback == 0 / capture == 1 */ struct snd_mixart *chip = mgr->chip[chip_number]; struct mixart_stream *stream; if ((chip_number >= mgr->num_cards) || (pcm_number >= MIXART_PCM_TOTAL) || (sub_number >= MIXART_PLAYBACK_STREAMS)) { dev_err(&mgr->pci->dev, "error MSG_SERVICES_TIMER_NOTIFY buffer_id (%x) pos(%d)\n", buffer_id, notify->streams[i].sample_pos_low_part); break; } if (is_capture) stream = &chip->capture_stream[pcm_number]; else stream = &chip->playback_stream[pcm_number][sub_number]; if (stream->substream && (stream->status == MIXART_STREAM_STATUS_RUNNING)) { struct snd_pcm_runtime *runtime = stream->substream->runtime; int elapsed = 0; u64 sample_count = ((u64)notify->streams[i].sample_pos_high_part) << 32; sample_count |= notify->streams[i].sample_pos_low_part; while (1) { u64 new_elapse_pos = stream->abs_period_elapsed + runtime->period_size; if (new_elapse_pos > sample_count) { break; /* while */ } else { elapsed = 1; stream->buf_periods++; if (stream->buf_periods >= runtime->periods) stream->buf_periods = 0; stream->abs_period_elapsed = new_elapse_pos; } } stream->buf_period_frag = (u32)( sample_count - stream->abs_period_elapsed ); if(elapsed) { mutex_unlock(&mgr->lock); snd_pcm_period_elapsed(stream->substream); mutex_lock(&mgr->lock); } } } break; } if(resp.message_id == MSG_SERVICES_REPORT_TRACES) { if(resp.size > 1) { #ifndef __BIG_ENDIAN /* Traces are text: the swapped msg_data has to be swapped back ! */ int i; for(i=0; i<(resp.size/4); i++) { ((__be32*)mixart_msg_data)[i] = cpu_to_be32((mixart_msg_data)[i]); } #endif ((char*)mixart_msg_data)[resp.size - 1] = 0; dev_dbg(&mgr->pci->dev, "MIXART TRACE : %s\n", (char *)mixart_msg_data); } break; } dev_dbg(&mgr->pci->dev, "command %x not handled\n", resp.message_id); break; case MSG_TYPE_NOTIFY: if(msg & MSG_CANCEL_NOTIFY_MASK) { msg &= ~MSG_CANCEL_NOTIFY_MASK; dev_err(&mgr->pci->dev, "canceled notification %x !\n", msg); } fallthrough; case MSG_TYPE_ANSWER: /* answer or notification to a message we are waiting for*/ mutex_lock(&mgr->msg_lock); if( (msg & ~MSG_TYPE_MASK) == mgr->pending_event ) { wake_up(&mgr->msg_sleep); mgr->pending_event = 0; } /* answer to a message we did't want to wait for */ else { mgr->msg_fifo[mgr->msg_fifo_writeptr] = msg; mgr->msg_fifo_writeptr++; mgr->msg_fifo_writeptr %= MSG_FIFO_SIZE; snd_mixart_process_msg(mgr); } mutex_unlock(&mgr->msg_lock); break; case MSG_TYPE_REQUEST: default: dev_dbg(&mgr->pci->dev, "interrupt received request %x\n", msg); /* TODO : are there things to do here ? */ break; } /* switch on msg type */ } /* while there are msgs */ /* allow interrupt again */ writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET)); mutex_unlock(&mgr->lock); return IRQ_HANDLED; } void snd_mixart_init_mailbox(struct mixart_mgr *mgr) { writel( 0, MIXART_MEM( mgr, MSG_HOST_RSC_PROTECTION ) ); writel( 0, MIXART_MEM( mgr, MSG_AGENT_RSC_PROTECTION ) ); /* allow outbound messagebox to generate interrupts */ if(mgr->irq >= 0) { writel_le( MIXART_ALLOW_OUTBOUND_DOORBELL, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET)); } return; } void snd_mixart_exit_mailbox(struct mixart_mgr *mgr) { /* no more interrupts on outbound messagebox */ writel_le( MIXART_HOST_ALL_INTERRUPT_MASKED, MIXART_REG( mgr, MIXART_PCI_OMIMR_OFFSET)); return; } void snd_mixart_reset_board(struct mixart_mgr *mgr) { /* reset miXart */ writel_be( 1, MIXART_REG(mgr, MIXART_BA1_BRUTAL_RESET_OFFSET) ); return; }
linux-master
sound/pci/mixart/mixart_core.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram miXart soundcards * * main file with alsa callbacks * * Copyright (c) 2003 by Digigram <[email protected]> */ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/pci.h> #include <linux/dma-mapping.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/slab.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/info.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include "mixart.h" #include "mixart_hwdep.h" #include "mixart_core.h" #include "mixart_mixer.h" #define CARD_NAME "miXart" MODULE_AUTHOR("Digigram <[email protected]>"); MODULE_DESCRIPTION("Digigram " CARD_NAME); MODULE_LICENSE("GPL"); static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard."); /* */ static const struct pci_device_id snd_mixart_ids[] = { { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */ { 0, } }; MODULE_DEVICE_TABLE(pci, snd_mixart_ids); static int mixart_set_pipe_state(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int start) { struct mixart_group_state_req group_state; struct mixart_group_state_resp group_state_resp; struct mixart_msg request; int err; u32 system_msg_uid; switch(pipe->status) { case PIPE_RUNNING: case PIPE_CLOCK_SET: if(start) return 0; /* already started */ break; case PIPE_STOPPED: if(!start) return 0; /* already stopped */ break; default: dev_err(&mgr->pci->dev, "error mixart_set_pipe_state called with wrong pipe->status!\n"); return -EINVAL; /* function called with wrong pipe status */ } system_msg_uid = 0x12345678; /* the event ! (take care: the MSB and two LSB's have to be 0) */ /* wait on the last MSG_SYSTEM_SEND_SYNCHRO_CMD command to be really finished */ request.message_id = MSG_SYSTEM_WAIT_SYNCHRO_CMD; request.uid = (struct mixart_uid){0,0}; request.data = &system_msg_uid; request.size = sizeof(system_msg_uid); err = snd_mixart_send_msg_wait_notif(mgr, &request, system_msg_uid); if(err) { dev_err(&mgr->pci->dev, "error : MSG_SYSTEM_WAIT_SYNCHRO_CMD was not notified !\n"); return err; } /* start or stop the pipe (1 pipe) */ memset(&group_state, 0, sizeof(group_state)); group_state.pipe_count = 1; group_state.pipe_uid = pipe->group_uid; if(start) request.message_id = MSG_STREAM_START_STREAM_GRP_PACKET; else request.message_id = MSG_STREAM_STOP_STREAM_GRP_PACKET; request.uid = pipe->group_uid; /*(struct mixart_uid){0,0};*/ request.data = &group_state; request.size = sizeof(group_state); err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp); if (err < 0 || group_state_resp.txx_status != 0) { dev_err(&mgr->pci->dev, "error MSG_STREAM_ST***_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status); return -EINVAL; } if(start) { u32 stat = 0; group_state.pipe_count = 0; /* in case of start same command once again with pipe_count=0 */ err = snd_mixart_send_msg(mgr, &request, sizeof(group_state_resp), &group_state_resp); if (err < 0 || group_state_resp.txx_status != 0) { dev_err(&mgr->pci->dev, "error MSG_STREAM_START_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status); return -EINVAL; } /* in case of start send a synchro top */ request.message_id = MSG_SYSTEM_SEND_SYNCHRO_CMD; request.uid = (struct mixart_uid){0,0}; request.data = NULL; request.size = 0; err = snd_mixart_send_msg(mgr, &request, sizeof(stat), &stat); if (err < 0 || stat != 0) { dev_err(&mgr->pci->dev, "error MSG_SYSTEM_SEND_SYNCHRO_CMD err=%x stat=%x !\n", err, stat); return -EINVAL; } pipe->status = PIPE_RUNNING; } else /* !start */ pipe->status = PIPE_STOPPED; return 0; } static int mixart_set_clock(struct mixart_mgr *mgr, struct mixart_pipe *pipe, unsigned int rate) { struct mixart_msg request; struct mixart_clock_properties clock_properties; struct mixart_clock_properties_resp clock_prop_resp; int err; switch(pipe->status) { case PIPE_CLOCK_SET: break; case PIPE_RUNNING: if(rate != 0) break; fallthrough; default: if(rate == 0) return 0; /* nothing to do */ else { dev_err(&mgr->pci->dev, "error mixart_set_clock(%d) called with wrong pipe->status !\n", rate); return -EINVAL; } } memset(&clock_properties, 0, sizeof(clock_properties)); clock_properties.clock_generic_type = (rate != 0) ? CGT_INTERNAL_CLOCK : CGT_NO_CLOCK; clock_properties.clock_mode = CM_STANDALONE; clock_properties.frequency = rate; clock_properties.nb_callers = 1; /* only one entry in uid_caller ! */ clock_properties.uid_caller = pipe->group_uid; dev_dbg(&mgr->pci->dev, "mixart_set_clock to %d kHz\n", rate); request.message_id = MSG_CLOCK_SET_PROPERTIES; request.uid = mgr->uid_console_manager; request.data = &clock_properties; request.size = sizeof(clock_properties); err = snd_mixart_send_msg(mgr, &request, sizeof(clock_prop_resp), &clock_prop_resp); if (err < 0 || clock_prop_resp.status != 0 || clock_prop_resp.clock_mode != CM_STANDALONE) { dev_err(&mgr->pci->dev, "error MSG_CLOCK_SET_PROPERTIES err=%x stat=%x mod=%x !\n", err, clock_prop_resp.status, clock_prop_resp.clock_mode); return -EINVAL; } if(rate) pipe->status = PIPE_CLOCK_SET; else pipe->status = PIPE_RUNNING; return 0; } /* * Allocate or reference output pipe for analog IOs (pcmp0/1) */ struct mixart_pipe * snd_mixart_add_ref_pipe(struct snd_mixart *chip, int pcm_number, int capture, int monitoring) { int stream_count; struct mixart_pipe *pipe; struct mixart_msg request; if(capture) { if (pcm_number == MIXART_PCM_ANALOG) { pipe = &(chip->pipe_in_ana); /* analog inputs */ } else { pipe = &(chip->pipe_in_dig); /* digital inputs */ } request.message_id = MSG_STREAM_ADD_OUTPUT_GROUP; stream_count = MIXART_CAPTURE_STREAMS; } else { if (pcm_number == MIXART_PCM_ANALOG) { pipe = &(chip->pipe_out_ana); /* analog outputs */ } else { pipe = &(chip->pipe_out_dig); /* digital outputs */ } request.message_id = MSG_STREAM_ADD_INPUT_GROUP; stream_count = MIXART_PLAYBACK_STREAMS; } /* a new stream is opened and there are already all streams in use */ if( (monitoring == 0) && (pipe->references >= stream_count) ) { return NULL; } /* pipe is not yet defined */ if( pipe->status == PIPE_UNDEFINED ) { int err, i; struct { struct mixart_streaming_group_req sgroup_req; struct mixart_streaming_group sgroup_resp; } *buf; dev_dbg(chip->card->dev, "add_ref_pipe audio chip(%d) pcm(%d)\n", chip->chip_idx, pcm_number); buf = kmalloc(sizeof(*buf), GFP_KERNEL); if (!buf) return NULL; request.uid = (struct mixart_uid){0,0}; /* should be StreamManagerUID, but zero is OK if there is only one ! */ request.data = &buf->sgroup_req; request.size = sizeof(buf->sgroup_req); memset(&buf->sgroup_req, 0, sizeof(buf->sgroup_req)); buf->sgroup_req.stream_count = stream_count; buf->sgroup_req.channel_count = 2; buf->sgroup_req.latency = 256; buf->sgroup_req.connector = pipe->uid_left_connector; /* the left connector */ for (i=0; i<stream_count; i++) { int j; struct mixart_flowinfo *flowinfo; struct mixart_bufferinfo *bufferinfo; /* we don't yet know the format, so config 16 bit pcm audio for instance */ buf->sgroup_req.stream_info[i].size_max_byte_frame = 1024; buf->sgroup_req.stream_info[i].size_max_sample_frame = 256; buf->sgroup_req.stream_info[i].nb_bytes_max_per_sample = MIXART_FLOAT_P__4_0_TO_HEX; /* is 4.0f */ /* find the right bufferinfo_array */ j = (chip->chip_idx * MIXART_MAX_STREAM_PER_CARD) + (pcm_number * (MIXART_PLAYBACK_STREAMS + MIXART_CAPTURE_STREAMS)) + i; if(capture) j += MIXART_PLAYBACK_STREAMS; /* in the array capture is behind playback */ buf->sgroup_req.flow_entry[i] = j; flowinfo = (struct mixart_flowinfo *)chip->mgr->flowinfo.area; flowinfo[j].bufferinfo_array_phy_address = (u32)chip->mgr->bufferinfo.addr + (j * sizeof(struct mixart_bufferinfo)); flowinfo[j].bufferinfo_count = 1; /* 1 will set the miXart to ring-buffer mode ! */ bufferinfo = (struct mixart_bufferinfo *)chip->mgr->bufferinfo.area; bufferinfo[j].buffer_address = 0; /* buffer is not yet allocated */ bufferinfo[j].available_length = 0; /* buffer is not yet allocated */ /* construct the identifier of the stream buffer received in the interrupts ! */ bufferinfo[j].buffer_id = (chip->chip_idx << MIXART_NOTIFY_CARD_OFFSET) + (pcm_number << MIXART_NOTIFY_PCM_OFFSET ) + i; if(capture) { bufferinfo[j].buffer_id |= MIXART_NOTIFY_CAPT_MASK; } } err = snd_mixart_send_msg(chip->mgr, &request, sizeof(buf->sgroup_resp), &buf->sgroup_resp); if((err < 0) || (buf->sgroup_resp.status != 0)) { dev_err(chip->card->dev, "error MSG_STREAM_ADD_**PUT_GROUP err=%x stat=%x !\n", err, buf->sgroup_resp.status); kfree(buf); return NULL; } pipe->group_uid = buf->sgroup_resp.group; /* id of the pipe, as returned by embedded */ pipe->stream_count = buf->sgroup_resp.stream_count; /* pipe->stream_uid[i] = buf->sgroup_resp.stream[i].stream_uid; */ pipe->status = PIPE_STOPPED; kfree(buf); } if(monitoring) pipe->monitoring = 1; else pipe->references++; return pipe; } int snd_mixart_kill_ref_pipe(struct mixart_mgr *mgr, struct mixart_pipe *pipe, int monitoring) { int err = 0; if(pipe->status == PIPE_UNDEFINED) return 0; if(monitoring) pipe->monitoring = 0; else pipe->references--; if((pipe->references <= 0) && (pipe->monitoring == 0)) { struct mixart_msg request; struct mixart_delete_group_resp delete_resp; /* release the clock */ err = mixart_set_clock( mgr, pipe, 0); if( err < 0 ) { dev_err(&mgr->pci->dev, "mixart_set_clock(0) return error!\n"); } /* stop the pipe */ err = mixart_set_pipe_state(mgr, pipe, 0); if( err < 0 ) { dev_err(&mgr->pci->dev, "error stopping pipe!\n"); } request.message_id = MSG_STREAM_DELETE_GROUP; request.uid = (struct mixart_uid){0,0}; request.data = &pipe->group_uid; /* the streaming group ! */ request.size = sizeof(pipe->group_uid); /* delete the pipe */ err = snd_mixart_send_msg(mgr, &request, sizeof(delete_resp), &delete_resp); if ((err < 0) || (delete_resp.status != 0)) { dev_err(&mgr->pci->dev, "error MSG_STREAM_DELETE_GROUP err(%x), status(%x)\n", err, delete_resp.status); } pipe->group_uid = (struct mixart_uid){0,0}; pipe->stream_count = 0; pipe->status = PIPE_UNDEFINED; } return err; } static int mixart_set_stream_state(struct mixart_stream *stream, int start) { struct snd_mixart *chip; struct mixart_stream_state_req stream_state_req; struct mixart_msg request; if(!stream->substream) return -EINVAL; memset(&stream_state_req, 0, sizeof(stream_state_req)); stream_state_req.stream_count = 1; stream_state_req.stream_info.stream_desc.uid_pipe = stream->pipe->group_uid; stream_state_req.stream_info.stream_desc.stream_idx = stream->substream->number; if (stream->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) request.message_id = start ? MSG_STREAM_START_INPUT_STAGE_PACKET : MSG_STREAM_STOP_INPUT_STAGE_PACKET; else request.message_id = start ? MSG_STREAM_START_OUTPUT_STAGE_PACKET : MSG_STREAM_STOP_OUTPUT_STAGE_PACKET; request.uid = (struct mixart_uid){0,0}; request.data = &stream_state_req; request.size = sizeof(stream_state_req); stream->abs_period_elapsed = 0; /* reset stream pos */ stream->buf_periods = 0; stream->buf_period_frag = 0; chip = snd_pcm_substream_chip(stream->substream); return snd_mixart_send_msg_nonblock(chip->mgr, &request); } /* * Trigger callback */ static int snd_mixart_trigger(struct snd_pcm_substream *subs, int cmd) { struct mixart_stream *stream = subs->runtime->private_data; switch (cmd) { case SNDRV_PCM_TRIGGER_START: dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_START\n"); /* START_STREAM */ if( mixart_set_stream_state(stream, 1) ) return -EINVAL; stream->status = MIXART_STREAM_STATUS_RUNNING; break; case SNDRV_PCM_TRIGGER_STOP: /* STOP_STREAM */ if( mixart_set_stream_state(stream, 0) ) return -EINVAL; stream->status = MIXART_STREAM_STATUS_OPEN; dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_TRIGGER_STOP\n"); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* TODO */ stream->status = MIXART_STREAM_STATUS_PAUSE; dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_PUSH\n"); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* TODO */ stream->status = MIXART_STREAM_STATUS_RUNNING; dev_dbg(subs->pcm->card->dev, "SNDRV_PCM_PAUSE_RELEASE\n"); break; default: return -EINVAL; } return 0; } static int mixart_sync_nonblock_events(struct mixart_mgr *mgr) { unsigned long timeout = jiffies + HZ; while (atomic_read(&mgr->msg_processed) > 0) { if (time_after(jiffies, timeout)) { dev_err(&mgr->pci->dev, "mixart: cannot process nonblock events!\n"); return -EBUSY; } schedule_timeout_uninterruptible(1); } return 0; } /* * prepare callback for all pcms */ static int snd_mixart_prepare(struct snd_pcm_substream *subs) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); struct mixart_stream *stream = subs->runtime->private_data; /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */ dev_dbg(chip->card->dev, "snd_mixart_prepare\n"); mixart_sync_nonblock_events(chip->mgr); /* only the first stream can choose the sample rate */ /* the further opened streams will be limited to its frequency (see open) */ if(chip->mgr->ref_count_rate == 1) chip->mgr->sample_rate = subs->runtime->rate; /* set the clock only once (first stream) on the same pipe */ if(stream->pipe->references == 1) { if( mixart_set_clock(chip->mgr, stream->pipe, subs->runtime->rate) ) return -EINVAL; } return 0; } static int mixart_set_format(struct mixart_stream *stream, snd_pcm_format_t format) { int err; struct snd_mixart *chip; struct mixart_msg request; struct mixart_stream_param_desc stream_param; struct mixart_return_uid resp; chip = snd_pcm_substream_chip(stream->substream); memset(&stream_param, 0, sizeof(stream_param)); stream_param.coding_type = CT_LINEAR; stream_param.number_of_channel = stream->channels; stream_param.sampling_freq = chip->mgr->sample_rate; if(stream_param.sampling_freq == 0) stream_param.sampling_freq = 44100; /* if frequency not yet defined, use some default */ switch(format){ case SNDRV_PCM_FORMAT_U8: stream_param.sample_type = ST_INTEGER_8; stream_param.sample_size = 8; break; case SNDRV_PCM_FORMAT_S16_LE: stream_param.sample_type = ST_INTEGER_16LE; stream_param.sample_size = 16; break; case SNDRV_PCM_FORMAT_S16_BE: stream_param.sample_type = ST_INTEGER_16BE; stream_param.sample_size = 16; break; case SNDRV_PCM_FORMAT_S24_3LE: stream_param.sample_type = ST_INTEGER_24LE; stream_param.sample_size = 24; break; case SNDRV_PCM_FORMAT_S24_3BE: stream_param.sample_type = ST_INTEGER_24BE; stream_param.sample_size = 24; break; case SNDRV_PCM_FORMAT_FLOAT_LE: stream_param.sample_type = ST_FLOATING_POINT_32LE; stream_param.sample_size = 32; break; case SNDRV_PCM_FORMAT_FLOAT_BE: stream_param.sample_type = ST_FLOATING_POINT_32BE; stream_param.sample_size = 32; break; default: dev_err(chip->card->dev, "error mixart_set_format() : unknown format\n"); return -EINVAL; } dev_dbg(chip->card->dev, "set SNDRV_PCM_FORMAT sample_type(%d) sample_size(%d) freq(%d) channels(%d)\n", stream_param.sample_type, stream_param.sample_size, stream_param.sampling_freq, stream->channels); /* TODO: what else to configure ? */ /* stream_param.samples_per_frame = 2; */ /* stream_param.bytes_per_frame = 4; */ /* stream_param.bytes_per_sample = 2; */ stream_param.pipe_count = 1; /* set to 1 */ stream_param.stream_count = 1; /* set to 1 */ stream_param.stream_desc.uid_pipe = stream->pipe->group_uid; stream_param.stream_desc.stream_idx = stream->substream->number; request.message_id = MSG_STREAM_SET_INPUT_STAGE_PARAM; request.uid = (struct mixart_uid){0,0}; request.data = &stream_param; request.size = sizeof(stream_param); err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); if((err < 0) || resp.error_code) { dev_err(chip->card->dev, "MSG_STREAM_SET_INPUT_STAGE_PARAM err=%x; resp=%x\n", err, resp.error_code); return -EINVAL; } return 0; } /* * HW_PARAMS callback for all pcms */ static int snd_mixart_hw_params(struct snd_pcm_substream *subs, struct snd_pcm_hw_params *hw) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); struct mixart_mgr *mgr = chip->mgr; struct mixart_stream *stream = subs->runtime->private_data; snd_pcm_format_t format; int err; int channels; /* set up channels */ channels = params_channels(hw); /* set up format for the stream */ format = params_format(hw); mutex_lock(&mgr->setup_mutex); /* update the stream levels */ if( stream->pcm_number <= MIXART_PCM_DIGITAL ) { int is_aes = stream->pcm_number > MIXART_PCM_ANALOG; if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) mixart_update_playback_stream_level(chip, is_aes, subs->number); else mixart_update_capture_stream_level( chip, is_aes); } stream->channels = channels; /* set the format to the board */ err = mixart_set_format(stream, format); if(err < 0) { mutex_unlock(&mgr->setup_mutex); return err; } if (subs->runtime->buffer_changed) { struct mixart_bufferinfo *bufferinfo; int i = (chip->chip_idx * MIXART_MAX_STREAM_PER_CARD) + (stream->pcm_number * (MIXART_PLAYBACK_STREAMS+MIXART_CAPTURE_STREAMS)) + subs->number; if( subs->stream == SNDRV_PCM_STREAM_CAPTURE ) { i += MIXART_PLAYBACK_STREAMS; /* in array capture is behind playback */ } bufferinfo = (struct mixart_bufferinfo *)chip->mgr->bufferinfo.area; bufferinfo[i].buffer_address = subs->runtime->dma_addr; bufferinfo[i].available_length = subs->runtime->dma_bytes; /* bufferinfo[i].buffer_id is already defined */ dev_dbg(chip->card->dev, "snd_mixart_hw_params(pcm %d) : dma_addr(%x) dma_bytes(%x) subs-number(%d)\n", i, bufferinfo[i].buffer_address, bufferinfo[i].available_length, subs->number); } mutex_unlock(&mgr->setup_mutex); return 0; } static int snd_mixart_hw_free(struct snd_pcm_substream *subs) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); mixart_sync_nonblock_events(chip->mgr); return 0; } /* * TODO CONFIGURATION SPACE for all pcms, mono pcm must update channels_max */ static const struct snd_pcm_hardware snd_mixart_analog_caps = { .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), .formats = ( SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE ), .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 = (32*1024), .period_bytes_min = 256, /* 256 frames U8 mono*/ .period_bytes_max = (16*1024), .periods_min = 2, .periods_max = (32*1024/256), }; static const struct snd_pcm_hardware snd_mixart_digital_caps = { .info = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), .formats = ( SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE ), .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, .rate_min = 32000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (32*1024), .period_bytes_min = 256, /* 256 frames U8 mono*/ .period_bytes_max = (16*1024), .periods_min = 2, .periods_max = (32*1024/256), }; static int snd_mixart_playback_open(struct snd_pcm_substream *subs) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); struct mixart_mgr *mgr = chip->mgr; struct snd_pcm_runtime *runtime = subs->runtime; struct snd_pcm *pcm = subs->pcm; struct mixart_stream *stream; struct mixart_pipe *pipe; int err = 0; int pcm_number; mutex_lock(&mgr->setup_mutex); if ( pcm == chip->pcm ) { pcm_number = MIXART_PCM_ANALOG; runtime->hw = snd_mixart_analog_caps; } else { snd_BUG_ON(pcm != chip->pcm_dig); pcm_number = MIXART_PCM_DIGITAL; runtime->hw = snd_mixart_digital_caps; } dev_dbg(chip->card->dev, "snd_mixart_playback_open C%d/P%d/Sub%d\n", chip->chip_idx, pcm_number, subs->number); /* get stream info */ stream = &(chip->playback_stream[pcm_number][subs->number]); if (stream->status != MIXART_STREAM_STATUS_FREE){ /* streams in use */ dev_err(chip->card->dev, "snd_mixart_playback_open C%d/P%d/Sub%d in use\n", chip->chip_idx, pcm_number, subs->number); err = -EBUSY; goto _exit_open; } /* get pipe pointer (out pipe) */ pipe = snd_mixart_add_ref_pipe(chip, pcm_number, 0, 0); if (pipe == NULL) { err = -EINVAL; goto _exit_open; } /* start the pipe if necessary */ err = mixart_set_pipe_state(chip->mgr, pipe, 1); if( err < 0 ) { dev_err(chip->card->dev, "error starting pipe!\n"); snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0); err = -EINVAL; goto _exit_open; } stream->pipe = pipe; stream->pcm_number = pcm_number; stream->status = MIXART_STREAM_STATUS_OPEN; stream->substream = subs; stream->channels = 0; /* not configured yet */ runtime->private_data = stream; snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 64); /* if a sample rate is already used, another stream cannot change */ if(mgr->ref_count_rate++) { if(mgr->sample_rate) { runtime->hw.rate_min = runtime->hw.rate_max = mgr->sample_rate; } } _exit_open: mutex_unlock(&mgr->setup_mutex); return err; } static int snd_mixart_capture_open(struct snd_pcm_substream *subs) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); struct mixart_mgr *mgr = chip->mgr; struct snd_pcm_runtime *runtime = subs->runtime; struct snd_pcm *pcm = subs->pcm; struct mixart_stream *stream; struct mixart_pipe *pipe; int err = 0; int pcm_number; mutex_lock(&mgr->setup_mutex); if ( pcm == chip->pcm ) { pcm_number = MIXART_PCM_ANALOG; runtime->hw = snd_mixart_analog_caps; } else { snd_BUG_ON(pcm != chip->pcm_dig); pcm_number = MIXART_PCM_DIGITAL; runtime->hw = snd_mixart_digital_caps; } runtime->hw.channels_min = 2; /* for instance, no mono */ dev_dbg(chip->card->dev, "snd_mixart_capture_open C%d/P%d/Sub%d\n", chip->chip_idx, pcm_number, subs->number); /* get stream info */ stream = &(chip->capture_stream[pcm_number]); if (stream->status != MIXART_STREAM_STATUS_FREE){ /* streams in use */ dev_err(chip->card->dev, "snd_mixart_capture_open C%d/P%d/Sub%d in use\n", chip->chip_idx, pcm_number, subs->number); err = -EBUSY; goto _exit_open; } /* get pipe pointer (in pipe) */ pipe = snd_mixart_add_ref_pipe(chip, pcm_number, 1, 0); if (pipe == NULL) { err = -EINVAL; goto _exit_open; } /* start the pipe if necessary */ err = mixart_set_pipe_state(chip->mgr, pipe, 1); if( err < 0 ) { dev_err(chip->card->dev, "error starting pipe!\n"); snd_mixart_kill_ref_pipe(chip->mgr, pipe, 0); err = -EINVAL; goto _exit_open; } stream->pipe = pipe; stream->pcm_number = pcm_number; stream->status = MIXART_STREAM_STATUS_OPEN; stream->substream = subs; stream->channels = 0; /* not configured yet */ runtime->private_data = stream; snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 64); /* if a sample rate is already used, another stream cannot change */ if(mgr->ref_count_rate++) { if(mgr->sample_rate) { runtime->hw.rate_min = runtime->hw.rate_max = mgr->sample_rate; } } _exit_open: mutex_unlock(&mgr->setup_mutex); return err; } static int snd_mixart_close(struct snd_pcm_substream *subs) { struct snd_mixart *chip = snd_pcm_substream_chip(subs); struct mixart_mgr *mgr = chip->mgr; struct mixart_stream *stream = subs->runtime->private_data; mutex_lock(&mgr->setup_mutex); dev_dbg(chip->card->dev, "snd_mixart_close C%d/P%d/Sub%d\n", chip->chip_idx, stream->pcm_number, subs->number); /* sample rate released */ if(--mgr->ref_count_rate == 0) { mgr->sample_rate = 0; } /* delete pipe */ if (snd_mixart_kill_ref_pipe(mgr, stream->pipe, 0 ) < 0) { dev_err(chip->card->dev, "error snd_mixart_kill_ref_pipe C%dP%d\n", chip->chip_idx, stream->pcm_number); } stream->pipe = NULL; stream->status = MIXART_STREAM_STATUS_FREE; stream->substream = NULL; mutex_unlock(&mgr->setup_mutex); return 0; } static snd_pcm_uframes_t snd_mixart_stream_pointer(struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; struct mixart_stream *stream = runtime->private_data; return (snd_pcm_uframes_t)((stream->buf_periods * runtime->period_size) + stream->buf_period_frag); } static const struct snd_pcm_ops snd_mixart_playback_ops = { .open = snd_mixart_playback_open, .close = snd_mixart_close, .prepare = snd_mixart_prepare, .hw_params = snd_mixart_hw_params, .hw_free = snd_mixart_hw_free, .trigger = snd_mixart_trigger, .pointer = snd_mixart_stream_pointer, }; static const struct snd_pcm_ops snd_mixart_capture_ops = { .open = snd_mixart_capture_open, .close = snd_mixart_close, .prepare = snd_mixart_prepare, .hw_params = snd_mixart_hw_params, .hw_free = snd_mixart_hw_free, .trigger = snd_mixart_trigger, .pointer = snd_mixart_stream_pointer, }; static void preallocate_buffers(struct snd_mixart *chip, struct snd_pcm *pcm) { #if 0 struct snd_pcm_substream *subs; int stream; for (stream = 0; stream < 2; stream++) { int idx = 0; for (subs = pcm->streams[stream].substream; subs; subs = subs->next, idx++) /* set up the unique device id with the chip index */ subs->dma_device.id = subs->pcm->device << 16 | subs->stream << 8 | (subs->number + 1) | (chip->chip_idx + 1) << 24; } #endif snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->mgr->pci->dev, 32*1024, 32*1024); } /* */ static int snd_mixart_pcm_analog(struct snd_mixart *chip) { int err; struct snd_pcm *pcm; char name[32]; sprintf(name, "miXart analog %d", chip->chip_idx); err = snd_pcm_new(chip->card, name, MIXART_PCM_ANALOG, MIXART_PLAYBACK_STREAMS, MIXART_CAPTURE_STREAMS, &pcm); if (err < 0) { dev_err(chip->card->dev, "cannot create the analog pcm %d\n", chip->chip_idx); return err; } pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_mixart_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_mixart_capture_ops); pcm->info_flags = 0; pcm->nonatomic = true; strcpy(pcm->name, name); preallocate_buffers(chip, pcm); chip->pcm = pcm; return 0; } /* */ static int snd_mixart_pcm_digital(struct snd_mixart *chip) { int err; struct snd_pcm *pcm; char name[32]; sprintf(name, "miXart AES/EBU %d", chip->chip_idx); err = snd_pcm_new(chip->card, name, MIXART_PCM_DIGITAL, MIXART_PLAYBACK_STREAMS, MIXART_CAPTURE_STREAMS, &pcm); if (err < 0) { dev_err(chip->card->dev, "cannot create the digital pcm %d\n", chip->chip_idx); return err; } pcm->private_data = chip; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_mixart_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_mixart_capture_ops); pcm->info_flags = 0; pcm->nonatomic = true; strcpy(pcm->name, name); preallocate_buffers(chip, pcm); chip->pcm_dig = pcm; return 0; } static int snd_mixart_chip_free(struct snd_mixart *chip) { kfree(chip); return 0; } static int snd_mixart_chip_dev_free(struct snd_device *device) { struct snd_mixart *chip = device->device_data; return snd_mixart_chip_free(chip); } /* */ static int snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *card, int idx) { int err; struct snd_mixart *chip; static const struct snd_device_ops ops = { .dev_free = snd_mixart_chip_dev_free, }; chip = kzalloc(sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; chip->card = card; chip->chip_idx = idx; chip->mgr = mgr; card->sync_irq = mgr->irq; err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); if (err < 0) { snd_mixart_chip_free(chip); return err; } mgr->chip[idx] = chip; return 0; } int snd_mixart_create_pcm(struct snd_mixart* chip) { int err; err = snd_mixart_pcm_analog(chip); if (err < 0) return err; if(chip->mgr->board_type == MIXART_DAUGHTER_TYPE_AES) { err = snd_mixart_pcm_digital(chip); if (err < 0) return err; } return err; } /* * release all the cards assigned to a manager instance */ static int snd_mixart_free(struct mixart_mgr *mgr) { unsigned int i; for (i = 0; i < mgr->num_cards; i++) { if (mgr->chip[i]) snd_card_free(mgr->chip[i]->card); } /* stop mailbox */ snd_mixart_exit_mailbox(mgr); /* release irq */ if (mgr->irq >= 0) free_irq(mgr->irq, mgr); /* reset board if some firmware was loaded */ if(mgr->dsp_loaded) { snd_mixart_reset_board(mgr); dev_dbg(&mgr->pci->dev, "reset miXart !\n"); } /* release the i/o ports */ for (i = 0; i < 2; ++i) iounmap(mgr->mem[i].virt); pci_release_regions(mgr->pci); /* free flowarray */ if(mgr->flowinfo.area) { snd_dma_free_pages(&mgr->flowinfo); mgr->flowinfo.area = NULL; } /* free bufferarray */ if(mgr->bufferinfo.area) { snd_dma_free_pages(&mgr->bufferinfo); mgr->bufferinfo.area = NULL; } pci_disable_device(mgr->pci); kfree(mgr); return 0; } /* * proc interface */ /* mixart_BA0 proc interface for BAR 0 - read callback */ static ssize_t snd_mixart_BA0_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, char __user *buf, size_t count, loff_t pos) { struct mixart_mgr *mgr = entry->private_data; count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ if (copy_to_user_fromio(buf, MIXART_MEM(mgr, pos), count)) return -EFAULT; return count; } /* mixart_BA1 proc interface for BAR 1 - read callback */ static ssize_t snd_mixart_BA1_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, char __user *buf, size_t count, loff_t pos) { struct mixart_mgr *mgr = entry->private_data; count = count & ~3; /* make sure the read size is a multiple of 4 bytes */ if (copy_to_user_fromio(buf, MIXART_REG(mgr, pos), count)) return -EFAULT; return count; } static const struct snd_info_entry_ops snd_mixart_proc_ops_BA0 = { .read = snd_mixart_BA0_read, }; static const struct snd_info_entry_ops snd_mixart_proc_ops_BA1 = { .read = snd_mixart_BA1_read, }; static void snd_mixart_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_mixart *chip = entry->private_data; u32 ref; snd_iprintf(buffer, "Digigram miXart (alsa card %d)\n\n", chip->chip_idx); /* stats available when embedded OS is running */ if (chip->mgr->dsp_loaded & ( 1 << MIXART_MOTHERBOARD_ELF_INDEX)) { snd_iprintf(buffer, "- hardware -\n"); switch (chip->mgr->board_type ) { case MIXART_DAUGHTER_TYPE_NONE : snd_iprintf(buffer, "\tmiXart8 (no daughter board)\n\n"); break; case MIXART_DAUGHTER_TYPE_AES : snd_iprintf(buffer, "\tmiXart8 AES/EBU\n\n"); break; case MIXART_DAUGHTER_TYPE_COBRANET : snd_iprintf(buffer, "\tmiXart8 Cobranet\n\n"); break; default: snd_iprintf(buffer, "\tUNKNOWN!\n\n"); break; } snd_iprintf(buffer, "- system load -\n"); /* get perf reference */ ref = readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_SYSTEM_LOAD_OFFSET)); if (ref) { u32 mailbox = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_MAILBX_LOAD_OFFSET)) / ref; u32 streaming = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_STREAM_LOAD_OFFSET)) / ref; u32 interr = 100 * readl_be( MIXART_MEM( chip->mgr, MIXART_PSEUDOREG_PERF_INTERR_LOAD_OFFSET)) / ref; snd_iprintf(buffer, "\tstreaming : %d\n", streaming); snd_iprintf(buffer, "\tmailbox : %d\n", mailbox); snd_iprintf(buffer, "\tinterrupts handling : %d\n\n", interr); } } /* endif elf loaded */ } static void snd_mixart_proc_init(struct snd_mixart *chip) { struct snd_info_entry *entry; /* text interface to read perf and temp meters */ snd_card_ro_proc_new(chip->card, "board_info", chip, snd_mixart_proc_read); if (! snd_card_proc_new(chip->card, "mixart_BA0", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = chip->mgr; entry->c.ops = &snd_mixart_proc_ops_BA0; entry->size = MIXART_BA0_SIZE; } if (! snd_card_proc_new(chip->card, "mixart_BA1", &entry)) { entry->content = SNDRV_INFO_CONTENT_DATA; entry->private_data = chip->mgr; entry->c.ops = &snd_mixart_proc_ops_BA1; entry->size = MIXART_BA1_SIZE; } } /* end of proc interface */ /* * probe function - creates the card manager */ static int snd_mixart_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; struct mixart_mgr *mgr; unsigned int i; int err; size_t size; /* */ if (dev >= SNDRV_CARDS) return -ENODEV; if (! enable[dev]) { dev++; return -ENOENT; } /* enable PCI device */ err = pci_enable_device(pci); if (err < 0) return err; pci_set_master(pci); /* check if we can restrict PCI DMA transfers to 32 bits */ if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) { dev_err(&pci->dev, "architecture does not support 32bit PCI busmaster DMA\n"); pci_disable_device(pci); return -ENXIO; } /* */ mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); if (! mgr) { pci_disable_device(pci); return -ENOMEM; } mgr->pci = pci; mgr->irq = -1; /* resource assignment */ err = pci_request_regions(pci, CARD_NAME); if (err < 0) { kfree(mgr); pci_disable_device(pci); return err; } for (i = 0; i < 2; i++) { mgr->mem[i].phys = pci_resource_start(pci, i); mgr->mem[i].virt = pci_ioremap_bar(pci, i); if (!mgr->mem[i].virt) { dev_err(&pci->dev, "unable to remap resource 0x%lx\n", mgr->mem[i].phys); snd_mixart_free(mgr); return -EBUSY; } } if (request_threaded_irq(pci->irq, snd_mixart_interrupt, snd_mixart_threaded_irq, IRQF_SHARED, KBUILD_MODNAME, mgr)) { dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq); snd_mixart_free(mgr); return -EBUSY; } mgr->irq = pci->irq; /* init mailbox */ mgr->msg_fifo_readptr = 0; mgr->msg_fifo_writeptr = 0; mutex_init(&mgr->lock); mutex_init(&mgr->msg_lock); init_waitqueue_head(&mgr->msg_sleep); atomic_set(&mgr->msg_processed, 0); /* init setup mutex*/ mutex_init(&mgr->setup_mutex); /* card assignment */ mgr->num_cards = MIXART_MAX_CARDS; /* 4 FIXME: configurable? */ for (i = 0; i < mgr->num_cards; i++) { struct snd_card *card; char tmpid[16]; int idx; if (index[dev] < 0) idx = index[dev]; else idx = index[dev] + i; snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i); err = snd_card_new(&pci->dev, idx, tmpid, THIS_MODULE, 0, &card); if (err < 0) { dev_err(&pci->dev, "cannot allocate the card %d\n", i); snd_mixart_free(mgr); return err; } strcpy(card->driver, CARD_NAME); snprintf(card->shortname, sizeof(card->shortname), "Digigram miXart [PCM #%d]", i); snprintf(card->longname, sizeof(card->longname), "Digigram miXart at 0x%lx & 0x%lx, irq %i [PCM #%d]", mgr->mem[0].phys, mgr->mem[1].phys, mgr->irq, i); err = snd_mixart_create(mgr, card, i); if (err < 0) { snd_card_free(card); snd_mixart_free(mgr); return err; } if(i==0) { /* init proc interface only for chip0 */ snd_mixart_proc_init(mgr->chip[i]); } err = snd_card_register(card); if (err < 0) { snd_mixart_free(mgr); return err; } } /* init firmware status (mgr->dsp_loaded reset in hwdep_new) */ mgr->board_type = MIXART_DAUGHTER_TYPE_NONE; /* create array of streaminfo */ size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS * sizeof(struct mixart_flowinfo)) ); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, &mgr->flowinfo) < 0) { snd_mixart_free(mgr); return -ENOMEM; } /* init streaminfo_array */ memset(mgr->flowinfo.area, 0, size); /* create array of bufferinfo */ size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS * sizeof(struct mixart_bufferinfo)) ); if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, &mgr->bufferinfo) < 0) { snd_mixart_free(mgr); return -ENOMEM; } /* init bufferinfo_array */ memset(mgr->bufferinfo.area, 0, size); /* set up firmware */ err = snd_mixart_setup_firmware(mgr); if (err < 0) { snd_mixart_free(mgr); return err; } pci_set_drvdata(pci, mgr); dev++; return 0; } static void snd_mixart_remove(struct pci_dev *pci) { snd_mixart_free(pci_get_drvdata(pci)); } static struct pci_driver mixart_driver = { .name = KBUILD_MODNAME, .id_table = snd_mixart_ids, .probe = snd_mixart_probe, .remove = snd_mixart_remove, }; module_pci_driver(mixart_driver);
linux-master
sound/pci/mixart/mixart.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram miXart soundcards * * mixer callbacks * * Copyright (c) 2003 by Digigram <[email protected]> */ #include <linux/time.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/mutex.h> #include <sound/core.h> #include "mixart.h" #include "mixart_core.h" #include "mixart_hwdep.h" #include <sound/control.h> #include <sound/tlv.h> #include "mixart_mixer.h" static const u32 mixart_analog_level[256] = { 0xc2c00000, /* [000] -96.0 dB */ 0xc2bf0000, /* [001] -95.5 dB */ 0xc2be0000, /* [002] -95.0 dB */ 0xc2bd0000, /* [003] -94.5 dB */ 0xc2bc0000, /* [004] -94.0 dB */ 0xc2bb0000, /* [005] -93.5 dB */ 0xc2ba0000, /* [006] -93.0 dB */ 0xc2b90000, /* [007] -92.5 dB */ 0xc2b80000, /* [008] -92.0 dB */ 0xc2b70000, /* [009] -91.5 dB */ 0xc2b60000, /* [010] -91.0 dB */ 0xc2b50000, /* [011] -90.5 dB */ 0xc2b40000, /* [012] -90.0 dB */ 0xc2b30000, /* [013] -89.5 dB */ 0xc2b20000, /* [014] -89.0 dB */ 0xc2b10000, /* [015] -88.5 dB */ 0xc2b00000, /* [016] -88.0 dB */ 0xc2af0000, /* [017] -87.5 dB */ 0xc2ae0000, /* [018] -87.0 dB */ 0xc2ad0000, /* [019] -86.5 dB */ 0xc2ac0000, /* [020] -86.0 dB */ 0xc2ab0000, /* [021] -85.5 dB */ 0xc2aa0000, /* [022] -85.0 dB */ 0xc2a90000, /* [023] -84.5 dB */ 0xc2a80000, /* [024] -84.0 dB */ 0xc2a70000, /* [025] -83.5 dB */ 0xc2a60000, /* [026] -83.0 dB */ 0xc2a50000, /* [027] -82.5 dB */ 0xc2a40000, /* [028] -82.0 dB */ 0xc2a30000, /* [029] -81.5 dB */ 0xc2a20000, /* [030] -81.0 dB */ 0xc2a10000, /* [031] -80.5 dB */ 0xc2a00000, /* [032] -80.0 dB */ 0xc29f0000, /* [033] -79.5 dB */ 0xc29e0000, /* [034] -79.0 dB */ 0xc29d0000, /* [035] -78.5 dB */ 0xc29c0000, /* [036] -78.0 dB */ 0xc29b0000, /* [037] -77.5 dB */ 0xc29a0000, /* [038] -77.0 dB */ 0xc2990000, /* [039] -76.5 dB */ 0xc2980000, /* [040] -76.0 dB */ 0xc2970000, /* [041] -75.5 dB */ 0xc2960000, /* [042] -75.0 dB */ 0xc2950000, /* [043] -74.5 dB */ 0xc2940000, /* [044] -74.0 dB */ 0xc2930000, /* [045] -73.5 dB */ 0xc2920000, /* [046] -73.0 dB */ 0xc2910000, /* [047] -72.5 dB */ 0xc2900000, /* [048] -72.0 dB */ 0xc28f0000, /* [049] -71.5 dB */ 0xc28e0000, /* [050] -71.0 dB */ 0xc28d0000, /* [051] -70.5 dB */ 0xc28c0000, /* [052] -70.0 dB */ 0xc28b0000, /* [053] -69.5 dB */ 0xc28a0000, /* [054] -69.0 dB */ 0xc2890000, /* [055] -68.5 dB */ 0xc2880000, /* [056] -68.0 dB */ 0xc2870000, /* [057] -67.5 dB */ 0xc2860000, /* [058] -67.0 dB */ 0xc2850000, /* [059] -66.5 dB */ 0xc2840000, /* [060] -66.0 dB */ 0xc2830000, /* [061] -65.5 dB */ 0xc2820000, /* [062] -65.0 dB */ 0xc2810000, /* [063] -64.5 dB */ 0xc2800000, /* [064] -64.0 dB */ 0xc27e0000, /* [065] -63.5 dB */ 0xc27c0000, /* [066] -63.0 dB */ 0xc27a0000, /* [067] -62.5 dB */ 0xc2780000, /* [068] -62.0 dB */ 0xc2760000, /* [069] -61.5 dB */ 0xc2740000, /* [070] -61.0 dB */ 0xc2720000, /* [071] -60.5 dB */ 0xc2700000, /* [072] -60.0 dB */ 0xc26e0000, /* [073] -59.5 dB */ 0xc26c0000, /* [074] -59.0 dB */ 0xc26a0000, /* [075] -58.5 dB */ 0xc2680000, /* [076] -58.0 dB */ 0xc2660000, /* [077] -57.5 dB */ 0xc2640000, /* [078] -57.0 dB */ 0xc2620000, /* [079] -56.5 dB */ 0xc2600000, /* [080] -56.0 dB */ 0xc25e0000, /* [081] -55.5 dB */ 0xc25c0000, /* [082] -55.0 dB */ 0xc25a0000, /* [083] -54.5 dB */ 0xc2580000, /* [084] -54.0 dB */ 0xc2560000, /* [085] -53.5 dB */ 0xc2540000, /* [086] -53.0 dB */ 0xc2520000, /* [087] -52.5 dB */ 0xc2500000, /* [088] -52.0 dB */ 0xc24e0000, /* [089] -51.5 dB */ 0xc24c0000, /* [090] -51.0 dB */ 0xc24a0000, /* [091] -50.5 dB */ 0xc2480000, /* [092] -50.0 dB */ 0xc2460000, /* [093] -49.5 dB */ 0xc2440000, /* [094] -49.0 dB */ 0xc2420000, /* [095] -48.5 dB */ 0xc2400000, /* [096] -48.0 dB */ 0xc23e0000, /* [097] -47.5 dB */ 0xc23c0000, /* [098] -47.0 dB */ 0xc23a0000, /* [099] -46.5 dB */ 0xc2380000, /* [100] -46.0 dB */ 0xc2360000, /* [101] -45.5 dB */ 0xc2340000, /* [102] -45.0 dB */ 0xc2320000, /* [103] -44.5 dB */ 0xc2300000, /* [104] -44.0 dB */ 0xc22e0000, /* [105] -43.5 dB */ 0xc22c0000, /* [106] -43.0 dB */ 0xc22a0000, /* [107] -42.5 dB */ 0xc2280000, /* [108] -42.0 dB */ 0xc2260000, /* [109] -41.5 dB */ 0xc2240000, /* [110] -41.0 dB */ 0xc2220000, /* [111] -40.5 dB */ 0xc2200000, /* [112] -40.0 dB */ 0xc21e0000, /* [113] -39.5 dB */ 0xc21c0000, /* [114] -39.0 dB */ 0xc21a0000, /* [115] -38.5 dB */ 0xc2180000, /* [116] -38.0 dB */ 0xc2160000, /* [117] -37.5 dB */ 0xc2140000, /* [118] -37.0 dB */ 0xc2120000, /* [119] -36.5 dB */ 0xc2100000, /* [120] -36.0 dB */ 0xc20e0000, /* [121] -35.5 dB */ 0xc20c0000, /* [122] -35.0 dB */ 0xc20a0000, /* [123] -34.5 dB */ 0xc2080000, /* [124] -34.0 dB */ 0xc2060000, /* [125] -33.5 dB */ 0xc2040000, /* [126] -33.0 dB */ 0xc2020000, /* [127] -32.5 dB */ 0xc2000000, /* [128] -32.0 dB */ 0xc1fc0000, /* [129] -31.5 dB */ 0xc1f80000, /* [130] -31.0 dB */ 0xc1f40000, /* [131] -30.5 dB */ 0xc1f00000, /* [132] -30.0 dB */ 0xc1ec0000, /* [133] -29.5 dB */ 0xc1e80000, /* [134] -29.0 dB */ 0xc1e40000, /* [135] -28.5 dB */ 0xc1e00000, /* [136] -28.0 dB */ 0xc1dc0000, /* [137] -27.5 dB */ 0xc1d80000, /* [138] -27.0 dB */ 0xc1d40000, /* [139] -26.5 dB */ 0xc1d00000, /* [140] -26.0 dB */ 0xc1cc0000, /* [141] -25.5 dB */ 0xc1c80000, /* [142] -25.0 dB */ 0xc1c40000, /* [143] -24.5 dB */ 0xc1c00000, /* [144] -24.0 dB */ 0xc1bc0000, /* [145] -23.5 dB */ 0xc1b80000, /* [146] -23.0 dB */ 0xc1b40000, /* [147] -22.5 dB */ 0xc1b00000, /* [148] -22.0 dB */ 0xc1ac0000, /* [149] -21.5 dB */ 0xc1a80000, /* [150] -21.0 dB */ 0xc1a40000, /* [151] -20.5 dB */ 0xc1a00000, /* [152] -20.0 dB */ 0xc19c0000, /* [153] -19.5 dB */ 0xc1980000, /* [154] -19.0 dB */ 0xc1940000, /* [155] -18.5 dB */ 0xc1900000, /* [156] -18.0 dB */ 0xc18c0000, /* [157] -17.5 dB */ 0xc1880000, /* [158] -17.0 dB */ 0xc1840000, /* [159] -16.5 dB */ 0xc1800000, /* [160] -16.0 dB */ 0xc1780000, /* [161] -15.5 dB */ 0xc1700000, /* [162] -15.0 dB */ 0xc1680000, /* [163] -14.5 dB */ 0xc1600000, /* [164] -14.0 dB */ 0xc1580000, /* [165] -13.5 dB */ 0xc1500000, /* [166] -13.0 dB */ 0xc1480000, /* [167] -12.5 dB */ 0xc1400000, /* [168] -12.0 dB */ 0xc1380000, /* [169] -11.5 dB */ 0xc1300000, /* [170] -11.0 dB */ 0xc1280000, /* [171] -10.5 dB */ 0xc1200000, /* [172] -10.0 dB */ 0xc1180000, /* [173] -9.5 dB */ 0xc1100000, /* [174] -9.0 dB */ 0xc1080000, /* [175] -8.5 dB */ 0xc1000000, /* [176] -8.0 dB */ 0xc0f00000, /* [177] -7.5 dB */ 0xc0e00000, /* [178] -7.0 dB */ 0xc0d00000, /* [179] -6.5 dB */ 0xc0c00000, /* [180] -6.0 dB */ 0xc0b00000, /* [181] -5.5 dB */ 0xc0a00000, /* [182] -5.0 dB */ 0xc0900000, /* [183] -4.5 dB */ 0xc0800000, /* [184] -4.0 dB */ 0xc0600000, /* [185] -3.5 dB */ 0xc0400000, /* [186] -3.0 dB */ 0xc0200000, /* [187] -2.5 dB */ 0xc0000000, /* [188] -2.0 dB */ 0xbfc00000, /* [189] -1.5 dB */ 0xbf800000, /* [190] -1.0 dB */ 0xbf000000, /* [191] -0.5 dB */ 0x00000000, /* [192] 0.0 dB */ 0x3f000000, /* [193] 0.5 dB */ 0x3f800000, /* [194] 1.0 dB */ 0x3fc00000, /* [195] 1.5 dB */ 0x40000000, /* [196] 2.0 dB */ 0x40200000, /* [197] 2.5 dB */ 0x40400000, /* [198] 3.0 dB */ 0x40600000, /* [199] 3.5 dB */ 0x40800000, /* [200] 4.0 dB */ 0x40900000, /* [201] 4.5 dB */ 0x40a00000, /* [202] 5.0 dB */ 0x40b00000, /* [203] 5.5 dB */ 0x40c00000, /* [204] 6.0 dB */ 0x40d00000, /* [205] 6.5 dB */ 0x40e00000, /* [206] 7.0 dB */ 0x40f00000, /* [207] 7.5 dB */ 0x41000000, /* [208] 8.0 dB */ 0x41080000, /* [209] 8.5 dB */ 0x41100000, /* [210] 9.0 dB */ 0x41180000, /* [211] 9.5 dB */ 0x41200000, /* [212] 10.0 dB */ 0x41280000, /* [213] 10.5 dB */ 0x41300000, /* [214] 11.0 dB */ 0x41380000, /* [215] 11.5 dB */ 0x41400000, /* [216] 12.0 dB */ 0x41480000, /* [217] 12.5 dB */ 0x41500000, /* [218] 13.0 dB */ 0x41580000, /* [219] 13.5 dB */ 0x41600000, /* [220] 14.0 dB */ 0x41680000, /* [221] 14.5 dB */ 0x41700000, /* [222] 15.0 dB */ 0x41780000, /* [223] 15.5 dB */ 0x41800000, /* [224] 16.0 dB */ 0x41840000, /* [225] 16.5 dB */ 0x41880000, /* [226] 17.0 dB */ 0x418c0000, /* [227] 17.5 dB */ 0x41900000, /* [228] 18.0 dB */ 0x41940000, /* [229] 18.5 dB */ 0x41980000, /* [230] 19.0 dB */ 0x419c0000, /* [231] 19.5 dB */ 0x41a00000, /* [232] 20.0 dB */ 0x41a40000, /* [233] 20.5 dB */ 0x41a80000, /* [234] 21.0 dB */ 0x41ac0000, /* [235] 21.5 dB */ 0x41b00000, /* [236] 22.0 dB */ 0x41b40000, /* [237] 22.5 dB */ 0x41b80000, /* [238] 23.0 dB */ 0x41bc0000, /* [239] 23.5 dB */ 0x41c00000, /* [240] 24.0 dB */ 0x41c40000, /* [241] 24.5 dB */ 0x41c80000, /* [242] 25.0 dB */ 0x41cc0000, /* [243] 25.5 dB */ 0x41d00000, /* [244] 26.0 dB */ 0x41d40000, /* [245] 26.5 dB */ 0x41d80000, /* [246] 27.0 dB */ 0x41dc0000, /* [247] 27.5 dB */ 0x41e00000, /* [248] 28.0 dB */ 0x41e40000, /* [249] 28.5 dB */ 0x41e80000, /* [250] 29.0 dB */ 0x41ec0000, /* [251] 29.5 dB */ 0x41f00000, /* [252] 30.0 dB */ 0x41f40000, /* [253] 30.5 dB */ 0x41f80000, /* [254] 31.0 dB */ 0x41fc0000, /* [255] 31.5 dB */ }; #define MIXART_ANALOG_CAPTURE_LEVEL_MIN 0 /* -96.0 dB + 8.0 dB = -88.0 dB */ #define MIXART_ANALOG_CAPTURE_LEVEL_MAX 255 /* 31.5 dB + 8.0 dB = 39.5 dB */ #define MIXART_ANALOG_CAPTURE_ZERO_LEVEL 176 /* -8.0 dB + 8.0 dB = 0.0 dB */ #define MIXART_ANALOG_PLAYBACK_LEVEL_MIN 0 /* -96.0 dB + 1.5 dB = -94.5 dB (possible is down to (-114.0+1.5)dB) */ #define MIXART_ANALOG_PLAYBACK_LEVEL_MAX 192 /* 0.0 dB + 1.5 dB = 1.5 dB */ #define MIXART_ANALOG_PLAYBACK_ZERO_LEVEL 189 /* -1.5 dB + 1.5 dB = 0.0 dB */ static int mixart_update_analog_audio_level(struct snd_mixart* chip, int is_capture) { int i, err; struct mixart_msg request; struct mixart_io_level io_level; struct mixart_return_uid resp; memset(&io_level, 0, sizeof(io_level)); io_level.channel = -1; /* left and right */ for(i=0; i<2; i++) { if(is_capture) { io_level.level[i].analog_level = mixart_analog_level[chip->analog_capture_volume[i]]; } else { if(chip->analog_playback_active[i]) io_level.level[i].analog_level = mixart_analog_level[chip->analog_playback_volume[i]]; else io_level.level[i].analog_level = mixart_analog_level[MIXART_ANALOG_PLAYBACK_LEVEL_MIN]; } } if(is_capture) request.uid = chip->uid_in_analog_physio; else request.uid = chip->uid_out_analog_physio; request.message_id = MSG_PHYSICALIO_SET_LEVEL; request.data = &io_level; request.size = sizeof(io_level); err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); if((err<0) || (resp.error_code)) { dev_dbg(chip->card->dev, "error MSG_PHYSICALIO_SET_LEVEL card(%d) is_capture(%d) error_code(%x)\n", chip->chip_idx, is_capture, resp.error_code); return -EINVAL; } return 0; } /* * analog level control */ static int mixart_analog_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; if(kcontrol->private_value == 0) { /* playback */ uinfo->value.integer.min = MIXART_ANALOG_PLAYBACK_LEVEL_MIN; /* -96 dB */ uinfo->value.integer.max = MIXART_ANALOG_PLAYBACK_LEVEL_MAX; /* 0 dB */ } else { /* capture */ uinfo->value.integer.min = MIXART_ANALOG_CAPTURE_LEVEL_MIN; /* -96 dB */ uinfo->value.integer.max = MIXART_ANALOG_CAPTURE_LEVEL_MAX; /* 31.5 dB */ } return 0; } static int mixart_analog_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); mutex_lock(&chip->mgr->mixer_mutex); if(kcontrol->private_value == 0) { /* playback */ ucontrol->value.integer.value[0] = chip->analog_playback_volume[0]; ucontrol->value.integer.value[1] = chip->analog_playback_volume[1]; } else { /* capture */ ucontrol->value.integer.value[0] = chip->analog_capture_volume[0]; ucontrol->value.integer.value[1] = chip->analog_capture_volume[1]; } mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_analog_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int is_capture, i; mutex_lock(&chip->mgr->mixer_mutex); is_capture = (kcontrol->private_value != 0); for (i = 0; i < 2; i++) { int new_volume = ucontrol->value.integer.value[i]; int *stored_volume = is_capture ? &chip->analog_capture_volume[i] : &chip->analog_playback_volume[i]; if (is_capture) { if (new_volume < MIXART_ANALOG_CAPTURE_LEVEL_MIN || new_volume > MIXART_ANALOG_CAPTURE_LEVEL_MAX) continue; } else { if (new_volume < MIXART_ANALOG_PLAYBACK_LEVEL_MIN || new_volume > MIXART_ANALOG_PLAYBACK_LEVEL_MAX) continue; } if (*stored_volume != new_volume) { *stored_volume = new_volume; changed = 1; } } if (changed) mixart_update_analog_audio_level(chip, is_capture); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } static const DECLARE_TLV_DB_SCALE(db_scale_analog, -9600, 50, 0); static const struct snd_kcontrol_new mixart_control_analog_level = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), /* name will be filled later */ .info = mixart_analog_vol_info, .get = mixart_analog_vol_get, .put = mixart_analog_vol_put, .tlv = { .p = db_scale_analog }, }; /* shared */ #define mixart_sw_info snd_ctl_boolean_stereo_info static int mixart_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); mutex_lock(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0] = chip->analog_playback_active[0]; ucontrol->value.integer.value[1] = chip->analog_playback_active[1]; mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int i, changed = 0; mutex_lock(&chip->mgr->mixer_mutex); for (i = 0; i < 2; i++) { if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) { chip->analog_playback_active[i] = !!ucontrol->value.integer.value[i]; changed = 1; } } if (changed) /* update playback levels */ mixart_update_analog_audio_level(chip, 0); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } static const struct snd_kcontrol_new mixart_control_output_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .info = mixart_sw_info, /* shared */ .get = mixart_audio_sw_get, .put = mixart_audio_sw_put }; static const u32 mixart_digital_level[256] = { 0x00000000, /* [000] = 0.00e+000 = mute if <= -109.5dB */ 0x366e1c7a, /* [001] = 3.55e-006 = pow(10.0, 0.05 * -109.0dB) */ 0x367c3860, /* [002] = 3.76e-006 = pow(10.0, 0.05 * -108.5dB) */ 0x36859525, /* [003] = 3.98e-006 = pow(10.0, 0.05 * -108.0dB) */ 0x368d7f74, /* [004] = 4.22e-006 = pow(10.0, 0.05 * -107.5dB) */ 0x3695e1d4, /* [005] = 4.47e-006 = pow(10.0, 0.05 * -107.0dB) */ 0x369ec362, /* [006] = 4.73e-006 = pow(10.0, 0.05 * -106.5dB) */ 0x36a82ba8, /* [007] = 5.01e-006 = pow(10.0, 0.05 * -106.0dB) */ 0x36b222a0, /* [008] = 5.31e-006 = pow(10.0, 0.05 * -105.5dB) */ 0x36bcb0c1, /* [009] = 5.62e-006 = pow(10.0, 0.05 * -105.0dB) */ 0x36c7defd, /* [010] = 5.96e-006 = pow(10.0, 0.05 * -104.5dB) */ 0x36d3b6d3, /* [011] = 6.31e-006 = pow(10.0, 0.05 * -104.0dB) */ 0x36e0424e, /* [012] = 6.68e-006 = pow(10.0, 0.05 * -103.5dB) */ 0x36ed8c14, /* [013] = 7.08e-006 = pow(10.0, 0.05 * -103.0dB) */ 0x36fb9f6c, /* [014] = 7.50e-006 = pow(10.0, 0.05 * -102.5dB) */ 0x37054423, /* [015] = 7.94e-006 = pow(10.0, 0.05 * -102.0dB) */ 0x370d29a5, /* [016] = 8.41e-006 = pow(10.0, 0.05 * -101.5dB) */ 0x371586f0, /* [017] = 8.91e-006 = pow(10.0, 0.05 * -101.0dB) */ 0x371e631b, /* [018] = 9.44e-006 = pow(10.0, 0.05 * -100.5dB) */ 0x3727c5ac, /* [019] = 1.00e-005 = pow(10.0, 0.05 * -100.0dB) */ 0x3731b69a, /* [020] = 1.06e-005 = pow(10.0, 0.05 * -99.5dB) */ 0x373c3e53, /* [021] = 1.12e-005 = pow(10.0, 0.05 * -99.0dB) */ 0x374765c8, /* [022] = 1.19e-005 = pow(10.0, 0.05 * -98.5dB) */ 0x3753366f, /* [023] = 1.26e-005 = pow(10.0, 0.05 * -98.0dB) */ 0x375fba4f, /* [024] = 1.33e-005 = pow(10.0, 0.05 * -97.5dB) */ 0x376cfc07, /* [025] = 1.41e-005 = pow(10.0, 0.05 * -97.0dB) */ 0x377b06d5, /* [026] = 1.50e-005 = pow(10.0, 0.05 * -96.5dB) */ 0x3784f352, /* [027] = 1.58e-005 = pow(10.0, 0.05 * -96.0dB) */ 0x378cd40b, /* [028] = 1.68e-005 = pow(10.0, 0.05 * -95.5dB) */ 0x37952c42, /* [029] = 1.78e-005 = pow(10.0, 0.05 * -95.0dB) */ 0x379e030e, /* [030] = 1.88e-005 = pow(10.0, 0.05 * -94.5dB) */ 0x37a75fef, /* [031] = 2.00e-005 = pow(10.0, 0.05 * -94.0dB) */ 0x37b14ad5, /* [032] = 2.11e-005 = pow(10.0, 0.05 * -93.5dB) */ 0x37bbcc2c, /* [033] = 2.24e-005 = pow(10.0, 0.05 * -93.0dB) */ 0x37c6ecdd, /* [034] = 2.37e-005 = pow(10.0, 0.05 * -92.5dB) */ 0x37d2b65a, /* [035] = 2.51e-005 = pow(10.0, 0.05 * -92.0dB) */ 0x37df32a3, /* [036] = 2.66e-005 = pow(10.0, 0.05 * -91.5dB) */ 0x37ec6c50, /* [037] = 2.82e-005 = pow(10.0, 0.05 * -91.0dB) */ 0x37fa6e9b, /* [038] = 2.99e-005 = pow(10.0, 0.05 * -90.5dB) */ 0x3804a2b3, /* [039] = 3.16e-005 = pow(10.0, 0.05 * -90.0dB) */ 0x380c7ea4, /* [040] = 3.35e-005 = pow(10.0, 0.05 * -89.5dB) */ 0x3814d1cc, /* [041] = 3.55e-005 = pow(10.0, 0.05 * -89.0dB) */ 0x381da33c, /* [042] = 3.76e-005 = pow(10.0, 0.05 * -88.5dB) */ 0x3826fa6f, /* [043] = 3.98e-005 = pow(10.0, 0.05 * -88.0dB) */ 0x3830df51, /* [044] = 4.22e-005 = pow(10.0, 0.05 * -87.5dB) */ 0x383b5a49, /* [045] = 4.47e-005 = pow(10.0, 0.05 * -87.0dB) */ 0x3846743b, /* [046] = 4.73e-005 = pow(10.0, 0.05 * -86.5dB) */ 0x38523692, /* [047] = 5.01e-005 = pow(10.0, 0.05 * -86.0dB) */ 0x385eab48, /* [048] = 5.31e-005 = pow(10.0, 0.05 * -85.5dB) */ 0x386bdcf1, /* [049] = 5.62e-005 = pow(10.0, 0.05 * -85.0dB) */ 0x3879d6bc, /* [050] = 5.96e-005 = pow(10.0, 0.05 * -84.5dB) */ 0x38845244, /* [051] = 6.31e-005 = pow(10.0, 0.05 * -84.0dB) */ 0x388c2971, /* [052] = 6.68e-005 = pow(10.0, 0.05 * -83.5dB) */ 0x3894778d, /* [053] = 7.08e-005 = pow(10.0, 0.05 * -83.0dB) */ 0x389d43a4, /* [054] = 7.50e-005 = pow(10.0, 0.05 * -82.5dB) */ 0x38a6952c, /* [055] = 7.94e-005 = pow(10.0, 0.05 * -82.0dB) */ 0x38b0740f, /* [056] = 8.41e-005 = pow(10.0, 0.05 * -81.5dB) */ 0x38bae8ac, /* [057] = 8.91e-005 = pow(10.0, 0.05 * -81.0dB) */ 0x38c5fbe2, /* [058] = 9.44e-005 = pow(10.0, 0.05 * -80.5dB) */ 0x38d1b717, /* [059] = 1.00e-004 = pow(10.0, 0.05 * -80.0dB) */ 0x38de2440, /* [060] = 1.06e-004 = pow(10.0, 0.05 * -79.5dB) */ 0x38eb4de8, /* [061] = 1.12e-004 = pow(10.0, 0.05 * -79.0dB) */ 0x38f93f3a, /* [062] = 1.19e-004 = pow(10.0, 0.05 * -78.5dB) */ 0x39040206, /* [063] = 1.26e-004 = pow(10.0, 0.05 * -78.0dB) */ 0x390bd472, /* [064] = 1.33e-004 = pow(10.0, 0.05 * -77.5dB) */ 0x39141d84, /* [065] = 1.41e-004 = pow(10.0, 0.05 * -77.0dB) */ 0x391ce445, /* [066] = 1.50e-004 = pow(10.0, 0.05 * -76.5dB) */ 0x39263027, /* [067] = 1.58e-004 = pow(10.0, 0.05 * -76.0dB) */ 0x3930090d, /* [068] = 1.68e-004 = pow(10.0, 0.05 * -75.5dB) */ 0x393a7753, /* [069] = 1.78e-004 = pow(10.0, 0.05 * -75.0dB) */ 0x394583d2, /* [070] = 1.88e-004 = pow(10.0, 0.05 * -74.5dB) */ 0x395137ea, /* [071] = 2.00e-004 = pow(10.0, 0.05 * -74.0dB) */ 0x395d9d8a, /* [072] = 2.11e-004 = pow(10.0, 0.05 * -73.5dB) */ 0x396abf37, /* [073] = 2.24e-004 = pow(10.0, 0.05 * -73.0dB) */ 0x3978a814, /* [074] = 2.37e-004 = pow(10.0, 0.05 * -72.5dB) */ 0x3983b1f8, /* [075] = 2.51e-004 = pow(10.0, 0.05 * -72.0dB) */ 0x398b7fa6, /* [076] = 2.66e-004 = pow(10.0, 0.05 * -71.5dB) */ 0x3993c3b2, /* [077] = 2.82e-004 = pow(10.0, 0.05 * -71.0dB) */ 0x399c8521, /* [078] = 2.99e-004 = pow(10.0, 0.05 * -70.5dB) */ 0x39a5cb5f, /* [079] = 3.16e-004 = pow(10.0, 0.05 * -70.0dB) */ 0x39af9e4d, /* [080] = 3.35e-004 = pow(10.0, 0.05 * -69.5dB) */ 0x39ba063f, /* [081] = 3.55e-004 = pow(10.0, 0.05 * -69.0dB) */ 0x39c50c0b, /* [082] = 3.76e-004 = pow(10.0, 0.05 * -68.5dB) */ 0x39d0b90a, /* [083] = 3.98e-004 = pow(10.0, 0.05 * -68.0dB) */ 0x39dd1726, /* [084] = 4.22e-004 = pow(10.0, 0.05 * -67.5dB) */ 0x39ea30db, /* [085] = 4.47e-004 = pow(10.0, 0.05 * -67.0dB) */ 0x39f81149, /* [086] = 4.73e-004 = pow(10.0, 0.05 * -66.5dB) */ 0x3a03621b, /* [087] = 5.01e-004 = pow(10.0, 0.05 * -66.0dB) */ 0x3a0b2b0d, /* [088] = 5.31e-004 = pow(10.0, 0.05 * -65.5dB) */ 0x3a136a16, /* [089] = 5.62e-004 = pow(10.0, 0.05 * -65.0dB) */ 0x3a1c2636, /* [090] = 5.96e-004 = pow(10.0, 0.05 * -64.5dB) */ 0x3a2566d5, /* [091] = 6.31e-004 = pow(10.0, 0.05 * -64.0dB) */ 0x3a2f33cd, /* [092] = 6.68e-004 = pow(10.0, 0.05 * -63.5dB) */ 0x3a399570, /* [093] = 7.08e-004 = pow(10.0, 0.05 * -63.0dB) */ 0x3a44948c, /* [094] = 7.50e-004 = pow(10.0, 0.05 * -62.5dB) */ 0x3a503a77, /* [095] = 7.94e-004 = pow(10.0, 0.05 * -62.0dB) */ 0x3a5c9112, /* [096] = 8.41e-004 = pow(10.0, 0.05 * -61.5dB) */ 0x3a69a2d7, /* [097] = 8.91e-004 = pow(10.0, 0.05 * -61.0dB) */ 0x3a777ada, /* [098] = 9.44e-004 = pow(10.0, 0.05 * -60.5dB) */ 0x3a83126f, /* [099] = 1.00e-003 = pow(10.0, 0.05 * -60.0dB) */ 0x3a8ad6a8, /* [100] = 1.06e-003 = pow(10.0, 0.05 * -59.5dB) */ 0x3a9310b1, /* [101] = 1.12e-003 = pow(10.0, 0.05 * -59.0dB) */ 0x3a9bc784, /* [102] = 1.19e-003 = pow(10.0, 0.05 * -58.5dB) */ 0x3aa50287, /* [103] = 1.26e-003 = pow(10.0, 0.05 * -58.0dB) */ 0x3aaec98e, /* [104] = 1.33e-003 = pow(10.0, 0.05 * -57.5dB) */ 0x3ab924e5, /* [105] = 1.41e-003 = pow(10.0, 0.05 * -57.0dB) */ 0x3ac41d56, /* [106] = 1.50e-003 = pow(10.0, 0.05 * -56.5dB) */ 0x3acfbc31, /* [107] = 1.58e-003 = pow(10.0, 0.05 * -56.0dB) */ 0x3adc0b51, /* [108] = 1.68e-003 = pow(10.0, 0.05 * -55.5dB) */ 0x3ae91528, /* [109] = 1.78e-003 = pow(10.0, 0.05 * -55.0dB) */ 0x3af6e4c6, /* [110] = 1.88e-003 = pow(10.0, 0.05 * -54.5dB) */ 0x3b02c2f2, /* [111] = 2.00e-003 = pow(10.0, 0.05 * -54.0dB) */ 0x3b0a8276, /* [112] = 2.11e-003 = pow(10.0, 0.05 * -53.5dB) */ 0x3b12b782, /* [113] = 2.24e-003 = pow(10.0, 0.05 * -53.0dB) */ 0x3b1b690d, /* [114] = 2.37e-003 = pow(10.0, 0.05 * -52.5dB) */ 0x3b249e76, /* [115] = 2.51e-003 = pow(10.0, 0.05 * -52.0dB) */ 0x3b2e5f8f, /* [116] = 2.66e-003 = pow(10.0, 0.05 * -51.5dB) */ 0x3b38b49f, /* [117] = 2.82e-003 = pow(10.0, 0.05 * -51.0dB) */ 0x3b43a669, /* [118] = 2.99e-003 = pow(10.0, 0.05 * -50.5dB) */ 0x3b4f3e37, /* [119] = 3.16e-003 = pow(10.0, 0.05 * -50.0dB) */ 0x3b5b85e0, /* [120] = 3.35e-003 = pow(10.0, 0.05 * -49.5dB) */ 0x3b6887cf, /* [121] = 3.55e-003 = pow(10.0, 0.05 * -49.0dB) */ 0x3b764f0e, /* [122] = 3.76e-003 = pow(10.0, 0.05 * -48.5dB) */ 0x3b8273a6, /* [123] = 3.98e-003 = pow(10.0, 0.05 * -48.0dB) */ 0x3b8a2e77, /* [124] = 4.22e-003 = pow(10.0, 0.05 * -47.5dB) */ 0x3b925e89, /* [125] = 4.47e-003 = pow(10.0, 0.05 * -47.0dB) */ 0x3b9b0ace, /* [126] = 4.73e-003 = pow(10.0, 0.05 * -46.5dB) */ 0x3ba43aa2, /* [127] = 5.01e-003 = pow(10.0, 0.05 * -46.0dB) */ 0x3badf5d1, /* [128] = 5.31e-003 = pow(10.0, 0.05 * -45.5dB) */ 0x3bb8449c, /* [129] = 5.62e-003 = pow(10.0, 0.05 * -45.0dB) */ 0x3bc32fc3, /* [130] = 5.96e-003 = pow(10.0, 0.05 * -44.5dB) */ 0x3bcec08a, /* [131] = 6.31e-003 = pow(10.0, 0.05 * -44.0dB) */ 0x3bdb00c0, /* [132] = 6.68e-003 = pow(10.0, 0.05 * -43.5dB) */ 0x3be7facc, /* [133] = 7.08e-003 = pow(10.0, 0.05 * -43.0dB) */ 0x3bf5b9b0, /* [134] = 7.50e-003 = pow(10.0, 0.05 * -42.5dB) */ 0x3c02248a, /* [135] = 7.94e-003 = pow(10.0, 0.05 * -42.0dB) */ 0x3c09daac, /* [136] = 8.41e-003 = pow(10.0, 0.05 * -41.5dB) */ 0x3c1205c6, /* [137] = 8.91e-003 = pow(10.0, 0.05 * -41.0dB) */ 0x3c1aacc8, /* [138] = 9.44e-003 = pow(10.0, 0.05 * -40.5dB) */ 0x3c23d70a, /* [139] = 1.00e-002 = pow(10.0, 0.05 * -40.0dB) */ 0x3c2d8c52, /* [140] = 1.06e-002 = pow(10.0, 0.05 * -39.5dB) */ 0x3c37d4dd, /* [141] = 1.12e-002 = pow(10.0, 0.05 * -39.0dB) */ 0x3c42b965, /* [142] = 1.19e-002 = pow(10.0, 0.05 * -38.5dB) */ 0x3c4e4329, /* [143] = 1.26e-002 = pow(10.0, 0.05 * -38.0dB) */ 0x3c5a7bf1, /* [144] = 1.33e-002 = pow(10.0, 0.05 * -37.5dB) */ 0x3c676e1e, /* [145] = 1.41e-002 = pow(10.0, 0.05 * -37.0dB) */ 0x3c7524ac, /* [146] = 1.50e-002 = pow(10.0, 0.05 * -36.5dB) */ 0x3c81d59f, /* [147] = 1.58e-002 = pow(10.0, 0.05 * -36.0dB) */ 0x3c898712, /* [148] = 1.68e-002 = pow(10.0, 0.05 * -35.5dB) */ 0x3c91ad39, /* [149] = 1.78e-002 = pow(10.0, 0.05 * -35.0dB) */ 0x3c9a4efc, /* [150] = 1.88e-002 = pow(10.0, 0.05 * -34.5dB) */ 0x3ca373af, /* [151] = 2.00e-002 = pow(10.0, 0.05 * -34.0dB) */ 0x3cad2314, /* [152] = 2.11e-002 = pow(10.0, 0.05 * -33.5dB) */ 0x3cb76563, /* [153] = 2.24e-002 = pow(10.0, 0.05 * -33.0dB) */ 0x3cc24350, /* [154] = 2.37e-002 = pow(10.0, 0.05 * -32.5dB) */ 0x3ccdc614, /* [155] = 2.51e-002 = pow(10.0, 0.05 * -32.0dB) */ 0x3cd9f773, /* [156] = 2.66e-002 = pow(10.0, 0.05 * -31.5dB) */ 0x3ce6e1c6, /* [157] = 2.82e-002 = pow(10.0, 0.05 * -31.0dB) */ 0x3cf49003, /* [158] = 2.99e-002 = pow(10.0, 0.05 * -30.5dB) */ 0x3d0186e2, /* [159] = 3.16e-002 = pow(10.0, 0.05 * -30.0dB) */ 0x3d0933ac, /* [160] = 3.35e-002 = pow(10.0, 0.05 * -29.5dB) */ 0x3d1154e1, /* [161] = 3.55e-002 = pow(10.0, 0.05 * -29.0dB) */ 0x3d19f169, /* [162] = 3.76e-002 = pow(10.0, 0.05 * -28.5dB) */ 0x3d231090, /* [163] = 3.98e-002 = pow(10.0, 0.05 * -28.0dB) */ 0x3d2cba15, /* [164] = 4.22e-002 = pow(10.0, 0.05 * -27.5dB) */ 0x3d36f62b, /* [165] = 4.47e-002 = pow(10.0, 0.05 * -27.0dB) */ 0x3d41cd81, /* [166] = 4.73e-002 = pow(10.0, 0.05 * -26.5dB) */ 0x3d4d494a, /* [167] = 5.01e-002 = pow(10.0, 0.05 * -26.0dB) */ 0x3d597345, /* [168] = 5.31e-002 = pow(10.0, 0.05 * -25.5dB) */ 0x3d6655c3, /* [169] = 5.62e-002 = pow(10.0, 0.05 * -25.0dB) */ 0x3d73fbb4, /* [170] = 5.96e-002 = pow(10.0, 0.05 * -24.5dB) */ 0x3d813856, /* [171] = 6.31e-002 = pow(10.0, 0.05 * -24.0dB) */ 0x3d88e078, /* [172] = 6.68e-002 = pow(10.0, 0.05 * -23.5dB) */ 0x3d90fcbf, /* [173] = 7.08e-002 = pow(10.0, 0.05 * -23.0dB) */ 0x3d99940e, /* [174] = 7.50e-002 = pow(10.0, 0.05 * -22.5dB) */ 0x3da2adad, /* [175] = 7.94e-002 = pow(10.0, 0.05 * -22.0dB) */ 0x3dac5156, /* [176] = 8.41e-002 = pow(10.0, 0.05 * -21.5dB) */ 0x3db68738, /* [177] = 8.91e-002 = pow(10.0, 0.05 * -21.0dB) */ 0x3dc157fb, /* [178] = 9.44e-002 = pow(10.0, 0.05 * -20.5dB) */ 0x3dcccccd, /* [179] = 1.00e-001 = pow(10.0, 0.05 * -20.0dB) */ 0x3dd8ef67, /* [180] = 1.06e-001 = pow(10.0, 0.05 * -19.5dB) */ 0x3de5ca15, /* [181] = 1.12e-001 = pow(10.0, 0.05 * -19.0dB) */ 0x3df367bf, /* [182] = 1.19e-001 = pow(10.0, 0.05 * -18.5dB) */ 0x3e00e9f9, /* [183] = 1.26e-001 = pow(10.0, 0.05 * -18.0dB) */ 0x3e088d77, /* [184] = 1.33e-001 = pow(10.0, 0.05 * -17.5dB) */ 0x3e10a4d3, /* [185] = 1.41e-001 = pow(10.0, 0.05 * -17.0dB) */ 0x3e1936ec, /* [186] = 1.50e-001 = pow(10.0, 0.05 * -16.5dB) */ 0x3e224b06, /* [187] = 1.58e-001 = pow(10.0, 0.05 * -16.0dB) */ 0x3e2be8d7, /* [188] = 1.68e-001 = pow(10.0, 0.05 * -15.5dB) */ 0x3e361887, /* [189] = 1.78e-001 = pow(10.0, 0.05 * -15.0dB) */ 0x3e40e2bb, /* [190] = 1.88e-001 = pow(10.0, 0.05 * -14.5dB) */ 0x3e4c509b, /* [191] = 2.00e-001 = pow(10.0, 0.05 * -14.0dB) */ 0x3e586bd9, /* [192] = 2.11e-001 = pow(10.0, 0.05 * -13.5dB) */ 0x3e653ebb, /* [193] = 2.24e-001 = pow(10.0, 0.05 * -13.0dB) */ 0x3e72d424, /* [194] = 2.37e-001 = pow(10.0, 0.05 * -12.5dB) */ 0x3e809bcc, /* [195] = 2.51e-001 = pow(10.0, 0.05 * -12.0dB) */ 0x3e883aa8, /* [196] = 2.66e-001 = pow(10.0, 0.05 * -11.5dB) */ 0x3e904d1c, /* [197] = 2.82e-001 = pow(10.0, 0.05 * -11.0dB) */ 0x3e98da02, /* [198] = 2.99e-001 = pow(10.0, 0.05 * -10.5dB) */ 0x3ea1e89b, /* [199] = 3.16e-001 = pow(10.0, 0.05 * -10.0dB) */ 0x3eab8097, /* [200] = 3.35e-001 = pow(10.0, 0.05 * -9.5dB) */ 0x3eb5aa1a, /* [201] = 3.55e-001 = pow(10.0, 0.05 * -9.0dB) */ 0x3ec06dc3, /* [202] = 3.76e-001 = pow(10.0, 0.05 * -8.5dB) */ 0x3ecbd4b4, /* [203] = 3.98e-001 = pow(10.0, 0.05 * -8.0dB) */ 0x3ed7e89b, /* [204] = 4.22e-001 = pow(10.0, 0.05 * -7.5dB) */ 0x3ee4b3b6, /* [205] = 4.47e-001 = pow(10.0, 0.05 * -7.0dB) */ 0x3ef240e2, /* [206] = 4.73e-001 = pow(10.0, 0.05 * -6.5dB) */ 0x3f004dce, /* [207] = 5.01e-001 = pow(10.0, 0.05 * -6.0dB) */ 0x3f07e80b, /* [208] = 5.31e-001 = pow(10.0, 0.05 * -5.5dB) */ 0x3f0ff59a, /* [209] = 5.62e-001 = pow(10.0, 0.05 * -5.0dB) */ 0x3f187d50, /* [210] = 5.96e-001 = pow(10.0, 0.05 * -4.5dB) */ 0x3f21866c, /* [211] = 6.31e-001 = pow(10.0, 0.05 * -4.0dB) */ 0x3f2b1896, /* [212] = 6.68e-001 = pow(10.0, 0.05 * -3.5dB) */ 0x3f353bef, /* [213] = 7.08e-001 = pow(10.0, 0.05 * -3.0dB) */ 0x3f3ff911, /* [214] = 7.50e-001 = pow(10.0, 0.05 * -2.5dB) */ 0x3f4b5918, /* [215] = 7.94e-001 = pow(10.0, 0.05 * -2.0dB) */ 0x3f5765ac, /* [216] = 8.41e-001 = pow(10.0, 0.05 * -1.5dB) */ 0x3f642905, /* [217] = 8.91e-001 = pow(10.0, 0.05 * -1.0dB) */ 0x3f71adf9, /* [218] = 9.44e-001 = pow(10.0, 0.05 * -0.5dB) */ 0x3f800000, /* [219] = 1.00e+000 = pow(10.0, 0.05 * 0.0dB) */ 0x3f8795a0, /* [220] = 1.06e+000 = pow(10.0, 0.05 * 0.5dB) */ 0x3f8f9e4d, /* [221] = 1.12e+000 = pow(10.0, 0.05 * 1.0dB) */ 0x3f9820d7, /* [222] = 1.19e+000 = pow(10.0, 0.05 * 1.5dB) */ 0x3fa12478, /* [223] = 1.26e+000 = pow(10.0, 0.05 * 2.0dB) */ 0x3faab0d5, /* [224] = 1.33e+000 = pow(10.0, 0.05 * 2.5dB) */ 0x3fb4ce08, /* [225] = 1.41e+000 = pow(10.0, 0.05 * 3.0dB) */ 0x3fbf84a6, /* [226] = 1.50e+000 = pow(10.0, 0.05 * 3.5dB) */ 0x3fcaddc8, /* [227] = 1.58e+000 = pow(10.0, 0.05 * 4.0dB) */ 0x3fd6e30d, /* [228] = 1.68e+000 = pow(10.0, 0.05 * 4.5dB) */ 0x3fe39ea9, /* [229] = 1.78e+000 = pow(10.0, 0.05 * 5.0dB) */ 0x3ff11b6a, /* [230] = 1.88e+000 = pow(10.0, 0.05 * 5.5dB) */ 0x3fff64c1, /* [231] = 2.00e+000 = pow(10.0, 0.05 * 6.0dB) */ 0x40074368, /* [232] = 2.11e+000 = pow(10.0, 0.05 * 6.5dB) */ 0x400f4735, /* [233] = 2.24e+000 = pow(10.0, 0.05 * 7.0dB) */ 0x4017c496, /* [234] = 2.37e+000 = pow(10.0, 0.05 * 7.5dB) */ 0x4020c2bf, /* [235] = 2.51e+000 = pow(10.0, 0.05 * 8.0dB) */ 0x402a4952, /* [236] = 2.66e+000 = pow(10.0, 0.05 * 8.5dB) */ 0x40346063, /* [237] = 2.82e+000 = pow(10.0, 0.05 * 9.0dB) */ 0x403f1082, /* [238] = 2.99e+000 = pow(10.0, 0.05 * 9.5dB) */ 0x404a62c2, /* [239] = 3.16e+000 = pow(10.0, 0.05 * 10.0dB) */ 0x405660bd, /* [240] = 3.35e+000 = pow(10.0, 0.05 * 10.5dB) */ 0x406314a0, /* [241] = 3.55e+000 = pow(10.0, 0.05 * 11.0dB) */ 0x40708933, /* [242] = 3.76e+000 = pow(10.0, 0.05 * 11.5dB) */ 0x407ec9e1, /* [243] = 3.98e+000 = pow(10.0, 0.05 * 12.0dB) */ 0x4086f161, /* [244] = 4.22e+000 = pow(10.0, 0.05 * 12.5dB) */ 0x408ef052, /* [245] = 4.47e+000 = pow(10.0, 0.05 * 13.0dB) */ 0x4097688d, /* [246] = 4.73e+000 = pow(10.0, 0.05 * 13.5dB) */ 0x40a06142, /* [247] = 5.01e+000 = pow(10.0, 0.05 * 14.0dB) */ 0x40a9e20e, /* [248] = 5.31e+000 = pow(10.0, 0.05 * 14.5dB) */ 0x40b3f300, /* [249] = 5.62e+000 = pow(10.0, 0.05 * 15.0dB) */ 0x40be9ca5, /* [250] = 5.96e+000 = pow(10.0, 0.05 * 15.5dB) */ 0x40c9e807, /* [251] = 6.31e+000 = pow(10.0, 0.05 * 16.0dB) */ 0x40d5debc, /* [252] = 6.68e+000 = pow(10.0, 0.05 * 16.5dB) */ 0x40e28aeb, /* [253] = 7.08e+000 = pow(10.0, 0.05 * 17.0dB) */ 0x40eff755, /* [254] = 7.50e+000 = pow(10.0, 0.05 * 17.5dB) */ 0x40fe2f5e, /* [255] = 7.94e+000 = pow(10.0, 0.05 * 18.0dB) */ }; #define MIXART_DIGITAL_LEVEL_MIN 0 /* -109.5 dB */ #define MIXART_DIGITAL_LEVEL_MAX 255 /* 18.0 dB */ #define MIXART_DIGITAL_ZERO_LEVEL 219 /* 0.0 dB */ int mixart_update_playback_stream_level(struct snd_mixart* chip, int is_aes, int idx) { int err, i; int volume[2]; struct mixart_msg request; struct mixart_set_out_stream_level_req set_level; u32 status = 0; struct mixart_pipe *pipe; memset(&set_level, 0, sizeof(set_level)); set_level.nb_of_stream = 1; set_level.stream_level.desc.stream_idx = idx; if(is_aes) { pipe = &chip->pipe_out_dig; /* AES playback */ idx += MIXART_PLAYBACK_STREAMS; } else { pipe = &chip->pipe_out_ana; /* analog playback */ } /* only when pipe exists ! */ if(pipe->status == PIPE_UNDEFINED) return 0; set_level.stream_level.desc.uid_pipe = pipe->group_uid; for(i=0; i<2; i++) { if(chip->digital_playback_active[idx][i]) volume[i] = chip->digital_playback_volume[idx][i]; else volume[i] = MIXART_DIGITAL_LEVEL_MIN; } set_level.stream_level.out_level.valid_mask1 = MIXART_OUT_STREAM_SET_LEVEL_LEFT_AUDIO1 | MIXART_OUT_STREAM_SET_LEVEL_RIGHT_AUDIO2; set_level.stream_level.out_level.left_to_out1_level = mixart_digital_level[volume[0]]; set_level.stream_level.out_level.right_to_out2_level = mixart_digital_level[volume[1]]; request.message_id = MSG_STREAM_SET_OUT_STREAM_LEVEL; request.uid = (struct mixart_uid){0,0}; request.data = &set_level; request.size = sizeof(set_level); err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status); if((err<0) || status) { dev_dbg(chip->card->dev, "error MSG_STREAM_SET_OUT_STREAM_LEVEL card(%d) status(%x)\n", chip->chip_idx, status); return -EINVAL; } return 0; } int mixart_update_capture_stream_level(struct snd_mixart* chip, int is_aes) { int err, i, idx; struct mixart_pipe *pipe; struct mixart_msg request; struct mixart_set_in_audio_level_req set_level; u32 status = 0; if(is_aes) { idx = 1; pipe = &chip->pipe_in_dig; } else { idx = 0; pipe = &chip->pipe_in_ana; } /* only when pipe exists ! */ if(pipe->status == PIPE_UNDEFINED) return 0; memset(&set_level, 0, sizeof(set_level)); set_level.audio_count = 2; set_level.level[0].connector = pipe->uid_left_connector; set_level.level[1].connector = pipe->uid_right_connector; for(i=0; i<2; i++) { set_level.level[i].valid_mask1 = MIXART_AUDIO_LEVEL_DIGITAL_MASK; set_level.level[i].digital_level = mixart_digital_level[chip->digital_capture_volume[idx][i]]; } request.message_id = MSG_STREAM_SET_IN_AUDIO_LEVEL; request.uid = (struct mixart_uid){0,0}; request.data = &set_level; request.size = sizeof(set_level); err = snd_mixart_send_msg(chip->mgr, &request, sizeof(status), &status); if((err<0) || status) { dev_dbg(chip->card->dev, "error MSG_STREAM_SET_IN_AUDIO_LEVEL card(%d) status(%x)\n", chip->chip_idx, status); return -EINVAL; } return 0; } /* shared */ static int mixart_digital_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = MIXART_DIGITAL_LEVEL_MIN; /* -109.5 dB */ uinfo->value.integer.max = MIXART_DIGITAL_LEVEL_MAX; /* 18.0 dB */ return 0; } #define MIXART_VOL_REC_MASK 1 #define MIXART_VOL_AES_MASK 2 static int mixart_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ int *stored_volume; int is_capture = kcontrol->private_value & MIXART_VOL_REC_MASK; int is_aes = kcontrol->private_value & MIXART_VOL_AES_MASK; mutex_lock(&chip->mgr->mixer_mutex); if(is_capture) { if(is_aes) stored_volume = chip->digital_capture_volume[1]; /* AES capture */ else stored_volume = chip->digital_capture_volume[0]; /* analog capture */ } else { snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS); if(is_aes) stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; /* AES playback */ else stored_volume = chip->digital_playback_volume[idx]; /* analog playback */ } ucontrol->value.integer.value[0] = stored_volume[0]; ucontrol->value.integer.value[1] = stored_volume[1]; mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ int changed = 0; int is_capture = kcontrol->private_value & MIXART_VOL_REC_MASK; int is_aes = kcontrol->private_value & MIXART_VOL_AES_MASK; int* stored_volume; int i; mutex_lock(&chip->mgr->mixer_mutex); if (is_capture) { if (is_aes) /* AES capture */ stored_volume = chip->digital_capture_volume[1]; else /* analog capture */ stored_volume = chip->digital_capture_volume[0]; } else { snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS); if (is_aes) /* AES playback */ stored_volume = chip->digital_playback_volume[MIXART_PLAYBACK_STREAMS + idx]; else /* analog playback */ stored_volume = chip->digital_playback_volume[idx]; } for (i = 0; i < 2; i++) { int vol = ucontrol->value.integer.value[i]; if (vol < MIXART_DIGITAL_LEVEL_MIN || vol > MIXART_DIGITAL_LEVEL_MAX) continue; if (stored_volume[i] != vol) { stored_volume[i] = vol; changed = 1; } } if (changed) { if (is_capture) mixart_update_capture_stream_level(chip, is_aes); else mixart_update_playback_stream_level(chip, is_aes, idx); } mutex_unlock(&chip->mgr->mixer_mutex); return changed; } static const DECLARE_TLV_DB_SCALE(db_scale_digital, -10950, 50, 0); static const struct snd_kcontrol_new snd_mixart_pcm_vol = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), /* name will be filled later */ /* count will be filled later */ .info = mixart_digital_vol_info, /* shared */ .get = mixart_pcm_vol_get, .put = mixart_pcm_vol_put, .tlv = { .p = db_scale_digital }, }; static int mixart_pcm_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS); mutex_lock(&chip->mgr->mixer_mutex); if(kcontrol->private_value & MIXART_VOL_AES_MASK) /* AES playback */ idx += MIXART_PLAYBACK_STREAMS; ucontrol->value.integer.value[0] = chip->digital_playback_active[idx][0]; ucontrol->value.integer.value[1] = chip->digital_playback_active[idx][1]; mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int is_aes = kcontrol->private_value & MIXART_VOL_AES_MASK; int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); /* index */ int i, j; snd_BUG_ON(idx >= MIXART_PLAYBACK_STREAMS); mutex_lock(&chip->mgr->mixer_mutex); j = idx; if (is_aes) j += MIXART_PLAYBACK_STREAMS; for (i = 0; i < 2; i++) { if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) { chip->digital_playback_active[j][i] = !!ucontrol->value.integer.value[i]; changed = 1; } } if (changed) mixart_update_playback_stream_level(chip, is_aes, idx); mutex_unlock(&chip->mgr->mixer_mutex); return changed; } static const struct snd_kcontrol_new mixart_control_pcm_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, /* name will be filled later */ .count = MIXART_PLAYBACK_STREAMS, .info = mixart_sw_info, /* shared */ .get = mixart_pcm_sw_get, .put = mixart_pcm_sw_put }; static int mixart_update_monitoring(struct snd_mixart* chip, int channel) { int err; struct mixart_msg request; struct mixart_set_out_audio_level audio_level; u32 resp = 0; if(chip->pipe_out_ana.status == PIPE_UNDEFINED) return -EINVAL; /* no pipe defined */ if(!channel) request.uid = chip->pipe_out_ana.uid_left_connector; else request.uid = chip->pipe_out_ana.uid_right_connector; request.message_id = MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL; request.data = &audio_level; request.size = sizeof(audio_level); memset(&audio_level, 0, sizeof(audio_level)); audio_level.valid_mask1 = MIXART_AUDIO_LEVEL_MONITOR_MASK | MIXART_AUDIO_LEVEL_MUTE_M1_MASK; audio_level.monitor_level = mixart_digital_level[chip->monitoring_volume[channel!=0]]; audio_level.monitor_mute1 = !chip->monitoring_active[channel!=0]; err = snd_mixart_send_msg(chip->mgr, &request, sizeof(resp), &resp); if((err<0) || resp) { dev_dbg(chip->card->dev, "error MSG_CONNECTOR_SET_OUT_AUDIO_LEVEL card(%d) resp(%x)\n", chip->chip_idx, resp); return -EINVAL; } return 0; } /* * monitoring level control */ static int mixart_monitor_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); mutex_lock(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0] = chip->monitoring_volume[0]; ucontrol->value.integer.value[1] = chip->monitoring_volume[1]; mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_monitor_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int i; mutex_lock(&chip->mgr->mixer_mutex); for (i = 0; i < 2; i++) { if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) { chip->monitoring_volume[i] = !!ucontrol->value.integer.value[i]; mixart_update_monitoring(chip, i); changed = 1; } } mutex_unlock(&chip->mgr->mixer_mutex); return changed; } static const struct snd_kcontrol_new mixart_control_monitor_vol = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), .name = "Monitoring Volume", .info = mixart_digital_vol_info, /* shared */ .get = mixart_monitor_vol_get, .put = mixart_monitor_vol_put, .tlv = { .p = db_scale_digital }, }; /* * monitoring switch control */ static int mixart_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); mutex_lock(&chip->mgr->mixer_mutex); ucontrol->value.integer.value[0] = chip->monitoring_active[0]; ucontrol->value.integer.value[1] = chip->monitoring_active[1]; mutex_unlock(&chip->mgr->mixer_mutex); return 0; } static int mixart_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_mixart *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int i; mutex_lock(&chip->mgr->mixer_mutex); for (i = 0; i < 2; i++) { if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) { chip->monitoring_active[i] = !!ucontrol->value.integer.value[i]; changed |= (1<<i); /* mask 0x01 ans 0x02 */ } } if (changed) { /* allocate or release resources for monitoring */ int allocate = chip->monitoring_active[0] || chip->monitoring_active[1]; if (allocate) { /* allocate the playback pipe for monitoring */ snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 0, 1); /* allocate the capture pipe for monitoring */ snd_mixart_add_ref_pipe(chip, MIXART_PCM_ANALOG, 1, 1); } if (changed & 0x01) mixart_update_monitoring(chip, 0); if (changed & 0x02) mixart_update_monitoring(chip, 1); if (!allocate) { /* release the capture pipe for monitoring */ snd_mixart_kill_ref_pipe(chip->mgr, &chip->pipe_in_ana, 1); /* release the playback pipe for monitoring */ snd_mixart_kill_ref_pipe(chip->mgr, &chip->pipe_out_ana, 1); } } mutex_unlock(&chip->mgr->mixer_mutex); return (changed != 0); } static const struct snd_kcontrol_new mixart_control_monitor_sw = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Monitoring Switch", .info = mixart_sw_info, /* shared */ .get = mixart_monitor_sw_get, .put = mixart_monitor_sw_put }; static void mixart_reset_audio_levels(struct snd_mixart *chip) { /* analog volumes can be set even if there is no pipe */ mixart_update_analog_audio_level(chip, 0); /* analog levels for capture only on the first two chips */ if(chip->chip_idx < 2) { mixart_update_analog_audio_level(chip, 1); } return; } int snd_mixart_create_mixer(struct mixart_mgr *mgr) { struct snd_mixart *chip; int err, i; mutex_init(&mgr->mixer_mutex); /* can be in another place */ for(i=0; i<mgr->num_cards; i++) { struct snd_kcontrol_new temp; chip = mgr->chip[i]; /* analog output level control */ temp = mixart_control_analog_level; temp.name = "Master Playback Volume"; temp.private_value = 0; /* playback */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; /* output mute controls */ err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_output_switch, chip)); if (err < 0) return err; /* analog input level control only on first two chips !*/ if(i<2) { temp = mixart_control_analog_level; temp.name = "Master Capture Volume"; temp.private_value = 1; /* capture */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } temp = snd_mixart_pcm_vol; temp.name = "PCM Playback Volume"; temp.count = MIXART_PLAYBACK_STREAMS; temp.private_value = 0; /* playback analog */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; temp.name = "PCM Capture Volume"; temp.count = 1; temp.private_value = MIXART_VOL_REC_MASK; /* capture analog */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; if(mgr->board_type == MIXART_DAUGHTER_TYPE_AES) { temp.name = "AES Playback Volume"; temp.count = MIXART_PLAYBACK_STREAMS; temp.private_value = MIXART_VOL_AES_MASK; /* playback AES/EBU */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; temp.name = "AES Capture Volume"; temp.count = 0; temp.private_value = MIXART_VOL_REC_MASK | MIXART_VOL_AES_MASK; /* capture AES/EBU */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } temp = mixart_control_pcm_switch; temp.name = "PCM Playback Switch"; temp.private_value = 0; /* playback analog */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; if(mgr->board_type == MIXART_DAUGHTER_TYPE_AES) { temp.name = "AES Playback Switch"; temp.private_value = MIXART_VOL_AES_MASK; /* playback AES/EBU */ err = snd_ctl_add(chip->card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } /* monitoring */ err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_monitor_vol, chip)); if (err < 0) return err; err = snd_ctl_add(chip->card, snd_ctl_new1(&mixart_control_monitor_sw, chip)); if (err < 0) return err; /* init all mixer data and program the master volumes/switches */ mixart_reset_audio_levels(chip); } return 0; }
linux-master
sound/pci/mixart/mixart_mixer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * serial-generic.c * Copyright (c) by Daniel Kaehn <[email protected] * Based on serial-u16550.c by Jaroslav Kysela <[email protected]>, * Isaku Yamahata <[email protected]>, * George Hansper <[email protected]>, * Hannu Savolainen * * Generic serial MIDI driver using the serdev serial bus API for hardware interaction */ #include <linux/err.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/of.h> #include <linux/serdev.h> #include <linux/serial_reg.h> #include <linux/slab.h> #include <linux/dev_printk.h> #include <sound/core.h> #include <sound/rawmidi.h> #include <sound/initval.h> MODULE_DESCRIPTION("Generic serial MIDI driver"); MODULE_LICENSE("GPL"); #define SERIAL_MODE_INPUT_OPEN 1 #define SERIAL_MODE_OUTPUT_OPEN 2 #define SERIAL_MODE_INPUT_TRIGGERED 3 #define SERIAL_MODE_OUTPUT_TRIGGERED 4 #define SERIAL_TX_STATE_ACTIVE 1 #define SERIAL_TX_STATE_WAKEUP 2 struct snd_serial_generic { struct serdev_device *serdev; struct snd_card *card; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *midi_output; struct snd_rawmidi_substream *midi_input; unsigned int baudrate; unsigned long filemode; /* open status of file */ struct work_struct tx_work; unsigned long tx_state; }; static void snd_serial_generic_tx_wakeup(struct snd_serial_generic *drvdata) { if (test_and_set_bit(SERIAL_TX_STATE_ACTIVE, &drvdata->tx_state)) set_bit(SERIAL_TX_STATE_WAKEUP, &drvdata->tx_state); schedule_work(&drvdata->tx_work); } #define INTERNAL_BUF_SIZE 256 static void snd_serial_generic_tx_work(struct work_struct *work) { static char buf[INTERNAL_BUF_SIZE]; int num_bytes; struct snd_serial_generic *drvdata = container_of(work, struct snd_serial_generic, tx_work); struct snd_rawmidi_substream *substream = drvdata->midi_output; clear_bit(SERIAL_TX_STATE_WAKEUP, &drvdata->tx_state); while (!snd_rawmidi_transmit_empty(substream)) { if (!test_bit(SERIAL_MODE_OUTPUT_OPEN, &drvdata->filemode)) break; num_bytes = snd_rawmidi_transmit_peek(substream, buf, INTERNAL_BUF_SIZE); num_bytes = serdev_device_write_buf(drvdata->serdev, buf, num_bytes); if (!num_bytes) break; snd_rawmidi_transmit_ack(substream, num_bytes); if (!test_bit(SERIAL_TX_STATE_WAKEUP, &drvdata->tx_state)) break; } clear_bit(SERIAL_TX_STATE_ACTIVE, &drvdata->tx_state); } static void snd_serial_generic_write_wakeup(struct serdev_device *serdev) { struct snd_serial_generic *drvdata = serdev_device_get_drvdata(serdev); snd_serial_generic_tx_wakeup(drvdata); } static int snd_serial_generic_receive_buf(struct serdev_device *serdev, const unsigned char *buf, size_t count) { int ret; struct snd_serial_generic *drvdata = serdev_device_get_drvdata(serdev); if (!test_bit(SERIAL_MODE_INPUT_OPEN, &drvdata->filemode)) return 0; ret = snd_rawmidi_receive(drvdata->midi_input, buf, count); return ret < 0 ? 0 : ret; } static const struct serdev_device_ops snd_serial_generic_serdev_device_ops = { .receive_buf = snd_serial_generic_receive_buf, .write_wakeup = snd_serial_generic_write_wakeup }; static int snd_serial_generic_ensure_serdev_open(struct snd_serial_generic *drvdata) { int err; unsigned int actual_baud; if (drvdata->filemode) return 0; dev_dbg(drvdata->card->dev, "Opening serial port for card %s\n", drvdata->card->shortname); err = serdev_device_open(drvdata->serdev); if (err < 0) return err; actual_baud = serdev_device_set_baudrate(drvdata->serdev, drvdata->baudrate); if (actual_baud != drvdata->baudrate) { dev_warn(drvdata->card->dev, "requested %d baud for card %s but it was actually set to %d\n", drvdata->baudrate, drvdata->card->shortname, actual_baud); } return 0; } static int snd_serial_generic_input_open(struct snd_rawmidi_substream *substream) { int err; struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; dev_dbg(drvdata->card->dev, "Opening input for card %s\n", drvdata->card->shortname); err = snd_serial_generic_ensure_serdev_open(drvdata); if (err < 0) return err; set_bit(SERIAL_MODE_INPUT_OPEN, &drvdata->filemode); drvdata->midi_input = substream; return 0; } static int snd_serial_generic_input_close(struct snd_rawmidi_substream *substream) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; dev_dbg(drvdata->card->dev, "Closing input for card %s\n", drvdata->card->shortname); clear_bit(SERIAL_MODE_INPUT_OPEN, &drvdata->filemode); clear_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode); drvdata->midi_input = NULL; if (!drvdata->filemode) serdev_device_close(drvdata->serdev); return 0; } static void snd_serial_generic_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; if (up) set_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode); else clear_bit(SERIAL_MODE_INPUT_TRIGGERED, &drvdata->filemode); } static int snd_serial_generic_output_open(struct snd_rawmidi_substream *substream) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; int err; dev_dbg(drvdata->card->dev, "Opening output for card %s\n", drvdata->card->shortname); err = snd_serial_generic_ensure_serdev_open(drvdata); if (err < 0) return err; set_bit(SERIAL_MODE_OUTPUT_OPEN, &drvdata->filemode); drvdata->midi_output = substream; return 0; }; static int snd_serial_generic_output_close(struct snd_rawmidi_substream *substream) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; dev_dbg(drvdata->card->dev, "Closing output for card %s\n", drvdata->card->shortname); clear_bit(SERIAL_MODE_OUTPUT_OPEN, &drvdata->filemode); clear_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode); if (!drvdata->filemode) serdev_device_close(drvdata->serdev); drvdata->midi_output = NULL; return 0; }; static void snd_serial_generic_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; if (up) set_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode); else clear_bit(SERIAL_MODE_OUTPUT_TRIGGERED, &drvdata->filemode); if (up) snd_serial_generic_tx_wakeup(drvdata); } static void snd_serial_generic_output_drain(struct snd_rawmidi_substream *substream) { struct snd_serial_generic *drvdata = substream->rmidi->card->private_data; /* Flush any pending characters */ serdev_device_write_flush(drvdata->serdev); cancel_work_sync(&drvdata->tx_work); } static const struct snd_rawmidi_ops snd_serial_generic_output = { .open = snd_serial_generic_output_open, .close = snd_serial_generic_output_close, .trigger = snd_serial_generic_output_trigger, .drain = snd_serial_generic_output_drain, }; static const struct snd_rawmidi_ops snd_serial_generic_input = { .open = snd_serial_generic_input_open, .close = snd_serial_generic_input_close, .trigger = snd_serial_generic_input_trigger, }; static void snd_serial_generic_parse_dt(struct serdev_device *serdev, struct snd_serial_generic *drvdata) { int err; err = of_property_read_u32(serdev->dev.of_node, "current-speed", &drvdata->baudrate); if (err < 0) { dev_dbg(drvdata->card->dev, "MIDI device reading of current-speed DT param failed with error %d, using default of 38400\n", err); drvdata->baudrate = 38400; } } static void snd_serial_generic_substreams(struct snd_rawmidi_str *stream, int dev_num) { struct snd_rawmidi_substream *substream; list_for_each_entry(substream, &stream->substreams, list) { sprintf(substream->name, "Serial MIDI %d-%d", dev_num, substream->number); } } static int snd_serial_generic_rmidi(struct snd_serial_generic *drvdata, int outs, int ins, struct snd_rawmidi **rmidi) { struct snd_rawmidi *rrawmidi; int err; err = snd_rawmidi_new(drvdata->card, drvdata->card->driver, 0, outs, ins, &rrawmidi); if (err < 0) return err; snd_rawmidi_set_ops(rrawmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_serial_generic_input); snd_rawmidi_set_ops(rrawmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_serial_generic_output); strcpy(rrawmidi->name, drvdata->card->shortname); snd_serial_generic_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], drvdata->serdev->ctrl->nr); snd_serial_generic_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], drvdata->serdev->ctrl->nr); rrawmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; if (rmidi) *rmidi = rrawmidi; return 0; } static int snd_serial_generic_probe(struct serdev_device *serdev) { struct snd_card *card; struct snd_serial_generic *drvdata; int err; err = snd_devm_card_new(&serdev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, THIS_MODULE, sizeof(struct snd_serial_generic), &card); if (err < 0) return err; strcpy(card->driver, "SerialMIDI"); sprintf(card->shortname, "SerialMIDI-%d", serdev->ctrl->nr); sprintf(card->longname, "Serial MIDI device at serial%d", serdev->ctrl->nr); drvdata = card->private_data; drvdata->serdev = serdev; drvdata->card = card; snd_serial_generic_parse_dt(serdev, drvdata); INIT_WORK(&drvdata->tx_work, snd_serial_generic_tx_work); err = snd_serial_generic_rmidi(drvdata, 1, 1, &drvdata->rmidi); if (err < 0) return err; serdev_device_set_client_ops(serdev, &snd_serial_generic_serdev_device_ops); serdev_device_set_drvdata(drvdata->serdev, drvdata); err = snd_card_register(card); if (err < 0) return err; return 0; } static const struct of_device_id snd_serial_generic_dt_ids[] = { { .compatible = "serial-midi" }, {}, }; MODULE_DEVICE_TABLE(of, snd_serial_generic_dt_ids); static struct serdev_device_driver snd_serial_generic_driver = { .driver = { .name = "snd-serial-generic", .of_match_table = snd_serial_generic_dt_ids, }, .probe = snd_serial_generic_probe, }; module_serdev_device_driver(snd_serial_generic_driver);
linux-master
sound/drivers/serial-generic.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA Driver for Ego Systems Inc. (ESI) Miditerminal 4140 * Copyright (c) 2006 by Matthias König <[email protected]> */ #include <linux/init.h> #include <linux/platform_device.h> #include <linux/parport.h> #include <linux/spinlock.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/slab.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/rawmidi.h> #include <sound/control.h> #define CARD_NAME "Miditerminal 4140" #define DRIVER_NAME "MTS64" #define PLATFORM_DRIVER "snd_mts64" static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; static struct platform_device *platform_devices[SNDRV_CARDS]; static int device_count; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); MODULE_AUTHOR("Matthias Koenig <[email protected]>"); MODULE_DESCRIPTION("ESI Miditerminal 4140"); MODULE_LICENSE("GPL"); /********************************************************************* * Chip specific *********************************************************************/ #define MTS64_NUM_INPUT_PORTS 5 #define MTS64_NUM_OUTPUT_PORTS 4 #define MTS64_SMPTE_SUBSTREAM 4 struct mts64 { spinlock_t lock; struct snd_card *card; struct snd_rawmidi *rmidi; struct pardevice *pardev; int open_count; int current_midi_output_port; int current_midi_input_port; u8 mode[MTS64_NUM_INPUT_PORTS]; struct snd_rawmidi_substream *midi_input_substream[MTS64_NUM_INPUT_PORTS]; int smpte_switch; u8 time[4]; /* [0]=hh, [1]=mm, [2]=ss, [3]=ff */ u8 fps; }; static int snd_mts64_free(struct mts64 *mts) { kfree(mts); return 0; } static int snd_mts64_create(struct snd_card *card, struct pardevice *pardev, struct mts64 **rchip) { struct mts64 *mts; *rchip = NULL; mts = kzalloc(sizeof(struct mts64), GFP_KERNEL); if (mts == NULL) return -ENOMEM; /* Init chip specific data */ spin_lock_init(&mts->lock); mts->card = card; mts->pardev = pardev; mts->current_midi_output_port = -1; mts->current_midi_input_port = -1; *rchip = mts; return 0; } /********************************************************************* * HW register related constants *********************************************************************/ /* Status Bits */ #define MTS64_STAT_BSY 0x80 #define MTS64_STAT_BIT_SET 0x20 /* readout process, bit is set */ #define MTS64_STAT_PORT 0x10 /* read byte is a port number */ /* Control Bits */ #define MTS64_CTL_READOUT 0x08 /* enable readout */ #define MTS64_CTL_WRITE_CMD 0x06 #define MTS64_CTL_WRITE_DATA 0x02 #define MTS64_CTL_STROBE 0x01 /* Command */ #define MTS64_CMD_RESET 0xfe #define MTS64_CMD_PROBE 0x8f /* Used in probing procedure */ #define MTS64_CMD_SMPTE_SET_TIME 0xe8 #define MTS64_CMD_SMPTE_SET_FPS 0xee #define MTS64_CMD_SMPTE_STOP 0xef #define MTS64_CMD_SMPTE_FPS_24 0xe3 #define MTS64_CMD_SMPTE_FPS_25 0xe2 #define MTS64_CMD_SMPTE_FPS_2997 0xe4 #define MTS64_CMD_SMPTE_FPS_30D 0xe1 #define MTS64_CMD_SMPTE_FPS_30 0xe0 #define MTS64_CMD_COM_OPEN 0xf8 /* setting the communication mode */ #define MTS64_CMD_COM_CLOSE1 0xff /* clearing communication mode */ #define MTS64_CMD_COM_CLOSE2 0xf5 /********************************************************************* * Hardware specific functions *********************************************************************/ static void mts64_enable_readout(struct parport *p); static void mts64_disable_readout(struct parport *p); static int mts64_device_ready(struct parport *p); static int mts64_device_init(struct parport *p); static int mts64_device_open(struct mts64 *mts); static int mts64_device_close(struct mts64 *mts); static u8 mts64_map_midi_input(u8 c); static int mts64_probe(struct parport *p); static u16 mts64_read(struct parport *p); static u8 mts64_read_char(struct parport *p); static void mts64_smpte_start(struct parport *p, u8 hours, u8 minutes, u8 seconds, u8 frames, u8 idx); static void mts64_smpte_stop(struct parport *p); static void mts64_write_command(struct parport *p, u8 c); static void mts64_write_data(struct parport *p, u8 c); static void mts64_write_midi(struct mts64 *mts, u8 c, int midiport); /* Enables the readout procedure * * Before we can read a midi byte from the device, we have to set * bit 3 of control port. */ static void mts64_enable_readout(struct parport *p) { u8 c; c = parport_read_control(p); c |= MTS64_CTL_READOUT; parport_write_control(p, c); } /* Disables readout * * Readout is disabled by clearing bit 3 of control */ static void mts64_disable_readout(struct parport *p) { u8 c; c = parport_read_control(p); c &= ~MTS64_CTL_READOUT; parport_write_control(p, c); } /* waits for device ready * * Checks if BUSY (Bit 7 of status) is clear * 1 device ready * 0 failure */ static int mts64_device_ready(struct parport *p) { int i; u8 c; for (i = 0; i < 0xffff; ++i) { c = parport_read_status(p); c &= MTS64_STAT_BSY; if (c != 0) return 1; } return 0; } /* Init device (LED blinking startup magic) * * Returns: * 0 init ok * -EIO failure */ static int mts64_device_init(struct parport *p) { int i; mts64_write_command(p, MTS64_CMD_RESET); for (i = 0; i < 64; ++i) { msleep(100); if (mts64_probe(p) == 0) { /* success */ mts64_disable_readout(p); return 0; } } mts64_disable_readout(p); return -EIO; } /* * Opens the device (set communication mode) */ static int mts64_device_open(struct mts64 *mts) { int i; struct parport *p = mts->pardev->port; for (i = 0; i < 5; ++i) mts64_write_command(p, MTS64_CMD_COM_OPEN); return 0; } /* * Close device (clear communication mode) */ static int mts64_device_close(struct mts64 *mts) { int i; struct parport *p = mts->pardev->port; for (i = 0; i < 5; ++i) { mts64_write_command(p, MTS64_CMD_COM_CLOSE1); mts64_write_command(p, MTS64_CMD_COM_CLOSE2); } return 0; } /* map hardware port to substream number * * When reading a byte from the device, the device tells us * on what port the byte is. This HW port has to be mapped to * the midiport (substream number). * substream 0-3 are Midiports 1-4 * substream 4 is SMPTE Timecode * The mapping is done by the table: * HW | 0 | 1 | 2 | 3 | 4 * SW | 0 | 1 | 4 | 2 | 3 */ static u8 mts64_map_midi_input(u8 c) { static const u8 map[] = { 0, 1, 4, 2, 3 }; return map[c]; } /* Probe parport for device * * Do we have a Miditerminal 4140 on parport? * Returns: * 0 device found * -ENODEV no device */ static int mts64_probe(struct parport *p) { u8 c; mts64_smpte_stop(p); mts64_write_command(p, MTS64_CMD_PROBE); msleep(50); c = mts64_read(p); c &= 0x00ff; if (c != MTS64_CMD_PROBE) return -ENODEV; else return 0; } /* Read byte incl. status from device * * Returns: * data in lower 8 bits and status in upper 8 bits */ static u16 mts64_read(struct parport *p) { u8 data, status; mts64_device_ready(p); mts64_enable_readout(p); status = parport_read_status(p); data = mts64_read_char(p); mts64_disable_readout(p); return (status << 8) | data; } /* Read a byte from device * * Note, that readout mode has to be enabled. * readout procedure is as follows: * - Write number of the Bit to read to DATA * - Read STATUS * - Bit 5 of STATUS indicates if Bit is set * * Returns: * Byte read from device */ static u8 mts64_read_char(struct parport *p) { u8 c = 0; u8 status; u8 i; for (i = 0; i < 8; ++i) { parport_write_data(p, i); c >>= 1; status = parport_read_status(p); if (status & MTS64_STAT_BIT_SET) c |= 0x80; } return c; } /* Starts SMPTE Timecode generation * * The device creates SMPTE Timecode by hardware. * 0 24 fps * 1 25 fps * 2 29.97 fps * 3 30 fps (Drop-frame) * 4 30 fps */ static void mts64_smpte_start(struct parport *p, u8 hours, u8 minutes, u8 seconds, u8 frames, u8 idx) { static const u8 fps[5] = { MTS64_CMD_SMPTE_FPS_24, MTS64_CMD_SMPTE_FPS_25, MTS64_CMD_SMPTE_FPS_2997, MTS64_CMD_SMPTE_FPS_30D, MTS64_CMD_SMPTE_FPS_30 }; mts64_write_command(p, MTS64_CMD_SMPTE_SET_TIME); mts64_write_command(p, frames); mts64_write_command(p, seconds); mts64_write_command(p, minutes); mts64_write_command(p, hours); mts64_write_command(p, MTS64_CMD_SMPTE_SET_FPS); mts64_write_command(p, fps[idx]); } /* Stops SMPTE Timecode generation */ static void mts64_smpte_stop(struct parport *p) { mts64_write_command(p, MTS64_CMD_SMPTE_STOP); } /* Write a command byte to device */ static void mts64_write_command(struct parport *p, u8 c) { mts64_device_ready(p); parport_write_data(p, c); parport_write_control(p, MTS64_CTL_WRITE_CMD); parport_write_control(p, MTS64_CTL_WRITE_CMD | MTS64_CTL_STROBE); parport_write_control(p, MTS64_CTL_WRITE_CMD); } /* Write a data byte to device */ static void mts64_write_data(struct parport *p, u8 c) { mts64_device_ready(p); parport_write_data(p, c); parport_write_control(p, MTS64_CTL_WRITE_DATA); parport_write_control(p, MTS64_CTL_WRITE_DATA | MTS64_CTL_STROBE); parport_write_control(p, MTS64_CTL_WRITE_DATA); } /* Write a MIDI byte to midiport * * midiport ranges from 0-3 and maps to Ports 1-4 * assumptions: communication mode is on */ static void mts64_write_midi(struct mts64 *mts, u8 c, int midiport) { struct parport *p = mts->pardev->port; /* check current midiport */ if (mts->current_midi_output_port != midiport) mts64_write_command(p, midiport); /* write midi byte */ mts64_write_data(p, c); } /********************************************************************* * Control elements *********************************************************************/ /* SMPTE Switch */ #define snd_mts64_ctl_smpte_switch_info snd_ctl_boolean_mono_info static int snd_mts64_ctl_smpte_switch_get(struct snd_kcontrol* kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); spin_lock_irq(&mts->lock); uctl->value.integer.value[0] = mts->smpte_switch; spin_unlock_irq(&mts->lock); return 0; } /* smpte_switch is not accessed from IRQ handler, so we just need to protect the HW access */ static int snd_mts64_ctl_smpte_switch_put(struct snd_kcontrol* kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); int changed = 0; int val = !!uctl->value.integer.value[0]; spin_lock_irq(&mts->lock); if (mts->smpte_switch == val) goto __out; changed = 1; mts->smpte_switch = val; if (mts->smpte_switch) { mts64_smpte_start(mts->pardev->port, mts->time[0], mts->time[1], mts->time[2], mts->time[3], mts->fps); } else { mts64_smpte_stop(mts->pardev->port); } __out: spin_unlock_irq(&mts->lock); return changed; } static const struct snd_kcontrol_new mts64_ctl_smpte_switch = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Playback Switch", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = snd_mts64_ctl_smpte_switch_info, .get = snd_mts64_ctl_smpte_switch_get, .put = snd_mts64_ctl_smpte_switch_put }; /* Time */ static int snd_mts64_ctl_smpte_time_h_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 23; return 0; } static int snd_mts64_ctl_smpte_time_f_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 99; return 0; } static int snd_mts64_ctl_smpte_time_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 59; return 0; } static int snd_mts64_ctl_smpte_time_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); int idx = kctl->private_value; spin_lock_irq(&mts->lock); uctl->value.integer.value[0] = mts->time[idx]; spin_unlock_irq(&mts->lock); return 0; } static int snd_mts64_ctl_smpte_time_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); int idx = kctl->private_value; unsigned int time = uctl->value.integer.value[0] % 60; int changed = 0; spin_lock_irq(&mts->lock); if (mts->time[idx] != time) { changed = 1; mts->time[idx] = time; } spin_unlock_irq(&mts->lock); return changed; } static const struct snd_kcontrol_new mts64_ctl_smpte_time_hours = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Time Hours", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = snd_mts64_ctl_smpte_time_h_info, .get = snd_mts64_ctl_smpte_time_get, .put = snd_mts64_ctl_smpte_time_put }; static const struct snd_kcontrol_new mts64_ctl_smpte_time_minutes = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Time Minutes", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 1, .info = snd_mts64_ctl_smpte_time_info, .get = snd_mts64_ctl_smpte_time_get, .put = snd_mts64_ctl_smpte_time_put }; static const struct snd_kcontrol_new mts64_ctl_smpte_time_seconds = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Time Seconds", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 2, .info = snd_mts64_ctl_smpte_time_info, .get = snd_mts64_ctl_smpte_time_get, .put = snd_mts64_ctl_smpte_time_put }; static const struct snd_kcontrol_new mts64_ctl_smpte_time_frames = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Time Frames", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 3, .info = snd_mts64_ctl_smpte_time_f_info, .get = snd_mts64_ctl_smpte_time_get, .put = snd_mts64_ctl_smpte_time_put }; /* FPS */ static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo) { static const char * const texts[5] = { "24", "25", "29.97", "30D", "30" }; return snd_ctl_enum_info(uinfo, 1, 5, texts); } static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); spin_lock_irq(&mts->lock); uctl->value.enumerated.item[0] = mts->fps; spin_unlock_irq(&mts->lock); return 0; } static int snd_mts64_ctl_smpte_fps_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *uctl) { struct mts64 *mts = snd_kcontrol_chip(kctl); int changed = 0; if (uctl->value.enumerated.item[0] >= 5) return -EINVAL; spin_lock_irq(&mts->lock); if (mts->fps != uctl->value.enumerated.item[0]) { changed = 1; mts->fps = uctl->value.enumerated.item[0]; } spin_unlock_irq(&mts->lock); return changed; } static const struct snd_kcontrol_new mts64_ctl_smpte_fps = { .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, .name = "SMPTE Fps", .index = 0, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .private_value = 0, .info = snd_mts64_ctl_smpte_fps_info, .get = snd_mts64_ctl_smpte_fps_get, .put = snd_mts64_ctl_smpte_fps_put }; static int snd_mts64_ctl_create(struct snd_card *card, struct mts64 *mts) { int err, i; static const struct snd_kcontrol_new *control[] = { &mts64_ctl_smpte_switch, &mts64_ctl_smpte_time_hours, &mts64_ctl_smpte_time_minutes, &mts64_ctl_smpte_time_seconds, &mts64_ctl_smpte_time_frames, &mts64_ctl_smpte_fps, NULL }; for (i = 0; control[i]; ++i) { err = snd_ctl_add(card, snd_ctl_new1(control[i], mts)); if (err < 0) { snd_printd("Cannot create control: %s\n", control[i]->name); return err; } } return 0; } /********************************************************************* * Rawmidi *********************************************************************/ #define MTS64_MODE_INPUT_TRIGGERED 0x01 static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream) { struct mts64 *mts = substream->rmidi->private_data; if (mts->open_count == 0) { /* We don't need a spinlock here, because this is just called if the device has not been opened before. So there aren't any IRQs from the device */ mts64_device_open(mts); msleep(50); } ++(mts->open_count); return 0; } static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream) { struct mts64 *mts = substream->rmidi->private_data; unsigned long flags; --(mts->open_count); if (mts->open_count == 0) { /* We need the spinlock_irqsave here because we can still have IRQs at this point */ spin_lock_irqsave(&mts->lock, flags); mts64_device_close(mts); spin_unlock_irqrestore(&mts->lock, flags); msleep(500); } else if (mts->open_count < 0) mts->open_count = 0; return 0; } static void snd_mts64_rawmidi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct mts64 *mts = substream->rmidi->private_data; u8 data; unsigned long flags; spin_lock_irqsave(&mts->lock, flags); while (snd_rawmidi_transmit_peek(substream, &data, 1) == 1) { mts64_write_midi(mts, data, substream->number+1); snd_rawmidi_transmit_ack(substream, 1); } spin_unlock_irqrestore(&mts->lock, flags); } static void snd_mts64_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct mts64 *mts = substream->rmidi->private_data; unsigned long flags; spin_lock_irqsave(&mts->lock, flags); if (up) mts->mode[substream->number] |= MTS64_MODE_INPUT_TRIGGERED; else mts->mode[substream->number] &= ~MTS64_MODE_INPUT_TRIGGERED; spin_unlock_irqrestore(&mts->lock, flags); } static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = { .open = snd_mts64_rawmidi_open, .close = snd_mts64_rawmidi_close, .trigger = snd_mts64_rawmidi_output_trigger }; static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = { .open = snd_mts64_rawmidi_open, .close = snd_mts64_rawmidi_close, .trigger = snd_mts64_rawmidi_input_trigger }; /* Create and initialize the rawmidi component */ static int snd_mts64_rawmidi_create(struct snd_card *card) { struct mts64 *mts = card->private_data; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *substream; struct list_head *list; int err; err = snd_rawmidi_new(card, CARD_NAME, 0, MTS64_NUM_OUTPUT_PORTS, MTS64_NUM_INPUT_PORTS, &rmidi); if (err < 0) return err; rmidi->private_data = mts; strcpy(rmidi->name, CARD_NAME); rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; mts->rmidi = rmidi; /* register rawmidi ops */ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_mts64_rawmidi_output_ops); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_mts64_rawmidi_input_ops); /* name substreams */ /* output */ list_for_each(list, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) { substream = list_entry(list, struct snd_rawmidi_substream, list); sprintf(substream->name, "Miditerminal %d", substream->number+1); } /* input */ list_for_each(list, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) { substream = list_entry(list, struct snd_rawmidi_substream, list); mts->midi_input_substream[substream->number] = substream; switch(substream->number) { case MTS64_SMPTE_SUBSTREAM: strcpy(substream->name, "Miditerminal SMPTE"); break; default: sprintf(substream->name, "Miditerminal %d", substream->number+1); } } /* controls */ err = snd_mts64_ctl_create(card, mts); return err; } /********************************************************************* * parport stuff *********************************************************************/ static void snd_mts64_interrupt(void *private) { struct mts64 *mts = ((struct snd_card*)private)->private_data; u16 ret; u8 status, data; struct snd_rawmidi_substream *substream; if (!mts) return; spin_lock(&mts->lock); ret = mts64_read(mts->pardev->port); data = ret & 0x00ff; status = ret >> 8; if (status & MTS64_STAT_PORT) { mts->current_midi_input_port = mts64_map_midi_input(data); } else { if (mts->current_midi_input_port == -1) goto __out; substream = mts->midi_input_substream[mts->current_midi_input_port]; if (mts->mode[substream->number] & MTS64_MODE_INPUT_TRIGGERED) snd_rawmidi_receive(substream, &data, 1); } __out: spin_unlock(&mts->lock); } static void snd_mts64_attach(struct parport *p) { struct platform_device *device; device = platform_device_alloc(PLATFORM_DRIVER, device_count); if (!device) return; /* Temporary assignment to forward the parport */ platform_set_drvdata(device, p); if (platform_device_add(device) < 0) { platform_device_put(device); return; } /* Since we dont get the return value of probe * We need to check if device probing succeeded or not */ if (!platform_get_drvdata(device)) { platform_device_unregister(device); return; } /* register device in global table */ platform_devices[device_count] = device; device_count++; } static void snd_mts64_detach(struct parport *p) { /* nothing to do here */ } static int snd_mts64_dev_probe(struct pardevice *pardev) { if (strcmp(pardev->name, DRIVER_NAME)) return -ENODEV; return 0; } static struct parport_driver mts64_parport_driver = { .name = "mts64", .probe = snd_mts64_dev_probe, .match_port = snd_mts64_attach, .detach = snd_mts64_detach, .devmodel = true, }; /********************************************************************* * platform stuff *********************************************************************/ static void snd_mts64_card_private_free(struct snd_card *card) { struct mts64 *mts = card->private_data; struct pardevice *pardev = mts->pardev; if (pardev) { parport_release(pardev); parport_unregister_device(pardev); } snd_mts64_free(mts); } static int snd_mts64_probe(struct platform_device *pdev) { struct pardevice *pardev; struct parport *p; int dev = pdev->id; struct snd_card *card = NULL; struct mts64 *mts = NULL; int err; struct pardev_cb mts64_cb = { .preempt = NULL, .wakeup = NULL, .irq_func = snd_mts64_interrupt, /* ISR */ .flags = PARPORT_DEV_EXCL, /* flags */ }; p = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) return -ENOENT; err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE, 0, &card); if (err < 0) { snd_printd("Cannot create card\n"); return err; } strcpy(card->driver, DRIVER_NAME); strcpy(card->shortname, "ESI " CARD_NAME); sprintf(card->longname, "%s at 0x%lx, irq %i", card->shortname, p->base, p->irq); mts64_cb.private = card; /* private */ pardev = parport_register_dev_model(p, /* port */ DRIVER_NAME, /* name */ &mts64_cb, /* callbacks */ pdev->id); /* device number */ if (!pardev) { snd_printd("Cannot register pardevice\n"); err = -EIO; goto __err; } /* claim parport */ if (parport_claim(pardev)) { snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base); err = -EIO; goto free_pardev; } err = snd_mts64_create(card, pardev, &mts); if (err < 0) { snd_printd("Cannot create main component\n"); goto release_pardev; } card->private_data = mts; card->private_free = snd_mts64_card_private_free; err = mts64_probe(p); if (err) { err = -EIO; goto __err; } err = snd_mts64_rawmidi_create(card); if (err < 0) { snd_printd("Creating Rawmidi component failed\n"); goto __err; } /* init device */ err = mts64_device_init(p); if (err < 0) goto __err; platform_set_drvdata(pdev, card); /* At this point card will be usable */ err = snd_card_register(card); if (err < 0) { snd_printd("Cannot register card\n"); goto __err; } snd_printk(KERN_INFO "ESI Miditerminal 4140 on 0x%lx\n", p->base); return 0; release_pardev: parport_release(pardev); free_pardev: parport_unregister_device(pardev); __err: snd_card_free(card); return err; } static void snd_mts64_remove(struct platform_device *pdev) { struct snd_card *card = platform_get_drvdata(pdev); if (card) snd_card_free(card); } static struct platform_driver snd_mts64_driver = { .probe = snd_mts64_probe, .remove_new = snd_mts64_remove, .driver = { .name = PLATFORM_DRIVER, } }; /********************************************************************* * module init stuff *********************************************************************/ static void snd_mts64_unregister_all(void) { int i; for (i = 0; i < SNDRV_CARDS; ++i) { if (platform_devices[i]) { platform_device_unregister(platform_devices[i]); platform_devices[i] = NULL; } } platform_driver_unregister(&snd_mts64_driver); parport_unregister_driver(&mts64_parport_driver); } static int __init snd_mts64_module_init(void) { int err; err = platform_driver_register(&snd_mts64_driver); if (err < 0) return err; if (parport_register_driver(&mts64_parport_driver) != 0) { platform_driver_unregister(&snd_mts64_driver); return -EIO; } if (device_count == 0) { snd_mts64_unregister_all(); return -ENODEV; } return 0; } static void __exit snd_mts64_module_exit(void) { snd_mts64_unregister_all(); } module_init(snd_mts64_module_init); module_exit(snd_mts64_module_exit);
linux-master
sound/drivers/mts64.c
// SPDX-License-Identifier: GPL-2.0 /* * Virtual ALSA driver for PCM testing/fuzzing * * Copyright 2023 Ivan Orlov <[email protected]> * * This is a simple virtual ALSA driver, which can be used for audio applications/PCM middle layer * testing or fuzzing. * It can: * - Simulate 'playback' and 'capture' actions * - Generate random or pattern-based capture data * - Check playback buffer for containing looped template, and notify about the results * through the debugfs entry * - Inject delays into the playback and capturing processes. See 'inject_delay' parameter. * - Inject errors during the PCM callbacks. * - Register custom RESET ioctl and notify when it is called through the debugfs entry * - Work in interleaved and non-interleaved modes * - Support up to 8 substreams * - Support up to 4 channels * - Support framerates from 8 kHz to 48 kHz * * When driver works in the capture mode with multiple channels, it duplicates the looped * pattern to each separate channel. For example, if we have 2 channels, format = U8, interleaved * access mode and pattern 'abacaba', the DMA buffer will look like aabbccaabbaaaa..., so buffer for * each channel will contain abacabaabacaba... Same for the non-interleaved mode. * * However, it may break the capturing on the higher framerates with small period size, so it is * better to choose larger period sizes. * * You can find the corresponding selftest in the 'alsa' selftests folder. */ #include <linux/module.h> #include <linux/init.h> #include <sound/pcm.h> #include <sound/core.h> #include <linux/dma-mapping.h> #include <linux/platform_device.h> #include <linux/timer.h> #include <linux/random.h> #include <linux/debugfs.h> #include <linux/delay.h> #define TIMER_PER_SEC 5 #define TIMER_INTERVAL (HZ / TIMER_PER_SEC) #define DELAY_JIFFIES HZ #define PLAYBACK_SUBSTREAM_CNT 8 #define CAPTURE_SUBSTREAM_CNT 8 #define MAX_CHANNELS_NUM 4 #define DEFAULT_PATTERN "abacaba" #define DEFAULT_PATTERN_LEN 7 #define FILL_MODE_RAND 0 #define FILL_MODE_PAT 1 #define MAX_PATTERN_LEN 4096 static int index = -1; static char *id = "pcmtest"; static bool enable = true; static int inject_delay; static bool inject_hwpars_err; static bool inject_prepare_err; static bool inject_trigger_err; static bool inject_open_err; static short fill_mode = FILL_MODE_PAT; static u8 playback_capture_test; static u8 ioctl_reset_test; static struct dentry *driver_debug_dir; module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for pcmtest soundcard"); module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for pcmtest soundcard"); module_param(enable, bool, 0444); MODULE_PARM_DESC(enable, "Enable pcmtest soundcard."); module_param(fill_mode, short, 0600); MODULE_PARM_DESC(fill_mode, "Buffer fill mode: rand(0) or pattern(1)"); module_param(inject_delay, int, 0600); MODULE_PARM_DESC(inject_delay, "Inject delays during playback/capture (in jiffies)"); module_param(inject_hwpars_err, bool, 0600); MODULE_PARM_DESC(inject_hwpars_err, "Inject EBUSY error in the 'hw_params' callback"); module_param(inject_prepare_err, bool, 0600); MODULE_PARM_DESC(inject_prepare_err, "Inject EINVAL error in the 'prepare' callback"); module_param(inject_trigger_err, bool, 0600); MODULE_PARM_DESC(inject_trigger_err, "Inject EINVAL error in the 'trigger' callback"); module_param(inject_open_err, bool, 0600); MODULE_PARM_DESC(inject_open_err, "Inject EBUSY error in the 'open' callback"); struct pcmtst { struct snd_pcm *pcm; struct snd_card *card; struct platform_device *pdev; }; struct pcmtst_buf_iter { size_t buf_pos; // position in the DMA buffer size_t period_pos; // period-relative position size_t b_rw; // Bytes to write on every timer tick size_t s_rw_ch; // Samples to write to one channel on every tick unsigned int sample_bytes; // sample_bits / 8 bool is_buf_corrupted; // playback test result indicator size_t period_bytes; // bytes in a one period bool interleaved; // Interleaved/Non-interleaved mode size_t total_bytes; // Total bytes read/written size_t chan_block; // Bytes in one channel buffer when non-interleaved struct snd_pcm_substream *substream; bool suspend; // We need to pause timer without shutting it down struct timer_list timer_instance; }; static struct snd_pcm_hardware snd_pcmtst_hw = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_NONINTERLEAVED | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE), .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_8000_48000, .rate_min = 8000, .rate_max = 48000, .channels_min = 1, .channels_max = MAX_CHANNELS_NUM, .buffer_bytes_max = 128 * 1024, .period_bytes_min = 4096, .period_bytes_max = 32768, .periods_min = 1, .periods_max = 1024, }; struct pattern_buf { char *buf; u32 len; }; static int buf_allocated; static struct pattern_buf patt_bufs[MAX_CHANNELS_NUM]; static inline void inc_buf_pos(struct pcmtst_buf_iter *v_iter, size_t by, size_t bytes) { v_iter->total_bytes += by; v_iter->buf_pos += by; if (v_iter->buf_pos >= bytes) v_iter->buf_pos %= bytes; } /* * Position in the DMA buffer when we are in the non-interleaved mode. We increment buf_pos * every time we write a byte to any channel, so the position in the current channel buffer is * (position in the DMA buffer) / count_of_channels + size_of_channel_buf * current_channel */ static inline size_t buf_pos_n(struct pcmtst_buf_iter *v_iter, unsigned int channels, unsigned int chan_num) { return v_iter->buf_pos / channels + v_iter->chan_block * chan_num; } /* * Get the count of bytes written for the current channel in the interleaved mode. * This is (count of samples written for the current channel) * bytes_in_sample + * (relative position in the current sample) */ static inline size_t ch_pos_i(size_t b_total, unsigned int channels, unsigned int b_sample) { return b_total / channels / b_sample * b_sample + (b_total % b_sample); } static void check_buf_block_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { size_t i; short ch_num; u8 current_byte; for (i = 0; i < v_iter->b_rw; i++) { current_byte = runtime->dma_area[v_iter->buf_pos]; if (!current_byte) break; ch_num = (v_iter->total_bytes / v_iter->sample_bytes) % runtime->channels; if (current_byte != patt_bufs[ch_num].buf[ch_pos_i(v_iter->total_bytes, runtime->channels, v_iter->sample_bytes) % patt_bufs[ch_num].len]) { v_iter->is_buf_corrupted = true; break; } inc_buf_pos(v_iter, 1, runtime->dma_bytes); } // If we broke during the loop, add remaining bytes to the buffer position. inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes); } static void check_buf_block_ni(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { unsigned int channels = runtime->channels; size_t i; short ch_num; u8 current_byte; for (i = 0; i < v_iter->b_rw; i++) { ch_num = i % channels; current_byte = runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)]; if (!current_byte) break; if (current_byte != patt_bufs[ch_num].buf[(v_iter->total_bytes / channels) % patt_bufs[ch_num].len]) { v_iter->is_buf_corrupted = true; break; } inc_buf_pos(v_iter, 1, runtime->dma_bytes); } inc_buf_pos(v_iter, v_iter->b_rw - i, runtime->dma_bytes); } /* * Check one block of the buffer. Here we iterate the buffer until we find '0'. This condition is * necessary because we need to detect when the reading/writing ends, so we assume that the pattern * doesn't contain zeros. */ static void check_buf_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { if (v_iter->interleaved) check_buf_block_i(v_iter, runtime); else check_buf_block_ni(v_iter, runtime); } /* * Fill buffer in the non-interleaved mode. The order of samples is C0, ..., C0, C1, ..., C1, C2... * The channel buffers lay in the DMA buffer continuously (see default copy * handlers in the pcm_lib.c file). * * Here we increment the DMA buffer position every time we write a byte to any channel 'buffer'. * We need this to simulate the correct hardware pointer moving. */ static void fill_block_pattern_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { size_t i; unsigned int channels = runtime->channels; short ch_num; for (i = 0; i < v_iter->b_rw; i++) { ch_num = i % channels; runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)] = patt_bufs[ch_num].buf[(v_iter->total_bytes / channels) % patt_bufs[ch_num].len]; inc_buf_pos(v_iter, 1, runtime->dma_bytes); } } // Fill buffer in the interleaved mode. The order of samples is C0, C1, C2, C0, C1, C2, ... static void fill_block_pattern_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { size_t sample; size_t pos_in_ch, pos_pattern; short ch, pos_sample; pos_in_ch = ch_pos_i(v_iter->total_bytes, runtime->channels, v_iter->sample_bytes); for (sample = 0; sample < v_iter->s_rw_ch; sample++) { for (ch = 0; ch < runtime->channels; ch++) { for (pos_sample = 0; pos_sample < v_iter->sample_bytes; pos_sample++) { pos_pattern = (pos_in_ch + sample * v_iter->sample_bytes + pos_sample) % patt_bufs[ch].len; runtime->dma_area[v_iter->buf_pos] = patt_bufs[ch].buf[pos_pattern]; inc_buf_pos(v_iter, 1, runtime->dma_bytes); } } } } static void fill_block_pattern(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { if (v_iter->interleaved) fill_block_pattern_i(v_iter, runtime); else fill_block_pattern_n(v_iter, runtime); } static void fill_block_rand_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { unsigned int channels = runtime->channels; // Remaining space in all channel buffers size_t bytes_remain = runtime->dma_bytes - v_iter->buf_pos; unsigned int i; for (i = 0; i < channels; i++) { if (v_iter->b_rw <= bytes_remain) { //b_rw - count of bytes must be written for all channels at each timer tick get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i), v_iter->b_rw / channels); } else { // Write to the end of buffer and start from the beginning of it get_random_bytes(runtime->dma_area + buf_pos_n(v_iter, channels, i), bytes_remain / channels); get_random_bytes(runtime->dma_area + v_iter->chan_block * i, (v_iter->b_rw - bytes_remain) / channels); } } inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes); } static void fill_block_rand_i(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { size_t in_cur_block = runtime->dma_bytes - v_iter->buf_pos; if (v_iter->b_rw <= in_cur_block) { get_random_bytes(&runtime->dma_area[v_iter->buf_pos], v_iter->b_rw); } else { get_random_bytes(&runtime->dma_area[v_iter->buf_pos], in_cur_block); get_random_bytes(runtime->dma_area, v_iter->b_rw - in_cur_block); } inc_buf_pos(v_iter, v_iter->b_rw, runtime->dma_bytes); } static void fill_block_random(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { if (v_iter->interleaved) fill_block_rand_i(v_iter, runtime); else fill_block_rand_n(v_iter, runtime); } static void fill_block(struct pcmtst_buf_iter *v_iter, struct snd_pcm_runtime *runtime) { switch (fill_mode) { case FILL_MODE_RAND: fill_block_random(v_iter, runtime); break; case FILL_MODE_PAT: fill_block_pattern(v_iter, runtime); break; } } /* * Here we iterate through the buffer by (buffer_size / iterates_per_second) bytes. * The driver uses timer to simulate the hardware pointer moving, and notify the PCM middle layer * about period elapsed. */ static void timer_timeout(struct timer_list *data) { struct pcmtst_buf_iter *v_iter; struct snd_pcm_substream *substream; v_iter = from_timer(v_iter, data, timer_instance); substream = v_iter->substream; if (v_iter->suspend) return; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !v_iter->is_buf_corrupted) check_buf_block(v_iter, substream->runtime); else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) fill_block(v_iter, substream->runtime); else inc_buf_pos(v_iter, v_iter->b_rw, substream->runtime->dma_bytes); v_iter->period_pos += v_iter->b_rw; if (v_iter->period_pos >= v_iter->period_bytes) { v_iter->period_pos %= v_iter->period_bytes; snd_pcm_period_elapsed(substream); } if (!v_iter->suspend) mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL + inject_delay); } static int snd_pcmtst_pcm_open(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct pcmtst_buf_iter *v_iter; if (inject_open_err) return -EBUSY; v_iter = kzalloc(sizeof(*v_iter), GFP_KERNEL); if (!v_iter) return -ENOMEM; v_iter->substream = substream; runtime->hw = snd_pcmtst_hw; runtime->private_data = v_iter; playback_capture_test = 0; ioctl_reset_test = 0; timer_setup(&v_iter->timer_instance, timer_timeout, 0); return 0; } static int snd_pcmtst_pcm_close(struct snd_pcm_substream *substream) { struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; timer_shutdown_sync(&v_iter->timer_instance); v_iter->substream = NULL; playback_capture_test = !v_iter->is_buf_corrupted; kfree(v_iter); return 0; } static inline void reset_buf_iterator(struct pcmtst_buf_iter *v_iter) { v_iter->buf_pos = 0; v_iter->is_buf_corrupted = false; v_iter->period_pos = 0; v_iter->total_bytes = 0; } static inline void start_pcmtest_timer(struct pcmtst_buf_iter *v_iter) { v_iter->suspend = false; mod_timer(&v_iter->timer_instance, jiffies + TIMER_INTERVAL); } static int snd_pcmtst_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; if (inject_trigger_err) return -EINVAL; switch (cmd) { case SNDRV_PCM_TRIGGER_START: reset_buf_iterator(v_iter); start_pcmtest_timer(v_iter); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: start_pcmtest_timer(v_iter); break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_PAUSE_PUSH: // We can't call timer_shutdown_sync here, as it is forbidden to sleep here v_iter->suspend = true; break; } return 0; } static snd_pcm_uframes_t snd_pcmtst_pcm_pointer(struct snd_pcm_substream *substream) { struct pcmtst_buf_iter *v_iter = substream->runtime->private_data; return bytes_to_frames(substream->runtime, v_iter->buf_pos); } static int snd_pcmtst_free(struct pcmtst *pcmtst) { if (!pcmtst) return 0; kfree(pcmtst); return 0; } // These callbacks are required, but empty - all freeing occurs in pdev_remove static int snd_pcmtst_dev_free(struct snd_device *device) { return 0; } static void pcmtst_pdev_release(struct device *dev) { } static int snd_pcmtst_pcm_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct pcmtst_buf_iter *v_iter = runtime->private_data; if (inject_prepare_err) return -EINVAL; v_iter->sample_bytes = samples_to_bytes(runtime, 1); v_iter->period_bytes = snd_pcm_lib_period_bytes(substream); v_iter->interleaved = true; if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED || runtime->access == SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED) { v_iter->chan_block = snd_pcm_lib_buffer_bytes(substream) / runtime->channels; v_iter->interleaved = false; } // We want to record RATE * ch_cnt samples per sec, it is rate * sample_bytes * ch_cnt bytes v_iter->s_rw_ch = runtime->rate / TIMER_PER_SEC; v_iter->b_rw = v_iter->s_rw_ch * v_iter->sample_bytes * runtime->channels; return 0; } static int snd_pcmtst_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { if (inject_hwpars_err) return -EBUSY; return 0; } static int snd_pcmtst_pcm_hw_free(struct snd_pcm_substream *substream) { return 0; } static int snd_pcmtst_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { switch (cmd) { case SNDRV_PCM_IOCTL1_RESET: ioctl_reset_test = 1; break; } return snd_pcm_lib_ioctl(substream, cmd, arg); } static const struct snd_pcm_ops snd_pcmtst_playback_ops = { .open = snd_pcmtst_pcm_open, .close = snd_pcmtst_pcm_close, .trigger = snd_pcmtst_pcm_trigger, .hw_params = snd_pcmtst_pcm_hw_params, .ioctl = snd_pcmtst_ioctl, .hw_free = snd_pcmtst_pcm_hw_free, .prepare = snd_pcmtst_pcm_prepare, .pointer = snd_pcmtst_pcm_pointer, }; static const struct snd_pcm_ops snd_pcmtst_capture_ops = { .open = snd_pcmtst_pcm_open, .close = snd_pcmtst_pcm_close, .trigger = snd_pcmtst_pcm_trigger, .hw_params = snd_pcmtst_pcm_hw_params, .hw_free = snd_pcmtst_pcm_hw_free, .ioctl = snd_pcmtst_ioctl, .prepare = snd_pcmtst_pcm_prepare, .pointer = snd_pcmtst_pcm_pointer, }; static int snd_pcmtst_new_pcm(struct pcmtst *pcmtst) { struct snd_pcm *pcm; int err; err = snd_pcm_new(pcmtst->card, "PCMTest", 0, PLAYBACK_SUBSTREAM_CNT, CAPTURE_SUBSTREAM_CNT, &pcm); if (err < 0) return err; pcm->private_data = pcmtst; strcpy(pcm->name, "PCMTest"); pcmtst->pcm = pcm; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_pcmtst_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_pcmtst_capture_ops); err = snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &pcmtst->pdev->dev, 0, 128 * 1024); return err; } static int snd_pcmtst_create(struct snd_card *card, struct platform_device *pdev, struct pcmtst **r_pcmtst) { struct pcmtst *pcmtst; int err; static const struct snd_device_ops ops = { .dev_free = snd_pcmtst_dev_free, }; pcmtst = kzalloc(sizeof(*pcmtst), GFP_KERNEL); if (!pcmtst) return -ENOMEM; pcmtst->card = card; pcmtst->pdev = pdev; err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pcmtst, &ops); if (err < 0) goto _err_free_chip; err = snd_pcmtst_new_pcm(pcmtst); if (err < 0) goto _err_free_chip; *r_pcmtst = pcmtst; return 0; _err_free_chip: snd_pcmtst_free(pcmtst); return err; } static int pcmtst_probe(struct platform_device *pdev) { struct snd_card *card; struct pcmtst *pcmtst; int err; err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); if (err) return err; err = snd_devm_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card); if (err < 0) return err; err = snd_pcmtst_create(card, pdev, &pcmtst); if (err < 0) return err; strcpy(card->driver, "PCM-TEST Driver"); strcpy(card->shortname, "PCM-Test"); strcpy(card->longname, "PCM-Test virtual driver"); err = snd_card_register(card); if (err < 0) return err; platform_set_drvdata(pdev, pcmtst); return 0; } static void pdev_remove(struct platform_device *pdev) { struct pcmtst *pcmtst = platform_get_drvdata(pdev); snd_pcmtst_free(pcmtst); } static struct platform_device pcmtst_pdev = { .name = "pcmtest", .dev.release = pcmtst_pdev_release, }; static struct platform_driver pcmtst_pdrv = { .probe = pcmtst_probe, .remove_new = pdev_remove, .driver = { .name = "pcmtest", }, }; static ssize_t pattern_write(struct file *file, const char __user *u_buff, size_t len, loff_t *off) { struct pattern_buf *patt_buf = file->f_inode->i_private; ssize_t to_write = len; if (*off + to_write > MAX_PATTERN_LEN) to_write = MAX_PATTERN_LEN - *off; // Crop silently everything over the buffer if (to_write <= 0) return len; if (copy_from_user(patt_buf->buf + *off, u_buff, to_write)) return -EFAULT; patt_buf->len = *off + to_write; *off += to_write; return to_write; } static ssize_t pattern_read(struct file *file, char __user *u_buff, size_t len, loff_t *off) { struct pattern_buf *patt_buf = file->f_inode->i_private; ssize_t to_read = len; if (*off + to_read >= MAX_PATTERN_LEN) to_read = MAX_PATTERN_LEN - *off; if (to_read <= 0) return 0; if (copy_to_user(u_buff, patt_buf->buf + *off, to_read)) to_read = 0; else *off += to_read; return to_read; } static const struct file_operations fill_pattern_fops = { .read = pattern_read, .write = pattern_write, }; static int setup_patt_bufs(void) { size_t i; for (i = 0; i < ARRAY_SIZE(patt_bufs); i++) { patt_bufs[i].buf = kzalloc(MAX_PATTERN_LEN, GFP_KERNEL); if (!patt_bufs[i].buf) break; strcpy(patt_bufs[i].buf, DEFAULT_PATTERN); patt_bufs[i].len = DEFAULT_PATTERN_LEN; } return i; } static const char * const pattern_files[] = { "fill_pattern0", "fill_pattern1", "fill_pattern2", "fill_pattern3"}; static int init_debug_files(int buf_count) { size_t i; char len_file_name[32]; driver_debug_dir = debugfs_create_dir("pcmtest", NULL); if (IS_ERR(driver_debug_dir)) return PTR_ERR(driver_debug_dir); debugfs_create_u8("pc_test", 0444, driver_debug_dir, &playback_capture_test); debugfs_create_u8("ioctl_test", 0444, driver_debug_dir, &ioctl_reset_test); for (i = 0; i < buf_count; i++) { debugfs_create_file(pattern_files[i], 0600, driver_debug_dir, &patt_bufs[i], &fill_pattern_fops); snprintf(len_file_name, sizeof(len_file_name), "%s_len", pattern_files[i]); debugfs_create_u32(len_file_name, 0444, driver_debug_dir, &patt_bufs[i].len); } return 0; } static void free_pattern_buffers(void) { int i; for (i = 0; i < buf_allocated; i++) kfree(patt_bufs[i].buf); } static void clear_debug_files(void) { debugfs_remove_recursive(driver_debug_dir); } static int __init mod_init(void) { int err = 0; buf_allocated = setup_patt_bufs(); if (!buf_allocated) return -ENOMEM; snd_pcmtst_hw.channels_max = buf_allocated; err = init_debug_files(buf_allocated); if (err) return err; err = platform_device_register(&pcmtst_pdev); if (err) return err; err = platform_driver_register(&pcmtst_pdrv); if (err) platform_device_unregister(&pcmtst_pdev); return err; } static void __exit mod_exit(void) { clear_debug_files(); free_pattern_buffers(); platform_driver_unregister(&pcmtst_pdrv); platform_device_unregister(&pcmtst_pdev); } MODULE_LICENSE("GPL"); MODULE_AUTHOR("Ivan Orlov"); module_init(mod_init); module_exit(mod_exit);
linux-master
sound/drivers/pcmtest.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * MOTU Midi Timepiece ALSA Main routines * Copyright by Michael T. Mayers (c) Jan 09, 2000 * mail: [email protected] * Thanks to John Galbraith * * This driver is for the 'Mark Of The Unicorn' (MOTU) * MidiTimePiece AV multiport MIDI interface * * IOPORTS * ------- * 8 MIDI Ins and 8 MIDI outs * Video Sync In (BNC), Word Sync Out (BNC), * ADAT Sync Out (DB9) * SMPTE in/out (1/4") * 2 programmable pedal/footswitch inputs and 4 programmable MIDI controller knobs. * Macintosh RS422 serial port * RS422 "network" port for ganging multiple MTP's * PC Parallel Port ( which this driver currently uses ) * * MISC FEATURES * ------------- * Hardware MIDI routing, merging, and filtering * MIDI Synchronization to Video, ADAT, SMPTE and other Clock sources * 128 'scene' memories, recallable from MIDI program change * * ChangeLog * Jun 11 2001 Takashi Iwai <[email protected]> * - Recoded & debugged * - Added timer interrupt for midi outputs * - hwports is between 1 and 8, which specifies the number of hardware ports. * The three global ports, computer, adat and broadcast ports, are created * always after h/w and remote ports. */ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/ioport.h> #include <linux/io.h> #include <linux/moduleparam.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/rawmidi.h> #include <linux/delay.h> /* * globals */ MODULE_AUTHOR("Michael T. Mayers"); MODULE_DESCRIPTION("MOTU MidiTimePiece AV multiport MIDI"); MODULE_LICENSE("GPL"); // io resources #define MTPAV_IOBASE 0x378 #define MTPAV_IRQ 7 #define MTPAV_MAX_PORTS 8 static int index = SNDRV_DEFAULT_IDX1; static char *id = SNDRV_DEFAULT_STR1; static long port = MTPAV_IOBASE; /* 0x378, 0x278 */ static int irq = MTPAV_IRQ; /* 7, 5 */ static int hwports = MTPAV_MAX_PORTS; /* use hardware ports 1-8 */ module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for MotuMTPAV MIDI."); module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for MotuMTPAV MIDI."); module_param_hw(port, long, ioport, 0444); MODULE_PARM_DESC(port, "Parallel port # for MotuMTPAV MIDI."); module_param_hw(irq, int, irq, 0444); MODULE_PARM_DESC(irq, "Parallel IRQ # for MotuMTPAV MIDI."); module_param(hwports, int, 0444); MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI."); static struct platform_device *device; /* * defines */ //#define USE_FAKE_MTP // don't actually read/write to MTP device (for debugging without an actual unit) (does not work yet) // parallel port usage masks #define SIGS_BYTE 0x08 #define SIGS_RFD 0x80 #define SIGS_IRQ 0x40 #define SIGS_IN0 0x10 #define SIGS_IN1 0x20 #define SIGC_WRITE 0x04 #define SIGC_READ 0x08 #define SIGC_INTEN 0x10 #define DREG 0 #define SREG 1 #define CREG 2 // #define MTPAV_MODE_INPUT_OPENED 0x01 #define MTPAV_MODE_OUTPUT_OPENED 0x02 #define MTPAV_MODE_INPUT_TRIGGERED 0x04 #define MTPAV_MODE_OUTPUT_TRIGGERED 0x08 #define NUMPORTS (0x12+1) /* */ struct mtpav_port { u8 number; u8 hwport; u8 mode; u8 running_status; struct snd_rawmidi_substream *input; struct snd_rawmidi_substream *output; }; struct mtpav { struct snd_card *card; unsigned long port; struct resource *res_port; int irq; /* interrupt (for inputs) */ spinlock_t spinlock; int share_irq; /* number of accesses to input interrupts */ int istimer; /* number of accesses to timer interrupts */ struct timer_list timer; /* timer interrupts for outputs */ struct snd_rawmidi *rmidi; int num_ports; /* number of hw ports (1-8) */ struct mtpav_port ports[NUMPORTS]; /* all ports including computer, adat and bc */ u32 inmidiport; /* selected input midi port */ u32 inmidistate; /* during midi command 0xf5 */ u32 outmidihwport; /* selected output midi hw port */ }; /* * possible hardware ports (selected by 0xf5 port message) * 0x00 all ports * 0x01 .. 0x08 this MTP's ports 1..8 * 0x09 .. 0x10 networked MTP's ports (9..16) * 0x11 networked MTP's computer port * 0x63 to ADAT * * mappig: * subdevice 0 - (X-1) ports * X - (2*X-1) networked ports * X computer * X+1 ADAT * X+2 all ports * * where X = chip->num_ports */ #define MTPAV_PIDX_COMPUTER 0 #define MTPAV_PIDX_ADAT 1 #define MTPAV_PIDX_BROADCAST 2 static int translate_subdevice_to_hwport(struct mtpav *chip, int subdev) { if (subdev < 0) return 0x01; /* invalid - use port 0 as default */ else if (subdev < chip->num_ports) return subdev + 1; /* single mtp port */ else if (subdev < chip->num_ports * 2) return subdev - chip->num_ports + 0x09; /* remote port */ else if (subdev == chip->num_ports * 2 + MTPAV_PIDX_COMPUTER) return 0x11; /* computer port */ else if (subdev == chip->num_ports + MTPAV_PIDX_ADAT) return 0x63; /* ADAT */ return 0; /* all ports */ } static int translate_hwport_to_subdevice(struct mtpav *chip, int hwport) { int p; if (hwport <= 0x00) /* all ports */ return chip->num_ports + MTPAV_PIDX_BROADCAST; else if (hwport <= 0x08) { /* single port */ p = hwport - 1; if (p >= chip->num_ports) p = 0; return p; } else if (hwport <= 0x10) { /* remote port */ p = hwport - 0x09 + chip->num_ports; if (p >= chip->num_ports * 2) p = chip->num_ports; return p; } else if (hwport == 0x11) /* computer port */ return chip->num_ports + MTPAV_PIDX_COMPUTER; else /* ADAT */ return chip->num_ports + MTPAV_PIDX_ADAT; } /* */ static u8 snd_mtpav_getreg(struct mtpav *chip, u16 reg) { u8 rval = 0; if (reg == SREG) { rval = inb(chip->port + SREG); rval = (rval & 0xf8); } else if (reg == CREG) { rval = inb(chip->port + CREG); rval = (rval & 0x1c); } return rval; } /* */ static inline void snd_mtpav_mputreg(struct mtpav *chip, u16 reg, u8 val) { if (reg == DREG || reg == CREG) outb(val, chip->port + reg); } /* */ static void snd_mtpav_wait_rfdhi(struct mtpav *chip) { int counts = 10000; u8 sbyte; sbyte = snd_mtpav_getreg(chip, SREG); while (!(sbyte & SIGS_RFD) && counts--) { sbyte = snd_mtpav_getreg(chip, SREG); udelay(10); } } static void snd_mtpav_send_byte(struct mtpav *chip, u8 byte) { u8 tcbyt; u8 clrwrite; u8 setwrite; snd_mtpav_wait_rfdhi(chip); ///////////////// tcbyt = snd_mtpav_getreg(chip, CREG); clrwrite = tcbyt & (SIGC_WRITE ^ 0xff); setwrite = tcbyt | SIGC_WRITE; snd_mtpav_mputreg(chip, DREG, byte); snd_mtpav_mputreg(chip, CREG, clrwrite); // clear write bit snd_mtpav_mputreg(chip, CREG, setwrite); // set write bit } /* */ /* call this with spin lock held */ static void snd_mtpav_output_port_write(struct mtpav *mtp_card, struct mtpav_port *portp, struct snd_rawmidi_substream *substream) { u8 outbyte; // Get the outbyte first, so we can emulate running status if // necessary if (snd_rawmidi_transmit(substream, &outbyte, 1) != 1) return; // send port change command if necessary if (portp->hwport != mtp_card->outmidihwport) { mtp_card->outmidihwport = portp->hwport; snd_mtpav_send_byte(mtp_card, 0xf5); snd_mtpav_send_byte(mtp_card, portp->hwport); /* snd_printk(KERN_DEBUG "new outport: 0x%x\n", (unsigned int) portp->hwport); */ if (!(outbyte & 0x80) && portp->running_status) snd_mtpav_send_byte(mtp_card, portp->running_status); } // send data do { if (outbyte & 0x80) portp->running_status = outbyte; snd_mtpav_send_byte(mtp_card, outbyte); } while (snd_rawmidi_transmit(substream, &outbyte, 1) == 1); } static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); snd_mtpav_output_port_write(mtp_card, portp, substream); spin_unlock_irqrestore(&mtp_card->spinlock, flags); } /* * mtpav control */ static void snd_mtpav_portscan(struct mtpav *chip) // put mtp into smart routing mode { u8 p; for (p = 0; p < 8; p++) { snd_mtpav_send_byte(chip, 0xf5); snd_mtpav_send_byte(chip, p); snd_mtpav_send_byte(chip, 0xfe); } } /* */ static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); portp->mode |= MTPAV_MODE_INPUT_OPENED; portp->input = substream; if (mtp_card->share_irq++ == 0) snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE)); // enable pport interrupts spin_unlock_irqrestore(&mtp_card->spinlock, flags); return 0; } /* */ static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); portp->mode &= ~MTPAV_MODE_INPUT_OPENED; portp->input = NULL; if (--mtp_card->share_irq == 0) snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts spin_unlock_irqrestore(&mtp_card->spinlock, flags); return 0; } /* */ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); if (up) portp->mode |= MTPAV_MODE_INPUT_TRIGGERED; else portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED; spin_unlock_irqrestore(&mtp_card->spinlock, flags); } /* * timer interrupt for outputs */ static void snd_mtpav_output_timer(struct timer_list *t) { unsigned long flags; struct mtpav *chip = from_timer(chip, t, timer); int p; spin_lock_irqsave(&chip->spinlock, flags); /* reprogram timer */ mod_timer(&chip->timer, 1 + jiffies); /* process each port */ for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) { struct mtpav_port *portp = &chip->ports[p]; if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output) snd_mtpav_output_port_write(chip, portp, portp->output); } spin_unlock_irqrestore(&chip->spinlock, flags); } /* spinlock held! */ static void snd_mtpav_add_output_timer(struct mtpav *chip) { mod_timer(&chip->timer, 1 + jiffies); } /* spinlock held! */ static void snd_mtpav_remove_output_timer(struct mtpav *chip) { del_timer(&chip->timer); } /* */ static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); portp->mode |= MTPAV_MODE_OUTPUT_OPENED; portp->output = substream; spin_unlock_irqrestore(&mtp_card->spinlock, flags); return 0; }; /* */ static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); portp->mode &= ~MTPAV_MODE_OUTPUT_OPENED; portp->output = NULL; spin_unlock_irqrestore(&mtp_card->spinlock, flags); return 0; }; /* */ static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct mtpav *mtp_card = substream->rmidi->private_data; struct mtpav_port *portp = &mtp_card->ports[substream->number]; unsigned long flags; spin_lock_irqsave(&mtp_card->spinlock, flags); if (up) { if (! (portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) { if (mtp_card->istimer++ == 0) snd_mtpav_add_output_timer(mtp_card); portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED; } } else { portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED; if (--mtp_card->istimer == 0) snd_mtpav_remove_output_timer(mtp_card); } spin_unlock_irqrestore(&mtp_card->spinlock, flags); if (up) snd_mtpav_output_write(substream); } /* * midi interrupt for inputs */ static void snd_mtpav_inmidi_process(struct mtpav *mcrd, u8 inbyte) { struct mtpav_port *portp; if ((int)mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST) return; portp = &mcrd->ports[mcrd->inmidiport]; if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED) snd_rawmidi_receive(portp->input, &inbyte, 1); } static void snd_mtpav_inmidi_h(struct mtpav *mcrd, u8 inbyte) { if (inbyte >= 0xf8) { /* real-time midi code */ snd_mtpav_inmidi_process(mcrd, inbyte); return; } if (mcrd->inmidistate == 0) { // awaiting command if (inbyte == 0xf5) // MTP port # mcrd->inmidistate = 1; else snd_mtpav_inmidi_process(mcrd, inbyte); } else if (mcrd->inmidistate) { mcrd->inmidiport = translate_hwport_to_subdevice(mcrd, inbyte); mcrd->inmidistate = 0; } } static void snd_mtpav_read_bytes(struct mtpav *mcrd) { u8 clrread, setread; u8 mtp_read_byte; u8 sr, cbyt; int i; u8 sbyt = snd_mtpav_getreg(mcrd, SREG); /* printk(KERN_DEBUG "snd_mtpav_read_bytes() sbyt: 0x%x\n", sbyt); */ if (!(sbyt & SIGS_BYTE)) return; cbyt = snd_mtpav_getreg(mcrd, CREG); clrread = cbyt & (SIGC_READ ^ 0xff); setread = cbyt | SIGC_READ; do { mtp_read_byte = 0; for (i = 0; i < 4; i++) { snd_mtpav_mputreg(mcrd, CREG, setread); sr = snd_mtpav_getreg(mcrd, SREG); snd_mtpav_mputreg(mcrd, CREG, clrread); sr &= SIGS_IN0 | SIGS_IN1; sr >>= 4; mtp_read_byte |= sr << (i * 2); } snd_mtpav_inmidi_h(mcrd, mtp_read_byte); sbyt = snd_mtpav_getreg(mcrd, SREG); } while (sbyt & SIGS_BYTE); } static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id) { struct mtpav *mcard = dev_id; spin_lock(&mcard->spinlock); snd_mtpav_read_bytes(mcard); spin_unlock(&mcard->spinlock); return IRQ_HANDLED; } /* * get ISA resources */ static int snd_mtpav_get_ISA(struct mtpav *mcard) { mcard->res_port = devm_request_region(mcard->card->dev, port, 3, "MotuMTPAV MIDI"); if (!mcard->res_port) { snd_printk(KERN_ERR "MTVAP port 0x%lx is busy\n", port); return -EBUSY; } mcard->port = port; if (devm_request_irq(mcard->card->dev, irq, snd_mtpav_irqh, 0, "MOTU MTPAV", mcard)) { snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq); return -EBUSY; } mcard->irq = irq; return 0; } /* */ static const struct snd_rawmidi_ops snd_mtpav_output = { .open = snd_mtpav_output_open, .close = snd_mtpav_output_close, .trigger = snd_mtpav_output_trigger, }; static const struct snd_rawmidi_ops snd_mtpav_input = { .open = snd_mtpav_input_open, .close = snd_mtpav_input_close, .trigger = snd_mtpav_input_trigger, }; /* * get RAWMIDI resources */ static void snd_mtpav_set_name(struct mtpav *chip, struct snd_rawmidi_substream *substream) { if (substream->number >= 0 && substream->number < chip->num_ports) sprintf(substream->name, "MTP direct %d", (substream->number % chip->num_ports) + 1); else if (substream->number >= 8 && substream->number < chip->num_ports * 2) sprintf(substream->name, "MTP remote %d", (substream->number % chip->num_ports) + 1); else if (substream->number == chip->num_ports * 2) strcpy(substream->name, "MTP computer"); else if (substream->number == chip->num_ports * 2 + 1) strcpy(substream->name, "MTP ADAT"); else strcpy(substream->name, "MTP broadcast"); } static int snd_mtpav_get_RAWMIDI(struct mtpav *mcard) { int rval; struct snd_rawmidi *rawmidi; struct snd_rawmidi_substream *substream; struct list_head *list; if (hwports < 1) hwports = 1; else if (hwports > 8) hwports = 8; mcard->num_ports = hwports; rval = snd_rawmidi_new(mcard->card, "MotuMIDI", 0, mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1, mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1, &mcard->rmidi); if (rval < 0) return rval; rawmidi = mcard->rmidi; rawmidi->private_data = mcard; list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) { substream = list_entry(list, struct snd_rawmidi_substream, list); snd_mtpav_set_name(mcard, substream); substream->ops = &snd_mtpav_input; } list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) { substream = list_entry(list, struct snd_rawmidi_substream, list); snd_mtpav_set_name(mcard, substream); substream->ops = &snd_mtpav_output; mcard->ports[substream->number].hwport = translate_subdevice_to_hwport(mcard, substream->number); } rawmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; sprintf(rawmidi->name, "MTP AV MIDI"); return 0; } /* */ static void snd_mtpav_free(struct snd_card *card) { struct mtpav *crd = card->private_data; unsigned long flags; spin_lock_irqsave(&crd->spinlock, flags); if (crd->istimer > 0) snd_mtpav_remove_output_timer(crd); spin_unlock_irqrestore(&crd->spinlock, flags); } /* */ static int snd_mtpav_probe(struct platform_device *dev) { struct snd_card *card; int err; struct mtpav *mtp_card; err = snd_devm_card_new(&dev->dev, index, id, THIS_MODULE, sizeof(*mtp_card), &card); if (err < 0) return err; mtp_card = card->private_data; spin_lock_init(&mtp_card->spinlock); mtp_card->card = card; mtp_card->irq = -1; mtp_card->share_irq = 0; mtp_card->inmidistate = 0; mtp_card->outmidihwport = 0xffffffff; timer_setup(&mtp_card->timer, snd_mtpav_output_timer, 0); err = snd_mtpav_get_RAWMIDI(mtp_card); if (err < 0) return err; mtp_card->inmidiport = mtp_card->num_ports + MTPAV_PIDX_BROADCAST; err = snd_mtpav_get_ISA(mtp_card); if (err < 0) return err; strcpy(card->driver, "MTPAV"); strcpy(card->shortname, "MTPAV on parallel port"); snprintf(card->longname, sizeof(card->longname), "MTPAV on parallel port at 0x%lx", port); snd_mtpav_portscan(mtp_card); err = snd_card_register(mtp_card->card); if (err < 0) return err; card->private_free = snd_mtpav_free; platform_set_drvdata(dev, card); printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port); return 0; } #define SND_MTPAV_DRIVER "snd_mtpav" static struct platform_driver snd_mtpav_driver = { .probe = snd_mtpav_probe, .driver = { .name = SND_MTPAV_DRIVER, }, }; static int __init alsa_card_mtpav_init(void) { int err; err = platform_driver_register(&snd_mtpav_driver); if (err < 0) return err; device = platform_device_register_simple(SND_MTPAV_DRIVER, -1, NULL, 0); if (!IS_ERR(device)) { if (platform_get_drvdata(device)) return 0; platform_device_unregister(device); err = -ENODEV; } else err = PTR_ERR(device); platform_driver_unregister(&snd_mtpav_driver); return err; } static void __exit alsa_card_mtpav_exit(void) { platform_device_unregister(device); platform_driver_unregister(&snd_mtpav_driver); } module_init(alsa_card_mtpav_init) module_exit(alsa_card_mtpav_exit)
linux-master
sound/drivers/mtpav.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Dummy soundcard * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/jiffies.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/wait.h> #include <linux/hrtimer.h> #include <linux/math64.h> #include <linux/module.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h> #include <sound/pcm.h> #include <sound/rawmidi.h> #include <sound/info.h> #include <sound/initval.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Dummy soundcard (/dev/null)"); MODULE_LICENSE("GPL"); #define MAX_PCM_DEVICES 4 #define MAX_PCM_SUBSTREAMS 128 #define MAX_MIDI_DEVICES 2 /* defaults */ #define MAX_BUFFER_SIZE (64*1024) #define MIN_PERIOD_SIZE 64 #define MAX_PERIOD_SIZE MAX_BUFFER_SIZE #define USE_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE) #define USE_RATE SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000 #define USE_RATE_MIN 5500 #define USE_RATE_MAX 48000 #define USE_CHANNELS_MIN 1 #define USE_CHANNELS_MAX 2 #define USE_PERIODS_MIN 1 #define USE_PERIODS_MAX 1024 #define USE_MIXER_VOLUME_LEVEL_MIN -50 #define USE_MIXER_VOLUME_LEVEL_MAX 100 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; static char *model[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = NULL}; static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; static int mixer_volume_level_min = USE_MIXER_VOLUME_LEVEL_MIN; static int mixer_volume_level_max = USE_MIXER_VOLUME_LEVEL_MAX; #ifdef CONFIG_HIGH_RES_TIMERS static bool hrtimer = 1; #endif static bool fake_buffer = 1; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for dummy soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for dummy soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable this dummy soundcard."); module_param_array(model, charp, NULL, 0444); MODULE_PARM_DESC(model, "Soundcard model."); module_param_array(pcm_devs, int, NULL, 0444); MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver."); module_param_array(pcm_substreams, int, NULL, 0444); MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver."); //module_param_array(midi_devs, int, NULL, 0444); //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); module_param(mixer_volume_level_min, int, 0444); MODULE_PARM_DESC(mixer_volume_level_min, "Minimum mixer volume level for dummy driver. Default: -50"); module_param(mixer_volume_level_max, int, 0444); MODULE_PARM_DESC(mixer_volume_level_max, "Maximum mixer volume level for dummy driver. Default: 100"); module_param(fake_buffer, bool, 0444); MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations."); #ifdef CONFIG_HIGH_RES_TIMERS module_param(hrtimer, bool, 0644); MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source."); #endif static struct platform_device *devices[SNDRV_CARDS]; #define MIXER_ADDR_MASTER 0 #define MIXER_ADDR_LINE 1 #define MIXER_ADDR_MIC 2 #define MIXER_ADDR_SYNTH 3 #define MIXER_ADDR_CD 4 #define MIXER_ADDR_LAST 4 struct dummy_timer_ops { int (*create)(struct snd_pcm_substream *); void (*free)(struct snd_pcm_substream *); int (*prepare)(struct snd_pcm_substream *); int (*start)(struct snd_pcm_substream *); int (*stop)(struct snd_pcm_substream *); snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *); }; #define get_dummy_ops(substream) \ (*(const struct dummy_timer_ops **)(substream)->runtime->private_data) struct dummy_model { const char *name; int (*playback_constraints)(struct snd_pcm_runtime *runtime); int (*capture_constraints)(struct snd_pcm_runtime *runtime); u64 formats; size_t buffer_bytes_max; size_t period_bytes_min; size_t period_bytes_max; unsigned int periods_min; unsigned int periods_max; unsigned int rates; unsigned int rate_min; unsigned int rate_max; unsigned int channels_min; unsigned int channels_max; }; struct snd_dummy { struct snd_card *card; const struct dummy_model *model; struct snd_pcm *pcm; struct snd_pcm_hardware pcm_hw; spinlock_t mixer_lock; int mixer_volume[MIXER_ADDR_LAST+1][2]; int capture_source[MIXER_ADDR_LAST+1][2]; int iobox; struct snd_kcontrol *cd_volume_ctl; struct snd_kcontrol *cd_switch_ctl; }; /* * card models */ static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime) { int err; err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX); if (err < 0) return err; return 0; } static const struct dummy_model model_emu10k1 = { .name = "emu10k1", .playback_constraints = emu10k1_playback_constraints, .buffer_bytes_max = 128 * 1024, }; static const struct dummy_model model_rme9652 = { .name = "rme9652", .buffer_bytes_max = 26 * 64 * 1024, .formats = SNDRV_PCM_FMTBIT_S32_LE, .channels_min = 26, .channels_max = 26, .periods_min = 2, .periods_max = 2, }; static const struct dummy_model model_ice1712 = { .name = "ice1712", .buffer_bytes_max = 256 * 1024, .formats = SNDRV_PCM_FMTBIT_S32_LE, .channels_min = 10, .channels_max = 10, .periods_min = 1, .periods_max = 1024, }; static const struct dummy_model model_uda1341 = { .name = "uda1341", .buffer_bytes_max = 16380, .formats = SNDRV_PCM_FMTBIT_S16_LE, .channels_min = 2, .channels_max = 2, .periods_min = 2, .periods_max = 255, }; static const struct dummy_model model_ac97 = { .name = "ac97", .formats = SNDRV_PCM_FMTBIT_S16_LE, .channels_min = 2, .channels_max = 2, .rates = SNDRV_PCM_RATE_48000, .rate_min = 48000, .rate_max = 48000, }; static const struct dummy_model model_ca0106 = { .name = "ca0106", .formats = SNDRV_PCM_FMTBIT_S16_LE, .buffer_bytes_max = ((65536-64)*8), .period_bytes_max = (65536-64), .periods_min = 2, .periods_max = 8, .channels_min = 2, .channels_max = 2, .rates = SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000, .rate_min = 48000, .rate_max = 192000, }; static const struct dummy_model *dummy_models[] = { &model_emu10k1, &model_rme9652, &model_ice1712, &model_uda1341, &model_ac97, &model_ca0106, NULL }; /* * system timer interface */ struct dummy_systimer_pcm { /* ops must be the first item */ const struct dummy_timer_ops *timer_ops; spinlock_t lock; struct timer_list timer; unsigned long base_time; unsigned int frac_pos; /* fractional sample position (based HZ) */ unsigned int frac_period_rest; unsigned int frac_buffer_size; /* buffer_size * HZ */ unsigned int frac_period_size; /* period_size * HZ */ unsigned int rate; int elapsed; struct snd_pcm_substream *substream; }; static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm) { mod_timer(&dpcm->timer, jiffies + DIV_ROUND_UP(dpcm->frac_period_rest, dpcm->rate)); } static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm) { unsigned long delta; delta = jiffies - dpcm->base_time; if (!delta) return; dpcm->base_time += delta; delta *= dpcm->rate; dpcm->frac_pos += delta; while (dpcm->frac_pos >= dpcm->frac_buffer_size) dpcm->frac_pos -= dpcm->frac_buffer_size; while (dpcm->frac_period_rest <= delta) { dpcm->elapsed++; dpcm->frac_period_rest += dpcm->frac_period_size; } dpcm->frac_period_rest -= delta; } static int dummy_systimer_start(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; spin_lock(&dpcm->lock); dpcm->base_time = jiffies; dummy_systimer_rearm(dpcm); spin_unlock(&dpcm->lock); return 0; } static int dummy_systimer_stop(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; spin_lock(&dpcm->lock); del_timer(&dpcm->timer); spin_unlock(&dpcm->lock); return 0; } static int dummy_systimer_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct dummy_systimer_pcm *dpcm = runtime->private_data; dpcm->frac_pos = 0; dpcm->rate = runtime->rate; dpcm->frac_buffer_size = runtime->buffer_size * HZ; dpcm->frac_period_size = runtime->period_size * HZ; dpcm->frac_period_rest = dpcm->frac_period_size; dpcm->elapsed = 0; return 0; } static void dummy_systimer_callback(struct timer_list *t) { struct dummy_systimer_pcm *dpcm = from_timer(dpcm, t, timer); unsigned long flags; int elapsed = 0; spin_lock_irqsave(&dpcm->lock, flags); dummy_systimer_update(dpcm); dummy_systimer_rearm(dpcm); elapsed = dpcm->elapsed; dpcm->elapsed = 0; spin_unlock_irqrestore(&dpcm->lock, flags); if (elapsed) snd_pcm_period_elapsed(dpcm->substream); } static snd_pcm_uframes_t dummy_systimer_pointer(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; snd_pcm_uframes_t pos; spin_lock(&dpcm->lock); dummy_systimer_update(dpcm); pos = dpcm->frac_pos / HZ; spin_unlock(&dpcm->lock); return pos; } static int dummy_systimer_create(struct snd_pcm_substream *substream) { struct dummy_systimer_pcm *dpcm; dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); if (!dpcm) return -ENOMEM; substream->runtime->private_data = dpcm; timer_setup(&dpcm->timer, dummy_systimer_callback, 0); spin_lock_init(&dpcm->lock); dpcm->substream = substream; return 0; } static void dummy_systimer_free(struct snd_pcm_substream *substream) { kfree(substream->runtime->private_data); } static const struct dummy_timer_ops dummy_systimer_ops = { .create = dummy_systimer_create, .free = dummy_systimer_free, .prepare = dummy_systimer_prepare, .start = dummy_systimer_start, .stop = dummy_systimer_stop, .pointer = dummy_systimer_pointer, }; #ifdef CONFIG_HIGH_RES_TIMERS /* * hrtimer interface */ struct dummy_hrtimer_pcm { /* ops must be the first item */ const struct dummy_timer_ops *timer_ops; ktime_t base_time; ktime_t period_time; atomic_t running; struct hrtimer timer; struct snd_pcm_substream *substream; }; static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer) { struct dummy_hrtimer_pcm *dpcm; dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer); if (!atomic_read(&dpcm->running)) return HRTIMER_NORESTART; /* * In cases of XRUN and draining, this calls .trigger to stop PCM * substream. */ snd_pcm_period_elapsed(dpcm->substream); if (!atomic_read(&dpcm->running)) return HRTIMER_NORESTART; hrtimer_forward_now(timer, dpcm->period_time); return HRTIMER_RESTART; } static int dummy_hrtimer_start(struct snd_pcm_substream *substream) { struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer); hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL_SOFT); atomic_set(&dpcm->running, 1); return 0; } static int dummy_hrtimer_stop(struct snd_pcm_substream *substream) { struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; atomic_set(&dpcm->running, 0); if (!hrtimer_callback_running(&dpcm->timer)) hrtimer_cancel(&dpcm->timer); return 0; } static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm) { hrtimer_cancel(&dpcm->timer); } static snd_pcm_uframes_t dummy_hrtimer_pointer(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct dummy_hrtimer_pcm *dpcm = runtime->private_data; u64 delta; u32 pos; delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer), dpcm->base_time); delta = div_u64(delta * runtime->rate + 999999, 1000000); div_u64_rem(delta, runtime->buffer_size, &pos); return pos; } static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct dummy_hrtimer_pcm *dpcm = runtime->private_data; unsigned int period, rate; long sec; unsigned long nsecs; dummy_hrtimer_sync(dpcm); period = runtime->period_size; rate = runtime->rate; sec = period / rate; period %= rate; nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate); dpcm->period_time = ktime_set(sec, nsecs); return 0; } static int dummy_hrtimer_create(struct snd_pcm_substream *substream) { struct dummy_hrtimer_pcm *dpcm; dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); if (!dpcm) return -ENOMEM; substream->runtime->private_data = dpcm; hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); dpcm->timer.function = dummy_hrtimer_callback; dpcm->substream = substream; atomic_set(&dpcm->running, 0); return 0; } static void dummy_hrtimer_free(struct snd_pcm_substream *substream) { struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; dummy_hrtimer_sync(dpcm); kfree(dpcm); } static const struct dummy_timer_ops dummy_hrtimer_ops = { .create = dummy_hrtimer_create, .free = dummy_hrtimer_free, .prepare = dummy_hrtimer_prepare, .start = dummy_hrtimer_start, .stop = dummy_hrtimer_stop, .pointer = dummy_hrtimer_pointer, }; #endif /* CONFIG_HIGH_RES_TIMERS */ /* * PCM interface */ static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: return get_dummy_ops(substream)->start(substream); case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: return get_dummy_ops(substream)->stop(substream); } return -EINVAL; } static int dummy_pcm_prepare(struct snd_pcm_substream *substream) { return get_dummy_ops(substream)->prepare(substream); } static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream) { return get_dummy_ops(substream)->pointer(substream); } static const struct snd_pcm_hardware dummy_pcm_hardware = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), .formats = USE_FORMATS, .rates = USE_RATE, .rate_min = USE_RATE_MIN, .rate_max = USE_RATE_MAX, .channels_min = USE_CHANNELS_MIN, .channels_max = USE_CHANNELS_MAX, .buffer_bytes_max = MAX_BUFFER_SIZE, .period_bytes_min = MIN_PERIOD_SIZE, .period_bytes_max = MAX_PERIOD_SIZE, .periods_min = USE_PERIODS_MIN, .periods_max = USE_PERIODS_MAX, .fifo_size = 0, }; static int dummy_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { if (fake_buffer) { /* runtime->dma_bytes has to be set manually to allow mmap */ substream->runtime->dma_bytes = params_buffer_bytes(hw_params); return 0; } return 0; } static int dummy_pcm_open(struct snd_pcm_substream *substream) { struct snd_dummy *dummy = snd_pcm_substream_chip(substream); const struct dummy_model *model = dummy->model; struct snd_pcm_runtime *runtime = substream->runtime; const struct dummy_timer_ops *ops; int err; ops = &dummy_systimer_ops; #ifdef CONFIG_HIGH_RES_TIMERS if (hrtimer) ops = &dummy_hrtimer_ops; #endif err = ops->create(substream); if (err < 0) return err; get_dummy_ops(substream) = ops; runtime->hw = dummy->pcm_hw; if (substream->pcm->device & 1) { runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; } if (substream->pcm->device & 2) runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID); if (model == NULL) return 0; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (model->playback_constraints) err = model->playback_constraints(substream->runtime); } else { if (model->capture_constraints) err = model->capture_constraints(substream->runtime); } if (err < 0) { get_dummy_ops(substream)->free(substream); return err; } return 0; } static int dummy_pcm_close(struct snd_pcm_substream *substream) { get_dummy_ops(substream)->free(substream); return 0; } /* * dummy buffer handling */ static void *dummy_page[2]; static void free_fake_buffer(void) { if (fake_buffer) { int i; for (i = 0; i < 2; i++) if (dummy_page[i]) { free_page((unsigned long)dummy_page[i]); dummy_page[i] = NULL; } } } static int alloc_fake_buffer(void) { int i; if (!fake_buffer) return 0; for (i = 0; i < 2; i++) { dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL); if (!dummy_page[i]) { free_fake_buffer(); return -ENOMEM; } } return 0; } static int dummy_pcm_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *iter, unsigned long bytes) { return 0; /* do nothing */ } static int dummy_pcm_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long bytes) { return 0; /* do nothing */ } static struct page *dummy_pcm_page(struct snd_pcm_substream *substream, unsigned long offset) { return virt_to_page(dummy_page[substream->stream]); /* the same page */ } static const struct snd_pcm_ops dummy_pcm_ops = { .open = dummy_pcm_open, .close = dummy_pcm_close, .hw_params = dummy_pcm_hw_params, .prepare = dummy_pcm_prepare, .trigger = dummy_pcm_trigger, .pointer = dummy_pcm_pointer, }; static const struct snd_pcm_ops dummy_pcm_ops_no_buf = { .open = dummy_pcm_open, .close = dummy_pcm_close, .hw_params = dummy_pcm_hw_params, .prepare = dummy_pcm_prepare, .trigger = dummy_pcm_trigger, .pointer = dummy_pcm_pointer, .copy = dummy_pcm_copy, .fill_silence = dummy_pcm_silence, .page = dummy_pcm_page, }; static int snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams) { struct snd_pcm *pcm; const struct snd_pcm_ops *ops; int err; err = snd_pcm_new(dummy->card, "Dummy PCM", device, substreams, substreams, &pcm); if (err < 0) return err; dummy->pcm = pcm; if (fake_buffer) ops = &dummy_pcm_ops_no_buf; else ops = &dummy_pcm_ops; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops); pcm->private_data = dummy; pcm->info_flags = 0; strcpy(pcm->name, "Dummy PCM"); if (!fake_buffer) { snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, NULL, 0, 64*1024); } return 0; } /* * mixer interface */ #define DUMMY_VOLUME(xname, xindex, addr) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .name = xname, .index = xindex, \ .info = snd_dummy_volume_info, \ .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \ .private_value = addr, \ .tlv = { .p = db_scale_dummy } } static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = mixer_volume_level_min; uinfo->value.integer.max = mixer_volume_level_max; return 0; } static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int addr = kcontrol->private_value; spin_lock_irq(&dummy->mixer_lock); ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; spin_unlock_irq(&dummy->mixer_lock); return 0; } static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int change, addr = kcontrol->private_value; int left, right; left = ucontrol->value.integer.value[0]; if (left < mixer_volume_level_min) left = mixer_volume_level_min; if (left > mixer_volume_level_max) left = mixer_volume_level_max; right = ucontrol->value.integer.value[1]; if (right < mixer_volume_level_min) right = mixer_volume_level_min; if (right > mixer_volume_level_max) right = mixer_volume_level_max; spin_lock_irq(&dummy->mixer_lock); change = dummy->mixer_volume[addr][0] != left || dummy->mixer_volume[addr][1] != right; dummy->mixer_volume[addr][0] = left; dummy->mixer_volume[addr][1] = right; spin_unlock_irq(&dummy->mixer_lock); return change; } static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0); #define DUMMY_CAPSRC(xname, xindex, addr) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_dummy_capsrc_info, \ .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \ .private_value = addr } #define snd_dummy_capsrc_info snd_ctl_boolean_stereo_info static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int addr = kcontrol->private_value; spin_lock_irq(&dummy->mixer_lock); ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; spin_unlock_irq(&dummy->mixer_lock); return 0; } static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int change, addr = kcontrol->private_value; int left, right; left = ucontrol->value.integer.value[0] & 1; right = ucontrol->value.integer.value[1] & 1; spin_lock_irq(&dummy->mixer_lock); change = dummy->capture_source[addr][0] != left && dummy->capture_source[addr][1] != right; dummy->capture_source[addr][0] = left; dummy->capture_source[addr][1] = right; spin_unlock_irq(&dummy->mixer_lock); return change; } static int snd_dummy_iobox_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *info) { static const char *const names[] = { "None", "CD Player" }; return snd_ctl_enum_info(info, 1, 2, names); } static int snd_dummy_iobox_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); value->value.enumerated.item[0] = dummy->iobox; return 0; } static int snd_dummy_iobox_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) { struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int changed; if (value->value.enumerated.item[0] > 1) return -EINVAL; changed = value->value.enumerated.item[0] != dummy->iobox; if (changed) { dummy->iobox = value->value.enumerated.item[0]; if (dummy->iobox) { dummy->cd_volume_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; dummy->cd_switch_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; } else { dummy->cd_volume_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; dummy->cd_switch_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; } snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO, &dummy->cd_volume_ctl->id); snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO, &dummy->cd_switch_ctl->id); } return changed; } static const struct snd_kcontrol_new snd_dummy_controls[] = { DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER), DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER), DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH), DUMMY_CAPSRC("Synth Capture Switch", 0, MIXER_ADDR_SYNTH), DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE), DUMMY_CAPSRC("Line Capture Switch", 0, MIXER_ADDR_LINE), DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC), DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC), DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD), DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_CD), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "External I/O Box", .info = snd_dummy_iobox_info, .get = snd_dummy_iobox_get, .put = snd_dummy_iobox_put, }, }; static int snd_card_dummy_new_mixer(struct snd_dummy *dummy) { struct snd_card *card = dummy->card; struct snd_kcontrol *kcontrol; unsigned int idx; int err; spin_lock_init(&dummy->mixer_lock); strcpy(card->mixername, "Dummy Mixer"); dummy->iobox = 1; for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) { kcontrol = snd_ctl_new1(&snd_dummy_controls[idx], dummy); err = snd_ctl_add(card, kcontrol); if (err < 0) return err; if (!strcmp(kcontrol->id.name, "CD Volume")) dummy->cd_volume_ctl = kcontrol; else if (!strcmp(kcontrol->id.name, "CD Capture Switch")) dummy->cd_switch_ctl = kcontrol; } return 0; } #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_PROC_FS) /* * proc interface */ static void print_formats(struct snd_dummy *dummy, struct snd_info_buffer *buffer) { snd_pcm_format_t i; pcm_for_each_format(i) { if (dummy->pcm_hw.formats & pcm_format_to_bits(i)) snd_iprintf(buffer, " %s", snd_pcm_format_name(i)); } } static void print_rates(struct snd_dummy *dummy, struct snd_info_buffer *buffer) { static const int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000, }; int i; if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_CONTINUOUS) snd_iprintf(buffer, " continuous"); if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_KNOT) snd_iprintf(buffer, " knot"); for (i = 0; i < ARRAY_SIZE(rates); i++) if (dummy->pcm_hw.rates & (1 << i)) snd_iprintf(buffer, " %d", rates[i]); } #define get_dummy_int_ptr(dummy, ofs) \ (unsigned int *)((char *)&((dummy)->pcm_hw) + (ofs)) #define get_dummy_ll_ptr(dummy, ofs) \ (unsigned long long *)((char *)&((dummy)->pcm_hw) + (ofs)) struct dummy_hw_field { const char *name; const char *format; unsigned int offset; unsigned int size; }; #define FIELD_ENTRY(item, fmt) { \ .name = #item, \ .format = fmt, \ .offset = offsetof(struct snd_pcm_hardware, item), \ .size = sizeof(dummy_pcm_hardware.item) } static const struct dummy_hw_field fields[] = { FIELD_ENTRY(formats, "%#llx"), FIELD_ENTRY(rates, "%#x"), FIELD_ENTRY(rate_min, "%d"), FIELD_ENTRY(rate_max, "%d"), FIELD_ENTRY(channels_min, "%d"), FIELD_ENTRY(channels_max, "%d"), FIELD_ENTRY(buffer_bytes_max, "%ld"), FIELD_ENTRY(period_bytes_min, "%ld"), FIELD_ENTRY(period_bytes_max, "%ld"), FIELD_ENTRY(periods_min, "%d"), FIELD_ENTRY(periods_max, "%d"), }; static void dummy_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_dummy *dummy = entry->private_data; int i; for (i = 0; i < ARRAY_SIZE(fields); i++) { snd_iprintf(buffer, "%s ", fields[i].name); if (fields[i].size == sizeof(int)) snd_iprintf(buffer, fields[i].format, *get_dummy_int_ptr(dummy, fields[i].offset)); else snd_iprintf(buffer, fields[i].format, *get_dummy_ll_ptr(dummy, fields[i].offset)); if (!strcmp(fields[i].name, "formats")) print_formats(dummy, buffer); else if (!strcmp(fields[i].name, "rates")) print_rates(dummy, buffer); snd_iprintf(buffer, "\n"); } } static void dummy_proc_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_dummy *dummy = entry->private_data; char line[64]; while (!snd_info_get_line(buffer, line, sizeof(line))) { char item[20]; const char *ptr; unsigned long long val; int i; ptr = snd_info_get_str(item, line, sizeof(item)); for (i = 0; i < ARRAY_SIZE(fields); i++) { if (!strcmp(item, fields[i].name)) break; } if (i >= ARRAY_SIZE(fields)) continue; snd_info_get_str(item, ptr, sizeof(item)); if (kstrtoull(item, 0, &val)) continue; if (fields[i].size == sizeof(int)) *get_dummy_int_ptr(dummy, fields[i].offset) = val; else *get_dummy_ll_ptr(dummy, fields[i].offset) = val; } } static void dummy_proc_init(struct snd_dummy *chip) { snd_card_rw_proc_new(chip->card, "dummy_pcm", chip, dummy_proc_read, dummy_proc_write); } #else #define dummy_proc_init(x) #endif /* CONFIG_SND_DEBUG && CONFIG_SND_PROC_FS */ static int snd_dummy_probe(struct platform_device *devptr) { struct snd_card *card; struct snd_dummy *dummy; const struct dummy_model *m = NULL, **mdl; int idx, err; int dev = devptr->id; err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, sizeof(struct snd_dummy), &card); if (err < 0) return err; dummy = card->private_data; dummy->card = card; for (mdl = dummy_models; *mdl && model[dev]; mdl++) { if (strcmp(model[dev], (*mdl)->name) == 0) { printk(KERN_INFO "snd-dummy: Using model '%s' for card %i\n", (*mdl)->name, card->number); m = dummy->model = *mdl; break; } } for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { if (pcm_substreams[dev] < 1) pcm_substreams[dev] = 1; if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev]); if (err < 0) return err; } dummy->pcm_hw = dummy_pcm_hardware; if (m) { if (m->formats) dummy->pcm_hw.formats = m->formats; if (m->buffer_bytes_max) dummy->pcm_hw.buffer_bytes_max = m->buffer_bytes_max; if (m->period_bytes_min) dummy->pcm_hw.period_bytes_min = m->period_bytes_min; if (m->period_bytes_max) dummy->pcm_hw.period_bytes_max = m->period_bytes_max; if (m->periods_min) dummy->pcm_hw.periods_min = m->periods_min; if (m->periods_max) dummy->pcm_hw.periods_max = m->periods_max; if (m->rates) dummy->pcm_hw.rates = m->rates; if (m->rate_min) dummy->pcm_hw.rate_min = m->rate_min; if (m->rate_max) dummy->pcm_hw.rate_max = m->rate_max; if (m->channels_min) dummy->pcm_hw.channels_min = m->channels_min; if (m->channels_max) dummy->pcm_hw.channels_max = m->channels_max; } if (mixer_volume_level_min > mixer_volume_level_max) { pr_warn("snd-dummy: Invalid mixer volume level: min=%d, max=%d. Fall back to default value.\n", mixer_volume_level_min, mixer_volume_level_max); mixer_volume_level_min = USE_MIXER_VOLUME_LEVEL_MIN; mixer_volume_level_max = USE_MIXER_VOLUME_LEVEL_MAX; } err = snd_card_dummy_new_mixer(dummy); if (err < 0) return err; strcpy(card->driver, "Dummy"); strcpy(card->shortname, "Dummy"); sprintf(card->longname, "Dummy %i", dev + 1); dummy_proc_init(dummy); err = snd_card_register(card); if (err < 0) return err; platform_set_drvdata(devptr, card); return 0; } #ifdef CONFIG_PM_SLEEP static int snd_dummy_suspend(struct device *pdev) { struct snd_card *card = dev_get_drvdata(pdev); snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); return 0; } static int snd_dummy_resume(struct device *pdev) { struct snd_card *card = dev_get_drvdata(pdev); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } static SIMPLE_DEV_PM_OPS(snd_dummy_pm, snd_dummy_suspend, snd_dummy_resume); #define SND_DUMMY_PM_OPS &snd_dummy_pm #else #define SND_DUMMY_PM_OPS NULL #endif #define SND_DUMMY_DRIVER "snd_dummy" static struct platform_driver snd_dummy_driver = { .probe = snd_dummy_probe, .driver = { .name = SND_DUMMY_DRIVER, .pm = SND_DUMMY_PM_OPS, }, }; static void snd_dummy_unregister_all(void) { int i; for (i = 0; i < ARRAY_SIZE(devices); ++i) platform_device_unregister(devices[i]); platform_driver_unregister(&snd_dummy_driver); free_fake_buffer(); } static int __init alsa_card_dummy_init(void) { int i, cards, err; err = platform_driver_register(&snd_dummy_driver); if (err < 0) return err; err = alloc_fake_buffer(); if (err < 0) { platform_driver_unregister(&snd_dummy_driver); return err; } cards = 0; for (i = 0; i < SNDRV_CARDS; i++) { struct platform_device *device; if (! enable[i]) continue; device = platform_device_register_simple(SND_DUMMY_DRIVER, i, NULL, 0); if (IS_ERR(device)) continue; if (!platform_get_drvdata(device)) { platform_device_unregister(device); continue; } devices[i] = device; cards++; } if (!cards) { #ifdef MODULE printk(KERN_ERR "Dummy soundcard not found or device busy\n"); #endif snd_dummy_unregister_all(); return -ENODEV; } return 0; } static void __exit alsa_card_dummy_exit(void) { snd_dummy_unregister_all(); } module_init(alsa_card_dummy_init) module_exit(alsa_card_dummy_exit)
linux-master
sound/drivers/dummy.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Midiman Portman2x4 parallel port midi interface * * Copyright (c) by Levent Guendogdu <[email protected]> * * ChangeLog * Jan 24 2007 Matthias Koenig <[email protected]> * - cleanup and rewrite * Sep 30 2004 Tobias Gehrig <[email protected]> * - source code cleanup * Sep 03 2004 Tobias Gehrig <[email protected]> * - fixed compilation problem with alsa 1.0.6a (removed MODULE_CLASSES, * MODULE_PARM_SYNTAX and changed MODULE_DEVICES to * MODULE_SUPPORTED_DEVICE) * Mar 24 2004 Tobias Gehrig <[email protected]> * - added 2.6 kernel support * Mar 18 2004 Tobias Gehrig <[email protected]> * - added parport_unregister_driver to the startup routine if the driver fails to detect a portman * - added support for all 4 output ports in portman_putmidi * Mar 17 2004 Tobias Gehrig <[email protected]> * - added checks for opened input device in interrupt handler * Feb 20 2004 Tobias Gehrig <[email protected]> * - ported from alsa 0.5 to 1.0 */ #include <linux/init.h> #include <linux/platform_device.h> #include <linux/parport.h> #include <linux/spinlock.h> #include <linux/delay.h> #include <linux/slab.h> #include <linux/module.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/rawmidi.h> #include <sound/control.h> #define CARD_NAME "Portman 2x4" #define DRIVER_NAME "portman" #define PLATFORM_DRIVER "snd_portman2x4" static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; static struct platform_device *platform_devices[SNDRV_CARDS]; static int device_count; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard."); MODULE_AUTHOR("Levent Guendogdu, Tobias Gehrig, Matthias Koenig"); MODULE_DESCRIPTION("Midiman Portman2x4"); MODULE_LICENSE("GPL"); /********************************************************************* * Chip specific *********************************************************************/ #define PORTMAN_NUM_INPUT_PORTS 2 #define PORTMAN_NUM_OUTPUT_PORTS 4 struct portman { spinlock_t reg_lock; struct snd_card *card; struct snd_rawmidi *rmidi; struct pardevice *pardev; int open_count; int mode[PORTMAN_NUM_INPUT_PORTS]; struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS]; }; static int portman_free(struct portman *pm) { kfree(pm); return 0; } static int portman_create(struct snd_card *card, struct pardevice *pardev, struct portman **rchip) { struct portman *pm; *rchip = NULL; pm = kzalloc(sizeof(struct portman), GFP_KERNEL); if (pm == NULL) return -ENOMEM; /* Init chip specific data */ spin_lock_init(&pm->reg_lock); pm->card = card; pm->pardev = pardev; *rchip = pm; return 0; } /********************************************************************* * HW related constants *********************************************************************/ /* Standard PC parallel port status register equates. */ #define PP_STAT_BSY 0x80 /* Busy status. Inverted. */ #define PP_STAT_ACK 0x40 /* Acknowledge. Non-Inverted. */ #define PP_STAT_POUT 0x20 /* Paper Out. Non-Inverted. */ #define PP_STAT_SEL 0x10 /* Select. Non-Inverted. */ #define PP_STAT_ERR 0x08 /* Error. Non-Inverted. */ /* Standard PC parallel port command register equates. */ #define PP_CMD_IEN 0x10 /* IRQ Enable. Non-Inverted. */ #define PP_CMD_SELI 0x08 /* Select Input. Inverted. */ #define PP_CMD_INIT 0x04 /* Init Printer. Non-Inverted. */ #define PP_CMD_FEED 0x02 /* Auto Feed. Inverted. */ #define PP_CMD_STB 0x01 /* Strobe. Inverted. */ /* Parallel Port Command Register as implemented by PCP2x4. */ #define INT_EN PP_CMD_IEN /* Interrupt enable. */ #define STROBE PP_CMD_STB /* Command strobe. */ /* The parallel port command register field (b1..b3) selects the * various "registers" within the PC/P 2x4. These are the internal * address of these "registers" that must be written to the parallel * port command register. */ #define RXDATA0 (0 << 1) /* PCP RxData channel 0. */ #define RXDATA1 (1 << 1) /* PCP RxData channel 1. */ #define GEN_CTL (2 << 1) /* PCP General Control Register. */ #define SYNC_CTL (3 << 1) /* PCP Sync Control Register. */ #define TXDATA0 (4 << 1) /* PCP TxData channel 0. */ #define TXDATA1 (5 << 1) /* PCP TxData channel 1. */ #define TXDATA2 (6 << 1) /* PCP TxData channel 2. */ #define TXDATA3 (7 << 1) /* PCP TxData channel 3. */ /* Parallel Port Status Register as implemented by PCP2x4. */ #define ESTB PP_STAT_POUT /* Echoed strobe. */ #define INT_REQ PP_STAT_ACK /* Input data int request. */ #define BUSY PP_STAT_ERR /* Interface Busy. */ /* Parallel Port Status Register BUSY and SELECT lines are multiplexed * between several functions. Depending on which 2x4 "register" is * currently selected (b1..b3), the BUSY and SELECT lines are * assigned as follows: * * SELECT LINE: A3 A2 A1 * -------- */ #define RXAVAIL PP_STAT_SEL /* Rx Available, channel 0. 0 0 0 */ // RXAVAIL1 PP_STAT_SEL /* Rx Available, channel 1. 0 0 1 */ #define SYNC_STAT PP_STAT_SEL /* Reserved - Sync Status. 0 1 0 */ // /* Reserved. 0 1 1 */ #define TXEMPTY PP_STAT_SEL /* Tx Empty, channel 0. 1 0 0 */ // TXEMPTY1 PP_STAT_SEL /* Tx Empty, channel 1. 1 0 1 */ // TXEMPTY2 PP_STAT_SEL /* Tx Empty, channel 2. 1 1 0 */ // TXEMPTY3 PP_STAT_SEL /* Tx Empty, channel 3. 1 1 1 */ /* BUSY LINE: A3 A2 A1 * -------- */ #define RXDATA PP_STAT_BSY /* Rx Input Data, channel 0. 0 0 0 */ // RXDATA1 PP_STAT_BSY /* Rx Input Data, channel 1. 0 0 1 */ #define SYNC_DATA PP_STAT_BSY /* Reserved - Sync Data. 0 1 0 */ /* Reserved. 0 1 1 */ #define DATA_ECHO PP_STAT_BSY /* Parallel Port Data Echo. 1 0 0 */ #define A0_ECHO PP_STAT_BSY /* Address 0 Echo. 1 0 1 */ #define A1_ECHO PP_STAT_BSY /* Address 1 Echo. 1 1 0 */ #define A2_ECHO PP_STAT_BSY /* Address 2 Echo. 1 1 1 */ #define PORTMAN2X4_MODE_INPUT_TRIGGERED 0x01 /********************************************************************* * Hardware specific functions *********************************************************************/ static inline void portman_write_command(struct portman *pm, u8 value) { parport_write_control(pm->pardev->port, value); } static inline u8 portman_read_status(struct portman *pm) { return parport_read_status(pm->pardev->port); } static inline void portman_write_data(struct portman *pm, u8 value) { parport_write_data(pm->pardev->port, value); } static void portman_write_midi(struct portman *pm, int port, u8 mididata) { int command = ((port + 4) << 1); /* Get entering data byte and port number in BL and BH respectively. * Set up Tx Channel address field for use with PP Cmd Register. * Store address field in BH register. * Inputs: AH = Output port number (0..3). * AL = Data byte. * command = TXDATA0 | INT_EN; * Align port num with address field (b1...b3), * set address for TXDatax, Strobe=0 */ command |= INT_EN; /* Disable interrupts so that the process is not interrupted, then * write the address associated with the current Tx channel to the * PP Command Reg. Do not set the Strobe signal yet. */ do { portman_write_command(pm, command); /* While the address lines settle, write parallel output data to * PP Data Reg. This has no effect until Strobe signal is asserted. */ portman_write_data(pm, mididata); /* If PCP channel's TxEmpty is set (TxEmpty is read through the PP * Status Register), then go write data. Else go back and wait. */ } while ((portman_read_status(pm) & TXEMPTY) != TXEMPTY); /* TxEmpty is set. Maintain PC/P destination address and assert * Strobe through the PP Command Reg. This will Strobe data into * the PC/P transmitter and set the PC/P BUSY signal. */ portman_write_command(pm, command | STROBE); /* Wait for strobe line to settle and echo back through hardware. * Once it has echoed back, assume that the address and data lines * have settled! */ while ((portman_read_status(pm) & ESTB) == 0) cpu_relax(); /* Release strobe and immediately re-allow interrupts. */ portman_write_command(pm, command); while ((portman_read_status(pm) & ESTB) == ESTB) cpu_relax(); /* PC/P BUSY is now set. We must wait until BUSY resets itself. * We'll reenable ints while we're waiting. */ while ((portman_read_status(pm) & BUSY) == BUSY) cpu_relax(); /* Data sent. */ } /* * Read MIDI byte from port * Attempt to read input byte from specified hardware input port (0..). * Return -1 if no data */ static int portman_read_midi(struct portman *pm, int port) { unsigned char midi_data = 0; unsigned char cmdout; /* Saved address+IE bit. */ /* Make sure clocking edge is down before starting... */ portman_write_data(pm, 0); /* Make sure edge is down. */ /* Set destination address to PCP. */ cmdout = (port << 1) | INT_EN; /* Address + IE + No Strobe. */ portman_write_command(pm, cmdout); while ((portman_read_status(pm) & ESTB) == ESTB) cpu_relax(); /* Wait for strobe echo. */ /* After the address lines settle, check multiplexed RxAvail signal. * If data is available, read it. */ if ((portman_read_status(pm) & RXAVAIL) == 0) return -1; /* No data. */ /* Set the Strobe signal to enable the Rx clocking circuitry. */ portman_write_command(pm, cmdout | STROBE); /* Write address+IE+Strobe. */ while ((portman_read_status(pm) & ESTB) == 0) cpu_relax(); /* Wait for strobe echo. */ /* The first data bit (msb) is already sitting on the input line. */ midi_data = (portman_read_status(pm) & 128); portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 6. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 1) & 64; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 5. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 2) & 32; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 4. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 3) & 16; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 3. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 4) & 8; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 2. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 5) & 4; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 1. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 6) & 2; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ /* Data bit 0. */ portman_write_data(pm, 0); /* Cause falling edge while data settles. */ midi_data |= (portman_read_status(pm) >> 7) & 1; portman_write_data(pm, 1); /* Cause rising edge, which shifts data. */ portman_write_data(pm, 0); /* Return data clock low. */ /* De-assert Strobe and return data. */ portman_write_command(pm, cmdout); /* Output saved address+IE. */ /* Wait for strobe echo. */ while ((portman_read_status(pm) & ESTB) == ESTB) cpu_relax(); return (midi_data & 255); /* Shift back and return value. */ } /* * Checks if any input data on the given channel is available * Checks RxAvail */ static int portman_data_avail(struct portman *pm, int channel) { int command = INT_EN; switch (channel) { case 0: command |= RXDATA0; break; case 1: command |= RXDATA1; break; } /* Write hardware (assumme STROBE=0) */ portman_write_command(pm, command); /* Check multiplexed RxAvail signal */ if ((portman_read_status(pm) & RXAVAIL) == RXAVAIL) return 1; /* Data available */ /* No Data available */ return 0; } /* * Flushes any input */ static void portman_flush_input(struct portman *pm, unsigned char port) { /* Local variable for counting things */ unsigned int i = 0; unsigned char command = 0; switch (port) { case 0: command = RXDATA0; break; case 1: command = RXDATA1; break; default: snd_printk(KERN_WARNING "portman_flush_input() Won't flush port %i\n", port); return; } /* Set address for specified channel in port and allow to settle. */ portman_write_command(pm, command); /* Assert the Strobe and wait for echo back. */ portman_write_command(pm, command | STROBE); /* Wait for ESTB */ while ((portman_read_status(pm) & ESTB) == 0) cpu_relax(); /* Output clock cycles to the Rx circuitry. */ portman_write_data(pm, 0); /* Flush 250 bits... */ for (i = 0; i < 250; i++) { portman_write_data(pm, 1); portman_write_data(pm, 0); } /* Deassert the Strobe signal of the port and wait for it to settle. */ portman_write_command(pm, command | INT_EN); /* Wait for settling */ while ((portman_read_status(pm) & ESTB) == ESTB) cpu_relax(); } static int portman_probe(struct parport *p) { /* Initialize the parallel port data register. Will set Rx clocks * low in case we happen to be addressing the Rx ports at this time. */ /* 1 */ parport_write_data(p, 0); /* Initialize the parallel port command register, thus initializing * hardware handshake lines to midi box: * * Strobe = 0 * Interrupt Enable = 0 */ /* 2 */ parport_write_control(p, 0); /* Check if Portman PC/P 2x4 is out there. */ /* 3 */ parport_write_control(p, RXDATA0); /* Write Strobe=0 to command reg. */ /* Check for ESTB to be clear */ /* 4 */ if ((parport_read_status(p) & ESTB) == ESTB) return 1; /* CODE 1 - Strobe Failure. */ /* Set for RXDATA0 where no damage will be done. */ /* 5 */ parport_write_control(p, RXDATA0 | STROBE); /* Write Strobe=1 to command reg. */ /* 6 */ if ((parport_read_status(p) & ESTB) != ESTB) return 1; /* CODE 1 - Strobe Failure. */ /* 7 */ parport_write_control(p, 0); /* Reset Strobe=0. */ /* Check if Tx circuitry is functioning properly. If initialized * unit TxEmpty is false, send out char and see if it goes true. */ /* 8 */ parport_write_control(p, TXDATA0); /* Tx channel 0, strobe off. */ /* If PCP channel's TxEmpty is set (TxEmpty is read through the PP * Status Register), then go write data. Else go back and wait. */ /* 9 */ if ((parport_read_status(p) & TXEMPTY) == 0) return 2; /* Return OK status. */ return 0; } static int portman_device_init(struct portman *pm) { portman_flush_input(pm, 0); portman_flush_input(pm, 1); return 0; } /********************************************************************* * Rawmidi *********************************************************************/ static int snd_portman_midi_open(struct snd_rawmidi_substream *substream) { return 0; } static int snd_portman_midi_close(struct snd_rawmidi_substream *substream) { return 0; } static void snd_portman_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) { struct portman *pm = substream->rmidi->private_data; unsigned long flags; spin_lock_irqsave(&pm->reg_lock, flags); if (up) pm->mode[substream->number] |= PORTMAN2X4_MODE_INPUT_TRIGGERED; else pm->mode[substream->number] &= ~PORTMAN2X4_MODE_INPUT_TRIGGERED; spin_unlock_irqrestore(&pm->reg_lock, flags); } static void snd_portman_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) { struct portman *pm = substream->rmidi->private_data; unsigned long flags; unsigned char byte; spin_lock_irqsave(&pm->reg_lock, flags); if (up) { while ((snd_rawmidi_transmit(substream, &byte, 1) == 1)) portman_write_midi(pm, substream->number, byte); } spin_unlock_irqrestore(&pm->reg_lock, flags); } static const struct snd_rawmidi_ops snd_portman_midi_output = { .open = snd_portman_midi_open, .close = snd_portman_midi_close, .trigger = snd_portman_midi_output_trigger, }; static const struct snd_rawmidi_ops snd_portman_midi_input = { .open = snd_portman_midi_open, .close = snd_portman_midi_close, .trigger = snd_portman_midi_input_trigger, }; /* Create and initialize the rawmidi component */ static int snd_portman_rawmidi_create(struct snd_card *card) { struct portman *pm = card->private_data; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *substream; int err; err = snd_rawmidi_new(card, CARD_NAME, 0, PORTMAN_NUM_OUTPUT_PORTS, PORTMAN_NUM_INPUT_PORTS, &rmidi); if (err < 0) return err; rmidi->private_data = pm; strcpy(rmidi->name, CARD_NAME); rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; pm->rmidi = rmidi; /* register rawmidi ops */ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_portman_midi_output); snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_portman_midi_input); /* name substreams */ /* output */ list_for_each_entry(substream, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams, list) { sprintf(substream->name, "Portman2x4 %d", substream->number+1); } /* input */ list_for_each_entry(substream, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams, list) { pm->midi_input[substream->number] = substream; sprintf(substream->name, "Portman2x4 %d", substream->number+1); } return err; } /********************************************************************* * parport stuff *********************************************************************/ static void snd_portman_interrupt(void *userdata) { unsigned char midivalue = 0; struct portman *pm = ((struct snd_card*)userdata)->private_data; spin_lock(&pm->reg_lock); /* While any input data is waiting */ while ((portman_read_status(pm) & INT_REQ) == INT_REQ) { /* If data available on channel 0, read it and stuff it into the queue. */ if (portman_data_avail(pm, 0)) { /* Read Midi */ midivalue = portman_read_midi(pm, 0); /* put midi into queue... */ if (pm->mode[0] & PORTMAN2X4_MODE_INPUT_TRIGGERED) snd_rawmidi_receive(pm->midi_input[0], &midivalue, 1); } /* If data available on channel 1, read it and stuff it into the queue. */ if (portman_data_avail(pm, 1)) { /* Read Midi */ midivalue = portman_read_midi(pm, 1); /* put midi into queue... */ if (pm->mode[1] & PORTMAN2X4_MODE_INPUT_TRIGGERED) snd_rawmidi_receive(pm->midi_input[1], &midivalue, 1); } } spin_unlock(&pm->reg_lock); } static void snd_portman_attach(struct parport *p) { struct platform_device *device; device = platform_device_alloc(PLATFORM_DRIVER, device_count); if (!device) return; /* Temporary assignment to forward the parport */ platform_set_drvdata(device, p); if (platform_device_add(device) < 0) { platform_device_put(device); return; } /* Since we dont get the return value of probe * We need to check if device probing succeeded or not */ if (!platform_get_drvdata(device)) { platform_device_unregister(device); return; } /* register device in global table */ platform_devices[device_count] = device; device_count++; } static void snd_portman_detach(struct parport *p) { /* nothing to do here */ } static int snd_portman_dev_probe(struct pardevice *pardev) { if (strcmp(pardev->name, DRIVER_NAME)) return -ENODEV; return 0; } static struct parport_driver portman_parport_driver = { .name = "portman2x4", .probe = snd_portman_dev_probe, .match_port = snd_portman_attach, .detach = snd_portman_detach, .devmodel = true, }; /********************************************************************* * platform stuff *********************************************************************/ static void snd_portman_card_private_free(struct snd_card *card) { struct portman *pm = card->private_data; struct pardevice *pardev = pm->pardev; if (pardev) { parport_release(pardev); parport_unregister_device(pardev); } portman_free(pm); } static int snd_portman_probe(struct platform_device *pdev) { struct pardevice *pardev; struct parport *p; int dev = pdev->id; struct snd_card *card = NULL; struct portman *pm = NULL; int err; struct pardev_cb portman_cb = { .preempt = NULL, .wakeup = NULL, .irq_func = snd_portman_interrupt, /* ISR */ .flags = PARPORT_DEV_EXCL, /* flags */ }; p = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); if (dev >= SNDRV_CARDS) return -ENODEV; if (!enable[dev]) return -ENOENT; err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE, 0, &card); if (err < 0) { snd_printd("Cannot create card\n"); return err; } strcpy(card->driver, DRIVER_NAME); strcpy(card->shortname, CARD_NAME); sprintf(card->longname, "%s at 0x%lx, irq %i", card->shortname, p->base, p->irq); portman_cb.private = card; /* private */ pardev = parport_register_dev_model(p, /* port */ DRIVER_NAME, /* name */ &portman_cb, /* callbacks */ pdev->id); /* device number */ if (pardev == NULL) { snd_printd("Cannot register pardevice\n"); err = -EIO; goto __err; } /* claim parport */ if (parport_claim(pardev)) { snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base); err = -EIO; goto free_pardev; } err = portman_create(card, pardev, &pm); if (err < 0) { snd_printd("Cannot create main component\n"); goto release_pardev; } card->private_data = pm; card->private_free = snd_portman_card_private_free; err = portman_probe(p); if (err) { err = -EIO; goto __err; } err = snd_portman_rawmidi_create(card); if (err < 0) { snd_printd("Creating Rawmidi component failed\n"); goto __err; } /* init device */ err = portman_device_init(pm); if (err < 0) goto __err; platform_set_drvdata(pdev, card); /* At this point card will be usable */ err = snd_card_register(card); if (err < 0) { snd_printd("Cannot register card\n"); goto __err; } snd_printk(KERN_INFO "Portman 2x4 on 0x%lx\n", p->base); return 0; release_pardev: parport_release(pardev); free_pardev: parport_unregister_device(pardev); __err: snd_card_free(card); return err; } static void snd_portman_remove(struct platform_device *pdev) { struct snd_card *card = platform_get_drvdata(pdev); if (card) snd_card_free(card); } static struct platform_driver snd_portman_driver = { .probe = snd_portman_probe, .remove_new = snd_portman_remove, .driver = { .name = PLATFORM_DRIVER, } }; /********************************************************************* * module init stuff *********************************************************************/ static void snd_portman_unregister_all(void) { int i; for (i = 0; i < SNDRV_CARDS; ++i) { if (platform_devices[i]) { platform_device_unregister(platform_devices[i]); platform_devices[i] = NULL; } } platform_driver_unregister(&snd_portman_driver); parport_unregister_driver(&portman_parport_driver); } static int __init snd_portman_module_init(void) { int err; err = platform_driver_register(&snd_portman_driver); if (err < 0) return err; if (parport_register_driver(&portman_parport_driver) != 0) { platform_driver_unregister(&snd_portman_driver); return -EIO; } if (device_count == 0) { snd_portman_unregister_all(); return -ENODEV; } return 0; } static void __exit snd_portman_module_exit(void) { snd_portman_unregister_all(); } module_init(snd_portman_module_init); module_exit(snd_portman_module_exit);
linux-master
sound/drivers/portman2x4.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Loopback soundcard * * Original code: * Copyright (c) by Jaroslav Kysela <[email protected]> * * More accurate positioning and full-duplex support: * Copyright (c) Ahmet İnan <ainan at mathematik.uni-freiburg.de> * * Major (almost complete) rewrite: * Copyright (c) by Takashi Iwai <[email protected]> * * A next major update in 2010 (separate timers for playback and capture): * Copyright (c) Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/jiffies.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/wait.h> #include <linux/module.h> #include <linux/platform_device.h> #include <sound/core.h> #include <sound/control.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/info.h> #include <sound/initval.h> #include <sound/timer.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("A loopback soundcard"); MODULE_LICENSE("GPL"); #define MAX_PCM_SUBSTREAMS 8 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; static int pcm_notify[SNDRV_CARDS]; static char *timer_source[SNDRV_CARDS]; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for loopback soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for loopback soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable this loopback soundcard."); module_param_array(pcm_substreams, int, NULL, 0444); MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-8) for loopback driver."); module_param_array(pcm_notify, int, NULL, 0444); MODULE_PARM_DESC(pcm_notify, "Break capture when PCM format/rate/channels changes."); module_param_array(timer_source, charp, NULL, 0444); MODULE_PARM_DESC(timer_source, "Sound card name or number and device/subdevice number of timer to be used. Empty string for jiffies timer [default]."); #define NO_PITCH 100000 #define CABLE_VALID_PLAYBACK BIT(SNDRV_PCM_STREAM_PLAYBACK) #define CABLE_VALID_CAPTURE BIT(SNDRV_PCM_STREAM_CAPTURE) #define CABLE_VALID_BOTH (CABLE_VALID_PLAYBACK | CABLE_VALID_CAPTURE) struct loopback_cable; struct loopback_pcm; struct loopback_ops { /* optional * call in loopback->cable_lock */ int (*open)(struct loopback_pcm *dpcm); /* required * call in cable->lock */ int (*start)(struct loopback_pcm *dpcm); /* required * call in cable->lock */ int (*stop)(struct loopback_pcm *dpcm); /* optional */ int (*stop_sync)(struct loopback_pcm *dpcm); /* optional */ int (*close_substream)(struct loopback_pcm *dpcm); /* optional * call in loopback->cable_lock */ int (*close_cable)(struct loopback_pcm *dpcm); /* optional * call in cable->lock */ unsigned int (*pos_update)(struct loopback_cable *cable); /* optional */ void (*dpcm_info)(struct loopback_pcm *dpcm, struct snd_info_buffer *buffer); }; struct loopback_cable { spinlock_t lock; struct loopback_pcm *streams[2]; struct snd_pcm_hardware hw; /* flags */ unsigned int valid; unsigned int running; unsigned int pause; /* timer specific */ const struct loopback_ops *ops; /* If sound timer is used */ struct { int stream; struct snd_timer_id id; struct work_struct event_work; struct snd_timer_instance *instance; } snd_timer; }; struct loopback_setup { unsigned int notify: 1; unsigned int rate_shift; snd_pcm_format_t format; unsigned int rate; unsigned int channels; struct snd_ctl_elem_id active_id; struct snd_ctl_elem_id format_id; struct snd_ctl_elem_id rate_id; struct snd_ctl_elem_id channels_id; }; struct loopback { struct snd_card *card; struct mutex cable_lock; struct loopback_cable *cables[MAX_PCM_SUBSTREAMS][2]; struct snd_pcm *pcm[2]; struct loopback_setup setup[MAX_PCM_SUBSTREAMS][2]; const char *timer_source; }; struct loopback_pcm { struct loopback *loopback; struct snd_pcm_substream *substream; struct loopback_cable *cable; unsigned int pcm_buffer_size; unsigned int buf_pos; /* position in buffer */ unsigned int silent_size; /* PCM parameters */ unsigned int pcm_period_size; unsigned int pcm_bps; /* bytes per second */ unsigned int pcm_salign; /* bytes per sample * channels */ unsigned int pcm_rate_shift; /* rate shift value */ /* flags */ unsigned int period_update_pending :1; /* timer stuff */ unsigned int irq_pos; /* fractional IRQ position in jiffies * ticks */ unsigned int period_size_frac; /* period size in jiffies ticks */ unsigned int last_drift; unsigned long last_jiffies; /* If jiffies timer is used */ struct timer_list timer; }; static struct platform_device *devices[SNDRV_CARDS]; static inline unsigned int byte_pos(struct loopback_pcm *dpcm, unsigned int x) { if (dpcm->pcm_rate_shift == NO_PITCH) { x /= HZ; } else { x = div_u64(NO_PITCH * (unsigned long long)x, HZ * (unsigned long long)dpcm->pcm_rate_shift); } return x - (x % dpcm->pcm_salign); } static inline unsigned int frac_pos(struct loopback_pcm *dpcm, unsigned int x) { if (dpcm->pcm_rate_shift == NO_PITCH) { /* no pitch */ return x * HZ; } else { x = div_u64(dpcm->pcm_rate_shift * (unsigned long long)x * HZ, NO_PITCH); } return x; } static inline struct loopback_setup *get_setup(struct loopback_pcm *dpcm) { int device = dpcm->substream->pstr->pcm->device; if (dpcm->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) device ^= 1; return &dpcm->loopback->setup[dpcm->substream->number][device]; } static inline unsigned int get_notify(struct loopback_pcm *dpcm) { return get_setup(dpcm)->notify; } static inline unsigned int get_rate_shift(struct loopback_pcm *dpcm) { return get_setup(dpcm)->rate_shift; } /* call in cable->lock */ static int loopback_jiffies_timer_start(struct loopback_pcm *dpcm) { unsigned long tick; unsigned int rate_shift = get_rate_shift(dpcm); if (rate_shift != dpcm->pcm_rate_shift) { dpcm->pcm_rate_shift = rate_shift; dpcm->period_size_frac = frac_pos(dpcm, dpcm->pcm_period_size); } if (dpcm->period_size_frac <= dpcm->irq_pos) { dpcm->irq_pos %= dpcm->period_size_frac; dpcm->period_update_pending = 1; } tick = dpcm->period_size_frac - dpcm->irq_pos; tick = DIV_ROUND_UP(tick, dpcm->pcm_bps); mod_timer(&dpcm->timer, jiffies + tick); return 0; } /* call in cable->lock */ static int loopback_snd_timer_start(struct loopback_pcm *dpcm) { struct loopback_cable *cable = dpcm->cable; int err; /* Loopback device has to use same period as timer card. Therefore * wake up for each snd_pcm_period_elapsed() call of timer card. */ err = snd_timer_start(cable->snd_timer.instance, 1); if (err < 0) { /* do not report error if trying to start but already * running. For example called by opposite substream * of the same cable */ if (err == -EBUSY) return 0; pcm_err(dpcm->substream->pcm, "snd_timer_start(%d,%d,%d) failed with %d", cable->snd_timer.id.card, cable->snd_timer.id.device, cable->snd_timer.id.subdevice, err); } return err; } /* call in cable->lock */ static inline int loopback_jiffies_timer_stop(struct loopback_pcm *dpcm) { del_timer(&dpcm->timer); dpcm->timer.expires = 0; return 0; } /* call in cable->lock */ static int loopback_snd_timer_stop(struct loopback_pcm *dpcm) { struct loopback_cable *cable = dpcm->cable; int err; /* only stop if both devices (playback and capture) are not running */ if (cable->running ^ cable->pause) return 0; err = snd_timer_stop(cable->snd_timer.instance); if (err < 0) { pcm_err(dpcm->substream->pcm, "snd_timer_stop(%d,%d,%d) failed with %d", cable->snd_timer.id.card, cable->snd_timer.id.device, cable->snd_timer.id.subdevice, err); } return err; } static inline int loopback_jiffies_timer_stop_sync(struct loopback_pcm *dpcm) { del_timer_sync(&dpcm->timer); return 0; } /* call in loopback->cable_lock */ static int loopback_snd_timer_close_cable(struct loopback_pcm *dpcm) { struct loopback_cable *cable = dpcm->cable; /* snd_timer was not opened */ if (!cable->snd_timer.instance) return 0; /* will only be called from free_cable() when other stream was * already closed. Other stream cannot be reopened as long as * loopback->cable_lock is locked. Therefore no need to lock * cable->lock; */ snd_timer_close(cable->snd_timer.instance); /* wait till drain work has finished if requested */ cancel_work_sync(&cable->snd_timer.event_work); snd_timer_instance_free(cable->snd_timer.instance); memset(&cable->snd_timer, 0, sizeof(cable->snd_timer)); return 0; } static int loopback_check_format(struct loopback_cable *cable, int stream) { struct snd_pcm_runtime *runtime, *cruntime; struct loopback_setup *setup; struct snd_card *card; int check; if (cable->valid != CABLE_VALID_BOTH) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) goto __notify; return 0; } runtime = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]-> substream->runtime; cruntime = cable->streams[SNDRV_PCM_STREAM_CAPTURE]-> substream->runtime; check = runtime->format != cruntime->format || runtime->rate != cruntime->rate || runtime->channels != cruntime->channels; if (!check) return 0; if (stream == SNDRV_PCM_STREAM_CAPTURE) { return -EIO; } else { snd_pcm_stop(cable->streams[SNDRV_PCM_STREAM_CAPTURE]-> substream, SNDRV_PCM_STATE_DRAINING); __notify: runtime = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]-> substream->runtime; setup = get_setup(cable->streams[SNDRV_PCM_STREAM_PLAYBACK]); card = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]->loopback->card; if (setup->format != runtime->format) { snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &setup->format_id); setup->format = runtime->format; } if (setup->rate != runtime->rate) { snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &setup->rate_id); setup->rate = runtime->rate; } if (setup->channels != runtime->channels) { snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &setup->channels_id); setup->channels = runtime->channels; } } return 0; } static void loopback_active_notify(struct loopback_pcm *dpcm) { snd_ctl_notify(dpcm->loopback->card, SNDRV_CTL_EVENT_MASK_VALUE, &get_setup(dpcm)->active_id); } static int loopback_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; int err = 0, stream = 1 << substream->stream; switch (cmd) { case SNDRV_PCM_TRIGGER_START: err = loopback_check_format(cable, substream->stream); if (err < 0) return err; dpcm->last_jiffies = jiffies; dpcm->pcm_rate_shift = 0; dpcm->last_drift = 0; spin_lock(&cable->lock); cable->running |= stream; cable->pause &= ~stream; err = cable->ops->start(dpcm); spin_unlock(&cable->lock); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_STOP: spin_lock(&cable->lock); cable->running &= ~stream; cable->pause &= ~stream; err = cable->ops->stop(dpcm); spin_unlock(&cable->lock); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_SUSPEND: spin_lock(&cable->lock); cable->pause |= stream; err = cable->ops->stop(dpcm); spin_unlock(&cable->lock); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: spin_lock(&cable->lock); dpcm->last_jiffies = jiffies; cable->pause &= ~stream; err = cable->ops->start(dpcm); spin_unlock(&cable->lock); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) loopback_active_notify(dpcm); break; default: return -EINVAL; } return err; } static void params_change(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; cable->hw.formats = pcm_format_to_bits(runtime->format); cable->hw.rate_min = runtime->rate; cable->hw.rate_max = runtime->rate; cable->hw.channels_min = runtime->channels; cable->hw.channels_max = runtime->channels; if (cable->snd_timer.instance) { cable->hw.period_bytes_min = frames_to_bytes(runtime, runtime->period_size); cable->hw.period_bytes_max = cable->hw.period_bytes_min; } } static int loopback_prepare(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; int err, bps, salign; if (cable->ops->stop_sync) { err = cable->ops->stop_sync(dpcm); if (err < 0) return err; } salign = (snd_pcm_format_physical_width(runtime->format) * runtime->channels) / 8; bps = salign * runtime->rate; if (bps <= 0 || salign <= 0) return -EINVAL; dpcm->buf_pos = 0; dpcm->pcm_buffer_size = frames_to_bytes(runtime, runtime->buffer_size); if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { /* clear capture buffer */ dpcm->silent_size = dpcm->pcm_buffer_size; snd_pcm_format_set_silence(runtime->format, runtime->dma_area, runtime->buffer_size * runtime->channels); } dpcm->irq_pos = 0; dpcm->period_update_pending = 0; dpcm->pcm_bps = bps; dpcm->pcm_salign = salign; dpcm->pcm_period_size = frames_to_bytes(runtime, runtime->period_size); mutex_lock(&dpcm->loopback->cable_lock); if (!(cable->valid & ~(1 << substream->stream)) || (get_setup(dpcm)->notify && substream->stream == SNDRV_PCM_STREAM_PLAYBACK)) params_change(substream); cable->valid |= 1 << substream->stream; mutex_unlock(&dpcm->loopback->cable_lock); return 0; } static void clear_capture_buf(struct loopback_pcm *dpcm, unsigned int bytes) { struct snd_pcm_runtime *runtime = dpcm->substream->runtime; char *dst = runtime->dma_area; unsigned int dst_off = dpcm->buf_pos; if (dpcm->silent_size >= dpcm->pcm_buffer_size) return; if (dpcm->silent_size + bytes > dpcm->pcm_buffer_size) bytes = dpcm->pcm_buffer_size - dpcm->silent_size; for (;;) { unsigned int size = bytes; if (dst_off + size > dpcm->pcm_buffer_size) size = dpcm->pcm_buffer_size - dst_off; snd_pcm_format_set_silence(runtime->format, dst + dst_off, bytes_to_frames(runtime, size) * runtime->channels); dpcm->silent_size += size; bytes -= size; if (!bytes) break; dst_off = 0; } } static void copy_play_buf(struct loopback_pcm *play, struct loopback_pcm *capt, unsigned int bytes) { struct snd_pcm_runtime *runtime = play->substream->runtime; char *src = runtime->dma_area; char *dst = capt->substream->runtime->dma_area; unsigned int src_off = play->buf_pos; unsigned int dst_off = capt->buf_pos; unsigned int clear_bytes = 0; /* check if playback is draining, trim the capture copy size * when our pointer is at the end of playback ring buffer */ if (runtime->state == SNDRV_PCM_STATE_DRAINING && snd_pcm_playback_hw_avail(runtime) < runtime->buffer_size) { snd_pcm_uframes_t appl_ptr, appl_ptr1, diff; appl_ptr = appl_ptr1 = runtime->control->appl_ptr; appl_ptr1 -= appl_ptr1 % runtime->buffer_size; appl_ptr1 += play->buf_pos / play->pcm_salign; if (appl_ptr < appl_ptr1) appl_ptr1 -= runtime->buffer_size; diff = (appl_ptr - appl_ptr1) * play->pcm_salign; if (diff < bytes) { clear_bytes = bytes - diff; bytes = diff; } } for (;;) { unsigned int size = bytes; if (src_off + size > play->pcm_buffer_size) size = play->pcm_buffer_size - src_off; if (dst_off + size > capt->pcm_buffer_size) size = capt->pcm_buffer_size - dst_off; memcpy(dst + dst_off, src + src_off, size); capt->silent_size = 0; bytes -= size; if (!bytes) break; src_off = (src_off + size) % play->pcm_buffer_size; dst_off = (dst_off + size) % capt->pcm_buffer_size; } if (clear_bytes > 0) { clear_capture_buf(capt, clear_bytes); capt->silent_size = 0; } } static inline unsigned int bytepos_delta(struct loopback_pcm *dpcm, unsigned int jiffies_delta) { unsigned long last_pos; unsigned int delta; last_pos = byte_pos(dpcm, dpcm->irq_pos); dpcm->irq_pos += jiffies_delta * dpcm->pcm_bps; delta = byte_pos(dpcm, dpcm->irq_pos) - last_pos; if (delta >= dpcm->last_drift) delta -= dpcm->last_drift; dpcm->last_drift = 0; if (dpcm->irq_pos >= dpcm->period_size_frac) { dpcm->irq_pos %= dpcm->period_size_frac; dpcm->period_update_pending = 1; } return delta; } static inline void bytepos_finish(struct loopback_pcm *dpcm, unsigned int delta) { dpcm->buf_pos += delta; dpcm->buf_pos %= dpcm->pcm_buffer_size; } /* call in cable->lock */ static unsigned int loopback_jiffies_timer_pos_update (struct loopback_cable *cable) { struct loopback_pcm *dpcm_play = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]; struct loopback_pcm *dpcm_capt = cable->streams[SNDRV_PCM_STREAM_CAPTURE]; unsigned long delta_play = 0, delta_capt = 0, cur_jiffies; unsigned int running, count1, count2; cur_jiffies = jiffies; running = cable->running ^ cable->pause; if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) { delta_play = cur_jiffies - dpcm_play->last_jiffies; dpcm_play->last_jiffies += delta_play; } if (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) { delta_capt = cur_jiffies - dpcm_capt->last_jiffies; dpcm_capt->last_jiffies += delta_capt; } if (delta_play == 0 && delta_capt == 0) goto unlock; if (delta_play > delta_capt) { count1 = bytepos_delta(dpcm_play, delta_play - delta_capt); bytepos_finish(dpcm_play, count1); delta_play = delta_capt; } else if (delta_play < delta_capt) { count1 = bytepos_delta(dpcm_capt, delta_capt - delta_play); clear_capture_buf(dpcm_capt, count1); bytepos_finish(dpcm_capt, count1); delta_capt = delta_play; } if (delta_play == 0 && delta_capt == 0) goto unlock; /* note delta_capt == delta_play at this moment */ count1 = bytepos_delta(dpcm_play, delta_play); count2 = bytepos_delta(dpcm_capt, delta_capt); if (count1 < count2) { dpcm_capt->last_drift = count2 - count1; count1 = count2; } else if (count1 > count2) { dpcm_play->last_drift = count1 - count2; } copy_play_buf(dpcm_play, dpcm_capt, count1); bytepos_finish(dpcm_play, count1); bytepos_finish(dpcm_capt, count1); unlock: return running; } static void loopback_jiffies_timer_function(struct timer_list *t) { struct loopback_pcm *dpcm = from_timer(dpcm, t, timer); unsigned long flags; spin_lock_irqsave(&dpcm->cable->lock, flags); if (loopback_jiffies_timer_pos_update(dpcm->cable) & (1 << dpcm->substream->stream)) { loopback_jiffies_timer_start(dpcm); if (dpcm->period_update_pending) { dpcm->period_update_pending = 0; spin_unlock_irqrestore(&dpcm->cable->lock, flags); /* need to unlock before calling below */ snd_pcm_period_elapsed(dpcm->substream); return; } } spin_unlock_irqrestore(&dpcm->cable->lock, flags); } /* call in cable->lock */ static int loopback_snd_timer_check_resolution(struct snd_pcm_runtime *runtime, unsigned long resolution) { if (resolution != runtime->timer_resolution) { struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; /* Worst case estimation of possible values for resolution * resolution <= (512 * 1024) frames / 8kHz in nsec * resolution <= 65.536.000.000 nsec * * period_size <= 65.536.000.000 nsec / 1000nsec/usec * 192kHz + * 500.000 * period_size <= 12.582.912.000.000 <64bit * / 1.000.000 usec/sec */ snd_pcm_uframes_t period_size_usec = resolution / 1000 * runtime->rate; /* round to nearest sample rate */ snd_pcm_uframes_t period_size = (period_size_usec + 500 * 1000) / (1000 * 1000); pcm_err(dpcm->substream->pcm, "Period size (%lu frames) of loopback device is not corresponding to timer resolution (%lu nsec = %lu frames) of card timer %d,%d,%d. Use period size of %lu frames for loopback device.", runtime->period_size, resolution, period_size, cable->snd_timer.id.card, cable->snd_timer.id.device, cable->snd_timer.id.subdevice, period_size); return -EINVAL; } return 0; } static void loopback_snd_timer_period_elapsed(struct loopback_cable *cable, int event, unsigned long resolution) { struct loopback_pcm *dpcm_play, *dpcm_capt; struct snd_pcm_substream *substream_play, *substream_capt; struct snd_pcm_runtime *valid_runtime; unsigned int running, elapsed_bytes; unsigned long flags; spin_lock_irqsave(&cable->lock, flags); running = cable->running ^ cable->pause; /* no need to do anything if no stream is running */ if (!running) { spin_unlock_irqrestore(&cable->lock, flags); return; } dpcm_play = cable->streams[SNDRV_PCM_STREAM_PLAYBACK]; dpcm_capt = cable->streams[SNDRV_PCM_STREAM_CAPTURE]; if (event == SNDRV_TIMER_EVENT_MSTOP) { if (!dpcm_play || dpcm_play->substream->runtime->state != SNDRV_PCM_STATE_DRAINING) { spin_unlock_irqrestore(&cable->lock, flags); return; } } substream_play = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? dpcm_play->substream : NULL; substream_capt = (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) ? dpcm_capt->substream : NULL; valid_runtime = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? dpcm_play->substream->runtime : dpcm_capt->substream->runtime; /* resolution is only valid for SNDRV_TIMER_EVENT_TICK events */ if (event == SNDRV_TIMER_EVENT_TICK) { /* The hardware rules guarantee that playback and capture period * are the same. Therefore only one device has to be checked * here. */ if (loopback_snd_timer_check_resolution(valid_runtime, resolution) < 0) { spin_unlock_irqrestore(&cable->lock, flags); if (substream_play) snd_pcm_stop_xrun(substream_play); if (substream_capt) snd_pcm_stop_xrun(substream_capt); return; } } elapsed_bytes = frames_to_bytes(valid_runtime, valid_runtime->period_size); /* The same timer interrupt is used for playback and capture device */ if ((running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) && (running & (1 << SNDRV_PCM_STREAM_CAPTURE))) { copy_play_buf(dpcm_play, dpcm_capt, elapsed_bytes); bytepos_finish(dpcm_play, elapsed_bytes); bytepos_finish(dpcm_capt, elapsed_bytes); } else if (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) { bytepos_finish(dpcm_play, elapsed_bytes); } else if (running & (1 << SNDRV_PCM_STREAM_CAPTURE)) { clear_capture_buf(dpcm_capt, elapsed_bytes); bytepos_finish(dpcm_capt, elapsed_bytes); } spin_unlock_irqrestore(&cable->lock, flags); if (substream_play) snd_pcm_period_elapsed(substream_play); if (substream_capt) snd_pcm_period_elapsed(substream_capt); } static void loopback_snd_timer_function(struct snd_timer_instance *timeri, unsigned long resolution, unsigned long ticks) { struct loopback_cable *cable = timeri->callback_data; loopback_snd_timer_period_elapsed(cable, SNDRV_TIMER_EVENT_TICK, resolution); } static void loopback_snd_timer_work(struct work_struct *work) { struct loopback_cable *cable; cable = container_of(work, struct loopback_cable, snd_timer.event_work); loopback_snd_timer_period_elapsed(cable, SNDRV_TIMER_EVENT_MSTOP, 0); } static void loopback_snd_timer_event(struct snd_timer_instance *timeri, int event, struct timespec64 *tstamp, unsigned long resolution) { /* Do not lock cable->lock here because timer->lock is already hold. * There are other functions which first lock cable->lock and than * timer->lock e.g. * loopback_trigger() * spin_lock(&cable->lock) * loopback_snd_timer_start() * snd_timer_start() * spin_lock(&timer->lock) * Therefore when using the oposit order of locks here it could result * in a deadlock. */ if (event == SNDRV_TIMER_EVENT_MSTOP) { struct loopback_cable *cable = timeri->callback_data; /* sound card of the timer was stopped. Therefore there will not * be any further timer callbacks. Due to this forward audio * data from here if in draining state. When still in running * state the streaming will be aborted by the usual timeout. It * should not be aborted here because may be the timer sound * card does only a recovery and the timer is back soon. * This work triggers loopback_snd_timer_work() */ schedule_work(&cable->snd_timer.event_work); } } static void loopback_jiffies_timer_dpcm_info(struct loopback_pcm *dpcm, struct snd_info_buffer *buffer) { snd_iprintf(buffer, " update_pending:\t%u\n", dpcm->period_update_pending); snd_iprintf(buffer, " irq_pos:\t\t%u\n", dpcm->irq_pos); snd_iprintf(buffer, " period_frac:\t%u\n", dpcm->period_size_frac); snd_iprintf(buffer, " last_jiffies:\t%lu (%lu)\n", dpcm->last_jiffies, jiffies); snd_iprintf(buffer, " timer_expires:\t%lu\n", dpcm->timer.expires); } static void loopback_snd_timer_dpcm_info(struct loopback_pcm *dpcm, struct snd_info_buffer *buffer) { struct loopback_cable *cable = dpcm->cable; snd_iprintf(buffer, " sound timer:\thw:%d,%d,%d\n", cable->snd_timer.id.card, cable->snd_timer.id.device, cable->snd_timer.id.subdevice); snd_iprintf(buffer, " timer open:\t\t%s\n", (cable->snd_timer.stream == SNDRV_PCM_STREAM_CAPTURE) ? "capture" : "playback"); } static snd_pcm_uframes_t loopback_pointer(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; snd_pcm_uframes_t pos; spin_lock(&dpcm->cable->lock); if (dpcm->cable->ops->pos_update) dpcm->cable->ops->pos_update(dpcm->cable); pos = dpcm->buf_pos; spin_unlock(&dpcm->cable->lock); return bytes_to_frames(runtime, pos); } static const struct snd_pcm_hardware loopback_pcm_hardware = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME), .formats = (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE | SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_192000, .rate_min = 8000, .rate_max = 192000, .channels_min = 1, .channels_max = 32, .buffer_bytes_max = 2 * 1024 * 1024, .period_bytes_min = 64, /* note check overflow in frac_pos() using pcm_rate_shift before changing period_bytes_max value */ .period_bytes_max = 1024 * 1024, .periods_min = 1, .periods_max = 1024, .fifo_size = 0, }; static void loopback_runtime_free(struct snd_pcm_runtime *runtime) { struct loopback_pcm *dpcm = runtime->private_data; kfree(dpcm); } static int loopback_hw_free(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback_pcm *dpcm = runtime->private_data; struct loopback_cable *cable = dpcm->cable; mutex_lock(&dpcm->loopback->cable_lock); cable->valid &= ~(1 << substream->stream); mutex_unlock(&dpcm->loopback->cable_lock); return 0; } static unsigned int get_cable_index(struct snd_pcm_substream *substream) { if (!substream->pcm->device) return substream->stream; else return !substream->stream; } static int rule_format(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct loopback_pcm *dpcm = rule->private; struct loopback_cable *cable = dpcm->cable; struct snd_mask m; snd_mask_none(&m); mutex_lock(&dpcm->loopback->cable_lock); m.bits[0] = (u_int32_t)cable->hw.formats; m.bits[1] = (u_int32_t)(cable->hw.formats >> 32); mutex_unlock(&dpcm->loopback->cable_lock); return snd_mask_refine(hw_param_mask(params, rule->var), &m); } static int rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct loopback_pcm *dpcm = rule->private; struct loopback_cable *cable = dpcm->cable; struct snd_interval t; mutex_lock(&dpcm->loopback->cable_lock); t.min = cable->hw.rate_min; t.max = cable->hw.rate_max; mutex_unlock(&dpcm->loopback->cable_lock); t.openmin = t.openmax = 0; t.integer = 0; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int rule_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct loopback_pcm *dpcm = rule->private; struct loopback_cable *cable = dpcm->cable; struct snd_interval t; mutex_lock(&dpcm->loopback->cable_lock); t.min = cable->hw.channels_min; t.max = cable->hw.channels_max; mutex_unlock(&dpcm->loopback->cable_lock); t.openmin = t.openmax = 0; t.integer = 0; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int rule_period_bytes(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct loopback_pcm *dpcm = rule->private; struct loopback_cable *cable = dpcm->cable; struct snd_interval t; mutex_lock(&dpcm->loopback->cable_lock); t.min = cable->hw.period_bytes_min; t.max = cable->hw.period_bytes_max; mutex_unlock(&dpcm->loopback->cable_lock); t.openmin = 0; t.openmax = 0; t.integer = 0; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static void free_cable(struct snd_pcm_substream *substream) { struct loopback *loopback = substream->private_data; int dev = get_cable_index(substream); struct loopback_cable *cable; cable = loopback->cables[substream->number][dev]; if (!cable) return; if (cable->streams[!substream->stream]) { /* other stream is still alive */ spin_lock_irq(&cable->lock); cable->streams[substream->stream] = NULL; spin_unlock_irq(&cable->lock); } else { struct loopback_pcm *dpcm = substream->runtime->private_data; if (cable->ops && cable->ops->close_cable && dpcm) cable->ops->close_cable(dpcm); /* free the cable */ loopback->cables[substream->number][dev] = NULL; kfree(cable); } } static int loopback_jiffies_timer_open(struct loopback_pcm *dpcm) { timer_setup(&dpcm->timer, loopback_jiffies_timer_function, 0); return 0; } static const struct loopback_ops loopback_jiffies_timer_ops = { .open = loopback_jiffies_timer_open, .start = loopback_jiffies_timer_start, .stop = loopback_jiffies_timer_stop, .stop_sync = loopback_jiffies_timer_stop_sync, .close_substream = loopback_jiffies_timer_stop_sync, .pos_update = loopback_jiffies_timer_pos_update, .dpcm_info = loopback_jiffies_timer_dpcm_info, }; static int loopback_parse_timer_id(const char *str, struct snd_timer_id *tid) { /* [<pref>:](<card name>|<card idx>)[{.,}<dev idx>[{.,}<subdev idx>]] */ const char * const sep_dev = ".,"; const char * const sep_pref = ":"; const char *name = str; char *sep, save = '\0'; int card_idx = 0, dev = 0, subdev = 0; int err; sep = strpbrk(str, sep_pref); if (sep) name = sep + 1; sep = strpbrk(name, sep_dev); if (sep) { save = *sep; *sep = '\0'; } err = kstrtoint(name, 0, &card_idx); if (err == -EINVAL) { /* Must be the name, not number */ for (card_idx = 0; card_idx < snd_ecards_limit; card_idx++) { struct snd_card *card = snd_card_ref(card_idx); if (card) { if (!strcmp(card->id, name)) err = 0; snd_card_unref(card); } if (!err) break; } } if (sep) { *sep = save; if (!err) { char *sep2, save2 = '\0'; sep2 = strpbrk(sep + 1, sep_dev); if (sep2) { save2 = *sep2; *sep2 = '\0'; } err = kstrtoint(sep + 1, 0, &dev); if (sep2) { *sep2 = save2; if (!err) err = kstrtoint(sep2 + 1, 0, &subdev); } } } if (!err && tid) { tid->card = card_idx; tid->device = dev; tid->subdevice = subdev; } return err; } /* call in loopback->cable_lock */ static int loopback_snd_timer_open(struct loopback_pcm *dpcm) { int err = 0; struct snd_timer_id tid = { .dev_class = SNDRV_TIMER_CLASS_PCM, .dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION, }; struct snd_timer_instance *timeri; struct loopback_cable *cable = dpcm->cable; /* check if timer was already opened. It is only opened once * per playback and capture subdevice (aka cable). */ if (cable->snd_timer.instance) goto exit; err = loopback_parse_timer_id(dpcm->loopback->timer_source, &tid); if (err < 0) { pcm_err(dpcm->substream->pcm, "Parsing timer source \'%s\' failed with %d", dpcm->loopback->timer_source, err); goto exit; } cable->snd_timer.stream = dpcm->substream->stream; cable->snd_timer.id = tid; timeri = snd_timer_instance_new(dpcm->loopback->card->id); if (!timeri) { err = -ENOMEM; goto exit; } /* The callback has to be called from another work. If * SNDRV_TIMER_IFLG_FAST is specified it will be called from the * snd_pcm_period_elapsed() call of the selected sound card. * snd_pcm_period_elapsed() helds snd_pcm_stream_lock_irqsave(). * Due to our callback loopback_snd_timer_function() also calls * snd_pcm_period_elapsed() which calls snd_pcm_stream_lock_irqsave(). * This would end up in a dead lock. */ timeri->flags |= SNDRV_TIMER_IFLG_AUTO; timeri->callback = loopback_snd_timer_function; timeri->callback_data = (void *)cable; timeri->ccallback = loopback_snd_timer_event; /* initialise a work used for draining */ INIT_WORK(&cable->snd_timer.event_work, loopback_snd_timer_work); /* The mutex loopback->cable_lock is kept locked. * Therefore snd_timer_open() cannot be called a second time * by the other device of the same cable. * Therefore the following issue cannot happen: * [proc1] Call loopback_timer_open() -> * Unlock cable->lock for snd_timer_close/open() call * [proc2] Call loopback_timer_open() -> snd_timer_open(), * snd_timer_start() * [proc1] Call snd_timer_open() and overwrite running timer * instance */ err = snd_timer_open(timeri, &cable->snd_timer.id, current->pid); if (err < 0) { pcm_err(dpcm->substream->pcm, "snd_timer_open (%d,%d,%d) failed with %d", cable->snd_timer.id.card, cable->snd_timer.id.device, cable->snd_timer.id.subdevice, err); snd_timer_instance_free(timeri); goto exit; } cable->snd_timer.instance = timeri; exit: return err; } /* stop_sync() is not required for sound timer because it does not need to be * restarted in loopback_prepare() on Xrun recovery */ static const struct loopback_ops loopback_snd_timer_ops = { .open = loopback_snd_timer_open, .start = loopback_snd_timer_start, .stop = loopback_snd_timer_stop, .close_cable = loopback_snd_timer_close_cable, .dpcm_info = loopback_snd_timer_dpcm_info, }; static int loopback_open(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct loopback *loopback = substream->private_data; struct loopback_pcm *dpcm; struct loopback_cable *cable = NULL; int err = 0; int dev = get_cable_index(substream); mutex_lock(&loopback->cable_lock); dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); if (!dpcm) { err = -ENOMEM; goto unlock; } dpcm->loopback = loopback; dpcm->substream = substream; cable = loopback->cables[substream->number][dev]; if (!cable) { cable = kzalloc(sizeof(*cable), GFP_KERNEL); if (!cable) { err = -ENOMEM; goto unlock; } spin_lock_init(&cable->lock); cable->hw = loopback_pcm_hardware; if (loopback->timer_source) cable->ops = &loopback_snd_timer_ops; else cable->ops = &loopback_jiffies_timer_ops; loopback->cables[substream->number][dev] = cable; } dpcm->cable = cable; runtime->private_data = dpcm; if (cable->ops->open) { err = cable->ops->open(dpcm); if (err < 0) goto unlock; } snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); /* use dynamic rules based on actual runtime->hw values */ /* note that the default rules created in the PCM midlevel code */ /* are cached -> they do not reflect the actual state */ err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, rule_format, dpcm, SNDRV_PCM_HW_PARAM_FORMAT, -1); if (err < 0) goto unlock; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, rule_rate, dpcm, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) goto unlock; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, rule_channels, dpcm, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) goto unlock; /* In case of sound timer the period time of both devices of the same * loop has to be the same. * This rule only takes effect if a sound timer was chosen */ if (cable->snd_timer.instance) { err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, rule_period_bytes, dpcm, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, -1); if (err < 0) goto unlock; } /* loopback_runtime_free() has not to be called if kfree(dpcm) was * already called here. Otherwise it will end up with a double free. */ runtime->private_free = loopback_runtime_free; if (get_notify(dpcm)) runtime->hw = loopback_pcm_hardware; else runtime->hw = cable->hw; spin_lock_irq(&cable->lock); cable->streams[substream->stream] = dpcm; spin_unlock_irq(&cable->lock); unlock: if (err < 0) { free_cable(substream); kfree(dpcm); } mutex_unlock(&loopback->cable_lock); return err; } static int loopback_close(struct snd_pcm_substream *substream) { struct loopback *loopback = substream->private_data; struct loopback_pcm *dpcm = substream->runtime->private_data; int err = 0; if (dpcm->cable->ops->close_substream) err = dpcm->cable->ops->close_substream(dpcm); mutex_lock(&loopback->cable_lock); free_cable(substream); mutex_unlock(&loopback->cable_lock); return err; } static const struct snd_pcm_ops loopback_pcm_ops = { .open = loopback_open, .close = loopback_close, .hw_free = loopback_hw_free, .prepare = loopback_prepare, .trigger = loopback_trigger, .pointer = loopback_pointer, }; static int loopback_pcm_new(struct loopback *loopback, int device, int substreams) { struct snd_pcm *pcm; int err; err = snd_pcm_new(loopback->card, "Loopback PCM", device, substreams, substreams, &pcm); if (err < 0) return err; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &loopback_pcm_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &loopback_pcm_ops); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); pcm->private_data = loopback; pcm->info_flags = 0; strcpy(pcm->name, "Loopback PCM"); loopback->pcm[device] = pcm; return 0; } static int loopback_rate_shift_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 80000; uinfo->value.integer.max = 120000; uinfo->value.integer.step = 1; return 0; } static int loopback_rate_shift_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); mutex_lock(&loopback->cable_lock); ucontrol->value.integer.value[0] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate_shift; mutex_unlock(&loopback->cable_lock); return 0; } static int loopback_rate_shift_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = ucontrol->value.integer.value[0]; if (val < 80000) val = 80000; if (val > 120000) val = 120000; mutex_lock(&loopback->cable_lock); if (val != loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate_shift) { loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate_shift = val; change = 1; } mutex_unlock(&loopback->cable_lock); return change; } static int loopback_notify_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); mutex_lock(&loopback->cable_lock); ucontrol->value.integer.value[0] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify; mutex_unlock(&loopback->cable_lock); return 0; } static int loopback_notify_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); unsigned int val; int change = 0; val = ucontrol->value.integer.value[0] ? 1 : 0; mutex_lock(&loopback->cable_lock); if (val != loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify) { loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].notify = val; change = 1; } mutex_unlock(&loopback->cable_lock); return change; } static int loopback_active_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); struct loopback_cable *cable; unsigned int val = 0; mutex_lock(&loopback->cable_lock); cable = loopback->cables[kcontrol->id.subdevice][kcontrol->id.device ^ 1]; if (cable != NULL) { unsigned int running = cable->running ^ cable->pause; val = (running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) ? 1 : 0; } mutex_unlock(&loopback->cable_lock); ucontrol->value.integer.value[0] = val; return 0; } static int loopback_format_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = (__force int)SNDRV_PCM_FORMAT_LAST; uinfo->value.integer.step = 1; return 0; } static int loopback_format_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = (__force int)loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].format; return 0; } static int loopback_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 192000; uinfo->value.integer.step = 1; return 0; } static int loopback_rate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); mutex_lock(&loopback->cable_lock); ucontrol->value.integer.value[0] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].rate; mutex_unlock(&loopback->cable_lock); return 0; } static int loopback_channels_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 1; uinfo->value.integer.min = 1; uinfo->value.integer.max = 1024; uinfo->value.integer.step = 1; return 0; } static int loopback_channels_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct loopback *loopback = snd_kcontrol_chip(kcontrol); mutex_lock(&loopback->cable_lock); ucontrol->value.integer.value[0] = loopback->setup[kcontrol->id.subdevice] [kcontrol->id.device].channels; mutex_unlock(&loopback->cable_lock); return 0; } static const struct snd_kcontrol_new loopback_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Rate Shift 100000", .info = loopback_rate_shift_info, .get = loopback_rate_shift_get, .put = loopback_rate_shift_put, }, { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Notify", .info = snd_ctl_boolean_mono_info, .get = loopback_notify_get, .put = loopback_notify_put, }, #define ACTIVE_IDX 2 { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Slave Active", .info = snd_ctl_boolean_mono_info, .get = loopback_active_get, }, #define FORMAT_IDX 3 { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Slave Format", .info = loopback_format_info, .get = loopback_format_get }, #define RATE_IDX 4 { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Slave Rate", .info = loopback_rate_info, .get = loopback_rate_get }, #define CHANNELS_IDX 5 { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = "PCM Slave Channels", .info = loopback_channels_info, .get = loopback_channels_get } }; static int loopback_mixer_new(struct loopback *loopback, int notify) { struct snd_card *card = loopback->card; struct snd_pcm *pcm; struct snd_kcontrol *kctl; struct loopback_setup *setup; int err, dev, substr, substr_count, idx; strcpy(card->mixername, "Loopback Mixer"); for (dev = 0; dev < 2; dev++) { pcm = loopback->pcm[dev]; substr_count = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count; for (substr = 0; substr < substr_count; substr++) { setup = &loopback->setup[substr][dev]; setup->notify = notify; setup->rate_shift = NO_PITCH; setup->format = SNDRV_PCM_FORMAT_S16_LE; setup->rate = 48000; setup->channels = 2; for (idx = 0; idx < ARRAY_SIZE(loopback_controls); idx++) { kctl = snd_ctl_new1(&loopback_controls[idx], loopback); if (!kctl) return -ENOMEM; kctl->id.device = dev; kctl->id.subdevice = substr; /* Add the control before copying the id so that * the numid field of the id is set in the copy. */ err = snd_ctl_add(card, kctl); if (err < 0) return err; switch (idx) { case ACTIVE_IDX: setup->active_id = kctl->id; break; case FORMAT_IDX: setup->format_id = kctl->id; break; case RATE_IDX: setup->rate_id = kctl->id; break; case CHANNELS_IDX: setup->channels_id = kctl->id; break; default: break; } } } } return 0; } static void print_dpcm_info(struct snd_info_buffer *buffer, struct loopback_pcm *dpcm, const char *id) { snd_iprintf(buffer, " %s\n", id); if (dpcm == NULL) { snd_iprintf(buffer, " inactive\n"); return; } snd_iprintf(buffer, " buffer_size:\t%u\n", dpcm->pcm_buffer_size); snd_iprintf(buffer, " buffer_pos:\t\t%u\n", dpcm->buf_pos); snd_iprintf(buffer, " silent_size:\t%u\n", dpcm->silent_size); snd_iprintf(buffer, " period_size:\t%u\n", dpcm->pcm_period_size); snd_iprintf(buffer, " bytes_per_sec:\t%u\n", dpcm->pcm_bps); snd_iprintf(buffer, " sample_align:\t%u\n", dpcm->pcm_salign); snd_iprintf(buffer, " rate_shift:\t\t%u\n", dpcm->pcm_rate_shift); if (dpcm->cable->ops->dpcm_info) dpcm->cable->ops->dpcm_info(dpcm, buffer); } static void print_substream_info(struct snd_info_buffer *buffer, struct loopback *loopback, int sub, int num) { struct loopback_cable *cable = loopback->cables[sub][num]; snd_iprintf(buffer, "Cable %i substream %i:\n", num, sub); if (cable == NULL) { snd_iprintf(buffer, " inactive\n"); return; } snd_iprintf(buffer, " valid: %u\n", cable->valid); snd_iprintf(buffer, " running: %u\n", cable->running); snd_iprintf(buffer, " pause: %u\n", cable->pause); print_dpcm_info(buffer, cable->streams[0], "Playback"); print_dpcm_info(buffer, cable->streams[1], "Capture"); } static void print_cable_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct loopback *loopback = entry->private_data; int sub, num; mutex_lock(&loopback->cable_lock); num = entry->name[strlen(entry->name)-1]; num = num == '0' ? 0 : 1; for (sub = 0; sub < MAX_PCM_SUBSTREAMS; sub++) print_substream_info(buffer, loopback, sub, num); mutex_unlock(&loopback->cable_lock); } static int loopback_cable_proc_new(struct loopback *loopback, int cidx) { char name[32]; snprintf(name, sizeof(name), "cable#%d", cidx); return snd_card_ro_proc_new(loopback->card, name, loopback, print_cable_info); } static void loopback_set_timer_source(struct loopback *loopback, const char *value) { if (loopback->timer_source) { devm_kfree(loopback->card->dev, loopback->timer_source); loopback->timer_source = NULL; } if (value && *value) loopback->timer_source = devm_kstrdup(loopback->card->dev, value, GFP_KERNEL); } static void print_timer_source_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct loopback *loopback = entry->private_data; mutex_lock(&loopback->cable_lock); snd_iprintf(buffer, "%s\n", loopback->timer_source ? loopback->timer_source : ""); mutex_unlock(&loopback->cable_lock); } static void change_timer_source_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct loopback *loopback = entry->private_data; char line[64]; mutex_lock(&loopback->cable_lock); if (!snd_info_get_line(buffer, line, sizeof(line))) loopback_set_timer_source(loopback, strim(line)); mutex_unlock(&loopback->cable_lock); } static int loopback_timer_source_proc_new(struct loopback *loopback) { return snd_card_rw_proc_new(loopback->card, "timer_source", loopback, print_timer_source_info, change_timer_source_info); } static int loopback_probe(struct platform_device *devptr) { struct snd_card *card; struct loopback *loopback; int dev = devptr->id; int err; err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, sizeof(struct loopback), &card); if (err < 0) return err; loopback = card->private_data; if (pcm_substreams[dev] < 1) pcm_substreams[dev] = 1; if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS) pcm_substreams[dev] = MAX_PCM_SUBSTREAMS; loopback->card = card; loopback_set_timer_source(loopback, timer_source[dev]); mutex_init(&loopback->cable_lock); err = loopback_pcm_new(loopback, 0, pcm_substreams[dev]); if (err < 0) return err; err = loopback_pcm_new(loopback, 1, pcm_substreams[dev]); if (err < 0) return err; err = loopback_mixer_new(loopback, pcm_notify[dev] ? 1 : 0); if (err < 0) return err; loopback_cable_proc_new(loopback, 0); loopback_cable_proc_new(loopback, 1); loopback_timer_source_proc_new(loopback); strcpy(card->driver, "Loopback"); strcpy(card->shortname, "Loopback"); sprintf(card->longname, "Loopback %i", dev + 1); err = snd_card_register(card); if (err < 0) return err; platform_set_drvdata(devptr, card); return 0; } #ifdef CONFIG_PM_SLEEP static int loopback_suspend(struct device *pdev) { struct snd_card *card = dev_get_drvdata(pdev); snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); return 0; } static int loopback_resume(struct device *pdev) { struct snd_card *card = dev_get_drvdata(pdev); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } static SIMPLE_DEV_PM_OPS(loopback_pm, loopback_suspend, loopback_resume); #define LOOPBACK_PM_OPS &loopback_pm #else #define LOOPBACK_PM_OPS NULL #endif #define SND_LOOPBACK_DRIVER "snd_aloop" static struct platform_driver loopback_driver = { .probe = loopback_probe, .driver = { .name = SND_LOOPBACK_DRIVER, .pm = LOOPBACK_PM_OPS, }, }; static void loopback_unregister_all(void) { int i; for (i = 0; i < ARRAY_SIZE(devices); ++i) platform_device_unregister(devices[i]); platform_driver_unregister(&loopback_driver); } static int __init alsa_card_loopback_init(void) { int i, err, cards; err = platform_driver_register(&loopback_driver); if (err < 0) return err; cards = 0; for (i = 0; i < SNDRV_CARDS; i++) { struct platform_device *device; if (!enable[i]) continue; device = platform_device_register_simple(SND_LOOPBACK_DRIVER, i, NULL, 0); if (IS_ERR(device)) continue; if (!platform_get_drvdata(device)) { platform_device_unregister(device); continue; } devices[i] = device; cards++; } if (!cards) { #ifdef MODULE printk(KERN_ERR "aloop: No loopback enabled\n"); #endif loopback_unregister_all(); return -ENODEV; } return 0; } static void __exit alsa_card_loopback_exit(void) { loopback_unregister_all(); } module_init(alsa_card_loopback_init) module_exit(alsa_card_loopback_exit)
linux-master
sound/drivers/aloop.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * serial.c * Copyright (c) by Jaroslav Kysela <[email protected]>, * Isaku Yamahata <[email protected]>, * George Hansper <[email protected]>, * Hannu Savolainen * * This code is based on the code from ALSA 0.5.9, but heavily rewritten. * * Sat Mar 31 17:27:57 PST 2001 [email protected] * Added support for the Midiator MS-124T and for the MS-124W in * Single Addressed (S/A) or Multiple Burst (M/B) mode, with * power derived either parasitically from the serial port or * from a separate power supply. * * More documentation can be found in serial-u16550.txt. */ #include <linux/init.h> #include <linux/interrupt.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/slab.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/io.h> #include <sound/core.h> #include <sound/rawmidi.h> #include <sound/initval.h> #include <linux/serial_reg.h> #include <linux/jiffies.h> MODULE_DESCRIPTION("MIDI serial u16550"); MODULE_LICENSE("GPL"); #define SNDRV_SERIAL_SOUNDCANVAS 0 /* Roland Soundcanvas; F5 NN selects part */ #define SNDRV_SERIAL_MS124T 1 /* Midiator MS-124T */ #define SNDRV_SERIAL_MS124W_SA 2 /* Midiator MS-124W in S/A mode */ #define SNDRV_SERIAL_MS124W_MB 3 /* Midiator MS-124W in M/B mode */ #define SNDRV_SERIAL_GENERIC 4 /* Generic Interface */ #define SNDRV_SERIAL_MAX_ADAPTOR SNDRV_SERIAL_GENERIC static const char * const adaptor_names[] = { "Soundcanvas", "MS-124T", "MS-124W S/A", "MS-124W M/B", "Generic" }; #define SNDRV_SERIAL_NORMALBUFF 0 /* Normal blocking buffer operation */ #define SNDRV_SERIAL_DROPBUFF 1 /* Non-blocking discard operation */ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x3f8,0x2f8,0x3e8,0x2e8 */ static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,4,5,7,9,10,11,14,15 */ static int speed[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 38400}; /* 9600,19200,38400,57600,115200 */ static int base[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 115200}; /* baud base */ static int outs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; /* 1 to 16 */ static int ins[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; /* 1 to 16 */ static int adaptor[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = SNDRV_SERIAL_SOUNDCANVAS}; static bool droponfull[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS -1)] = SNDRV_SERIAL_NORMALBUFF }; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for Serial MIDI."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for Serial MIDI."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable UART16550A chip."); module_param_hw_array(port, long, ioport, NULL, 0444); MODULE_PARM_DESC(port, "Port # for UART16550A chip."); module_param_hw_array(irq, int, irq, NULL, 0444); MODULE_PARM_DESC(irq, "IRQ # for UART16550A chip."); module_param_array(speed, int, NULL, 0444); MODULE_PARM_DESC(speed, "Speed in bauds."); module_param_array(base, int, NULL, 0444); MODULE_PARM_DESC(base, "Base for divisor in bauds."); module_param_array(outs, int, NULL, 0444); MODULE_PARM_DESC(outs, "Number of MIDI outputs."); module_param_array(ins, int, NULL, 0444); MODULE_PARM_DESC(ins, "Number of MIDI inputs."); module_param_array(droponfull, bool, NULL, 0444); MODULE_PARM_DESC(droponfull, "Flag to enable drop-on-full buffer mode"); module_param_array(adaptor, int, NULL, 0444); MODULE_PARM_DESC(adaptor, "Type of adaptor."); /*#define SNDRV_SERIAL_MS124W_MB_NOCOMBO 1*/ /* Address outs as 0-3 instead of bitmap */ #define SNDRV_SERIAL_MAX_OUTS 16 /* max 64, min 16 */ #define SNDRV_SERIAL_MAX_INS 16 /* max 64, min 16 */ #define TX_BUFF_SIZE (1<<15) /* Must be 2^n */ #define TX_BUFF_MASK (TX_BUFF_SIZE - 1) #define SERIAL_MODE_NOT_OPENED (0) #define SERIAL_MODE_INPUT_OPEN (1 << 0) #define SERIAL_MODE_OUTPUT_OPEN (1 << 1) #define SERIAL_MODE_INPUT_TRIGGERED (1 << 2) #define SERIAL_MODE_OUTPUT_TRIGGERED (1 << 3) struct snd_uart16550 { struct snd_card *card; struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *midi_output[SNDRV_SERIAL_MAX_OUTS]; struct snd_rawmidi_substream *midi_input[SNDRV_SERIAL_MAX_INS]; int filemode; /* open status of file */ spinlock_t open_lock; int irq; unsigned long base; unsigned int speed; unsigned int speed_base; unsigned char divisor; unsigned char old_divisor_lsb; unsigned char old_divisor_msb; unsigned char old_line_ctrl_reg; /* parameter for using of write loop */ short int fifo_limit; /* used in uart16550 */ short int fifo_count; /* used in uart16550 */ /* type of adaptor */ int adaptor; /* inputs */ int prev_in; unsigned char rstatus; /* outputs */ int prev_out; unsigned char prev_status[SNDRV_SERIAL_MAX_OUTS]; /* write buffer and its writing/reading position */ unsigned char tx_buff[TX_BUFF_SIZE]; int buff_in_count; int buff_in; int buff_out; int drop_on_full; /* wait timer */ unsigned int timer_running:1; struct timer_list buffer_timer; }; static struct platform_device *devices[SNDRV_CARDS]; static inline void snd_uart16550_add_timer(struct snd_uart16550 *uart) { if (!uart->timer_running) { /* timer 38600bps * 10bit * 16byte */ mod_timer(&uart->buffer_timer, jiffies + (HZ + 255) / 256); uart->timer_running = 1; } } static inline void snd_uart16550_del_timer(struct snd_uart16550 *uart) { if (uart->timer_running) { del_timer(&uart->buffer_timer); uart->timer_running = 0; } } /* This macro is only used in snd_uart16550_io_loop */ static inline void snd_uart16550_buffer_output(struct snd_uart16550 *uart) { unsigned short buff_out = uart->buff_out; if (uart->buff_in_count > 0) { outb(uart->tx_buff[buff_out], uart->base + UART_TX); uart->fifo_count++; buff_out++; buff_out &= TX_BUFF_MASK; uart->buff_out = buff_out; uart->buff_in_count--; } } /* This loop should be called with interrupts disabled * We don't want to interrupt this, * as we're already handling an interrupt */ static void snd_uart16550_io_loop(struct snd_uart16550 * uart) { unsigned char c, status; int substream; /* recall previous stream */ substream = uart->prev_in; /* Read Loop */ while ((status = inb(uart->base + UART_LSR)) & UART_LSR_DR) { /* while receive data ready */ c = inb(uart->base + UART_RX); /* keep track of last status byte */ if (c & 0x80) uart->rstatus = c; /* handle stream switch */ if (uart->adaptor == SNDRV_SERIAL_GENERIC) { if (uart->rstatus == 0xf5) { if (c <= SNDRV_SERIAL_MAX_INS && c > 0) substream = c - 1; if (c != 0xf5) /* prevent future bytes from being interpreted as streams */ uart->rstatus = 0; } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) && uart->midi_input[substream]) snd_rawmidi_receive(uart->midi_input[substream], &c, 1); } else if ((uart->filemode & SERIAL_MODE_INPUT_OPEN) && uart->midi_input[substream]) snd_rawmidi_receive(uart->midi_input[substream], &c, 1); if (status & UART_LSR_OE) snd_printk(KERN_WARNING "%s: Overrun on device at 0x%lx\n", uart->rmidi->name, uart->base); } /* remember the last stream */ uart->prev_in = substream; /* no need of check SERIAL_MODE_OUTPUT_OPEN because if not, buffer is never filled. */ /* Check write status */ if (status & UART_LSR_THRE) uart->fifo_count = 0; if (uart->adaptor == SNDRV_SERIAL_MS124W_SA || uart->adaptor == SNDRV_SERIAL_GENERIC) { /* Can't use FIFO, must send only when CTS is true */ status = inb(uart->base + UART_MSR); while (uart->fifo_count == 0 && (status & UART_MSR_CTS) && uart->buff_in_count > 0) { snd_uart16550_buffer_output(uart); status = inb(uart->base + UART_MSR); } } else { /* Write loop */ while (uart->fifo_count < uart->fifo_limit /* Can we write ? */ && uart->buff_in_count > 0) /* Do we want to? */ snd_uart16550_buffer_output(uart); } if (uart->irq < 0 && uart->buff_in_count > 0) snd_uart16550_add_timer(uart); } /* NOTES ON SERVICING INTERUPTS * --------------------------- * After receiving a interrupt, it is important to indicate to the UART that * this has been done. * For a Rx interrupt, this is done by reading the received byte. * For a Tx interrupt this is done by either: * a) Writing a byte * b) Reading the IIR * It is particularly important to read the IIR if a Tx interrupt is received * when there is no data in tx_buff[], as in this case there no other * indication that the interrupt has been serviced, and it remains outstanding * indefinitely. This has the curious side effect that and no further interrupts * will be generated from this device AT ALL!!. * It is also desirable to clear outstanding interrupts when the device is * opened/closed. * * * Note that some devices need OUT2 to be set before they will generate * interrupts at all. (Possibly tied to an internal pull-up on CTS?) */ static irqreturn_t snd_uart16550_interrupt(int irq, void *dev_id) { struct snd_uart16550 *uart; uart = dev_id; spin_lock(&uart->open_lock); if (uart->filemode == SERIAL_MODE_NOT_OPENED) { spin_unlock(&uart->open_lock); return IRQ_NONE; } /* indicate to the UART that the interrupt has been serviced */ inb(uart->base + UART_IIR); snd_uart16550_io_loop(uart); spin_unlock(&uart->open_lock); return IRQ_HANDLED; } /* When the polling mode, this function calls snd_uart16550_io_loop. */ static void snd_uart16550_buffer_timer(struct timer_list *t) { unsigned long flags; struct snd_uart16550 *uart; uart = from_timer(uart, t, buffer_timer); spin_lock_irqsave(&uart->open_lock, flags); snd_uart16550_del_timer(uart); snd_uart16550_io_loop(uart); spin_unlock_irqrestore(&uart->open_lock, flags); } /* * this method probes, if an uart sits on given port * return 0 if found * return negative error if not found */ static int snd_uart16550_detect(struct snd_uart16550 *uart) { unsigned long io_base = uart->base; int ok; unsigned char c; /* Do some vague tests for the presence of the uart */ if (io_base == 0 || io_base == SNDRV_AUTO_PORT) { return -ENODEV; /* Not configured */ } if (!devm_request_region(uart->card->dev, io_base, 8, "Serial MIDI")) { snd_printk(KERN_ERR "u16550: can't grab port 0x%lx\n", io_base); return -EBUSY; } /* uart detected unless one of the following tests should fail */ ok = 1; /* 8 data-bits, 1 stop-bit, parity off, DLAB = 0 */ outb(UART_LCR_WLEN8, io_base + UART_LCR); /* Line Control Register */ c = inb(io_base + UART_IER); /* The top four bits of the IER should always == 0 */ if ((c & 0xf0) != 0) ok = 0; /* failed */ outb(0xaa, io_base + UART_SCR); /* Write arbitrary data into the scratch reg */ c = inb(io_base + UART_SCR); /* If it comes back, it's OK */ if (c != 0xaa) ok = 0; /* failed */ outb(0x55, io_base + UART_SCR); /* Write arbitrary data into the scratch reg */ c = inb(io_base + UART_SCR); /* If it comes back, it's OK */ if (c != 0x55) ok = 0; /* failed */ return ok; } static void snd_uart16550_do_open(struct snd_uart16550 * uart) { char byte; /* Initialize basic variables */ uart->buff_in_count = 0; uart->buff_in = 0; uart->buff_out = 0; uart->fifo_limit = 1; uart->fifo_count = 0; uart->timer_running = 0; outb(UART_FCR_ENABLE_FIFO /* Enable FIFO's (if available) */ | UART_FCR_CLEAR_RCVR /* Clear receiver FIFO */ | UART_FCR_CLEAR_XMIT /* Clear transmitter FIFO */ | UART_FCR_TRIGGER_4 /* Set FIFO trigger at 4-bytes */ /* NOTE: interrupt generated after T=(time)4-bytes * if less than UART_FCR_TRIGGER bytes received */ ,uart->base + UART_FCR); /* FIFO Control Register */ if ((inb(uart->base + UART_IIR) & 0xf0) == 0xc0) uart->fifo_limit = 16; if (uart->divisor != 0) { uart->old_line_ctrl_reg = inb(uart->base + UART_LCR); outb(UART_LCR_DLAB /* Divisor latch access bit */ ,uart->base + UART_LCR); /* Line Control Register */ uart->old_divisor_lsb = inb(uart->base + UART_DLL); uart->old_divisor_msb = inb(uart->base + UART_DLM); outb(uart->divisor ,uart->base + UART_DLL); /* Divisor Latch Low */ outb(0 ,uart->base + UART_DLM); /* Divisor Latch High */ /* DLAB is reset to 0 in next outb() */ } /* Set serial parameters (parity off, etc) */ outb(UART_LCR_WLEN8 /* 8 data-bits */ | 0 /* 1 stop-bit */ | 0 /* parity off */ | 0 /* DLAB = 0 */ ,uart->base + UART_LCR); /* Line Control Register */ switch (uart->adaptor) { default: outb(UART_MCR_RTS /* Set Request-To-Send line active */ | UART_MCR_DTR /* Set Data-Terminal-Ready line active */ | UART_MCR_OUT2 /* Set OUT2 - not always required, but when * it is, it is ESSENTIAL for enabling interrupts */ ,uart->base + UART_MCR); /* Modem Control Register */ break; case SNDRV_SERIAL_MS124W_SA: case SNDRV_SERIAL_MS124W_MB: /* MS-124W can draw power from RTS and DTR if they are in opposite states. */ outb(UART_MCR_RTS | (0&UART_MCR_DTR) | UART_MCR_OUT2, uart->base + UART_MCR); break; case SNDRV_SERIAL_MS124T: /* MS-124T can draw power from RTS and/or DTR (preferably both) if they are both asserted. */ outb(UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2, uart->base + UART_MCR); break; } if (uart->irq < 0) { byte = (0 & UART_IER_RDI) /* Disable Receiver data interrupt */ |(0 & UART_IER_THRI) /* Disable Transmitter holding register empty interrupt */ ; } else if (uart->adaptor == SNDRV_SERIAL_MS124W_SA) { byte = UART_IER_RDI /* Enable Receiver data interrupt */ | UART_IER_MSI /* Enable Modem status interrupt */ ; } else if (uart->adaptor == SNDRV_SERIAL_GENERIC) { byte = UART_IER_RDI /* Enable Receiver data interrupt */ | UART_IER_MSI /* Enable Modem status interrupt */ | UART_IER_THRI /* Enable Transmitter holding register empty interrupt */ ; } else { byte = UART_IER_RDI /* Enable Receiver data interrupt */ | UART_IER_THRI /* Enable Transmitter holding register empty interrupt */ ; } outb(byte, uart->base + UART_IER); /* Interrupt enable Register */ inb(uart->base + UART_LSR); /* Clear any pre-existing overrun indication */ inb(uart->base + UART_IIR); /* Clear any pre-existing transmit interrupt */ inb(uart->base + UART_RX); /* Clear any pre-existing receive interrupt */ } static void snd_uart16550_do_close(struct snd_uart16550 * uart) { if (uart->irq < 0) snd_uart16550_del_timer(uart); /* NOTE: may need to disable interrupts before de-registering out handler. * For now, the consequences are harmless. */ outb((0 & UART_IER_RDI) /* Disable Receiver data interrupt */ |(0 & UART_IER_THRI) /* Disable Transmitter holding register empty interrupt */ ,uart->base + UART_IER); /* Interrupt enable Register */ switch (uart->adaptor) { default: outb((0 & UART_MCR_RTS) /* Deactivate Request-To-Send line */ |(0 & UART_MCR_DTR) /* Deactivate Data-Terminal-Ready line */ |(0 & UART_MCR_OUT2) /* Deactivate OUT2 */ ,uart->base + UART_MCR); /* Modem Control Register */ break; case SNDRV_SERIAL_MS124W_SA: case SNDRV_SERIAL_MS124W_MB: /* MS-124W can draw power from RTS and DTR if they are in opposite states; leave it powered. */ outb(UART_MCR_RTS | (0&UART_MCR_DTR) | (0&UART_MCR_OUT2), uart->base + UART_MCR); break; case SNDRV_SERIAL_MS124T: /* MS-124T can draw power from RTS and/or DTR (preferably both) if they are both asserted; leave it powered. */ outb(UART_MCR_RTS | UART_MCR_DTR | (0&UART_MCR_OUT2), uart->base + UART_MCR); break; } inb(uart->base + UART_IIR); /* Clear any outstanding interrupts */ /* Restore old divisor */ if (uart->divisor != 0) { outb(UART_LCR_DLAB /* Divisor latch access bit */ ,uart->base + UART_LCR); /* Line Control Register */ outb(uart->old_divisor_lsb ,uart->base + UART_DLL); /* Divisor Latch Low */ outb(uart->old_divisor_msb ,uart->base + UART_DLM); /* Divisor Latch High */ /* Restore old LCR (data bits, stop bits, parity, DLAB) */ outb(uart->old_line_ctrl_reg ,uart->base + UART_LCR); /* Line Control Register */ } } static int snd_uart16550_input_open(struct snd_rawmidi_substream *substream) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); if (uart->filemode == SERIAL_MODE_NOT_OPENED) snd_uart16550_do_open(uart); uart->filemode |= SERIAL_MODE_INPUT_OPEN; uart->midi_input[substream->number] = substream; spin_unlock_irqrestore(&uart->open_lock, flags); return 0; } static int snd_uart16550_input_close(struct snd_rawmidi_substream *substream) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); uart->filemode &= ~SERIAL_MODE_INPUT_OPEN; uart->midi_input[substream->number] = NULL; if (uart->filemode == SERIAL_MODE_NOT_OPENED) snd_uart16550_do_close(uart); spin_unlock_irqrestore(&uart->open_lock, flags); return 0; } static void snd_uart16550_input_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); if (up) uart->filemode |= SERIAL_MODE_INPUT_TRIGGERED; else uart->filemode &= ~SERIAL_MODE_INPUT_TRIGGERED; spin_unlock_irqrestore(&uart->open_lock, flags); } static int snd_uart16550_output_open(struct snd_rawmidi_substream *substream) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); if (uart->filemode == SERIAL_MODE_NOT_OPENED) snd_uart16550_do_open(uart); uart->filemode |= SERIAL_MODE_OUTPUT_OPEN; uart->midi_output[substream->number] = substream; spin_unlock_irqrestore(&uart->open_lock, flags); return 0; }; static int snd_uart16550_output_close(struct snd_rawmidi_substream *substream) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); uart->filemode &= ~SERIAL_MODE_OUTPUT_OPEN; uart->midi_output[substream->number] = NULL; if (uart->filemode == SERIAL_MODE_NOT_OPENED) snd_uart16550_do_close(uart); spin_unlock_irqrestore(&uart->open_lock, flags); return 0; }; static inline int snd_uart16550_buffer_can_write(struct snd_uart16550 *uart, int Num) { if (uart->buff_in_count + Num < TX_BUFF_SIZE) return 1; else return 0; } static inline int snd_uart16550_write_buffer(struct snd_uart16550 *uart, unsigned char byte) { unsigned short buff_in = uart->buff_in; if (uart->buff_in_count < TX_BUFF_SIZE) { uart->tx_buff[buff_in] = byte; buff_in++; buff_in &= TX_BUFF_MASK; uart->buff_in = buff_in; uart->buff_in_count++; if (uart->irq < 0) /* polling mode */ snd_uart16550_add_timer(uart); return 1; } else return 0; } static int snd_uart16550_output_byte(struct snd_uart16550 *uart, struct snd_rawmidi_substream *substream, unsigned char midi_byte) { if (uart->buff_in_count == 0 /* Buffer empty? */ && ((uart->adaptor != SNDRV_SERIAL_MS124W_SA && uart->adaptor != SNDRV_SERIAL_GENERIC) || (uart->fifo_count == 0 /* FIFO empty? */ && (inb(uart->base + UART_MSR) & UART_MSR_CTS)))) { /* CTS? */ /* Tx Buffer Empty - try to write immediately */ if ((inb(uart->base + UART_LSR) & UART_LSR_THRE) != 0) { /* Transmitter holding register (and Tx FIFO) empty */ uart->fifo_count = 1; outb(midi_byte, uart->base + UART_TX); } else { if (uart->fifo_count < uart->fifo_limit) { uart->fifo_count++; outb(midi_byte, uart->base + UART_TX); } else { /* Cannot write (buffer empty) - * put char in buffer */ snd_uart16550_write_buffer(uart, midi_byte); } } } else { if (!snd_uart16550_write_buffer(uart, midi_byte)) { snd_printk(KERN_WARNING "%s: Buffer overrun on device at 0x%lx\n", uart->rmidi->name, uart->base); return 0; } } return 1; } static void snd_uart16550_output_write(struct snd_rawmidi_substream *substream) { unsigned long flags; unsigned char midi_byte, addr_byte; struct snd_uart16550 *uart = substream->rmidi->private_data; char first; static unsigned long lasttime = 0; /* Interrupts are disabled during the updating of the tx_buff, * since it is 'bad' to have two processes updating the same * variables (ie buff_in & buff_out) */ spin_lock_irqsave(&uart->open_lock, flags); if (uart->irq < 0) /* polling */ snd_uart16550_io_loop(uart); if (uart->adaptor == SNDRV_SERIAL_MS124W_MB) { while (1) { /* buffer full? */ /* in this mode we need two bytes of space */ if (uart->buff_in_count > TX_BUFF_SIZE - 2) break; if (snd_rawmidi_transmit(substream, &midi_byte, 1) != 1) break; #ifdef SNDRV_SERIAL_MS124W_MB_NOCOMBO /* select exactly one of the four ports */ addr_byte = (1 << (substream->number + 4)) | 0x08; #else /* select any combination of the four ports */ addr_byte = (substream->number << 4) | 0x08; /* ...except none */ if (addr_byte == 0x08) addr_byte = 0xf8; #endif snd_uart16550_output_byte(uart, substream, addr_byte); /* send midi byte */ snd_uart16550_output_byte(uart, substream, midi_byte); } } else { first = 0; while (snd_rawmidi_transmit_peek(substream, &midi_byte, 1) == 1) { /* Also send F5 after 3 seconds with no data * to handle device disconnect */ if (first == 0 && (uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS || uart->adaptor == SNDRV_SERIAL_GENERIC) && (uart->prev_out != substream->number || time_after(jiffies, lasttime + 3*HZ))) { if (snd_uart16550_buffer_can_write(uart, 3)) { /* Roland Soundcanvas part selection */ /* If this substream of the data is * different previous substream * in this uart, send the change part * event */ uart->prev_out = substream->number; /* change part */ snd_uart16550_output_byte(uart, substream, 0xf5); /* data */ snd_uart16550_output_byte(uart, substream, uart->prev_out + 1); /* If midi_byte is a data byte, * send the previous status byte */ if (midi_byte < 0x80 && uart->adaptor == SNDRV_SERIAL_SOUNDCANVAS) snd_uart16550_output_byte(uart, substream, uart->prev_status[uart->prev_out]); } else if (!uart->drop_on_full) break; } /* send midi byte */ if (!snd_uart16550_output_byte(uart, substream, midi_byte) && !uart->drop_on_full ) break; if (midi_byte >= 0x80 && midi_byte < 0xf0) uart->prev_status[uart->prev_out] = midi_byte; first = 1; snd_rawmidi_transmit_ack( substream, 1 ); } lasttime = jiffies; } spin_unlock_irqrestore(&uart->open_lock, flags); } static void snd_uart16550_output_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_uart16550 *uart = substream->rmidi->private_data; spin_lock_irqsave(&uart->open_lock, flags); if (up) uart->filemode |= SERIAL_MODE_OUTPUT_TRIGGERED; else uart->filemode &= ~SERIAL_MODE_OUTPUT_TRIGGERED; spin_unlock_irqrestore(&uart->open_lock, flags); if (up) snd_uart16550_output_write(substream); } static const struct snd_rawmidi_ops snd_uart16550_output = { .open = snd_uart16550_output_open, .close = snd_uart16550_output_close, .trigger = snd_uart16550_output_trigger, }; static const struct snd_rawmidi_ops snd_uart16550_input = { .open = snd_uart16550_input_open, .close = snd_uart16550_input_close, .trigger = snd_uart16550_input_trigger, }; static int snd_uart16550_create(struct snd_card *card, unsigned long iobase, int irq, unsigned int speed, unsigned int base, int adaptor, int droponfull, struct snd_uart16550 **ruart) { struct snd_uart16550 *uart; int err; uart = devm_kzalloc(card->dev, sizeof(*uart), GFP_KERNEL); if (!uart) return -ENOMEM; uart->adaptor = adaptor; uart->card = card; spin_lock_init(&uart->open_lock); uart->irq = -1; uart->base = iobase; uart->drop_on_full = droponfull; err = snd_uart16550_detect(uart); if (err <= 0) { printk(KERN_ERR "no UART detected at 0x%lx\n", iobase); return -ENODEV; } if (irq >= 0 && irq != SNDRV_AUTO_IRQ) { if (devm_request_irq(card->dev, irq, snd_uart16550_interrupt, 0, "Serial MIDI", uart)) { snd_printk(KERN_WARNING "irq %d busy. Using Polling.\n", irq); } else { uart->irq = irq; } } uart->divisor = base / speed; uart->speed = base / (unsigned int)uart->divisor; uart->speed_base = base; uart->prev_out = -1; uart->prev_in = 0; uart->rstatus = 0; memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS); timer_setup(&uart->buffer_timer, snd_uart16550_buffer_timer, 0); uart->timer_running = 0; switch (uart->adaptor) { case SNDRV_SERIAL_MS124W_SA: case SNDRV_SERIAL_MS124W_MB: /* MS-124W can draw power from RTS and DTR if they are in opposite states. */ outb(UART_MCR_RTS | (0&UART_MCR_DTR), uart->base + UART_MCR); break; case SNDRV_SERIAL_MS124T: /* MS-124T can draw power from RTS and/or DTR (preferably both) if they are asserted. */ outb(UART_MCR_RTS | UART_MCR_DTR, uart->base + UART_MCR); break; default: break; } if (ruart) *ruart = uart; return 0; } static void snd_uart16550_substreams(struct snd_rawmidi_str *stream) { struct snd_rawmidi_substream *substream; list_for_each_entry(substream, &stream->substreams, list) { sprintf(substream->name, "Serial MIDI %d", substream->number + 1); } } static int snd_uart16550_rmidi(struct snd_uart16550 *uart, int device, int outs, int ins, struct snd_rawmidi **rmidi) { struct snd_rawmidi *rrawmidi; int err; err = snd_rawmidi_new(uart->card, "UART Serial MIDI", device, outs, ins, &rrawmidi); if (err < 0) return err; snd_rawmidi_set_ops(rrawmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_uart16550_input); snd_rawmidi_set_ops(rrawmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_uart16550_output); strcpy(rrawmidi->name, "Serial MIDI"); snd_uart16550_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); snd_uart16550_substreams(&rrawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]); rrawmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX; rrawmidi->private_data = uart; if (rmidi) *rmidi = rrawmidi; return 0; } static int snd_serial_probe(struct platform_device *devptr) { struct snd_card *card; struct snd_uart16550 *uart; int err; int dev = devptr->id; switch (adaptor[dev]) { case SNDRV_SERIAL_SOUNDCANVAS: ins[dev] = 1; break; case SNDRV_SERIAL_MS124T: case SNDRV_SERIAL_MS124W_SA: outs[dev] = 1; ins[dev] = 1; break; case SNDRV_SERIAL_MS124W_MB: outs[dev] = 16; ins[dev] = 1; break; case SNDRV_SERIAL_GENERIC: break; default: snd_printk(KERN_ERR "Adaptor type is out of range 0-%d (%d)\n", SNDRV_SERIAL_MAX_ADAPTOR, adaptor[dev]); return -ENODEV; } if (outs[dev] < 1 || outs[dev] > SNDRV_SERIAL_MAX_OUTS) { snd_printk(KERN_ERR "Count of outputs is out of range 1-%d (%d)\n", SNDRV_SERIAL_MAX_OUTS, outs[dev]); return -ENODEV; } if (ins[dev] < 1 || ins[dev] > SNDRV_SERIAL_MAX_INS) { snd_printk(KERN_ERR "Count of inputs is out of range 1-%d (%d)\n", SNDRV_SERIAL_MAX_INS, ins[dev]); return -ENODEV; } err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, 0, &card); if (err < 0) return err; strcpy(card->driver, "Serial"); strcpy(card->shortname, "Serial MIDI (UART16550A)"); err = snd_uart16550_create(card, port[dev], irq[dev], speed[dev], base[dev], adaptor[dev], droponfull[dev], &uart); if (err < 0) return err; err = snd_uart16550_rmidi(uart, 0, outs[dev], ins[dev], &uart->rmidi); if (err < 0) return err; sprintf(card->longname, "%s [%s] at %#lx, irq %d", card->shortname, adaptor_names[uart->adaptor], uart->base, uart->irq); err = snd_card_register(card); if (err < 0) return err; platform_set_drvdata(devptr, card); return 0; } #define SND_SERIAL_DRIVER "snd_serial_u16550" static struct platform_driver snd_serial_driver = { .probe = snd_serial_probe, .driver = { .name = SND_SERIAL_DRIVER, }, }; static void snd_serial_unregister_all(void) { int i; for (i = 0; i < ARRAY_SIZE(devices); ++i) platform_device_unregister(devices[i]); platform_driver_unregister(&snd_serial_driver); } static int __init alsa_card_serial_init(void) { int i, cards, err; err = platform_driver_register(&snd_serial_driver); if (err < 0) return err; cards = 0; for (i = 0; i < SNDRV_CARDS; i++) { struct platform_device *device; if (! enable[i]) continue; device = platform_device_register_simple(SND_SERIAL_DRIVER, i, NULL, 0); if (IS_ERR(device)) continue; if (!platform_get_drvdata(device)) { platform_device_unregister(device); continue; } devices[i] = device; cards++; } if (! cards) { #ifdef MODULE printk(KERN_ERR "serial midi soundcard not found or device busy\n"); #endif snd_serial_unregister_all(); return -ENODEV; } return 0; } static void __exit alsa_card_serial_exit(void) { snd_serial_unregister_all(); } module_init(alsa_card_serial_init) module_exit(alsa_card_serial_exit)
linux-master
sound/drivers/serial-u16550.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Dummy soundcard for virtual rawmidi devices * * Copyright (c) 2000 by Takashi Iwai <[email protected]> */ /* * VIRTUAL RAW MIDI DEVICE CARDS * * This dummy card contains up to 4 virtual rawmidi devices. * They are not real rawmidi devices but just associated with sequencer * clients, so that any input/output sources can be connected as a raw * MIDI device arbitrary. * Also, multiple access is allowed to a single rawmidi device. * * Typical usage is like following: * - Load snd-virmidi module. * # modprobe snd-virmidi index=2 * Then, sequencer clients 72:0 to 75:0 will be created, which are * mapped from /dev/snd/midiC1D0 to /dev/snd/midiC1D3, respectively. * * - Connect input/output via aconnect. * % aconnect 64:0 72:0 # keyboard input redirection 64:0 -> 72:0 * % aconnect 72:0 65:0 # output device redirection 72:0 -> 65:0 * * - Run application using a midi device (eg. /dev/snd/midiC1D0) */ #include <linux/init.h> #include <linux/wait.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/module.h> #include <sound/core.h> #include <sound/seq_kernel.h> #include <sound/seq_virmidi.h> #include <sound/initval.h> /* hack: OSS defines midi_devs, so undefine it (versioned symbols) */ #undef midi_devs MODULE_AUTHOR("Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("Dummy soundcard for virtual rawmidi devices"); MODULE_LICENSE("GPL"); #define MAX_MIDI_DEVICES 4 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4}; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for virmidi soundcard."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for virmidi soundcard."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable this soundcard."); module_param_array(midi_devs, int, NULL, 0444); MODULE_PARM_DESC(midi_devs, "MIDI devices # (1-4)"); struct snd_card_virmidi { struct snd_card *card; struct snd_rawmidi *midi[MAX_MIDI_DEVICES]; }; static struct platform_device *devices[SNDRV_CARDS]; static int snd_virmidi_probe(struct platform_device *devptr) { struct snd_card *card; struct snd_card_virmidi *vmidi; int idx, err; int dev = devptr->id; err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, sizeof(struct snd_card_virmidi), &card); if (err < 0) return err; vmidi = card->private_data; vmidi->card = card; if (midi_devs[dev] > MAX_MIDI_DEVICES) { snd_printk(KERN_WARNING "too much midi devices for virmidi %d: force to use %d\n", dev, MAX_MIDI_DEVICES); midi_devs[dev] = MAX_MIDI_DEVICES; } for (idx = 0; idx < midi_devs[dev]; idx++) { struct snd_rawmidi *rmidi; err = snd_virmidi_new(card, idx, &rmidi); if (err < 0) return err; vmidi->midi[idx] = rmidi; strcpy(rmidi->name, "Virtual Raw MIDI"); } strcpy(card->driver, "VirMIDI"); strcpy(card->shortname, "VirMIDI"); sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); err = snd_card_register(card); if (err) return err; platform_set_drvdata(devptr, card); return 0; } #define SND_VIRMIDI_DRIVER "snd_virmidi" static struct platform_driver snd_virmidi_driver = { .probe = snd_virmidi_probe, .driver = { .name = SND_VIRMIDI_DRIVER, }, }; static void snd_virmidi_unregister_all(void) { int i; for (i = 0; i < ARRAY_SIZE(devices); ++i) platform_device_unregister(devices[i]); platform_driver_unregister(&snd_virmidi_driver); } static int __init alsa_card_virmidi_init(void) { int i, cards, err; err = platform_driver_register(&snd_virmidi_driver); if (err < 0) return err; cards = 0; for (i = 0; i < SNDRV_CARDS; i++) { struct platform_device *device; if (!enable[i]) continue; device = platform_device_register_simple(SND_VIRMIDI_DRIVER, i, NULL, 0); if (IS_ERR(device)) continue; if (!platform_get_drvdata(device)) { platform_device_unregister(device); continue; } devices[i] = device; cards++; } if (!cards) { #ifdef MODULE printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n"); #endif snd_virmidi_unregister_all(); return -ENODEV; } return 0; } static void __exit alsa_card_virmidi_exit(void) { snd_virmidi_unregister_all(); } module_init(alsa_card_virmidi_init) module_exit(alsa_card_virmidi_exit)
linux-master
sound/drivers/virmidi.c
// SPDX-License-Identifier: GPL-2.0 /* * PC-Speaker driver for Linux * * Mixer implementation. * Copyright (C) 2001-2008 Stas Sergeev */ #include <sound/core.h> #include <sound/control.h> #include "pcsp.h" static int pcsp_enable_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int pcsp_enable_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->enable; return 0; } static int pcsp_enable_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int enab = ucontrol->value.integer.value[0]; if (enab != chip->enable) { chip->enable = enab; changed = 1; } return changed; } static int pcsp_treble_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = chip->max_treble + 1; if (uinfo->value.enumerated.item > chip->max_treble) uinfo->value.enumerated.item = chip->max_treble; sprintf(uinfo->value.enumerated.name, "%lu", (unsigned long)PCSP_CALC_RATE(uinfo->value.enumerated.item)); return 0; } static int pcsp_treble_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = chip->treble; return 0; } static int pcsp_treble_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int treble = ucontrol->value.enumerated.item[0]; if (treble != chip->treble) { chip->treble = treble; #if PCSP_DEBUG printk(KERN_INFO "PCSP: rate set to %li\n", PCSP_RATE()); #endif changed = 1; } return changed; } static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->pcspkr; return 0; } static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol); int changed = 0; int spkr = ucontrol->value.integer.value[0]; if (spkr != chip->pcspkr) { chip->pcspkr = spkr; changed = 1; } return changed; } #define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = ctl_name, \ .info = pcsp_##ctl_type##_info, \ .get = pcsp_##ctl_type##_get, \ .put = pcsp_##ctl_type##_put, \ } static const struct snd_kcontrol_new snd_pcsp_controls_pcm[] = { PCSP_MIXER_CONTROL(enable, "Master Playback Switch"), PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"), }; static const struct snd_kcontrol_new snd_pcsp_controls_spkr[] = { PCSP_MIXER_CONTROL(pcspkr, "Beep Playback Switch"), }; static int snd_pcsp_ctls_add(struct snd_pcsp *chip, const struct snd_kcontrol_new *ctls, int num) { int i, err; struct snd_card *card = chip->card; for (i = 0; i < num; i++) { err = snd_ctl_add(card, snd_ctl_new1(ctls + i, chip)); if (err < 0) return err; } return 0; } int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm) { int err; struct snd_card *card = chip->card; if (!nopcm) { err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_pcm, ARRAY_SIZE(snd_pcsp_controls_pcm)); if (err < 0) return err; } err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_spkr, ARRAY_SIZE(snd_pcsp_controls_spkr)); if (err < 0) return err; strcpy(card->mixername, "PC-Speaker"); return 0; }
linux-master
sound/drivers/pcsp/pcsp_mixer.c
// SPDX-License-Identifier: GPL-2.0-only /* * PC-Speaker driver for Linux * * Copyright (C) 1997-2001 David Woodhouse * Copyright (C) 2001-2008 Stas Sergeev */ #include <linux/init.h> #include <linux/module.h> #include <linux/platform_device.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/pcm.h> #include <linux/input.h> #include <linux/delay.h> #include <linux/bitops.h> #include <linux/mm.h> #include "pcsp_input.h" #include "pcsp.h" MODULE_AUTHOR("Stas Sergeev <[email protected]>"); MODULE_DESCRIPTION("PC-Speaker driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:pcspkr"); static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ static bool nopcm; /* Disable PCM capability of the driver */ module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for pcsp soundcard."); module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for pcsp soundcard."); module_param(enable, bool, 0444); MODULE_PARM_DESC(enable, "Enable PC-Speaker sound."); module_param(nopcm, bool, 0444); MODULE_PARM_DESC(nopcm, "Disable PC-Speaker PCM sound. Only beeps remain."); struct snd_pcsp pcsp_chip; static int snd_pcsp_create(struct snd_card *card) { unsigned int resolution = hrtimer_resolution; int div, min_div, order; if (!nopcm) { if (resolution > PCSP_MAX_PERIOD_NS) { printk(KERN_ERR "PCSP: Timer resolution is not sufficient " "(%unS)\n", resolution); printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI " "enabled.\n"); printk(KERN_ERR "PCSP: Turned into nopcm mode.\n"); nopcm = 1; } } if (loops_per_jiffy >= PCSP_MIN_LPJ && resolution <= PCSP_MIN_PERIOD_NS) min_div = MIN_DIV; else min_div = MAX_DIV; #if PCSP_DEBUG printk(KERN_DEBUG "PCSP: lpj=%li, min_div=%i, res=%u\n", loops_per_jiffy, min_div, resolution); #endif div = MAX_DIV / min_div; order = fls(div) - 1; pcsp_chip.max_treble = min(order, PCSP_MAX_TREBLE); pcsp_chip.treble = min(pcsp_chip.max_treble, PCSP_DEFAULT_TREBLE); pcsp_chip.playback_ptr = 0; pcsp_chip.period_ptr = 0; atomic_set(&pcsp_chip.timer_active, 0); pcsp_chip.enable = 1; pcsp_chip.pcspkr = 1; spin_lock_init(&pcsp_chip.substream_lock); pcsp_chip.card = card; pcsp_chip.port = 0x61; pcsp_chip.irq = -1; pcsp_chip.dma = -1; card->private_data = &pcsp_chip; return 0; } static void pcsp_stop_beep(struct snd_pcsp *chip); static void alsa_card_pcsp_free(struct snd_card *card) { pcsp_stop_beep(card->private_data); } static int snd_card_pcsp_probe(int devnum, struct device *dev) { struct snd_card *card; int err; if (devnum != 0) return -EINVAL; hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); pcsp_chip.timer.function = pcsp_do_timer; err = snd_devm_card_new(dev, index, id, THIS_MODULE, 0, &card); if (err < 0) return err; err = snd_pcsp_create(card); if (err < 0) return err; if (!nopcm) { err = snd_pcsp_new_pcm(&pcsp_chip); if (err < 0) return err; } err = snd_pcsp_new_mixer(&pcsp_chip, nopcm); if (err < 0) return err; strcpy(card->driver, "PC-Speaker"); strcpy(card->shortname, "pcsp"); sprintf(card->longname, "Internal PC-Speaker at port 0x%x", pcsp_chip.port); err = snd_card_register(card); if (err < 0) return err; card->private_free = alsa_card_pcsp_free; return 0; } static int alsa_card_pcsp_init(struct device *dev) { int err; err = snd_card_pcsp_probe(0, dev); if (err) { printk(KERN_ERR "PC-Speaker initialization failed.\n"); return err; } /* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */ if (debug_pagealloc_enabled()) { printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, " "which may make the sound noisy.\n"); } return 0; } static int pcsp_probe(struct platform_device *dev) { int err; err = pcspkr_input_init(&pcsp_chip.input_dev, &dev->dev); if (err < 0) return err; err = alsa_card_pcsp_init(&dev->dev); if (err < 0) return err; platform_set_drvdata(dev, &pcsp_chip); return 0; } static void pcsp_stop_beep(struct snd_pcsp *chip) { pcsp_sync_stop(chip); pcspkr_stop_sound(); } #ifdef CONFIG_PM_SLEEP static int pcsp_suspend(struct device *dev) { struct snd_pcsp *chip = dev_get_drvdata(dev); pcsp_stop_beep(chip); return 0; } static SIMPLE_DEV_PM_OPS(pcsp_pm, pcsp_suspend, NULL); #define PCSP_PM_OPS &pcsp_pm #else #define PCSP_PM_OPS NULL #endif /* CONFIG_PM_SLEEP */ static void pcsp_shutdown(struct platform_device *dev) { struct snd_pcsp *chip = platform_get_drvdata(dev); pcsp_stop_beep(chip); } static struct platform_driver pcsp_platform_driver = { .driver = { .name = "pcspkr", .pm = PCSP_PM_OPS, }, .probe = pcsp_probe, .shutdown = pcsp_shutdown, }; static int __init pcsp_init(void) { if (!enable) return -ENODEV; return platform_driver_register(&pcsp_platform_driver); } static void __exit pcsp_exit(void) { platform_driver_unregister(&pcsp_platform_driver); } module_init(pcsp_init); module_exit(pcsp_exit);
linux-master
sound/drivers/pcsp/pcsp.c
// SPDX-License-Identifier: GPL-2.0 /* * PC-Speaker driver for Linux * * Copyright (C) 1993-1997 Michael Beck * Copyright (C) 1997-2001 David Woodhouse * Copyright (C) 2001-2008 Stas Sergeev */ #include <linux/module.h> #include <linux/gfp.h> #include <linux/moduleparam.h> #include <linux/interrupt.h> #include <linux/io.h> #include <sound/pcm.h> #include "pcsp.h" static bool nforce_wa; module_param(nforce_wa, bool, 0444); MODULE_PARM_DESC(nforce_wa, "Apply NForce chipset workaround " "(expect bad sound)"); #define DMIX_WANTS_S16 1 /* * Call snd_pcm_period_elapsed in a work * This avoids spinlock messes and long-running irq contexts */ static void pcsp_call_pcm_elapsed(struct work_struct *work) { if (atomic_read(&pcsp_chip.timer_active)) { struct snd_pcm_substream *substream; substream = pcsp_chip.playback_substream; if (substream) snd_pcm_period_elapsed(substream); } } static DECLARE_WORK(pcsp_pcm_work, pcsp_call_pcm_elapsed); /* write the port and returns the next expire time in ns; * called at the trigger-start and in hrtimer callback */ static u64 pcsp_timer_update(struct snd_pcsp *chip) { unsigned char timer_cnt, val; u64 ns; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; unsigned long flags; if (chip->thalf) { outb(chip->val61, 0x61); chip->thalf = 0; return chip->ns_rem; } substream = chip->playback_substream; if (!substream) return 0; runtime = substream->runtime; /* assume it is mono! */ val = runtime->dma_area[chip->playback_ptr + chip->fmt_size - 1]; if (chip->is_signed) val ^= 0x80; timer_cnt = val * CUR_DIV() / 256; if (timer_cnt && chip->enable) { raw_spin_lock_irqsave(&i8253_lock, flags); if (!nforce_wa) { outb_p(chip->val61, 0x61); outb_p(timer_cnt, 0x42); outb(chip->val61 ^ 1, 0x61); } else { outb(chip->val61 ^ 2, 0x61); chip->thalf = 1; } raw_spin_unlock_irqrestore(&i8253_lock, flags); } chip->ns_rem = PCSP_PERIOD_NS(); ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem); chip->ns_rem -= ns; return ns; } static void pcsp_pointer_update(struct snd_pcsp *chip) { struct snd_pcm_substream *substream; size_t period_bytes, buffer_bytes; int periods_elapsed; unsigned long flags; /* update the playback position */ substream = chip->playback_substream; if (!substream) return; period_bytes = snd_pcm_lib_period_bytes(substream); buffer_bytes = snd_pcm_lib_buffer_bytes(substream); spin_lock_irqsave(&chip->substream_lock, flags); chip->playback_ptr += PCSP_INDEX_INC() * chip->fmt_size; periods_elapsed = chip->playback_ptr - chip->period_ptr; if (periods_elapsed < 0) { #if PCSP_DEBUG printk(KERN_INFO "PCSP: buffer_bytes mod period_bytes != 0 ? " "(%zi %zi %zi)\n", chip->playback_ptr, period_bytes, buffer_bytes); #endif periods_elapsed += buffer_bytes; } periods_elapsed /= period_bytes; /* wrap the pointer _before_ calling snd_pcm_period_elapsed(), * or ALSA will BUG on us. */ chip->playback_ptr %= buffer_bytes; if (periods_elapsed) { chip->period_ptr += periods_elapsed * period_bytes; chip->period_ptr %= buffer_bytes; queue_work(system_highpri_wq, &pcsp_pcm_work); } spin_unlock_irqrestore(&chip->substream_lock, flags); } enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle) { struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer); int pointer_update; u64 ns; if (!atomic_read(&chip->timer_active) || !chip->playback_substream) return HRTIMER_NORESTART; pointer_update = !chip->thalf; ns = pcsp_timer_update(chip); if (!ns) { printk(KERN_WARNING "PCSP: unexpected stop\n"); return HRTIMER_NORESTART; } if (pointer_update) pcsp_pointer_update(chip); hrtimer_forward_now(handle, ns_to_ktime(ns)); return HRTIMER_RESTART; } static int pcsp_start_playing(struct snd_pcsp *chip) { #if PCSP_DEBUG printk(KERN_INFO "PCSP: start_playing called\n"); #endif if (atomic_read(&chip->timer_active)) { printk(KERN_ERR "PCSP: Timer already active\n"); return -EIO; } raw_spin_lock(&i8253_lock); chip->val61 = inb(0x61) | 0x03; outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */ raw_spin_unlock(&i8253_lock); atomic_set(&chip->timer_active, 1); chip->thalf = 0; hrtimer_start(&pcsp_chip.timer, 0, HRTIMER_MODE_REL); return 0; } static void pcsp_stop_playing(struct snd_pcsp *chip) { #if PCSP_DEBUG printk(KERN_INFO "PCSP: stop_playing called\n"); #endif if (!atomic_read(&chip->timer_active)) return; atomic_set(&chip->timer_active, 0); raw_spin_lock(&i8253_lock); /* restore the timer */ outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */ outb(chip->val61 & 0xFC, 0x61); raw_spin_unlock(&i8253_lock); } /* * Force to stop and sync the stream */ void pcsp_sync_stop(struct snd_pcsp *chip) { local_irq_disable(); pcsp_stop_playing(chip); local_irq_enable(); hrtimer_cancel(&chip->timer); cancel_work_sync(&pcsp_pcm_work); } static int snd_pcsp_playback_close(struct snd_pcm_substream *substream) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); #if PCSP_DEBUG printk(KERN_INFO "PCSP: close called\n"); #endif pcsp_sync_stop(chip); chip->playback_substream = NULL; return 0; } static int snd_pcsp_playback_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); pcsp_sync_stop(chip); return 0; } static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); #if PCSP_DEBUG printk(KERN_INFO "PCSP: hw_free called\n"); #endif pcsp_sync_stop(chip); return 0; } static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); pcsp_sync_stop(chip); chip->playback_ptr = 0; chip->period_ptr = 0; chip->fmt_size = snd_pcm_format_physical_width(substream->runtime->format) >> 3; chip->is_signed = snd_pcm_format_signed(substream->runtime->format); #if PCSP_DEBUG printk(KERN_INFO "PCSP: prepare called, " "size=%zi psize=%zi f=%zi f1=%i fsize=%i\n", snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream) / snd_pcm_lib_period_bytes(substream), substream->runtime->periods, chip->fmt_size); #endif return 0; } static int snd_pcsp_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); #if PCSP_DEBUG printk(KERN_INFO "PCSP: trigger called\n"); #endif switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: return pcsp_start_playing(chip); case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: pcsp_stop_playing(chip); break; default: return -EINVAL; } return 0; } static snd_pcm_uframes_t snd_pcsp_playback_pointer(struct snd_pcm_substream *substream) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); unsigned int pos; spin_lock(&chip->substream_lock); pos = chip->playback_ptr; spin_unlock(&chip->substream_lock); return bytes_to_frames(substream->runtime, pos); } static const struct snd_pcm_hardware snd_pcsp_playback = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_HALF_DUPLEX | SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID), .formats = (SNDRV_PCM_FMTBIT_U8 #if DMIX_WANTS_S16 | SNDRV_PCM_FMTBIT_S16_LE #endif ), .rates = SNDRV_PCM_RATE_KNOT, .rate_min = PCSP_DEFAULT_SRATE, .rate_max = PCSP_DEFAULT_SRATE, .channels_min = 1, .channels_max = 1, .buffer_bytes_max = PCSP_BUFFER_SIZE, .period_bytes_min = 64, .period_bytes_max = PCSP_MAX_PERIOD_SIZE, .periods_min = 2, .periods_max = PCSP_MAX_PERIODS, .fifo_size = 0, }; static int snd_pcsp_playback_open(struct snd_pcm_substream *substream) { struct snd_pcsp *chip = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; #if PCSP_DEBUG printk(KERN_INFO "PCSP: open called\n"); #endif if (atomic_read(&chip->timer_active)) { printk(KERN_ERR "PCSP: still active!!\n"); return -EBUSY; } runtime->hw = snd_pcsp_playback; chip->playback_substream = substream; return 0; } static const struct snd_pcm_ops snd_pcsp_playback_ops = { .open = snd_pcsp_playback_open, .close = snd_pcsp_playback_close, .hw_params = snd_pcsp_playback_hw_params, .hw_free = snd_pcsp_playback_hw_free, .prepare = snd_pcsp_playback_prepare, .trigger = snd_pcsp_trigger, .pointer = snd_pcsp_playback_pointer, }; int snd_pcsp_new_pcm(struct snd_pcsp *chip) { int err; err = snd_pcm_new(chip->card, "pcspeaker", 0, 1, 0, &chip->pcm); if (err < 0) return err; snd_pcm_set_ops(chip->pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_pcsp_playback_ops); chip->pcm->private_data = chip; chip->pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; strcpy(chip->pcm->name, "pcsp"); snd_pcm_set_managed_buffer_all(chip->pcm, SNDRV_DMA_TYPE_CONTINUOUS, NULL, PCSP_BUFFER_SIZE, PCSP_BUFFER_SIZE); return 0; }
linux-master
sound/drivers/pcsp/pcsp_lib.c
// SPDX-License-Identifier: GPL-2.0-only /* * PC Speaker beeper driver for Linux * * Copyright (c) 2002 Vojtech Pavlik * Copyright (c) 1992 Orest Zborowski */ #include <linux/init.h> #include <linux/input.h> #include <linux/io.h> #include "pcsp.h" #include "pcsp_input.h" static void pcspkr_do_sound(unsigned int count) { unsigned long flags; raw_spin_lock_irqsave(&i8253_lock, flags); if (count) { /* set command for counter 2, 2 byte write */ outb_p(0xB6, 0x43); /* select desired HZ */ outb_p(count & 0xff, 0x42); outb((count >> 8) & 0xff, 0x42); /* enable counter 2 */ outb_p(inb_p(0x61) | 3, 0x61); } else { /* disable counter 2 */ outb(inb_p(0x61) & 0xFC, 0x61); } raw_spin_unlock_irqrestore(&i8253_lock, flags); } void pcspkr_stop_sound(void) { pcspkr_do_sound(0); } static int pcspkr_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { unsigned int count = 0; if (atomic_read(&pcsp_chip.timer_active) || !pcsp_chip.pcspkr) return 0; switch (type) { case EV_SND: switch (code) { case SND_BELL: if (value) value = 1000; break; case SND_TONE: break; default: return -1; } break; default: return -1; } if (value > 20 && value < 32767) count = PIT_TICK_RATE / value; pcspkr_do_sound(count); return 0; } int pcspkr_input_init(struct input_dev **rdev, struct device *dev) { int err; struct input_dev *input_dev = devm_input_allocate_device(dev); if (!input_dev) return -ENOMEM; input_dev->name = "PC Speaker"; input_dev->phys = "isa0061/input0"; input_dev->id.bustype = BUS_ISA; input_dev->id.vendor = 0x001f; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->dev.parent = dev; input_dev->evbit[0] = BIT(EV_SND); input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); input_dev->event = pcspkr_input_event; err = input_register_device(input_dev); if (err) return err; *rdev = input_dev; return 0; }
linux-master
sound/drivers/pcsp/pcsp_input.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]>, * Hannu Savolainen 1993-1996, * Rob Hooft * * Routines for control of AdLib FM cards (OPL2/OPL3/OPL4 chips) * * Most if code is ported from OSS/Lite. */ #include <sound/opl3.h> #include <linux/io.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/ioport.h> #include <sound/minors.h> #include "opl3_voice.h" MODULE_AUTHOR("Jaroslav Kysela <[email protected]>, Hannu Savolainen 1993-1996, Rob Hooft"); MODULE_DESCRIPTION("Routines for control of AdLib FM cards (OPL2/OPL3/OPL4 chips)"); MODULE_LICENSE("GPL"); static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) { unsigned long flags; unsigned long port; /* * The original 2-OP synth requires a quite long delay * after writing to a register. */ port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; spin_lock_irqsave(&opl3->reg_lock, flags); outb((unsigned char) cmd, port); udelay(10); outb((unsigned char) val, port + 1); udelay(30); spin_unlock_irqrestore(&opl3->reg_lock, flags); } static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) { unsigned long flags; unsigned long port; /* * The OPL-3 survives with just two INBs * after writing to a register. */ port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; spin_lock_irqsave(&opl3->reg_lock, flags); outb((unsigned char) cmd, port); inb(opl3->l_port); inb(opl3->l_port); outb((unsigned char) val, port + 1); inb(opl3->l_port); inb(opl3->l_port); spin_unlock_irqrestore(&opl3->reg_lock, flags); } static int snd_opl3_detect(struct snd_opl3 * opl3) { /* * This function returns 1 if the FM chip is present at the given I/O port * The detection algorithm plays with the timer built in the FM chip and * looks for a change in the status register. * * Note! The timers of the FM chip are not connected to AdLib (and compatible) * boards. * * Note2! The chip is initialized if detected. */ unsigned char stat1, stat2, signature; /* Reset timers 1 and 2 */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK); /* Reset the IRQ of the FM chip */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); signature = stat1 = inb(opl3->l_port); /* Status register */ if ((stat1 & 0xe0) != 0x00) { /* Should be 0x00 */ snd_printd("OPL3: stat1 = 0x%x\n", stat1); return -ENODEV; } /* Set timer1 to 0xff */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 0xff); /* Unmask and start timer 1 */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER2_MASK | OPL3_TIMER1_START); /* Now we have to delay at least 80us */ udelay(200); /* Read status after timers have expired */ stat2 = inb(opl3->l_port); /* Stop the timers */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_TIMER1_MASK | OPL3_TIMER2_MASK); /* Reset the IRQ of the FM chip */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); if ((stat2 & 0xe0) != 0xc0) { /* There is no YM3812 */ snd_printd("OPL3: stat2 = 0x%x\n", stat2); return -ENODEV; } /* If the toplevel code knows exactly the type of chip, don't try to detect it. */ if (opl3->hardware != OPL3_HW_AUTO) return 0; /* There is a FM chip on this address. Detect the type (OPL2 to OPL4) */ if (signature == 0x06) { /* OPL2 */ opl3->hardware = OPL3_HW_OPL2; } else { /* * If we had an OPL4 chip, opl3->hardware would have been set * by the OPL4 driver; so we can assume OPL3 here. */ if (snd_BUG_ON(!opl3->r_port)) return -ENODEV; opl3->hardware = OPL3_HW_OPL3; } return 0; } /* * AdLib timers */ /* * Timer 1 - 80us */ static int snd_opl3_timer1_start(struct snd_timer * timer) { unsigned long flags; unsigned char tmp; unsigned int ticks; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); spin_lock_irqsave(&opl3->timer_lock, flags); ticks = timer->sticks; tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } static int snd_opl3_timer1_stop(struct snd_timer * timer) { unsigned long flags; unsigned char tmp; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); spin_lock_irqsave(&opl3->timer_lock, flags); tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } /* * Timer 2 - 320us */ static int snd_opl3_timer2_start(struct snd_timer * timer) { unsigned long flags; unsigned char tmp; unsigned int ticks; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); spin_lock_irqsave(&opl3->timer_lock, flags); ticks = timer->sticks; tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } static int snd_opl3_timer2_stop(struct snd_timer * timer) { unsigned long flags; unsigned char tmp; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); spin_lock_irqsave(&opl3->timer_lock, flags); tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } /* */ static const struct snd_timer_hardware snd_opl3_timer1 = { .flags = SNDRV_TIMER_HW_STOP, .resolution = 80000, .ticks = 256, .start = snd_opl3_timer1_start, .stop = snd_opl3_timer1_stop, }; static const struct snd_timer_hardware snd_opl3_timer2 = { .flags = SNDRV_TIMER_HW_STOP, .resolution = 320000, .ticks = 256, .start = snd_opl3_timer2_start, .stop = snd_opl3_timer2_stop, }; static int snd_opl3_timer1_init(struct snd_opl3 * opl3, int timer_no) { struct snd_timer *timer = NULL; struct snd_timer_id tid; int err; tid.dev_class = SNDRV_TIMER_CLASS_CARD; tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; tid.card = opl3->card->number; tid.device = timer_no; tid.subdevice = 0; err = snd_timer_new(opl3->card, "AdLib timer #1", &tid, &timer); if (err >= 0) { strcpy(timer->name, "AdLib timer #1"); timer->private_data = opl3; timer->hw = snd_opl3_timer1; } opl3->timer1 = timer; return err; } static int snd_opl3_timer2_init(struct snd_opl3 * opl3, int timer_no) { struct snd_timer *timer = NULL; struct snd_timer_id tid; int err; tid.dev_class = SNDRV_TIMER_CLASS_CARD; tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; tid.card = opl3->card->number; tid.device = timer_no; tid.subdevice = 0; err = snd_timer_new(opl3->card, "AdLib timer #2", &tid, &timer); if (err >= 0) { strcpy(timer->name, "AdLib timer #2"); timer->private_data = opl3; timer->hw = snd_opl3_timer2; } opl3->timer2 = timer; return err; } /* */ void snd_opl3_interrupt(struct snd_hwdep * hw) { unsigned char status; struct snd_opl3 *opl3; struct snd_timer *timer; if (hw == NULL) return; opl3 = hw->private_data; status = inb(opl3->l_port); #if 0 snd_printk(KERN_DEBUG "AdLib IRQ status = 0x%x\n", status); #endif if (!(status & 0x80)) return; if (status & 0x40) { timer = opl3->timer1; snd_timer_interrupt(timer, timer->sticks); } if (status & 0x20) { timer = opl3->timer2; snd_timer_interrupt(timer, timer->sticks); } } EXPORT_SYMBOL(snd_opl3_interrupt); /* */ static int snd_opl3_free(struct snd_opl3 *opl3) { if (snd_BUG_ON(!opl3)) return -ENXIO; if (opl3->private_free) opl3->private_free(opl3); snd_opl3_clear_patches(opl3); release_and_free_resource(opl3->res_l_port); release_and_free_resource(opl3->res_r_port); kfree(opl3); return 0; } static int snd_opl3_dev_free(struct snd_device *device) { struct snd_opl3 *opl3 = device->device_data; return snd_opl3_free(opl3); } int snd_opl3_new(struct snd_card *card, unsigned short hardware, struct snd_opl3 **ropl3) { static const struct snd_device_ops ops = { .dev_free = snd_opl3_dev_free, }; struct snd_opl3 *opl3; int err; *ropl3 = NULL; opl3 = kzalloc(sizeof(*opl3), GFP_KERNEL); if (!opl3) return -ENOMEM; opl3->card = card; opl3->hardware = hardware; spin_lock_init(&opl3->reg_lock); spin_lock_init(&opl3->timer_lock); err = snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops); if (err < 0) { snd_opl3_free(opl3); return err; } *ropl3 = opl3; return 0; } EXPORT_SYMBOL(snd_opl3_new); int snd_opl3_init(struct snd_opl3 *opl3) { if (! opl3->command) { printk(KERN_ERR "snd_opl3_init: command not defined!\n"); return -EINVAL; } opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT); /* Melodic mode */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00); switch (opl3->hardware & OPL3_HW_MASK) { case OPL3_HW_OPL2: opl3->max_voices = MAX_OPL2_VOICES; break; case OPL3_HW_OPL3: case OPL3_HW_OPL4: opl3->max_voices = MAX_OPL3_VOICES; /* Enter OPL3 mode */ opl3->command(opl3, OPL3_RIGHT | OPL3_REG_MODE, OPL3_OPL3_ENABLE); } return 0; } EXPORT_SYMBOL(snd_opl3_init); int snd_opl3_create(struct snd_card *card, unsigned long l_port, unsigned long r_port, unsigned short hardware, int integrated, struct snd_opl3 ** ropl3) { struct snd_opl3 *opl3; int err; *ropl3 = NULL; err = snd_opl3_new(card, hardware, &opl3); if (err < 0) return err; if (! integrated) { opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)"); if (!opl3->res_l_port) { snd_printk(KERN_ERR "opl3: can't grab left port 0x%lx\n", l_port); snd_device_free(card, opl3); return -EBUSY; } if (r_port != 0) { opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)"); if (!opl3->res_r_port) { snd_printk(KERN_ERR "opl3: can't grab right port 0x%lx\n", r_port); snd_device_free(card, opl3); return -EBUSY; } } } opl3->l_port = l_port; opl3->r_port = r_port; switch (opl3->hardware) { /* some hardware doesn't support timers */ case OPL3_HW_OPL3_SV: case OPL3_HW_OPL3_CS: case OPL3_HW_OPL3_FM801: opl3->command = &snd_opl3_command; break; default: opl3->command = &snd_opl2_command; err = snd_opl3_detect(opl3); if (err < 0) { snd_printd("OPL2/3 chip not detected at 0x%lx/0x%lx\n", opl3->l_port, opl3->r_port); snd_device_free(card, opl3); return err; } /* detect routine returns correct hardware type */ switch (opl3->hardware & OPL3_HW_MASK) { case OPL3_HW_OPL3: case OPL3_HW_OPL4: opl3->command = &snd_opl3_command; } } snd_opl3_init(opl3); *ropl3 = opl3; return 0; } EXPORT_SYMBOL(snd_opl3_create); int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev) { int err; if (timer1_dev >= 0) { err = snd_opl3_timer1_init(opl3, timer1_dev); if (err < 0) return err; } if (timer2_dev >= 0) { err = snd_opl3_timer2_init(opl3, timer2_dev); if (err < 0) { snd_device_free(opl3->card, opl3->timer1); opl3->timer1 = NULL; return err; } } return 0; } EXPORT_SYMBOL(snd_opl3_timer_new); int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device, struct snd_hwdep ** rhwdep) { struct snd_hwdep *hw; struct snd_card *card = opl3->card; int err; if (rhwdep) *rhwdep = NULL; /* create hardware dependent device (direct FM) */ err = snd_hwdep_new(card, "OPL2/OPL3", device, &hw); if (err < 0) { snd_device_free(card, opl3); return err; } hw->private_data = opl3; hw->exclusive = 1; #ifdef CONFIG_SND_OSSEMUL if (device == 0) hw->oss_type = SNDRV_OSS_DEVICE_TYPE_DMFM; #endif strcpy(hw->name, hw->id); switch (opl3->hardware & OPL3_HW_MASK) { case OPL3_HW_OPL2: strcpy(hw->name, "OPL2 FM"); hw->iface = SNDRV_HWDEP_IFACE_OPL2; break; case OPL3_HW_OPL3: strcpy(hw->name, "OPL3 FM"); hw->iface = SNDRV_HWDEP_IFACE_OPL3; break; case OPL3_HW_OPL4: strcpy(hw->name, "OPL4 FM"); hw->iface = SNDRV_HWDEP_IFACE_OPL4; break; } /* operators - only ioctl */ hw->ops.open = snd_opl3_open; hw->ops.ioctl = snd_opl3_ioctl; hw->ops.write = snd_opl3_write; hw->ops.release = snd_opl3_release; opl3->hwdep = hw; opl3->seq_dev_num = seq_device; #if IS_ENABLED(CONFIG_SND_SEQUENCER) if (snd_seq_device_new(card, seq_device, SNDRV_SEQ_DEV_ID_OPL3, sizeof(struct snd_opl3 *), &opl3->seq_dev) >= 0) { strcpy(opl3->seq_dev->name, hw->name); *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(opl3->seq_dev) = opl3; } #endif if (rhwdep) *rhwdep = hw; return 0; } EXPORT_SYMBOL(snd_opl3_hwdep_new);
linux-master
sound/drivers/opl3/opl3_lib.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Uros Bizjak <[email protected]> * * Routines for OPL2/OPL3/OPL4 control */ #include <linux/slab.h> #include <linux/export.h> #include <linux/nospec.h> #include <sound/opl3.h> #include <sound/asound_fm.h> #include "opl3_voice.h" #if IS_ENABLED(CONFIG_SND_SEQUENCER) #define OPL3_SUPPORT_SYNTH #endif /* * There is 18 possible 2 OP voices * (9 in the left and 9 in the right). * The first OP is the modulator and 2nd is the carrier. * * The first three voices in the both sides may be connected * with another voice to a 4 OP voice. For example voice 0 * can be connected with voice 3. The operators of voice 3 are * used as operators 3 and 4 of the new 4 OP voice. * In this case the 2 OP voice number 0 is the 'first half' and * voice 3 is the second. */ /* * Register offset table for OPL2/3 voices, * OPL2 / one OPL3 register array side only */ char snd_opl3_regmap[MAX_OPL2_VOICES][4] = { /* OP1 OP2 OP3 OP4 */ /* ------------------------ */ { 0x00, 0x03, 0x08, 0x0b }, { 0x01, 0x04, 0x09, 0x0c }, { 0x02, 0x05, 0x0a, 0x0d }, { 0x08, 0x0b, 0x00, 0x00 }, { 0x09, 0x0c, 0x00, 0x00 }, { 0x0a, 0x0d, 0x00, 0x00 }, { 0x10, 0x13, 0x00, 0x00 }, /* used by percussive voices */ { 0x11, 0x14, 0x00, 0x00 }, /* if the percussive mode */ { 0x12, 0x15, 0x00, 0x00 } /* is selected (only left reg block) */ }; EXPORT_SYMBOL(snd_opl3_regmap); /* * prototypes */ static int snd_opl3_play_note(struct snd_opl3 * opl3, struct snd_dm_fm_note * note); static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * voice); static int snd_opl3_set_params(struct snd_opl3 * opl3, struct snd_dm_fm_params * params); static int snd_opl3_set_mode(struct snd_opl3 * opl3, int mode); static int snd_opl3_set_connection(struct snd_opl3 * opl3, int connection); /* ------------------------------ */ /* * open the device exclusively */ int snd_opl3_open(struct snd_hwdep * hw, struct file *file) { return 0; } /* * ioctl for hwdep device: */ int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg) { struct snd_opl3 *opl3 = hw->private_data; void __user *argp = (void __user *)arg; if (snd_BUG_ON(!opl3)) return -EINVAL; switch (cmd) { /* get information */ case SNDRV_DM_FM_IOCTL_INFO: { struct snd_dm_fm_info info; memset(&info, 0, sizeof(info)); info.fm_mode = opl3->fm_mode; info.rhythm = opl3->rhythm; if (copy_to_user(argp, &info, sizeof(struct snd_dm_fm_info))) return -EFAULT; return 0; } case SNDRV_DM_FM_IOCTL_RESET: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_RESET: #endif snd_opl3_reset(opl3); return 0; case SNDRV_DM_FM_IOCTL_PLAY_NOTE: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_PLAY_NOTE: #endif { struct snd_dm_fm_note note; if (copy_from_user(&note, argp, sizeof(struct snd_dm_fm_note))) return -EFAULT; return snd_opl3_play_note(opl3, &note); } case SNDRV_DM_FM_IOCTL_SET_VOICE: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_SET_VOICE: #endif { struct snd_dm_fm_voice voice; if (copy_from_user(&voice, argp, sizeof(struct snd_dm_fm_voice))) return -EFAULT; return snd_opl3_set_voice(opl3, &voice); } case SNDRV_DM_FM_IOCTL_SET_PARAMS: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_SET_PARAMS: #endif { struct snd_dm_fm_params params; if (copy_from_user(&params, argp, sizeof(struct snd_dm_fm_params))) return -EFAULT; return snd_opl3_set_params(opl3, &params); } case SNDRV_DM_FM_IOCTL_SET_MODE: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_SET_MODE: #endif return snd_opl3_set_mode(opl3, (int) arg); case SNDRV_DM_FM_IOCTL_SET_CONNECTION: #ifdef CONFIG_SND_OSSEMUL case SNDRV_DM_FM_OSS_IOCTL_SET_OPL: #endif return snd_opl3_set_connection(opl3, (int) arg); #ifdef OPL3_SUPPORT_SYNTH case SNDRV_DM_FM_IOCTL_CLEAR_PATCHES: snd_opl3_clear_patches(opl3); return 0; #endif #ifdef CONFIG_SND_DEBUG default: snd_printk(KERN_WARNING "unknown IOCTL: 0x%x\n", cmd); #endif } return -ENOTTY; } /* * close the device */ int snd_opl3_release(struct snd_hwdep * hw, struct file *file) { struct snd_opl3 *opl3 = hw->private_data; snd_opl3_reset(opl3); return 0; } #ifdef OPL3_SUPPORT_SYNTH /* * write the device - load patches */ long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count, loff_t *offset) { struct snd_opl3 *opl3 = hw->private_data; long result = 0; int err = 0; struct sbi_patch inst; while (count >= sizeof(inst)) { unsigned char type; if (copy_from_user(&inst, buf, sizeof(inst))) return -EFAULT; if (!memcmp(inst.key, FM_KEY_SBI, 4) || !memcmp(inst.key, FM_KEY_2OP, 4)) type = FM_PATCH_OPL2; else if (!memcmp(inst.key, FM_KEY_4OP, 4)) type = FM_PATCH_OPL3; else /* invalid type */ break; err = snd_opl3_load_patch(opl3, inst.prog, inst.bank, type, inst.name, inst.extension, inst.data); if (err < 0) break; result += sizeof(inst); count -= sizeof(inst); } return result > 0 ? result : err; } /* * Patch management */ /* offsets for SBI params */ #define AM_VIB 0 #define KSL_LEVEL 2 #define ATTACK_DECAY 4 #define SUSTAIN_RELEASE 6 #define WAVE_SELECT 8 /* offset for SBI instrument */ #define CONNECTION 10 #define OFFSET_4OP 11 /* * load a patch, obviously. * * loaded on the given program and bank numbers with the given type * (FM_PATCH_OPLx). * data is the pointer of SBI record _without_ header (key and name). * name is the name string of the patch. * ext is the extension data of 7 bytes long (stored in name of SBI * data up to offset 25), or NULL to skip. * return 0 if successful or a negative error code. */ int snd_opl3_load_patch(struct snd_opl3 *opl3, int prog, int bank, int type, const char *name, const unsigned char *ext, const unsigned char *data) { struct fm_patch *patch; int i; patch = snd_opl3_find_patch(opl3, prog, bank, 1); if (!patch) return -ENOMEM; patch->type = type; for (i = 0; i < 2; i++) { patch->inst.op[i].am_vib = data[AM_VIB + i]; patch->inst.op[i].ksl_level = data[KSL_LEVEL + i]; patch->inst.op[i].attack_decay = data[ATTACK_DECAY + i]; patch->inst.op[i].sustain_release = data[SUSTAIN_RELEASE + i]; patch->inst.op[i].wave_select = data[WAVE_SELECT + i]; } patch->inst.feedback_connection[0] = data[CONNECTION]; if (type == FM_PATCH_OPL3) { for (i = 0; i < 2; i++) { patch->inst.op[i+2].am_vib = data[OFFSET_4OP + AM_VIB + i]; patch->inst.op[i+2].ksl_level = data[OFFSET_4OP + KSL_LEVEL + i]; patch->inst.op[i+2].attack_decay = data[OFFSET_4OP + ATTACK_DECAY + i]; patch->inst.op[i+2].sustain_release = data[OFFSET_4OP + SUSTAIN_RELEASE + i]; patch->inst.op[i+2].wave_select = data[OFFSET_4OP + WAVE_SELECT + i]; } patch->inst.feedback_connection[1] = data[OFFSET_4OP + CONNECTION]; } if (ext) { patch->inst.echo_delay = ext[0]; patch->inst.echo_atten = ext[1]; patch->inst.chorus_spread = ext[2]; patch->inst.trnsps = ext[3]; patch->inst.fix_dur = ext[4]; patch->inst.modes = ext[5]; patch->inst.fix_key = ext[6]; } if (name) strscpy(patch->name, name, sizeof(patch->name)); return 0; } EXPORT_SYMBOL(snd_opl3_load_patch); /* * find a patch with the given program and bank numbers, returns its pointer * if no matching patch is found and create_patch is set, it creates a * new patch object. */ struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank, int create_patch) { /* pretty dumb hash key */ unsigned int key = (prog + bank) % OPL3_PATCH_HASH_SIZE; struct fm_patch *patch; for (patch = opl3->patch_table[key]; patch; patch = patch->next) { if (patch->prog == prog && patch->bank == bank) return patch; } if (!create_patch) return NULL; patch = kzalloc(sizeof(*patch), GFP_KERNEL); if (!patch) return NULL; patch->prog = prog; patch->bank = bank; patch->next = opl3->patch_table[key]; opl3->patch_table[key] = patch; return patch; } EXPORT_SYMBOL(snd_opl3_find_patch); /* * Clear all patches of the given OPL3 instance */ void snd_opl3_clear_patches(struct snd_opl3 *opl3) { int i; for (i = 0; i < OPL3_PATCH_HASH_SIZE; i++) { struct fm_patch *patch, *next; for (patch = opl3->patch_table[i]; patch; patch = next) { next = patch->next; kfree(patch); } } memset(opl3->patch_table, 0, sizeof(opl3->patch_table)); } #endif /* OPL3_SUPPORT_SYNTH */ /* ------------------------------ */ void snd_opl3_reset(struct snd_opl3 * opl3) { unsigned short opl3_reg; unsigned short reg_side; unsigned char voice_offset; int max_voices, i; max_voices = (opl3->hardware < OPL3_HW_OPL3) ? MAX_OPL2_VOICES : MAX_OPL3_VOICES; for (i = 0; i < max_voices; i++) { /* Get register array side and offset of voice */ if (i < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = i; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = i - MAX_OPL2_VOICES; } opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + snd_opl3_regmap[voice_offset][0]); opl3->command(opl3, opl3_reg, OPL3_TOTAL_LEVEL_MASK); /* Operator 1 volume */ opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + snd_opl3_regmap[voice_offset][1]); opl3->command(opl3, opl3_reg, OPL3_TOTAL_LEVEL_MASK); /* Operator 2 volume */ opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3->command(opl3, opl3_reg, 0x00); /* Note off */ } opl3->max_voices = MAX_OPL2_VOICES; opl3->fm_mode = SNDRV_DM_FM_MODE_OPL2; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TEST, OPL3_ENABLE_WAVE_SELECT); opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, 0x00); /* Melodic mode */ opl3->rhythm = 0; } EXPORT_SYMBOL(snd_opl3_reset); static int snd_opl3_play_note(struct snd_opl3 * opl3, struct snd_dm_fm_note * note) { unsigned short reg_side; unsigned char voice_offset; unsigned short opl3_reg; unsigned char reg_val; /* Voices 0 - 8 in OPL2 mode */ /* Voices 0 - 17 in OPL3 mode */ if (note->voice >= ((opl3->fm_mode == SNDRV_DM_FM_MODE_OPL3) ? MAX_OPL3_VOICES : MAX_OPL2_VOICES)) return -EINVAL; /* Get register array side and offset of voice */ if (note->voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = note->voice; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = note->voice - MAX_OPL2_VOICES; } /* Set lower 8 bits of note frequency */ reg_val = (unsigned char) note->fnum; opl3_reg = reg_side | (OPL3_REG_FNUM_LOW + voice_offset); opl3->command(opl3, opl3_reg, reg_val); reg_val = 0x00; /* Set output sound flag */ if (note->key_on) reg_val |= OPL3_KEYON_BIT; /* Set octave */ reg_val |= (note->octave << 2) & OPL3_BLOCKNUM_MASK; /* Set higher 2 bits of note frequency */ reg_val |= (unsigned char) (note->fnum >> 8) & OPL3_FNUM_HIGH_MASK; /* Set OPL3 KEYON_BLOCK register of requested voice */ opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3->command(opl3, opl3_reg, reg_val); return 0; } static int snd_opl3_set_voice(struct snd_opl3 * opl3, struct snd_dm_fm_voice * voice) { unsigned short reg_side; unsigned char op_offset; unsigned char voice_offset, voice_op; unsigned short opl3_reg; unsigned char reg_val; /* Only operators 1 and 2 */ if (voice->op > 1) return -EINVAL; /* Voices 0 - 8 in OPL2 mode */ /* Voices 0 - 17 in OPL3 mode */ if (voice->voice >= ((opl3->fm_mode == SNDRV_DM_FM_MODE_OPL3) ? MAX_OPL3_VOICES : MAX_OPL2_VOICES)) return -EINVAL; /* Get register array side and offset of voice */ if (voice->voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = voice->voice; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = voice->voice - MAX_OPL2_VOICES; } /* Get register offset of operator */ voice_offset = array_index_nospec(voice_offset, MAX_OPL2_VOICES); voice_op = array_index_nospec(voice->op, 4); op_offset = snd_opl3_regmap[voice_offset][voice_op]; reg_val = 0x00; /* Set amplitude modulation (tremolo) effect */ if (voice->am) reg_val |= OPL3_TREMOLO_ON; /* Set vibrato effect */ if (voice->vibrato) reg_val |= OPL3_VIBRATO_ON; /* Set sustaining sound phase */ if (voice->do_sustain) reg_val |= OPL3_SUSTAIN_ON; /* Set keyboard scaling bit */ if (voice->kbd_scale) reg_val |= OPL3_KSR; /* Set harmonic or frequency multiplier */ reg_val |= voice->harmonic & OPL3_MULTIPLE_MASK; /* Set OPL3 AM_VIB register of requested voice/operator */ opl3_reg = reg_side | (OPL3_REG_AM_VIB + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set decreasing volume of higher notes */ reg_val = (voice->scale_level << 6) & OPL3_KSL_MASK; /* Set output volume */ reg_val |= ~voice->volume & OPL3_TOTAL_LEVEL_MASK; /* Set OPL3 KSL_LEVEL register of requested voice/operator */ opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set attack phase level */ reg_val = (voice->attack << 4) & OPL3_ATTACK_MASK; /* Set decay phase level */ reg_val |= voice->decay & OPL3_DECAY_MASK; /* Set OPL3 ATTACK_DECAY register of requested voice/operator */ opl3_reg = reg_side | (OPL3_REG_ATTACK_DECAY + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set sustain phase level */ reg_val = (voice->sustain << 4) & OPL3_SUSTAIN_MASK; /* Set release phase level */ reg_val |= voice->release & OPL3_RELEASE_MASK; /* Set OPL3 SUSTAIN_RELEASE register of requested voice/operator */ opl3_reg = reg_side | (OPL3_REG_SUSTAIN_RELEASE + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set inter-operator feedback */ reg_val = (voice->feedback << 1) & OPL3_FEEDBACK_MASK; /* Set inter-operator connection */ if (voice->connection) reg_val |= OPL3_CONNECTION_BIT; /* OPL-3 only */ if (opl3->fm_mode == SNDRV_DM_FM_MODE_OPL3) { if (voice->left) reg_val |= OPL3_VOICE_TO_LEFT; if (voice->right) reg_val |= OPL3_VOICE_TO_RIGHT; } /* Feedback/connection bits are applicable to voice */ opl3_reg = reg_side | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset); opl3->command(opl3, opl3_reg, reg_val); /* Select waveform */ reg_val = voice->waveform & OPL3_WAVE_SELECT_MASK; opl3_reg = reg_side | (OPL3_REG_WAVE_SELECT + op_offset); opl3->command(opl3, opl3_reg, reg_val); return 0; } static int snd_opl3_set_params(struct snd_opl3 * opl3, struct snd_dm_fm_params * params) { unsigned char reg_val; reg_val = 0x00; /* Set keyboard split method */ if (params->kbd_split) reg_val |= OPL3_KEYBOARD_SPLIT; opl3->command(opl3, OPL3_LEFT | OPL3_REG_KBD_SPLIT, reg_val); reg_val = 0x00; /* Set amplitude modulation (tremolo) depth */ if (params->am_depth) reg_val |= OPL3_TREMOLO_DEPTH; /* Set vibrato depth */ if (params->vib_depth) reg_val |= OPL3_VIBRATO_DEPTH; /* Set percussion mode */ if (params->rhythm) { reg_val |= OPL3_PERCUSSION_ENABLE; opl3->rhythm = 1; } else { opl3->rhythm = 0; } /* Play percussion instruments */ if (params->bass) reg_val |= OPL3_BASSDRUM_ON; if (params->snare) reg_val |= OPL3_SNAREDRUM_ON; if (params->tomtom) reg_val |= OPL3_TOMTOM_ON; if (params->cymbal) reg_val |= OPL3_CYMBAL_ON; if (params->hihat) reg_val |= OPL3_HIHAT_ON; opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, reg_val); return 0; } static int snd_opl3_set_mode(struct snd_opl3 * opl3, int mode) { if ((mode == SNDRV_DM_FM_MODE_OPL3) && (opl3->hardware < OPL3_HW_OPL3)) return -EINVAL; opl3->fm_mode = mode; if (opl3->hardware >= OPL3_HW_OPL3) opl3->command(opl3, OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT, 0x00); /* Clear 4-op connections */ return 0; } static int snd_opl3_set_connection(struct snd_opl3 * opl3, int connection) { unsigned char reg_val; /* OPL-3 only */ if (opl3->fm_mode != SNDRV_DM_FM_MODE_OPL3) return -EINVAL; reg_val = connection & (OPL3_RIGHT_4OP_0 | OPL3_RIGHT_4OP_1 | OPL3_RIGHT_4OP_2 | OPL3_LEFT_4OP_0 | OPL3_LEFT_4OP_1 | OPL3_LEFT_4OP_2); /* Set 4-op connections */ opl3->command(opl3, OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT, reg_val); return 0; }
linux-master
sound/drivers/opl3/opl3_synth.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Uros Bizjak <[email protected]> * * OPL2/OPL3/OPL4 FM routines for internal percussion channels */ #include "opl3_voice.h" static const char snd_opl3_drum_table[47] = { OPL3_BASSDRUM_ON, OPL3_BASSDRUM_ON, OPL3_HIHAT_ON, /* 35 - 37 */ OPL3_SNAREDRUM_ON, OPL3_HIHAT_ON, OPL3_SNAREDRUM_ON, /* 38 - 40 */ OPL3_BASSDRUM_ON, OPL3_HIHAT_ON, OPL3_BASSDRUM_ON, /* 41 - 43 */ OPL3_HIHAT_ON, OPL3_TOMTOM_ON, OPL3_HIHAT_ON, /* 44 - 46 */ OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_CYMBAL_ON, /* 47 - 49 */ OPL3_TOMTOM_ON, OPL3_CYMBAL_ON, OPL3_CYMBAL_ON, /* 50 - 52 */ OPL3_CYMBAL_ON, OPL3_CYMBAL_ON, OPL3_CYMBAL_ON, /* 53 - 55 */ OPL3_HIHAT_ON, OPL3_CYMBAL_ON, OPL3_TOMTOM_ON, /* 56 - 58 */ OPL3_CYMBAL_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, /* 59 - 61 */ OPL3_HIHAT_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, /* 62 - 64 */ OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, /* 65 - 67 */ OPL3_TOMTOM_ON, OPL3_HIHAT_ON, OPL3_HIHAT_ON, /* 68 - 70 */ OPL3_HIHAT_ON, OPL3_HIHAT_ON, OPL3_TOMTOM_ON, /* 71 - 73 */ OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, /* 74 - 76 */ OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, OPL3_TOMTOM_ON, /* 77 - 79 */ OPL3_CYMBAL_ON, OPL3_CYMBAL_ON /* 80 - 81 */ }; struct snd_opl3_drum_voice { int voice; int op; unsigned char am_vib; unsigned char ksl_level; unsigned char attack_decay; unsigned char sustain_release; unsigned char feedback_connection; unsigned char wave_select; }; struct snd_opl3_drum_note { int voice; unsigned char fnum; unsigned char octave_f; unsigned char feedback_connection; }; static const struct snd_opl3_drum_voice bass_op0 = {6, 0, 0x00, 0x32, 0xf8, 0x66, 0x30, 0x00}; static const struct snd_opl3_drum_voice bass_op1 = {6, 1, 0x00, 0x03, 0xf6, 0x57, 0x30, 0x00}; static const struct snd_opl3_drum_note bass_note = {6, 0x90, 0x09}; static const struct snd_opl3_drum_voice hihat = {7, 0, 0x00, 0x03, 0xf0, 0x06, 0x20, 0x00}; static const struct snd_opl3_drum_voice snare = {7, 1, 0x00, 0x03, 0xf0, 0x07, 0x20, 0x02}; static const struct snd_opl3_drum_note snare_note = {7, 0xf4, 0x0d}; static const struct snd_opl3_drum_voice tomtom = {8, 0, 0x02, 0x03, 0xf0, 0x06, 0x10, 0x00}; static const struct snd_opl3_drum_note tomtom_note = {8, 0xf4, 0x09}; static const struct snd_opl3_drum_voice cymbal = {8, 1, 0x04, 0x03, 0xf0, 0x06, 0x10, 0x00}; /* * set drum voice characteristics */ static void snd_opl3_drum_voice_set(struct snd_opl3 *opl3, const struct snd_opl3_drum_voice *data) { unsigned char op_offset = snd_opl3_regmap[data->voice][data->op]; unsigned char voice_offset = data->voice; unsigned short opl3_reg; /* Set OPL3 AM_VIB register */ opl3_reg = OPL3_LEFT | (OPL3_REG_AM_VIB + op_offset); opl3->command(opl3, opl3_reg, data->am_vib); /* Set OPL3 KSL_LEVEL register */ opl3_reg = OPL3_LEFT | (OPL3_REG_KSL_LEVEL + op_offset); opl3->command(opl3, opl3_reg, data->ksl_level); /* Set OPL3 ATTACK_DECAY register */ opl3_reg = OPL3_LEFT | (OPL3_REG_ATTACK_DECAY + op_offset); opl3->command(opl3, opl3_reg, data->attack_decay); /* Set OPL3 SUSTAIN_RELEASE register */ opl3_reg = OPL3_LEFT | (OPL3_REG_SUSTAIN_RELEASE + op_offset); opl3->command(opl3, opl3_reg, data->sustain_release); /* Set OPL3 FEEDBACK_CONNECTION register */ opl3_reg = OPL3_LEFT | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset); opl3->command(opl3, opl3_reg, data->feedback_connection); /* Select waveform */ opl3_reg = OPL3_LEFT | (OPL3_REG_WAVE_SELECT + op_offset); opl3->command(opl3, opl3_reg, data->wave_select); } /* * Set drum voice pitch */ static void snd_opl3_drum_note_set(struct snd_opl3 *opl3, const struct snd_opl3_drum_note *data) { unsigned char voice_offset = data->voice; unsigned short opl3_reg; /* Set OPL3 FNUM_LOW register */ opl3_reg = OPL3_LEFT | (OPL3_REG_FNUM_LOW + voice_offset); opl3->command(opl3, opl3_reg, data->fnum); /* Set OPL3 KEYON_BLOCK register */ opl3_reg = OPL3_LEFT | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3->command(opl3, opl3_reg, data->octave_f); } /* * Set drum voice volume and position */ static void snd_opl3_drum_vol_set(struct snd_opl3 *opl3, const struct snd_opl3_drum_voice *data, int vel, struct snd_midi_channel *chan) { unsigned char op_offset = snd_opl3_regmap[data->voice][data->op]; unsigned char voice_offset = data->voice; unsigned char reg_val; unsigned short opl3_reg; /* Set OPL3 KSL_LEVEL register */ reg_val = data->ksl_level; snd_opl3_calc_volume(&reg_val, vel, chan); opl3_reg = OPL3_LEFT | (OPL3_REG_KSL_LEVEL + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set OPL3 FEEDBACK_CONNECTION register */ /* Set output voice connection */ reg_val = data->feedback_connection | OPL3_STEREO_BITS; if (chan->gm_pan < 43) reg_val &= ~OPL3_VOICE_TO_RIGHT; if (chan->gm_pan > 85) reg_val &= ~OPL3_VOICE_TO_LEFT; opl3_reg = OPL3_LEFT | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset); opl3->command(opl3, opl3_reg, reg_val); } /* * Loads drum voices at init time */ void snd_opl3_load_drums(struct snd_opl3 *opl3) { snd_opl3_drum_voice_set(opl3, &bass_op0); snd_opl3_drum_voice_set(opl3, &bass_op1); snd_opl3_drum_note_set(opl3, &bass_note); snd_opl3_drum_voice_set(opl3, &hihat); snd_opl3_drum_voice_set(opl3, &snare); snd_opl3_drum_note_set(opl3, &snare_note); snd_opl3_drum_voice_set(opl3, &tomtom); snd_opl3_drum_note_set(opl3, &tomtom_note); snd_opl3_drum_voice_set(opl3, &cymbal); } /* * Switch drum voice on or off */ void snd_opl3_drum_switch(struct snd_opl3 *opl3, int note, int vel, int on_off, struct snd_midi_channel *chan) { unsigned char drum_mask; const struct snd_opl3_drum_voice *drum_voice; if (!(opl3->drum_reg & OPL3_PERCUSSION_ENABLE)) return; if ((note < 35) || (note > 81)) return; drum_mask = snd_opl3_drum_table[note - 35]; if (on_off) { switch (drum_mask) { case OPL3_BASSDRUM_ON: drum_voice = &bass_op1; break; case OPL3_HIHAT_ON: drum_voice = &hihat; break; case OPL3_SNAREDRUM_ON: drum_voice = &snare; break; case OPL3_TOMTOM_ON: drum_voice = &tomtom; break; case OPL3_CYMBAL_ON: drum_voice = &cymbal; break; default: drum_voice = &tomtom; } snd_opl3_drum_vol_set(opl3, drum_voice, vel, chan); opl3->drum_reg |= drum_mask; } else { opl3->drum_reg &= ~drum_mask; } opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, opl3->drum_reg); }
linux-master
sound/drivers/opl3/opl3_drums.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Uros Bizjak <[email protected]> * * Midi synth routines for OPL2/OPL3/OPL4 FM */ #undef DEBUG_ALLOC #undef DEBUG_MIDI #include "opl3_voice.h" #include <sound/asoundef.h> static void snd_opl3_note_off_unsafe(void *p, int note, int vel, struct snd_midi_channel *chan); /* * The next table looks magical, but it certainly is not. Its values have * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception * for i=0. This log-table converts a linear volume-scaling (0..127) to a * logarithmic scaling as present in the FM-synthesizer chips. so : Volume * 64 = 0 db = relative volume 0 and: Volume 32 = -6 db = relative * volume -8 it was implemented as a table because it is only 128 bytes and * it saves a lot of log() calculations. (Rob Hooft <[email protected]>) */ static const char opl3_volume_table[128] = { -63, -48, -40, -35, -32, -29, -27, -26, -24, -23, -21, -20, -19, -18, -18, -17, -16, -15, -15, -14, -13, -13, -12, -12, -11, -11, -10, -10, -10, -9, -9, -8, -8, -8, -7, -7, -7, -6, -6, -6, -5, -5, -5, -5, -4, -4, -4, -4, -3, -3, -3, -3, -2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8 }; void snd_opl3_calc_volume(unsigned char *volbyte, int vel, struct snd_midi_channel *chan) { int oldvol, newvol, n; int volume; volume = (vel * chan->gm_volume * chan->gm_expression) / (127*127); if (volume > 127) volume = 127; oldvol = OPL3_TOTAL_LEVEL_MASK - (*volbyte & OPL3_TOTAL_LEVEL_MASK); newvol = opl3_volume_table[volume] + oldvol; if (newvol > OPL3_TOTAL_LEVEL_MASK) newvol = OPL3_TOTAL_LEVEL_MASK; else if (newvol < 0) newvol = 0; n = OPL3_TOTAL_LEVEL_MASK - (newvol & OPL3_TOTAL_LEVEL_MASK); *volbyte = (*volbyte & OPL3_KSL_MASK) | (n & OPL3_TOTAL_LEVEL_MASK); } /* * Converts the note frequency to block and fnum values for the FM chip */ static const short opl3_note_table[16] = { 305, 323, /* for pitch bending, -2 semitones */ 343, 363, 385, 408, 432, 458, 485, 514, 544, 577, 611, 647, 686, 726 /* for pitch bending, +2 semitones */ }; static void snd_opl3_calc_pitch(unsigned char *fnum, unsigned char *blocknum, int note, struct snd_midi_channel *chan) { int block = ((note / 12) & 0x07) - 1; int idx = (note % 12) + 2; int freq; if (chan->midi_pitchbend) { int pitchbend = chan->midi_pitchbend; int segment; if (pitchbend < -0x2000) pitchbend = -0x2000; if (pitchbend > 0x1FFF) pitchbend = 0x1FFF; segment = pitchbend / 0x1000; freq = opl3_note_table[idx+segment]; freq += ((opl3_note_table[idx+segment+1] - freq) * (pitchbend % 0x1000)) / 0x1000; } else { freq = opl3_note_table[idx]; } *fnum = (unsigned char) freq; *blocknum = ((freq >> 8) & OPL3_FNUM_HIGH_MASK) | ((block << 2) & OPL3_BLOCKNUM_MASK); } #ifdef DEBUG_ALLOC static void debug_alloc(struct snd_opl3 *opl3, char *s, int voice) { int i; char *str = "x.24"; printk(KERN_DEBUG "time %.5i: %s [%.2i]: ", opl3->use_time, s, voice); for (i = 0; i < opl3->max_voices; i++) printk(KERN_CONT "%c", *(str + opl3->voices[i].state + 1)); printk(KERN_CONT "\n"); } #endif /* * Get a FM voice (channel) to play a note on. */ static int opl3_get_voice(struct snd_opl3 *opl3, int instr_4op, struct snd_midi_channel *chan) { int chan_4op_1; /* first voice for 4op instrument */ int chan_4op_2; /* second voice for 4op instrument */ struct snd_opl3_voice *vp, *vp2; unsigned int voice_time; int i; #ifdef DEBUG_ALLOC char *alloc_type[3] = { "FREE ", "CHEAP ", "EXPENSIVE" }; #endif /* This is our "allocation cost" table */ enum { FREE = 0, CHEAP, EXPENSIVE, END }; /* Keeps track of what we are finding */ struct best { unsigned int time; int voice; } best[END]; struct best *bp; for (i = 0; i < END; i++) { best[i].time = (unsigned int)(-1); /* XXX MAX_?INT really */ best[i].voice = -1; } /* Look through all the channels for the most suitable. */ for (i = 0; i < opl3->max_voices; i++) { vp = &opl3->voices[i]; if (vp->state == SNDRV_OPL3_ST_NOT_AVAIL) /* skip unavailable channels, allocated by drum voices or by bounded 4op voices) */ continue; voice_time = vp->time; bp = best; chan_4op_1 = ((i < 3) || (i > 8 && i < 12)); chan_4op_2 = ((i > 2 && i < 6) || (i > 11 && i < 15)); if (instr_4op) { /* allocate 4op voice */ /* skip channels unavailable to 4op instrument */ if (!chan_4op_1) continue; if (vp->state) /* kill one voice, CHEAP */ bp++; /* get state of bounded 2op channel to be allocated for 4op instrument */ vp2 = &opl3->voices[i + 3]; if (vp2->state == SNDRV_OPL3_ST_ON_2OP) { /* kill two voices, EXPENSIVE */ bp++; voice_time = max(voice_time, vp2->time); } } else { /* allocate 2op voice */ if ((chan_4op_1) || (chan_4op_2)) /* use bounded channels for 2op, CHEAP */ bp++; else if (vp->state) /* kill one voice on 2op channel, CHEAP */ bp++; /* raise kill cost to EXPENSIVE for all channels */ if (vp->state) bp++; } if (voice_time < bp->time) { bp->time = voice_time; bp->voice = i; } } for (i = 0; i < END; i++) { if (best[i].voice >= 0) { #ifdef DEBUG_ALLOC printk(KERN_DEBUG "%s %iop allocation on voice %i\n", alloc_type[i], instr_4op ? 4 : 2, best[i].voice); #endif return best[i].voice; } } /* not found */ return -1; } /* ------------------------------ */ /* * System timer interrupt function */ void snd_opl3_timer_func(struct timer_list *t) { struct snd_opl3 *opl3 = from_timer(opl3, t, tlist); unsigned long flags; int again = 0; int i; spin_lock_irqsave(&opl3->voice_lock, flags); for (i = 0; i < opl3->max_voices; i++) { struct snd_opl3_voice *vp = &opl3->voices[i]; if (vp->state > 0 && vp->note_off_check) { if (vp->note_off == jiffies) snd_opl3_note_off_unsafe(opl3, vp->note, 0, vp->chan); else again++; } } spin_unlock_irqrestore(&opl3->voice_lock, flags); spin_lock_irqsave(&opl3->sys_timer_lock, flags); if (again) mod_timer(&opl3->tlist, jiffies + 1); /* invoke again */ else opl3->sys_timer_status = 0; spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); } /* * Start system timer */ static void snd_opl3_start_timer(struct snd_opl3 *opl3) { unsigned long flags; spin_lock_irqsave(&opl3->sys_timer_lock, flags); if (! opl3->sys_timer_status) { mod_timer(&opl3->tlist, jiffies + 1); opl3->sys_timer_status = 1; } spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); } /* ------------------------------ */ static const int snd_opl3_oss_map[MAX_OPL3_VOICES] = { 0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17, 3, 4 ,5, 12, 13, 14 }; /* * Start a note. */ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl3 *opl3; int instr_4op; int voice; struct snd_opl3_voice *vp, *vp2; unsigned short connect_mask; unsigned char connection; unsigned char vol_op[4]; int extra_prg = 0; unsigned short reg_side; unsigned char op_offset; unsigned char voice_offset; unsigned short opl3_reg; unsigned char reg_val; unsigned char prg, bank; int key = note; unsigned char fnum, blocknum; int i; struct fm_patch *patch; struct fm_instrument *fm; unsigned long flags; opl3 = p; #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "Note on, ch %i, inst %i, note %i, vel %i\n", chan->number, chan->midi_program, note, vel); #endif /* in SYNTH mode, application takes care of voices */ /* in SEQ mode, drum voice numbers are notes on drum channel */ if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { if (chan->drum_channel) { /* percussion instruments are located in bank 128 */ bank = 128; prg = note; } else { bank = chan->gm_bank_select; prg = chan->midi_program; } } else { /* Prepare for OSS mode */ if (chan->number >= MAX_OPL3_VOICES) return; /* OSS instruments are located in bank 127 */ bank = 127; prg = chan->midi_program; } spin_lock_irqsave(&opl3->voice_lock, flags); if (use_internal_drums) { snd_opl3_drum_switch(opl3, note, vel, 1, chan); spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } __extra_prg: patch = snd_opl3_find_patch(opl3, prg, bank, 0); if (!patch) { spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } fm = &patch->inst; switch (patch->type) { case FM_PATCH_OPL2: instr_4op = 0; break; case FM_PATCH_OPL3: if (opl3->hardware >= OPL3_HW_OPL3) { instr_4op = 1; break; } fallthrough; default: spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " --> OPL%i instrument: %s\n", instr_4op ? 3 : 2, patch->name); #endif /* in SYNTH mode, application takes care of voices */ /* in SEQ mode, allocate voice on free OPL3 channel */ if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { voice = opl3_get_voice(opl3, instr_4op, chan); } else { /* remap OSS voice */ voice = snd_opl3_oss_map[chan->number]; } if (voice < 0) { spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } if (voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = voice; connect_mask = (OPL3_LEFT_4OP_0 << voice_offset) & 0x07; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = voice - MAX_OPL2_VOICES; connect_mask = (OPL3_RIGHT_4OP_0 << voice_offset) & 0x38; } /* kill voice on channel */ vp = &opl3->voices[voice]; if (vp->state > 0) { opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); reg_val = vp->keyon_reg & ~OPL3_KEYON_BIT; opl3->command(opl3, opl3_reg, reg_val); } if (instr_4op) { vp2 = &opl3->voices[voice + 3]; if (vp2->state > 0) { opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset + 3); reg_val = vp->keyon_reg & ~OPL3_KEYON_BIT; opl3->command(opl3, opl3_reg, reg_val); } } /* set connection register */ if (instr_4op) { if ((opl3->connection_reg ^ connect_mask) & connect_mask) { opl3->connection_reg |= connect_mask; /* set connection bit */ opl3_reg = OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT; opl3->command(opl3, opl3_reg, opl3->connection_reg); } } else { if ((opl3->connection_reg ^ ~connect_mask) & connect_mask) { opl3->connection_reg &= ~connect_mask; /* clear connection bit */ opl3_reg = OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT; opl3->command(opl3, opl3_reg, opl3->connection_reg); } } #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " --> setting OPL3 connection: 0x%x\n", opl3->connection_reg); #endif /* * calculate volume depending on connection * between FM operators (see include/opl3.h) */ for (i = 0; i < (instr_4op ? 4 : 2); i++) vol_op[i] = fm->op[i].ksl_level; connection = fm->feedback_connection[0] & 0x01; if (instr_4op) { connection <<= 1; connection |= fm->feedback_connection[1] & 0x01; snd_opl3_calc_volume(&vol_op[3], vel, chan); switch (connection) { case 0x03: snd_opl3_calc_volume(&vol_op[2], vel, chan); fallthrough; case 0x02: snd_opl3_calc_volume(&vol_op[0], vel, chan); break; case 0x01: snd_opl3_calc_volume(&vol_op[1], vel, chan); } } else { snd_opl3_calc_volume(&vol_op[1], vel, chan); if (connection) snd_opl3_calc_volume(&vol_op[0], vel, chan); } /* Program the FM voice characteristics */ for (i = 0; i < (instr_4op ? 4 : 2); i++) { #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " --> programming operator %i\n", i); #endif op_offset = snd_opl3_regmap[voice_offset][i]; /* Set OPL3 AM_VIB register of requested voice/operator */ reg_val = fm->op[i].am_vib; opl3_reg = reg_side | (OPL3_REG_AM_VIB + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set OPL3 KSL_LEVEL register of requested voice/operator */ reg_val = vol_op[i]; opl3_reg = reg_side | (OPL3_REG_KSL_LEVEL + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set OPL3 ATTACK_DECAY register of requested voice/operator */ reg_val = fm->op[i].attack_decay; opl3_reg = reg_side | (OPL3_REG_ATTACK_DECAY + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Set OPL3 SUSTAIN_RELEASE register of requested voice/operator */ reg_val = fm->op[i].sustain_release; opl3_reg = reg_side | (OPL3_REG_SUSTAIN_RELEASE + op_offset); opl3->command(opl3, opl3_reg, reg_val); /* Select waveform */ reg_val = fm->op[i].wave_select; opl3_reg = reg_side | (OPL3_REG_WAVE_SELECT + op_offset); opl3->command(opl3, opl3_reg, reg_val); } /* Set operator feedback and 2op inter-operator connection */ reg_val = fm->feedback_connection[0]; /* Set output voice connection */ reg_val |= OPL3_STEREO_BITS; if (chan->gm_pan < 43) reg_val &= ~OPL3_VOICE_TO_RIGHT; if (chan->gm_pan > 85) reg_val &= ~OPL3_VOICE_TO_LEFT; opl3_reg = reg_side | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset); opl3->command(opl3, opl3_reg, reg_val); if (instr_4op) { /* Set 4op inter-operator connection */ reg_val = fm->feedback_connection[1] & OPL3_CONNECTION_BIT; /* Set output voice connection */ reg_val |= OPL3_STEREO_BITS; if (chan->gm_pan < 43) reg_val &= ~OPL3_VOICE_TO_RIGHT; if (chan->gm_pan > 85) reg_val &= ~OPL3_VOICE_TO_LEFT; opl3_reg = reg_side | (OPL3_REG_FEEDBACK_CONNECTION + voice_offset + 3); opl3->command(opl3, opl3_reg, reg_val); } /* * Special treatment of percussion notes for fm: * Requested pitch is really program, and pitch for * device is whatever was specified in the patch library. */ if (fm->fix_key) note = fm->fix_key; /* * use transpose if defined in patch library */ if (fm->trnsps) note += (fm->trnsps - 64); snd_opl3_calc_pitch(&fnum, &blocknum, note, chan); /* Set OPL3 FNUM_LOW register of requested voice */ opl3_reg = reg_side | (OPL3_REG_FNUM_LOW + voice_offset); opl3->command(opl3, opl3_reg, fnum); opl3->voices[voice].keyon_reg = blocknum; /* Set output sound flag */ blocknum |= OPL3_KEYON_BIT; #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " --> trigger voice %i\n", voice); #endif /* Set OPL3 KEYON_BLOCK register of requested voice */ opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3->command(opl3, opl3_reg, blocknum); /* kill note after fixed duration (in centiseconds) */ if (fm->fix_dur) { opl3->voices[voice].note_off = jiffies + (fm->fix_dur * HZ) / 100; snd_opl3_start_timer(opl3); opl3->voices[voice].note_off_check = 1; } else opl3->voices[voice].note_off_check = 0; /* get extra pgm, but avoid possible loops */ extra_prg = (extra_prg) ? 0 : fm->modes; /* do the bookkeeping */ vp->time = opl3->use_time++; vp->note = key; vp->chan = chan; if (instr_4op) { vp->state = SNDRV_OPL3_ST_ON_4OP; vp2 = &opl3->voices[voice + 3]; vp2->time = opl3->use_time++; vp2->note = key; vp2->chan = chan; vp2->state = SNDRV_OPL3_ST_NOT_AVAIL; } else { if (vp->state == SNDRV_OPL3_ST_ON_4OP) { /* 4op killed by 2op, release bounded voice */ vp2 = &opl3->voices[voice + 3]; vp2->time = opl3->use_time++; vp2->state = SNDRV_OPL3_ST_OFF; } vp->state = SNDRV_OPL3_ST_ON_2OP; } #ifdef DEBUG_ALLOC debug_alloc(opl3, "note on ", voice); #endif /* allocate extra program if specified in patch library */ if (extra_prg) { if (extra_prg > 128) { bank = 128; /* percussions start at 35 */ prg = extra_prg - 128 + 35 - 1; } else { bank = 0; prg = extra_prg - 1; } #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " *** allocating extra program\n"); #endif goto __extra_prg; } spin_unlock_irqrestore(&opl3->voice_lock, flags); } static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice) { unsigned short reg_side; unsigned char voice_offset; unsigned short opl3_reg; struct snd_opl3_voice *vp, *vp2; if (snd_BUG_ON(voice >= MAX_OPL3_VOICES)) return; vp = &opl3->voices[voice]; if (voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = voice; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = voice - MAX_OPL2_VOICES; } /* kill voice */ #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG " --> kill voice %i\n", voice); #endif opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); /* clear Key ON bit */ opl3->command(opl3, opl3_reg, vp->keyon_reg); /* do the bookkeeping */ vp->time = opl3->use_time++; if (vp->state == SNDRV_OPL3_ST_ON_4OP) { vp2 = &opl3->voices[voice + 3]; vp2->time = opl3->use_time++; vp2->state = SNDRV_OPL3_ST_OFF; } vp->state = SNDRV_OPL3_ST_OFF; #ifdef DEBUG_ALLOC debug_alloc(opl3, "note off", voice); #endif } /* * Release a note in response to a midi note off. */ static void snd_opl3_note_off_unsafe(void *p, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl3 *opl3; int voice; struct snd_opl3_voice *vp; opl3 = p; #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "Note off, ch %i, inst %i, note %i\n", chan->number, chan->midi_program, note); #endif if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { if (chan->drum_channel && use_internal_drums) { snd_opl3_drum_switch(opl3, note, vel, 0, chan); return; } /* this loop will hopefully kill all extra voices, because they are grouped by the same channel and note values */ for (voice = 0; voice < opl3->max_voices; voice++) { vp = &opl3->voices[voice]; if (vp->state > 0 && vp->chan == chan && vp->note == note) { snd_opl3_kill_voice(opl3, voice); } } } else { /* remap OSS voices */ if (chan->number < MAX_OPL3_VOICES) { voice = snd_opl3_oss_map[chan->number]; snd_opl3_kill_voice(opl3, voice); } } } void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl3 *opl3 = p; unsigned long flags; spin_lock_irqsave(&opl3->voice_lock, flags); snd_opl3_note_off_unsafe(p, note, vel, chan); spin_unlock_irqrestore(&opl3->voice_lock, flags); } /* * key pressure change */ void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *chan) { #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "Key pressure, ch#: %i, inst#: %i\n", chan->number, chan->midi_program); #endif } /* * terminate note */ void snd_opl3_terminate_note(void *p, int note, struct snd_midi_channel *chan) { #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "Terminate note, ch#: %i, inst#: %i\n", chan->number, chan->midi_program); #endif } static void snd_opl3_update_pitch(struct snd_opl3 *opl3, int voice) { unsigned short reg_side; unsigned char voice_offset; unsigned short opl3_reg; unsigned char fnum, blocknum; struct snd_opl3_voice *vp; if (snd_BUG_ON(voice >= MAX_OPL3_VOICES)) return; vp = &opl3->voices[voice]; if (vp->chan == NULL) return; /* not allocated? */ if (voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ reg_side = OPL3_LEFT; voice_offset = voice; } else { /* Right register block for voices 9 .. 17 */ reg_side = OPL3_RIGHT; voice_offset = voice - MAX_OPL2_VOICES; } snd_opl3_calc_pitch(&fnum, &blocknum, vp->note, vp->chan); /* Set OPL3 FNUM_LOW register of requested voice */ opl3_reg = reg_side | (OPL3_REG_FNUM_LOW + voice_offset); opl3->command(opl3, opl3_reg, fnum); vp->keyon_reg = blocknum; /* Set output sound flag */ blocknum |= OPL3_KEYON_BIT; /* Set OPL3 KEYON_BLOCK register of requested voice */ opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3->command(opl3, opl3_reg, blocknum); vp->time = opl3->use_time++; } /* * Update voice pitch controller */ static void snd_opl3_pitch_ctrl(struct snd_opl3 *opl3, struct snd_midi_channel *chan) { int voice; struct snd_opl3_voice *vp; unsigned long flags; spin_lock_irqsave(&opl3->voice_lock, flags); if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { for (voice = 0; voice < opl3->max_voices; voice++) { vp = &opl3->voices[voice]; if (vp->state > 0 && vp->chan == chan) { snd_opl3_update_pitch(opl3, voice); } } } else { /* remap OSS voices */ if (chan->number < MAX_OPL3_VOICES) { voice = snd_opl3_oss_map[chan->number]; snd_opl3_update_pitch(opl3, voice); } } spin_unlock_irqrestore(&opl3->voice_lock, flags); } /* * Deal with a controller type event. This includes all types of * control events, not just the midi controllers */ void snd_opl3_control(void *p, int type, struct snd_midi_channel *chan) { struct snd_opl3 *opl3; opl3 = p; #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "Controller, TYPE = %i, ch#: %i, inst#: %i\n", type, chan->number, chan->midi_program); #endif switch (type) { case MIDI_CTL_MSB_MODWHEEL: if (chan->control[MIDI_CTL_MSB_MODWHEEL] > 63) opl3->drum_reg |= OPL3_VIBRATO_DEPTH; else opl3->drum_reg &= ~OPL3_VIBRATO_DEPTH; opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, opl3->drum_reg); break; case MIDI_CTL_E2_TREMOLO_DEPTH: if (chan->control[MIDI_CTL_E2_TREMOLO_DEPTH] > 63) opl3->drum_reg |= OPL3_TREMOLO_DEPTH; else opl3->drum_reg &= ~OPL3_TREMOLO_DEPTH; opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, opl3->drum_reg); break; case MIDI_CTL_PITCHBEND: snd_opl3_pitch_ctrl(opl3, chan); break; } } /* * NRPN events */ void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan, struct snd_midi_channel_set *chset) { #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "NRPN, ch#: %i, inst#: %i\n", chan->number, chan->midi_program); #endif } /* * receive sysex */ void snd_opl3_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset) { #ifdef DEBUG_MIDI snd_printk(KERN_DEBUG "SYSEX\n"); #endif }
linux-master
sound/drivers/opl3/opl3_midi.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Interface for OSS sequencer emulation * * Copyright (C) 2000 Uros Bizjak <[email protected]> */ #include <linux/export.h> #include "opl3_voice.h" static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure); static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg); static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd, unsigned long ioarg); static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format, const char __user *buf, int offs, int count); static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg); /* operators */ static const struct snd_seq_oss_callback oss_callback = { .owner = THIS_MODULE, .open = snd_opl3_open_seq_oss, .close = snd_opl3_close_seq_oss, .ioctl = snd_opl3_ioctl_seq_oss, .load_patch = snd_opl3_load_patch_seq_oss, .reset = snd_opl3_reset_seq_oss, }; static int snd_opl3_oss_event_input(struct snd_seq_event *ev, int direct, void *private_data, int atomic, int hop) { struct snd_opl3 *opl3 = private_data; if (ev->type != SNDRV_SEQ_EVENT_OSS) snd_midi_process_event(&opl3_ops, ev, opl3->oss_chset); return 0; } /* ------------------------------ */ static void snd_opl3_oss_free_port(void *private_data) { struct snd_opl3 *opl3 = private_data; snd_midi_channel_free_set(opl3->oss_chset); } static int snd_opl3_oss_create_port(struct snd_opl3 * opl3) { struct snd_seq_port_callback callbacks; char name[32]; int voices, opl_ver; voices = (opl3->hardware < OPL3_HW_OPL3) ? MAX_OPL2_VOICES : MAX_OPL3_VOICES; opl3->oss_chset = snd_midi_channel_alloc_set(voices); if (opl3->oss_chset == NULL) return -ENOMEM; opl3->oss_chset->private_data = opl3; memset(&callbacks, 0, sizeof(callbacks)); callbacks.owner = THIS_MODULE; callbacks.event_input = snd_opl3_oss_event_input; callbacks.private_free = snd_opl3_oss_free_port; callbacks.private_data = opl3; opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8; sprintf(name, "OPL%i OSS Port", opl_ver); opl3->oss_chset->client = opl3->seq_client; opl3->oss_chset->port = snd_seq_event_port_attach(opl3->seq_client, &callbacks, SNDRV_SEQ_PORT_CAP_WRITE, SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | SNDRV_SEQ_PORT_TYPE_MIDI_GM | SNDRV_SEQ_PORT_TYPE_HARDWARE | SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, voices, voices, name); if (opl3->oss_chset->port < 0) { int port; port = opl3->oss_chset->port; snd_midi_channel_free_set(opl3->oss_chset); return port; } return 0; } /* ------------------------------ */ /* register OSS synth */ void snd_opl3_init_seq_oss(struct snd_opl3 *opl3, char *name) { struct snd_seq_oss_reg *arg; struct snd_seq_device *dev; if (snd_seq_device_new(opl3->card, 0, SNDRV_SEQ_DEV_ID_OSS, sizeof(struct snd_seq_oss_reg), &dev) < 0) return; opl3->oss_seq_dev = dev; strscpy(dev->name, name, sizeof(dev->name)); arg = SNDRV_SEQ_DEVICE_ARGPTR(dev); arg->type = SYNTH_TYPE_FM; if (opl3->hardware < OPL3_HW_OPL3) { arg->subtype = FM_TYPE_ADLIB; arg->nvoices = MAX_OPL2_VOICES; } else { arg->subtype = FM_TYPE_OPL3; arg->nvoices = MAX_OPL3_VOICES; } arg->oper = oss_callback; arg->private_data = opl3; if (snd_opl3_oss_create_port(opl3)) { /* register to OSS synth table */ snd_device_register(opl3->card, dev); } } /* unregister */ void snd_opl3_free_seq_oss(struct snd_opl3 *opl3) { if (opl3->oss_seq_dev) { /* The instance should have been released in prior */ opl3->oss_seq_dev = NULL; } } /* ------------------------------ */ /* open OSS sequencer */ static int snd_opl3_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure) { struct snd_opl3 *opl3 = closure; int err; if (snd_BUG_ON(!arg)) return -ENXIO; err = snd_opl3_synth_setup(opl3); if (err < 0) return err; /* fill the argument data */ arg->private_data = opl3; arg->addr.client = opl3->oss_chset->client; arg->addr.port = opl3->oss_chset->port; err = snd_opl3_synth_use_inc(opl3); if (err < 0) return err; opl3->synth_mode = SNDRV_OPL3_MODE_SYNTH; return 0; } /* close OSS sequencer */ static int snd_opl3_close_seq_oss(struct snd_seq_oss_arg *arg) { struct snd_opl3 *opl3; if (snd_BUG_ON(!arg)) return -ENXIO; opl3 = arg->private_data; snd_opl3_synth_cleanup(opl3); snd_opl3_synth_use_dec(opl3); return 0; } /* load patch */ /* from sound_config.h */ #define SBFM_MAXINSTR 256 static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format, const char __user *buf, int offs, int count) { struct snd_opl3 *opl3; struct sbi_instrument sbi; char name[32]; int err, type; if (snd_BUG_ON(!arg)) return -ENXIO; opl3 = arg->private_data; if (format == FM_PATCH) type = FM_PATCH_OPL2; else if (format == OPL3_PATCH) type = FM_PATCH_OPL3; else return -EINVAL; if (count < (int)sizeof(sbi)) { snd_printk(KERN_ERR "FM Error: Patch record too short\n"); return -EINVAL; } if (copy_from_user(&sbi, buf, sizeof(sbi))) return -EFAULT; if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) { snd_printk(KERN_ERR "FM Error: Invalid instrument number %d\n", sbi.channel); return -EINVAL; } memset(name, 0, sizeof(name)); sprintf(name, "Chan%d", sbi.channel); err = snd_opl3_load_patch(opl3, sbi.channel, 127, type, name, NULL, sbi.operators); if (err < 0) return err; return sizeof(sbi); } /* ioctl */ static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd, unsigned long ioarg) { if (snd_BUG_ON(!arg)) return -ENXIO; switch (cmd) { case SNDCTL_FM_LOAD_INSTR: snd_printk(KERN_ERR "OPL3: " "Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. " "Fix the program.\n"); return -EINVAL; case SNDCTL_SYNTH_MEMAVL: return 0x7fffffff; case SNDCTL_FM_4OP_ENABLE: // handled automatically by OPL instrument type return 0; default: return -EINVAL; } return 0; } /* reset device */ static int snd_opl3_reset_seq_oss(struct snd_seq_oss_arg *arg) { if (snd_BUG_ON(!arg)) return -ENXIO; return 0; }
linux-master
sound/drivers/opl3/opl3_oss.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Uros Bizjak <[email protected]> * * Midi Sequencer interface routines for OPL2/OPL3/OPL4 FM * * OPL2/3 FM instrument loader: * alsa-tools/seq/sbiload/ */ #include "opl3_voice.h" #include <linux/init.h> #include <linux/moduleparam.h> #include <linux/module.h> #include <sound/initval.h> MODULE_AUTHOR("Uros Bizjak <[email protected]>"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("ALSA driver for OPL3 FM synth"); bool use_internal_drums = 0; module_param(use_internal_drums, bool, 0444); MODULE_PARM_DESC(use_internal_drums, "Enable internal OPL2/3 drums."); int snd_opl3_synth_use_inc(struct snd_opl3 * opl3) { if (!try_module_get(opl3->card->module)) return -EFAULT; return 0; } void snd_opl3_synth_use_dec(struct snd_opl3 * opl3) { module_put(opl3->card->module); } int snd_opl3_synth_setup(struct snd_opl3 * opl3) { int idx; struct snd_hwdep *hwdep = opl3->hwdep; mutex_lock(&hwdep->open_mutex); if (hwdep->used) { mutex_unlock(&hwdep->open_mutex); return -EBUSY; } hwdep->used++; mutex_unlock(&hwdep->open_mutex); snd_opl3_reset(opl3); for (idx = 0; idx < MAX_OPL3_VOICES; idx++) { opl3->voices[idx].state = SNDRV_OPL3_ST_OFF; opl3->voices[idx].time = 0; opl3->voices[idx].keyon_reg = 0x00; } opl3->use_time = 0; opl3->connection_reg = 0x00; if (opl3->hardware >= OPL3_HW_OPL3) { /* Clear 4-op connections */ opl3->command(opl3, OPL3_RIGHT | OPL3_REG_CONNECTION_SELECT, opl3->connection_reg); opl3->max_voices = MAX_OPL3_VOICES; } return 0; } void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) { unsigned long flags; struct snd_hwdep *hwdep; /* Stop system timer */ spin_lock_irqsave(&opl3->sys_timer_lock, flags); if (opl3->sys_timer_status) { del_timer(&opl3->tlist); opl3->sys_timer_status = 0; } spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); snd_opl3_reset(opl3); hwdep = opl3->hwdep; mutex_lock(&hwdep->open_mutex); hwdep->used--; mutex_unlock(&hwdep->open_mutex); wake_up(&hwdep->open_wait); } static int snd_opl3_synth_use(void *private_data, struct snd_seq_port_subscribe * info) { struct snd_opl3 *opl3 = private_data; int err; err = snd_opl3_synth_setup(opl3); if (err < 0) return err; if (use_internal_drums) { /* Percussion mode */ opl3->voices[6].state = opl3->voices[7].state = opl3->voices[8].state = SNDRV_OPL3_ST_NOT_AVAIL; snd_opl3_load_drums(opl3); opl3->drum_reg = OPL3_PERCUSSION_ENABLE; opl3->command(opl3, OPL3_LEFT | OPL3_REG_PERCUSSION, opl3->drum_reg); } else { opl3->drum_reg = 0x00; } if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM) { err = snd_opl3_synth_use_inc(opl3); if (err < 0) return err; } opl3->synth_mode = SNDRV_OPL3_MODE_SEQ; return 0; } static int snd_opl3_synth_unuse(void *private_data, struct snd_seq_port_subscribe * info) { struct snd_opl3 *opl3 = private_data; snd_opl3_synth_cleanup(opl3); if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM) snd_opl3_synth_use_dec(opl3); return 0; } /* * MIDI emulation operators */ const struct snd_midi_op opl3_ops = { .note_on = snd_opl3_note_on, .note_off = snd_opl3_note_off, .key_press = snd_opl3_key_press, .note_terminate = snd_opl3_terminate_note, .control = snd_opl3_control, .nrpn = snd_opl3_nrpn, .sysex = snd_opl3_sysex, }; static int snd_opl3_synth_event_input(struct snd_seq_event * ev, int direct, void *private_data, int atomic, int hop) { struct snd_opl3 *opl3 = private_data; snd_midi_process_event(&opl3_ops, ev, opl3->chset); return 0; } /* ------------------------------ */ static void snd_opl3_synth_free_port(void *private_data) { struct snd_opl3 *opl3 = private_data; snd_midi_channel_free_set(opl3->chset); } static int snd_opl3_synth_create_port(struct snd_opl3 * opl3) { struct snd_seq_port_callback callbacks; char name[32]; int voices, opl_ver; voices = (opl3->hardware < OPL3_HW_OPL3) ? MAX_OPL2_VOICES : MAX_OPL3_VOICES; opl3->chset = snd_midi_channel_alloc_set(16); if (opl3->chset == NULL) return -ENOMEM; opl3->chset->private_data = opl3; memset(&callbacks, 0, sizeof(callbacks)); callbacks.owner = THIS_MODULE; callbacks.use = snd_opl3_synth_use; callbacks.unuse = snd_opl3_synth_unuse; callbacks.event_input = snd_opl3_synth_event_input; callbacks.private_free = snd_opl3_synth_free_port; callbacks.private_data = opl3; opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8; sprintf(name, "OPL%i FM Port", opl_ver); opl3->chset->client = opl3->seq_client; opl3->chset->port = snd_seq_event_port_attach(opl3->seq_client, &callbacks, SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE, SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | SNDRV_SEQ_PORT_TYPE_MIDI_GM | SNDRV_SEQ_PORT_TYPE_DIRECT_SAMPLE | SNDRV_SEQ_PORT_TYPE_HARDWARE | SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, 16, voices, name); if (opl3->chset->port < 0) { int port; port = opl3->chset->port; snd_midi_channel_free_set(opl3->chset); return port; } return 0; } /* ------------------------------ */ static int snd_opl3_seq_probe(struct device *_dev) { struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_opl3 *opl3; int client, err; char name[32]; int opl_ver; opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (opl3 == NULL) return -EINVAL; spin_lock_init(&opl3->voice_lock); opl3->seq_client = -1; /* allocate new client */ opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8; sprintf(name, "OPL%i FM synth", opl_ver); client = opl3->seq_client = snd_seq_create_kernel_client(opl3->card, opl3->seq_dev_num, name); if (client < 0) return client; err = snd_opl3_synth_create_port(opl3); if (err < 0) { snd_seq_delete_kernel_client(client); opl3->seq_client = -1; return err; } /* setup system timer */ timer_setup(&opl3->tlist, snd_opl3_timer_func, 0); spin_lock_init(&opl3->sys_timer_lock); opl3->sys_timer_status = 0; #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) snd_opl3_init_seq_oss(opl3, name); #endif return 0; } static int snd_opl3_seq_remove(struct device *_dev) { struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_opl3 *opl3; opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (opl3 == NULL) return -EINVAL; #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS) snd_opl3_free_seq_oss(opl3); #endif if (opl3->seq_client >= 0) { snd_seq_delete_kernel_client(opl3->seq_client); opl3->seq_client = -1; } return 0; } static struct snd_seq_driver opl3_seq_driver = { .driver = { .name = KBUILD_MODNAME, .probe = snd_opl3_seq_probe, .remove = snd_opl3_seq_remove, }, .id = SNDRV_SEQ_DEV_ID_OPL3, .argsize = sizeof(struct snd_opl3 *), }; module_snd_seq_driver(opl3_seq_driver);
linux-master
sound/drivers/opl3/opl3_seq.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Functions for the OPL4 proc file * Copyright (c) 2003 by Clemens Ladisch <[email protected]> */ #include "opl4_local.h" #include <linux/vmalloc.h> #include <linux/export.h> #include <sound/info.h> static int snd_opl4_mem_proc_open(struct snd_info_entry *entry, unsigned short mode, void **file_private_data) { struct snd_opl4 *opl4 = entry->private_data; mutex_lock(&opl4->access_mutex); if (opl4->memory_access) { mutex_unlock(&opl4->access_mutex); return -EBUSY; } opl4->memory_access++; mutex_unlock(&opl4->access_mutex); return 0; } static int snd_opl4_mem_proc_release(struct snd_info_entry *entry, unsigned short mode, void *file_private_data) { struct snd_opl4 *opl4 = entry->private_data; mutex_lock(&opl4->access_mutex); opl4->memory_access--; mutex_unlock(&opl4->access_mutex); return 0; } static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, char __user *_buf, size_t count, loff_t pos) { struct snd_opl4 *opl4 = entry->private_data; char* buf; buf = vmalloc(count); if (!buf) return -ENOMEM; snd_opl4_read_memory(opl4, buf, pos, count); if (copy_to_user(_buf, buf, count)) { vfree(buf); return -EFAULT; } vfree(buf); return count; } static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry, void *file_private_data, struct file *file, const char __user *_buf, size_t count, loff_t pos) { struct snd_opl4 *opl4 = entry->private_data; char *buf; buf = vmalloc(count); if (!buf) return -ENOMEM; if (copy_from_user(buf, _buf, count)) { vfree(buf); return -EFAULT; } snd_opl4_write_memory(opl4, buf, pos, count); vfree(buf); return count; } static const struct snd_info_entry_ops snd_opl4_mem_proc_ops = { .open = snd_opl4_mem_proc_open, .release = snd_opl4_mem_proc_release, .read = snd_opl4_mem_proc_read, .write = snd_opl4_mem_proc_write, }; int snd_opl4_create_proc(struct snd_opl4 *opl4) { struct snd_info_entry *entry; entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root); if (entry) { if (opl4->hardware < OPL3_HW_OPL4_ML) { /* OPL4 can access 4 MB external ROM/SRAM */ entry->mode |= 0200; entry->size = 4 * 1024 * 1024; } else { /* OPL4-ML has 1 MB internal ROM */ entry->size = 1 * 1024 * 1024; } entry->content = SNDRV_INFO_CONTENT_DATA; entry->c.ops = &snd_opl4_mem_proc_ops; entry->module = THIS_MODULE; entry->private_data = opl4; } opl4->proc_entry = entry; return 0; } void snd_opl4_free_proc(struct snd_opl4 *opl4) { snd_info_free_entry(opl4->proc_entry); }
linux-master
sound/drivers/opl4/opl4_proc.c
/* * OPL4 MIDI synthesizer functions * * Copyright (c) 2003 by Clemens Ladisch <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed and/or modified 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 SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "opl4_local.h" #include <linux/delay.h> #include <linux/io.h> #include <sound/asoundef.h> /* GM2 controllers */ #ifndef MIDI_CTL_RELEASE_TIME #define MIDI_CTL_RELEASE_TIME 0x48 #define MIDI_CTL_ATTACK_TIME 0x49 #define MIDI_CTL_DECAY_TIME 0x4b #define MIDI_CTL_VIBRATO_RATE 0x4c #define MIDI_CTL_VIBRATO_DEPTH 0x4d #define MIDI_CTL_VIBRATO_DELAY 0x4e #endif /* * This table maps 100/128 cents to F_NUMBER. */ static const s16 snd_opl4_pitch_map[0x600] = { 0x000,0x000,0x001,0x001,0x002,0x002,0x003,0x003, 0x004,0x004,0x005,0x005,0x006,0x006,0x006,0x007, 0x007,0x008,0x008,0x009,0x009,0x00a,0x00a,0x00b, 0x00b,0x00c,0x00c,0x00d,0x00d,0x00d,0x00e,0x00e, 0x00f,0x00f,0x010,0x010,0x011,0x011,0x012,0x012, 0x013,0x013,0x014,0x014,0x015,0x015,0x015,0x016, 0x016,0x017,0x017,0x018,0x018,0x019,0x019,0x01a, 0x01a,0x01b,0x01b,0x01c,0x01c,0x01d,0x01d,0x01e, 0x01e,0x01e,0x01f,0x01f,0x020,0x020,0x021,0x021, 0x022,0x022,0x023,0x023,0x024,0x024,0x025,0x025, 0x026,0x026,0x027,0x027,0x028,0x028,0x029,0x029, 0x029,0x02a,0x02a,0x02b,0x02b,0x02c,0x02c,0x02d, 0x02d,0x02e,0x02e,0x02f,0x02f,0x030,0x030,0x031, 0x031,0x032,0x032,0x033,0x033,0x034,0x034,0x035, 0x035,0x036,0x036,0x037,0x037,0x038,0x038,0x038, 0x039,0x039,0x03a,0x03a,0x03b,0x03b,0x03c,0x03c, 0x03d,0x03d,0x03e,0x03e,0x03f,0x03f,0x040,0x040, 0x041,0x041,0x042,0x042,0x043,0x043,0x044,0x044, 0x045,0x045,0x046,0x046,0x047,0x047,0x048,0x048, 0x049,0x049,0x04a,0x04a,0x04b,0x04b,0x04c,0x04c, 0x04d,0x04d,0x04e,0x04e,0x04f,0x04f,0x050,0x050, 0x051,0x051,0x052,0x052,0x053,0x053,0x054,0x054, 0x055,0x055,0x056,0x056,0x057,0x057,0x058,0x058, 0x059,0x059,0x05a,0x05a,0x05b,0x05b,0x05c,0x05c, 0x05d,0x05d,0x05e,0x05e,0x05f,0x05f,0x060,0x060, 0x061,0x061,0x062,0x062,0x063,0x063,0x064,0x064, 0x065,0x065,0x066,0x066,0x067,0x067,0x068,0x068, 0x069,0x069,0x06a,0x06a,0x06b,0x06b,0x06c,0x06c, 0x06d,0x06d,0x06e,0x06e,0x06f,0x06f,0x070,0x071, 0x071,0x072,0x072,0x073,0x073,0x074,0x074,0x075, 0x075,0x076,0x076,0x077,0x077,0x078,0x078,0x079, 0x079,0x07a,0x07a,0x07b,0x07b,0x07c,0x07c,0x07d, 0x07d,0x07e,0x07e,0x07f,0x07f,0x080,0x081,0x081, 0x082,0x082,0x083,0x083,0x084,0x084,0x085,0x085, 0x086,0x086,0x087,0x087,0x088,0x088,0x089,0x089, 0x08a,0x08a,0x08b,0x08b,0x08c,0x08d,0x08d,0x08e, 0x08e,0x08f,0x08f,0x090,0x090,0x091,0x091,0x092, 0x092,0x093,0x093,0x094,0x094,0x095,0x096,0x096, 0x097,0x097,0x098,0x098,0x099,0x099,0x09a,0x09a, 0x09b,0x09b,0x09c,0x09c,0x09d,0x09d,0x09e,0x09f, 0x09f,0x0a0,0x0a0,0x0a1,0x0a1,0x0a2,0x0a2,0x0a3, 0x0a3,0x0a4,0x0a4,0x0a5,0x0a6,0x0a6,0x0a7,0x0a7, 0x0a8,0x0a8,0x0a9,0x0a9,0x0aa,0x0aa,0x0ab,0x0ab, 0x0ac,0x0ad,0x0ad,0x0ae,0x0ae,0x0af,0x0af,0x0b0, 0x0b0,0x0b1,0x0b1,0x0b2,0x0b2,0x0b3,0x0b4,0x0b4, 0x0b5,0x0b5,0x0b6,0x0b6,0x0b7,0x0b7,0x0b8,0x0b8, 0x0b9,0x0ba,0x0ba,0x0bb,0x0bb,0x0bc,0x0bc,0x0bd, 0x0bd,0x0be,0x0be,0x0bf,0x0c0,0x0c0,0x0c1,0x0c1, 0x0c2,0x0c2,0x0c3,0x0c3,0x0c4,0x0c4,0x0c5,0x0c6, 0x0c6,0x0c7,0x0c7,0x0c8,0x0c8,0x0c9,0x0c9,0x0ca, 0x0cb,0x0cb,0x0cc,0x0cc,0x0cd,0x0cd,0x0ce,0x0ce, 0x0cf,0x0d0,0x0d0,0x0d1,0x0d1,0x0d2,0x0d2,0x0d3, 0x0d3,0x0d4,0x0d5,0x0d5,0x0d6,0x0d6,0x0d7,0x0d7, 0x0d8,0x0d8,0x0d9,0x0da,0x0da,0x0db,0x0db,0x0dc, 0x0dc,0x0dd,0x0de,0x0de,0x0df,0x0df,0x0e0,0x0e0, 0x0e1,0x0e1,0x0e2,0x0e3,0x0e3,0x0e4,0x0e4,0x0e5, 0x0e5,0x0e6,0x0e7,0x0e7,0x0e8,0x0e8,0x0e9,0x0e9, 0x0ea,0x0eb,0x0eb,0x0ec,0x0ec,0x0ed,0x0ed,0x0ee, 0x0ef,0x0ef,0x0f0,0x0f0,0x0f1,0x0f1,0x0f2,0x0f3, 0x0f3,0x0f4,0x0f4,0x0f5,0x0f5,0x0f6,0x0f7,0x0f7, 0x0f8,0x0f8,0x0f9,0x0f9,0x0fa,0x0fb,0x0fb,0x0fc, 0x0fc,0x0fd,0x0fd,0x0fe,0x0ff,0x0ff,0x100,0x100, 0x101,0x101,0x102,0x103,0x103,0x104,0x104,0x105, 0x106,0x106,0x107,0x107,0x108,0x108,0x109,0x10a, 0x10a,0x10b,0x10b,0x10c,0x10c,0x10d,0x10e,0x10e, 0x10f,0x10f,0x110,0x111,0x111,0x112,0x112,0x113, 0x114,0x114,0x115,0x115,0x116,0x116,0x117,0x118, 0x118,0x119,0x119,0x11a,0x11b,0x11b,0x11c,0x11c, 0x11d,0x11e,0x11e,0x11f,0x11f,0x120,0x120,0x121, 0x122,0x122,0x123,0x123,0x124,0x125,0x125,0x126, 0x126,0x127,0x128,0x128,0x129,0x129,0x12a,0x12b, 0x12b,0x12c,0x12c,0x12d,0x12e,0x12e,0x12f,0x12f, 0x130,0x131,0x131,0x132,0x132,0x133,0x134,0x134, 0x135,0x135,0x136,0x137,0x137,0x138,0x138,0x139, 0x13a,0x13a,0x13b,0x13b,0x13c,0x13d,0x13d,0x13e, 0x13e,0x13f,0x140,0x140,0x141,0x141,0x142,0x143, 0x143,0x144,0x144,0x145,0x146,0x146,0x147,0x148, 0x148,0x149,0x149,0x14a,0x14b,0x14b,0x14c,0x14c, 0x14d,0x14e,0x14e,0x14f,0x14f,0x150,0x151,0x151, 0x152,0x153,0x153,0x154,0x154,0x155,0x156,0x156, 0x157,0x157,0x158,0x159,0x159,0x15a,0x15b,0x15b, 0x15c,0x15c,0x15d,0x15e,0x15e,0x15f,0x160,0x160, 0x161,0x161,0x162,0x163,0x163,0x164,0x165,0x165, 0x166,0x166,0x167,0x168,0x168,0x169,0x16a,0x16a, 0x16b,0x16b,0x16c,0x16d,0x16d,0x16e,0x16f,0x16f, 0x170,0x170,0x171,0x172,0x172,0x173,0x174,0x174, 0x175,0x175,0x176,0x177,0x177,0x178,0x179,0x179, 0x17a,0x17a,0x17b,0x17c,0x17c,0x17d,0x17e,0x17e, 0x17f,0x180,0x180,0x181,0x181,0x182,0x183,0x183, 0x184,0x185,0x185,0x186,0x187,0x187,0x188,0x188, 0x189,0x18a,0x18a,0x18b,0x18c,0x18c,0x18d,0x18e, 0x18e,0x18f,0x190,0x190,0x191,0x191,0x192,0x193, 0x193,0x194,0x195,0x195,0x196,0x197,0x197,0x198, 0x199,0x199,0x19a,0x19a,0x19b,0x19c,0x19c,0x19d, 0x19e,0x19e,0x19f,0x1a0,0x1a0,0x1a1,0x1a2,0x1a2, 0x1a3,0x1a4,0x1a4,0x1a5,0x1a6,0x1a6,0x1a7,0x1a8, 0x1a8,0x1a9,0x1a9,0x1aa,0x1ab,0x1ab,0x1ac,0x1ad, 0x1ad,0x1ae,0x1af,0x1af,0x1b0,0x1b1,0x1b1,0x1b2, 0x1b3,0x1b3,0x1b4,0x1b5,0x1b5,0x1b6,0x1b7,0x1b7, 0x1b8,0x1b9,0x1b9,0x1ba,0x1bb,0x1bb,0x1bc,0x1bd, 0x1bd,0x1be,0x1bf,0x1bf,0x1c0,0x1c1,0x1c1,0x1c2, 0x1c3,0x1c3,0x1c4,0x1c5,0x1c5,0x1c6,0x1c7,0x1c7, 0x1c8,0x1c9,0x1c9,0x1ca,0x1cb,0x1cb,0x1cc,0x1cd, 0x1cd,0x1ce,0x1cf,0x1cf,0x1d0,0x1d1,0x1d1,0x1d2, 0x1d3,0x1d3,0x1d4,0x1d5,0x1d5,0x1d6,0x1d7,0x1d7, 0x1d8,0x1d9,0x1d9,0x1da,0x1db,0x1db,0x1dc,0x1dd, 0x1dd,0x1de,0x1df,0x1df,0x1e0,0x1e1,0x1e1,0x1e2, 0x1e3,0x1e4,0x1e4,0x1e5,0x1e6,0x1e6,0x1e7,0x1e8, 0x1e8,0x1e9,0x1ea,0x1ea,0x1eb,0x1ec,0x1ec,0x1ed, 0x1ee,0x1ee,0x1ef,0x1f0,0x1f0,0x1f1,0x1f2,0x1f3, 0x1f3,0x1f4,0x1f5,0x1f5,0x1f6,0x1f7,0x1f7,0x1f8, 0x1f9,0x1f9,0x1fa,0x1fb,0x1fb,0x1fc,0x1fd,0x1fe, 0x1fe,0x1ff,0x200,0x200,0x201,0x202,0x202,0x203, 0x204,0x205,0x205,0x206,0x207,0x207,0x208,0x209, 0x209,0x20a,0x20b,0x20b,0x20c,0x20d,0x20e,0x20e, 0x20f,0x210,0x210,0x211,0x212,0x212,0x213,0x214, 0x215,0x215,0x216,0x217,0x217,0x218,0x219,0x21a, 0x21a,0x21b,0x21c,0x21c,0x21d,0x21e,0x21e,0x21f, 0x220,0x221,0x221,0x222,0x223,0x223,0x224,0x225, 0x226,0x226,0x227,0x228,0x228,0x229,0x22a,0x22b, 0x22b,0x22c,0x22d,0x22d,0x22e,0x22f,0x230,0x230, 0x231,0x232,0x232,0x233,0x234,0x235,0x235,0x236, 0x237,0x237,0x238,0x239,0x23a,0x23a,0x23b,0x23c, 0x23c,0x23d,0x23e,0x23f,0x23f,0x240,0x241,0x241, 0x242,0x243,0x244,0x244,0x245,0x246,0x247,0x247, 0x248,0x249,0x249,0x24a,0x24b,0x24c,0x24c,0x24d, 0x24e,0x24f,0x24f,0x250,0x251,0x251,0x252,0x253, 0x254,0x254,0x255,0x256,0x257,0x257,0x258,0x259, 0x259,0x25a,0x25b,0x25c,0x25c,0x25d,0x25e,0x25f, 0x25f,0x260,0x261,0x262,0x262,0x263,0x264,0x265, 0x265,0x266,0x267,0x267,0x268,0x269,0x26a,0x26a, 0x26b,0x26c,0x26d,0x26d,0x26e,0x26f,0x270,0x270, 0x271,0x272,0x273,0x273,0x274,0x275,0x276,0x276, 0x277,0x278,0x279,0x279,0x27a,0x27b,0x27c,0x27c, 0x27d,0x27e,0x27f,0x27f,0x280,0x281,0x282,0x282, 0x283,0x284,0x285,0x285,0x286,0x287,0x288,0x288, 0x289,0x28a,0x28b,0x28b,0x28c,0x28d,0x28e,0x28e, 0x28f,0x290,0x291,0x291,0x292,0x293,0x294,0x294, 0x295,0x296,0x297,0x298,0x298,0x299,0x29a,0x29b, 0x29b,0x29c,0x29d,0x29e,0x29e,0x29f,0x2a0,0x2a1, 0x2a1,0x2a2,0x2a3,0x2a4,0x2a5,0x2a5,0x2a6,0x2a7, 0x2a8,0x2a8,0x2a9,0x2aa,0x2ab,0x2ab,0x2ac,0x2ad, 0x2ae,0x2af,0x2af,0x2b0,0x2b1,0x2b2,0x2b2,0x2b3, 0x2b4,0x2b5,0x2b5,0x2b6,0x2b7,0x2b8,0x2b9,0x2b9, 0x2ba,0x2bb,0x2bc,0x2bc,0x2bd,0x2be,0x2bf,0x2c0, 0x2c0,0x2c1,0x2c2,0x2c3,0x2c4,0x2c4,0x2c5,0x2c6, 0x2c7,0x2c7,0x2c8,0x2c9,0x2ca,0x2cb,0x2cb,0x2cc, 0x2cd,0x2ce,0x2ce,0x2cf,0x2d0,0x2d1,0x2d2,0x2d2, 0x2d3,0x2d4,0x2d5,0x2d6,0x2d6,0x2d7,0x2d8,0x2d9, 0x2da,0x2da,0x2db,0x2dc,0x2dd,0x2dd,0x2de,0x2df, 0x2e0,0x2e1,0x2e1,0x2e2,0x2e3,0x2e4,0x2e5,0x2e5, 0x2e6,0x2e7,0x2e8,0x2e9,0x2e9,0x2ea,0x2eb,0x2ec, 0x2ed,0x2ed,0x2ee,0x2ef,0x2f0,0x2f1,0x2f1,0x2f2, 0x2f3,0x2f4,0x2f5,0x2f5,0x2f6,0x2f7,0x2f8,0x2f9, 0x2f9,0x2fa,0x2fb,0x2fc,0x2fd,0x2fd,0x2fe,0x2ff, 0x300,0x301,0x302,0x302,0x303,0x304,0x305,0x306, 0x306,0x307,0x308,0x309,0x30a,0x30a,0x30b,0x30c, 0x30d,0x30e,0x30f,0x30f,0x310,0x311,0x312,0x313, 0x313,0x314,0x315,0x316,0x317,0x318,0x318,0x319, 0x31a,0x31b,0x31c,0x31c,0x31d,0x31e,0x31f,0x320, 0x321,0x321,0x322,0x323,0x324,0x325,0x326,0x326, 0x327,0x328,0x329,0x32a,0x32a,0x32b,0x32c,0x32d, 0x32e,0x32f,0x32f,0x330,0x331,0x332,0x333,0x334, 0x334,0x335,0x336,0x337,0x338,0x339,0x339,0x33a, 0x33b,0x33c,0x33d,0x33e,0x33e,0x33f,0x340,0x341, 0x342,0x343,0x343,0x344,0x345,0x346,0x347,0x348, 0x349,0x349,0x34a,0x34b,0x34c,0x34d,0x34e,0x34e, 0x34f,0x350,0x351,0x352,0x353,0x353,0x354,0x355, 0x356,0x357,0x358,0x359,0x359,0x35a,0x35b,0x35c, 0x35d,0x35e,0x35f,0x35f,0x360,0x361,0x362,0x363, 0x364,0x364,0x365,0x366,0x367,0x368,0x369,0x36a, 0x36a,0x36b,0x36c,0x36d,0x36e,0x36f,0x370,0x370, 0x371,0x372,0x373,0x374,0x375,0x376,0x377,0x377, 0x378,0x379,0x37a,0x37b,0x37c,0x37d,0x37d,0x37e, 0x37f,0x380,0x381,0x382,0x383,0x383,0x384,0x385, 0x386,0x387,0x388,0x389,0x38a,0x38a,0x38b,0x38c, 0x38d,0x38e,0x38f,0x390,0x391,0x391,0x392,0x393, 0x394,0x395,0x396,0x397,0x398,0x398,0x399,0x39a, 0x39b,0x39c,0x39d,0x39e,0x39f,0x39f,0x3a0,0x3a1, 0x3a2,0x3a3,0x3a4,0x3a5,0x3a6,0x3a7,0x3a7,0x3a8, 0x3a9,0x3aa,0x3ab,0x3ac,0x3ad,0x3ae,0x3ae,0x3af, 0x3b0,0x3b1,0x3b2,0x3b3,0x3b4,0x3b5,0x3b6,0x3b6, 0x3b7,0x3b8,0x3b9,0x3ba,0x3bb,0x3bc,0x3bd,0x3be, 0x3bf,0x3bf,0x3c0,0x3c1,0x3c2,0x3c3,0x3c4,0x3c5, 0x3c6,0x3c7,0x3c7,0x3c8,0x3c9,0x3ca,0x3cb,0x3cc, 0x3cd,0x3ce,0x3cf,0x3d0,0x3d1,0x3d1,0x3d2,0x3d3, 0x3d4,0x3d5,0x3d6,0x3d7,0x3d8,0x3d9,0x3da,0x3da, 0x3db,0x3dc,0x3dd,0x3de,0x3df,0x3e0,0x3e1,0x3e2, 0x3e3,0x3e4,0x3e4,0x3e5,0x3e6,0x3e7,0x3e8,0x3e9, 0x3ea,0x3eb,0x3ec,0x3ed,0x3ee,0x3ef,0x3ef,0x3f0, 0x3f1,0x3f2,0x3f3,0x3f4,0x3f5,0x3f6,0x3f7,0x3f8, 0x3f9,0x3fa,0x3fa,0x3fb,0x3fc,0x3fd,0x3fe,0x3ff }; /* * Attenuation according to GM recommendations, in -0.375 dB units. * table[v] = 40 * log(v / 127) / -0.375 */ static const unsigned char snd_opl4_volume_table[128] = { 255,224,192,173,160,150,141,134, 128,122,117,113,109,105,102, 99, 96, 93, 90, 88, 85, 83, 81, 79, 77, 75, 73, 71, 70, 68, 67, 65, 64, 62, 61, 59, 58, 57, 56, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 39, 38, 37, 36, 35, 34, 34, 33, 32, 31, 31, 30, 29, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23, 22, 22, 21, 21, 20, 19, 19, 18, 18, 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 9, 8, 8, 7, 7, 6, 6, 6, 5, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 0, 0, 0 }; /* * Initializes all voices. */ void snd_opl4_synth_reset(struct snd_opl4 *opl4) { unsigned long flags; int i; spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < OPL4_MAX_VOICES; i++) snd_opl4_write(opl4, OPL4_REG_MISC + i, OPL4_DAMP_BIT); spin_unlock_irqrestore(&opl4->reg_lock, flags); INIT_LIST_HEAD(&opl4->off_voices); INIT_LIST_HEAD(&opl4->on_voices); memset(opl4->voices, 0, sizeof(opl4->voices)); for (i = 0; i < OPL4_MAX_VOICES; i++) { opl4->voices[i].number = i; list_add_tail(&opl4->voices[i].list, &opl4->off_voices); } snd_midi_channel_set_clear(opl4->chset); } /* * Shuts down all voices. */ void snd_opl4_synth_shutdown(struct snd_opl4 *opl4) { unsigned long flags; int i; spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < OPL4_MAX_VOICES; i++) snd_opl4_write(opl4, OPL4_REG_MISC + i, opl4->voices[i].reg_misc & ~OPL4_KEY_ON_BIT); spin_unlock_irqrestore(&opl4->reg_lock, flags); } /* * Executes the callback for all voices playing the specified note. */ static void snd_opl4_do_for_note(struct snd_opl4 *opl4, int note, struct snd_midi_channel *chan, void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice)) { int i; unsigned long flags; struct opl4_voice *voice; spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < OPL4_MAX_VOICES; i++) { voice = &opl4->voices[i]; if (voice->chan == chan && voice->note == note) { func(opl4, voice); } } spin_unlock_irqrestore(&opl4->reg_lock, flags); } /* * Executes the callback for all voices of to the specified channel. */ static void snd_opl4_do_for_channel(struct snd_opl4 *opl4, struct snd_midi_channel *chan, void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice)) { int i; unsigned long flags; struct opl4_voice *voice; spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < OPL4_MAX_VOICES; i++) { voice = &opl4->voices[i]; if (voice->chan == chan) { func(opl4, voice); } } spin_unlock_irqrestore(&opl4->reg_lock, flags); } /* * Executes the callback for all active voices. */ static void snd_opl4_do_for_all(struct snd_opl4 *opl4, void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice)) { int i; unsigned long flags; struct opl4_voice *voice; spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < OPL4_MAX_VOICES; i++) { voice = &opl4->voices[i]; if (voice->chan) func(opl4, voice); } spin_unlock_irqrestore(&opl4->reg_lock, flags); } static void snd_opl4_update_volume(struct snd_opl4 *opl4, struct opl4_voice *voice) { int att; att = voice->sound->tone_attenuate; att += snd_opl4_volume_table[opl4->chset->gs_master_volume & 0x7f]; att += snd_opl4_volume_table[voice->chan->gm_volume & 0x7f]; att += snd_opl4_volume_table[voice->chan->gm_expression & 0x7f]; att += snd_opl4_volume_table[voice->velocity]; att = 0x7f - (0x7f - att) * (voice->sound->volume_factor) / 0xfe - volume_boost; if (att < 0) att = 0; else if (att > 0x7e) att = 0x7e; snd_opl4_write(opl4, OPL4_REG_LEVEL + voice->number, (att << 1) | voice->level_direct); voice->level_direct = 0; } static void snd_opl4_update_pan(struct snd_opl4 *opl4, struct opl4_voice *voice) { int pan = voice->sound->panpot; if (!voice->chan->drum_channel) pan += (voice->chan->control[MIDI_CTL_MSB_PAN] - 0x40) >> 3; if (pan < -7) pan = -7; else if (pan > 7) pan = 7; voice->reg_misc = (voice->reg_misc & ~OPL4_PAN_POT_MASK) | (pan & OPL4_PAN_POT_MASK); snd_opl4_write(opl4, OPL4_REG_MISC + voice->number, voice->reg_misc); } static void snd_opl4_update_vibrato_depth(struct snd_opl4 *opl4, struct opl4_voice *voice) { int depth; if (voice->chan->drum_channel) return; depth = (7 - voice->sound->vibrato) * (voice->chan->control[MIDI_CTL_VIBRATO_DEPTH] & 0x7f); depth = (depth >> 7) + voice->sound->vibrato; voice->reg_lfo_vibrato &= ~OPL4_VIBRATO_DEPTH_MASK; voice->reg_lfo_vibrato |= depth & OPL4_VIBRATO_DEPTH_MASK; snd_opl4_write(opl4, OPL4_REG_LFO_VIBRATO + voice->number, voice->reg_lfo_vibrato); } static void snd_opl4_update_pitch(struct snd_opl4 *opl4, struct opl4_voice *voice) { struct snd_midi_channel *chan = voice->chan; int note, pitch, octave; note = chan->drum_channel ? 60 : voice->note; /* * pitch is in 100/128 cents, so 0x80 is one semitone and * 0x600 is one octave. */ pitch = ((note - 60) << 7) * voice->sound->key_scaling / 100 + (60 << 7); pitch += voice->sound->pitch_offset; if (!chan->drum_channel) pitch += chan->gm_rpn_coarse_tuning; pitch += chan->gm_rpn_fine_tuning >> 7; pitch += chan->midi_pitchbend * chan->gm_rpn_pitch_bend_range / 0x2000; if (pitch < 0) pitch = 0; else if (pitch >= 0x6000) pitch = 0x5fff; octave = pitch / 0x600 - 8; pitch = snd_opl4_pitch_map[pitch % 0x600]; snd_opl4_write(opl4, OPL4_REG_OCTAVE + voice->number, (octave << 4) | ((pitch >> 7) & OPL4_F_NUMBER_HIGH_MASK)); voice->reg_f_number = (voice->reg_f_number & OPL4_TONE_NUMBER_BIT8) | ((pitch << 1) & OPL4_F_NUMBER_LOW_MASK); snd_opl4_write(opl4, OPL4_REG_F_NUMBER + voice->number, voice->reg_f_number); } static void snd_opl4_update_tone_parameters(struct snd_opl4 *opl4, struct opl4_voice *voice) { snd_opl4_write(opl4, OPL4_REG_ATTACK_DECAY1 + voice->number, voice->sound->reg_attack_decay1); snd_opl4_write(opl4, OPL4_REG_LEVEL_DECAY2 + voice->number, voice->sound->reg_level_decay2); snd_opl4_write(opl4, OPL4_REG_RELEASE_CORRECTION + voice->number, voice->sound->reg_release_correction); snd_opl4_write(opl4, OPL4_REG_TREMOLO + voice->number, voice->sound->reg_tremolo); } /* allocate one voice */ static struct opl4_voice *snd_opl4_get_voice(struct snd_opl4 *opl4) { /* first, try to get the oldest key-off voice */ if (!list_empty(&opl4->off_voices)) return list_entry(opl4->off_voices.next, struct opl4_voice, list); /* then get the oldest key-on voice */ snd_BUG_ON(list_empty(&opl4->on_voices)); return list_entry(opl4->on_voices.next, struct opl4_voice, list); } static void snd_opl4_wait_for_wave_headers(struct snd_opl4 *opl4) { int timeout = 200; while ((inb(opl4->fm_port) & OPL4_STATUS_LOAD) && --timeout > 0) udelay(10); } void snd_opl4_note_on(void *private_data, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl4 *opl4 = private_data; const struct opl4_region_ptr *regions; struct opl4_voice *voice[2]; const struct opl4_sound *sound[2]; int voices = 0, i; unsigned long flags; /* determine the number of voices and voice parameters */ i = chan->drum_channel ? 0x80 : (chan->midi_program & 0x7f); regions = &snd_yrw801_regions[i]; for (i = 0; i < regions->count; i++) { if (note >= regions->regions[i].key_min && note <= regions->regions[i].key_max) { sound[voices] = &regions->regions[i].sound; if (++voices >= 2) break; } } /* allocate and initialize the needed voices */ spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < voices; i++) { voice[i] = snd_opl4_get_voice(opl4); list_move_tail(&voice[i]->list, &opl4->on_voices); voice[i]->chan = chan; voice[i]->note = note; voice[i]->velocity = vel & 0x7f; voice[i]->sound = sound[i]; } /* set tone number (triggers header loading) */ for (i = 0; i < voices; i++) { voice[i]->reg_f_number = (sound[i]->tone >> 8) & OPL4_TONE_NUMBER_BIT8; snd_opl4_write(opl4, OPL4_REG_F_NUMBER + voice[i]->number, voice[i]->reg_f_number); snd_opl4_write(opl4, OPL4_REG_TONE_NUMBER + voice[i]->number, sound[i]->tone & 0xff); } /* set parameters which can be set while loading */ for (i = 0; i < voices; i++) { voice[i]->reg_misc = OPL4_LFO_RESET_BIT; snd_opl4_update_pan(opl4, voice[i]); snd_opl4_update_pitch(opl4, voice[i]); voice[i]->level_direct = OPL4_LEVEL_DIRECT_BIT; snd_opl4_update_volume(opl4, voice[i]); } spin_unlock_irqrestore(&opl4->reg_lock, flags); /* wait for completion of loading */ snd_opl4_wait_for_wave_headers(opl4); /* set remaining parameters */ spin_lock_irqsave(&opl4->reg_lock, flags); for (i = 0; i < voices; i++) { snd_opl4_update_tone_parameters(opl4, voice[i]); voice[i]->reg_lfo_vibrato = voice[i]->sound->reg_lfo_vibrato; snd_opl4_update_vibrato_depth(opl4, voice[i]); } /* finally, switch on all voices */ for (i = 0; i < voices; i++) { voice[i]->reg_misc = (voice[i]->reg_misc & 0x1f) | OPL4_KEY_ON_BIT; snd_opl4_write(opl4, OPL4_REG_MISC + voice[i]->number, voice[i]->reg_misc); } spin_unlock_irqrestore(&opl4->reg_lock, flags); } static void snd_opl4_voice_off(struct snd_opl4 *opl4, struct opl4_voice *voice) { list_move_tail(&voice->list, &opl4->off_voices); voice->reg_misc &= ~OPL4_KEY_ON_BIT; snd_opl4_write(opl4, OPL4_REG_MISC + voice->number, voice->reg_misc); } void snd_opl4_note_off(void *private_data, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl4 *opl4 = private_data; snd_opl4_do_for_note(opl4, note, chan, snd_opl4_voice_off); } static void snd_opl4_terminate_voice(struct snd_opl4 *opl4, struct opl4_voice *voice) { list_move_tail(&voice->list, &opl4->off_voices); voice->reg_misc = (voice->reg_misc & ~OPL4_KEY_ON_BIT) | OPL4_DAMP_BIT; snd_opl4_write(opl4, OPL4_REG_MISC + voice->number, voice->reg_misc); } void snd_opl4_terminate_note(void *private_data, int note, struct snd_midi_channel *chan) { struct snd_opl4 *opl4 = private_data; snd_opl4_do_for_note(opl4, note, chan, snd_opl4_terminate_voice); } void snd_opl4_control(void *private_data, int type, struct snd_midi_channel *chan) { struct snd_opl4 *opl4 = private_data; switch (type) { case MIDI_CTL_MSB_MODWHEEL: chan->control[MIDI_CTL_VIBRATO_DEPTH] = chan->control[MIDI_CTL_MSB_MODWHEEL]; snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_vibrato_depth); break; case MIDI_CTL_MSB_MAIN_VOLUME: snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_volume); break; case MIDI_CTL_MSB_PAN: snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_pan); break; case MIDI_CTL_MSB_EXPRESSION: snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_volume); break; case MIDI_CTL_VIBRATO_RATE: /* not yet supported */ break; case MIDI_CTL_VIBRATO_DEPTH: snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_vibrato_depth); break; case MIDI_CTL_VIBRATO_DELAY: /* not yet supported */ break; case MIDI_CTL_E1_REVERB_DEPTH: /* * Each OPL4 voice has a bit called "Pseudo-Reverb", but * IMHO _not_ using it enhances the listening experience. */ break; case MIDI_CTL_PITCHBEND: snd_opl4_do_for_channel(opl4, chan, snd_opl4_update_pitch); break; } } void snd_opl4_sysex(void *private_data, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset) { struct snd_opl4 *opl4 = private_data; if (parsed == SNDRV_MIDI_SYSEX_GS_MASTER_VOLUME) snd_opl4_do_for_all(opl4, snd_opl4_update_volume); }
linux-master
sound/drivers/opl4/opl4_synth.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Functions for accessing OPL4 devices * Copyright (c) 2003 by Clemens Ladisch <[email protected]> */ #include "opl4_local.h" #include <sound/initval.h> #include <linux/ioport.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/module.h> #include <linux/io.h> MODULE_AUTHOR("Clemens Ladisch <[email protected]>"); MODULE_DESCRIPTION("OPL4 driver"); MODULE_LICENSE("GPL"); static inline void snd_opl4_wait(struct snd_opl4 *opl4) { int timeout = 10; while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0) ; } void snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value) { snd_opl4_wait(opl4); outb(reg, opl4->pcm_port); snd_opl4_wait(opl4); outb(value, opl4->pcm_port + 1); } EXPORT_SYMBOL(snd_opl4_write); u8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg) { snd_opl4_wait(opl4); outb(reg, opl4->pcm_port); snd_opl4_wait(opl4); return inb(opl4->pcm_port + 1); } EXPORT_SYMBOL(snd_opl4_read); void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size) { unsigned long flags; u8 memcfg; spin_lock_irqsave(&opl4->reg_lock, flags); memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION); snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset); snd_opl4_wait(opl4); outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port); snd_opl4_wait(opl4); insb(opl4->pcm_port + 1, buf, size); snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg); spin_unlock_irqrestore(&opl4->reg_lock, flags); } EXPORT_SYMBOL(snd_opl4_read_memory); void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size) { unsigned long flags; u8 memcfg; spin_lock_irqsave(&opl4->reg_lock, flags); memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION); snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_HIGH, offset >> 16); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_MID, offset >> 8); snd_opl4_write(opl4, OPL4_REG_MEMORY_ADDRESS_LOW, offset); snd_opl4_wait(opl4); outb(OPL4_REG_MEMORY_DATA, opl4->pcm_port); snd_opl4_wait(opl4); outsb(opl4->pcm_port + 1, buf, size); snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg); spin_unlock_irqrestore(&opl4->reg_lock, flags); } EXPORT_SYMBOL(snd_opl4_write_memory); static void snd_opl4_enable_opl4(struct snd_opl4 *opl4) { outb(OPL3_REG_MODE, opl4->fm_port + 2); inb(opl4->fm_port); inb(opl4->fm_port); outb(OPL3_OPL3_ENABLE | OPL3_OPL4_ENABLE, opl4->fm_port + 3); inb(opl4->fm_port); inb(opl4->fm_port); } static int snd_opl4_detect(struct snd_opl4 *opl4) { u8 id1, id2; snd_opl4_enable_opl4(opl4); id1 = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION); snd_printdd("OPL4[02]=%02x\n", id1); switch (id1 & OPL4_DEVICE_ID_MASK) { case 0x20: opl4->hardware = OPL3_HW_OPL4; break; case 0x40: opl4->hardware = OPL3_HW_OPL4_ML; break; default: return -ENODEV; } snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x00); snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0xff); id1 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_FM); id2 = snd_opl4_read(opl4, OPL4_REG_MIX_CONTROL_PCM); snd_printdd("OPL4 id1=%02x id2=%02x\n", id1, id2); if (id1 != 0x00 || id2 != 0xff) return -ENODEV; snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_FM, 0x3f); snd_opl4_write(opl4, OPL4_REG_MIX_CONTROL_PCM, 0x3f); snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, 0x00); return 0; } #if IS_ENABLED(CONFIG_SND_SEQUENCER) static void snd_opl4_seq_dev_free(struct snd_seq_device *seq_dev) { struct snd_opl4 *opl4 = seq_dev->private_data; opl4->seq_dev = NULL; } static int snd_opl4_create_seq_dev(struct snd_opl4 *opl4, int seq_device) { opl4->seq_dev_num = seq_device; if (snd_seq_device_new(opl4->card, seq_device, SNDRV_SEQ_DEV_ID_OPL4, sizeof(struct snd_opl4 *), &opl4->seq_dev) >= 0) { strcpy(opl4->seq_dev->name, "OPL4 Wavetable"); *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(opl4->seq_dev) = opl4; opl4->seq_dev->private_data = opl4; opl4->seq_dev->private_free = snd_opl4_seq_dev_free; } return 0; } #endif static void snd_opl4_free(struct snd_opl4 *opl4) { snd_opl4_free_proc(opl4); release_and_free_resource(opl4->res_fm_port); release_and_free_resource(opl4->res_pcm_port); kfree(opl4); } static int snd_opl4_dev_free(struct snd_device *device) { struct snd_opl4 *opl4 = device->device_data; snd_opl4_free(opl4); return 0; } int snd_opl4_create(struct snd_card *card, unsigned long fm_port, unsigned long pcm_port, int seq_device, struct snd_opl3 **ropl3, struct snd_opl4 **ropl4) { struct snd_opl4 *opl4; struct snd_opl3 *opl3; int err; static const struct snd_device_ops ops = { .dev_free = snd_opl4_dev_free }; if (ropl3) *ropl3 = NULL; if (ropl4) *ropl4 = NULL; opl4 = kzalloc(sizeof(*opl4), GFP_KERNEL); if (!opl4) return -ENOMEM; opl4->res_fm_port = request_region(fm_port, 8, "OPL4 FM"); opl4->res_pcm_port = request_region(pcm_port, 8, "OPL4 PCM/MIX"); if (!opl4->res_fm_port || !opl4->res_pcm_port) { snd_printk(KERN_ERR "opl4: can't grab ports 0x%lx, 0x%lx\n", fm_port, pcm_port); snd_opl4_free(opl4); return -EBUSY; } opl4->card = card; opl4->fm_port = fm_port; opl4->pcm_port = pcm_port; spin_lock_init(&opl4->reg_lock); mutex_init(&opl4->access_mutex); err = snd_opl4_detect(opl4); if (err < 0) { snd_opl4_free(opl4); snd_printd("OPL4 chip not detected at %#lx/%#lx\n", fm_port, pcm_port); return err; } err = snd_device_new(card, SNDRV_DEV_CODEC, opl4, &ops); if (err < 0) { snd_opl4_free(opl4); return err; } err = snd_opl3_create(card, fm_port, fm_port + 2, opl4->hardware, 1, &opl3); if (err < 0) { snd_device_free(card, opl4); return err; } /* opl3 initialization disabled opl4, so reenable */ snd_opl4_enable_opl4(opl4); snd_opl4_create_mixer(opl4); snd_opl4_create_proc(opl4); #if IS_ENABLED(CONFIG_SND_SEQUENCER) opl4->seq_client = -1; if (opl4->hardware < OPL3_HW_OPL4_ML) snd_opl4_create_seq_dev(opl4, seq_device); #endif if (ropl3) *ropl3 = opl3; if (ropl4) *ropl4 = opl4; return 0; } EXPORT_SYMBOL(snd_opl4_create);
linux-master
sound/drivers/opl4/opl4_lib.c
/* * OPL4 sequencer functions * * Copyright (c) 2003 by Clemens Ladisch <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed and/or modified 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 SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "opl4_local.h" #include <linux/init.h> #include <linux/moduleparam.h> #include <linux/module.h> #include <sound/initval.h> MODULE_AUTHOR("Clemens Ladisch <[email protected]>"); MODULE_DESCRIPTION("OPL4 wavetable synth driver"); MODULE_LICENSE("Dual BSD/GPL"); int volume_boost = 8; module_param(volume_boost, int, 0644); MODULE_PARM_DESC(volume_boost, "Additional volume for OPL4 wavetable sounds."); static int snd_opl4_seq_use_inc(struct snd_opl4 *opl4) { if (!try_module_get(opl4->card->module)) return -EFAULT; return 0; } static void snd_opl4_seq_use_dec(struct snd_opl4 *opl4) { module_put(opl4->card->module); } static int snd_opl4_seq_use(void *private_data, struct snd_seq_port_subscribe *info) { struct snd_opl4 *opl4 = private_data; int err; mutex_lock(&opl4->access_mutex); if (opl4->used) { mutex_unlock(&opl4->access_mutex); return -EBUSY; } opl4->used++; if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM) { err = snd_opl4_seq_use_inc(opl4); if (err < 0) { mutex_unlock(&opl4->access_mutex); return err; } } mutex_unlock(&opl4->access_mutex); snd_opl4_synth_reset(opl4); return 0; } static int snd_opl4_seq_unuse(void *private_data, struct snd_seq_port_subscribe *info) { struct snd_opl4 *opl4 = private_data; snd_opl4_synth_shutdown(opl4); mutex_lock(&opl4->access_mutex); opl4->used--; mutex_unlock(&opl4->access_mutex); if (info->sender.client != SNDRV_SEQ_CLIENT_SYSTEM) snd_opl4_seq_use_dec(opl4); return 0; } static const struct snd_midi_op opl4_ops = { .note_on = snd_opl4_note_on, .note_off = snd_opl4_note_off, .note_terminate = snd_opl4_terminate_note, .control = snd_opl4_control, .sysex = snd_opl4_sysex, }; static int snd_opl4_seq_event_input(struct snd_seq_event *ev, int direct, void *private_data, int atomic, int hop) { struct snd_opl4 *opl4 = private_data; snd_midi_process_event(&opl4_ops, ev, opl4->chset); return 0; } static void snd_opl4_seq_free_port(void *private_data) { struct snd_opl4 *opl4 = private_data; snd_midi_channel_free_set(opl4->chset); } static int snd_opl4_seq_probe(struct device *_dev) { struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_opl4 *opl4; int client; struct snd_seq_port_callback pcallbacks; opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (!opl4) return -EINVAL; if (snd_yrw801_detect(opl4) < 0) return -ENODEV; opl4->chset = snd_midi_channel_alloc_set(16); if (!opl4->chset) return -ENOMEM; opl4->chset->private_data = opl4; /* allocate new client */ client = snd_seq_create_kernel_client(opl4->card, opl4->seq_dev_num, "OPL4 Wavetable"); if (client < 0) { snd_midi_channel_free_set(opl4->chset); return client; } opl4->seq_client = client; opl4->chset->client = client; /* create new port */ memset(&pcallbacks, 0, sizeof(pcallbacks)); pcallbacks.owner = THIS_MODULE; pcallbacks.use = snd_opl4_seq_use; pcallbacks.unuse = snd_opl4_seq_unuse; pcallbacks.event_input = snd_opl4_seq_event_input; pcallbacks.private_free = snd_opl4_seq_free_port; pcallbacks.private_data = opl4; opl4->chset->port = snd_seq_event_port_attach(client, &pcallbacks, SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE, SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC | SNDRV_SEQ_PORT_TYPE_MIDI_GM | SNDRV_SEQ_PORT_TYPE_HARDWARE | SNDRV_SEQ_PORT_TYPE_SYNTHESIZER, 16, 24, "OPL4 Wavetable Port"); if (opl4->chset->port < 0) { int err = opl4->chset->port; snd_midi_channel_free_set(opl4->chset); snd_seq_delete_kernel_client(client); opl4->seq_client = -1; return err; } return 0; } static int snd_opl4_seq_remove(struct device *_dev) { struct snd_seq_device *dev = to_seq_dev(_dev); struct snd_opl4 *opl4; opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev); if (!opl4) return -EINVAL; if (opl4->seq_client >= 0) { snd_seq_delete_kernel_client(opl4->seq_client); opl4->seq_client = -1; } return 0; } static struct snd_seq_driver opl4_seq_driver = { .driver = { .name = KBUILD_MODNAME, .probe = snd_opl4_seq_probe, .remove = snd_opl4_seq_remove, }, .id = SNDRV_SEQ_DEV_ID_OPL4, .argsize = sizeof(struct snd_opl4 *), }; module_snd_seq_driver(opl4_seq_driver);
linux-master
sound/drivers/opl4/opl4_seq.c
/* * Information about the Yamaha YRW801 wavetable ROM chip * * Copyright (c) 2003 by Clemens Ladisch <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * Alternatively, this software may be distributed and/or modified 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 SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include "opl4_local.h" int snd_yrw801_detect(struct snd_opl4 *opl4) { char buf[15]; snd_opl4_read_memory(opl4, buf, 0x001200, 15); if (memcmp(buf, "CopyrightYAMAHA", 15)) return -ENODEV; snd_opl4_read_memory(opl4, buf, 0x1ffffe, 2); if (buf[0] != 0x01) return -ENODEV; snd_printdd("YRW801 ROM version %02x.%02x\n", buf[0], buf[1]); return 0; } /* * The instrument definitions are stored statically because, in practice, the * OPL4 is always coupled with a YRW801. Dynamic instrument loading would be * required if downloading sample data to external SRAM was actually supported * by this driver. */ static const struct opl4_region regions_00[] = { /* Acoustic Grand Piano */ {0x14, 0x27, {0x12c,7474,100, 0,0,0x00,0xc8,0x20,0xf2,0x13,0x08,0x0}}, {0x28, 0x2d, {0x12d,6816,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x2e, 0x33, {0x12e,5899,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12f,5290,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x130,4260,100, 0,0,0x0a,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x131,3625,100, 0,0,0x0a,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x132,3116,100, 0,0,0x04,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x133,2081,100, 0,0,0x03,0xc8,0x20,0xf2,0x14,0x18,0x0}}, {0x53, 0x58, {0x134,1444,100, 0,0,0x07,0xc8,0x20,0xf3,0x14,0x18,0x0}}, {0x59, 0x6d, {0x135,1915,100, 0,0,0x00,0xc8,0x20,0xf4,0x15,0x08,0x0}} }; static const struct opl4_region regions_01[] = { /* Bright Acoustic Piano */ {0x14, 0x2d, {0x12c,7474,100, 0,0,0x00,0xc8,0x20,0xf2,0x13,0x08,0x0}}, {0x2e, 0x33, {0x12d,6816,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12e,5899,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x12f,5290,100, 0,0,0x00,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x130,4260,100, 0,0,0x0a,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x131,3625,100, 0,0,0x0a,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x132,3116,100, 0,0,0x04,0xc8,0x20,0xf2,0x14,0x08,0x0}}, {0x53, 0x58, {0x133,2081,100, 0,0,0x07,0xc8,0x20,0xf2,0x14,0x18,0x0}}, {0x59, 0x5e, {0x134,1444,100, 0,0,0x0a,0xc8,0x20,0xf3,0x14,0x18,0x0}}, {0x5f, 0x6d, {0x135,1915,100, 0,0,0x00,0xc8,0x20,0xf4,0x15,0x08,0x0}} }; static const struct opl4_region regions_02[] = { /* Electric Grand Piano */ {0x14, 0x2d, {0x12c,7476,100, 1,0,0x00,0xae,0x20,0xf2,0x13,0x07,0x0}}, {0x2e, 0x33, {0x12d,6818,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x34, 0x39, {0x12e,5901,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x3a, 0x3f, {0x12f,5292,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x40, 0x45, {0x130,4262,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x46, 0x4b, {0x131,3627,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x4c, 0x52, {0x132,3118,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x07,0x0}}, {0x53, 0x58, {0x133,2083,100, 1,0,0x00,0xae,0x20,0xf2,0x14,0x17,0x0}}, {0x59, 0x5e, {0x134,1446,100, 1,0,0x00,0xae,0x20,0xf3,0x14,0x17,0x0}}, {0x5f, 0x6d, {0x135,1917,100, 1,0,0x00,0xae,0x20,0xf4,0x15,0x07,0x0}}, {0x00, 0x7f, {0x06c,6375,100,-1,0,0x00,0xc2,0x28,0xf4,0x23,0x18,0x0}} }; static const struct opl4_region regions_03[] = { /* Honky-Tonk Piano */ {0x14, 0x27, {0x12c,7474,100, 0,0,0x00,0xb4,0x20,0xf2,0x13,0x08,0x0}}, {0x28, 0x2d, {0x12d,6816,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x2e, 0x33, {0x12e,5899,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12f,5290,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x130,4260,100, 0,0,0x0a,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x131,3625,100, 0,0,0x0a,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x132,3116,100, 0,0,0x04,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x133,2081,100, 0,0,0x03,0xb4,0x20,0xf2,0x14,0x18,0x0}}, {0x53, 0x58, {0x134,1444,100, 0,0,0x07,0xb4,0x20,0xf3,0x14,0x18,0x0}}, {0x59, 0x6d, {0x135,1915,100, 0,0,0x00,0xb4,0x20,0xf4,0x15,0x08,0x0}}, {0x14, 0x27, {0x12c,7486,100, 0,0,0x00,0xb4,0x20,0xf2,0x13,0x08,0x0}}, {0x28, 0x2d, {0x12d,6803,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x2e, 0x33, {0x12e,5912,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12f,5275,100, 0,0,0x00,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x130,4274,100, 0,0,0x0a,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x131,3611,100, 0,0,0x0a,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x132,3129,100, 0,0,0x04,0xb4,0x20,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x133,2074,100, 0,0,0x07,0xb4,0x20,0xf2,0x14,0x18,0x0}}, {0x53, 0x58, {0x134,1457,100, 0,0,0x01,0xb4,0x20,0xf3,0x14,0x18,0x0}}, {0x59, 0x6d, {0x135,1903,100, 0,0,0x00,0xb4,0x20,0xf4,0x15,0x08,0x0}} }; static const struct opl4_region regions_04[] = { /* Electric Piano 1 */ {0x15, 0x6c, {0x00b,6570,100, 0,0,0x00,0x28,0x38,0xf0,0x00,0x0c,0x0}}, {0x00, 0x7f, {0x06c,6375,100, 0,2,0x00,0xb0,0x22,0xf4,0x23,0x19,0x0}} }; static const struct opl4_region regions_05[] = { /* Electric Piano 2 */ {0x14, 0x27, {0x12c,7476,100, 0,3,0x00,0xa2,0x1b,0xf2,0x13,0x08,0x0}}, {0x28, 0x2d, {0x12d,6818,100, 0,3,0x00,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x2e, 0x33, {0x12e,5901,100, 0,3,0x00,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12f,5292,100, 0,3,0x00,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x130,4262,100, 0,3,0x0a,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x131,3627,100, 0,3,0x0a,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x132,3118,100, 0,3,0x04,0xa2,0x1b,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x133,2083,100, 0,3,0x03,0xa2,0x1b,0xf2,0x14,0x18,0x0}}, {0x53, 0x58, {0x134,1446,100, 0,3,0x07,0xa2,0x1b,0xf3,0x14,0x18,0x0}}, {0x59, 0x6d, {0x135,1917,100, 0,3,0x00,0xa2,0x1b,0xf4,0x15,0x08,0x0}}, {0x14, 0x2d, {0x12c,7472,100, 0,0,0x00,0xa2,0x18,0xf2,0x13,0x08,0x0}}, {0x2e, 0x33, {0x12d,6814,100, 0,0,0x00,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x34, 0x39, {0x12e,5897,100, 0,0,0x00,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x3a, 0x3f, {0x12f,5288,100, 0,0,0x00,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x40, 0x45, {0x130,4258,100, 0,0,0x0a,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x46, 0x4b, {0x131,3623,100, 0,0,0x0a,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x4c, 0x52, {0x132,3114,100, 0,0,0x04,0xa2,0x18,0xf2,0x14,0x08,0x0}}, {0x53, 0x58, {0x133,2079,100, 0,0,0x07,0xa2,0x18,0xf2,0x14,0x18,0x0}}, {0x59, 0x5e, {0x134,1442,100, 0,0,0x0a,0xa2,0x18,0xf3,0x14,0x18,0x0}}, {0x5f, 0x6d, {0x135,1913,100, 0,0,0x00,0xa2,0x18,0xf4,0x15,0x08,0x0}} }; static const struct opl4_region regions_06[] = { /* Harpsichord */ {0x15, 0x39, {0x080,5158,100, 0,0,0x00,0xb2,0x20,0xf5,0x24,0x19,0x0}}, {0x3a, 0x3f, {0x081,4408,100, 0,0,0x00,0xb2,0x20,0xf5,0x25,0x09,0x0}}, {0x40, 0x45, {0x082,3622,100, 0,0,0x00,0xb2,0x20,0xf5,0x25,0x09,0x0}}, {0x46, 0x4d, {0x083,2843,100, 0,0,0x00,0xb2,0x20,0xf5,0x25,0x19,0x0}}, {0x4e, 0x6c, {0x084,1307,100, 0,0,0x00,0xb2,0x20,0xf5,0x25,0x29,0x0}} }; static const struct opl4_region regions_07[] = { /* Clavinet */ {0x15, 0x51, {0x027,5009,100, 0,0,0x00,0xd2,0x28,0xf5,0x13,0x2b,0x0}}, {0x52, 0x6c, {0x028,3495,100, 0,0,0x00,0xd2,0x28,0xf5,0x13,0x3b,0x0}} }; static const struct opl4_region regions_08[] = { /* Celesta */ {0x15, 0x6c, {0x02b,3267,100, 0,0,0x00,0xdc,0x20,0xf4,0x15,0x07,0x3}} }; static const struct opl4_region regions_09[] = { /* Glockenspiel */ {0x15, 0x78, {0x0f3, 285,100, 0,0,0x00,0xc2,0x28,0xf6,0x25,0x25,0x0}} }; static const struct opl4_region regions_0a[] = { /* Music Box */ {0x15, 0x6c, {0x0f3,3362,100, 0,0,0x00,0xb6,0x20,0xa6,0x25,0x25,0x0}}, {0x15, 0x6c, {0x101,4773,100, 0,0,0x00,0xaa,0x20,0xd4,0x14,0x16,0x0}} }; static const struct opl4_region regions_0b[] = { /* Vibraphone */ {0x15, 0x6c, {0x101,4778,100, 0,0,0x00,0xc0,0x28,0xf4,0x14,0x16,0x4}} }; static const struct opl4_region regions_0c[] = { /* Marimba */ {0x15, 0x3f, {0x0f4,4778,100, 0,0,0x00,0xc4,0x38,0xf7,0x47,0x08,0x0}}, {0x40, 0x4c, {0x0f5,3217,100, 0,0,0x00,0xc4,0x38,0xf7,0x47,0x08,0x0}}, {0x4d, 0x5a, {0x0f5,3217,100, 0,0,0x00,0xc4,0x38,0xf7,0x48,0x08,0x0}}, {0x5b, 0x7f, {0x0f5,3218,100, 0,0,0x00,0xc4,0x38,0xf7,0x48,0x18,0x0}} }; static const struct opl4_region regions_0d[] = { /* Xylophone */ {0x00, 0x7f, {0x136,1729,100, 0,0,0x00,0xd2,0x38,0xf0,0x06,0x36,0x0}} }; static const struct opl4_region regions_0e[] = { /* Tubular Bell */ {0x01, 0x7f, {0x0ff,3999,100, 0,1,0x00,0x90,0x21,0xf4,0xa3,0x25,0x1}} }; static const struct opl4_region regions_0f[] = { /* Dulcimer */ {0x00, 0x7f, {0x03f,4236,100, 0,1,0x00,0xbc,0x29,0xf5,0x16,0x07,0x0}}, {0x00, 0x7f, {0x040,4236,100, 0,2,0x0e,0x94,0x2a,0xf5,0x16,0x07,0x0}} }; static const struct opl4_region regions_10[] = { /* Drawbar Organ */ {0x01, 0x7f, {0x08e,4394,100, 0,2,0x14,0xc2,0x3a,0xf0,0x00,0x0a,0x0}} }; static const struct opl4_region regions_11[] = { /* Percussive Organ */ {0x15, 0x3b, {0x08c,6062,100, 0,3,0x00,0xbe,0x3b,0xf0,0x00,0x09,0x0}}, {0x3c, 0x6c, {0x08d,2984,100, 0,3,0x00,0xbe,0x3b,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_12[] = { /* Rock Organ */ {0x15, 0x30, {0x128,6574,100, 0,1,0x00,0xcc,0x39,0xf0,0x00,0x0a,0x0}}, {0x31, 0x3c, {0x129,5040,100, 0,1,0x00,0xcc,0x39,0xf0,0x00,0x0a,0x0}}, {0x3d, 0x48, {0x12a,3498,100, 0,1,0x00,0xcc,0x39,0xf0,0x00,0x0a,0x0}}, {0x49, 0x54, {0x12b,1957,100, 0,1,0x00,0xcc,0x39,0xf0,0x00,0x0a,0x0}}, {0x55, 0x6c, {0x127, 423,100, 0,1,0x00,0xcc,0x39,0xf0,0x00,0x0a,0x0}} }; static const struct opl4_region regions_13[] = { /* Church Organ */ {0x15, 0x29, {0x087,7466,100, 0,1,0x00,0xc4,0x11,0xf0,0x00,0x09,0x0}}, {0x2a, 0x30, {0x088,6456,100, 0,1,0x00,0xc4,0x11,0xf0,0x00,0x09,0x0}}, {0x31, 0x38, {0x089,5428,100, 0,1,0x00,0xc4,0x11,0xf0,0x00,0x09,0x0}}, {0x39, 0x41, {0x08a,4408,100, 0,1,0x00,0xc4,0x11,0xf0,0x00,0x09,0x0}}, {0x42, 0x6c, {0x08b,3406,100, 0,1,0x00,0xc4,0x11,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_14[] = { /* Reed Organ */ {0x00, 0x53, {0x0ac,5570,100, 0,0,0x06,0xc0,0x38,0xf0,0x00,0x09,0x1}}, {0x54, 0x7f, {0x0ad,2497,100, 0,0,0x00,0xc0,0x38,0xf0,0x00,0x09,0x1}} }; static const struct opl4_region regions_15[] = { /* Accordion */ {0x15, 0x4c, {0x006,4261,100, 0,2,0x00,0xa4,0x22,0x90,0x00,0x09,0x0}}, {0x4d, 0x6c, {0x007,1530,100, 0,2,0x00,0xa4,0x22,0x90,0x00,0x09,0x0}}, {0x15, 0x6c, {0x070,4391,100, 0,3,0x00,0x8a,0x23,0xa0,0x00,0x09,0x0}} }; static const struct opl4_region regions_16[] = { /* Harmonica */ {0x15, 0x6c, {0x070,4408,100, 0,0,0x00,0xae,0x30,0xa0,0x00,0x09,0x2}} }; static const struct opl4_region regions_17[] = { /* Tango Accordion */ {0x00, 0x53, {0x0ac,5573,100, 0,0,0x00,0xae,0x38,0xf0,0x00,0x09,0x0}}, {0x54, 0x7f, {0x0ad,2500,100, 0,0,0x00,0xae,0x38,0xf0,0x00,0x09,0x0}}, {0x15, 0x6c, {0x041,8479,100, 0,2,0x00,0x6a,0x3a,0x75,0x20,0x0a,0x0}} }; static const struct opl4_region regions_18[] = { /* Nylon Guitar */ {0x15, 0x2f, {0x0b3,6964,100, 0,0,0x05,0xca,0x28,0xf5,0x34,0x09,0x0}}, {0x30, 0x36, {0x0b7,5567,100, 0,0,0x0c,0xca,0x28,0xf5,0x34,0x09,0x0}}, {0x37, 0x3c, {0x0b5,4653,100, 0,0,0x00,0xca,0x28,0xf6,0x34,0x09,0x0}}, {0x3d, 0x43, {0x0b4,3892,100, 0,0,0x00,0xca,0x28,0xf6,0x35,0x09,0x0}}, {0x44, 0x60, {0x0b6,2723,100, 0,0,0x00,0xca,0x28,0xf6,0x35,0x19,0x0}} }; static const struct opl4_region regions_19[] = { /* Steel Guitar */ {0x15, 0x31, {0x00c,6937,100, 0,0,0x00,0xbc,0x28,0xf0,0x04,0x19,0x0}}, {0x32, 0x38, {0x00d,5410,100, 0,0,0x00,0xbc,0x28,0xf0,0x05,0x09,0x0}}, {0x39, 0x47, {0x00e,4379,100, 0,0,0x00,0xbc,0x28,0xf5,0x94,0x09,0x0}}, {0x48, 0x6c, {0x00f,2843,100, 0,0,0x00,0xbc,0x28,0xf6,0x95,0x09,0x0}} }; static const struct opl4_region regions_1a[] = { /* Jazz Guitar */ {0x15, 0x31, {0x05a,6832,100, 0,0,0x00,0xca,0x28,0xf6,0x34,0x09,0x0}}, {0x32, 0x3f, {0x05b,4897,100, 0,0,0x00,0xca,0x28,0xf6,0x34,0x09,0x0}}, {0x40, 0x6c, {0x05c,3218,100, 0,0,0x00,0xca,0x28,0xf6,0x34,0x09,0x0}} }; static const struct opl4_region regions_1b[] = { /* Clean Guitar */ {0x15, 0x2c, {0x061,7053,100, 0,1,0x00,0xb4,0x29,0xf5,0x54,0x0a,0x0}}, {0x2d, 0x31, {0x060,6434,100, 0,1,0x00,0xb4,0x29,0xf5,0x54,0x0a,0x0}}, {0x32, 0x38, {0x063,5764,100, 0,1,0x00,0xbe,0x29,0xf5,0x55,0x0a,0x0}}, {0x39, 0x3f, {0x062,4627,100, 0,1,0x00,0xb4,0x29,0xf5,0x55,0x0a,0x0}}, {0x40, 0x44, {0x065,3963,100, 0,1,0x00,0xb4,0x29,0xf5,0x55,0x1a,0x0}}, {0x45, 0x4b, {0x064,3313,100, 0,1,0x00,0xb4,0x29,0xf5,0x55,0x1a,0x0}}, {0x4c, 0x54, {0x066,2462,100, 0,1,0x00,0xb4,0x29,0xf5,0x55,0x2a,0x0}}, {0x55, 0x6c, {0x067,1307,100, 0,1,0x00,0xb4,0x29,0xf6,0x56,0x0a,0x0}} }; static const struct opl4_region regions_1c[] = { /* Muted Guitar */ {0x01, 0x7f, {0x068,4408,100, 0,0,0x00,0xcc,0x28,0xf6,0x15,0x09,0x0}} }; static const struct opl4_region regions_1d[] = { /* Overdriven Guitar */ {0x00, 0x40, {0x0a5,6589,100, 0,1,0x00,0xc0,0x29,0xf2,0x11,0x09,0x0}}, {0x41, 0x7f, {0x0a6,5428,100, 0,1,0x00,0xc0,0x29,0xf2,0x11,0x09,0x0}} }; static const struct opl4_region regions_1e[] = { /* Distortion Guitar */ {0x15, 0x2a, {0x051,6928,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x2b, 0x2e, {0x052,6433,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x2f, 0x32, {0x053,5944,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x33, 0x36, {0x054,5391,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x37, 0x3a, {0x055,4897,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x3b, 0x3e, {0x056,4408,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x3f, 0x42, {0x057,3892,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x43, 0x46, {0x058,3361,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}}, {0x47, 0x6c, {0x059,2784,100, 0,1,0x00,0xbc,0x21,0xa2,0x12,0x0a,0x0}} }; static const struct opl4_region regions_1f[] = { /* Guitar Harmonics */ {0x15, 0x44, {0x05e,5499,100, 0,0,0x00,0xce,0x28,0xf4,0x24,0x09,0x0}}, {0x45, 0x49, {0x05d,4850,100, 0,0,0x00,0xe2,0x28,0xf4,0x24,0x09,0x0}}, {0x4a, 0x6c, {0x05f,4259,100, 0,0,0x00,0xce,0x28,0xf4,0x24,0x09,0x0}} }; static const struct opl4_region regions_20[] = { /* Acoustic Bass */ {0x15, 0x30, {0x004,8053,100, 0,0,0x00,0xe2,0x18,0xf5,0x15,0x09,0x0}}, {0x31, 0x6c, {0x005,4754,100, 0,0,0x00,0xe2,0x18,0xf5,0x15,0x09,0x0}} }; static const struct opl4_region regions_21[] = { /* Fingered Bass */ {0x01, 0x20, {0x04a,8762,100, 0,0,0x00,0xde,0x18,0xf6,0x14,0x09,0x0}}, {0x21, 0x25, {0x04b,8114,100, 0,0,0x00,0xde,0x18,0xf6,0x14,0x09,0x0}}, {0x26, 0x2a, {0x04c,7475,100, 0,0,0x00,0xde,0x18,0xf6,0x14,0x09,0x0}}, {0x2b, 0x7f, {0x04d,6841,100, 0,0,0x00,0xde,0x18,0xf6,0x14,0x09,0x0}} }; static const struct opl4_region regions_22[] = { /* Picked Bass */ {0x15, 0x23, {0x04f,7954,100, 0,0,0x00,0xcc,0x18,0xf3,0x90,0x0a,0x0}}, {0x24, 0x2a, {0x050,7318,100, 0,0,0x05,0xcc,0x18,0xf3,0x90,0x1a,0x0}}, {0x2b, 0x2f, {0x06b,6654,100, 0,0,0x00,0xcc,0x18,0xf3,0x90,0x2a,0x0}}, {0x30, 0x47, {0x069,6031,100, 0,0,0x00,0xcc,0x18,0xf5,0xb0,0x0a,0x0}}, {0x48, 0x6c, {0x06a,5393,100, 0,0,0x00,0xcc,0x18,0xf5,0xb0,0x0a,0x0}} }; static const struct opl4_region regions_23[] = { /* Fretless Bass */ {0x01, 0x7f, {0x04e,5297,100, 0,0,0x00,0xd2,0x10,0xf3,0x63,0x19,0x0}} }; static const struct opl4_region regions_24[] = { /* Slap Bass 1 */ {0x15, 0x6c, {0x0a3,7606,100, 0,1,0x00,0xde,0x19,0xf5,0x32,0x1a,0x0}} }; static const struct opl4_region regions_25[] = { /* Slap Bass 2 */ {0x01, 0x7f, {0x0a2,6694,100, 0,0,0x00,0xda,0x20,0xb0,0x02,0x09,0x0}} }; static const struct opl4_region regions_26[] = { /* Synth Bass 1 */ {0x15, 0x6c, {0x0be,7466,100, 0,1,0x00,0xb8,0x39,0xf4,0x14,0x09,0x0}} }; static const struct opl4_region regions_27[] = { /* Synth Bass 2 */ {0x00, 0x7f, {0x117,8103,100, 0,1,0x00,0xca,0x39,0xf3,0x50,0x08,0x0}} }; static const struct opl4_region regions_28[] = { /* Violin */ {0x15, 0x3a, {0x105,5158,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x3b, 0x3f, {0x102,4754,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x40, 0x41, {0x106,4132,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x42, 0x44, {0x107,4033,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x45, 0x47, {0x108,3580,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x48, 0x4a, {0x10a,2957,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x4b, 0x4c, {0x10b,2724,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x4d, 0x4e, {0x10c,2530,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x4f, 0x51, {0x10d,2166,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}}, {0x52, 0x6c, {0x109,1825,100, 0,3,0x00,0xcc,0x3b,0xf3,0x20,0x09,0x0}} }; static const struct opl4_region regions_29[] = { /* Viola */ {0x15, 0x32, {0x103,5780,100, 0,3,0x00,0xc4,0x3b,0xa3,0x20,0x09,0x0}}, {0x33, 0x35, {0x104,5534,100, 0,3,0x00,0xc4,0x3b,0xa3,0x20,0x09,0x0}}, {0x36, 0x38, {0x105,5158,100, 0,3,0x00,0xc4,0x3b,0xa3,0x20,0x09,0x0}}, {0x39, 0x3d, {0x102,4754,100, 0,3,0x00,0xca,0x3b,0xa3,0x20,0x09,0x0}}, {0x3e, 0x3f, {0x106,4132,100, 0,3,0x00,0xc4,0x3b,0xa3,0x20,0x09,0x0}}, {0x40, 0x42, {0x107,4033,100, 0,3,0x00,0xc4,0x3b,0xa3,0x20,0x09,0x0}}, {0x43, 0x45, {0x108,3580,100, 0,3,0x00,0xd0,0x3b,0xa3,0x20,0x09,0x0}}, {0x46, 0x48, {0x10a,2957,100, 0,3,0x00,0xca,0x3b,0xa3,0x20,0x09,0x0}}, {0x49, 0x4a, {0x10b,2724,100, 0,3,0x00,0xd0,0x3b,0xa3,0x20,0x09,0x0}}, {0x4b, 0x4c, {0x10c,2530,100, 0,3,0x00,0xca,0x3b,0xa3,0x20,0x09,0x0}}, {0x4d, 0x4f, {0x10d,2166,100, 0,3,0x00,0xd0,0x3b,0xa3,0x20,0x09,0x0}}, {0x50, 0x6c, {0x109,1825,100, 0,3,0x00,0xd0,0x3b,0xa3,0x20,0x09,0x0}} }; static const struct opl4_region regions_2a[] = { /* Cello */ {0x15, 0x2d, {0x112,6545,100, 0,3,0x00,0xc0,0x33,0xa0,0x00,0x08,0x0}}, {0x2e, 0x37, {0x113,5764,100, 0,3,0x00,0xc0,0x33,0xa0,0x00,0x08,0x0}}, {0x38, 0x3e, {0x115,4378,100, 0,3,0x00,0xc0,0x33,0xa0,0x00,0x18,0x0}}, {0x3f, 0x44, {0x116,3998,100, 0,3,0x00,0xc0,0x33,0xa0,0x00,0x18,0x0}}, {0x45, 0x6c, {0x114,3218,100, 0,3,0x00,0xc0,0x33,0xa0,0x00,0x18,0x0}} }; static const struct opl4_region regions_2b[] = { /* Contrabass */ {0x15, 0x29, {0x110,7713,100, 0,1,0x00,0xc2,0x19,0x90,0x00,0x09,0x0}}, {0x2a, 0x6c, {0x111,6162,100, 0,1,0x00,0xc2,0x19,0x90,0x00,0x09,0x0}} }; static const struct opl4_region regions_2c[] = { /* Tremolo Strings */ {0x15, 0x3b, {0x0b0,4810,100, 0,0,0x0a,0xde,0x38,0xf0,0x00,0x07,0x6}}, {0x3c, 0x41, {0x035,4035,100, 0,0,0x05,0xde,0x38,0xf0,0x00,0x07,0x6}}, {0x42, 0x47, {0x033,3129,100, 0,0,0x05,0xde,0x38,0xf0,0x00,0x07,0x6}}, {0x48, 0x52, {0x034,2625,100, 0,0,0x05,0xde,0x38,0xf0,0x00,0x07,0x6}}, {0x53, 0x6c, {0x0af, 936,100, 0,0,0x00,0xde,0x38,0xf0,0x00,0x07,0x6}} }; static const struct opl4_region regions_2d[] = { /* Pizzicato Strings */ {0x15, 0x32, {0x0b8,6186,100, 0,0,0x00,0xbc,0x28,0xf0,0x00,0x05,0x0}}, {0x33, 0x3b, {0x0b9,5031,100, 0,0,0x00,0xbc,0x28,0xf0,0x00,0x05,0x0}}, {0x3c, 0x42, {0x0bb,4146,100, 0,0,0x00,0xbc,0x28,0xf0,0x00,0x05,0x0}}, {0x43, 0x48, {0x0ba,3245,100, 0,0,0x00,0xc2,0x28,0xf0,0x00,0x05,0x0}}, {0x49, 0x6c, {0x0bc,2352,100, 0,0,0x00,0xbc,0x28,0xf0,0x00,0x05,0x0}} }; static const struct opl4_region regions_2e[] = { /* Harp */ {0x15, 0x46, {0x07e,3740,100, 0,1,0x00,0xd2,0x29,0xf5,0x25,0x07,0x0}}, {0x47, 0x6c, {0x07f,2319,100, 0,1,0x00,0xd2,0x29,0xf5,0x25,0x07,0x0}} }; static const struct opl4_region regions_2f[] = { /* Timpani */ {0x15, 0x6c, {0x100,6570,100, 0,0,0x00,0xf8,0x28,0xf0,0x05,0x16,0x0}} }; static const struct opl4_region regions_30[] = { /* Strings */ {0x15, 0x3b, {0x13c,4806,100, 0,0,0x00,0xc8,0x20,0x80,0x00,0x07,0x0}}, {0x3c, 0x41, {0x13e,4035,100, 0,0,0x00,0xc8,0x20,0x80,0x00,0x07,0x0}}, {0x42, 0x47, {0x13d,3122,100, 0,0,0x00,0xc8,0x20,0x80,0x00,0x07,0x0}}, {0x48, 0x52, {0x13f,2629,100, 0,0,0x00,0xbe,0x20,0x80,0x00,0x07,0x0}}, {0x53, 0x6c, {0x140, 950,100, 0,0,0x00,0xbe,0x20,0x80,0x00,0x07,0x0}} }; static const struct opl4_region regions_31[] = { /* Slow Strings */ {0x15, 0x3b, {0x0b0,4810,100, 0,1,0x0a,0xbe,0x19,0xf0,0x00,0x07,0x0}}, {0x3c, 0x41, {0x035,4035,100, 0,1,0x05,0xbe,0x19,0xf0,0x00,0x07,0x0}}, {0x42, 0x47, {0x033,3129,100, 0,1,0x05,0xbe,0x19,0xf0,0x00,0x07,0x0}}, {0x48, 0x52, {0x034,2625,100, 0,1,0x05,0xbe,0x19,0xf0,0x00,0x07,0x0}}, {0x53, 0x6c, {0x0af, 936,100, 0,1,0x00,0xbe,0x19,0xf0,0x00,0x07,0x0}} }; static const struct opl4_region regions_32[] = { /* Synth Strings 1 */ {0x05, 0x71, {0x002,6045,100,-2,0,0x00,0xa6,0x20,0x93,0x22,0x06,0x0}}, {0x15, 0x6c, {0x0ae,3261,100, 2,0,0x00,0xc6,0x20,0x70,0x01,0x06,0x0}} }; static const struct opl4_region regions_33[] = { /* Synth Strings 2 */ {0x15, 0x6c, {0x002,4513,100, 5,1,0x00,0xb4,0x19,0x70,0x00,0x06,0x0}}, {0x15, 0x6c, {0x002,4501,100,-5,1,0x00,0xb4,0x19,0x70,0x00,0x06,0x0}} }; static const struct opl4_region regions_34[] = { /* Choir Aahs */ {0x15, 0x3a, {0x018,5010,100, 0,2,0x00,0xc2,0x1a,0x70,0x00,0x08,0x0}}, {0x3b, 0x40, {0x019,4370,100, 0,2,0x00,0xc2,0x1a,0x70,0x00,0x08,0x0}}, {0x41, 0x47, {0x01a,3478,100, 0,2,0x00,0xc2,0x1a,0x70,0x00,0x08,0x0}}, {0x48, 0x6c, {0x01b,2197,100, 0,2,0x00,0xc2,0x1a,0x70,0x00,0x08,0x0}} }; static const struct opl4_region regions_35[] = { /* Voice Oohs */ {0x15, 0x6c, {0x029,3596,100, 0,0,0x00,0xe6,0x20,0xf7,0x20,0x08,0x0}} }; static const struct opl4_region regions_36[] = { /* Synth Voice */ {0x15, 0x6c, {0x02a,3482,100, 0,1,0x00,0xc2,0x19,0x85,0x21,0x07,0x0}} }; static const struct opl4_region regions_37[] = { /* Orchestra Hit */ {0x15, 0x6c, {0x049,4394,100, 0,0,0x00,0xfe,0x30,0x80,0x05,0x05,0x0}} }; static const struct opl4_region regions_38[] = { /* Trumpet */ {0x15, 0x3c, {0x0f6,4706,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}}, {0x3d, 0x43, {0x0f8,3894,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}}, {0x44, 0x48, {0x0f7,3118,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}}, {0x49, 0x4e, {0x0fa,2322,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}}, {0x4f, 0x55, {0x0f9,1634,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}}, {0x56, 0x6c, {0x0fb, 786,100, 0,2,0x00,0xd6,0x32,0xf3,0x20,0x0a,0x0}} }; static const struct opl4_region regions_39[] = { /* Trombone */ {0x15, 0x3a, {0x0f0,5053,100, 0,1,0x00,0xd6,0x21,0xf0,0x00,0x09,0x0}}, {0x3b, 0x3f, {0x0f1,4290,100, 0,1,0x00,0xd6,0x21,0xf0,0x00,0x09,0x0}}, {0x40, 0x6c, {0x0f2,3580,100, 0,1,0x00,0xd6,0x21,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_3a[] = { /* Tuba */ {0x15, 0x2d, {0x085,7096,100, 0,1,0x00,0xde,0x21,0xf5,0x10,0x09,0x0}}, {0x2e, 0x6c, {0x086,6014,100, 0,1,0x00,0xde,0x21,0xf5,0x10,0x09,0x0}} }; static const struct opl4_region regions_3b[] = { /* Muted Trumpet */ {0x15, 0x45, {0x0b1,4135,100, 0,0,0x00,0xcc,0x28,0xf3,0x10,0x0a,0x1}}, {0x46, 0x6c, {0x0b2,2599,100, 0,0,0x00,0xcc,0x28,0x83,0x10,0x0a,0x1}} }; static const struct opl4_region regions_3c[] = { /* French Horns */ {0x15, 0x49, {0x07c,3624,100, 0,2,0x00,0xd0,0x1a,0xf0,0x00,0x09,0x0}}, {0x4a, 0x6c, {0x07d,2664,100, 0,2,0x00,0xd0,0x1a,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_3d[] = { /* Brass Section */ {0x15, 0x42, {0x0fc,4375,100, 0,0,0x00,0xd6,0x28,0xf0,0x00,0x0a,0x0}}, {0x43, 0x6c, {0x0fd,2854,100, 0,0,0x00,0xd6,0x28,0xf0,0x00,0x0a,0x0}} }; static const struct opl4_region regions_3e[] = { /* Synth Brass 1 */ {0x01, 0x27, {0x0d3,9094,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x28, 0x2d, {0x0da,8335,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x2e, 0x33, {0x0d4,7558,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x34, 0x39, {0x0db,6785,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x3a, 0x3f, {0x0d5,6042,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x40, 0x45, {0x0dc,5257,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x46, 0x4b, {0x0d6,4493,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x4c, 0x51, {0x0dd,3741,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x52, 0x57, {0x0d7,3012,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x58, 0x5d, {0x0de,2167,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x5e, 0x63, {0x0d8,1421,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x64, 0x7f, {0x0d9,-115,100,-1,0,0x00,0xbe,0x18,0xa5,0x11,0x08,0x0}}, {0x01, 0x27, {0x118,9103,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x28, 0x2d, {0x119,8340,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x2e, 0x33, {0x11a,7565,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x34, 0x39, {0x11b,6804,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x3a, 0x3f, {0x11c,6042,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x40, 0x45, {0x11d,5277,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x46, 0x4b, {0x11e,4520,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x4c, 0x51, {0x11f,3741,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x52, 0x57, {0x120,3012,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x58, 0x5d, {0x121,2166,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x5e, 0x64, {0x122,1421,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}}, {0x65, 0x7f, {0x123,-115,100, 1,1,0x00,0xbe,0x19,0x85,0x23,0x08,0x0}} }; static const struct opl4_region regions_3f[] = { /* Synth Brass 2 */ {0x01, 0x27, {0x118,9113,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x28, 0x2d, {0x119,8350,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x2e, 0x33, {0x11a,7575,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x34, 0x39, {0x11b,6814,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x3a, 0x3f, {0x11c,6052,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x40, 0x45, {0x11d,5287,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x46, 0x4b, {0x11e,4530,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x4c, 0x51, {0x11f,3751,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x52, 0x57, {0x120,3022,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x58, 0x5d, {0x121,2176,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x5e, 0x64, {0x122,1431,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x65, 0x7f, {0x123,-105,100, 3,6,0x00,0xae,0x26,0x85,0x23,0x08,0x0}}, {0x00, 0x7f, {0x124,4034,100,-3,2,0x00,0xea,0x22,0x85,0x23,0x08,0x0}} }; static const struct opl4_region regions_40[] = { /* Soprano Sax */ {0x15, 0x3f, {0x0e3,4228,100, 0,1,0x00,0xc8,0x21,0xf5,0x20,0x0a,0x0}}, {0x40, 0x45, {0x0e4,3495,100, 0,1,0x00,0xc8,0x21,0xf5,0x20,0x0a,0x0}}, {0x46, 0x4b, {0x0e5,2660,100, 0,1,0x00,0xd6,0x21,0xf5,0x20,0x0a,0x0}}, {0x4c, 0x51, {0x0e6,2002,100, 0,1,0x00,0xd6,0x21,0xf5,0x20,0x0a,0x0}}, {0x52, 0x59, {0x0e7,1186,100, 0,1,0x00,0xd6,0x21,0xf5,0x20,0x0a,0x0}}, {0x59, 0x6c, {0x0e8,1730,100, 0,1,0x00,0xc8,0x21,0xf5,0x20,0x0a,0x0}} }; static const struct opl4_region regions_41[] = { /* Alto Sax */ {0x15, 0x32, {0x092,6204,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x33, 0x35, {0x096,5812,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x36, 0x3a, {0x099,5318,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x3b, 0x3b, {0x08f,5076,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x3c, 0x3e, {0x093,4706,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x3f, 0x41, {0x097,4321,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x42, 0x44, {0x09a,3893,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x45, 0x47, {0x090,3497,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x48, 0x4a, {0x094,3119,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x4b, 0x4d, {0x098,2726,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x4e, 0x50, {0x09b,2393,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x51, 0x53, {0x091,2088,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}}, {0x54, 0x6c, {0x095,1732,100, 0,1,0x00,0xbe,0x19,0xf5,0x20,0x0b,0x0}} }; static const struct opl4_region regions_42[] = { /* Tenor Sax */ {0x24, 0x30, {0x0e9,6301,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x31, 0x34, {0x0ea,5781,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x35, 0x3a, {0x0eb,5053,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x3b, 0x41, {0x0ed,4165,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x42, 0x47, {0x0ec,3218,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x48, 0x51, {0x0ee,2462,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}}, {0x52, 0x6c, {0x0ef,1421,100, 0,1,0x00,0xbc,0x19,0xf4,0x10,0x0b,0x0}} }; static const struct opl4_region regions_43[] = { /* Baritone Sax */ {0x15, 0x2d, {0x0df,6714,100, 0,1,0x00,0xce,0x19,0xf0,0x00,0x0a,0x0}}, {0x2e, 0x34, {0x0e1,5552,100, 0,1,0x00,0xce,0x19,0xf0,0x00,0x0a,0x0}}, {0x35, 0x39, {0x0e2,5178,100, 0,1,0x00,0xce,0x19,0xf0,0x00,0x0a,0x0}}, {0x3a, 0x6c, {0x0e0,4437,100, 0,1,0x00,0xce,0x19,0xf0,0x00,0x0a,0x0}} }; static const struct opl4_region regions_44[] = { /* Oboe */ {0x15, 0x3c, {0x042,4493,100, 0,1,0x00,0xe6,0x39,0xf4,0x10,0x0a,0x0}}, {0x3d, 0x43, {0x044,3702,100, 0,1,0x00,0xdc,0x39,0xf4,0x10,0x0a,0x0}}, {0x44, 0x49, {0x043,2956,100, 0,1,0x00,0xdc,0x39,0xf4,0x10,0x0a,0x0}}, {0x4a, 0x4f, {0x046,2166,100, 0,1,0x00,0xdc,0x39,0xf4,0x10,0x0a,0x0}}, {0x50, 0x55, {0x045,1420,100, 0,1,0x00,0xdc,0x39,0xf4,0x10,0x0a,0x0}}, {0x56, 0x6c, {0x047, 630,100, 0,1,0x00,0xe6,0x39,0xf4,0x10,0x0a,0x0}} }; static const struct opl4_region regions_45[] = { /* English Horn */ {0x15, 0x38, {0x03c,5098,100, 0,1,0x00,0xc4,0x31,0xf0,0x00,0x09,0x0}}, {0x39, 0x3e, {0x03b,4291,100, 0,1,0x00,0xc4,0x31,0xf0,0x00,0x09,0x0}}, {0x3f, 0x6c, {0x03d,3540,100, 0,1,0x00,0xc4,0x31,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_46[] = { /* Bassoon */ {0x15, 0x22, {0x038,7833,100, 0,1,0x00,0xc6,0x31,0xf0,0x00,0x0b,0x0}}, {0x23, 0x2e, {0x03a,7070,100, 0,1,0x00,0xc6,0x31,0xf0,0x00,0x0b,0x0}}, {0x2f, 0x6c, {0x039,6302,100, 0,1,0x00,0xc6,0x31,0xf0,0x00,0x0b,0x0}} }; static const struct opl4_region regions_47[] = { /* Clarinet */ {0x15, 0x3b, {0x09e,5900,100, 0,1,0x00,0xc8,0x29,0xf3,0x20,0x0a,0x0}}, {0x3c, 0x41, {0x0a0,5158,100, 0,1,0x00,0xc8,0x29,0xf3,0x20,0x0a,0x0}}, {0x42, 0x4a, {0x09f,4260,100, 0,1,0x00,0xc8,0x29,0xf3,0x20,0x0a,0x0}}, {0x4b, 0x6c, {0x0a1,2957,100, 0,1,0x00,0xc8,0x29,0xf3,0x20,0x0a,0x0}} }; static const struct opl4_region regions_48[] = { /* Piccolo */ {0x15, 0x40, {0x071,4803,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}}, {0x41, 0x4d, {0x072,3314,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}}, {0x4e, 0x53, {0x073,1731,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}}, {0x54, 0x5f, {0x074,2085,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}}, {0x60, 0x6c, {0x075,1421,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}} }; static const struct opl4_region regions_49[] = { /* Flute */ {0x15, 0x40, {0x071,4803,100, 0,0,0x00,0xdc,0x38,0xf0,0x00,0x0a,0x2}}, {0x41, 0x4d, {0x072,3314,100, 0,0,0x00,0xdc,0x38,0xf0,0x00,0x0a,0x2}}, {0x4e, 0x6c, {0x073,1731,100, 0,0,0x00,0xe6,0x38,0xf0,0x00,0x0a,0x2}} }; static const struct opl4_region regions_4a[] = { /* Recorder */ {0x15, 0x6f, {0x0bd,4897,100, 0,0,0x00,0xec,0x30,0x70,0x00,0x09,0x1}} }; static const struct opl4_region regions_4b[] = { /* Pan Flute */ {0x15, 0x6c, {0x077,2359,100, 0,0,0x00,0xde,0x38,0xf0,0x00,0x09,0x3}} }; static const struct opl4_region regions_4c[] = { /* Bottle Blow */ {0x15, 0x6c, {0x077,2359,100, 0,0,0x00,0xc8,0x38,0xf0,0x00,0x09,0x1}}, {0x01, 0x7f, {0x125,7372,100, 0,0,0x1e,0x80,0x00,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_4d[] = { /* Shakuhachi */ {0x00, 0x7f, {0x0ab,4548,100, 0,0,0x00,0xd6,0x30,0xf0,0x00,0x0a,0x3}}, {0x15, 0x6c, {0x076,3716,100, 0,0,0x00,0xa2,0x28,0x70,0x00,0x09,0x2}} }; static const struct opl4_region regions_4e[] = { /* Whistle */ {0x00, 0x7f, {0x0aa,1731,100, 0,4,0x00,0xd2,0x2c,0x70,0x00,0x0a,0x0}} }; static const struct opl4_region regions_4f[] = { /* Ocarina */ {0x00, 0x7f, {0x0aa,1731,100, 0,1,0x00,0xce,0x29,0x90,0x00,0x0a,0x1}} }; static const struct opl4_region regions_50[] = { /* Square Lead */ {0x01, 0x2a, {0x0cc,9853,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x2b, 0x36, {0x0cd,6785,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x37, 0x42, {0x0ca,5248,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x43, 0x4e, {0x0cf,3713,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x4f, 0x5a, {0x0ce,2176,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x5b, 0x7f, {0x0cb, 640,100, 3,0,0x00,0xac,0x38,0xc6,0x21,0x09,0x0}}, {0x01, 0x2a, {0x0cc,9844,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}}, {0x2b, 0x36, {0x0cd,6776,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}}, {0x37, 0x42, {0x0ca,5239,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}}, {0x43, 0x4e, {0x0cf,3704,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}}, {0x4f, 0x5a, {0x0ce,2167,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}}, {0x5b, 0x7f, {0x0cb, 631,100,-3,0,0x00,0xac,0x08,0xc6,0x21,0x09,0x0}} }; static const struct opl4_region regions_51[] = { /* Sawtooth Lead */ {0x01, 0x27, {0x118,9108,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x28, 0x2d, {0x119,8345,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x2e, 0x33, {0x11a,7570,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x34, 0x39, {0x11b,6809,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x3a, 0x3f, {0x11c,6047,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x40, 0x45, {0x11d,5282,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x46, 0x4b, {0x11e,4525,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x4c, 0x51, {0x11f,3746,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x52, 0x57, {0x120,3017,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x58, 0x5d, {0x121,2171,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x5e, 0x66, {0x122,1426,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x67, 0x7f, {0x123,-110,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x01, 0x27, {0x118,9098,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x28, 0x2d, {0x119,8335,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x2e, 0x33, {0x11a,7560,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x34, 0x39, {0x11b,6799,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x3a, 0x3f, {0x11c,6037,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x40, 0x45, {0x11d,5272,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x46, 0x4b, {0x11e,4515,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x4c, 0x51, {0x11f,3736,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x52, 0x57, {0x120,3007,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x58, 0x5d, {0x121,2161,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x5e, 0x66, {0x122,1416,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}}, {0x67, 0x7f, {0x123,-120,100, 0,0,0x00,0xc8,0x30,0xf2,0x22,0x0a,0x0}} }; static const struct opl4_region regions_52[] = { /* Calliope Lead */ {0x00, 0x7f, {0x0aa,1731,100, 0,0,0x00,0xc2,0x28,0x90,0x00,0x0a,0x2}}, {0x15, 0x6c, {0x076,3716,100, 0,0,0x00,0xb6,0x28,0xb0,0x00,0x09,0x2}} }; static const struct opl4_region regions_53[] = { /* Chiffer Lead */ {0x00, 0x7f, {0x13a,3665,100, 0,2,0x00,0xcc,0x2a,0xf0,0x10,0x09,0x1}}, {0x01, 0x7f, {0x0fe,3660,100, 0,0,0x00,0xbe,0x28,0xf3,0x10,0x17,0x0}} }; static const struct opl4_region regions_54[] = { /* Charang Lead */ {0x00, 0x40, {0x0a5,6594,100, 0,3,0x00,0xba,0x33,0xf2,0x11,0x09,0x0}}, {0x41, 0x7f, {0x0a6,5433,100, 0,3,0x00,0xba,0x33,0xf2,0x11,0x09,0x0}}, {0x01, 0x27, {0x118,9098,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x28, 0x2d, {0x119,8335,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x2e, 0x33, {0x11a,7560,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x34, 0x39, {0x11b,6799,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x3a, 0x3f, {0x11c,6037,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x40, 0x45, {0x11d,5272,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x46, 0x4b, {0x11e,4515,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x4c, 0x51, {0x11f,3736,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x52, 0x57, {0x120,3007,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x58, 0x5d, {0x121,2161,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x5e, 0x66, {0x122,1416,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}}, {0x67, 0x7f, {0x123,-120,100, 0,2,0x00,0xa4,0x2a,0xf2,0x22,0x0e,0x0}} }; static const struct opl4_region regions_55[] = { /* Voice Lead */ {0x00, 0x7f, {0x0aa,1739,100, 0,6,0x00,0x8c,0x2e,0x90,0x00,0x0a,0x0}}, {0x15, 0x6c, {0x02a,3474,100, 0,1,0x00,0xd8,0x29,0xf0,0x05,0x0a,0x0}} }; static const struct opl4_region regions_56[] = { /* 5ths Lead */ {0x01, 0x27, {0x118,8468,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x28, 0x2d, {0x119,7705,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x2e, 0x33, {0x11a,6930,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x34, 0x39, {0x11b,6169,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x3a, 0x3f, {0x11c,5407,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x40, 0x45, {0x11d,4642,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x46, 0x4b, {0x11e,3885,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x4c, 0x51, {0x11f,3106,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x52, 0x57, {0x120,2377,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x58, 0x5d, {0x121,1531,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x5e, 0x64, {0x122, 786,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x65, 0x7f, {0x123,-750,100, 0,2,0x00,0xd0,0x32,0xf5,0x20,0x08,0x0}}, {0x05, 0x71, {0x002,4503,100, 0,1,0x00,0xb8,0x31,0xb3,0x20,0x0b,0x0}} }; static const struct opl4_region regions_57[] = { /* Bass & Lead */ {0x00, 0x7f, {0x117,8109,100, 0,1,0x00,0xbc,0x29,0xf3,0x50,0x08,0x0}}, {0x01, 0x27, {0x118,9097,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x28, 0x2d, {0x119,8334,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x2e, 0x33, {0x11a,7559,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x34, 0x39, {0x11b,6798,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x3a, 0x3f, {0x11c,6036,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x40, 0x45, {0x11d,5271,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x46, 0x4b, {0x11e,4514,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x4c, 0x51, {0x11f,3735,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x52, 0x57, {0x120,3006,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x58, 0x5d, {0x121,2160,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x5e, 0x66, {0x122,1415,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}}, {0x67, 0x7f, {0x123,-121,100, 0,2,0x00,0xbc,0x2a,0xf2,0x20,0x0a,0x0}} }; static const struct opl4_region regions_58[] = { /* New Age Pad */ {0x15, 0x6c, {0x002,4501,100, 0,4,0x00,0xa4,0x24,0x80,0x01,0x05,0x0}}, {0x15, 0x6c, {0x0f3,4253,100, 0,3,0x00,0x8c,0x23,0xa2,0x14,0x06,0x1}} }; static const struct opl4_region regions_59[] = { /* Warm Pad */ {0x15, 0x6c, {0x04e,5306,100, 2,2,0x00,0x92,0x2a,0x34,0x23,0x05,0x2}}, {0x15, 0x6c, {0x029,3575,100,-2,2,0x00,0xbe,0x22,0x31,0x23,0x06,0x0}} }; static const struct opl4_region regions_5a[] = { /* Polysynth Pad */ {0x01, 0x27, {0x118,9111,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x28, 0x2d, {0x119,8348,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x2e, 0x33, {0x11a,7573,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x34, 0x39, {0x11b,6812,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x3a, 0x3f, {0x11c,6050,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x40, 0x45, {0x11d,5285,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x46, 0x4b, {0x11e,4528,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x4c, 0x51, {0x11f,3749,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x52, 0x57, {0x120,3020,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x58, 0x5d, {0x121,2174,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x5e, 0x66, {0x122,1429,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x67, 0x7f, {0x123,-107,100, 0,3,0x00,0xae,0x23,0xf2,0x20,0x07,0x1}}, {0x00, 0x7f, {0x124,4024,100, 0,2,0x00,0xae,0x22,0xe5,0x20,0x08,0x0}} }; static const struct opl4_region regions_5b[] = { /* Choir Pad */ {0x15, 0x3a, {0x018,5010,100, 0,5,0x00,0xb0,0x25,0x70,0x00,0x06,0x0}}, {0x3b, 0x40, {0x019,4370,100, 0,5,0x00,0xb0,0x25,0x70,0x00,0x06,0x0}}, {0x41, 0x47, {0x01a,3478,100, 0,5,0x00,0xb0,0x25,0x70,0x00,0x06,0x0}}, {0x48, 0x6c, {0x01b,2197,100, 0,5,0x00,0xb0,0x25,0x70,0x00,0x06,0x0}}, {0x15, 0x6c, {0x02a,3482,100, 0,4,0x00,0x98,0x24,0x65,0x21,0x06,0x0}} }; static const struct opl4_region regions_5c[] = { /* Bowed Pad */ {0x15, 0x6c, {0x101,4790,100,-1,1,0x00,0xbe,0x19,0x44,0x14,0x16,0x0}}, {0x00, 0x7f, {0x0aa,1720,100, 1,1,0x00,0x94,0x19,0x40,0x00,0x06,0x0}} }; static const struct opl4_region regions_5d[] = { /* Metallic Pad */ {0x15, 0x31, {0x00c,6943,100, 0,2,0x00,0xa0,0x0a,0x60,0x03,0x06,0x0}}, {0x32, 0x38, {0x00d,5416,100, 0,2,0x00,0xa0,0x0a,0x60,0x03,0x06,0x0}}, {0x39, 0x47, {0x00e,4385,100, 0,2,0x00,0xa0,0x0a,0x60,0x03,0x06,0x0}}, {0x48, 0x6c, {0x00f,2849,100, 0,2,0x00,0xa0,0x0a,0x60,0x03,0x06,0x0}}, {0x00, 0x7f, {0x03f,4224,100, 0,1,0x00,0x9c,0x31,0x65,0x16,0x07,0x0}} }; static const struct opl4_region regions_5e[] = { /* Halo Pad */ {0x00, 0x7f, {0x124,4038,100, 0,2,0x00,0xa6,0x1a,0x85,0x23,0x08,0x0}}, {0x15, 0x6c, {0x02a,3471,100, 0,3,0x00,0xc0,0x1b,0xc0,0x05,0x06,0x0}} }; static const struct opl4_region regions_5f[] = { /* Sweep Pad */ {0x01, 0x27, {0x0d3,9100,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x28, 0x2d, {0x0da,8341,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x2e, 0x33, {0x0d4,7564,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x34, 0x39, {0x0db,6791,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x3a, 0x3f, {0x0d5,6048,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x40, 0x45, {0x0dc,5263,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x46, 0x4b, {0x0d6,4499,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x4c, 0x51, {0x0dd,3747,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x52, 0x57, {0x0d7,3018,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x58, 0x5d, {0x0de,2173,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x5e, 0x63, {0x0d8,1427,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x64, 0x7f, {0x0d9,-109,100, 0,1,0x00,0xce,0x19,0x13,0x11,0x06,0x0}}, {0x01, 0x27, {0x0d3,9088,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x28, 0x2d, {0x0da,8329,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x2e, 0x33, {0x0d4,7552,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x34, 0x39, {0x0db,6779,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x3a, 0x3f, {0x0d5,6036,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x40, 0x45, {0x0dc,5251,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x46, 0x4b, {0x0d6,4487,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x4c, 0x51, {0x0dd,3735,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x52, 0x57, {0x0d7,3006,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x58, 0x5d, {0x0de,2161,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x5e, 0x63, {0x0d8,1415,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}}, {0x64, 0x7f, {0x0d9,-121,100, 0,0,0x00,0xce,0x18,0x13,0x11,0x06,0x0}} }; static const struct opl4_region regions_60[] = { /* Ice Rain */ {0x01, 0x7f, {0x04e,9345,100, 0,2,0x00,0xcc,0x22,0xa3,0x63,0x17,0x0}}, {0x00, 0x7f, {0x143,5586, 20, 0,2,0x00,0x6e,0x2a,0xf0,0x05,0x05,0x0}} }; static const struct opl4_region regions_61[] = { /* Soundtrack */ {0x15, 0x6c, {0x002,4501,100, 0,2,0x00,0xb6,0x2a,0x60,0x01,0x05,0x0}}, {0x15, 0x6c, {0x0f3,1160,100, 0,5,0x00,0xa8,0x2d,0x52,0x14,0x06,0x2}} }; static const struct opl4_region regions_62[] = { /* Crystal */ {0x15, 0x6c, {0x0f3,1826,100, 0,3,0x00,0xb8,0x33,0xf6,0x25,0x25,0x0}}, {0x15, 0x2c, {0x06d,7454,100, 0,3,0x00,0xac,0x3b,0x85,0x24,0x06,0x0}}, {0x2d, 0x36, {0x06e,5925,100, 0,3,0x00,0xac,0x3b,0x85,0x24,0x06,0x0}}, {0x37, 0x6c, {0x06f,4403,100, 0,3,0x09,0xac,0x3b,0x85,0x24,0x06,0x0}} }; static const struct opl4_region regions_63[] = { /* Atmosphere */ {0x05, 0x71, {0x002,4509,100, 0,2,0x00,0xc8,0x32,0x73,0x22,0x06,0x1}}, {0x15, 0x2f, {0x0b3,6964,100, 0,2,0x05,0xc2,0x32,0xf5,0x34,0x07,0x2}}, {0x30, 0x36, {0x0b7,5567,100, 0,2,0x0c,0xc2,0x32,0xf5,0x34,0x07,0x2}}, {0x37, 0x3c, {0x0b5,4653,100, 0,2,0x00,0xc2,0x32,0xf6,0x34,0x07,0x2}}, {0x3d, 0x43, {0x0b4,3892,100, 0,2,0x00,0xc2,0x32,0xf6,0x35,0x07,0x2}}, {0x44, 0x60, {0x0b6,2723,100, 0,2,0x00,0xc2,0x32,0xf6,0x35,0x17,0x2}} }; static const struct opl4_region regions_64[] = { /* Brightness */ {0x00, 0x7f, {0x137,5285,100, 0,2,0x00,0xbe,0x2a,0xa5,0x18,0x08,0x0}}, {0x15, 0x6c, {0x02a,3481,100, 0,1,0x00,0xc8,0x29,0x80,0x05,0x05,0x0}} }; static const struct opl4_region regions_65[] = { /* Goblins */ {0x15, 0x6c, {0x002,4501,100,-1,2,0x00,0xca,0x2a,0x40,0x01,0x05,0x0}}, {0x15, 0x6c, {0x009,9679, 20, 1,4,0x00,0x3c,0x0c,0x22,0x11,0x06,0x0}} }; static const struct opl4_region regions_66[] = { /* Echoes */ {0x15, 0x6c, {0x02a,3487,100, 0,3,0x00,0xae,0x2b,0xf5,0x21,0x06,0x0}}, {0x00, 0x7f, {0x124,4027,100, 0,3,0x00,0xae,0x2b,0x85,0x23,0x07,0x0}} }; static const struct opl4_region regions_67[] = { /* Sci-Fi */ {0x15, 0x31, {0x00c,6940,100, 0,3,0x00,0xc8,0x2b,0x90,0x05,0x06,0x3}}, {0x32, 0x38, {0x00d,5413,100, 0,3,0x00,0xc8,0x2b,0x90,0x05,0x06,0x3}}, {0x39, 0x47, {0x00e,4382,100, 0,3,0x00,0xc8,0x2b,0x90,0x05,0x06,0x3}}, {0x48, 0x6c, {0x00f,2846,100, 0,3,0x00,0xc8,0x2b,0x90,0x05,0x06,0x3}}, {0x15, 0x6c, {0x002,4498,100, 0,2,0x00,0xd4,0x22,0x80,0x01,0x05,0x0}} }; static const struct opl4_region regions_68[] = { /* Sitar */ {0x00, 0x7f, {0x10f,4408,100, 0,2,0x00,0xc4,0x32,0xf4,0x15,0x16,0x1}} }; static const struct opl4_region regions_69[] = { /* Banjo */ {0x15, 0x34, {0x013,5685,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}}, {0x35, 0x38, {0x014,5009,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}}, {0x39, 0x3c, {0x012,4520,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}}, {0x3d, 0x44, {0x015,3622,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}}, {0x45, 0x4c, {0x017,2661,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}}, {0x4d, 0x6d, {0x016,1632,100, 0,0,0x00,0xdc,0x38,0xf6,0x15,0x09,0x0}} }; static const struct opl4_region regions_6a[] = { /* Shamisen */ {0x15, 0x6c, {0x10e,3273,100, 0,0,0x00,0xc0,0x28,0xf7,0x76,0x08,0x0}} }; static const struct opl4_region regions_6b[] = { /* Koto */ {0x00, 0x7f, {0x0a9,4033,100, 0,0,0x00,0xc6,0x20,0xf0,0x06,0x07,0x0}} }; static const struct opl4_region regions_6c[] = { /* Kalimba */ {0x00, 0x7f, {0x137,3749,100, 0,0,0x00,0xce,0x38,0xf5,0x18,0x08,0x0}} }; static const struct opl4_region regions_6d[] = { /* Bagpipe */ {0x15, 0x39, {0x0a4,7683,100, 0,4,0x00,0xc0,0x1c,0xf0,0x00,0x09,0x0}}, {0x15, 0x39, {0x0a7,7680,100, 0,1,0x00,0xaa,0x19,0xf0,0x00,0x09,0x0}}, {0x3a, 0x6c, {0x0a8,3697,100, 0,1,0x00,0xaa,0x19,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_6e[] = { /* Fiddle */ {0x15, 0x3a, {0x105,5158,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x3b, 0x3f, {0x102,4754,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x40, 0x41, {0x106,4132,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x42, 0x44, {0x107,4033,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x45, 0x47, {0x108,3580,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x48, 0x4a, {0x10a,2957,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x4b, 0x4c, {0x10b,2724,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x4d, 0x4e, {0x10c,2530,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x4f, 0x51, {0x10d,2166,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}}, {0x52, 0x6c, {0x109,1825,100, 0,1,0x00,0xca,0x31,0xf3,0x20,0x09,0x0}} }; static const struct opl4_region regions_6f[] = { /* Shanai */ {0x15, 0x6c, {0x041,6946,100, 0,1,0x00,0xc4,0x31,0x95,0x20,0x09,0x0}} }; static const struct opl4_region regions_70[] = { /* Tinkle Bell */ {0x15, 0x73, {0x0f3,1821,100, 0,3,0x00,0xc8,0x3b,0xd6,0x25,0x25,0x0}}, {0x00, 0x7f, {0x137,5669,100, 0,3,0x00,0x66,0x3b,0xf5,0x18,0x08,0x0}} }; static const struct opl4_region regions_71[] = { /* Agogo */ {0x15, 0x74, {0x00b,2474,100, 0,0,0x00,0xd2,0x38,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_72[] = { /* Steel Drums */ {0x01, 0x7f, {0x0fe,3670,100, 0,0,0x00,0xca,0x38,0xf3,0x06,0x17,0x1}}, {0x15, 0x6c, {0x100,9602,100, 0,0,0x00,0x54,0x38,0xb0,0x05,0x16,0x1}} }; static const struct opl4_region regions_73[] = { /* Woodblock */ {0x15, 0x6c, {0x02c,2963, 50, 0,0,0x07,0xd4,0x00,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_74[] = { /* Taiko Drum */ {0x13, 0x6c, {0x03e,1194, 50, 0,0,0x00,0xaa,0x38,0xf0,0x04,0x04,0x0}} }; static const struct opl4_region regions_75[] = { /* Melodic Tom */ {0x15, 0x6c, {0x0c7,6418, 50, 0,0,0x00,0xe4,0x38,0xf0,0x05,0x01,0x0}} }; static const struct opl4_region regions_76[] = { /* Synth Drum */ {0x15, 0x6c, {0x026,3898, 50, 0,0,0x00,0xd0,0x38,0xf0,0x04,0x04,0x0}} }; static const struct opl4_region regions_77[] = { /* Reverse Cymbal */ {0x15, 0x6c, {0x031,4138, 50, 0,0,0x00,0xfe,0x38,0x3a,0xf0,0x09,0x0}} }; static const struct opl4_region regions_78[] = { /* Guitar Fret Noise */ {0x15, 0x6c, {0x138,5266,100, 0,0,0x00,0xa0,0x38,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_79[] = { /* Breath Noise */ {0x01, 0x7f, {0x125,4269,100, 0,0,0x1e,0xd0,0x38,0xf0,0x00,0x09,0x0}} }; static const struct opl4_region regions_7a[] = { /* Seashore */ {0x15, 0x6c, {0x008,2965, 20,-2,0,0x00,0xfe,0x00,0x20,0x03,0x04,0x0}}, {0x01, 0x7f, {0x037,4394, 20, 2,0,0x14,0xfe,0x00,0x20,0x04,0x05,0x0}} }; static const struct opl4_region regions_7b[] = { /* Bird Tweet */ {0x15, 0x6c, {0x009,8078, 5,-4,7,0x00,0xc2,0x0f,0x22,0x12,0x07,0x0}}, {0x15, 0x6c, {0x009,3583, 5, 4,5,0x00,0xae,0x15,0x72,0x12,0x07,0x0}} }; static const struct opl4_region regions_7c[] = { /* Telephone Ring */ {0x15, 0x6c, {0x003,3602, 10, 0,0,0x00,0xce,0x00,0xf0,0x00,0x0f,0x0}} }; static const struct opl4_region regions_7d[] = { /* Helicopter */ {0x0c, 0x7f, {0x001,2965, 10,-2,0,0x00,0xe0,0x08,0x30,0x01,0x07,0x0}}, {0x01, 0x7f, {0x037,4394, 10, 2,0,0x44,0x76,0x00,0x30,0x01,0x07,0x0}} }; static const struct opl4_region regions_7e[] = { /* Applause */ {0x15, 0x6c, {0x036,8273, 20,-6,7,0x00,0xc4,0x0f,0x70,0x01,0x05,0x0}}, {0x15, 0x6c, {0x036,8115, 5, 6,7,0x00,0xc6,0x07,0x70,0x01,0x05,0x0}} }; static const struct opl4_region regions_7f[] = { /* Gun Shot */ {0x15, 0x6c, {0x139,2858, 20, 0,0,0x00,0xbe,0x38,0xf0,0x03,0x00,0x0}} }; static const struct opl4_region regions_drums[] = { {0x18, 0x18, {0x0cb,6397,100, 3,0,0x00,0xf4,0x38,0xc9,0x1c,0x0c,0x0}}, {0x19, 0x19, {0x0c4,3714,100, 0,0,0x00,0xe0,0x00,0x97,0x19,0x09,0x0}}, {0x1a, 0x1a, {0x0c4,3519,100, 0,0,0x00,0xea,0x00,0x61,0x01,0x07,0x0}}, {0x1b, 0x1b, {0x0c4,3586,100, 0,0,0x00,0xea,0x00,0xf7,0x19,0x09,0x0}}, {0x1c, 0x1c, {0x0c4,3586,100, 0,0,0x00,0xea,0x00,0x81,0x01,0x07,0x0}}, {0x1e, 0x1e, {0x0c3,4783,100, 0,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x1f, 0x1f, {0x0d1,4042,100, 0,0,0x00,0xd6,0x00,0xf0,0x05,0x05,0x0}}, {0x20, 0x20, {0x0d2,5943,100, 0,0,0x00,0xcc,0x00,0xf0,0x00,0x09,0x0}}, {0x21, 0x21, {0x011,3842,100, 0,0,0x00,0xea,0x00,0xf0,0x16,0x06,0x0}}, {0x23, 0x23, {0x011,4098,100, 0,0,0x00,0xea,0x00,0xf0,0x16,0x06,0x0}}, {0x24, 0x24, {0x011,4370,100, 0,0,0x00,0xea,0x00,0xf0,0x00,0x06,0x0}}, {0x25, 0x25, {0x0d2,4404,100, 0,0,0x00,0xd6,0x00,0xf0,0x00,0x06,0x0}}, {0x26, 0x26, {0x0d1,4298,100, 0,0,0x00,0xd6,0x00,0xf0,0x05,0x05,0x0}}, {0x27, 0x27, {0x00a,4403,100,-1,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}}, {0x28, 0x28, {0x0d1,4554,100, 0,0,0x00,0xdc,0x00,0xf0,0x07,0x07,0x0}}, {0x29, 0x29, {0x0c8,4242,100,-4,0,0x00,0xd6,0x00,0xf6,0x16,0x06,0x0}}, {0x2a, 0x2a, {0x079,6160,100, 2,0,0x00,0xe0,0x00,0xf5,0x19,0x09,0x0}}, {0x2b, 0x2b, {0x0c8,4626,100,-3,0,0x00,0xd6,0x00,0xf6,0x16,0x06,0x0}}, {0x2c, 0x2c, {0x07b,6039,100, 2,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}}, {0x2d, 0x2d, {0x0c8,5394,100,-2,0,0x00,0xd6,0x00,0xf6,0x16,0x06,0x0}}, {0x2e, 0x2e, {0x07a,5690,100, 2,0,0x00,0xd6,0x00,0xf0,0x00,0x05,0x0}}, {0x2f, 0x2f, {0x0c7,5185,100, 2,0,0x00,0xe0,0x00,0xf6,0x17,0x07,0x0}}, {0x30, 0x30, {0x0c7,5650,100, 3,0,0x00,0xe0,0x00,0xf6,0x17,0x07,0x0}}, {0x31, 0x31, {0x031,4395,100, 2,0,0x00,0xea,0x00,0xf0,0x05,0x05,0x0}}, {0x32, 0x32, {0x0c7,6162,100, 4,0,0x00,0xe0,0x00,0xf6,0x17,0x07,0x0}}, {0x33, 0x33, {0x02e,4391,100,-2,0,0x00,0xea,0x00,0xf0,0x05,0x05,0x0}}, {0x34, 0x34, {0x07a,3009,100,-2,0,0x00,0xea,0x00,0xf2,0x15,0x05,0x0}}, {0x35, 0x35, {0x021,4522,100,-3,0,0x00,0xd6,0x00,0xf0,0x05,0x05,0x0}}, {0x36, 0x36, {0x025,5163,100, 1,0,0x00,0xe0,0x00,0xf0,0x00,0x09,0x0}}, {0x37, 0x37, {0x031,5287,100,-1,0,0x00,0xea,0x00,0xf5,0x16,0x06,0x0}}, {0x38, 0x38, {0x01d,4395,100, 2,0,0x00,0xe0,0x00,0xf0,0x00,0x09,0x0}}, {0x39, 0x39, {0x031,4647,100,-2,0,0x00,0xea,0x00,0xf4,0x16,0x06,0x0}}, {0x3a, 0x3a, {0x09d,4426,100,-4,0,0x00,0xe0,0x00,0xf4,0x17,0x07,0x0}}, {0x3b, 0x3b, {0x02e,4659,100,-2,0,0x00,0xea,0x00,0xf0,0x06,0x06,0x0}}, {0x3c, 0x3c, {0x01c,4769,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x3d, 0x3d, {0x01c,4611,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x3e, 0x3e, {0x01e,4402,100,-3,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x3f, 0x3f, {0x01f,4387,100,-3,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x40, 0x40, {0x01f,3983,100,-2,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x41, 0x41, {0x09c,4526,100, 2,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x42, 0x42, {0x09c,4016,100, 2,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x43, 0x43, {0x00b,4739,100,-4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x44, 0x44, {0x00b,4179,100,-4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x45, 0x45, {0x02f,4787,100,-4,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}}, {0x46, 0x46, {0x030,4665,100,-4,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}}, {0x47, 0x47, {0x144,4519,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x0b,0x0}}, {0x48, 0x48, {0x144,4111,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x0b,0x0}}, {0x49, 0x49, {0x024,6408,100, 3,0,0x00,0xe0,0x00,0xf0,0x00,0x09,0x0}}, {0x4a, 0x4a, {0x024,4144,100, 3,0,0x00,0xcc,0x00,0xf0,0x00,0x09,0x0}}, {0x4b, 0x4b, {0x020,4001,100, 2,0,0x00,0xe0,0x00,0xf0,0x00,0x09,0x0}}, {0x4c, 0x4c, {0x02c,4402,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x4d, 0x4d, {0x02c,3612,100, 4,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x4e, 0x4e, {0x022,4129,100,-2,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x4f, 0x4f, {0x023,4147,100,-2,0,0x00,0xea,0x00,0xf0,0x00,0x09,0x0}}, {0x50, 0x50, {0x032,4412,100,-4,0,0x00,0xd6,0x00,0xf0,0x08,0x09,0x0}}, {0x51, 0x51, {0x032,4385,100,-4,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}}, {0x52, 0x52, {0x02f,5935,100,-1,0,0x00,0xd6,0x00,0xf0,0x00,0x09,0x0}} }; #define REGION(num) { ARRAY_SIZE(regions ## num), regions ## num } const struct opl4_region_ptr snd_yrw801_regions[0x81] = { REGION(_00), REGION(_01), REGION(_02), REGION(_03), REGION(_04), REGION(_05), REGION(_06), REGION(_07), REGION(_08), REGION(_09), REGION(_0a), REGION(_0b), REGION(_0c), REGION(_0d), REGION(_0e), REGION(_0f), REGION(_10), REGION(_11), REGION(_12), REGION(_13), REGION(_14), REGION(_15), REGION(_16), REGION(_17), REGION(_18), REGION(_19), REGION(_1a), REGION(_1b), REGION(_1c), REGION(_1d), REGION(_1e), REGION(_1f), REGION(_20), REGION(_21), REGION(_22), REGION(_23), REGION(_24), REGION(_25), REGION(_26), REGION(_27), REGION(_28), REGION(_29), REGION(_2a), REGION(_2b), REGION(_2c), REGION(_2d), REGION(_2e), REGION(_2f), REGION(_30), REGION(_31), REGION(_32), REGION(_33), REGION(_34), REGION(_35), REGION(_36), REGION(_37), REGION(_38), REGION(_39), REGION(_3a), REGION(_3b), REGION(_3c), REGION(_3d), REGION(_3e), REGION(_3f), REGION(_40), REGION(_41), REGION(_42), REGION(_43), REGION(_44), REGION(_45), REGION(_46), REGION(_47), REGION(_48), REGION(_49), REGION(_4a), REGION(_4b), REGION(_4c), REGION(_4d), REGION(_4e), REGION(_4f), REGION(_50), REGION(_51), REGION(_52), REGION(_53), REGION(_54), REGION(_55), REGION(_56), REGION(_57), REGION(_58), REGION(_59), REGION(_5a), REGION(_5b), REGION(_5c), REGION(_5d), REGION(_5e), REGION(_5f), REGION(_60), REGION(_61), REGION(_62), REGION(_63), REGION(_64), REGION(_65), REGION(_66), REGION(_67), REGION(_68), REGION(_69), REGION(_6a), REGION(_6b), REGION(_6c), REGION(_6d), REGION(_6e), REGION(_6f), REGION(_70), REGION(_71), REGION(_72), REGION(_73), REGION(_74), REGION(_75), REGION(_76), REGION(_77), REGION(_78), REGION(_79), REGION(_7a), REGION(_7b), REGION(_7c), REGION(_7d), REGION(_7e), REGION(_7f), REGION(_drums) };
linux-master
sound/drivers/opl4/yrw801.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * OPL4 mixer functions * Copyright (c) 2003 by Clemens Ladisch <[email protected]> */ #include "opl4_local.h" #include <sound/control.h> static int snd_opl4_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 7; return 0; } static int snd_opl4_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol); unsigned long flags; u8 reg = kcontrol->private_value; u8 value; spin_lock_irqsave(&opl4->reg_lock, flags); value = snd_opl4_read(opl4, reg); spin_unlock_irqrestore(&opl4->reg_lock, flags); ucontrol->value.integer.value[0] = 7 - (value & 7); ucontrol->value.integer.value[1] = 7 - ((value >> 3) & 7); return 0; } static int snd_opl4_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol); unsigned long flags; u8 reg = kcontrol->private_value; u8 value, old_value; value = (7 - (ucontrol->value.integer.value[0] & 7)) | ((7 - (ucontrol->value.integer.value[1] & 7)) << 3); spin_lock_irqsave(&opl4->reg_lock, flags); old_value = snd_opl4_read(opl4, reg); snd_opl4_write(opl4, reg, value); spin_unlock_irqrestore(&opl4->reg_lock, flags); return value != old_value; } static const struct snd_kcontrol_new snd_opl4_controls[] = { { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "FM Playback Volume", .info = snd_opl4_ctl_info, .get = snd_opl4_ctl_get, .put = snd_opl4_ctl_put, .private_value = OPL4_REG_MIX_CONTROL_FM }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Wavetable Playback Volume", .info = snd_opl4_ctl_info, .get = snd_opl4_ctl_get, .put = snd_opl4_ctl_put, .private_value = OPL4_REG_MIX_CONTROL_PCM } }; int snd_opl4_create_mixer(struct snd_opl4 *opl4) { struct snd_card *card = opl4->card; int i, err; strcat(card->mixername, ",OPL4"); for (i = 0; i < 2; ++i) { err = snd_ctl_add(card, snd_ctl_new1(&snd_opl4_controls[i], opl4)); if (err < 0) return err; } return 0; }
linux-master
sound/drivers/opl4/opl4_mixer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * IEC958 stuff * * Copyright (c) 2002 by Takashi Iwai <[email protected]> */ #include <linux/delay.h> #include <sound/core.h> #include <sound/vx_core.h> #include "vx_cmd.h" /* * vx_modify_board_clock - tell the board that its clock has been modified * @sync: DSP needs to resynchronize its FIFO */ static int vx_modify_board_clock(struct vx_core *chip, int sync) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_MODIFY_CLOCK); /* Ask the DSP to resynchronize its FIFO. */ if (sync) rmh.Cmd[0] |= CMD_MODIFY_CLOCK_S_BIT; return vx_send_msg(chip, &rmh); } /* * vx_modify_board_inputs - resync audio inputs */ static int vx_modify_board_inputs(struct vx_core *chip) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_RESYNC_AUDIO_INPUTS); rmh.Cmd[0] |= 1 << 0; /* reference: AUDIO 0 */ return vx_send_msg(chip, &rmh); } /* * vx_read_one_cbit - read one bit from UER config * @index: the bit index * returns 0 or 1. */ static int vx_read_one_cbit(struct vx_core *chip, int index) { int val; mutex_lock(&chip->lock); if (chip->type >= VX_TYPE_VXPOCKET) { vx_outb(chip, CSUER, 1); /* read */ vx_outb(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK); val = (vx_inb(chip, RUER) >> 7) & 0x01; } else { vx_outl(chip, CSUER, 1); /* read */ vx_outl(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK); val = (vx_inl(chip, RUER) >> 7) & 0x01; } mutex_unlock(&chip->lock); return val; } /* * vx_write_one_cbit - write one bit to UER config * @index: the bit index * @val: bit value, 0 or 1 */ static void vx_write_one_cbit(struct vx_core *chip, int index, int val) { val = !!val; /* 0 or 1 */ mutex_lock(&chip->lock); if (vx_is_pcmcia(chip)) { vx_outb(chip, CSUER, 0); /* write */ vx_outb(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK)); } else { vx_outl(chip, CSUER, 0); /* write */ vx_outl(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK)); } mutex_unlock(&chip->lock); } /* * vx_read_uer_status - read the current UER status * @mode: pointer to store the UER mode, VX_UER_MODE_XXX * * returns the frequency of UER, or 0 if not sync, * or a negative error code. */ static int vx_read_uer_status(struct vx_core *chip, unsigned int *mode) { int val, freq; /* Default values */ freq = 0; /* Read UER status */ if (vx_is_pcmcia(chip)) val = vx_inb(chip, CSUER); else val = vx_inl(chip, CSUER); if (val < 0) return val; /* If clock is present, read frequency */ if (val & VX_SUER_CLOCK_PRESENT_MASK) { switch (val & VX_SUER_FREQ_MASK) { case VX_SUER_FREQ_32KHz_MASK: freq = 32000; break; case VX_SUER_FREQ_44KHz_MASK: freq = 44100; break; case VX_SUER_FREQ_48KHz_MASK: freq = 48000; break; } } if (val & VX_SUER_DATA_PRESENT_MASK) /* bit 0 corresponds to consumer/professional bit */ *mode = vx_read_one_cbit(chip, 0) ? VX_UER_MODE_PROFESSIONAL : VX_UER_MODE_CONSUMER; else *mode = VX_UER_MODE_NOT_PRESENT; return freq; } /* * compute the sample clock value from frequency * * The formula is as follows: * * HexFreq = (dword) ((double) ((double) 28224000 / (double) Frequency)) * switch ( HexFreq & 0x00000F00 ) * case 0x00000100: ; * case 0x00000200: * case 0x00000300: HexFreq -= 0x00000201 ; * case 0x00000400: * case 0x00000500: * case 0x00000600: * case 0x00000700: HexFreq = (dword) (((double) 28224000 / (double) (Frequency*2)) - 1) * default : HexFreq = (dword) ((double) 28224000 / (double) (Frequency*4)) - 0x000001FF */ static int vx_calc_clock_from_freq(struct vx_core *chip, int freq) { int hexfreq; if (snd_BUG_ON(freq <= 0)) return 0; hexfreq = (28224000 * 10) / freq; hexfreq = (hexfreq + 5) / 10; /* max freq = 55125 Hz */ if (snd_BUG_ON(hexfreq <= 0x00000200)) return 0; if (hexfreq <= 0x03ff) return hexfreq - 0x00000201; if (hexfreq <= 0x07ff) return (hexfreq / 2) - 1; if (hexfreq <= 0x0fff) return (hexfreq / 4) + 0x000001ff; return 0x5fe; /* min freq = 6893 Hz */ } /* * vx_change_clock_source - change the clock source * @source: the new source */ static void vx_change_clock_source(struct vx_core *chip, int source) { /* we mute DAC to prevent clicks */ vx_toggle_dac_mute(chip, 1); mutex_lock(&chip->lock); chip->ops->set_clock_source(chip, source); chip->clock_source = source; mutex_unlock(&chip->lock); /* unmute */ vx_toggle_dac_mute(chip, 0); } /* * set the internal clock */ void vx_set_internal_clock(struct vx_core *chip, unsigned int freq) { int clock; /* Get real clock value */ clock = vx_calc_clock_from_freq(chip, freq); snd_printdd(KERN_DEBUG "set internal clock to 0x%x from freq %d\n", clock, freq); mutex_lock(&chip->lock); if (vx_is_pcmcia(chip)) { vx_outb(chip, HIFREQ, (clock >> 8) & 0x0f); vx_outb(chip, LOFREQ, clock & 0xff); } else { vx_outl(chip, HIFREQ, (clock >> 8) & 0x0f); vx_outl(chip, LOFREQ, clock & 0xff); } mutex_unlock(&chip->lock); } /* * set the iec958 status bits * @bits: 32-bit status bits */ void vx_set_iec958_status(struct vx_core *chip, unsigned int bits) { int i; if (chip->chip_status & VX_STAT_IS_STALE) return; for (i = 0; i < 32; i++) vx_write_one_cbit(chip, i, bits & (1 << i)); } /* * vx_set_clock - change the clock and audio source if necessary */ int vx_set_clock(struct vx_core *chip, unsigned int freq) { int src_changed = 0; if (chip->chip_status & VX_STAT_IS_STALE) return 0; /* change the audio source if possible */ vx_sync_audio_source(chip); if (chip->clock_mode == VX_CLOCK_MODE_EXTERNAL || (chip->clock_mode == VX_CLOCK_MODE_AUTO && chip->audio_source == VX_AUDIO_SRC_DIGITAL)) { if (chip->clock_source != UER_SYNC) { vx_change_clock_source(chip, UER_SYNC); mdelay(6); src_changed = 1; } } else if (chip->clock_mode == VX_CLOCK_MODE_INTERNAL || (chip->clock_mode == VX_CLOCK_MODE_AUTO && chip->audio_source != VX_AUDIO_SRC_DIGITAL)) { if (chip->clock_source != INTERNAL_QUARTZ) { vx_change_clock_source(chip, INTERNAL_QUARTZ); src_changed = 1; } if (chip->freq == freq) return 0; vx_set_internal_clock(chip, freq); if (src_changed) vx_modify_board_inputs(chip); } if (chip->freq == freq) return 0; chip->freq = freq; vx_modify_board_clock(chip, 1); return 0; } /* * vx_change_frequency - called from interrupt handler */ int vx_change_frequency(struct vx_core *chip) { int freq; if (chip->chip_status & VX_STAT_IS_STALE) return 0; if (chip->clock_source == INTERNAL_QUARTZ) return 0; /* * Read the real UER board frequency */ freq = vx_read_uer_status(chip, &chip->uer_detected); if (freq < 0) return freq; /* * The frequency computed by the DSP is good and * is different from the previous computed. */ if (freq == 48000 || freq == 44100 || freq == 32000) chip->freq_detected = freq; return 0; }
linux-master
sound/drivers/vx/vx_uer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * Hardware core part * * Copyright (c) 2002 by Takashi Iwai <[email protected]> */ #include <linux/delay.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/device.h> #include <linux/firmware.h> #include <linux/module.h> #include <linux/io.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/asoundef.h> #include <sound/info.h> #include <sound/vx_core.h> #include "vx_cmd.h" MODULE_AUTHOR("Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("Common routines for Digigram VX drivers"); MODULE_LICENSE("GPL"); /* * vx_check_reg_bit - wait for the specified bit is set/reset on a register * @reg: register to check * @mask: bit mask * @bit: resultant bit to be checked * @time: time-out of loop in msec * * returns zero if a bit matches, or a negative error code. */ int snd_vx_check_reg_bit(struct vx_core *chip, int reg, int mask, int bit, int time) { unsigned long end_time = jiffies + (time * HZ + 999) / 1000; static const char * const reg_names[VX_REG_MAX] = { "ICR", "CVR", "ISR", "IVR", "RXH", "RXM", "RXL", "DMA", "CDSP", "RFREQ", "RUER/V2", "DATA", "MEMIRQ", "ACQ", "BIT0", "BIT1", "MIC0", "MIC1", "MIC2", "MIC3", "INTCSR", "CNTRL", "GPIOC", "LOFREQ", "HIFREQ", "CSUER", "RUER" }; do { if ((snd_vx_inb(chip, reg) & mask) == bit) return 0; //msleep(10); } while (time_after_eq(end_time, jiffies)); snd_printd(KERN_DEBUG "vx_check_reg_bit: timeout, reg=%s, mask=0x%x, val=0x%x\n", reg_names[reg], mask, snd_vx_inb(chip, reg)); return -EIO; } EXPORT_SYMBOL(snd_vx_check_reg_bit); /* * vx_send_irq_dsp - set command irq bit * @num: the requested IRQ type, IRQ_XXX * * this triggers the specified IRQ request * returns 0 if successful, or a negative error code. * */ static int vx_send_irq_dsp(struct vx_core *chip, int num) { int nirq; /* wait for Hc = 0 */ if (snd_vx_check_reg_bit(chip, VX_CVR, CVR_HC, 0, 200) < 0) return -EIO; nirq = num; if (vx_has_new_dsp(chip)) nirq += VXP_IRQ_OFFSET; vx_outb(chip, CVR, (nirq >> 1) | CVR_HC); return 0; } /* * vx_reset_chk - reset CHK bit on ISR * * returns 0 if successful, or a negative error code. */ static int vx_reset_chk(struct vx_core *chip) { /* Reset irq CHK */ if (vx_send_irq_dsp(chip, IRQ_RESET_CHK) < 0) return -EIO; /* Wait until CHK = 0 */ if (vx_check_isr(chip, ISR_CHK, 0, 200) < 0) return -EIO; return 0; } /* * vx_transfer_end - terminate message transfer * @cmd: IRQ message to send (IRQ_MESS_XXX_END) * * returns 0 if successful, or a negative error code. * the error code can be VX-specific, retrieved via vx_get_error(). * NB: call with mutex held! */ static int vx_transfer_end(struct vx_core *chip, int cmd) { int err; err = vx_reset_chk(chip); if (err < 0) return err; /* irq MESS_READ/WRITE_END */ err = vx_send_irq_dsp(chip, cmd); if (err < 0) return err; /* Wait CHK = 1 */ err = vx_wait_isr_bit(chip, ISR_CHK); if (err < 0) return err; /* If error, Read RX */ err = vx_inb(chip, ISR); if (err & ISR_ERR) { err = vx_wait_for_rx_full(chip); if (err < 0) { snd_printd(KERN_DEBUG "transfer_end: error in rx_full\n"); return err; } err = vx_inb(chip, RXH) << 16; err |= vx_inb(chip, RXM) << 8; err |= vx_inb(chip, RXL); snd_printd(KERN_DEBUG "transfer_end: error = 0x%x\n", err); return -(VX_ERR_MASK | err); } return 0; } /* * vx_read_status - return the status rmh * @rmh: rmh record to store the status * * returns 0 if successful, or a negative error code. * the error code can be VX-specific, retrieved via vx_get_error(). * NB: call with mutex held! */ static int vx_read_status(struct vx_core *chip, struct vx_rmh *rmh) { int i, err, val, size; /* no read necessary? */ if (rmh->DspStat == RMH_SSIZE_FIXED && rmh->LgStat == 0) return 0; /* Wait for RX full (with timeout protection) * The first word of status is in RX */ err = vx_wait_for_rx_full(chip); if (err < 0) return err; /* Read RX */ val = vx_inb(chip, RXH) << 16; val |= vx_inb(chip, RXM) << 8; val |= vx_inb(chip, RXL); /* If status given by DSP, let's decode its size */ switch (rmh->DspStat) { case RMH_SSIZE_ARG: size = val & 0xff; rmh->Stat[0] = val & 0xffff00; rmh->LgStat = size + 1; break; case RMH_SSIZE_MASK: /* Let's count the arg numbers from a mask */ rmh->Stat[0] = val; size = 0; while (val) { if (val & 0x01) size++; val >>= 1; } rmh->LgStat = size + 1; break; default: /* else retrieve the status length given by the driver */ size = rmh->LgStat; rmh->Stat[0] = val; /* Val is the status 1st word */ size--; /* hence adjust remaining length */ break; } if (size < 1) return 0; if (snd_BUG_ON(size >= SIZE_MAX_STATUS)) return -EINVAL; for (i = 1; i <= size; i++) { /* trigger an irq MESS_WRITE_NEXT */ err = vx_send_irq_dsp(chip, IRQ_MESS_WRITE_NEXT); if (err < 0) return err; /* Wait for RX full (with timeout protection) */ err = vx_wait_for_rx_full(chip); if (err < 0) return err; rmh->Stat[i] = vx_inb(chip, RXH) << 16; rmh->Stat[i] |= vx_inb(chip, RXM) << 8; rmh->Stat[i] |= vx_inb(chip, RXL); } return vx_transfer_end(chip, IRQ_MESS_WRITE_END); } #define MASK_MORE_THAN_1_WORD_COMMAND 0x00008000 #define MASK_1_WORD_COMMAND 0x00ff7fff /* * vx_send_msg_nolock - send a DSP message and read back the status * @rmh: the rmh record to send and receive * * returns 0 if successful, or a negative error code. * the error code can be VX-specific, retrieved via vx_get_error(). * * this function doesn't call mutex lock at all. */ int vx_send_msg_nolock(struct vx_core *chip, struct vx_rmh *rmh) { int i, err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; err = vx_reset_chk(chip); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: vx_reset_chk error\n"); return err; } #if 0 printk(KERN_DEBUG "rmh: cmd = 0x%06x, length = %d, stype = %d\n", rmh->Cmd[0], rmh->LgCmd, rmh->DspStat); if (rmh->LgCmd > 1) { printk(KERN_DEBUG " "); for (i = 1; i < rmh->LgCmd; i++) printk(KERN_CONT "0x%06x ", rmh->Cmd[i]); printk(KERN_CONT "\n"); } #endif /* Check bit M is set according to length of the command */ if (rmh->LgCmd > 1) rmh->Cmd[0] |= MASK_MORE_THAN_1_WORD_COMMAND; else rmh->Cmd[0] &= MASK_1_WORD_COMMAND; /* Wait for TX empty */ err = vx_wait_isr_bit(chip, ISR_TX_EMPTY); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: wait tx empty error\n"); return err; } /* Write Cmd[0] */ vx_outb(chip, TXH, (rmh->Cmd[0] >> 16) & 0xff); vx_outb(chip, TXM, (rmh->Cmd[0] >> 8) & 0xff); vx_outb(chip, TXL, rmh->Cmd[0] & 0xff); /* Trigger irq MESSAGE */ err = vx_send_irq_dsp(chip, IRQ_MESSAGE); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: send IRQ_MESSAGE error\n"); return err; } /* Wait for CHK = 1 */ err = vx_wait_isr_bit(chip, ISR_CHK); if (err < 0) return err; /* If error, get error value from RX */ if (vx_inb(chip, ISR) & ISR_ERR) { err = vx_wait_for_rx_full(chip); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: rx_full read error\n"); return err; } err = vx_inb(chip, RXH) << 16; err |= vx_inb(chip, RXM) << 8; err |= vx_inb(chip, RXL); snd_printd(KERN_DEBUG "msg got error = 0x%x at cmd[0]\n", err); err = -(VX_ERR_MASK | err); return err; } /* Send the other words */ if (rmh->LgCmd > 1) { for (i = 1; i < rmh->LgCmd; i++) { /* Wait for TX ready */ err = vx_wait_isr_bit(chip, ISR_TX_READY); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: tx_ready error\n"); return err; } /* Write Cmd[i] */ vx_outb(chip, TXH, (rmh->Cmd[i] >> 16) & 0xff); vx_outb(chip, TXM, (rmh->Cmd[i] >> 8) & 0xff); vx_outb(chip, TXL, rmh->Cmd[i] & 0xff); /* Trigger irq MESS_READ_NEXT */ err = vx_send_irq_dsp(chip, IRQ_MESS_READ_NEXT); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: IRQ_READ_NEXT error\n"); return err; } } /* Wait for TX empty */ err = vx_wait_isr_bit(chip, ISR_TX_READY); if (err < 0) { snd_printd(KERN_DEBUG "vx_send_msg: TX_READY error\n"); return err; } /* End of transfer */ err = vx_transfer_end(chip, IRQ_MESS_READ_END); if (err < 0) return err; } return vx_read_status(chip, rmh); } /* * vx_send_msg - send a DSP message with mutex * @rmh: the rmh record to send and receive * * returns 0 if successful, or a negative error code. * see vx_send_msg_nolock(). */ int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh) { int err; mutex_lock(&chip->lock); err = vx_send_msg_nolock(chip, rmh); mutex_unlock(&chip->lock); return err; } /* * vx_send_rih_nolock - send an RIH to xilinx * @cmd: the command to send * * returns 0 if successful, or a negative error code. * the error code can be VX-specific, retrieved via vx_get_error(). * * this function doesn't call mutex at all. * * unlike RMH, no command is sent to DSP. */ int vx_send_rih_nolock(struct vx_core *chip, int cmd) { int err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; #if 0 printk(KERN_DEBUG "send_rih: cmd = 0x%x\n", cmd); #endif err = vx_reset_chk(chip); if (err < 0) return err; /* send the IRQ */ err = vx_send_irq_dsp(chip, cmd); if (err < 0) return err; /* Wait CHK = 1 */ err = vx_wait_isr_bit(chip, ISR_CHK); if (err < 0) return err; /* If error, read RX */ if (vx_inb(chip, ISR) & ISR_ERR) { err = vx_wait_for_rx_full(chip); if (err < 0) return err; err = vx_inb(chip, RXH) << 16; err |= vx_inb(chip, RXM) << 8; err |= vx_inb(chip, RXL); return -(VX_ERR_MASK | err); } return 0; } /* * vx_send_rih - send an RIH with mutex * @cmd: the command to send * * see vx_send_rih_nolock(). */ int vx_send_rih(struct vx_core *chip, int cmd) { int err; mutex_lock(&chip->lock); err = vx_send_rih_nolock(chip, cmd); mutex_unlock(&chip->lock); return err; } #define END_OF_RESET_WAIT_TIME 500 /* us */ /** * snd_vx_load_boot_image - boot up the xilinx interface * @chip: VX core instance * @boot: the boot record to load */ int snd_vx_load_boot_image(struct vx_core *chip, const struct firmware *boot) { unsigned int i; int no_fillup = vx_has_new_dsp(chip); /* check the length of boot image */ if (boot->size <= 0) return -EINVAL; if (boot->size % 3) return -EINVAL; #if 0 { /* more strict check */ unsigned int c = ((u32)boot->data[0] << 16) | ((u32)boot->data[1] << 8) | boot->data[2]; if (boot->size != (c + 2) * 3) return -EINVAL; } #endif /* reset dsp */ vx_reset_dsp(chip); udelay(END_OF_RESET_WAIT_TIME); /* another wait? */ /* download boot strap */ for (i = 0; i < 0x600; i += 3) { if (i >= boot->size) { if (no_fillup) break; if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) { snd_printk(KERN_ERR "dsp boot failed at %d\n", i); return -EIO; } vx_outb(chip, TXH, 0); vx_outb(chip, TXM, 0); vx_outb(chip, TXL, 0); } else { const unsigned char *image = boot->data + i; if (vx_wait_isr_bit(chip, ISR_TX_EMPTY) < 0) { snd_printk(KERN_ERR "dsp boot failed at %d\n", i); return -EIO; } vx_outb(chip, TXH, image[0]); vx_outb(chip, TXM, image[1]); vx_outb(chip, TXL, image[2]); } } return 0; } EXPORT_SYMBOL(snd_vx_load_boot_image); /* * vx_test_irq_src - query the source of interrupts * * called from irq handler only */ static int vx_test_irq_src(struct vx_core *chip, unsigned int *ret) { int err; vx_init_rmh(&chip->irq_rmh, CMD_TEST_IT); mutex_lock(&chip->lock); err = vx_send_msg_nolock(chip, &chip->irq_rmh); if (err < 0) *ret = 0; else *ret = chip->irq_rmh.Stat[0]; mutex_unlock(&chip->lock); return err; } /* * snd_vx_threaded_irq_handler - threaded irq handler */ irqreturn_t snd_vx_threaded_irq_handler(int irq, void *dev) { struct vx_core *chip = dev; unsigned int events; if (chip->chip_status & VX_STAT_IS_STALE) return IRQ_HANDLED; if (vx_test_irq_src(chip, &events) < 0) return IRQ_HANDLED; #if 0 if (events & 0x000800) printk(KERN_ERR "DSP Stream underrun ! IRQ events = 0x%x\n", events); #endif // printk(KERN_DEBUG "IRQ events = 0x%x\n", events); /* We must prevent any application using this DSP * and block any further request until the application * either unregisters or reloads the DSP */ if (events & FATAL_DSP_ERROR) { snd_printk(KERN_ERR "vx_core: fatal DSP error!!\n"); return IRQ_HANDLED; } /* The start on time code conditions are filled (ie the time code * received by the board is equal to one of those given to it). */ if (events & TIME_CODE_EVENT_PENDING) { ; /* so far, nothing to do yet */ } /* The frequency has changed on the board (UER mode). */ if (events & FREQUENCY_CHANGE_EVENT_PENDING) vx_change_frequency(chip); /* update the pcm streams */ vx_pcm_update_intr(chip, events); return IRQ_HANDLED; } EXPORT_SYMBOL(snd_vx_threaded_irq_handler); /** * snd_vx_irq_handler - interrupt handler * @irq: irq number * @dev: VX core instance */ irqreturn_t snd_vx_irq_handler(int irq, void *dev) { struct vx_core *chip = dev; if (! (chip->chip_status & VX_STAT_CHIP_INIT) || (chip->chip_status & VX_STAT_IS_STALE)) return IRQ_NONE; if (! vx_test_and_ack(chip)) return IRQ_WAKE_THREAD; return IRQ_NONE; } EXPORT_SYMBOL(snd_vx_irq_handler); /* */ static void vx_reset_board(struct vx_core *chip, int cold_reset) { if (snd_BUG_ON(!chip->ops->reset_board)) return; /* current source, later sync'ed with target */ chip->audio_source = VX_AUDIO_SRC_LINE; if (cold_reset) { chip->audio_source_target = chip->audio_source; chip->clock_source = INTERNAL_QUARTZ; chip->clock_mode = VX_CLOCK_MODE_AUTO; chip->freq = 48000; chip->uer_detected = VX_UER_MODE_NOT_PRESENT; chip->uer_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; } chip->ops->reset_board(chip, cold_reset); vx_reset_codec(chip, cold_reset); vx_set_internal_clock(chip, chip->freq); /* Reset the DSP */ vx_reset_dsp(chip); if (vx_is_pcmcia(chip)) { /* Acknowledge any pending IRQ and reset the MEMIRQ flag. */ vx_test_and_ack(chip); vx_validate_irq(chip, 1); } /* init CBits */ vx_set_iec958_status(chip, chip->uer_bits); } /* * proc interface */ static void vx_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct vx_core *chip = entry->private_data; static const char * const audio_src_vxp[] = { "Line", "Mic", "Digital" }; static const char * const audio_src_vx2[] = { "Analog", "Analog", "Digital" }; static const char * const clock_mode[] = { "Auto", "Internal", "External" }; static const char * const clock_src[] = { "Internal", "External" }; static const char * const uer_type[] = { "Consumer", "Professional", "Not Present" }; snd_iprintf(buffer, "%s\n", chip->card->longname); snd_iprintf(buffer, "Xilinx Firmware: %s\n", (chip->chip_status & VX_STAT_XILINX_LOADED) ? "Loaded" : "No"); snd_iprintf(buffer, "Device Initialized: %s\n", (chip->chip_status & VX_STAT_DEVICE_INIT) ? "Yes" : "No"); snd_iprintf(buffer, "DSP audio info:"); if (chip->audio_info & VX_AUDIO_INFO_REAL_TIME) snd_iprintf(buffer, " realtime"); if (chip->audio_info & VX_AUDIO_INFO_OFFLINE) snd_iprintf(buffer, " offline"); if (chip->audio_info & VX_AUDIO_INFO_MPEG1) snd_iprintf(buffer, " mpeg1"); if (chip->audio_info & VX_AUDIO_INFO_MPEG2) snd_iprintf(buffer, " mpeg2"); if (chip->audio_info & VX_AUDIO_INFO_LINEAR_8) snd_iprintf(buffer, " linear8"); if (chip->audio_info & VX_AUDIO_INFO_LINEAR_16) snd_iprintf(buffer, " linear16"); if (chip->audio_info & VX_AUDIO_INFO_LINEAR_24) snd_iprintf(buffer, " linear24"); snd_iprintf(buffer, "\n"); snd_iprintf(buffer, "Input Source: %s\n", vx_is_pcmcia(chip) ? audio_src_vxp[chip->audio_source] : audio_src_vx2[chip->audio_source]); snd_iprintf(buffer, "Clock Mode: %s\n", clock_mode[chip->clock_mode]); snd_iprintf(buffer, "Clock Source: %s\n", clock_src[chip->clock_source]); snd_iprintf(buffer, "Frequency: %d\n", chip->freq); snd_iprintf(buffer, "Detected Frequency: %d\n", chip->freq_detected); snd_iprintf(buffer, "Detected UER type: %s\n", uer_type[chip->uer_detected]); snd_iprintf(buffer, "Min/Max/Cur IBL: %d/%d/%d (granularity=%d)\n", chip->ibl.min_size, chip->ibl.max_size, chip->ibl.size, chip->ibl.granularity); } static void vx_proc_init(struct vx_core *chip) { snd_card_ro_proc_new(chip->card, "vx-status", chip, vx_proc_read); } /** * snd_vx_dsp_boot - load the DSP boot * @chip: VX core instance * @boot: firmware data */ int snd_vx_dsp_boot(struct vx_core *chip, const struct firmware *boot) { int err; int cold_reset = !(chip->chip_status & VX_STAT_DEVICE_INIT); vx_reset_board(chip, cold_reset); vx_validate_irq(chip, 0); err = snd_vx_load_boot_image(chip, boot); if (err < 0) return err; msleep(10); return 0; } EXPORT_SYMBOL(snd_vx_dsp_boot); /** * snd_vx_dsp_load - load the DSP image * @chip: VX core instance * @dsp: firmware data */ int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp) { unsigned int i; int err; unsigned int csum = 0; const unsigned char *image, *cptr; if (dsp->size % 3) return -EINVAL; vx_toggle_dac_mute(chip, 1); /* Transfert data buffer from PC to DSP */ for (i = 0; i < dsp->size; i += 3) { image = dsp->data + i; /* Wait DSP ready for a new read */ err = vx_wait_isr_bit(chip, ISR_TX_EMPTY); if (err < 0) { printk(KERN_ERR "dsp loading error at position %d\n", i); return err; } cptr = image; csum ^= *cptr; csum = (csum >> 24) | (csum << 8); vx_outb(chip, TXH, *cptr++); csum ^= *cptr; csum = (csum >> 24) | (csum << 8); vx_outb(chip, TXM, *cptr++); csum ^= *cptr; csum = (csum >> 24) | (csum << 8); vx_outb(chip, TXL, *cptr++); } snd_printdd(KERN_DEBUG "checksum = 0x%08x\n", csum); msleep(200); err = vx_wait_isr_bit(chip, ISR_CHK); if (err < 0) return err; vx_toggle_dac_mute(chip, 0); vx_test_and_ack(chip); vx_validate_irq(chip, 1); return 0; } EXPORT_SYMBOL(snd_vx_dsp_load); #ifdef CONFIG_PM /* * suspend */ int snd_vx_suspend(struct vx_core *chip) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); chip->chip_status |= VX_STAT_IN_SUSPEND; return 0; } EXPORT_SYMBOL(snd_vx_suspend); /* * resume */ int snd_vx_resume(struct vx_core *chip) { int i, err; chip->chip_status &= ~VX_STAT_CHIP_INIT; for (i = 0; i < 4; i++) { if (! chip->firmware[i]) continue; err = chip->ops->load_dsp(chip, i, chip->firmware[i]); if (err < 0) { snd_printk(KERN_ERR "vx: firmware resume error at DSP %d\n", i); return -EIO; } } chip->chip_status |= VX_STAT_CHIP_INIT; chip->chip_status &= ~VX_STAT_IN_SUSPEND; snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); return 0; } EXPORT_SYMBOL(snd_vx_resume); #endif static void snd_vx_release(struct device *dev, void *data) { snd_vx_free_firmware(data); } /** * snd_vx_create - constructor for struct vx_core * @card: card instance * @hw: hardware specific record * @ops: VX ops pointer * @extra_size: extra byte size to allocate appending to chip * * this function allocates the instance and prepare for the hardware * initialization. * * The object is managed via devres, and will be automatically released. * * return the instance pointer if successful, NULL in error. */ struct vx_core *snd_vx_create(struct snd_card *card, const struct snd_vx_hardware *hw, const struct snd_vx_ops *ops, int extra_size) { struct vx_core *chip; if (snd_BUG_ON(!card || !hw || !ops)) return NULL; chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size, GFP_KERNEL); if (!chip) return NULL; mutex_init(&chip->lock); chip->irq = -1; chip->hw = hw; chip->type = hw->type; chip->ops = ops; mutex_init(&chip->mixer_mutex); chip->card = card; card->private_data = chip; strcpy(card->driver, hw->name); sprintf(card->shortname, "Digigram %s", hw->name); vx_proc_init(chip); return chip; } EXPORT_SYMBOL(snd_vx_create);
linux-master
sound/drivers/vx/vx_core.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * DSP firmware management * * Copyright (c) 2002 by Takashi Iwai <[email protected]> */ #include <linux/device.h> #include <linux/firmware.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/module.h> #include <sound/core.h> #include <sound/hwdep.h> #include <sound/vx_core.h> MODULE_FIRMWARE("vx/bx_1_vxp.b56"); MODULE_FIRMWARE("vx/bx_1_vp4.b56"); MODULE_FIRMWARE("vx/x1_1_vx2.xlx"); MODULE_FIRMWARE("vx/x1_2_v22.xlx"); MODULE_FIRMWARE("vx/x1_1_vxp.xlx"); MODULE_FIRMWARE("vx/x1_1_vp4.xlx"); MODULE_FIRMWARE("vx/bd56002.boot"); MODULE_FIRMWARE("vx/bd563v2.boot"); MODULE_FIRMWARE("vx/bd563s3.boot"); MODULE_FIRMWARE("vx/l_1_vx2.d56"); MODULE_FIRMWARE("vx/l_1_v22.d56"); MODULE_FIRMWARE("vx/l_1_vxp.d56"); MODULE_FIRMWARE("vx/l_1_vp4.d56"); int snd_vx_setup_firmware(struct vx_core *chip) { static const char * const fw_files[VX_TYPE_NUMS][4] = { [VX_TYPE_BOARD] = { NULL, "x1_1_vx2.xlx", "bd56002.boot", "l_1_vx2.d56", }, [VX_TYPE_V2] = { NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56", }, [VX_TYPE_MIC] = { NULL, "x1_2_v22.xlx", "bd563v2.boot", "l_1_v22.d56", }, [VX_TYPE_VXPOCKET] = { "bx_1_vxp.b56", "x1_1_vxp.xlx", "bd563s3.boot", "l_1_vxp.d56" }, [VX_TYPE_VXP440] = { "bx_1_vp4.b56", "x1_1_vp4.xlx", "bd563s3.boot", "l_1_vp4.d56" }, }; int i, err; for (i = 0; i < 4; i++) { char path[32]; const struct firmware *fw; if (! fw_files[chip->type][i]) continue; sprintf(path, "vx/%s", fw_files[chip->type][i]); if (request_firmware(&fw, path, chip->dev)) { snd_printk(KERN_ERR "vx: can't load firmware %s\n", path); return -ENOENT; } err = chip->ops->load_dsp(chip, i, fw); if (err < 0) { release_firmware(fw); return err; } if (i == 1) chip->chip_status |= VX_STAT_XILINX_LOADED; #ifdef CONFIG_PM chip->firmware[i] = fw; #else release_firmware(fw); #endif } /* ok, we reached to the last one */ /* create the devices if not built yet */ err = snd_vx_pcm_new(chip); if (err < 0) return err; err = snd_vx_mixer_new(chip); if (err < 0) return err; if (chip->ops->add_controls) { err = chip->ops->add_controls(chip); if (err < 0) return err; } chip->chip_status |= VX_STAT_DEVICE_INIT; chip->chip_status |= VX_STAT_CHIP_INIT; return snd_card_register(chip->card); } /* exported */ void snd_vx_free_firmware(struct vx_core *chip) { #ifdef CONFIG_PM int i; for (i = 0; i < 4; i++) release_firmware(chip->firmware[i]); #endif } EXPORT_SYMBOL(snd_vx_setup_firmware); EXPORT_SYMBOL(snd_vx_free_firmware);
linux-master
sound/drivers/vx/vx_hwdep.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * DSP commands * * Copyright (c) 2002 by Takashi Iwai <[email protected]> */ #include <sound/core.h> #include <sound/pcm.h> #include <sound/vx_core.h> #include "vx_cmd.h" /* * Array of DSP commands */ static const struct vx_cmd_info vx_dsp_cmds[] = { [CMD_VERSION] = { 0x010000, 2, RMH_SSIZE_FIXED, 1 }, [CMD_SUPPORTED] = { 0x020000, 1, RMH_SSIZE_FIXED, 2 }, [CMD_TEST_IT] = { 0x040000, 1, RMH_SSIZE_FIXED, 1 }, [CMD_SEND_IRQA] = { 0x070001, 1, RMH_SSIZE_FIXED, 0 }, [CMD_IBL] = { 0x080000, 1, RMH_SSIZE_FIXED, 4 }, [CMD_ASYNC] = { 0x0A0000, 1, RMH_SSIZE_ARG, 0 }, [CMD_RES_PIPE] = { 0x400000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_FREE_PIPE] = { 0x410000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_CONF_PIPE] = { 0x42A101, 2, RMH_SSIZE_FIXED, 0 }, [CMD_ABORT_CONF_PIPE] = { 0x42A100, 2, RMH_SSIZE_FIXED, 0 }, [CMD_PARAM_OUTPUT_PIPE] = { 0x43A000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_STOP_PIPE] = { 0x470004, 1, RMH_SSIZE_FIXED, 0 }, [CMD_PIPE_STATE] = { 0x480000, 1, RMH_SSIZE_FIXED, 1 }, [CMD_PIPE_SPL_COUNT] = { 0x49A000, 2, RMH_SSIZE_FIXED, 2 }, [CMD_CAN_START_PIPE] = { 0x4b0000, 1, RMH_SSIZE_FIXED, 1 }, [CMD_SIZE_HBUFFER] = { 0x4C0000, 1, RMH_SSIZE_FIXED, 1 }, [CMD_START_STREAM] = { 0x80A000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_START_ONE_STREAM] = { 0x800000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_PAUSE_STREAM] = { 0x81A000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_PAUSE_ONE_STREAM] = { 0x810000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_STREAM_OUT_LEVEL_ADJUST] = { 0x828000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_STOP_STREAM] = { 0x830000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_FORMAT_STREAM_OUT] = { 0x868000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_FORMAT_STREAM_IN] = { 0x878800, 1, RMH_SSIZE_FIXED, 0 }, [CMD_GET_STREAM_STATE] = { 0x890001, 2, RMH_SSIZE_FIXED, 1 }, [CMD_DROP_BYTES_AWAY] = { 0x8A8000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_GET_REMAINING_BYTES] = { 0x8D0800, 1, RMH_SSIZE_FIXED, 2 }, [CMD_CONNECT_AUDIO] = { 0xC10000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_AUDIO_LEVEL_ADJUST] = { 0xC2A000, 3, RMH_SSIZE_FIXED, 0 }, [CMD_AUDIO_VU_PIC_METER] = { 0xC3A003, 2, RMH_SSIZE_FIXED, 1 }, [CMD_GET_AUDIO_LEVELS] = { 0xC4A000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_GET_NOTIFY_EVENT] = { 0x4D0000, 1, RMH_SSIZE_ARG, 0 }, [CMD_INFO_NOTIFIED] = { 0x0B0000, 1, RMH_SSIZE_FIXED, 2 }, [CMD_ACCESS_IO_FCT] = { 0x098000, 1, RMH_SSIZE_ARG, 0 }, [CMD_STATUS_R_BUFFERS] = { 0x440000, 1, RMH_SSIZE_ARG, 0 }, [CMD_UPDATE_R_BUFFERS] = { 0x848000, 4, RMH_SSIZE_FIXED, 0 }, [CMD_LOAD_EFFECT_CONTEXT] = { 0x0c8000, 3, RMH_SSIZE_FIXED, 1 }, [CMD_EFFECT_ONE_PIPE] = { 0x458000, 0, RMH_SSIZE_FIXED, 0 }, [CMD_MODIFY_CLOCK] = { 0x0d0000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_STREAM1_OUT_SET_N_LEVELS] ={ 0x858000, 3, RMH_SSIZE_FIXED, 0 }, [CMD_PURGE_STREAM_DCMDS] = { 0x8b8000, 3, RMH_SSIZE_FIXED, 0 }, [CMD_NOTIFY_PIPE_TIME] = { 0x4e0000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_LOAD_EFFECT_CONTEXT_PACKET] = { 0x0c8000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_RELIC_R_BUFFER] = { 0x8e0800, 1, RMH_SSIZE_FIXED, 1 }, [CMD_RESYNC_AUDIO_INPUTS] = { 0x0e0000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_NOTIFY_STREAM_TIME] = { 0x8f0000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_STREAM_SAMPLE_COUNT] = { 0x900000, 1, RMH_SSIZE_FIXED, 2 }, [CMD_CONFIG_TIME_CODE] = { 0x050000, 2, RMH_SSIZE_FIXED, 0 }, [CMD_GET_TIME_CODE] = { 0x060000, 1, RMH_SSIZE_FIXED, 5 }, [CMD_MANAGE_SIGNAL] = { 0x0f0000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_PARAMETER_STREAM_OUT] = { 0x91A000, 3, RMH_SSIZE_FIXED, 0 }, [CMD_READ_BOARD_FREQ] = { 0x030000, 1, RMH_SSIZE_FIXED, 2 }, [CMD_GET_STREAM_LEVELS] = { 0x8c0000, 1, RMH_SSIZE_FIXED, 3 }, [CMD_PURGE_PIPE_DCMDS] = { 0x4f8000, 3, RMH_SSIZE_FIXED, 0 }, // [CMD_SET_STREAM_OUT_EFFECTS] = { 0x888000, 34, RMH_SSIZE_FIXED, 0 }, // [CMD_GET_STREAM_OUT_EFFECTS] = { 0x928000, 2, RMH_SSIZE_FIXED, 32 }, [CMD_CONNECT_MONITORING] = { 0xC00000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_STREAM2_OUT_SET_N_LEVELS] = { 0x938000, 3, RMH_SSIZE_FIXED, 0 }, [CMD_CANCEL_R_BUFFERS] = { 0x948000, 4, RMH_SSIZE_FIXED, 0 }, [CMD_NOTIFY_END_OF_BUFFER] = { 0x950000, 1, RMH_SSIZE_FIXED, 0 }, [CMD_GET_STREAM_VU_METER] = { 0x95A000, 2, RMH_SSIZE_ARG, 0 }, }; /** * vx_init_rmh - initialize the RMH instance * @rmh: the rmh pointer to be initialized * @cmd: the rmh command to be set */ void vx_init_rmh(struct vx_rmh *rmh, unsigned int cmd) { if (snd_BUG_ON(cmd >= CMD_LAST_INDEX)) return; rmh->LgCmd = vx_dsp_cmds[cmd].length; rmh->LgStat = vx_dsp_cmds[cmd].st_length; rmh->DspStat = vx_dsp_cmds[cmd].st_type; rmh->Cmd[0] = vx_dsp_cmds[cmd].opcode; }
linux-master
sound/drivers/vx/vx_cmd.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * Common mixer part * * Copyright (c) 2002 by Takashi Iwai <[email protected]> */ #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h> #include <sound/vx_core.h> #include "vx_cmd.h" /* * write a codec data (24bit) */ static void vx_write_codec_reg(struct vx_core *chip, int codec, unsigned int data) { if (snd_BUG_ON(!chip->ops->write_codec)) return; if (chip->chip_status & VX_STAT_IS_STALE) return; mutex_lock(&chip->lock); chip->ops->write_codec(chip, codec, data); mutex_unlock(&chip->lock); } /* * Data type used to access the Codec */ union vx_codec_data { u32 l; #ifdef SNDRV_BIG_ENDIAN struct w { u16 h; u16 l; } w; struct b { u8 hh; u8 mh; u8 ml; u8 ll; } b; #else /* LITTLE_ENDIAN */ struct w { u16 l; u16 h; } w; struct b { u8 ll; u8 ml; u8 mh; u8 hh; } b; #endif }; #define SET_CDC_DATA_SEL(di,s) ((di).b.mh = (u8) (s)) #define SET_CDC_DATA_REG(di,r) ((di).b.ml = (u8) (r)) #define SET_CDC_DATA_VAL(di,d) ((di).b.ll = (u8) (d)) #define SET_CDC_DATA_INIT(di) ((di).l = 0L, SET_CDC_DATA_SEL(di,XX_CODEC_SELECTOR)) /* * set up codec register and write the value * @codec: the codec id, 0 or 1 * @reg: register index * @val: data value */ static void vx_set_codec_reg(struct vx_core *chip, int codec, int reg, int val) { union vx_codec_data data; /* DAC control register */ SET_CDC_DATA_INIT(data); SET_CDC_DATA_REG(data, reg); SET_CDC_DATA_VAL(data, val); vx_write_codec_reg(chip, codec, data.l); } /* * vx_set_analog_output_level - set the output attenuation level * @codec: the output codec, 0 or 1. (1 for VXP440 only) * @left: left output level, 0 = mute * @right: right output level */ static void vx_set_analog_output_level(struct vx_core *chip, int codec, int left, int right) { left = chip->hw->output_level_max - left; right = chip->hw->output_level_max - right; if (chip->ops->akm_write) { chip->ops->akm_write(chip, XX_CODEC_LEVEL_LEFT_REGISTER, left); chip->ops->akm_write(chip, XX_CODEC_LEVEL_RIGHT_REGISTER, right); } else { /* convert to attenuation level: 0 = 0dB (max), 0xe3 = -113.5 dB (min) */ vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_LEFT_REGISTER, left); vx_set_codec_reg(chip, codec, XX_CODEC_LEVEL_RIGHT_REGISTER, right); } } /* * vx_toggle_dac_mute - mute/unmute DAC * @mute: 0 = unmute, 1 = mute */ #define DAC_ATTEN_MIN 0x08 #define DAC_ATTEN_MAX 0x38 void vx_toggle_dac_mute(struct vx_core *chip, int mute) { unsigned int i; for (i = 0; i < chip->hw->num_codecs; i++) { if (chip->ops->akm_write) chip->ops->akm_write(chip, XX_CODEC_DAC_CONTROL_REGISTER, mute); /* XXX */ else vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, mute ? DAC_ATTEN_MAX : DAC_ATTEN_MIN); } } /* * vx_reset_codec - reset and initialize the codecs */ void vx_reset_codec(struct vx_core *chip, int cold_reset) { unsigned int i; int port = chip->type >= VX_TYPE_VXPOCKET ? 0x75 : 0x65; chip->ops->reset_codec(chip); /* AKM codecs should be initialized in reset_codec callback */ if (! chip->ops->akm_write) { /* initialize old codecs */ for (i = 0; i < chip->hw->num_codecs; i++) { /* DAC control register (change level when zero crossing + mute) */ vx_set_codec_reg(chip, i, XX_CODEC_DAC_CONTROL_REGISTER, DAC_ATTEN_MAX); /* ADC control register */ vx_set_codec_reg(chip, i, XX_CODEC_ADC_CONTROL_REGISTER, 0x00); /* Port mode register */ vx_set_codec_reg(chip, i, XX_CODEC_PORT_MODE_REGISTER, port); /* Clock control register */ vx_set_codec_reg(chip, i, XX_CODEC_CLOCK_CONTROL_REGISTER, 0x00); } } /* mute analog output */ for (i = 0; i < chip->hw->num_codecs; i++) { chip->output_level[i][0] = 0; chip->output_level[i][1] = 0; vx_set_analog_output_level(chip, i, 0, 0); } } /* * change the audio input source * @src: the target source (VX_AUDIO_SRC_XXX) */ static void vx_change_audio_source(struct vx_core *chip, int src) { if (chip->chip_status & VX_STAT_IS_STALE) return; mutex_lock(&chip->lock); chip->ops->change_audio_source(chip, src); mutex_unlock(&chip->lock); } /* * change the audio source if necessary and possible * returns 1 if the source is actually changed. */ int vx_sync_audio_source(struct vx_core *chip) { if (chip->audio_source_target == chip->audio_source || chip->pcm_running) return 0; vx_change_audio_source(chip, chip->audio_source_target); chip->audio_source = chip->audio_source_target; return 1; } /* * audio level, mute, monitoring */ struct vx_audio_level { unsigned int has_level: 1; unsigned int has_monitor_level: 1; unsigned int has_mute: 1; unsigned int has_monitor_mute: 1; unsigned int mute; unsigned int monitor_mute; short level; short monitor_level; }; static int vx_adjust_audio_level(struct vx_core *chip, int audio, int capture, struct vx_audio_level *info) { struct vx_rmh rmh; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; vx_init_rmh(&rmh, CMD_AUDIO_LEVEL_ADJUST); if (capture) rmh.Cmd[0] |= COMMAND_RECORD_MASK; /* Add Audio IO mask */ rmh.Cmd[1] = 1 << audio; rmh.Cmd[2] = 0; if (info->has_level) { rmh.Cmd[0] |= VALID_AUDIO_IO_DIGITAL_LEVEL; rmh.Cmd[2] |= info->level; } if (info->has_monitor_level) { rmh.Cmd[0] |= VALID_AUDIO_IO_MONITORING_LEVEL; rmh.Cmd[2] |= ((unsigned int)info->monitor_level << 10); } if (info->has_mute) { rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_LEVEL; if (info->mute) rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_LEVEL; } if (info->has_monitor_mute) { /* validate flag for M2 at least to unmute it */ rmh.Cmd[0] |= VALID_AUDIO_IO_MUTE_MONITORING_1 | VALID_AUDIO_IO_MUTE_MONITORING_2; if (info->monitor_mute) rmh.Cmd[2] |= AUDIO_IO_HAS_MUTE_MONITORING_1; } return vx_send_msg(chip, &rmh); } #if 0 // not used static int vx_read_audio_level(struct vx_core *chip, int audio, int capture, struct vx_audio_level *info) { int err; struct vx_rmh rmh; memset(info, 0, sizeof(*info)); vx_init_rmh(&rmh, CMD_GET_AUDIO_LEVELS); if (capture) rmh.Cmd[0] |= COMMAND_RECORD_MASK; /* Add Audio IO mask */ rmh.Cmd[1] = 1 << audio; err = vx_send_msg(chip, &rmh); if (err < 0) return err; info.level = rmh.Stat[0] & MASK_DSP_WORD_LEVEL; info.monitor_level = (rmh.Stat[0] >> 10) & MASK_DSP_WORD_LEVEL; info.mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_LEVEL) ? 1 : 0; info.monitor_mute = (rmh.Stat[i] & AUDIO_IO_HAS_MUTE_MONITORING_1) ? 1 : 0; return 0; } #endif // not used /* * set the monitoring level and mute state of the given audio * no more static, because must be called from vx_pcm to demute monitoring */ int vx_set_monitor_level(struct vx_core *chip, int audio, int level, int active) { struct vx_audio_level info; memset(&info, 0, sizeof(info)); info.has_monitor_level = 1; info.monitor_level = level; info.has_monitor_mute = 1; info.monitor_mute = !active; chip->audio_monitor[audio] = level; chip->audio_monitor_active[audio] = active; return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */ } /* * set the mute status of the given audio */ static int vx_set_audio_switch(struct vx_core *chip, int audio, int active) { struct vx_audio_level info; memset(&info, 0, sizeof(info)); info.has_mute = 1; info.mute = !active; chip->audio_active[audio] = active; return vx_adjust_audio_level(chip, audio, 0, &info); /* playback only */ } /* * set the mute status of the given audio */ static int vx_set_audio_gain(struct vx_core *chip, int audio, int capture, int level) { struct vx_audio_level info; memset(&info, 0, sizeof(info)); info.has_level = 1; info.level = level; chip->audio_gain[capture][audio] = level; return vx_adjust_audio_level(chip, audio, capture, &info); } /* * reset all audio levels */ static void vx_reset_audio_levels(struct vx_core *chip) { unsigned int i, c; struct vx_audio_level info; memset(chip->audio_gain, 0, sizeof(chip->audio_gain)); memset(chip->audio_active, 0, sizeof(chip->audio_active)); memset(chip->audio_monitor, 0, sizeof(chip->audio_monitor)); memset(chip->audio_monitor_active, 0, sizeof(chip->audio_monitor_active)); for (c = 0; c < 2; c++) { for (i = 0; i < chip->hw->num_ins * 2; i++) { memset(&info, 0, sizeof(info)); if (c == 0) { info.has_monitor_level = 1; info.has_mute = 1; info.has_monitor_mute = 1; } info.has_level = 1; info.level = CVAL_0DB; /* default: 0dB */ vx_adjust_audio_level(chip, i, c, &info); chip->audio_gain[c][i] = CVAL_0DB; chip->audio_monitor[i] = CVAL_0DB; } } } /* * VU, peak meter record */ #define VU_METER_CHANNELS 2 struct vx_vu_meter { int saturated; int vu_level; int peak_level; }; /* * get the VU and peak meter values * @audio: the audio index * @capture: 0 = playback, 1 = capture operation * @info: the array of vx_vu_meter records (size = 2). */ static int vx_get_audio_vu_meter(struct vx_core *chip, int audio, int capture, struct vx_vu_meter *info) { struct vx_rmh rmh; int i, err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; vx_init_rmh(&rmh, CMD_AUDIO_VU_PIC_METER); rmh.LgStat += 2 * VU_METER_CHANNELS; if (capture) rmh.Cmd[0] |= COMMAND_RECORD_MASK; /* Add Audio IO mask */ rmh.Cmd[1] = 0; for (i = 0; i < VU_METER_CHANNELS; i++) rmh.Cmd[1] |= 1 << (audio + i); err = vx_send_msg(chip, &rmh); if (err < 0) return err; /* Read response */ for (i = 0; i < 2 * VU_METER_CHANNELS; i +=2) { info->saturated = (rmh.Stat[0] & (1 << (audio + i))) ? 1 : 0; info->vu_level = rmh.Stat[i + 1]; info->peak_level = rmh.Stat[i + 2]; info++; } return 0; } /* * control API entries */ /* * output level control */ static int vx_output_level_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = chip->hw->output_level_max; return 0; } static int vx_output_level_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int codec = kcontrol->id.index; mutex_lock(&chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->output_level[codec][0]; ucontrol->value.integer.value[1] = chip->output_level[codec][1]; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int codec = kcontrol->id.index; unsigned int val[2], vmax; vmax = chip->hw->output_level_max; val[0] = ucontrol->value.integer.value[0]; val[1] = ucontrol->value.integer.value[1]; if (val[0] > vmax || val[1] > vmax) return -EINVAL; mutex_lock(&chip->mixer_mutex); if (val[0] != chip->output_level[codec][0] || val[1] != chip->output_level[codec][1]) { vx_set_analog_output_level(chip, codec, val[0], val[1]); chip->output_level[codec][0] = val[0]; chip->output_level[codec][1] = val[1]; mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static const struct snd_kcontrol_new vx_control_output_level = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), .name = "Master Playback Volume", .info = vx_output_level_info, .get = vx_output_level_get, .put = vx_output_level_put, /* tlv will be filled later */ }; /* * audio source select */ static int vx_audio_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts_mic[3] = { "Digital", "Line", "Mic" }; static const char * const texts_vx2[2] = { "Digital", "Analog" }; struct vx_core *chip = snd_kcontrol_chip(kcontrol); if (chip->type >= VX_TYPE_VXPOCKET) return snd_ctl_enum_info(uinfo, 1, 3, texts_mic); else return snd_ctl_enum_info(uinfo, 1, 2, texts_vx2); } static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = chip->audio_source_target; return 0; } static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); if (chip->type >= VX_TYPE_VXPOCKET) { if (ucontrol->value.enumerated.item[0] > 2) return -EINVAL; } else { if (ucontrol->value.enumerated.item[0] > 1) return -EINVAL; } mutex_lock(&chip->mixer_mutex); if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { chip->audio_source_target = ucontrol->value.enumerated.item[0]; vx_sync_audio_source(chip); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static const struct snd_kcontrol_new vx_control_audio_src = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Capture Source", .info = vx_audio_src_info, .get = vx_audio_src_get, .put = vx_audio_src_put, }; /* * clock mode selection */ static int vx_clock_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { static const char * const texts[3] = { "Auto", "Internal", "External" }; return snd_ctl_enum_info(uinfo, 1, 3, texts); } static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = chip->clock_mode; return 0; } static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); if (ucontrol->value.enumerated.item[0] > 2) return -EINVAL; mutex_lock(&chip->mixer_mutex); if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { chip->clock_mode = ucontrol->value.enumerated.item[0]; vx_set_clock(chip, chip->freq); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static const struct snd_kcontrol_new vx_control_clock_mode = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Clock Mode", .info = vx_clock_mode_info, .get = vx_clock_mode_get, .put = vx_clock_mode_put, }; /* * Audio Gain */ static int vx_audio_gain_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = CVAL_MAX; return 0; } static int vx_audio_gain_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; int capture = (kcontrol->private_value >> 8) & 1; mutex_lock(&chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio]; ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1]; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; int capture = (kcontrol->private_value >> 8) & 1; unsigned int val[2]; val[0] = ucontrol->value.integer.value[0]; val[1] = ucontrol->value.integer.value[1]; if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) return -EINVAL; mutex_lock(&chip->mixer_mutex); if (val[0] != chip->audio_gain[capture][audio] || val[1] != chip->audio_gain[capture][audio+1]) { vx_set_audio_gain(chip, audio, capture, val[0]); vx_set_audio_gain(chip, audio+1, capture, val[1]); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_audio_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; mutex_lock(&chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->audio_monitor[audio]; ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1]; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; unsigned int val[2]; val[0] = ucontrol->value.integer.value[0]; val[1] = ucontrol->value.integer.value[1]; if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) return -EINVAL; mutex_lock(&chip->mixer_mutex); if (val[0] != chip->audio_monitor[audio] || val[1] != chip->audio_monitor[audio+1]) { vx_set_monitor_level(chip, audio, val[0], chip->audio_monitor_active[audio]); vx_set_monitor_level(chip, audio+1, val[1], chip->audio_monitor_active[audio+1]); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } #define vx_audio_sw_info snd_ctl_boolean_stereo_info static int vx_audio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; mutex_lock(&chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->audio_active[audio]; ucontrol->value.integer.value[1] = chip->audio_active[audio+1]; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; mutex_lock(&chip->mixer_mutex); if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { vx_set_audio_switch(chip, audio, !!ucontrol->value.integer.value[0]); vx_set_audio_switch(chip, audio+1, !!ucontrol->value.integer.value[1]); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_monitor_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; mutex_lock(&chip->mixer_mutex); ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio]; ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1]; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); int audio = kcontrol->private_value & 0xff; mutex_lock(&chip->mixer_mutex); if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], !!ucontrol->value.integer.value[0]); vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], !!ucontrol->value.integer.value[1]); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static const DECLARE_TLV_DB_SCALE(db_scale_audio_gain, -10975, 25, 0); static const struct snd_kcontrol_new vx_control_audio_gain = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), /* name will be filled later */ .info = vx_audio_gain_info, .get = vx_audio_gain_get, .put = vx_audio_gain_put, .tlv = { .p = db_scale_audio_gain }, }; static const struct snd_kcontrol_new vx_control_output_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "PCM Playback Switch", .info = vx_audio_sw_info, .get = vx_audio_sw_get, .put = vx_audio_sw_put }; static const struct snd_kcontrol_new vx_control_monitor_gain = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Monitoring Volume", .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ), .info = vx_audio_gain_info, /* shared */ .get = vx_audio_monitor_get, .put = vx_audio_monitor_put, .tlv = { .p = db_scale_audio_gain }, }; static const struct snd_kcontrol_new vx_control_monitor_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Monitoring Switch", .info = vx_audio_sw_info, /* shared */ .get = vx_monitor_sw_get, .put = vx_monitor_sw_put }; /* * IEC958 status bits */ static int vx_iec958_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; uinfo->count = 1; return 0; } static int vx_iec958_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); mutex_lock(&chip->mixer_mutex); ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff; ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff; ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff; ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff; mutex_unlock(&chip->mixer_mutex); return 0; } static int vx_iec958_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.iec958.status[0] = 0xff; ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[2] = 0xff; ucontrol->value.iec958.status[3] = 0xff; return 0; } static int vx_iec958_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); unsigned int val; val = (ucontrol->value.iec958.status[0] << 0) | (ucontrol->value.iec958.status[1] << 8) | (ucontrol->value.iec958.status[2] << 16) | (ucontrol->value.iec958.status[3] << 24); mutex_lock(&chip->mixer_mutex); if (chip->uer_bits != val) { chip->uer_bits = val; vx_set_iec958_status(chip, val); mutex_unlock(&chip->mixer_mutex); return 1; } mutex_unlock(&chip->mixer_mutex); return 0; } static const struct snd_kcontrol_new vx_control_iec958_mask = { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK), .info = vx_iec958_info, /* shared */ .get = vx_iec958_mask_get, }; static const struct snd_kcontrol_new vx_control_iec958 = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), .info = vx_iec958_info, .get = vx_iec958_get, .put = vx_iec958_put }; /* * VU meter */ #define METER_MAX 0xff #define METER_SHIFT 16 static int vx_vu_meter_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = METER_MAX; return 0; } static int vx_vu_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); struct vx_vu_meter meter[2]; int audio = kcontrol->private_value & 0xff; int capture = (kcontrol->private_value >> 8) & 1; vx_get_audio_vu_meter(chip, audio, capture, meter); ucontrol->value.integer.value[0] = meter[0].vu_level >> METER_SHIFT; ucontrol->value.integer.value[1] = meter[1].vu_level >> METER_SHIFT; return 0; } static int vx_peak_meter_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); struct vx_vu_meter meter[2]; int audio = kcontrol->private_value & 0xff; int capture = (kcontrol->private_value >> 8) & 1; vx_get_audio_vu_meter(chip, audio, capture, meter); ucontrol->value.integer.value[0] = meter[0].peak_level >> METER_SHIFT; ucontrol->value.integer.value[1] = meter[1].peak_level >> METER_SHIFT; return 0; } #define vx_saturation_info snd_ctl_boolean_stereo_info static int vx_saturation_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct vx_core *chip = snd_kcontrol_chip(kcontrol); struct vx_vu_meter meter[2]; int audio = kcontrol->private_value & 0xff; vx_get_audio_vu_meter(chip, audio, 1, meter); /* capture only */ ucontrol->value.integer.value[0] = meter[0].saturated; ucontrol->value.integer.value[1] = meter[1].saturated; return 0; } static const struct snd_kcontrol_new vx_control_vu_meter = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, /* name will be filled later */ .info = vx_vu_meter_info, .get = vx_vu_meter_get, }; static const struct snd_kcontrol_new vx_control_peak_meter = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, /* name will be filled later */ .info = vx_vu_meter_info, /* shared */ .get = vx_peak_meter_get, }; static const struct snd_kcontrol_new vx_control_saturation = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Input Saturation", .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, .info = vx_saturation_info, .get = vx_saturation_get, }; /* * */ int snd_vx_mixer_new(struct vx_core *chip) { unsigned int i, c; int err; struct snd_kcontrol_new temp; struct snd_card *card = chip->card; char name[32]; strcpy(card->mixername, card->driver); /* output level controls */ for (i = 0; i < chip->hw->num_outs; i++) { temp = vx_control_output_level; temp.index = i; temp.tlv.p = chip->hw->output_level_db_scale; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } /* PCM volumes, switches, monitoring */ for (i = 0; i < chip->hw->num_outs; i++) { int val = i * 2; temp = vx_control_audio_gain; temp.index = i; temp.name = "PCM Playback Volume"; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; temp = vx_control_output_switch; temp.index = i; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; temp = vx_control_monitor_gain; temp.index = i; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; temp = vx_control_monitor_switch; temp.index = i; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } for (i = 0; i < chip->hw->num_outs; i++) { temp = vx_control_audio_gain; temp.index = i; temp.name = "PCM Capture Volume"; temp.private_value = (i * 2) | (1 << 8); err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } /* Audio source */ err = snd_ctl_add(card, snd_ctl_new1(&vx_control_audio_src, chip)); if (err < 0) return err; /* clock mode */ err = snd_ctl_add(card, snd_ctl_new1(&vx_control_clock_mode, chip)); if (err < 0) return err; /* IEC958 controls */ err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958_mask, chip)); if (err < 0) return err; err = snd_ctl_add(card, snd_ctl_new1(&vx_control_iec958, chip)); if (err < 0) return err; /* VU, peak, saturation meters */ for (c = 0; c < 2; c++) { static const char * const dir[2] = { "Output", "Input" }; for (i = 0; i < chip->hw->num_ins; i++) { int val = (i * 2) | (c << 8); if (c == 1) { temp = vx_control_saturation; temp.index = i; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } sprintf(name, "%s VU Meter", dir[c]); temp = vx_control_vu_meter; temp.index = i; temp.name = name; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; sprintf(name, "%s Peak Meter", dir[c]); temp = vx_control_peak_meter; temp.index = i; temp.name = name; temp.private_value = val; err = snd_ctl_add(card, snd_ctl_new1(&temp, chip)); if (err < 0) return err; } } vx_reset_audio_levels(chip); return 0; }
linux-master
sound/drivers/vx/vx_mixer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for Digigram VX soundcards * * PCM part * * Copyright (c) 2002,2003 by Takashi Iwai <[email protected]> * * STRATEGY * for playback, we send series of "chunks", which size is equal with the * IBL size, typically 126 samples. at each end of chunk, the end-of-buffer * interrupt is notified, and the interrupt handler will feed the next chunk. * * the current position is calculated from the sample count RMH. * pipe->transferred is the counter of data which has been already transferred. * if this counter reaches to the period size, snd_pcm_period_elapsed() will * be issued. * * for capture, the situation is much easier. * to get a low latency response, we'll check the capture streams at each * interrupt (capture stream has no EOB notification). if the pending * data is accumulated to the period size, snd_pcm_period_elapsed() is * called and the pointer is updated. * * the current point of read buffer is kept in pipe->hw_ptr. note that * this is in bytes. * * TODO * - linked trigger for full-duplex mode. * - scheduled action on the stream. */ #include <linux/slab.h> #include <linux/delay.h> #include <sound/core.h> #include <sound/asoundef.h> #include <sound/pcm.h> #include <sound/vx_core.h> #include "vx_cmd.h" /* * read three pending pcm bytes via inb() */ static void vx_pcm_read_per_bytes(struct vx_core *chip, struct snd_pcm_runtime *runtime, struct vx_pipe *pipe) { int offset = pipe->hw_ptr; unsigned char *buf = (unsigned char *)(runtime->dma_area + offset); *buf++ = vx_inb(chip, RXH); if (++offset >= pipe->buffer_bytes) { offset = 0; buf = (unsigned char *)runtime->dma_area; } *buf++ = vx_inb(chip, RXM); if (++offset >= pipe->buffer_bytes) { offset = 0; buf = (unsigned char *)runtime->dma_area; } *buf++ = vx_inb(chip, RXL); if (++offset >= pipe->buffer_bytes) { offset = 0; } pipe->hw_ptr = offset; } /* * vx_set_pcx_time - convert from the PC time to the RMH status time. * @pc_time: the pointer for the PC-time to set * @dsp_time: the pointer for RMH status time array */ static void vx_set_pcx_time(struct vx_core *chip, pcx_time_t *pc_time, unsigned int *dsp_time) { dsp_time[0] = (unsigned int)((*pc_time) >> 24) & PCX_TIME_HI_MASK; dsp_time[1] = (unsigned int)(*pc_time) & MASK_DSP_WORD; } /* * vx_set_differed_time - set the differed time if specified * @rmh: the rmh record to modify * @pipe: the pipe to be checked * * if the pipe is programmed with the differed time, set the DSP time * on the rmh and changes its command length. * * returns the increase of the command length. */ static int vx_set_differed_time(struct vx_core *chip, struct vx_rmh *rmh, struct vx_pipe *pipe) { /* Update The length added to the RMH command by the timestamp */ if (! (pipe->differed_type & DC_DIFFERED_DELAY)) return 0; /* Set the T bit */ rmh->Cmd[0] |= DSP_DIFFERED_COMMAND_MASK; /* Time stamp is the 1st following parameter */ vx_set_pcx_time(chip, &pipe->pcx_time, &rmh->Cmd[1]); /* Add the flags to a notified differed command */ if (pipe->differed_type & DC_NOTIFY_DELAY) rmh->Cmd[1] |= NOTIFY_MASK_TIME_HIGH ; /* Add the flags to a multiple differed command */ if (pipe->differed_type & DC_MULTIPLE_DELAY) rmh->Cmd[1] |= MULTIPLE_MASK_TIME_HIGH; /* Add the flags to a stream-time differed command */ if (pipe->differed_type & DC_STREAM_TIME_DELAY) rmh->Cmd[1] |= STREAM_MASK_TIME_HIGH; rmh->LgCmd += 2; return 2; } /* * vx_set_stream_format - send the stream format command * @pipe: the affected pipe * @data: format bitmask */ static int vx_set_stream_format(struct vx_core *chip, struct vx_pipe *pipe, unsigned int data) { struct vx_rmh rmh; vx_init_rmh(&rmh, pipe->is_capture ? CMD_FORMAT_STREAM_IN : CMD_FORMAT_STREAM_OUT); rmh.Cmd[0] |= pipe->number << FIELD_SIZE; /* Command might be longer since we may have to add a timestamp */ vx_set_differed_time(chip, &rmh, pipe); rmh.Cmd[rmh.LgCmd] = (data & 0xFFFFFF00) >> 8; rmh.Cmd[rmh.LgCmd + 1] = (data & 0xFF) << 16 /*| (datal & 0xFFFF00) >> 8*/; rmh.LgCmd += 2; return vx_send_msg(chip, &rmh); } /* * vx_set_format - set the format of a pipe * @pipe: the affected pipe * @runtime: pcm runtime instance to be referred * * returns 0 if successful, or a negative error code. */ static int vx_set_format(struct vx_core *chip, struct vx_pipe *pipe, struct snd_pcm_runtime *runtime) { unsigned int header = HEADER_FMT_BASE; if (runtime->channels == 1) header |= HEADER_FMT_MONO; if (snd_pcm_format_little_endian(runtime->format)) header |= HEADER_FMT_INTEL; if (runtime->rate < 32000 && runtime->rate > 11025) header |= HEADER_FMT_UPTO32; else if (runtime->rate <= 11025) header |= HEADER_FMT_UPTO11; switch (snd_pcm_format_physical_width(runtime->format)) { // case 8: break; case 16: header |= HEADER_FMT_16BITS; break; case 24: header |= HEADER_FMT_24BITS; break; default : snd_BUG(); return -EINVAL; } return vx_set_stream_format(chip, pipe, header); } /* * set / query the IBL size */ static int vx_set_ibl(struct vx_core *chip, struct vx_ibl_info *info) { int err; struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_IBL); rmh.Cmd[0] |= info->size & 0x03ffff; err = vx_send_msg(chip, &rmh); if (err < 0) return err; info->size = rmh.Stat[0]; info->max_size = rmh.Stat[1]; info->min_size = rmh.Stat[2]; info->granularity = rmh.Stat[3]; snd_printdd(KERN_DEBUG "vx_set_ibl: size = %d, max = %d, min = %d, gran = %d\n", info->size, info->max_size, info->min_size, info->granularity); return 0; } /* * vx_get_pipe_state - get the state of a pipe * @pipe: the pipe to be checked * @state: the pointer for the returned state * * checks the state of a given pipe, and stores the state (1 = running, * 0 = paused) on the given pointer. * * called from trigger callback only */ static int vx_get_pipe_state(struct vx_core *chip, struct vx_pipe *pipe, int *state) { int err; struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_PIPE_STATE); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); err = vx_send_msg(chip, &rmh); if (! err) *state = (rmh.Stat[0] & (1 << pipe->number)) ? 1 : 0; return err; } /* * vx_query_hbuffer_size - query available h-buffer size in bytes * @pipe: the pipe to be checked * * return the available size on h-buffer in bytes, * or a negative error code. * * NOTE: calling this function always switches to the stream mode. * you'll need to disconnect the host to get back to the * normal mode. */ static int vx_query_hbuffer_size(struct vx_core *chip, struct vx_pipe *pipe) { int result; struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_SIZE_HBUFFER); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); if (pipe->is_capture) rmh.Cmd[0] |= 0x00000001; result = vx_send_msg(chip, &rmh); if (! result) result = rmh.Stat[0] & 0xffff; return result; } /* * vx_pipe_can_start - query whether a pipe is ready for start * @pipe: the pipe to be checked * * return 1 if ready, 0 if not ready, and negative value on error. * * called from trigger callback only */ static int vx_pipe_can_start(struct vx_core *chip, struct vx_pipe *pipe) { int err; struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_CAN_START_PIPE); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); rmh.Cmd[0] |= 1; err = vx_send_msg(chip, &rmh); if (! err) { if (rmh.Stat[0]) err = 1; } return err; } /* * vx_conf_pipe - tell the pipe to stand by and wait for IRQA. * @pipe: the pipe to be configured */ static int vx_conf_pipe(struct vx_core *chip, struct vx_pipe *pipe) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_CONF_PIPE); if (pipe->is_capture) rmh.Cmd[0] |= COMMAND_RECORD_MASK; rmh.Cmd[1] = 1 << pipe->number; return vx_send_msg(chip, &rmh); } /* * vx_send_irqa - trigger IRQA */ static int vx_send_irqa(struct vx_core *chip) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_SEND_IRQA); return vx_send_msg(chip, &rmh); } #define MAX_WAIT_FOR_DSP 250 /* * vx boards do not support inter-card sync, besides * only 126 samples require to be prepared before a pipe can start */ #define CAN_START_DELAY 2 /* wait 2ms only before asking if the pipe is ready*/ #define WAIT_STATE_DELAY 2 /* wait 2ms after irqA was requested and check if the pipe state toggled*/ /* * vx_toggle_pipe - start / pause a pipe * @pipe: the pipe to be triggered * @state: start = 1, pause = 0 * * called from trigger callback only * */ static int vx_toggle_pipe(struct vx_core *chip, struct vx_pipe *pipe, int state) { int err, i, cur_state; /* Check the pipe is not already in the requested state */ if (vx_get_pipe_state(chip, pipe, &cur_state) < 0) return -EBADFD; if (state == cur_state) return 0; /* If a start is requested, ask the DSP to get prepared * and wait for a positive acknowledge (when there are * enough sound buffer for this pipe) */ if (state) { for (i = 0 ; i < MAX_WAIT_FOR_DSP; i++) { err = vx_pipe_can_start(chip, pipe); if (err > 0) break; /* Wait for a few, before asking again * to avoid flooding the DSP with our requests */ mdelay(1); } } err = vx_conf_pipe(chip, pipe); if (err < 0) return err; err = vx_send_irqa(chip); if (err < 0) return err; /* If it completes successfully, wait for the pipes * reaching the expected state before returning * Check one pipe only (since they are synchronous) */ for (i = 0; i < MAX_WAIT_FOR_DSP; i++) { err = vx_get_pipe_state(chip, pipe, &cur_state); if (err < 0 || cur_state == state) break; err = -EIO; mdelay(1); } return err < 0 ? -EIO : 0; } /* * vx_stop_pipe - stop a pipe * @pipe: the pipe to be stopped * * called from trigger callback only */ static int vx_stop_pipe(struct vx_core *chip, struct vx_pipe *pipe) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_STOP_PIPE); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); return vx_send_msg(chip, &rmh); } /* * vx_alloc_pipe - allocate a pipe and initialize the pipe instance * @capture: 0 = playback, 1 = capture operation * @audioid: the audio id to be assigned * @num_audio: number of audio channels * @pipep: the returned pipe instance * * return 0 on success, or a negative error code. */ static int vx_alloc_pipe(struct vx_core *chip, int capture, int audioid, int num_audio, struct vx_pipe **pipep) { int err; struct vx_pipe *pipe; struct vx_rmh rmh; int data_mode; *pipep = NULL; vx_init_rmh(&rmh, CMD_RES_PIPE); vx_set_pipe_cmd_params(&rmh, capture, audioid, num_audio); #if 0 // NYI if (underrun_skip_sound) rmh.Cmd[0] |= BIT_SKIP_SOUND; #endif // NYI data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0; if (! capture && data_mode) rmh.Cmd[0] |= BIT_DATA_MODE; err = vx_send_msg(chip, &rmh); if (err < 0) return err; /* initialize the pipe record */ pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); if (! pipe) { /* release the pipe */ vx_init_rmh(&rmh, CMD_FREE_PIPE); vx_set_pipe_cmd_params(&rmh, capture, audioid, 0); vx_send_msg(chip, &rmh); return -ENOMEM; } /* the pipe index should be identical with the audio index */ pipe->number = audioid; pipe->is_capture = capture; pipe->channels = num_audio; pipe->differed_type = 0; pipe->pcx_time = 0; pipe->data_mode = data_mode; *pipep = pipe; return 0; } /* * vx_free_pipe - release a pipe * @pipe: pipe to be released */ static int vx_free_pipe(struct vx_core *chip, struct vx_pipe *pipe) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_FREE_PIPE); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); vx_send_msg(chip, &rmh); kfree(pipe); return 0; } /* * vx_start_stream - start the stream * * called from trigger callback only */ static int vx_start_stream(struct vx_core *chip, struct vx_pipe *pipe) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_START_ONE_STREAM); vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number); vx_set_differed_time(chip, &rmh, pipe); return vx_send_msg(chip, &rmh); } /* * vx_stop_stream - stop the stream * * called from trigger callback only */ static int vx_stop_stream(struct vx_core *chip, struct vx_pipe *pipe) { struct vx_rmh rmh; vx_init_rmh(&rmh, CMD_STOP_STREAM); vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number); return vx_send_msg(chip, &rmh); } /* * playback hw information */ static const struct snd_pcm_hardware vx_pcm_playback_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/ /*SNDRV_PCM_INFO_RESUME*/), .formats = (/*SNDRV_PCM_FMTBIT_U8 |*/ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 5000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 126, .period_bytes_max = (128*1024), .periods_min = 2, .periods_max = VX_MAX_PERIODS, .fifo_size = 126, }; /* * vx_pcm_playback_open - open callback for playback */ static int vx_pcm_playback_open(struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; struct vx_core *chip = snd_pcm_substream_chip(subs); struct vx_pipe *pipe = NULL; unsigned int audio; int err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; audio = subs->pcm->device * 2; if (snd_BUG_ON(audio >= chip->audio_outs)) return -EINVAL; /* playback pipe may have been already allocated for monitoring */ pipe = chip->playback_pipes[audio]; if (! pipe) { /* not allocated yet */ err = vx_alloc_pipe(chip, 0, audio, 2, &pipe); /* stereo playback */ if (err < 0) return err; } /* open for playback */ pipe->references++; pipe->substream = subs; chip->playback_pipes[audio] = pipe; runtime->hw = vx_pcm_playback_hw; runtime->hw.period_bytes_min = chip->ibl.size; runtime->private_data = pipe; /* align to 4 bytes (otherwise will be problematic when 24bit is used) */ snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 4); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4); return 0; } /* * vx_pcm_playback_close - close callback for playback */ static int vx_pcm_playback_close(struct snd_pcm_substream *subs) { struct vx_core *chip = snd_pcm_substream_chip(subs); struct vx_pipe *pipe; if (! subs->runtime->private_data) return -EINVAL; pipe = subs->runtime->private_data; if (--pipe->references == 0) { chip->playback_pipes[pipe->number] = NULL; vx_free_pipe(chip, pipe); } return 0; } /* * vx_notify_end_of_buffer - send "end-of-buffer" notifier at the given pipe * @pipe: the pipe to notify * * NB: call with a certain lock. */ static int vx_notify_end_of_buffer(struct vx_core *chip, struct vx_pipe *pipe) { int err; struct vx_rmh rmh; /* use a temporary rmh here */ /* Toggle Dsp Host Interface into Message mode */ vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT); vx_init_rmh(&rmh, CMD_NOTIFY_END_OF_BUFFER); vx_set_stream_cmd_params(&rmh, 0, pipe->number); err = vx_send_msg_nolock(chip, &rmh); if (err < 0) return err; /* Toggle Dsp Host Interface back to sound transfer mode */ vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT); return 0; } /* * vx_pcm_playback_transfer_chunk - transfer a single chunk * @subs: substream * @pipe: the pipe to transfer * @size: chunk size in bytes * * transfer a single buffer chunk. EOB notificaton is added after that. * called from the interrupt handler, too. * * return 0 if ok. */ static int vx_pcm_playback_transfer_chunk(struct vx_core *chip, struct snd_pcm_runtime *runtime, struct vx_pipe *pipe, int size) { int space, err = 0; space = vx_query_hbuffer_size(chip, pipe); if (space < 0) { /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); snd_printd("error hbuffer\n"); return space; } if (space < size) { vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); snd_printd("no enough hbuffer space %d\n", space); return -EIO; /* XRUN */ } /* we don't need irqsave here, because this function * is called from either trigger callback or irq handler */ mutex_lock(&chip->lock); vx_pseudo_dma_write(chip, runtime, pipe, size); err = vx_notify_end_of_buffer(chip, pipe); /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ vx_send_rih_nolock(chip, IRQ_CONNECT_STREAM_NEXT); mutex_unlock(&chip->lock); return err; } /* * update the position of the given pipe. * pipe->position is updated and wrapped within the buffer size. * pipe->transferred is updated, too, but the size is not wrapped, * so that the caller can check the total transferred size later * (to call snd_pcm_period_elapsed). */ static int vx_update_pipe_position(struct vx_core *chip, struct snd_pcm_runtime *runtime, struct vx_pipe *pipe) { struct vx_rmh rmh; int err, update; u64 count; vx_init_rmh(&rmh, CMD_STREAM_SAMPLE_COUNT); vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); err = vx_send_msg(chip, &rmh); if (err < 0) return err; count = ((u64)(rmh.Stat[0] & 0xfffff) << 24) | (u64)rmh.Stat[1]; update = (int)(count - pipe->cur_count); pipe->cur_count = count; pipe->position += update; if (pipe->position >= (int)runtime->buffer_size) pipe->position %= runtime->buffer_size; pipe->transferred += update; return 0; } /* * transfer the pending playback buffer data to DSP * called from interrupt handler */ static void vx_pcm_playback_transfer(struct vx_core *chip, struct snd_pcm_substream *subs, struct vx_pipe *pipe, int nchunks) { int i, err; struct snd_pcm_runtime *runtime = subs->runtime; if (! pipe->prepared || (chip->chip_status & VX_STAT_IS_STALE)) return; for (i = 0; i < nchunks; i++) { err = vx_pcm_playback_transfer_chunk(chip, runtime, pipe, chip->ibl.size); if (err < 0) return; } } /* * update the playback position and call snd_pcm_period_elapsed() if necessary * called from interrupt handler */ static void vx_pcm_playback_update(struct vx_core *chip, struct snd_pcm_substream *subs, struct vx_pipe *pipe) { int err; struct snd_pcm_runtime *runtime = subs->runtime; if (pipe->running && ! (chip->chip_status & VX_STAT_IS_STALE)) { err = vx_update_pipe_position(chip, runtime, pipe); if (err < 0) return; if (pipe->transferred >= (int)runtime->period_size) { pipe->transferred %= runtime->period_size; snd_pcm_period_elapsed(subs); } } } /* * vx_pcm_playback_trigger - trigger callback for playback */ static int vx_pcm_trigger(struct snd_pcm_substream *subs, int cmd) { struct vx_core *chip = snd_pcm_substream_chip(subs); struct vx_pipe *pipe = subs->runtime->private_data; int err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: if (! pipe->is_capture) vx_pcm_playback_transfer(chip, subs, pipe, 2); err = vx_start_stream(chip, pipe); if (err < 0) { pr_debug("vx: cannot start stream\n"); return err; } err = vx_toggle_pipe(chip, pipe, 1); if (err < 0) { pr_debug("vx: cannot start pipe\n"); vx_stop_stream(chip, pipe); return err; } chip->pcm_running++; pipe->running = 1; break; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: vx_toggle_pipe(chip, pipe, 0); vx_stop_pipe(chip, pipe); vx_stop_stream(chip, pipe); chip->pcm_running--; pipe->running = 0; break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: err = vx_toggle_pipe(chip, pipe, 0); if (err < 0) return err; break; case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: err = vx_toggle_pipe(chip, pipe, 1); if (err < 0) return err; break; default: return -EINVAL; } return 0; } /* * vx_pcm_playback_pointer - pointer callback for playback */ static snd_pcm_uframes_t vx_pcm_playback_pointer(struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; struct vx_pipe *pipe = runtime->private_data; return pipe->position; } /* * vx_pcm_prepare - prepare callback for playback and capture */ static int vx_pcm_prepare(struct snd_pcm_substream *subs) { struct vx_core *chip = snd_pcm_substream_chip(subs); struct snd_pcm_runtime *runtime = subs->runtime; struct vx_pipe *pipe = runtime->private_data; int err, data_mode; // int max_size, nchunks; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0; if (data_mode != pipe->data_mode && ! pipe->is_capture) { /* IEC958 status (raw-mode) was changed */ /* we reopen the pipe */ struct vx_rmh rmh; snd_printdd(KERN_DEBUG "reopen the pipe with data_mode = %d\n", data_mode); vx_init_rmh(&rmh, CMD_FREE_PIPE); vx_set_pipe_cmd_params(&rmh, 0, pipe->number, 0); err = vx_send_msg(chip, &rmh); if (err < 0) return err; vx_init_rmh(&rmh, CMD_RES_PIPE); vx_set_pipe_cmd_params(&rmh, 0, pipe->number, pipe->channels); if (data_mode) rmh.Cmd[0] |= BIT_DATA_MODE; err = vx_send_msg(chip, &rmh); if (err < 0) return err; pipe->data_mode = data_mode; } if (chip->pcm_running && chip->freq != runtime->rate) { snd_printk(KERN_ERR "vx: cannot set different clock %d " "from the current %d\n", runtime->rate, chip->freq); return -EINVAL; } vx_set_clock(chip, runtime->rate); err = vx_set_format(chip, pipe, runtime); if (err < 0) return err; if (vx_is_pcmcia(chip)) { pipe->align = 2; /* 16bit word */ } else { pipe->align = 4; /* 32bit word */ } pipe->buffer_bytes = frames_to_bytes(runtime, runtime->buffer_size); pipe->period_bytes = frames_to_bytes(runtime, runtime->period_size); pipe->hw_ptr = 0; /* set the timestamp */ vx_update_pipe_position(chip, runtime, pipe); /* clear again */ pipe->transferred = 0; pipe->position = 0; pipe->prepared = 1; return 0; } /* * operators for PCM playback */ static const struct snd_pcm_ops vx_pcm_playback_ops = { .open = vx_pcm_playback_open, .close = vx_pcm_playback_close, .prepare = vx_pcm_prepare, .trigger = vx_pcm_trigger, .pointer = vx_pcm_playback_pointer, }; /* * playback hw information */ static const struct snd_pcm_hardware vx_pcm_capture_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/ /*SNDRV_PCM_INFO_RESUME*/), .formats = (/*SNDRV_PCM_FMTBIT_U8 |*/ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 5000, .rate_max = 48000, .channels_min = 1, .channels_max = 2, .buffer_bytes_max = (128*1024), .period_bytes_min = 126, .period_bytes_max = (128*1024), .periods_min = 2, .periods_max = VX_MAX_PERIODS, .fifo_size = 126, }; /* * vx_pcm_capture_open - open callback for capture */ static int vx_pcm_capture_open(struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; struct vx_core *chip = snd_pcm_substream_chip(subs); struct vx_pipe *pipe; struct vx_pipe *pipe_out_monitoring = NULL; unsigned int audio; int err; if (chip->chip_status & VX_STAT_IS_STALE) return -EBUSY; audio = subs->pcm->device * 2; if (snd_BUG_ON(audio >= chip->audio_ins)) return -EINVAL; err = vx_alloc_pipe(chip, 1, audio, 2, &pipe); if (err < 0) return err; pipe->substream = subs; chip->capture_pipes[audio] = pipe; /* check if monitoring is needed */ if (chip->audio_monitor_active[audio]) { pipe_out_monitoring = chip->playback_pipes[audio]; if (! pipe_out_monitoring) { /* allocate a pipe */ err = vx_alloc_pipe(chip, 0, audio, 2, &pipe_out_monitoring); if (err < 0) return err; chip->playback_pipes[audio] = pipe_out_monitoring; } pipe_out_monitoring->references++; /* if an output pipe is available, it's audios still may need to be unmuted. hence we'll have to call a mixer entry point. */ vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], chip->audio_monitor_active[audio]); /* assuming stereo */ vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], chip->audio_monitor_active[audio+1]); } pipe->monitoring_pipe = pipe_out_monitoring; /* default value NULL */ runtime->hw = vx_pcm_capture_hw; runtime->hw.period_bytes_min = chip->ibl.size; runtime->private_data = pipe; /* align to 4 bytes (otherwise will be problematic when 24bit is used) */ snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 4); snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 4); return 0; } /* * vx_pcm_capture_close - close callback for capture */ static int vx_pcm_capture_close(struct snd_pcm_substream *subs) { struct vx_core *chip = snd_pcm_substream_chip(subs); struct vx_pipe *pipe; struct vx_pipe *pipe_out_monitoring; if (! subs->runtime->private_data) return -EINVAL; pipe = subs->runtime->private_data; chip->capture_pipes[pipe->number] = NULL; pipe_out_monitoring = pipe->monitoring_pipe; /* if an output pipe is attached to this input, check if it needs to be released. */ if (pipe_out_monitoring) { if (--pipe_out_monitoring->references == 0) { vx_free_pipe(chip, pipe_out_monitoring); chip->playback_pipes[pipe->number] = NULL; pipe->monitoring_pipe = NULL; } } vx_free_pipe(chip, pipe); return 0; } #define DMA_READ_ALIGN 6 /* hardware alignment for read */ /* * vx_pcm_capture_update - update the capture buffer */ static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream *subs, struct vx_pipe *pipe) { int size, space, count; struct snd_pcm_runtime *runtime = subs->runtime; if (!pipe->running || (chip->chip_status & VX_STAT_IS_STALE)) return; size = runtime->buffer_size - snd_pcm_capture_avail(runtime); if (! size) return; size = frames_to_bytes(runtime, size); space = vx_query_hbuffer_size(chip, pipe); if (space < 0) goto _error; if (size > space) size = space; size = (size / 3) * 3; /* align to 3 bytes */ if (size < DMA_READ_ALIGN) goto _error; /* keep the last 6 bytes, they will be read after disconnection */ count = size - DMA_READ_ALIGN; /* read bytes until the current pointer reaches to the aligned position * for word-transfer */ while (count > 0) { if ((pipe->hw_ptr % pipe->align) == 0) break; if (vx_wait_for_rx_full(chip) < 0) goto _error; vx_pcm_read_per_bytes(chip, runtime, pipe); count -= 3; } if (count > 0) { /* ok, let's accelerate! */ int align = pipe->align * 3; space = (count / align) * align; if (space > 0) { vx_pseudo_dma_read(chip, runtime, pipe, space); count -= space; } } /* read the rest of bytes */ while (count > 0) { if (vx_wait_for_rx_full(chip) < 0) goto _error; vx_pcm_read_per_bytes(chip, runtime, pipe); count -= 3; } /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); /* read the last pending 6 bytes */ count = DMA_READ_ALIGN; while (count > 0) { vx_pcm_read_per_bytes(chip, runtime, pipe); count -= 3; } /* update the position */ pipe->transferred += size; if (pipe->transferred >= pipe->period_bytes) { pipe->transferred %= pipe->period_bytes; snd_pcm_period_elapsed(subs); } return; _error: /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); return; } /* * vx_pcm_capture_pointer - pointer callback for capture */ static snd_pcm_uframes_t vx_pcm_capture_pointer(struct snd_pcm_substream *subs) { struct snd_pcm_runtime *runtime = subs->runtime; struct vx_pipe *pipe = runtime->private_data; return bytes_to_frames(runtime, pipe->hw_ptr); } /* * operators for PCM capture */ static const struct snd_pcm_ops vx_pcm_capture_ops = { .open = vx_pcm_capture_open, .close = vx_pcm_capture_close, .prepare = vx_pcm_prepare, .trigger = vx_pcm_trigger, .pointer = vx_pcm_capture_pointer, }; /* * interrupt handler for pcm streams */ void vx_pcm_update_intr(struct vx_core *chip, unsigned int events) { unsigned int i; struct vx_pipe *pipe; #define EVENT_MASK (END_OF_BUFFER_EVENTS_PENDING|ASYNC_EVENTS_PENDING) if (events & EVENT_MASK) { vx_init_rmh(&chip->irq_rmh, CMD_ASYNC); if (events & ASYNC_EVENTS_PENDING) chip->irq_rmh.Cmd[0] |= 0x00000001; /* SEL_ASYNC_EVENTS */ if (events & END_OF_BUFFER_EVENTS_PENDING) chip->irq_rmh.Cmd[0] |= 0x00000002; /* SEL_END_OF_BUF_EVENTS */ if (vx_send_msg(chip, &chip->irq_rmh) < 0) { snd_printdd(KERN_ERR "msg send error!!\n"); return; } i = 1; while (i < chip->irq_rmh.LgStat) { int p, buf, capture, eob; p = chip->irq_rmh.Stat[i] & MASK_FIRST_FIELD; capture = (chip->irq_rmh.Stat[i] & 0x400000) ? 1 : 0; eob = (chip->irq_rmh.Stat[i] & 0x800000) ? 1 : 0; i++; if (events & ASYNC_EVENTS_PENDING) i++; buf = 1; /* force to transfer */ if (events & END_OF_BUFFER_EVENTS_PENDING) { if (eob) buf = chip->irq_rmh.Stat[i]; i++; } if (capture) continue; if (snd_BUG_ON(p < 0 || p >= chip->audio_outs)) continue; pipe = chip->playback_pipes[p]; if (pipe && pipe->substream) { vx_pcm_playback_update(chip, pipe->substream, pipe); vx_pcm_playback_transfer(chip, pipe->substream, pipe, buf); } } } /* update the capture pcm pointers as frequently as possible */ for (i = 0; i < chip->audio_ins; i++) { pipe = chip->capture_pipes[i]; if (pipe && pipe->substream) vx_pcm_capture_update(chip, pipe->substream, pipe); } } /* * vx_init_audio_io - check the available audio i/o and allocate pipe arrays */ static int vx_init_audio_io(struct vx_core *chip) { struct vx_rmh rmh; int preferred; vx_init_rmh(&rmh, CMD_SUPPORTED); if (vx_send_msg(chip, &rmh) < 0) { snd_printk(KERN_ERR "vx: cannot get the supported audio data\n"); return -ENXIO; } chip->audio_outs = rmh.Stat[0] & MASK_FIRST_FIELD; chip->audio_ins = (rmh.Stat[0] >> (FIELD_SIZE*2)) & MASK_FIRST_FIELD; chip->audio_info = rmh.Stat[1]; /* allocate pipes */ chip->playback_pipes = kcalloc(chip->audio_outs, sizeof(struct vx_pipe *), GFP_KERNEL); if (!chip->playback_pipes) return -ENOMEM; chip->capture_pipes = kcalloc(chip->audio_ins, sizeof(struct vx_pipe *), GFP_KERNEL); if (!chip->capture_pipes) { kfree(chip->playback_pipes); return -ENOMEM; } preferred = chip->ibl.size; chip->ibl.size = 0; vx_set_ibl(chip, &chip->ibl); /* query the info */ if (preferred > 0) { chip->ibl.size = roundup(preferred, chip->ibl.granularity); if (chip->ibl.size > chip->ibl.max_size) chip->ibl.size = chip->ibl.max_size; } else chip->ibl.size = chip->ibl.min_size; /* set to the minimum */ vx_set_ibl(chip, &chip->ibl); return 0; } /* * free callback for pcm */ static void snd_vx_pcm_free(struct snd_pcm *pcm) { struct vx_core *chip = pcm->private_data; chip->pcm[pcm->device] = NULL; kfree(chip->playback_pipes); chip->playback_pipes = NULL; kfree(chip->capture_pipes); chip->capture_pipes = NULL; } /* * snd_vx_pcm_new - create and initialize a pcm */ int snd_vx_pcm_new(struct vx_core *chip) { struct snd_pcm *pcm; unsigned int i; int err; err = vx_init_audio_io(chip); if (err < 0) return err; for (i = 0; i < chip->hw->num_codecs; i++) { unsigned int outs, ins; outs = chip->audio_outs > i * 2 ? 1 : 0; ins = chip->audio_ins > i * 2 ? 1 : 0; if (! outs && ! ins) break; err = snd_pcm_new(chip->card, "VX PCM", i, outs, ins, &pcm); if (err < 0) return err; if (outs) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &vx_pcm_playback_ops); if (ins) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &vx_pcm_capture_ops); snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_VMALLOC, NULL, 0, 0); pcm->private_data = chip; pcm->private_free = snd_vx_pcm_free; pcm->info_flags = 0; pcm->nonatomic = true; strcpy(pcm->name, chip->card->shortname); chip->pcm[i] = pcm; } return 0; }
linux-master
sound/drivers/vx/vx_pcm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]> * Routines for control of MPU-401 in UART mode * * MPU-401 supports UART mode which is not capable generate transmit * interrupts thus output is done via polling. Without interrupt, * input is done also via polling. Do not expect good performance. * * 13-03-2003: * Added support for different kind of hardware I/O. Build in choices * are port and mmio. For other kind of I/O, set mpu->read and * mpu->write to your own I/O functions. */ #include <linux/io.h> #include <linux/delay.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/interrupt.h> #include <linux/errno.h> #include <sound/core.h> #include <sound/mpu401.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Routines for control of MPU-401 in UART mode"); MODULE_LICENSE("GPL"); static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu); static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu); /* */ #define snd_mpu401_input_avail(mpu) \ (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY)) #define snd_mpu401_output_ready(mpu) \ (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL)) /* Build in lowlevel io */ static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data, unsigned long addr) { outb(data, addr); } static unsigned char mpu401_read_port(struct snd_mpu401 *mpu, unsigned long addr) { return inb(addr); } static void mpu401_write_mmio(struct snd_mpu401 *mpu, unsigned char data, unsigned long addr) { writeb(data, (void __iomem *)addr); } static unsigned char mpu401_read_mmio(struct snd_mpu401 *mpu, unsigned long addr) { return readb((void __iomem *)addr); } /* */ static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu) { int timeout = 100000; for (; timeout > 0 && snd_mpu401_input_avail(mpu); timeout--) mpu->read(mpu, MPU401D(mpu)); #ifdef CONFIG_SND_DEBUG if (timeout <= 0) snd_printk(KERN_ERR "cmd: clear rx timeout (status = 0x%x)\n", mpu->read(mpu, MPU401C(mpu))); #endif } static void uart_interrupt_tx(struct snd_mpu401 *mpu) { unsigned long flags; if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) && test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) { spin_lock_irqsave(&mpu->output_lock, flags); snd_mpu401_uart_output_write(mpu); spin_unlock_irqrestore(&mpu->output_lock, flags); } } static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu) { unsigned long flags; if (mpu->info_flags & MPU401_INFO_INPUT) { spin_lock_irqsave(&mpu->input_lock, flags); if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) snd_mpu401_uart_input_read(mpu); else snd_mpu401_uart_clear_rx(mpu); spin_unlock_irqrestore(&mpu->input_lock, flags); } if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) /* ok. for better Tx performance try do some output when input is done */ uart_interrupt_tx(mpu); } /** * snd_mpu401_uart_interrupt - generic MPU401-UART interrupt handler * @irq: the irq number * @dev_id: mpu401 instance * * Processes the interrupt for MPU401-UART i/o. * * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise. */ irqreturn_t snd_mpu401_uart_interrupt(int irq, void *dev_id) { struct snd_mpu401 *mpu = dev_id; if (!mpu) return IRQ_NONE; _snd_mpu401_uart_interrupt(mpu); return IRQ_HANDLED; } EXPORT_SYMBOL(snd_mpu401_uart_interrupt); /** * snd_mpu401_uart_interrupt_tx - generic MPU401-UART transmit irq handler * @irq: the irq number * @dev_id: mpu401 instance * * Processes the interrupt for MPU401-UART output. * * Return: %IRQ_HANDLED if the interrupt was handled. %IRQ_NONE otherwise. */ irqreturn_t snd_mpu401_uart_interrupt_tx(int irq, void *dev_id) { struct snd_mpu401 *mpu = dev_id; if (!mpu) return IRQ_NONE; uart_interrupt_tx(mpu); return IRQ_HANDLED; } EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx); /* * timer callback * reprogram the timer and call the interrupt job */ static void snd_mpu401_uart_timer(struct timer_list *t) { struct snd_mpu401 *mpu = from_timer(mpu, t, timer); unsigned long flags; spin_lock_irqsave(&mpu->timer_lock, flags); /*mpu->mode |= MPU401_MODE_TIMER;*/ mod_timer(&mpu->timer, 1 + jiffies); spin_unlock_irqrestore(&mpu->timer_lock, flags); if (mpu->rmidi) _snd_mpu401_uart_interrupt(mpu); } /* * initialize the timer callback if not programmed yet */ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input) { unsigned long flags; spin_lock_irqsave (&mpu->timer_lock, flags); if (mpu->timer_invoked == 0) { timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0); mod_timer(&mpu->timer, 1 + jiffies); } mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER : MPU401_MODE_OUTPUT_TIMER; spin_unlock_irqrestore (&mpu->timer_lock, flags); } /* * remove the timer callback if still active */ static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input) { unsigned long flags; spin_lock_irqsave (&mpu->timer_lock, flags); if (mpu->timer_invoked) { mpu->timer_invoked &= input ? ~MPU401_MODE_INPUT_TIMER : ~MPU401_MODE_OUTPUT_TIMER; if (! mpu->timer_invoked) del_timer(&mpu->timer); } spin_unlock_irqrestore (&mpu->timer_lock, flags); } /* * send a UART command * return zero if successful, non-zero for some errors */ static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd, int ack) { unsigned long flags; int timeout, ok; spin_lock_irqsave(&mpu->input_lock, flags); if (mpu->hardware != MPU401_HW_TRID4DWAVE) { mpu->write(mpu, 0x00, MPU401D(mpu)); /*snd_mpu401_uart_clear_rx(mpu);*/ } /* ok. standard MPU-401 initialization */ if (mpu->hardware != MPU401_HW_SB) { for (timeout = 1000; timeout > 0 && !snd_mpu401_output_ready(mpu); timeout--) udelay(10); #ifdef CONFIG_SND_DEBUG if (!timeout) snd_printk(KERN_ERR "cmd: tx timeout (status = 0x%x)\n", mpu->read(mpu, MPU401C(mpu))); #endif } mpu->write(mpu, cmd, MPU401C(mpu)); if (ack && !(mpu->info_flags & MPU401_INFO_NO_ACK)) { ok = 0; timeout = 10000; while (!ok && timeout-- > 0) { if (snd_mpu401_input_avail(mpu)) { if (mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK) ok = 1; } } if (!ok && mpu->read(mpu, MPU401D(mpu)) == MPU401_ACK) ok = 1; } else ok = 1; spin_unlock_irqrestore(&mpu->input_lock, flags); if (!ok) { snd_printk(KERN_ERR "cmd: 0x%x failed at 0x%lx " "(status = 0x%x, data = 0x%x)\n", cmd, mpu->port, mpu->read(mpu, MPU401C(mpu)), mpu->read(mpu, MPU401D(mpu))); return 1; } return 0; } static int snd_mpu401_do_reset(struct snd_mpu401 *mpu) { if (snd_mpu401_uart_cmd(mpu, MPU401_RESET, 1)) return -EIO; if (snd_mpu401_uart_cmd(mpu, MPU401_ENTER_UART, 0)) return -EIO; return 0; } /* * input/output open/close - protected by open_mutex in rawmidi.c */ static int snd_mpu401_uart_input_open(struct snd_rawmidi_substream *substream) { struct snd_mpu401 *mpu; int err; mpu = substream->rmidi->private_data; if (mpu->open_input) { err = mpu->open_input(mpu); if (err < 0) return err; } if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode)) { if (snd_mpu401_do_reset(mpu) < 0) goto error_out; } mpu->substream_input = substream; set_bit(MPU401_MODE_BIT_INPUT, &mpu->mode); return 0; error_out: if (mpu->open_input && mpu->close_input) mpu->close_input(mpu); return -EIO; } static int snd_mpu401_uart_output_open(struct snd_rawmidi_substream *substream) { struct snd_mpu401 *mpu; int err; mpu = substream->rmidi->private_data; if (mpu->open_output) { err = mpu->open_output(mpu); if (err < 0) return err; } if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) { if (snd_mpu401_do_reset(mpu) < 0) goto error_out; } mpu->substream_output = substream; set_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode); return 0; error_out: if (mpu->open_output && mpu->close_output) mpu->close_output(mpu); return -EIO; } static int snd_mpu401_uart_input_close(struct snd_rawmidi_substream *substream) { struct snd_mpu401 *mpu; int err = 0; mpu = substream->rmidi->private_data; clear_bit(MPU401_MODE_BIT_INPUT, &mpu->mode); mpu->substream_input = NULL; if (! test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode)) err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0); if (mpu->close_input) mpu->close_input(mpu); if (err) return -EIO; return 0; } static int snd_mpu401_uart_output_close(struct snd_rawmidi_substream *substream) { struct snd_mpu401 *mpu; int err = 0; mpu = substream->rmidi->private_data; clear_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode); mpu->substream_output = NULL; if (! test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) err = snd_mpu401_uart_cmd(mpu, MPU401_RESET, 0); if (mpu->close_output) mpu->close_output(mpu); if (err) return -EIO; return 0; } /* * trigger input callback */ static void snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_mpu401 *mpu; int max = 64; mpu = substream->rmidi->private_data; if (up) { if (! test_and_set_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode)) { /* first time - flush FIFO */ while (max-- > 0) mpu->read(mpu, MPU401D(mpu)); if (mpu->info_flags & MPU401_INFO_USE_TIMER) snd_mpu401_uart_add_timer(mpu, 1); } /* read data in advance */ spin_lock_irqsave(&mpu->input_lock, flags); snd_mpu401_uart_input_read(mpu); spin_unlock_irqrestore(&mpu->input_lock, flags); } else { if (mpu->info_flags & MPU401_INFO_USE_TIMER) snd_mpu401_uart_remove_timer(mpu, 1); clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode); } } /* * transfer input pending data * call with input_lock spinlock held */ static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu) { int max = 128; unsigned char byte; while (max-- > 0) { if (! snd_mpu401_input_avail(mpu)) break; /* input not available */ byte = mpu->read(mpu, MPU401D(mpu)); if (test_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode)) snd_rawmidi_receive(mpu->substream_input, &byte, 1); } } /* * Tx FIFO sizes: * CS4237B - 16 bytes * AudioDrive ES1688 - 12 bytes * S3 SonicVibes - 8 bytes * SoundBlaster AWE 64 - 2 bytes (ugly hardware) */ /* * write output pending bytes * call with output_lock spinlock held */ static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu) { unsigned char byte; int max = 256; do { if (snd_rawmidi_transmit_peek(mpu->substream_output, &byte, 1) == 1) { /* * Try twice because there is hardware that insists on * setting the output busy bit after each write. */ if (!snd_mpu401_output_ready(mpu) && !snd_mpu401_output_ready(mpu)) break; /* Tx FIFO full - try again later */ mpu->write(mpu, byte, MPU401D(mpu)); snd_rawmidi_transmit_ack(mpu->substream_output, 1); } else { snd_mpu401_uart_remove_timer (mpu, 0); break; /* no other data - leave the tx loop */ } } while (--max > 0); } /* * output trigger callback */ static void snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up) { unsigned long flags; struct snd_mpu401 *mpu; mpu = substream->rmidi->private_data; if (up) { set_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode); /* try to add the timer at each output trigger, * since the output timer might have been removed in * snd_mpu401_uart_output_write(). */ if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) snd_mpu401_uart_add_timer(mpu, 0); /* output pending data */ spin_lock_irqsave(&mpu->output_lock, flags); snd_mpu401_uart_output_write(mpu); spin_unlock_irqrestore(&mpu->output_lock, flags); } else { if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) snd_mpu401_uart_remove_timer(mpu, 0); clear_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode); } } /* */ static const struct snd_rawmidi_ops snd_mpu401_uart_output = { .open = snd_mpu401_uart_output_open, .close = snd_mpu401_uart_output_close, .trigger = snd_mpu401_uart_output_trigger, }; static const struct snd_rawmidi_ops snd_mpu401_uart_input = { .open = snd_mpu401_uart_input_open, .close = snd_mpu401_uart_input_close, .trigger = snd_mpu401_uart_input_trigger, }; static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) { struct snd_mpu401 *mpu = rmidi->private_data; if (mpu->irq >= 0) free_irq(mpu->irq, (void *) mpu); release_and_free_resource(mpu->res); kfree(mpu); } /** * snd_mpu401_uart_new - create an MPU401-UART instance * @card: the card instance * @device: the device index, zero-based * @hardware: the hardware type, MPU401_HW_XXXX * @port: the base address of MPU401 port * @info_flags: bitflags MPU401_INFO_XXX * @irq: the ISA irq number, -1 if not to be allocated * @rrawmidi: the pointer to store the new rawmidi instance * * Creates a new MPU-401 instance. * * Note that the rawmidi instance is returned on the rrawmidi argument, * not the mpu401 instance itself. To access to the mpu401 instance, * cast from rawmidi->private_data (with struct snd_mpu401 magic-cast). * * Return: Zero if successful, or a negative error code. */ int snd_mpu401_uart_new(struct snd_card *card, int device, unsigned short hardware, unsigned long port, unsigned int info_flags, int irq, struct snd_rawmidi ** rrawmidi) { struct snd_mpu401 *mpu; struct snd_rawmidi *rmidi; int in_enable, out_enable; int err; if (rrawmidi) *rrawmidi = NULL; if (! (info_flags & (MPU401_INFO_INPUT | MPU401_INFO_OUTPUT))) info_flags |= MPU401_INFO_INPUT | MPU401_INFO_OUTPUT; in_enable = (info_flags & MPU401_INFO_INPUT) ? 1 : 0; out_enable = (info_flags & MPU401_INFO_OUTPUT) ? 1 : 0; err = snd_rawmidi_new(card, "MPU-401U", device, out_enable, in_enable, &rmidi); if (err < 0) return err; mpu = kzalloc(sizeof(*mpu), GFP_KERNEL); if (!mpu) { err = -ENOMEM; goto free_device; } rmidi->private_data = mpu; rmidi->private_free = snd_mpu401_uart_free; spin_lock_init(&mpu->input_lock); spin_lock_init(&mpu->output_lock); spin_lock_init(&mpu->timer_lock); mpu->hardware = hardware; mpu->irq = -1; if (! (info_flags & MPU401_INFO_INTEGRATED)) { int res_size = hardware == MPU401_HW_PC98II ? 4 : 2; mpu->res = request_region(port, res_size, "MPU401 UART"); if (!mpu->res) { snd_printk(KERN_ERR "mpu401_uart: " "unable to grab port 0x%lx size %d\n", port, res_size); err = -EBUSY; goto free_device; } } if (info_flags & MPU401_INFO_MMIO) { mpu->write = mpu401_write_mmio; mpu->read = mpu401_read_mmio; } else { mpu->write = mpu401_write_port; mpu->read = mpu401_read_port; } mpu->port = port; if (hardware == MPU401_HW_PC98II) mpu->cport = port + 2; else mpu->cport = port + 1; if (irq >= 0) { if (request_irq(irq, snd_mpu401_uart_interrupt, 0, "MPU401 UART", (void *) mpu)) { snd_printk(KERN_ERR "mpu401_uart: " "unable to grab IRQ %d\n", irq); err = -EBUSY; goto free_device; } } if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK)) info_flags |= MPU401_INFO_USE_TIMER; mpu->info_flags = info_flags; mpu->irq = irq; if (card->shortname[0]) snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI", card->shortname); else sprintf(rmidi->name, "MPU-401 MIDI %d-%d",card->number, device); if (out_enable) { snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_mpu401_uart_output); rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT; } if (in_enable) { snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_mpu401_uart_input); rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; if (out_enable) rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX; } mpu->rmidi = rmidi; if (rrawmidi) *rrawmidi = rmidi; return 0; free_device: snd_device_free(card, rmidi); return err; } EXPORT_SYMBOL(snd_mpu401_uart_new);
linux-master
sound/drivers/mpu401/mpu401_uart.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Driver for generic MPU-401 boards (UART mode only) * Copyright (c) by Jaroslav Kysela <[email protected]> * Copyright (c) 2004 by Castet Matthieu <[email protected]> */ #include <linux/init.h> #include <linux/pnp.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/module.h> #include <sound/core.h> #include <sound/mpu401.h> #include <sound/initval.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("MPU-401 UART"); MODULE_LICENSE("GPL"); static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* exclude the first card */ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ #ifdef CONFIG_PNP static bool pnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; #endif static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* MPU-401 port number */ static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* MPU-401 IRQ */ static bool uart_enter[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for MPU-401 device."); module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for MPU-401 device."); module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable MPU-401 device."); #ifdef CONFIG_PNP module_param_array(pnp, bool, NULL, 0444); MODULE_PARM_DESC(pnp, "PnP detection for MPU-401 device."); #endif module_param_hw_array(port, long, ioport, NULL, 0444); MODULE_PARM_DESC(port, "Port # for MPU-401 device."); module_param_hw_array(irq, int, irq, NULL, 0444); MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device."); module_param_array(uart_enter, bool, NULL, 0444); MODULE_PARM_DESC(uart_enter, "Issue UART_ENTER command at open."); static struct platform_device *platform_devices[SNDRV_CARDS]; static int pnp_registered; static unsigned int snd_mpu401_devices; static int snd_mpu401_create(struct device *devptr, int dev, struct snd_card **rcard) { struct snd_card *card; int err; if (!uart_enter[dev]) snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n"); *rcard = NULL; err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE, 0, &card); if (err < 0) return err; strcpy(card->driver, "MPU-401 UART"); strcpy(card->shortname, card->driver); sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]); if (irq[dev] >= 0) { sprintf(card->longname + strlen(card->longname), "irq %d", irq[dev]); } else { strcat(card->longname, "polled"); } err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0, irq[dev], NULL); if (err < 0) { printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); return err; } *rcard = card; return 0; } static int snd_mpu401_probe(struct platform_device *devptr) { int dev = devptr->id; int err; struct snd_card *card; if (port[dev] == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR "specify port\n"); return -EINVAL; } if (irq[dev] == SNDRV_AUTO_IRQ) { snd_printk(KERN_ERR "specify or disable IRQ\n"); return -EINVAL; } err = snd_mpu401_create(&devptr->dev, dev, &card); if (err < 0) return err; err = snd_card_register(card); if (err < 0) return err; platform_set_drvdata(devptr, card); return 0; } #define SND_MPU401_DRIVER "snd_mpu401" static struct platform_driver snd_mpu401_driver = { .probe = snd_mpu401_probe, .driver = { .name = SND_MPU401_DRIVER, }, }; #ifdef CONFIG_PNP #define IO_EXTENT 2 static const struct pnp_device_id snd_mpu401_pnpids[] = { { .id = "PNPb006" }, { .id = "" } }; MODULE_DEVICE_TABLE(pnp, snd_mpu401_pnpids); static int snd_mpu401_pnp(int dev, struct pnp_dev *device, const struct pnp_device_id *id) { if (!pnp_port_valid(device, 0) || pnp_port_flags(device, 0) & IORESOURCE_DISABLED) { snd_printk(KERN_ERR "no PnP port\n"); return -ENODEV; } if (pnp_port_len(device, 0) < IO_EXTENT) { snd_printk(KERN_ERR "PnP port length is %llu, expected %d\n", (unsigned long long)pnp_port_len(device, 0), IO_EXTENT); return -ENODEV; } port[dev] = pnp_port_start(device, 0); if (!pnp_irq_valid(device, 0) || pnp_irq_flags(device, 0) & IORESOURCE_DISABLED) { snd_printk(KERN_WARNING "no PnP irq, using polling\n"); irq[dev] = -1; } else { irq[dev] = pnp_irq(device, 0); } return 0; } static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) { static int dev; struct snd_card *card; int err; for ( ; dev < SNDRV_CARDS; ++dev) { if (!enable[dev] || !pnp[dev]) continue; err = snd_mpu401_pnp(dev, pnp_dev, id); if (err < 0) return err; err = snd_mpu401_create(&pnp_dev->dev, dev, &card); if (err < 0) return err; err = snd_card_register(card); if (err < 0) return err; pnp_set_drvdata(pnp_dev, card); snd_mpu401_devices++; ++dev; return 0; } return -ENODEV; } static struct pnp_driver snd_mpu401_pnp_driver = { .name = "mpu401", .id_table = snd_mpu401_pnpids, .probe = snd_mpu401_pnp_probe, }; #else static struct pnp_driver snd_mpu401_pnp_driver; #endif static void snd_mpu401_unregister_all(void) { int i; if (pnp_registered) pnp_unregister_driver(&snd_mpu401_pnp_driver); for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) platform_device_unregister(platform_devices[i]); platform_driver_unregister(&snd_mpu401_driver); } static int __init alsa_card_mpu401_init(void) { int i, err; err = platform_driver_register(&snd_mpu401_driver); if (err < 0) return err; for (i = 0; i < SNDRV_CARDS; i++) { struct platform_device *device; if (! enable[i]) continue; #ifdef CONFIG_PNP if (pnp[i]) continue; #endif device = platform_device_register_simple(SND_MPU401_DRIVER, i, NULL, 0); if (IS_ERR(device)) continue; if (!platform_get_drvdata(device)) { platform_device_unregister(device); continue; } platform_devices[i] = device; snd_mpu401_devices++; } err = pnp_register_driver(&snd_mpu401_pnp_driver); if (!err) pnp_registered = 1; if (!snd_mpu401_devices) { #ifdef MODULE printk(KERN_ERR "MPU-401 device not found or device busy\n"); #endif snd_mpu401_unregister_all(); return -ENODEV; } return 0; } static void __exit alsa_card_mpu401_exit(void) { snd_mpu401_unregister_all(); } module_init(alsa_card_mpu401_init) module_exit(alsa_card_mpu401_exit)
linux-master
sound/drivers/mpu401/mpu401.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * LED state routines for driver control interface * Copyright (c) 2021 by Jaroslav Kysela <[email protected]> */ #include <linux/slab.h> #include <linux/module.h> #include <linux/leds.h> #include <sound/core.h> #include <sound/control.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("ALSA control interface to LED trigger code."); MODULE_LICENSE("GPL"); #define MAX_LED (((SNDRV_CTL_ELEM_ACCESS_MIC_LED - SNDRV_CTL_ELEM_ACCESS_SPK_LED) \ >> SNDRV_CTL_ELEM_ACCESS_LED_SHIFT) + 1) #define to_led_card_dev(_dev) \ container_of(_dev, struct snd_ctl_led_card, dev) enum snd_ctl_led_mode { MODE_FOLLOW_MUTE = 0, MODE_FOLLOW_ROUTE, MODE_OFF, MODE_ON, }; struct snd_ctl_led_card { struct device dev; int number; struct snd_ctl_led *led; }; struct snd_ctl_led { struct device dev; struct list_head controls; const char *name; unsigned int group; enum led_audio trigger_type; enum snd_ctl_led_mode mode; struct snd_ctl_led_card *cards[SNDRV_CARDS]; }; struct snd_ctl_led_ctl { struct list_head list; struct snd_card *card; unsigned int access; struct snd_kcontrol *kctl; unsigned int index_offset; }; static DEFINE_MUTEX(snd_ctl_led_mutex); static bool snd_ctl_led_card_valid[SNDRV_CARDS]; static struct snd_ctl_led snd_ctl_leds[MAX_LED] = { { .name = "speaker", .group = (SNDRV_CTL_ELEM_ACCESS_SPK_LED >> SNDRV_CTL_ELEM_ACCESS_LED_SHIFT) - 1, .trigger_type = LED_AUDIO_MUTE, .mode = MODE_FOLLOW_MUTE, }, { .name = "mic", .group = (SNDRV_CTL_ELEM_ACCESS_MIC_LED >> SNDRV_CTL_ELEM_ACCESS_LED_SHIFT) - 1, .trigger_type = LED_AUDIO_MICMUTE, .mode = MODE_FOLLOW_MUTE, }, }; static void snd_ctl_led_sysfs_add(struct snd_card *card); static void snd_ctl_led_sysfs_remove(struct snd_card *card); #define UPDATE_ROUTE(route, cb) \ do { \ int route2 = (cb); \ if (route2 >= 0) \ route = route < 0 ? route2 : (route | route2); \ } while (0) static inline unsigned int access_to_group(unsigned int access) { return ((access & SNDRV_CTL_ELEM_ACCESS_LED_MASK) >> SNDRV_CTL_ELEM_ACCESS_LED_SHIFT) - 1; } static inline unsigned int group_to_access(unsigned int group) { return (group + 1) << SNDRV_CTL_ELEM_ACCESS_LED_SHIFT; } static struct snd_ctl_led *snd_ctl_led_get_by_access(unsigned int access) { unsigned int group = access_to_group(access); if (group >= MAX_LED) return NULL; return &snd_ctl_leds[group]; } /* * A note for callers: * The two static variables info and value are protected using snd_ctl_led_mutex. */ static int snd_ctl_led_get(struct snd_ctl_led_ctl *lctl) { static struct snd_ctl_elem_info info; static struct snd_ctl_elem_value value; struct snd_kcontrol *kctl = lctl->kctl; unsigned int i; int result; memset(&info, 0, sizeof(info)); info.id = kctl->id; info.id.index += lctl->index_offset; info.id.numid += lctl->index_offset; result = kctl->info(kctl, &info); if (result < 0) return -1; memset(&value, 0, sizeof(value)); value.id = info.id; result = kctl->get(kctl, &value); if (result < 0) return -1; if (info.type == SNDRV_CTL_ELEM_TYPE_BOOLEAN || info.type == SNDRV_CTL_ELEM_TYPE_INTEGER) { for (i = 0; i < info.count; i++) if (value.value.integer.value[i] != info.value.integer.min) return 1; } else if (info.type == SNDRV_CTL_ELEM_TYPE_INTEGER64) { for (i = 0; i < info.count; i++) if (value.value.integer64.value[i] != info.value.integer64.min) return 1; } return 0; } static void snd_ctl_led_set_state(struct snd_card *card, unsigned int access, struct snd_kcontrol *kctl, unsigned int ioff) { struct snd_ctl_led *led; struct snd_ctl_led_ctl *lctl; int route; bool found; led = snd_ctl_led_get_by_access(access); if (!led) return; route = -1; found = false; mutex_lock(&snd_ctl_led_mutex); /* the card may not be registered (active) at this point */ if (card && !snd_ctl_led_card_valid[card->number]) { mutex_unlock(&snd_ctl_led_mutex); return; } list_for_each_entry(lctl, &led->controls, list) { if (lctl->kctl == kctl && lctl->index_offset == ioff) found = true; UPDATE_ROUTE(route, snd_ctl_led_get(lctl)); } if (!found && kctl && card) { lctl = kzalloc(sizeof(*lctl), GFP_KERNEL); if (lctl) { lctl->card = card; lctl->access = access; lctl->kctl = kctl; lctl->index_offset = ioff; list_add(&lctl->list, &led->controls); UPDATE_ROUTE(route, snd_ctl_led_get(lctl)); } } mutex_unlock(&snd_ctl_led_mutex); switch (led->mode) { case MODE_OFF: route = 1; break; case MODE_ON: route = 0; break; case MODE_FOLLOW_ROUTE: if (route >= 0) route ^= 1; break; case MODE_FOLLOW_MUTE: /* noop */ break; } if (route >= 0) ledtrig_audio_set(led->trigger_type, route ? LED_OFF : LED_ON); } static struct snd_ctl_led_ctl *snd_ctl_led_find(struct snd_kcontrol *kctl, unsigned int ioff) { struct list_head *controls; struct snd_ctl_led_ctl *lctl; unsigned int group; for (group = 0; group < MAX_LED; group++) { controls = &snd_ctl_leds[group].controls; list_for_each_entry(lctl, controls, list) if (lctl->kctl == kctl && lctl->index_offset == ioff) return lctl; } return NULL; } static unsigned int snd_ctl_led_remove(struct snd_kcontrol *kctl, unsigned int ioff, unsigned int access) { struct snd_ctl_led_ctl *lctl; unsigned int ret = 0; mutex_lock(&snd_ctl_led_mutex); lctl = snd_ctl_led_find(kctl, ioff); if (lctl && (access == 0 || access != lctl->access)) { ret = lctl->access; list_del(&lctl->list); kfree(lctl); } mutex_unlock(&snd_ctl_led_mutex); return ret; } static void snd_ctl_led_notify(struct snd_card *card, unsigned int mask, struct snd_kcontrol *kctl, unsigned int ioff) { struct snd_kcontrol_volatile *vd; unsigned int access, access2; if (mask == SNDRV_CTL_EVENT_MASK_REMOVE) { access = snd_ctl_led_remove(kctl, ioff, 0); if (access) snd_ctl_led_set_state(card, access, NULL, 0); } else if (mask & SNDRV_CTL_EVENT_MASK_INFO) { vd = &kctl->vd[ioff]; access = vd->access & SNDRV_CTL_ELEM_ACCESS_LED_MASK; access2 = snd_ctl_led_remove(kctl, ioff, access); if (access2) snd_ctl_led_set_state(card, access2, NULL, 0); if (access) snd_ctl_led_set_state(card, access, kctl, ioff); } else if ((mask & (SNDRV_CTL_EVENT_MASK_ADD | SNDRV_CTL_EVENT_MASK_VALUE)) != 0) { vd = &kctl->vd[ioff]; access = vd->access & SNDRV_CTL_ELEM_ACCESS_LED_MASK; if (access) snd_ctl_led_set_state(card, access, kctl, ioff); } } static int snd_ctl_led_set_id(int card_number, struct snd_ctl_elem_id *id, unsigned int group, bool set) { struct snd_card *card; struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; unsigned int ioff, access, new_access; int err = 0; card = snd_card_ref(card_number); if (card) { down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); if (kctl) { ioff = snd_ctl_get_ioff(kctl, id); vd = &kctl->vd[ioff]; access = vd->access & SNDRV_CTL_ELEM_ACCESS_LED_MASK; if (access != 0 && access != group_to_access(group)) { err = -EXDEV; goto unlock; } new_access = vd->access & ~SNDRV_CTL_ELEM_ACCESS_LED_MASK; if (set) new_access |= group_to_access(group); if (new_access != vd->access) { vd->access = new_access; snd_ctl_led_notify(card, SNDRV_CTL_EVENT_MASK_INFO, kctl, ioff); } } else { err = -ENOENT; } unlock: up_write(&card->controls_rwsem); snd_card_unref(card); } else { err = -ENXIO; } return err; } static void snd_ctl_led_refresh(void) { unsigned int group; for (group = 0; group < MAX_LED; group++) snd_ctl_led_set_state(NULL, group_to_access(group), NULL, 0); } static void snd_ctl_led_ctl_destroy(struct snd_ctl_led_ctl *lctl) { list_del(&lctl->list); kfree(lctl); } static void snd_ctl_led_clean(struct snd_card *card) { unsigned int group; struct snd_ctl_led *led; struct snd_ctl_led_ctl *lctl; for (group = 0; group < MAX_LED; group++) { led = &snd_ctl_leds[group]; repeat: list_for_each_entry(lctl, &led->controls, list) if (!card || lctl->card == card) { snd_ctl_led_ctl_destroy(lctl); goto repeat; } } } static int snd_ctl_led_reset(int card_number, unsigned int group) { struct snd_card *card; struct snd_ctl_led *led; struct snd_ctl_led_ctl *lctl; struct snd_kcontrol_volatile *vd; bool change = false; card = snd_card_ref(card_number); if (!card) return -ENXIO; mutex_lock(&snd_ctl_led_mutex); if (!snd_ctl_led_card_valid[card_number]) { mutex_unlock(&snd_ctl_led_mutex); snd_card_unref(card); return -ENXIO; } led = &snd_ctl_leds[group]; repeat: list_for_each_entry(lctl, &led->controls, list) if (lctl->card == card) { vd = &lctl->kctl->vd[lctl->index_offset]; vd->access &= ~group_to_access(group); snd_ctl_led_ctl_destroy(lctl); change = true; goto repeat; } mutex_unlock(&snd_ctl_led_mutex); if (change) snd_ctl_led_set_state(NULL, group_to_access(group), NULL, 0); snd_card_unref(card); return 0; } static void snd_ctl_led_register(struct snd_card *card) { struct snd_kcontrol *kctl; unsigned int ioff; if (snd_BUG_ON(card->number < 0 || card->number >= ARRAY_SIZE(snd_ctl_led_card_valid))) return; mutex_lock(&snd_ctl_led_mutex); snd_ctl_led_card_valid[card->number] = true; mutex_unlock(&snd_ctl_led_mutex); /* the register callback is already called with held card->controls_rwsem */ list_for_each_entry(kctl, &card->controls, list) for (ioff = 0; ioff < kctl->count; ioff++) snd_ctl_led_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, kctl, ioff); snd_ctl_led_refresh(); snd_ctl_led_sysfs_add(card); } static void snd_ctl_led_disconnect(struct snd_card *card) { snd_ctl_led_sysfs_remove(card); mutex_lock(&snd_ctl_led_mutex); snd_ctl_led_card_valid[card->number] = false; snd_ctl_led_clean(card); mutex_unlock(&snd_ctl_led_mutex); snd_ctl_led_refresh(); } static void snd_ctl_led_card_release(struct device *dev) { struct snd_ctl_led_card *led_card = to_led_card_dev(dev); kfree(led_card); } static void snd_ctl_led_release(struct device *dev) { } static void snd_ctl_led_dev_release(struct device *dev) { } /* * sysfs */ static ssize_t mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev); const char *str = NULL; switch (led->mode) { case MODE_FOLLOW_MUTE: str = "follow-mute"; break; case MODE_FOLLOW_ROUTE: str = "follow-route"; break; case MODE_ON: str = "on"; break; case MODE_OFF: str = "off"; break; } return sysfs_emit(buf, "%s\n", str); } static ssize_t mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev); char _buf[16]; size_t l = min(count, sizeof(_buf) - 1); enum snd_ctl_led_mode mode; memcpy(_buf, buf, l); _buf[l] = '\0'; if (strstr(_buf, "mute")) mode = MODE_FOLLOW_MUTE; else if (strstr(_buf, "route")) mode = MODE_FOLLOW_ROUTE; else if (strncmp(_buf, "off", 3) == 0 || strncmp(_buf, "0", 1) == 0) mode = MODE_OFF; else if (strncmp(_buf, "on", 2) == 0 || strncmp(_buf, "1", 1) == 0) mode = MODE_ON; else return count; mutex_lock(&snd_ctl_led_mutex); led->mode = mode; mutex_unlock(&snd_ctl_led_mutex); snd_ctl_led_set_state(NULL, group_to_access(led->group), NULL, 0); return count; } static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_ctl_led *led = container_of(dev, struct snd_ctl_led, dev); return sysfs_emit(buf, "%u\n", ledtrig_audio_get(led->trigger_type)); } static DEVICE_ATTR_RW(mode); static DEVICE_ATTR_RO(brightness); static struct attribute *snd_ctl_led_dev_attrs[] = { &dev_attr_mode.attr, &dev_attr_brightness.attr, NULL, }; static const struct attribute_group snd_ctl_led_dev_attr_group = { .attrs = snd_ctl_led_dev_attrs, }; static const struct attribute_group *snd_ctl_led_dev_attr_groups[] = { &snd_ctl_led_dev_attr_group, NULL, }; static char *find_eos(char *s) { while (*s && *s != ',') s++; if (*s) s++; return s; } static char *parse_uint(char *s, unsigned int *val) { unsigned long long res; if (kstrtoull(s, 10, &res)) res = 0; *val = res; return find_eos(s); } static char *parse_string(char *s, char *val, size_t val_size) { if (*s == '"' || *s == '\'') { char c = *s; s++; while (*s && *s != c) { if (val_size > 1) { *val++ = *s; val_size--; } s++; } } else { while (*s && *s != ',') { if (val_size > 1) { *val++ = *s; val_size--; } s++; } } *val = '\0'; if (*s) s++; return s; } static char *parse_iface(char *s, snd_ctl_elem_iface_t *val) { if (!strncasecmp(s, "card", 4)) *val = SNDRV_CTL_ELEM_IFACE_CARD; else if (!strncasecmp(s, "mixer", 5)) *val = SNDRV_CTL_ELEM_IFACE_MIXER; return find_eos(s); } /* * These types of input strings are accepted: * * unsigned integer - numid (equivaled to numid=UINT) * string - basic mixer name (equivalent to iface=MIXER,name=STR) * numid=UINT * [iface=MIXER,][device=UINT,][subdevice=UINT,]name=STR[,index=UINT] */ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, size_t count, bool attach) { char buf2[256], *s, *os; struct snd_ctl_elem_id id; int err; if (strscpy(buf2, buf, sizeof(buf2)) < 0) return -E2BIG; memset(&id, 0, sizeof(id)); id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; s = buf2; while (*s) { os = s; if (!strncasecmp(s, "numid=", 6)) { s = parse_uint(s + 6, &id.numid); } else if (!strncasecmp(s, "iface=", 6)) { s = parse_iface(s + 6, &id.iface); } else if (!strncasecmp(s, "device=", 7)) { s = parse_uint(s + 7, &id.device); } else if (!strncasecmp(s, "subdevice=", 10)) { s = parse_uint(s + 10, &id.subdevice); } else if (!strncasecmp(s, "name=", 5)) { s = parse_string(s + 5, id.name, sizeof(id.name)); } else if (!strncasecmp(s, "index=", 6)) { s = parse_uint(s + 6, &id.index); } else if (s == buf2) { while (*s) { if (*s < '0' || *s > '9') break; s++; } if (*s == '\0') parse_uint(buf2, &id.numid); else { for (; *s >= ' '; s++); *s = '\0'; strscpy(id.name, buf2, sizeof(id.name)); } break; } if (*s == ',') s++; if (s == os) break; } err = snd_ctl_led_set_id(led_card->number, &id, led_card->led->group, attach); if (err < 0) return err; return count; } static ssize_t attach_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); return set_led_id(led_card, buf, count, true); } static ssize_t detach_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); return set_led_id(led_card, buf, count, false); } static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); int err; if (count > 0 && buf[0] == '1') { err = snd_ctl_led_reset(led_card->number, led_card->led->group); if (err < 0) return err; } return count; } static ssize_t list_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); struct snd_card *card; struct snd_ctl_led_ctl *lctl; size_t l = 0; card = snd_card_ref(led_card->number); if (!card) return -ENXIO; down_read(&card->controls_rwsem); mutex_lock(&snd_ctl_led_mutex); if (snd_ctl_led_card_valid[led_card->number]) { list_for_each_entry(lctl, &led_card->led->controls, list) { if (lctl->card != card) continue; if (l) l += sysfs_emit_at(buf, l, " "); l += sysfs_emit_at(buf, l, "%u", lctl->kctl->id.numid + lctl->index_offset); } } mutex_unlock(&snd_ctl_led_mutex); up_read(&card->controls_rwsem); snd_card_unref(card); return l; } static DEVICE_ATTR_WO(attach); static DEVICE_ATTR_WO(detach); static DEVICE_ATTR_WO(reset); static DEVICE_ATTR_RO(list); static struct attribute *snd_ctl_led_card_attrs[] = { &dev_attr_attach.attr, &dev_attr_detach.attr, &dev_attr_reset.attr, &dev_attr_list.attr, NULL, }; static const struct attribute_group snd_ctl_led_card_attr_group = { .attrs = snd_ctl_led_card_attrs, }; static const struct attribute_group *snd_ctl_led_card_attr_groups[] = { &snd_ctl_led_card_attr_group, NULL, }; static struct device snd_ctl_led_dev; static void snd_ctl_led_sysfs_add(struct snd_card *card) { unsigned int group; struct snd_ctl_led_card *led_card; struct snd_ctl_led *led; char link_name[32]; for (group = 0; group < MAX_LED; group++) { led = &snd_ctl_leds[group]; led_card = kzalloc(sizeof(*led_card), GFP_KERNEL); if (!led_card) goto cerr2; led_card->number = card->number; led_card->led = led; device_initialize(&led_card->dev); led_card->dev.release = snd_ctl_led_card_release; if (dev_set_name(&led_card->dev, "card%d", card->number) < 0) goto cerr; led_card->dev.parent = &led->dev; led_card->dev.groups = snd_ctl_led_card_attr_groups; if (device_add(&led_card->dev)) goto cerr; led->cards[card->number] = led_card; snprintf(link_name, sizeof(link_name), "led-%s", led->name); WARN(sysfs_create_link(&card->ctl_dev->kobj, &led_card->dev.kobj, link_name), "can't create symlink to controlC%i device\n", card->number); WARN(sysfs_create_link(&led_card->dev.kobj, &card->card_dev.kobj, "card"), "can't create symlink to card%i\n", card->number); continue; cerr: put_device(&led_card->dev); cerr2: printk(KERN_ERR "snd_ctl_led: unable to add card%d", card->number); } } static void snd_ctl_led_sysfs_remove(struct snd_card *card) { unsigned int group; struct snd_ctl_led_card *led_card; struct snd_ctl_led *led; char link_name[32]; for (group = 0; group < MAX_LED; group++) { led = &snd_ctl_leds[group]; led_card = led->cards[card->number]; if (!led_card) continue; snprintf(link_name, sizeof(link_name), "led-%s", led->name); sysfs_remove_link(&card->ctl_dev->kobj, link_name); sysfs_remove_link(&led_card->dev.kobj, "card"); device_unregister(&led_card->dev); led->cards[card->number] = NULL; } } /* * Control layer registration */ static struct snd_ctl_layer_ops snd_ctl_led_lops = { .module_name = SND_CTL_LAYER_MODULE_LED, .lregister = snd_ctl_led_register, .ldisconnect = snd_ctl_led_disconnect, .lnotify = snd_ctl_led_notify, }; static int __init snd_ctl_led_init(void) { struct snd_ctl_led *led; unsigned int group; device_initialize(&snd_ctl_led_dev); snd_ctl_led_dev.class = &sound_class; snd_ctl_led_dev.release = snd_ctl_led_dev_release; dev_set_name(&snd_ctl_led_dev, "ctl-led"); if (device_add(&snd_ctl_led_dev)) { put_device(&snd_ctl_led_dev); return -ENOMEM; } for (group = 0; group < MAX_LED; group++) { led = &snd_ctl_leds[group]; INIT_LIST_HEAD(&led->controls); device_initialize(&led->dev); led->dev.parent = &snd_ctl_led_dev; led->dev.release = snd_ctl_led_release; led->dev.groups = snd_ctl_led_dev_attr_groups; dev_set_name(&led->dev, led->name); if (device_add(&led->dev)) { put_device(&led->dev); for (; group > 0; group--) { led = &snd_ctl_leds[group - 1]; device_unregister(&led->dev); } device_unregister(&snd_ctl_led_dev); return -ENOMEM; } } snd_ctl_register_layer(&snd_ctl_led_lops); return 0; } static void __exit snd_ctl_led_exit(void) { struct snd_ctl_led *led; struct snd_card *card; unsigned int group, card_number; snd_ctl_disconnect_layer(&snd_ctl_led_lops); for (card_number = 0; card_number < SNDRV_CARDS; card_number++) { if (!snd_ctl_led_card_valid[card_number]) continue; card = snd_card_ref(card_number); if (card) { snd_ctl_led_sysfs_remove(card); snd_card_unref(card); } } for (group = 0; group < MAX_LED; group++) { led = &snd_ctl_leds[group]; device_unregister(&led->dev); } device_unregister(&snd_ctl_led_dev); snd_ctl_led_clean(NULL); } module_init(snd_ctl_led_init) module_exit(snd_ctl_led_exit)
linux-master
sound/core/control_led.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Timers abstract layer * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/delay.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/mutex.h> #include <linux/device.h> #include <linux/module.h> #include <linux/string.h> #include <linux/sched/signal.h> #include <sound/core.h> #include <sound/timer.h> #include <sound/control.h> #include <sound/info.h> #include <sound/minors.h> #include <sound/initval.h> #include <linux/kmod.h> /* internal flags */ #define SNDRV_TIMER_IFLG_PAUSED 0x00010000 #define SNDRV_TIMER_IFLG_DEAD 0x00020000 #if IS_ENABLED(CONFIG_SND_HRTIMER) #define DEFAULT_TIMER_LIMIT 4 #else #define DEFAULT_TIMER_LIMIT 1 #endif static int timer_limit = DEFAULT_TIMER_LIMIT; static int timer_tstamp_monotonic = 1; MODULE_AUTHOR("Jaroslav Kysela <[email protected]>, Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("ALSA timer interface"); MODULE_LICENSE("GPL"); module_param(timer_limit, int, 0444); MODULE_PARM_DESC(timer_limit, "Maximum global timers in system."); module_param(timer_tstamp_monotonic, int, 0444); MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default)."); MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER); MODULE_ALIAS("devname:snd/timer"); enum timer_tread_format { TREAD_FORMAT_NONE = 0, TREAD_FORMAT_TIME64, TREAD_FORMAT_TIME32, }; struct snd_timer_tread32 { int event; s32 tstamp_sec; s32 tstamp_nsec; unsigned int val; }; struct snd_timer_tread64 { int event; u8 pad1[4]; s64 tstamp_sec; s64 tstamp_nsec; unsigned int val; u8 pad2[4]; }; struct snd_timer_user { struct snd_timer_instance *timeri; int tread; /* enhanced read with timestamps and events */ unsigned long ticks; unsigned long overrun; int qhead; int qtail; int qused; int queue_size; bool disconnected; struct snd_timer_read *queue; struct snd_timer_tread64 *tqueue; spinlock_t qlock; unsigned long last_resolution; unsigned int filter; struct timespec64 tstamp; /* trigger tstamp */ wait_queue_head_t qchange_sleep; struct snd_fasync *fasync; struct mutex ioctl_lock; }; struct snd_timer_status32 { s32 tstamp_sec; /* Timestamp - last update */ s32 tstamp_nsec; unsigned int resolution; /* current period resolution in ns */ unsigned int lost; /* counter of master tick lost */ unsigned int overrun; /* count of read queue overruns */ unsigned int queue; /* used queue size */ unsigned char reserved[64]; /* reserved */ }; #define SNDRV_TIMER_IOCTL_STATUS32 _IOR('T', 0x14, struct snd_timer_status32) struct snd_timer_status64 { s64 tstamp_sec; /* Timestamp - last update */ s64 tstamp_nsec; unsigned int resolution; /* current period resolution in ns */ unsigned int lost; /* counter of master tick lost */ unsigned int overrun; /* count of read queue overruns */ unsigned int queue; /* used queue size */ unsigned char reserved[64]; /* reserved */ }; #define SNDRV_TIMER_IOCTL_STATUS64 _IOR('T', 0x14, struct snd_timer_status64) /* list of timers */ static LIST_HEAD(snd_timer_list); /* list of slave instances */ static LIST_HEAD(snd_timer_slave_list); /* lock for slave active lists */ static DEFINE_SPINLOCK(slave_active_lock); #define MAX_SLAVE_INSTANCES 1000 static int num_slaves; static DEFINE_MUTEX(register_mutex); static int snd_timer_free(struct snd_timer *timer); static int snd_timer_dev_free(struct snd_device *device); static int snd_timer_dev_register(struct snd_device *device); static int snd_timer_dev_disconnect(struct snd_device *device); static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left); /* * create a timer instance with the given owner string. */ struct snd_timer_instance *snd_timer_instance_new(const char *owner) { struct snd_timer_instance *timeri; timeri = kzalloc(sizeof(*timeri), GFP_KERNEL); if (timeri == NULL) return NULL; timeri->owner = kstrdup(owner, GFP_KERNEL); if (! timeri->owner) { kfree(timeri); return NULL; } INIT_LIST_HEAD(&timeri->open_list); INIT_LIST_HEAD(&timeri->active_list); INIT_LIST_HEAD(&timeri->ack_list); INIT_LIST_HEAD(&timeri->slave_list_head); INIT_LIST_HEAD(&timeri->slave_active_head); return timeri; } EXPORT_SYMBOL(snd_timer_instance_new); void snd_timer_instance_free(struct snd_timer_instance *timeri) { if (timeri) { if (timeri->private_free) timeri->private_free(timeri); kfree(timeri->owner); kfree(timeri); } } EXPORT_SYMBOL(snd_timer_instance_free); /* * find a timer instance from the given timer id */ static struct snd_timer *snd_timer_find(struct snd_timer_id *tid) { struct snd_timer *timer; list_for_each_entry(timer, &snd_timer_list, device_list) { if (timer->tmr_class != tid->dev_class) continue; if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD || timer->tmr_class == SNDRV_TIMER_CLASS_PCM) && (timer->card == NULL || timer->card->number != tid->card)) continue; if (timer->tmr_device != tid->device) continue; if (timer->tmr_subdevice != tid->subdevice) continue; return timer; } return NULL; } #ifdef CONFIG_MODULES static void snd_timer_request(struct snd_timer_id *tid) { switch (tid->dev_class) { case SNDRV_TIMER_CLASS_GLOBAL: if (tid->device < timer_limit) request_module("snd-timer-%i", tid->device); break; case SNDRV_TIMER_CLASS_CARD: case SNDRV_TIMER_CLASS_PCM: if (tid->card < snd_ecards_limit) request_module("snd-card-%i", tid->card); break; default: break; } } #endif /* move the slave if it belongs to the master; return 1 if match */ static int check_matching_master_slave(struct snd_timer_instance *master, struct snd_timer_instance *slave) { if (slave->slave_class != master->slave_class || slave->slave_id != master->slave_id) return 0; if (master->timer->num_instances >= master->timer->max_instances) return -EBUSY; list_move_tail(&slave->open_list, &master->slave_list_head); master->timer->num_instances++; spin_lock_irq(&slave_active_lock); spin_lock(&master->timer->lock); slave->master = master; slave->timer = master->timer; if (slave->flags & SNDRV_TIMER_IFLG_RUNNING) list_add_tail(&slave->active_list, &master->slave_active_head); spin_unlock(&master->timer->lock); spin_unlock_irq(&slave_active_lock); return 1; } /* * look for a master instance matching with the slave id of the given slave. * when found, relink the open_link of the slave. * * call this with register_mutex down. */ static int snd_timer_check_slave(struct snd_timer_instance *slave) { struct snd_timer *timer; struct snd_timer_instance *master; int err = 0; /* FIXME: it's really dumb to look up all entries.. */ list_for_each_entry(timer, &snd_timer_list, device_list) { list_for_each_entry(master, &timer->open_list_head, open_list) { err = check_matching_master_slave(master, slave); if (err != 0) /* match found or error */ goto out; } } out: return err < 0 ? err : 0; } /* * look for slave instances matching with the slave id of the given master. * when found, relink the open_link of slaves. * * call this with register_mutex down. */ static int snd_timer_check_master(struct snd_timer_instance *master) { struct snd_timer_instance *slave, *tmp; int err = 0; /* check all pending slaves */ list_for_each_entry_safe(slave, tmp, &snd_timer_slave_list, open_list) { err = check_matching_master_slave(master, slave); if (err < 0) break; } return err < 0 ? err : 0; } static void snd_timer_close_locked(struct snd_timer_instance *timeri, struct device **card_devp_to_put); /* * open a timer instance * when opening a master, the slave id must be here given. */ int snd_timer_open(struct snd_timer_instance *timeri, struct snd_timer_id *tid, unsigned int slave_id) { struct snd_timer *timer; struct device *card_dev_to_put = NULL; int err; mutex_lock(&register_mutex); if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) { /* open a slave instance */ if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) { pr_debug("ALSA: timer: invalid slave class %i\n", tid->dev_sclass); err = -EINVAL; goto unlock; } if (num_slaves >= MAX_SLAVE_INSTANCES) { err = -EBUSY; goto unlock; } timeri->slave_class = tid->dev_sclass; timeri->slave_id = tid->device; timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; list_add_tail(&timeri->open_list, &snd_timer_slave_list); num_slaves++; err = snd_timer_check_slave(timeri); goto list_added; } /* open a master instance */ timer = snd_timer_find(tid); #ifdef CONFIG_MODULES if (!timer) { mutex_unlock(&register_mutex); snd_timer_request(tid); mutex_lock(&register_mutex); timer = snd_timer_find(tid); } #endif if (!timer) { err = -ENODEV; goto unlock; } if (!list_empty(&timer->open_list_head)) { struct snd_timer_instance *t = list_entry(timer->open_list_head.next, struct snd_timer_instance, open_list); if (t->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { err = -EBUSY; goto unlock; } } if (timer->num_instances >= timer->max_instances) { err = -EBUSY; goto unlock; } if (!try_module_get(timer->module)) { err = -EBUSY; goto unlock; } /* take a card refcount for safe disconnection */ if (timer->card) { get_device(&timer->card->card_dev); card_dev_to_put = &timer->card->card_dev; } if (list_empty(&timer->open_list_head) && timer->hw.open) { err = timer->hw.open(timer); if (err) { module_put(timer->module); goto unlock; } } timeri->timer = timer; timeri->slave_class = tid->dev_sclass; timeri->slave_id = slave_id; list_add_tail(&timeri->open_list, &timer->open_list_head); timer->num_instances++; err = snd_timer_check_master(timeri); list_added: if (err < 0) snd_timer_close_locked(timeri, &card_dev_to_put); unlock: mutex_unlock(&register_mutex); /* put_device() is called after unlock for avoiding deadlock */ if (err < 0 && card_dev_to_put) put_device(card_dev_to_put); return err; } EXPORT_SYMBOL(snd_timer_open); /* * close a timer instance * call this with register_mutex down. */ static void snd_timer_close_locked(struct snd_timer_instance *timeri, struct device **card_devp_to_put) { struct snd_timer *timer = timeri->timer; struct snd_timer_instance *slave, *tmp; if (timer) { spin_lock_irq(&timer->lock); timeri->flags |= SNDRV_TIMER_IFLG_DEAD; spin_unlock_irq(&timer->lock); } if (!list_empty(&timeri->open_list)) { list_del_init(&timeri->open_list); if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) num_slaves--; } /* force to stop the timer */ snd_timer_stop(timeri); if (timer) { timer->num_instances--; /* wait, until the active callback is finished */ spin_lock_irq(&timer->lock); while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) { spin_unlock_irq(&timer->lock); udelay(10); spin_lock_irq(&timer->lock); } spin_unlock_irq(&timer->lock); /* remove slave links */ spin_lock_irq(&slave_active_lock); spin_lock(&timer->lock); timeri->timer = NULL; list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head, open_list) { list_move_tail(&slave->open_list, &snd_timer_slave_list); timer->num_instances--; slave->master = NULL; slave->timer = NULL; list_del_init(&slave->ack_list); list_del_init(&slave->active_list); } spin_unlock(&timer->lock); spin_unlock_irq(&slave_active_lock); /* slave doesn't need to release timer resources below */ if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) timer = NULL; } if (timer) { if (list_empty(&timer->open_list_head) && timer->hw.close) timer->hw.close(timer); /* release a card refcount for safe disconnection */ if (timer->card) *card_devp_to_put = &timer->card->card_dev; module_put(timer->module); } } /* * close a timer instance */ void snd_timer_close(struct snd_timer_instance *timeri) { struct device *card_dev_to_put = NULL; if (snd_BUG_ON(!timeri)) return; mutex_lock(&register_mutex); snd_timer_close_locked(timeri, &card_dev_to_put); mutex_unlock(&register_mutex); /* put_device() is called after unlock for avoiding deadlock */ if (card_dev_to_put) put_device(card_dev_to_put); } EXPORT_SYMBOL(snd_timer_close); static unsigned long snd_timer_hw_resolution(struct snd_timer *timer) { if (timer->hw.c_resolution) return timer->hw.c_resolution(timer); else return timer->hw.resolution; } unsigned long snd_timer_resolution(struct snd_timer_instance *timeri) { struct snd_timer * timer; unsigned long ret = 0; unsigned long flags; if (timeri == NULL) return 0; timer = timeri->timer; if (timer) { spin_lock_irqsave(&timer->lock, flags); ret = snd_timer_hw_resolution(timer); spin_unlock_irqrestore(&timer->lock, flags); } return ret; } EXPORT_SYMBOL(snd_timer_resolution); static void snd_timer_notify1(struct snd_timer_instance *ti, int event) { struct snd_timer *timer = ti->timer; unsigned long resolution = 0; struct snd_timer_instance *ts; struct timespec64 tstamp; if (timer_tstamp_monotonic) ktime_get_ts64(&tstamp); else ktime_get_real_ts64(&tstamp); if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START || event > SNDRV_TIMER_EVENT_PAUSE)) return; if (timer && (event == SNDRV_TIMER_EVENT_START || event == SNDRV_TIMER_EVENT_CONTINUE)) resolution = snd_timer_hw_resolution(timer); if (ti->ccallback) ti->ccallback(ti, event, &tstamp, resolution); if (ti->flags & SNDRV_TIMER_IFLG_SLAVE) return; if (timer == NULL) return; if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) return; event += 10; /* convert to SNDRV_TIMER_EVENT_MXXX */ list_for_each_entry(ts, &ti->slave_active_head, active_list) if (ts->ccallback) ts->ccallback(ts, event, &tstamp, resolution); } /* start/continue a master timer */ static int snd_timer_start1(struct snd_timer_instance *timeri, bool start, unsigned long ticks) { struct snd_timer *timer; int result; unsigned long flags; timer = timeri->timer; if (!timer) return -EINVAL; spin_lock_irqsave(&timer->lock, flags); if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) { result = -EINVAL; goto unlock; } if (timer->card && timer->card->shutdown) { result = -ENODEV; goto unlock; } if (timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START)) { result = -EBUSY; goto unlock; } if (start) timeri->ticks = timeri->cticks = ticks; else if (!timeri->cticks) timeri->cticks = 1; timeri->pticks = 0; list_move_tail(&timeri->active_list, &timer->active_list_head); if (timer->running) { if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) goto __start_now; timer->flags |= SNDRV_TIMER_FLG_RESCHED; timeri->flags |= SNDRV_TIMER_IFLG_START; result = 1; /* delayed start */ } else { if (start) timer->sticks = ticks; timer->hw.start(timer); __start_now: timer->running++; timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; result = 0; } snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START : SNDRV_TIMER_EVENT_CONTINUE); unlock: spin_unlock_irqrestore(&timer->lock, flags); return result; } /* start/continue a slave timer */ static int snd_timer_start_slave(struct snd_timer_instance *timeri, bool start) { unsigned long flags; int err; spin_lock_irqsave(&slave_active_lock, flags); if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) { err = -EINVAL; goto unlock; } if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) { err = -EBUSY; goto unlock; } timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; if (timeri->master && timeri->timer) { spin_lock(&timeri->timer->lock); list_add_tail(&timeri->active_list, &timeri->master->slave_active_head); snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START : SNDRV_TIMER_EVENT_CONTINUE); spin_unlock(&timeri->timer->lock); } err = 1; /* delayed start */ unlock: spin_unlock_irqrestore(&slave_active_lock, flags); return err; } /* stop/pause a master timer */ static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop) { struct snd_timer *timer; int result = 0; unsigned long flags; timer = timeri->timer; if (!timer) return -EINVAL; spin_lock_irqsave(&timer->lock, flags); list_del_init(&timeri->ack_list); list_del_init(&timeri->active_list); if (!(timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START))) { result = -EBUSY; goto unlock; } if (timer->card && timer->card->shutdown) goto unlock; if (stop) { timeri->cticks = timeri->ticks; timeri->pticks = 0; } if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) && !(--timer->running)) { timer->hw.stop(timer); if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; snd_timer_reschedule(timer, 0); if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; timer->hw.start(timer); } } } timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); if (stop) timeri->flags &= ~SNDRV_TIMER_IFLG_PAUSED; else timeri->flags |= SNDRV_TIMER_IFLG_PAUSED; snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : SNDRV_TIMER_EVENT_PAUSE); unlock: spin_unlock_irqrestore(&timer->lock, flags); return result; } /* stop/pause a slave timer */ static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop) { unsigned long flags; bool running; spin_lock_irqsave(&slave_active_lock, flags); running = timeri->flags & SNDRV_TIMER_IFLG_RUNNING; timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING; if (timeri->timer) { spin_lock(&timeri->timer->lock); list_del_init(&timeri->ack_list); list_del_init(&timeri->active_list); if (running) snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP : SNDRV_TIMER_EVENT_PAUSE); spin_unlock(&timeri->timer->lock); } spin_unlock_irqrestore(&slave_active_lock, flags); return running ? 0 : -EBUSY; } /* * start the timer instance */ int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks) { if (timeri == NULL || ticks < 1) return -EINVAL; if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) return snd_timer_start_slave(timeri, true); else return snd_timer_start1(timeri, true, ticks); } EXPORT_SYMBOL(snd_timer_start); /* * stop the timer instance. * * do not call this from the timer callback! */ int snd_timer_stop(struct snd_timer_instance *timeri) { if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) return snd_timer_stop_slave(timeri, true); else return snd_timer_stop1(timeri, true); } EXPORT_SYMBOL(snd_timer_stop); /* * start again.. the tick is kept. */ int snd_timer_continue(struct snd_timer_instance *timeri) { /* timer can continue only after pause */ if (!(timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) return -EINVAL; if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) return snd_timer_start_slave(timeri, false); else return snd_timer_start1(timeri, false, 0); } EXPORT_SYMBOL(snd_timer_continue); /* * pause.. remember the ticks left */ int snd_timer_pause(struct snd_timer_instance * timeri) { if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) return snd_timer_stop_slave(timeri, false); else return snd_timer_stop1(timeri, false); } EXPORT_SYMBOL(snd_timer_pause); /* * reschedule the timer * * start pending instances and check the scheduling ticks. * when the scheduling ticks is changed set CHANGE flag to reprogram the timer. */ static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left) { struct snd_timer_instance *ti; unsigned long ticks = ~0UL; list_for_each_entry(ti, &timer->active_list_head, active_list) { if (ti->flags & SNDRV_TIMER_IFLG_START) { ti->flags &= ~SNDRV_TIMER_IFLG_START; ti->flags |= SNDRV_TIMER_IFLG_RUNNING; timer->running++; } if (ti->flags & SNDRV_TIMER_IFLG_RUNNING) { if (ticks > ti->cticks) ticks = ti->cticks; } } if (ticks == ~0UL) { timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; return; } if (ticks > timer->hw.ticks) ticks = timer->hw.ticks; if (ticks_left != ticks) timer->flags |= SNDRV_TIMER_FLG_CHANGE; timer->sticks = ticks; } /* call callbacks in timer ack list */ static void snd_timer_process_callbacks(struct snd_timer *timer, struct list_head *head) { struct snd_timer_instance *ti; unsigned long resolution, ticks; while (!list_empty(head)) { ti = list_first_entry(head, struct snd_timer_instance, ack_list); /* remove from ack_list and make empty */ list_del_init(&ti->ack_list); if (!(ti->flags & SNDRV_TIMER_IFLG_DEAD)) { ticks = ti->pticks; ti->pticks = 0; resolution = ti->resolution; ti->flags |= SNDRV_TIMER_IFLG_CALLBACK; spin_unlock(&timer->lock); if (ti->callback) ti->callback(ti, resolution, ticks); spin_lock(&timer->lock); ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK; } } } /* clear pending instances from ack list */ static void snd_timer_clear_callbacks(struct snd_timer *timer, struct list_head *head) { unsigned long flags; spin_lock_irqsave(&timer->lock, flags); while (!list_empty(head)) list_del_init(head->next); spin_unlock_irqrestore(&timer->lock, flags); } /* * timer work * */ static void snd_timer_work(struct work_struct *work) { struct snd_timer *timer = container_of(work, struct snd_timer, task_work); unsigned long flags; if (timer->card && timer->card->shutdown) { snd_timer_clear_callbacks(timer, &timer->sack_list_head); return; } spin_lock_irqsave(&timer->lock, flags); snd_timer_process_callbacks(timer, &timer->sack_list_head); spin_unlock_irqrestore(&timer->lock, flags); } /* * timer interrupt * * ticks_left is usually equal to timer->sticks. * */ void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) { struct snd_timer_instance *ti, *ts, *tmp; unsigned long resolution; struct list_head *ack_list_head; unsigned long flags; bool use_work = false; if (timer == NULL) return; if (timer->card && timer->card->shutdown) { snd_timer_clear_callbacks(timer, &timer->ack_list_head); return; } spin_lock_irqsave(&timer->lock, flags); /* remember the current resolution */ resolution = snd_timer_hw_resolution(timer); /* loop for all active instances * Here we cannot use list_for_each_entry because the active_list of a * processed instance is relinked to done_list_head before the callback * is called. */ list_for_each_entry_safe(ti, tmp, &timer->active_list_head, active_list) { if (ti->flags & SNDRV_TIMER_IFLG_DEAD) continue; if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING)) continue; ti->pticks += ticks_left; ti->resolution = resolution; if (ti->cticks < ticks_left) ti->cticks = 0; else ti->cticks -= ticks_left; if (ti->cticks) /* not expired */ continue; if (ti->flags & SNDRV_TIMER_IFLG_AUTO) { ti->cticks = ti->ticks; } else { ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING; --timer->running; list_del_init(&ti->active_list); } if ((timer->hw.flags & SNDRV_TIMER_HW_WORK) || (ti->flags & SNDRV_TIMER_IFLG_FAST)) ack_list_head = &timer->ack_list_head; else ack_list_head = &timer->sack_list_head; if (list_empty(&ti->ack_list)) list_add_tail(&ti->ack_list, ack_list_head); list_for_each_entry(ts, &ti->slave_active_head, active_list) { ts->pticks = ti->pticks; ts->resolution = resolution; if (list_empty(&ts->ack_list)) list_add_tail(&ts->ack_list, ack_list_head); } } if (timer->flags & SNDRV_TIMER_FLG_RESCHED) snd_timer_reschedule(timer, timer->sticks); if (timer->running) { if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { timer->hw.stop(timer); timer->flags |= SNDRV_TIMER_FLG_CHANGE; } if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { /* restart timer */ timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; timer->hw.start(timer); } } else { timer->hw.stop(timer); } /* now process all fast callbacks */ snd_timer_process_callbacks(timer, &timer->ack_list_head); /* do we have any slow callbacks? */ use_work = !list_empty(&timer->sack_list_head); spin_unlock_irqrestore(&timer->lock, flags); if (use_work) queue_work(system_highpri_wq, &timer->task_work); } EXPORT_SYMBOL(snd_timer_interrupt); /* */ int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer) { struct snd_timer *timer; int err; static const struct snd_device_ops ops = { .dev_free = snd_timer_dev_free, .dev_register = snd_timer_dev_register, .dev_disconnect = snd_timer_dev_disconnect, }; if (snd_BUG_ON(!tid)) return -EINVAL; if (tid->dev_class == SNDRV_TIMER_CLASS_CARD || tid->dev_class == SNDRV_TIMER_CLASS_PCM) { if (WARN_ON(!card)) return -EINVAL; } if (rtimer) *rtimer = NULL; timer = kzalloc(sizeof(*timer), GFP_KERNEL); if (!timer) return -ENOMEM; timer->tmr_class = tid->dev_class; timer->card = card; timer->tmr_device = tid->device; timer->tmr_subdevice = tid->subdevice; if (id) strscpy(timer->id, id, sizeof(timer->id)); timer->sticks = 1; INIT_LIST_HEAD(&timer->device_list); INIT_LIST_HEAD(&timer->open_list_head); INIT_LIST_HEAD(&timer->active_list_head); INIT_LIST_HEAD(&timer->ack_list_head); INIT_LIST_HEAD(&timer->sack_list_head); spin_lock_init(&timer->lock); INIT_WORK(&timer->task_work, snd_timer_work); timer->max_instances = 1000; /* default limit per timer */ if (card != NULL) { timer->module = card->module; err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops); if (err < 0) { snd_timer_free(timer); return err; } } if (rtimer) *rtimer = timer; return 0; } EXPORT_SYMBOL(snd_timer_new); static int snd_timer_free(struct snd_timer *timer) { if (!timer) return 0; mutex_lock(&register_mutex); if (! list_empty(&timer->open_list_head)) { struct list_head *p, *n; struct snd_timer_instance *ti; pr_warn("ALSA: timer %p is busy?\n", timer); list_for_each_safe(p, n, &timer->open_list_head) { list_del_init(p); ti = list_entry(p, struct snd_timer_instance, open_list); ti->timer = NULL; } } list_del(&timer->device_list); mutex_unlock(&register_mutex); if (timer->private_free) timer->private_free(timer); kfree(timer); return 0; } static int snd_timer_dev_free(struct snd_device *device) { struct snd_timer *timer = device->device_data; return snd_timer_free(timer); } static int snd_timer_dev_register(struct snd_device *dev) { struct snd_timer *timer = dev->device_data; struct snd_timer *timer1; if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop)) return -ENXIO; if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && !timer->hw.resolution && timer->hw.c_resolution == NULL) return -EINVAL; mutex_lock(&register_mutex); list_for_each_entry(timer1, &snd_timer_list, device_list) { if (timer1->tmr_class > timer->tmr_class) break; if (timer1->tmr_class < timer->tmr_class) continue; if (timer1->card && timer->card) { if (timer1->card->number > timer->card->number) break; if (timer1->card->number < timer->card->number) continue; } if (timer1->tmr_device > timer->tmr_device) break; if (timer1->tmr_device < timer->tmr_device) continue; if (timer1->tmr_subdevice > timer->tmr_subdevice) break; if (timer1->tmr_subdevice < timer->tmr_subdevice) continue; /* conflicts.. */ mutex_unlock(&register_mutex); return -EBUSY; } list_add_tail(&timer->device_list, &timer1->device_list); mutex_unlock(&register_mutex); return 0; } static int snd_timer_dev_disconnect(struct snd_device *device) { struct snd_timer *timer = device->device_data; struct snd_timer_instance *ti; mutex_lock(&register_mutex); list_del_init(&timer->device_list); /* wake up pending sleepers */ list_for_each_entry(ti, &timer->open_list_head, open_list) { if (ti->disconnect) ti->disconnect(ti); } mutex_unlock(&register_mutex); return 0; } void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp) { unsigned long flags; unsigned long resolution = 0; struct snd_timer_instance *ti, *ts; if (timer->card && timer->card->shutdown) return; if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) return; if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_MSTART || event > SNDRV_TIMER_EVENT_MRESUME)) return; spin_lock_irqsave(&timer->lock, flags); if (event == SNDRV_TIMER_EVENT_MSTART || event == SNDRV_TIMER_EVENT_MCONTINUE || event == SNDRV_TIMER_EVENT_MRESUME) resolution = snd_timer_hw_resolution(timer); list_for_each_entry(ti, &timer->active_list_head, active_list) { if (ti->ccallback) ti->ccallback(ti, event, tstamp, resolution); list_for_each_entry(ts, &ti->slave_active_head, active_list) if (ts->ccallback) ts->ccallback(ts, event, tstamp, resolution); } spin_unlock_irqrestore(&timer->lock, flags); } EXPORT_SYMBOL(snd_timer_notify); /* * exported functions for global timers */ int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer) { struct snd_timer_id tid; tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL; tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; tid.card = -1; tid.device = device; tid.subdevice = 0; return snd_timer_new(NULL, id, &tid, rtimer); } EXPORT_SYMBOL(snd_timer_global_new); int snd_timer_global_free(struct snd_timer *timer) { return snd_timer_free(timer); } EXPORT_SYMBOL(snd_timer_global_free); int snd_timer_global_register(struct snd_timer *timer) { struct snd_device dev; memset(&dev, 0, sizeof(dev)); dev.device_data = timer; return snd_timer_dev_register(&dev); } EXPORT_SYMBOL(snd_timer_global_register); /* * System timer */ struct snd_timer_system_private { struct timer_list tlist; struct snd_timer *snd_timer; unsigned long last_expires; unsigned long last_jiffies; unsigned long correction; }; static void snd_timer_s_function(struct timer_list *t) { struct snd_timer_system_private *priv = from_timer(priv, t, tlist); struct snd_timer *timer = priv->snd_timer; unsigned long jiff = jiffies; if (time_after(jiff, priv->last_expires)) priv->correction += (long)jiff - (long)priv->last_expires; snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies); } static int snd_timer_s_start(struct snd_timer * timer) { struct snd_timer_system_private *priv; unsigned long njiff; priv = (struct snd_timer_system_private *) timer->private_data; njiff = (priv->last_jiffies = jiffies); if (priv->correction > timer->sticks - 1) { priv->correction -= timer->sticks - 1; njiff++; } else { njiff += timer->sticks - priv->correction; priv->correction = 0; } priv->last_expires = njiff; mod_timer(&priv->tlist, njiff); return 0; } static int snd_timer_s_stop(struct snd_timer * timer) { struct snd_timer_system_private *priv; unsigned long jiff; priv = (struct snd_timer_system_private *) timer->private_data; del_timer(&priv->tlist); jiff = jiffies; if (time_before(jiff, priv->last_expires)) timer->sticks = priv->last_expires - jiff; else timer->sticks = 1; priv->correction = 0; return 0; } static int snd_timer_s_close(struct snd_timer *timer) { struct snd_timer_system_private *priv; priv = (struct snd_timer_system_private *)timer->private_data; del_timer_sync(&priv->tlist); return 0; } static const struct snd_timer_hardware snd_timer_system = { .flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_WORK, .resolution = 1000000000L / HZ, .ticks = 10000000L, .close = snd_timer_s_close, .start = snd_timer_s_start, .stop = snd_timer_s_stop }; static void snd_timer_free_system(struct snd_timer *timer) { kfree(timer->private_data); } static int snd_timer_register_system(void) { struct snd_timer *timer; struct snd_timer_system_private *priv; int err; err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer); if (err < 0) return err; strcpy(timer->name, "system timer"); timer->hw = snd_timer_system; priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (priv == NULL) { snd_timer_free(timer); return -ENOMEM; } priv->snd_timer = timer; timer_setup(&priv->tlist, snd_timer_s_function, 0); timer->private_data = priv; timer->private_free = snd_timer_free_system; return snd_timer_global_register(timer); } #ifdef CONFIG_SND_PROC_FS /* * Info interface */ static void snd_timer_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_timer *timer; struct snd_timer_instance *ti; unsigned long resolution; mutex_lock(&register_mutex); list_for_each_entry(timer, &snd_timer_list, device_list) { if (timer->card && timer->card->shutdown) continue; switch (timer->tmr_class) { case SNDRV_TIMER_CLASS_GLOBAL: snd_iprintf(buffer, "G%i: ", timer->tmr_device); break; case SNDRV_TIMER_CLASS_CARD: snd_iprintf(buffer, "C%i-%i: ", timer->card->number, timer->tmr_device); break; case SNDRV_TIMER_CLASS_PCM: snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, timer->tmr_device, timer->tmr_subdevice); break; default: snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, timer->card ? timer->card->number : -1, timer->tmr_device, timer->tmr_subdevice); } snd_iprintf(buffer, "%s :", timer->name); spin_lock_irq(&timer->lock); resolution = snd_timer_hw_resolution(timer); spin_unlock_irq(&timer->lock); if (resolution) snd_iprintf(buffer, " %lu.%03luus (%lu ticks)", resolution / 1000, resolution % 1000, timer->hw.ticks); if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) snd_iprintf(buffer, " SLAVE"); snd_iprintf(buffer, "\n"); list_for_each_entry(ti, &timer->open_list_head, open_list) snd_iprintf(buffer, " Client %s : %s\n", ti->owner ? ti->owner : "unknown", (ti->flags & (SNDRV_TIMER_IFLG_START | SNDRV_TIMER_IFLG_RUNNING)) ? "running" : "stopped"); } mutex_unlock(&register_mutex); } static struct snd_info_entry *snd_timer_proc_entry; static void __init snd_timer_proc_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL); if (entry != NULL) { entry->c.text.read = snd_timer_proc_read; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } } snd_timer_proc_entry = entry; } static void __exit snd_timer_proc_done(void) { snd_info_free_entry(snd_timer_proc_entry); } #else /* !CONFIG_SND_PROC_FS */ #define snd_timer_proc_init() #define snd_timer_proc_done() #endif /* * USER SPACE interface */ static void snd_timer_user_interrupt(struct snd_timer_instance *timeri, unsigned long resolution, unsigned long ticks) { struct snd_timer_user *tu = timeri->callback_data; struct snd_timer_read *r; int prev; spin_lock(&tu->qlock); if (tu->qused > 0) { prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->queue[prev]; if (r->resolution == resolution) { r->ticks += ticks; goto __wake; } } if (tu->qused >= tu->queue_size) { tu->overrun++; } else { r = &tu->queue[tu->qtail++]; tu->qtail %= tu->queue_size; r->resolution = resolution; r->ticks = ticks; tu->qused++; } __wake: spin_unlock(&tu->qlock); snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); wake_up(&tu->qchange_sleep); } static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu, struct snd_timer_tread64 *tread) { if (tu->qused >= tu->queue_size) { tu->overrun++; } else { memcpy(&tu->tqueue[tu->qtail++], tread, sizeof(*tread)); tu->qtail %= tu->queue_size; tu->qused++; } } static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, int event, struct timespec64 *tstamp, unsigned long resolution) { struct snd_timer_user *tu = timeri->callback_data; struct snd_timer_tread64 r1; unsigned long flags; if (event >= SNDRV_TIMER_EVENT_START && event <= SNDRV_TIMER_EVENT_PAUSE) tu->tstamp = *tstamp; if ((tu->filter & (1 << event)) == 0 || !tu->tread) return; memset(&r1, 0, sizeof(r1)); r1.event = event; r1.tstamp_sec = tstamp->tv_sec; r1.tstamp_nsec = tstamp->tv_nsec; r1.val = resolution; spin_lock_irqsave(&tu->qlock, flags); snd_timer_user_append_to_tqueue(tu, &r1); spin_unlock_irqrestore(&tu->qlock, flags); snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); wake_up(&tu->qchange_sleep); } static void snd_timer_user_disconnect(struct snd_timer_instance *timeri) { struct snd_timer_user *tu = timeri->callback_data; tu->disconnected = true; wake_up(&tu->qchange_sleep); } static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, unsigned long resolution, unsigned long ticks) { struct snd_timer_user *tu = timeri->callback_data; struct snd_timer_tread64 *r, r1; struct timespec64 tstamp; int prev, append = 0; memset(&r1, 0, sizeof(r1)); memset(&tstamp, 0, sizeof(tstamp)); spin_lock(&tu->qlock); if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) | (1 << SNDRV_TIMER_EVENT_TICK))) == 0) { spin_unlock(&tu->qlock); return; } if (tu->last_resolution != resolution || ticks > 0) { if (timer_tstamp_monotonic) ktime_get_ts64(&tstamp); else ktime_get_real_ts64(&tstamp); } if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && tu->last_resolution != resolution) { r1.event = SNDRV_TIMER_EVENT_RESOLUTION; r1.tstamp_sec = tstamp.tv_sec; r1.tstamp_nsec = tstamp.tv_nsec; r1.val = resolution; snd_timer_user_append_to_tqueue(tu, &r1); tu->last_resolution = resolution; append++; } if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0) goto __wake; if (ticks == 0) goto __wake; if (tu->qused > 0) { prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; r = &tu->tqueue[prev]; if (r->event == SNDRV_TIMER_EVENT_TICK) { r->tstamp_sec = tstamp.tv_sec; r->tstamp_nsec = tstamp.tv_nsec; r->val += ticks; append++; goto __wake; } } r1.event = SNDRV_TIMER_EVENT_TICK; r1.tstamp_sec = tstamp.tv_sec; r1.tstamp_nsec = tstamp.tv_nsec; r1.val = ticks; snd_timer_user_append_to_tqueue(tu, &r1); append++; __wake: spin_unlock(&tu->qlock); if (append == 0) return; snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); wake_up(&tu->qchange_sleep); } static int realloc_user_queue(struct snd_timer_user *tu, int size) { struct snd_timer_read *queue = NULL; struct snd_timer_tread64 *tqueue = NULL; if (tu->tread) { tqueue = kcalloc(size, sizeof(*tqueue), GFP_KERNEL); if (!tqueue) return -ENOMEM; } else { queue = kcalloc(size, sizeof(*queue), GFP_KERNEL); if (!queue) return -ENOMEM; } spin_lock_irq(&tu->qlock); kfree(tu->queue); kfree(tu->tqueue); tu->queue_size = size; tu->queue = queue; tu->tqueue = tqueue; tu->qhead = tu->qtail = tu->qused = 0; spin_unlock_irq(&tu->qlock); return 0; } static int snd_timer_user_open(struct inode *inode, struct file *file) { struct snd_timer_user *tu; int err; err = stream_open(inode, file); if (err < 0) return err; tu = kzalloc(sizeof(*tu), GFP_KERNEL); if (tu == NULL) return -ENOMEM; spin_lock_init(&tu->qlock); init_waitqueue_head(&tu->qchange_sleep); mutex_init(&tu->ioctl_lock); tu->ticks = 1; if (realloc_user_queue(tu, 128) < 0) { kfree(tu); return -ENOMEM; } file->private_data = tu; return 0; } static int snd_timer_user_release(struct inode *inode, struct file *file) { struct snd_timer_user *tu; if (file->private_data) { tu = file->private_data; file->private_data = NULL; mutex_lock(&tu->ioctl_lock); if (tu->timeri) { snd_timer_close(tu->timeri); snd_timer_instance_free(tu->timeri); } mutex_unlock(&tu->ioctl_lock); snd_fasync_free(tu->fasync); kfree(tu->queue); kfree(tu->tqueue); kfree(tu); } return 0; } static void snd_timer_user_zero_id(struct snd_timer_id *id) { id->dev_class = SNDRV_TIMER_CLASS_NONE; id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; id->card = -1; id->device = -1; id->subdevice = -1; } static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer) { id->dev_class = timer->tmr_class; id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; id->card = timer->card ? timer->card->number : -1; id->device = timer->tmr_device; id->subdevice = timer->tmr_subdevice; } static int snd_timer_user_next_device(struct snd_timer_id __user *_tid) { struct snd_timer_id id; struct snd_timer *timer; struct list_head *p; if (copy_from_user(&id, _tid, sizeof(id))) return -EFAULT; mutex_lock(&register_mutex); if (id.dev_class < 0) { /* first item */ if (list_empty(&snd_timer_list)) snd_timer_user_zero_id(&id); else { timer = list_entry(snd_timer_list.next, struct snd_timer, device_list); snd_timer_user_copy_id(&id, timer); } } else { switch (id.dev_class) { case SNDRV_TIMER_CLASS_GLOBAL: id.device = id.device < 0 ? 0 : id.device + 1; list_for_each(p, &snd_timer_list) { timer = list_entry(p, struct snd_timer, device_list); if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { snd_timer_user_copy_id(&id, timer); break; } if (timer->tmr_device >= id.device) { snd_timer_user_copy_id(&id, timer); break; } } if (p == &snd_timer_list) snd_timer_user_zero_id(&id); break; case SNDRV_TIMER_CLASS_CARD: case SNDRV_TIMER_CLASS_PCM: if (id.card < 0) { id.card = 0; } else { if (id.device < 0) { id.device = 0; } else { if (id.subdevice < 0) id.subdevice = 0; else if (id.subdevice < INT_MAX) id.subdevice++; } } list_for_each(p, &snd_timer_list) { timer = list_entry(p, struct snd_timer, device_list); if (timer->tmr_class > id.dev_class) { snd_timer_user_copy_id(&id, timer); break; } if (timer->tmr_class < id.dev_class) continue; if (timer->card->number > id.card) { snd_timer_user_copy_id(&id, timer); break; } if (timer->card->number < id.card) continue; if (timer->tmr_device > id.device) { snd_timer_user_copy_id(&id, timer); break; } if (timer->tmr_device < id.device) continue; if (timer->tmr_subdevice > id.subdevice) { snd_timer_user_copy_id(&id, timer); break; } if (timer->tmr_subdevice < id.subdevice) continue; snd_timer_user_copy_id(&id, timer); break; } if (p == &snd_timer_list) snd_timer_user_zero_id(&id); break; default: snd_timer_user_zero_id(&id); } } mutex_unlock(&register_mutex); if (copy_to_user(_tid, &id, sizeof(*_tid))) return -EFAULT; return 0; } static int snd_timer_user_ginfo(struct file *file, struct snd_timer_ginfo __user *_ginfo) { struct snd_timer_ginfo *ginfo; struct snd_timer_id tid; struct snd_timer *t; struct list_head *p; int err = 0; ginfo = memdup_user(_ginfo, sizeof(*ginfo)); if (IS_ERR(ginfo)) return PTR_ERR(ginfo); tid = ginfo->tid; memset(ginfo, 0, sizeof(*ginfo)); ginfo->tid = tid; mutex_lock(&register_mutex); t = snd_timer_find(&tid); if (t != NULL) { ginfo->card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; strscpy(ginfo->id, t->id, sizeof(ginfo->id)); strscpy(ginfo->name, t->name, sizeof(ginfo->name)); spin_lock_irq(&t->lock); ginfo->resolution = snd_timer_hw_resolution(t); spin_unlock_irq(&t->lock); if (t->hw.resolution_min > 0) { ginfo->resolution_min = t->hw.resolution_min; ginfo->resolution_max = t->hw.resolution_max; } list_for_each(p, &t->open_list_head) { ginfo->clients++; } } else { err = -ENODEV; } mutex_unlock(&register_mutex); if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo))) err = -EFAULT; kfree(ginfo); return err; } static int timer_set_gparams(struct snd_timer_gparams *gparams) { struct snd_timer *t; int err; mutex_lock(&register_mutex); t = snd_timer_find(&gparams->tid); if (!t) { err = -ENODEV; goto _error; } if (!list_empty(&t->open_list_head)) { err = -EBUSY; goto _error; } if (!t->hw.set_period) { err = -ENOSYS; goto _error; } err = t->hw.set_period(t, gparams->period_num, gparams->period_den); _error: mutex_unlock(&register_mutex); return err; } static int snd_timer_user_gparams(struct file *file, struct snd_timer_gparams __user *_gparams) { struct snd_timer_gparams gparams; if (copy_from_user(&gparams, _gparams, sizeof(gparams))) return -EFAULT; return timer_set_gparams(&gparams); } static int snd_timer_user_gstatus(struct file *file, struct snd_timer_gstatus __user *_gstatus) { struct snd_timer_gstatus gstatus; struct snd_timer_id tid; struct snd_timer *t; int err = 0; if (copy_from_user(&gstatus, _gstatus, sizeof(gstatus))) return -EFAULT; tid = gstatus.tid; memset(&gstatus, 0, sizeof(gstatus)); gstatus.tid = tid; mutex_lock(&register_mutex); t = snd_timer_find(&tid); if (t != NULL) { spin_lock_irq(&t->lock); gstatus.resolution = snd_timer_hw_resolution(t); if (t->hw.precise_resolution) { t->hw.precise_resolution(t, &gstatus.resolution_num, &gstatus.resolution_den); } else { gstatus.resolution_num = gstatus.resolution; gstatus.resolution_den = 1000000000uL; } spin_unlock_irq(&t->lock); } else { err = -ENODEV; } mutex_unlock(&register_mutex); if (err >= 0 && copy_to_user(_gstatus, &gstatus, sizeof(gstatus))) err = -EFAULT; return err; } static int snd_timer_user_tselect(struct file *file, struct snd_timer_select __user *_tselect) { struct snd_timer_user *tu; struct snd_timer_select tselect; char str[32]; int err = 0; tu = file->private_data; if (tu->timeri) { snd_timer_close(tu->timeri); snd_timer_instance_free(tu->timeri); tu->timeri = NULL; } if (copy_from_user(&tselect, _tselect, sizeof(tselect))) { err = -EFAULT; goto __err; } sprintf(str, "application %i", current->pid); if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE) tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION; tu->timeri = snd_timer_instance_new(str); if (!tu->timeri) { err = -ENOMEM; goto __err; } tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST; tu->timeri->callback = tu->tread ? snd_timer_user_tinterrupt : snd_timer_user_interrupt; tu->timeri->ccallback = snd_timer_user_ccallback; tu->timeri->callback_data = (void *)tu; tu->timeri->disconnect = snd_timer_user_disconnect; err = snd_timer_open(tu->timeri, &tselect.id, current->pid); if (err < 0) { snd_timer_instance_free(tu->timeri); tu->timeri = NULL; } __err: return err; } static int snd_timer_user_info(struct file *file, struct snd_timer_info __user *_info) { struct snd_timer_user *tu; struct snd_timer_info *info; struct snd_timer *t; int err = 0; tu = file->private_data; if (!tu->timeri) return -EBADFD; t = tu->timeri->timer; if (!t) return -EBADFD; info = kzalloc(sizeof(*info), GFP_KERNEL); if (! info) return -ENOMEM; info->card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) info->flags |= SNDRV_TIMER_FLG_SLAVE; strscpy(info->id, t->id, sizeof(info->id)); strscpy(info->name, t->name, sizeof(info->name)); spin_lock_irq(&t->lock); info->resolution = snd_timer_hw_resolution(t); spin_unlock_irq(&t->lock); if (copy_to_user(_info, info, sizeof(*_info))) err = -EFAULT; kfree(info); return err; } static int snd_timer_user_params(struct file *file, struct snd_timer_params __user *_params) { struct snd_timer_user *tu; struct snd_timer_params params; struct snd_timer *t; int err; tu = file->private_data; if (!tu->timeri) return -EBADFD; t = tu->timeri->timer; if (!t) return -EBADFD; if (copy_from_user(&params, _params, sizeof(params))) return -EFAULT; if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE)) { u64 resolution; if (params.ticks < 1) { err = -EINVAL; goto _end; } /* Don't allow resolution less than 1ms */ resolution = snd_timer_resolution(tu->timeri); resolution *= params.ticks; if (resolution < 1000000) { err = -EINVAL; goto _end; } } if (params.queue_size > 0 && (params.queue_size < 32 || params.queue_size > 1024)) { err = -EINVAL; goto _end; } if (params.filter & ~((1<<SNDRV_TIMER_EVENT_RESOLUTION)| (1<<SNDRV_TIMER_EVENT_TICK)| (1<<SNDRV_TIMER_EVENT_START)| (1<<SNDRV_TIMER_EVENT_STOP)| (1<<SNDRV_TIMER_EVENT_CONTINUE)| (1<<SNDRV_TIMER_EVENT_PAUSE)| (1<<SNDRV_TIMER_EVENT_SUSPEND)| (1<<SNDRV_TIMER_EVENT_RESUME)| (1<<SNDRV_TIMER_EVENT_MSTART)| (1<<SNDRV_TIMER_EVENT_MSTOP)| (1<<SNDRV_TIMER_EVENT_MCONTINUE)| (1<<SNDRV_TIMER_EVENT_MPAUSE)| (1<<SNDRV_TIMER_EVENT_MSUSPEND)| (1<<SNDRV_TIMER_EVENT_MRESUME))) { err = -EINVAL; goto _end; } snd_timer_stop(tu->timeri); spin_lock_irq(&t->lock); tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO| SNDRV_TIMER_IFLG_EXCLUSIVE| SNDRV_TIMER_IFLG_EARLY_EVENT); if (params.flags & SNDRV_TIMER_PSFLG_AUTO) tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO; if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE) tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE; if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT) tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; spin_unlock_irq(&t->lock); if (params.queue_size > 0 && (unsigned int)tu->queue_size != params.queue_size) { err = realloc_user_queue(tu, params.queue_size); if (err < 0) goto _end; } spin_lock_irq(&tu->qlock); tu->qhead = tu->qtail = tu->qused = 0; if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { if (tu->tread) { struct snd_timer_tread64 tread; memset(&tread, 0, sizeof(tread)); tread.event = SNDRV_TIMER_EVENT_EARLY; tread.tstamp_sec = 0; tread.tstamp_nsec = 0; tread.val = 0; snd_timer_user_append_to_tqueue(tu, &tread); } else { struct snd_timer_read *r = &tu->queue[0]; r->resolution = 0; r->ticks = 0; tu->qused++; tu->qtail++; } } tu->filter = params.filter; tu->ticks = params.ticks; spin_unlock_irq(&tu->qlock); err = 0; _end: if (copy_to_user(_params, &params, sizeof(params))) return -EFAULT; return err; } static int snd_timer_user_status32(struct file *file, struct snd_timer_status32 __user *_status) { struct snd_timer_user *tu; struct snd_timer_status32 status; tu = file->private_data; if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); status.tstamp_sec = tu->tstamp.tv_sec; status.tstamp_nsec = tu->tstamp.tv_nsec; status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; spin_lock_irq(&tu->qlock); status.queue = tu->qused; spin_unlock_irq(&tu->qlock); if (copy_to_user(_status, &status, sizeof(status))) return -EFAULT; return 0; } static int snd_timer_user_status64(struct file *file, struct snd_timer_status64 __user *_status) { struct snd_timer_user *tu; struct snd_timer_status64 status; tu = file->private_data; if (!tu->timeri) return -EBADFD; memset(&status, 0, sizeof(status)); status.tstamp_sec = tu->tstamp.tv_sec; status.tstamp_nsec = tu->tstamp.tv_nsec; status.resolution = snd_timer_resolution(tu->timeri); status.lost = tu->timeri->lost; status.overrun = tu->overrun; spin_lock_irq(&tu->qlock); status.queue = tu->qused; spin_unlock_irq(&tu->qlock); if (copy_to_user(_status, &status, sizeof(status))) return -EFAULT; return 0; } static int snd_timer_user_start(struct file *file) { int err; struct snd_timer_user *tu; tu = file->private_data; if (!tu->timeri) return -EBADFD; snd_timer_stop(tu->timeri); tu->timeri->lost = 0; tu->last_resolution = 0; err = snd_timer_start(tu->timeri, tu->ticks); if (err < 0) return err; return 0; } static int snd_timer_user_stop(struct file *file) { int err; struct snd_timer_user *tu; tu = file->private_data; if (!tu->timeri) return -EBADFD; err = snd_timer_stop(tu->timeri); if (err < 0) return err; return 0; } static int snd_timer_user_continue(struct file *file) { int err; struct snd_timer_user *tu; tu = file->private_data; if (!tu->timeri) return -EBADFD; /* start timer instead of continue if it's not used before */ if (!(tu->timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) return snd_timer_user_start(file); tu->timeri->lost = 0; err = snd_timer_continue(tu->timeri); if (err < 0) return err; return 0; } static int snd_timer_user_pause(struct file *file) { int err; struct snd_timer_user *tu; tu = file->private_data; if (!tu->timeri) return -EBADFD; err = snd_timer_pause(tu->timeri); if (err < 0) return err; return 0; } static int snd_timer_user_tread(void __user *argp, struct snd_timer_user *tu, unsigned int cmd, bool compat) { int __user *p = argp; int xarg, old_tread; if (tu->timeri) /* too late */ return -EBUSY; if (get_user(xarg, p)) return -EFAULT; old_tread = tu->tread; if (!xarg) tu->tread = TREAD_FORMAT_NONE; else if (cmd == SNDRV_TIMER_IOCTL_TREAD64 || (IS_ENABLED(CONFIG_64BIT) && !compat)) tu->tread = TREAD_FORMAT_TIME64; else tu->tread = TREAD_FORMAT_TIME32; if (tu->tread != old_tread && realloc_user_queue(tu, tu->queue_size) < 0) { tu->tread = old_tread; return -ENOMEM; } return 0; } enum { SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20), SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21), SNDRV_TIMER_IOCTL_CONTINUE_OLD = _IO('T', 0x22), SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23), }; static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg, bool compat) { struct snd_timer_user *tu; void __user *argp = (void __user *)arg; int __user *p = argp; tu = file->private_data; switch (cmd) { case SNDRV_TIMER_IOCTL_PVERSION: return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0; case SNDRV_TIMER_IOCTL_NEXT_DEVICE: return snd_timer_user_next_device(argp); case SNDRV_TIMER_IOCTL_TREAD_OLD: case SNDRV_TIMER_IOCTL_TREAD64: return snd_timer_user_tread(argp, tu, cmd, compat); case SNDRV_TIMER_IOCTL_GINFO: return snd_timer_user_ginfo(file, argp); case SNDRV_TIMER_IOCTL_GPARAMS: return snd_timer_user_gparams(file, argp); case SNDRV_TIMER_IOCTL_GSTATUS: return snd_timer_user_gstatus(file, argp); case SNDRV_TIMER_IOCTL_SELECT: return snd_timer_user_tselect(file, argp); case SNDRV_TIMER_IOCTL_INFO: return snd_timer_user_info(file, argp); case SNDRV_TIMER_IOCTL_PARAMS: return snd_timer_user_params(file, argp); case SNDRV_TIMER_IOCTL_STATUS32: return snd_timer_user_status32(file, argp); case SNDRV_TIMER_IOCTL_STATUS64: return snd_timer_user_status64(file, argp); case SNDRV_TIMER_IOCTL_START: case SNDRV_TIMER_IOCTL_START_OLD: return snd_timer_user_start(file); case SNDRV_TIMER_IOCTL_STOP: case SNDRV_TIMER_IOCTL_STOP_OLD: return snd_timer_user_stop(file); case SNDRV_TIMER_IOCTL_CONTINUE: case SNDRV_TIMER_IOCTL_CONTINUE_OLD: return snd_timer_user_continue(file); case SNDRV_TIMER_IOCTL_PAUSE: case SNDRV_TIMER_IOCTL_PAUSE_OLD: return snd_timer_user_pause(file); } return -ENOTTY; } static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_timer_user *tu = file->private_data; long ret; mutex_lock(&tu->ioctl_lock); ret = __snd_timer_user_ioctl(file, cmd, arg, false); mutex_unlock(&tu->ioctl_lock); return ret; } static int snd_timer_user_fasync(int fd, struct file * file, int on) { struct snd_timer_user *tu; tu = file->private_data; return snd_fasync_helper(fd, file, on, &tu->fasync); } static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, size_t count, loff_t *offset) { struct snd_timer_tread64 *tread; struct snd_timer_tread32 tread32; struct snd_timer_user *tu; long result = 0, unit; int qhead; int err = 0; tu = file->private_data; switch (tu->tread) { case TREAD_FORMAT_TIME64: unit = sizeof(struct snd_timer_tread64); break; case TREAD_FORMAT_TIME32: unit = sizeof(struct snd_timer_tread32); break; case TREAD_FORMAT_NONE: unit = sizeof(struct snd_timer_read); break; default: WARN_ONCE(1, "Corrupt snd_timer_user\n"); return -ENOTSUPP; } mutex_lock(&tu->ioctl_lock); spin_lock_irq(&tu->qlock); while ((long)count - result >= unit) { while (!tu->qused) { wait_queue_entry_t wait; if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) { err = -EAGAIN; goto _error; } set_current_state(TASK_INTERRUPTIBLE); init_waitqueue_entry(&wait, current); add_wait_queue(&tu->qchange_sleep, &wait); spin_unlock_irq(&tu->qlock); mutex_unlock(&tu->ioctl_lock); schedule(); mutex_lock(&tu->ioctl_lock); spin_lock_irq(&tu->qlock); remove_wait_queue(&tu->qchange_sleep, &wait); if (tu->disconnected) { err = -ENODEV; goto _error; } if (signal_pending(current)) { err = -ERESTARTSYS; goto _error; } } qhead = tu->qhead++; tu->qhead %= tu->queue_size; tu->qused--; spin_unlock_irq(&tu->qlock); tread = &tu->tqueue[qhead]; switch (tu->tread) { case TREAD_FORMAT_TIME64: if (copy_to_user(buffer, tread, sizeof(struct snd_timer_tread64))) err = -EFAULT; break; case TREAD_FORMAT_TIME32: memset(&tread32, 0, sizeof(tread32)); tread32 = (struct snd_timer_tread32) { .event = tread->event, .tstamp_sec = tread->tstamp_sec, .tstamp_nsec = tread->tstamp_nsec, .val = tread->val, }; if (copy_to_user(buffer, &tread32, sizeof(tread32))) err = -EFAULT; break; case TREAD_FORMAT_NONE: if (copy_to_user(buffer, &tu->queue[qhead], sizeof(struct snd_timer_read))) err = -EFAULT; break; default: err = -ENOTSUPP; break; } spin_lock_irq(&tu->qlock); if (err < 0) goto _error; result += unit; buffer += unit; } _error: spin_unlock_irq(&tu->qlock); mutex_unlock(&tu->ioctl_lock); return result > 0 ? result : err; } static __poll_t snd_timer_user_poll(struct file *file, poll_table * wait) { __poll_t mask; struct snd_timer_user *tu; tu = file->private_data; poll_wait(file, &tu->qchange_sleep, wait); mask = 0; spin_lock_irq(&tu->qlock); if (tu->qused) mask |= EPOLLIN | EPOLLRDNORM; if (tu->disconnected) mask |= EPOLLERR; spin_unlock_irq(&tu->qlock); return mask; } #ifdef CONFIG_COMPAT #include "timer_compat.c" #else #define snd_timer_user_ioctl_compat NULL #endif static const struct file_operations snd_timer_f_ops = { .owner = THIS_MODULE, .read = snd_timer_user_read, .open = snd_timer_user_open, .release = snd_timer_user_release, .llseek = no_llseek, .poll = snd_timer_user_poll, .unlocked_ioctl = snd_timer_user_ioctl, .compat_ioctl = snd_timer_user_ioctl_compat, .fasync = snd_timer_user_fasync, }; /* unregister the system timer */ static void snd_timer_free_all(void) { struct snd_timer *timer, *n; list_for_each_entry_safe(timer, n, &snd_timer_list, device_list) snd_timer_free(timer); } static struct device *timer_dev; /* * ENTRY functions */ static int __init alsa_timer_init(void) { int err; err = snd_device_alloc(&timer_dev, NULL); if (err < 0) return err; dev_set_name(timer_dev, "timer"); #ifdef SNDRV_OSS_INFO_DEV_TIMERS snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1, "system timer"); #endif err = snd_timer_register_system(); if (err < 0) { pr_err("ALSA: unable to register system timer (%i)\n", err); goto put_timer; } err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0, &snd_timer_f_ops, NULL, timer_dev); if (err < 0) { pr_err("ALSA: unable to register timer device (%i)\n", err); snd_timer_free_all(); goto put_timer; } snd_timer_proc_init(); return 0; put_timer: put_device(timer_dev); return err; } static void __exit alsa_timer_exit(void) { snd_unregister_device(timer_dev); snd_timer_free_all(); put_device(timer_dev); snd_timer_proc_done(); #ifdef SNDRV_OSS_INFO_DEV_TIMERS snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1); #endif } module_init(alsa_timer_init) module_exit(alsa_timer_exit)
linux-master
sound/core/timer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Abstract layer for MIDI v1.0 stream * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <sound/core.h> #include <linux/major.h> #include <linux/init.h> #include <linux/sched/signal.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/wait.h> #include <linux/mutex.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/mm.h> #include <linux/nospec.h> #include <sound/rawmidi.h> #include <sound/info.h> #include <sound/control.h> #include <sound/minors.h> #include <sound/initval.h> #include <sound/ump.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Midlevel RawMidi code for ALSA."); MODULE_LICENSE("GPL"); #ifdef CONFIG_SND_OSSEMUL static int midi_map[SNDRV_CARDS]; static int amidi_map[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1}; module_param_array(midi_map, int, NULL, 0444); MODULE_PARM_DESC(midi_map, "Raw MIDI device number assigned to 1st OSS device."); module_param_array(amidi_map, int, NULL, 0444); MODULE_PARM_DESC(amidi_map, "Raw MIDI device number assigned to 2nd OSS device."); #endif /* CONFIG_SND_OSSEMUL */ static int snd_rawmidi_dev_free(struct snd_device *device); static int snd_rawmidi_dev_register(struct snd_device *device); static int snd_rawmidi_dev_disconnect(struct snd_device *device); static LIST_HEAD(snd_rawmidi_devices); static DEFINE_MUTEX(register_mutex); #define rmidi_err(rmidi, fmt, args...) \ dev_err((rmidi)->dev, fmt, ##args) #define rmidi_warn(rmidi, fmt, args...) \ dev_warn((rmidi)->dev, fmt, ##args) #define rmidi_dbg(rmidi, fmt, args...) \ dev_dbg((rmidi)->dev, fmt, ##args) struct snd_rawmidi_status32 { s32 stream; s32 tstamp_sec; /* Timestamp */ s32 tstamp_nsec; u32 avail; /* available bytes */ u32 xruns; /* count of overruns since last status (in bytes) */ unsigned char reserved[16]; /* reserved for future use */ }; #define SNDRV_RAWMIDI_IOCTL_STATUS32 _IOWR('W', 0x20, struct snd_rawmidi_status32) struct snd_rawmidi_status64 { int stream; u8 rsvd[4]; /* alignment */ s64 tstamp_sec; /* Timestamp */ s64 tstamp_nsec; size_t avail; /* available bytes */ size_t xruns; /* count of overruns since last status (in bytes) */ unsigned char reserved[16]; /* reserved for future use */ }; #define SNDRV_RAWMIDI_IOCTL_STATUS64 _IOWR('W', 0x20, struct snd_rawmidi_status64) #define rawmidi_is_ump(rmidi) \ (IS_ENABLED(CONFIG_SND_UMP) && ((rmidi)->info_flags & SNDRV_RAWMIDI_INFO_UMP)) static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device) { struct snd_rawmidi *rawmidi; list_for_each_entry(rawmidi, &snd_rawmidi_devices, list) if (rawmidi->card == card && rawmidi->device == device) return rawmidi; return NULL; } static inline unsigned short snd_rawmidi_file_flags(struct file *file) { switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) { case FMODE_WRITE: return SNDRV_RAWMIDI_LFLG_OUTPUT; case FMODE_READ: return SNDRV_RAWMIDI_LFLG_INPUT; default: return SNDRV_RAWMIDI_LFLG_OPEN; } } static inline bool __snd_rawmidi_ready(struct snd_rawmidi_runtime *runtime) { return runtime->avail >= runtime->avail_min; } static bool snd_rawmidi_ready(struct snd_rawmidi_substream *substream) { unsigned long flags; bool ready; spin_lock_irqsave(&substream->lock, flags); ready = __snd_rawmidi_ready(substream->runtime); spin_unlock_irqrestore(&substream->lock, flags); return ready; } static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream, size_t count) { struct snd_rawmidi_runtime *runtime = substream->runtime; return runtime->avail >= runtime->avail_min && (!substream->append || runtime->avail >= count); } static void snd_rawmidi_input_event_work(struct work_struct *work) { struct snd_rawmidi_runtime *runtime = container_of(work, struct snd_rawmidi_runtime, event_work); if (runtime->event) runtime->event(runtime->substream); } /* buffer refcount management: call with substream->lock held */ static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime) { runtime->buffer_ref++; } static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime) { runtime->buffer_ref--; } static void snd_rawmidi_buffer_ref_sync(struct snd_rawmidi_substream *substream) { int loop = HZ; spin_lock_irq(&substream->lock); while (substream->runtime->buffer_ref) { spin_unlock_irq(&substream->lock); if (!--loop) { rmidi_err(substream->rmidi, "Buffer ref sync timeout\n"); return; } schedule_timeout_uninterruptible(1); spin_lock_irq(&substream->lock); } spin_unlock_irq(&substream->lock); } static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream) { struct snd_rawmidi_runtime *runtime; runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); if (!runtime) return -ENOMEM; runtime->substream = substream; init_waitqueue_head(&runtime->sleep); INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work); runtime->event = NULL; runtime->buffer_size = PAGE_SIZE; runtime->avail_min = 1; if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT) runtime->avail = 0; else runtime->avail = runtime->buffer_size; runtime->buffer = kvzalloc(runtime->buffer_size, GFP_KERNEL); if (!runtime->buffer) { kfree(runtime); return -ENOMEM; } runtime->appl_ptr = runtime->hw_ptr = 0; substream->runtime = runtime; if (rawmidi_is_ump(substream->rmidi)) runtime->align = 3; return 0; } /* get the current alignment (either 0 or 3) */ static inline int get_align(struct snd_rawmidi_runtime *runtime) { if (IS_ENABLED(CONFIG_SND_UMP)) return runtime->align; else return 0; } /* get the trimmed size with the current alignment */ #define get_aligned_size(runtime, size) ((size) & ~get_align(runtime)) static int snd_rawmidi_runtime_free(struct snd_rawmidi_substream *substream) { struct snd_rawmidi_runtime *runtime = substream->runtime; kvfree(runtime->buffer); kfree(runtime); substream->runtime = NULL; return 0; } static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *substream, int up) { if (!substream->opened) return; substream->ops->trigger(substream, up); } static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up) { if (!substream->opened) return; substream->ops->trigger(substream, up); if (!up) cancel_work_sync(&substream->runtime->event_work); } static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime, bool is_input) { runtime->drain = 0; runtime->appl_ptr = runtime->hw_ptr = 0; runtime->avail = is_input ? 0 : runtime->buffer_size; } static void reset_runtime_ptrs(struct snd_rawmidi_substream *substream, bool is_input) { unsigned long flags; spin_lock_irqsave(&substream->lock, flags); if (substream->opened && substream->runtime) __reset_runtime_ptrs(substream->runtime, is_input); spin_unlock_irqrestore(&substream->lock, flags); } int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream) { snd_rawmidi_output_trigger(substream, 0); reset_runtime_ptrs(substream, false); return 0; } EXPORT_SYMBOL(snd_rawmidi_drop_output); int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream) { int err = 0; long timeout; struct snd_rawmidi_runtime *runtime; spin_lock_irq(&substream->lock); runtime = substream->runtime; if (!substream->opened || !runtime || !runtime->buffer) { err = -EINVAL; } else { snd_rawmidi_buffer_ref(runtime); runtime->drain = 1; } spin_unlock_irq(&substream->lock); if (err < 0) return err; timeout = wait_event_interruptible_timeout(runtime->sleep, (runtime->avail >= runtime->buffer_size), 10*HZ); spin_lock_irq(&substream->lock); if (signal_pending(current)) err = -ERESTARTSYS; if (runtime->avail < runtime->buffer_size && !timeout) { rmidi_warn(substream->rmidi, "rawmidi drain error (avail = %li, buffer_size = %li)\n", (long)runtime->avail, (long)runtime->buffer_size); err = -EIO; } runtime->drain = 0; spin_unlock_irq(&substream->lock); if (err != -ERESTARTSYS) { /* we need wait a while to make sure that Tx FIFOs are empty */ if (substream->ops->drain) substream->ops->drain(substream); else msleep(50); snd_rawmidi_drop_output(substream); } spin_lock_irq(&substream->lock); snd_rawmidi_buffer_unref(runtime); spin_unlock_irq(&substream->lock); return err; } EXPORT_SYMBOL(snd_rawmidi_drain_output); int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream) { snd_rawmidi_input_trigger(substream, 0); reset_runtime_ptrs(substream, true); return 0; } EXPORT_SYMBOL(snd_rawmidi_drain_input); /* look for an available substream for the given stream direction; * if a specific subdevice is given, try to assign it */ static int assign_substream(struct snd_rawmidi *rmidi, int subdevice, int stream, int mode, struct snd_rawmidi_substream **sub_ret) { struct snd_rawmidi_substream *substream; struct snd_rawmidi_str *s = &rmidi->streams[stream]; static const unsigned int info_flags[2] = { [SNDRV_RAWMIDI_STREAM_OUTPUT] = SNDRV_RAWMIDI_INFO_OUTPUT, [SNDRV_RAWMIDI_STREAM_INPUT] = SNDRV_RAWMIDI_INFO_INPUT, }; if (!(rmidi->info_flags & info_flags[stream])) return -ENXIO; if (subdevice >= 0 && subdevice >= s->substream_count) return -ENODEV; list_for_each_entry(substream, &s->substreams, list) { if (substream->opened) { if (stream == SNDRV_RAWMIDI_STREAM_INPUT || !(mode & SNDRV_RAWMIDI_LFLG_APPEND) || !substream->append) continue; } if (subdevice < 0 || subdevice == substream->number) { *sub_ret = substream; return 0; } } return -EAGAIN; } /* open and do ref-counting for the given substream */ static int open_substream(struct snd_rawmidi *rmidi, struct snd_rawmidi_substream *substream, int mode) { int err; if (substream->use_count == 0) { err = snd_rawmidi_runtime_create(substream); if (err < 0) return err; err = substream->ops->open(substream); if (err < 0) { snd_rawmidi_runtime_free(substream); return err; } spin_lock_irq(&substream->lock); substream->opened = 1; substream->active_sensing = 0; if (mode & SNDRV_RAWMIDI_LFLG_APPEND) substream->append = 1; substream->pid = get_pid(task_pid(current)); rmidi->streams[substream->stream].substream_opened++; spin_unlock_irq(&substream->lock); } substream->use_count++; return 0; } static void close_substream(struct snd_rawmidi *rmidi, struct snd_rawmidi_substream *substream, int cleanup); static int rawmidi_open_priv(struct snd_rawmidi *rmidi, int subdevice, int mode, struct snd_rawmidi_file *rfile) { struct snd_rawmidi_substream *sinput = NULL, *soutput = NULL; int err; rfile->input = rfile->output = NULL; if (mode & SNDRV_RAWMIDI_LFLG_INPUT) { err = assign_substream(rmidi, subdevice, SNDRV_RAWMIDI_STREAM_INPUT, mode, &sinput); if (err < 0) return err; } if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) { err = assign_substream(rmidi, subdevice, SNDRV_RAWMIDI_STREAM_OUTPUT, mode, &soutput); if (err < 0) return err; } if (sinput) { err = open_substream(rmidi, sinput, mode); if (err < 0) return err; } if (soutput) { err = open_substream(rmidi, soutput, mode); if (err < 0) { if (sinput) close_substream(rmidi, sinput, 0); return err; } } rfile->rmidi = rmidi; rfile->input = sinput; rfile->output = soutput; return 0; } /* called from sound/core/seq/seq_midi.c */ int snd_rawmidi_kernel_open(struct snd_rawmidi *rmidi, int subdevice, int mode, struct snd_rawmidi_file *rfile) { int err; if (snd_BUG_ON(!rfile)) return -EINVAL; if (!try_module_get(rmidi->card->module)) return -ENXIO; mutex_lock(&rmidi->open_mutex); err = rawmidi_open_priv(rmidi, subdevice, mode, rfile); mutex_unlock(&rmidi->open_mutex); if (err < 0) module_put(rmidi->card->module); return err; } EXPORT_SYMBOL(snd_rawmidi_kernel_open); static int snd_rawmidi_open(struct inode *inode, struct file *file) { int maj = imajor(inode); struct snd_card *card; int subdevice; unsigned short fflags; int err; struct snd_rawmidi *rmidi; struct snd_rawmidi_file *rawmidi_file = NULL; wait_queue_entry_t wait; if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) return -EINVAL; /* invalid combination */ err = stream_open(inode, file); if (err < 0) return err; if (maj == snd_major) { rmidi = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_RAWMIDI); #ifdef CONFIG_SND_OSSEMUL } else if (maj == SOUND_MAJOR) { rmidi = snd_lookup_oss_minor_data(iminor(inode), SNDRV_OSS_DEVICE_TYPE_MIDI); #endif } else return -ENXIO; if (rmidi == NULL) return -ENODEV; if (!try_module_get(rmidi->card->module)) { snd_card_unref(rmidi->card); return -ENXIO; } mutex_lock(&rmidi->open_mutex); card = rmidi->card; err = snd_card_file_add(card, file); if (err < 0) goto __error_card; fflags = snd_rawmidi_file_flags(file); if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */ fflags |= SNDRV_RAWMIDI_LFLG_APPEND; rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL); if (rawmidi_file == NULL) { err = -ENOMEM; goto __error; } rawmidi_file->user_pversion = 0; init_waitqueue_entry(&wait, current); add_wait_queue(&rmidi->open_wait, &wait); while (1) { subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_RAWMIDI); err = rawmidi_open_priv(rmidi, subdevice, fflags, rawmidi_file); if (err >= 0) break; if (err == -EAGAIN) { if (file->f_flags & O_NONBLOCK) { err = -EBUSY; break; } } else break; set_current_state(TASK_INTERRUPTIBLE); mutex_unlock(&rmidi->open_mutex); schedule(); mutex_lock(&rmidi->open_mutex); if (rmidi->card->shutdown) { err = -ENODEV; break; } if (signal_pending(current)) { err = -ERESTARTSYS; break; } } remove_wait_queue(&rmidi->open_wait, &wait); if (err < 0) { kfree(rawmidi_file); goto __error; } #ifdef CONFIG_SND_OSSEMUL if (rawmidi_file->input && rawmidi_file->input->runtime) rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR); if (rawmidi_file->output && rawmidi_file->output->runtime) rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR); #endif file->private_data = rawmidi_file; mutex_unlock(&rmidi->open_mutex); snd_card_unref(rmidi->card); return 0; __error: snd_card_file_remove(card, file); __error_card: mutex_unlock(&rmidi->open_mutex); module_put(rmidi->card->module); snd_card_unref(rmidi->card); return err; } static void close_substream(struct snd_rawmidi *rmidi, struct snd_rawmidi_substream *substream, int cleanup) { if (--substream->use_count) return; if (cleanup) { if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT) snd_rawmidi_input_trigger(substream, 0); else { if (substream->active_sensing) { unsigned char buf = 0xfe; /* sending single active sensing message * to shut the device up */ snd_rawmidi_kernel_write(substream, &buf, 1); } if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS) snd_rawmidi_output_trigger(substream, 0); } snd_rawmidi_buffer_ref_sync(substream); } spin_lock_irq(&substream->lock); substream->opened = 0; substream->append = 0; spin_unlock_irq(&substream->lock); substream->ops->close(substream); if (substream->runtime->private_free) substream->runtime->private_free(substream); snd_rawmidi_runtime_free(substream); put_pid(substream->pid); substream->pid = NULL; rmidi->streams[substream->stream].substream_opened--; } static void rawmidi_release_priv(struct snd_rawmidi_file *rfile) { struct snd_rawmidi *rmidi; rmidi = rfile->rmidi; mutex_lock(&rmidi->open_mutex); if (rfile->input) { close_substream(rmidi, rfile->input, 1); rfile->input = NULL; } if (rfile->output) { close_substream(rmidi, rfile->output, 1); rfile->output = NULL; } rfile->rmidi = NULL; mutex_unlock(&rmidi->open_mutex); wake_up(&rmidi->open_wait); } /* called from sound/core/seq/seq_midi.c */ int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile) { struct snd_rawmidi *rmidi; if (snd_BUG_ON(!rfile)) return -ENXIO; rmidi = rfile->rmidi; rawmidi_release_priv(rfile); module_put(rmidi->card->module); return 0; } EXPORT_SYMBOL(snd_rawmidi_kernel_release); static int snd_rawmidi_release(struct inode *inode, struct file *file) { struct snd_rawmidi_file *rfile; struct snd_rawmidi *rmidi; struct module *module; rfile = file->private_data; rmidi = rfile->rmidi; rawmidi_release_priv(rfile); kfree(rfile); module = rmidi->card->module; snd_card_file_remove(rmidi->card, file); module_put(module); return 0; } static int snd_rawmidi_info(struct snd_rawmidi_substream *substream, struct snd_rawmidi_info *info) { struct snd_rawmidi *rmidi; if (substream == NULL) return -ENODEV; rmidi = substream->rmidi; memset(info, 0, sizeof(*info)); info->card = rmidi->card->number; info->device = rmidi->device; info->subdevice = substream->number; info->stream = substream->stream; info->flags = rmidi->info_flags; strcpy(info->id, rmidi->id); strcpy(info->name, rmidi->name); strcpy(info->subname, substream->name); info->subdevices_count = substream->pstr->substream_count; info->subdevices_avail = (substream->pstr->substream_count - substream->pstr->substream_opened); return 0; } static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream, struct snd_rawmidi_info __user *_info) { struct snd_rawmidi_info info; int err; err = snd_rawmidi_info(substream, &info); if (err < 0) return err; if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info))) return -EFAULT; return 0; } static int __snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info) { struct snd_rawmidi *rmidi; struct snd_rawmidi_str *pstr; struct snd_rawmidi_substream *substream; rmidi = snd_rawmidi_search(card, info->device); if (!rmidi) return -ENXIO; if (info->stream < 0 || info->stream > 1) return -EINVAL; info->stream = array_index_nospec(info->stream, 2); pstr = &rmidi->streams[info->stream]; if (pstr->substream_count == 0) return -ENOENT; if (info->subdevice >= pstr->substream_count) return -ENXIO; list_for_each_entry(substream, &pstr->substreams, list) { if ((unsigned int)substream->number == info->subdevice) return snd_rawmidi_info(substream, info); } return -ENXIO; } int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info) { int ret; mutex_lock(&register_mutex); ret = __snd_rawmidi_info_select(card, info); mutex_unlock(&register_mutex); return ret; } EXPORT_SYMBOL(snd_rawmidi_info_select); static int snd_rawmidi_info_select_user(struct snd_card *card, struct snd_rawmidi_info __user *_info) { int err; struct snd_rawmidi_info info; if (get_user(info.device, &_info->device)) return -EFAULT; if (get_user(info.stream, &_info->stream)) return -EFAULT; if (get_user(info.subdevice, &_info->subdevice)) return -EFAULT; err = snd_rawmidi_info_select(card, &info); if (err < 0) return err; if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info))) return -EFAULT; return 0; } static int resize_runtime_buffer(struct snd_rawmidi_substream *substream, struct snd_rawmidi_params *params, bool is_input) { struct snd_rawmidi_runtime *runtime = substream->runtime; char *newbuf, *oldbuf; unsigned int framing = params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK; if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) return -EINVAL; if (framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP && (params->buffer_size & 0x1f) != 0) return -EINVAL; if (params->avail_min < 1 || params->avail_min > params->buffer_size) return -EINVAL; if (params->buffer_size & get_align(runtime)) return -EINVAL; if (params->buffer_size != runtime->buffer_size) { newbuf = kvzalloc(params->buffer_size, GFP_KERNEL); if (!newbuf) return -ENOMEM; spin_lock_irq(&substream->lock); if (runtime->buffer_ref) { spin_unlock_irq(&substream->lock); kvfree(newbuf); return -EBUSY; } oldbuf = runtime->buffer; runtime->buffer = newbuf; runtime->buffer_size = params->buffer_size; __reset_runtime_ptrs(runtime, is_input); spin_unlock_irq(&substream->lock); kvfree(oldbuf); } runtime->avail_min = params->avail_min; return 0; } int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream, struct snd_rawmidi_params *params) { int err; snd_rawmidi_drain_output(substream); mutex_lock(&substream->rmidi->open_mutex); if (substream->append && substream->use_count > 1) err = -EBUSY; else err = resize_runtime_buffer(substream, params, false); if (!err) substream->active_sensing = !params->no_active_sensing; mutex_unlock(&substream->rmidi->open_mutex); return err; } EXPORT_SYMBOL(snd_rawmidi_output_params); int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, struct snd_rawmidi_params *params) { unsigned int framing = params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK; unsigned int clock_type = params->mode & SNDRV_RAWMIDI_MODE_CLOCK_MASK; int err; snd_rawmidi_drain_input(substream); mutex_lock(&substream->rmidi->open_mutex); if (framing == SNDRV_RAWMIDI_MODE_FRAMING_NONE && clock_type != SNDRV_RAWMIDI_MODE_CLOCK_NONE) err = -EINVAL; else if (clock_type > SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW) err = -EINVAL; else if (framing > SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) err = -EINVAL; else err = resize_runtime_buffer(substream, params, true); if (!err) { substream->framing = framing; substream->clock_type = clock_type; } mutex_unlock(&substream->rmidi->open_mutex); return 0; } EXPORT_SYMBOL(snd_rawmidi_input_params); static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream, struct snd_rawmidi_status64 *status) { struct snd_rawmidi_runtime *runtime = substream->runtime; memset(status, 0, sizeof(*status)); status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT; spin_lock_irq(&substream->lock); status->avail = runtime->avail; spin_unlock_irq(&substream->lock); return 0; } static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream, struct snd_rawmidi_status64 *status) { struct snd_rawmidi_runtime *runtime = substream->runtime; memset(status, 0, sizeof(*status)); status->stream = SNDRV_RAWMIDI_STREAM_INPUT; spin_lock_irq(&substream->lock); status->avail = runtime->avail; status->xruns = runtime->xruns; runtime->xruns = 0; spin_unlock_irq(&substream->lock); return 0; } static int snd_rawmidi_ioctl_status32(struct snd_rawmidi_file *rfile, struct snd_rawmidi_status32 __user *argp) { int err = 0; struct snd_rawmidi_status32 __user *status = argp; struct snd_rawmidi_status32 status32; struct snd_rawmidi_status64 status64; if (copy_from_user(&status32, argp, sizeof(struct snd_rawmidi_status32))) return -EFAULT; switch (status32.stream) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (rfile->output == NULL) return -EINVAL; err = snd_rawmidi_output_status(rfile->output, &status64); break; case SNDRV_RAWMIDI_STREAM_INPUT: if (rfile->input == NULL) return -EINVAL; err = snd_rawmidi_input_status(rfile->input, &status64); break; default: return -EINVAL; } if (err < 0) return err; status32 = (struct snd_rawmidi_status32) { .stream = status64.stream, .tstamp_sec = status64.tstamp_sec, .tstamp_nsec = status64.tstamp_nsec, .avail = status64.avail, .xruns = status64.xruns, }; if (copy_to_user(status, &status32, sizeof(*status))) return -EFAULT; return 0; } static int snd_rawmidi_ioctl_status64(struct snd_rawmidi_file *rfile, struct snd_rawmidi_status64 __user *argp) { int err = 0; struct snd_rawmidi_status64 status; if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status64))) return -EFAULT; switch (status.stream) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (rfile->output == NULL) return -EINVAL; err = snd_rawmidi_output_status(rfile->output, &status); break; case SNDRV_RAWMIDI_STREAM_INPUT: if (rfile->input == NULL) return -EINVAL; err = snd_rawmidi_input_status(rfile->input, &status); break; default: return -EINVAL; } if (err < 0) return err; if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status64))) return -EFAULT; return 0; } static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_rawmidi_file *rfile; struct snd_rawmidi *rmidi; void __user *argp = (void __user *)arg; rfile = file->private_data; if (((cmd >> 8) & 0xff) != 'W') return -ENOTTY; switch (cmd) { case SNDRV_RAWMIDI_IOCTL_PVERSION: return put_user(SNDRV_RAWMIDI_VERSION, (int __user *)argp) ? -EFAULT : 0; case SNDRV_RAWMIDI_IOCTL_INFO: { int stream; struct snd_rawmidi_info __user *info = argp; if (get_user(stream, &info->stream)) return -EFAULT; switch (stream) { case SNDRV_RAWMIDI_STREAM_INPUT: return snd_rawmidi_info_user(rfile->input, info); case SNDRV_RAWMIDI_STREAM_OUTPUT: return snd_rawmidi_info_user(rfile->output, info); default: return -EINVAL; } } case SNDRV_RAWMIDI_IOCTL_USER_PVERSION: if (get_user(rfile->user_pversion, (unsigned int __user *)arg)) return -EFAULT; return 0; case SNDRV_RAWMIDI_IOCTL_PARAMS: { struct snd_rawmidi_params params; if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params))) return -EFAULT; if (rfile->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 2)) { params.mode = 0; memset(params.reserved, 0, sizeof(params.reserved)); } switch (params.stream) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (rfile->output == NULL) return -EINVAL; return snd_rawmidi_output_params(rfile->output, &params); case SNDRV_RAWMIDI_STREAM_INPUT: if (rfile->input == NULL) return -EINVAL; return snd_rawmidi_input_params(rfile->input, &params); default: return -EINVAL; } } case SNDRV_RAWMIDI_IOCTL_STATUS32: return snd_rawmidi_ioctl_status32(rfile, argp); case SNDRV_RAWMIDI_IOCTL_STATUS64: return snd_rawmidi_ioctl_status64(rfile, argp); case SNDRV_RAWMIDI_IOCTL_DROP: { int val; if (get_user(val, (int __user *) argp)) return -EFAULT; switch (val) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (rfile->output == NULL) return -EINVAL; return snd_rawmidi_drop_output(rfile->output); default: return -EINVAL; } } case SNDRV_RAWMIDI_IOCTL_DRAIN: { int val; if (get_user(val, (int __user *) argp)) return -EFAULT; switch (val) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (rfile->output == NULL) return -EINVAL; return snd_rawmidi_drain_output(rfile->output); case SNDRV_RAWMIDI_STREAM_INPUT: if (rfile->input == NULL) return -EINVAL; return snd_rawmidi_drain_input(rfile->input); default: return -EINVAL; } } default: rmidi = rfile->rmidi; if (rmidi->ops && rmidi->ops->ioctl) return rmidi->ops->ioctl(rmidi, cmd, argp); rmidi_dbg(rmidi, "rawmidi: unknown command = 0x%x\n", cmd); } return -ENOTTY; } /* ioctl to find the next device; either legacy or UMP depending on @find_ump */ static int snd_rawmidi_next_device(struct snd_card *card, int __user *argp, bool find_ump) { struct snd_rawmidi *rmidi; int device; bool is_ump; if (get_user(device, argp)) return -EFAULT; if (device >= SNDRV_RAWMIDI_DEVICES) /* next device is -1 */ device = SNDRV_RAWMIDI_DEVICES - 1; mutex_lock(&register_mutex); device = device < 0 ? 0 : device + 1; for (; device < SNDRV_RAWMIDI_DEVICES; device++) { rmidi = snd_rawmidi_search(card, device); if (!rmidi) continue; is_ump = rawmidi_is_ump(rmidi); if (find_ump == is_ump) break; } if (device == SNDRV_RAWMIDI_DEVICES) device = -1; mutex_unlock(&register_mutex); if (put_user(device, argp)) return -EFAULT; return 0; } #if IS_ENABLED(CONFIG_SND_UMP) /* inquiry of UMP endpoint and block info via control API */ static int snd_rawmidi_call_ump_ioctl(struct snd_card *card, int cmd, void __user *argp) { struct snd_ump_endpoint_info __user *info = argp; struct snd_rawmidi *rmidi; int device, ret; if (get_user(device, &info->device)) return -EFAULT; mutex_lock(&register_mutex); rmidi = snd_rawmidi_search(card, device); if (rmidi && rmidi->ops && rmidi->ops->ioctl) ret = rmidi->ops->ioctl(rmidi, cmd, argp); else ret = -ENXIO; mutex_unlock(&register_mutex); return ret; } #endif static int snd_rawmidi_control_ioctl(struct snd_card *card, struct snd_ctl_file *control, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; switch (cmd) { case SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE: return snd_rawmidi_next_device(card, argp, false); #if IS_ENABLED(CONFIG_SND_UMP) case SNDRV_CTL_IOCTL_UMP_NEXT_DEVICE: return snd_rawmidi_next_device(card, argp, true); case SNDRV_CTL_IOCTL_UMP_ENDPOINT_INFO: return snd_rawmidi_call_ump_ioctl(card, SNDRV_UMP_IOCTL_ENDPOINT_INFO, argp); case SNDRV_CTL_IOCTL_UMP_BLOCK_INFO: return snd_rawmidi_call_ump_ioctl(card, SNDRV_UMP_IOCTL_BLOCK_INFO, argp); #endif case SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE: { int val; if (get_user(val, (int __user *)argp)) return -EFAULT; control->preferred_subdevice[SND_CTL_SUBDEV_RAWMIDI] = val; return 0; } case SNDRV_CTL_IOCTL_RAWMIDI_INFO: return snd_rawmidi_info_select_user(card, argp); } return -ENOIOCTLCMD; } static int receive_with_tstamp_framing(struct snd_rawmidi_substream *substream, const unsigned char *buffer, int src_count, const struct timespec64 *tstamp) { struct snd_rawmidi_runtime *runtime = substream->runtime; struct snd_rawmidi_framing_tstamp *dest_ptr; struct snd_rawmidi_framing_tstamp frame = { .tv_sec = tstamp->tv_sec, .tv_nsec = tstamp->tv_nsec }; int orig_count = src_count; int frame_size = sizeof(struct snd_rawmidi_framing_tstamp); int align = get_align(runtime); BUILD_BUG_ON(frame_size != 0x20); if (snd_BUG_ON((runtime->hw_ptr & 0x1f) != 0)) return -EINVAL; while (src_count > align) { if ((int)(runtime->buffer_size - runtime->avail) < frame_size) { runtime->xruns += src_count; break; } if (src_count >= SNDRV_RAWMIDI_FRAMING_DATA_LENGTH) frame.length = SNDRV_RAWMIDI_FRAMING_DATA_LENGTH; else { frame.length = get_aligned_size(runtime, src_count); if (!frame.length) break; memset(frame.data, 0, SNDRV_RAWMIDI_FRAMING_DATA_LENGTH); } memcpy(frame.data, buffer, frame.length); buffer += frame.length; src_count -= frame.length; dest_ptr = (struct snd_rawmidi_framing_tstamp *) (runtime->buffer + runtime->hw_ptr); *dest_ptr = frame; runtime->avail += frame_size; runtime->hw_ptr += frame_size; runtime->hw_ptr %= runtime->buffer_size; } return orig_count - src_count; } static struct timespec64 get_framing_tstamp(struct snd_rawmidi_substream *substream) { struct timespec64 ts64 = {0, 0}; switch (substream->clock_type) { case SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW: ktime_get_raw_ts64(&ts64); break; case SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC: ktime_get_ts64(&ts64); break; case SNDRV_RAWMIDI_MODE_CLOCK_REALTIME: ktime_get_real_ts64(&ts64); break; } return ts64; } /** * snd_rawmidi_receive - receive the input data from the device * @substream: the rawmidi substream * @buffer: the buffer pointer * @count: the data size to read * * Reads the data from the internal buffer. * * Return: The size of read data, or a negative error code on failure. */ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, const unsigned char *buffer, int count) { unsigned long flags; struct timespec64 ts64 = get_framing_tstamp(substream); int result = 0, count1; struct snd_rawmidi_runtime *runtime; spin_lock_irqsave(&substream->lock, flags); if (!substream->opened) { result = -EBADFD; goto unlock; } runtime = substream->runtime; if (!runtime || !runtime->buffer) { rmidi_dbg(substream->rmidi, "snd_rawmidi_receive: input is not active!!!\n"); result = -EINVAL; goto unlock; } count = get_aligned_size(runtime, count); if (!count) goto unlock; if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) { result = receive_with_tstamp_framing(substream, buffer, count, &ts64); } else if (count == 1) { /* special case, faster code */ substream->bytes++; if (runtime->avail < runtime->buffer_size) { runtime->buffer[runtime->hw_ptr++] = buffer[0]; runtime->hw_ptr %= runtime->buffer_size; runtime->avail++; result++; } else { runtime->xruns++; } } else { substream->bytes += count; count1 = runtime->buffer_size - runtime->hw_ptr; if (count1 > count) count1 = count; if (count1 > (int)(runtime->buffer_size - runtime->avail)) count1 = runtime->buffer_size - runtime->avail; count1 = get_aligned_size(runtime, count1); if (!count1) goto unlock; memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); runtime->hw_ptr += count1; runtime->hw_ptr %= runtime->buffer_size; runtime->avail += count1; count -= count1; result += count1; if (count > 0) { buffer += count1; count1 = count; if (count1 > (int)(runtime->buffer_size - runtime->avail)) { count1 = runtime->buffer_size - runtime->avail; runtime->xruns += count - count1; } if (count1 > 0) { memcpy(runtime->buffer, buffer, count1); runtime->hw_ptr = count1; runtime->avail += count1; result += count1; } } } if (result > 0) { if (runtime->event) schedule_work(&runtime->event_work); else if (__snd_rawmidi_ready(runtime)) wake_up(&runtime->sleep); } unlock: spin_unlock_irqrestore(&substream->lock, flags); return result; } EXPORT_SYMBOL(snd_rawmidi_receive); static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream, unsigned char __user *userbuf, unsigned char *kernelbuf, long count) { unsigned long flags; long result = 0, count1; struct snd_rawmidi_runtime *runtime = substream->runtime; unsigned long appl_ptr; int err = 0; spin_lock_irqsave(&substream->lock, flags); snd_rawmidi_buffer_ref(runtime); while (count > 0 && runtime->avail) { count1 = runtime->buffer_size - runtime->appl_ptr; if (count1 > count) count1 = count; if (count1 > (int)runtime->avail) count1 = runtime->avail; /* update runtime->appl_ptr before unlocking for userbuf */ appl_ptr = runtime->appl_ptr; runtime->appl_ptr += count1; runtime->appl_ptr %= runtime->buffer_size; runtime->avail -= count1; if (kernelbuf) memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1); if (userbuf) { spin_unlock_irqrestore(&substream->lock, flags); if (copy_to_user(userbuf + result, runtime->buffer + appl_ptr, count1)) err = -EFAULT; spin_lock_irqsave(&substream->lock, flags); if (err) goto out; } result += count1; count -= count1; } out: snd_rawmidi_buffer_unref(runtime); spin_unlock_irqrestore(&substream->lock, flags); return result > 0 ? result : err; } long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream, unsigned char *buf, long count) { snd_rawmidi_input_trigger(substream, 1); return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count); } EXPORT_SYMBOL(snd_rawmidi_kernel_read); static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { long result; int count1; struct snd_rawmidi_file *rfile; struct snd_rawmidi_substream *substream; struct snd_rawmidi_runtime *runtime; rfile = file->private_data; substream = rfile->input; if (substream == NULL) return -EIO; runtime = substream->runtime; snd_rawmidi_input_trigger(substream, 1); result = 0; while (count > 0) { spin_lock_irq(&substream->lock); while (!__snd_rawmidi_ready(runtime)) { wait_queue_entry_t wait; if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) { spin_unlock_irq(&substream->lock); return result > 0 ? result : -EAGAIN; } init_waitqueue_entry(&wait, current); add_wait_queue(&runtime->sleep, &wait); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irq(&substream->lock); schedule(); remove_wait_queue(&runtime->sleep, &wait); if (rfile->rmidi->card->shutdown) return -ENODEV; if (signal_pending(current)) return result > 0 ? result : -ERESTARTSYS; spin_lock_irq(&substream->lock); if (!runtime->avail) { spin_unlock_irq(&substream->lock); return result > 0 ? result : -EIO; } } spin_unlock_irq(&substream->lock); count1 = snd_rawmidi_kernel_read1(substream, (unsigned char __user *)buf, NULL/*kernelbuf*/, count); if (count1 < 0) return result > 0 ? result : count1; result += count1; buf += count1; count -= count1; } return result; } /** * snd_rawmidi_transmit_empty - check whether the output buffer is empty * @substream: the rawmidi substream * * Return: 1 if the internal output buffer is empty, 0 if not. */ int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream) { struct snd_rawmidi_runtime *runtime; int result; unsigned long flags; spin_lock_irqsave(&substream->lock, flags); runtime = substream->runtime; if (!substream->opened || !runtime || !runtime->buffer) { rmidi_dbg(substream->rmidi, "snd_rawmidi_transmit_empty: output is not active!!!\n"); result = 1; } else { result = runtime->avail >= runtime->buffer_size; } spin_unlock_irqrestore(&substream->lock, flags); return result; } EXPORT_SYMBOL(snd_rawmidi_transmit_empty); /* * __snd_rawmidi_transmit_peek - copy data from the internal buffer * @substream: the rawmidi substream * @buffer: the buffer pointer * @count: data size to transfer * * This is a variant of snd_rawmidi_transmit_peek() without spinlock. */ static int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, unsigned char *buffer, int count) { int result, count1; struct snd_rawmidi_runtime *runtime = substream->runtime; if (runtime->buffer == NULL) { rmidi_dbg(substream->rmidi, "snd_rawmidi_transmit_peek: output is not active!!!\n"); return -EINVAL; } result = 0; if (runtime->avail >= runtime->buffer_size) { /* warning: lowlevel layer MUST trigger down the hardware */ goto __skip; } if (count == 1) { /* special case, faster code */ *buffer = runtime->buffer[runtime->hw_ptr]; result++; } else { count1 = runtime->buffer_size - runtime->hw_ptr; if (count1 > count) count1 = count; if (count1 > (int)(runtime->buffer_size - runtime->avail)) count1 = runtime->buffer_size - runtime->avail; count1 = get_aligned_size(runtime, count1); if (!count1) goto __skip; memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1); count -= count1; result += count1; if (count > 0) { if (count > (int)(runtime->buffer_size - runtime->avail - count1)) count = runtime->buffer_size - runtime->avail - count1; count = get_aligned_size(runtime, count); if (!count) goto __skip; memcpy(buffer + count1, runtime->buffer, count); result += count; } } __skip: return result; } /** * snd_rawmidi_transmit_peek - copy data from the internal buffer * @substream: the rawmidi substream * @buffer: the buffer pointer * @count: data size to transfer * * Copies data from the internal output buffer to the given buffer. * * Call this in the interrupt handler when the midi output is ready, * and call snd_rawmidi_transmit_ack() after the transmission is * finished. * * Return: The size of copied data, or a negative error code on failure. */ int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, unsigned char *buffer, int count) { int result; unsigned long flags; spin_lock_irqsave(&substream->lock, flags); if (!substream->opened || !substream->runtime) result = -EBADFD; else result = __snd_rawmidi_transmit_peek(substream, buffer, count); spin_unlock_irqrestore(&substream->lock, flags); return result; } EXPORT_SYMBOL(snd_rawmidi_transmit_peek); /* * __snd_rawmidi_transmit_ack - acknowledge the transmission * @substream: the rawmidi substream * @count: the transferred count * * This is a variant of __snd_rawmidi_transmit_ack() without spinlock. */ static int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) { struct snd_rawmidi_runtime *runtime = substream->runtime; if (runtime->buffer == NULL) { rmidi_dbg(substream->rmidi, "snd_rawmidi_transmit_ack: output is not active!!!\n"); return -EINVAL; } snd_BUG_ON(runtime->avail + count > runtime->buffer_size); count = get_aligned_size(runtime, count); runtime->hw_ptr += count; runtime->hw_ptr %= runtime->buffer_size; runtime->avail += count; substream->bytes += count; if (count > 0) { if (runtime->drain || __snd_rawmidi_ready(runtime)) wake_up(&runtime->sleep); } return count; } /** * snd_rawmidi_transmit_ack - acknowledge the transmission * @substream: the rawmidi substream * @count: the transferred count * * Advances the hardware pointer for the internal output buffer with * the given size and updates the condition. * Call after the transmission is finished. * * Return: The advanced size if successful, or a negative error code on failure. */ int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) { int result; unsigned long flags; spin_lock_irqsave(&substream->lock, flags); if (!substream->opened || !substream->runtime) result = -EBADFD; else result = __snd_rawmidi_transmit_ack(substream, count); spin_unlock_irqrestore(&substream->lock, flags); return result; } EXPORT_SYMBOL(snd_rawmidi_transmit_ack); /** * snd_rawmidi_transmit - copy from the buffer to the device * @substream: the rawmidi substream * @buffer: the buffer pointer * @count: the data size to transfer * * Copies data from the buffer to the device and advances the pointer. * * Return: The copied size if successful, or a negative error code on failure. */ int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream, unsigned char *buffer, int count) { int result; unsigned long flags; spin_lock_irqsave(&substream->lock, flags); if (!substream->opened) result = -EBADFD; else { count = __snd_rawmidi_transmit_peek(substream, buffer, count); if (count <= 0) result = count; else result = __snd_rawmidi_transmit_ack(substream, count); } spin_unlock_irqrestore(&substream->lock, flags); return result; } EXPORT_SYMBOL(snd_rawmidi_transmit); /** * snd_rawmidi_proceed - Discard the all pending bytes and proceed * @substream: rawmidi substream * * Return: the number of discarded bytes */ int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream) { struct snd_rawmidi_runtime *runtime; unsigned long flags; int count = 0; spin_lock_irqsave(&substream->lock, flags); runtime = substream->runtime; if (substream->opened && runtime && runtime->avail < runtime->buffer_size) { count = runtime->buffer_size - runtime->avail; __snd_rawmidi_transmit_ack(substream, count); } spin_unlock_irqrestore(&substream->lock, flags); return count; } EXPORT_SYMBOL(snd_rawmidi_proceed); static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream, const unsigned char __user *userbuf, const unsigned char *kernelbuf, long count) { unsigned long flags; long count1, result; struct snd_rawmidi_runtime *runtime = substream->runtime; unsigned long appl_ptr; if (!kernelbuf && !userbuf) return -EINVAL; if (snd_BUG_ON(!runtime->buffer)) return -EINVAL; result = 0; spin_lock_irqsave(&substream->lock, flags); if (substream->append) { if ((long)runtime->avail < count) { spin_unlock_irqrestore(&substream->lock, flags); return -EAGAIN; } } snd_rawmidi_buffer_ref(runtime); while (count > 0 && runtime->avail > 0) { count1 = runtime->buffer_size - runtime->appl_ptr; if (count1 > count) count1 = count; if (count1 > (long)runtime->avail) count1 = runtime->avail; /* update runtime->appl_ptr before unlocking for userbuf */ appl_ptr = runtime->appl_ptr; runtime->appl_ptr += count1; runtime->appl_ptr %= runtime->buffer_size; runtime->avail -= count1; if (kernelbuf) memcpy(runtime->buffer + appl_ptr, kernelbuf + result, count1); else if (userbuf) { spin_unlock_irqrestore(&substream->lock, flags); if (copy_from_user(runtime->buffer + appl_ptr, userbuf + result, count1)) { spin_lock_irqsave(&substream->lock, flags); result = result > 0 ? result : -EFAULT; goto __end; } spin_lock_irqsave(&substream->lock, flags); } result += count1; count -= count1; } __end: count1 = runtime->avail < runtime->buffer_size; snd_rawmidi_buffer_unref(runtime); spin_unlock_irqrestore(&substream->lock, flags); if (count1) snd_rawmidi_output_trigger(substream, 1); return result; } long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream, const unsigned char *buf, long count) { return snd_rawmidi_kernel_write1(substream, NULL, buf, count); } EXPORT_SYMBOL(snd_rawmidi_kernel_write); static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf, size_t count, loff_t *offset) { long result, timeout; int count1; struct snd_rawmidi_file *rfile; struct snd_rawmidi_runtime *runtime; struct snd_rawmidi_substream *substream; rfile = file->private_data; substream = rfile->output; runtime = substream->runtime; /* we cannot put an atomic message to our buffer */ if (substream->append && count > runtime->buffer_size) return -EIO; result = 0; while (count > 0) { spin_lock_irq(&substream->lock); while (!snd_rawmidi_ready_append(substream, count)) { wait_queue_entry_t wait; if (file->f_flags & O_NONBLOCK) { spin_unlock_irq(&substream->lock); return result > 0 ? result : -EAGAIN; } init_waitqueue_entry(&wait, current); add_wait_queue(&runtime->sleep, &wait); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irq(&substream->lock); timeout = schedule_timeout(30 * HZ); remove_wait_queue(&runtime->sleep, &wait); if (rfile->rmidi->card->shutdown) return -ENODEV; if (signal_pending(current)) return result > 0 ? result : -ERESTARTSYS; spin_lock_irq(&substream->lock); if (!runtime->avail && !timeout) { spin_unlock_irq(&substream->lock); return result > 0 ? result : -EIO; } } spin_unlock_irq(&substream->lock); count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count); if (count1 < 0) return result > 0 ? result : count1; result += count1; buf += count1; if ((size_t)count1 < count && (file->f_flags & O_NONBLOCK)) break; count -= count1; } if (file->f_flags & O_DSYNC) { spin_lock_irq(&substream->lock); while (runtime->avail != runtime->buffer_size) { wait_queue_entry_t wait; unsigned int last_avail = runtime->avail; init_waitqueue_entry(&wait, current); add_wait_queue(&runtime->sleep, &wait); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irq(&substream->lock); timeout = schedule_timeout(30 * HZ); remove_wait_queue(&runtime->sleep, &wait); if (signal_pending(current)) return result > 0 ? result : -ERESTARTSYS; if (runtime->avail == last_avail && !timeout) return result > 0 ? result : -EIO; spin_lock_irq(&substream->lock); } spin_unlock_irq(&substream->lock); } return result; } static __poll_t snd_rawmidi_poll(struct file *file, poll_table *wait) { struct snd_rawmidi_file *rfile; struct snd_rawmidi_runtime *runtime; __poll_t mask; rfile = file->private_data; if (rfile->input != NULL) { runtime = rfile->input->runtime; snd_rawmidi_input_trigger(rfile->input, 1); poll_wait(file, &runtime->sleep, wait); } if (rfile->output != NULL) { runtime = rfile->output->runtime; poll_wait(file, &runtime->sleep, wait); } mask = 0; if (rfile->input != NULL) { if (snd_rawmidi_ready(rfile->input)) mask |= EPOLLIN | EPOLLRDNORM; } if (rfile->output != NULL) { if (snd_rawmidi_ready(rfile->output)) mask |= EPOLLOUT | EPOLLWRNORM; } return mask; } /* */ #ifdef CONFIG_COMPAT #include "rawmidi_compat.c" #else #define snd_rawmidi_ioctl_compat NULL #endif /* */ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_rawmidi *rmidi; struct snd_rawmidi_substream *substream; struct snd_rawmidi_runtime *runtime; unsigned long buffer_size, avail, xruns; unsigned int clock_type; static const char *clock_names[4] = { "none", "realtime", "monotonic", "monotonic raw" }; rmidi = entry->private_data; snd_iprintf(buffer, "%s\n\n", rmidi->name); if (IS_ENABLED(CONFIG_SND_UMP)) snd_iprintf(buffer, "Type: %s\n", rawmidi_is_ump(rmidi) ? "UMP" : "Legacy"); if (rmidi->ops && rmidi->ops->proc_read) rmidi->ops->proc_read(entry, buffer); mutex_lock(&rmidi->open_mutex); if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT) { list_for_each_entry(substream, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams, list) { snd_iprintf(buffer, "Output %d\n" " Tx bytes : %lu\n", substream->number, (unsigned long) substream->bytes); if (substream->opened) { snd_iprintf(buffer, " Owner PID : %d\n", pid_vnr(substream->pid)); runtime = substream->runtime; spin_lock_irq(&substream->lock); buffer_size = runtime->buffer_size; avail = runtime->avail; spin_unlock_irq(&substream->lock); snd_iprintf(buffer, " Mode : %s\n" " Buffer size : %lu\n" " Avail : %lu\n", runtime->oss ? "OSS compatible" : "native", buffer_size, avail); } } } if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT) { list_for_each_entry(substream, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams, list) { snd_iprintf(buffer, "Input %d\n" " Rx bytes : %lu\n", substream->number, (unsigned long) substream->bytes); if (substream->opened) { snd_iprintf(buffer, " Owner PID : %d\n", pid_vnr(substream->pid)); runtime = substream->runtime; spin_lock_irq(&substream->lock); buffer_size = runtime->buffer_size; avail = runtime->avail; xruns = runtime->xruns; spin_unlock_irq(&substream->lock); snd_iprintf(buffer, " Buffer size : %lu\n" " Avail : %lu\n" " Overruns : %lu\n", buffer_size, avail, xruns); if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) { clock_type = substream->clock_type >> SNDRV_RAWMIDI_MODE_CLOCK_SHIFT; if (!snd_BUG_ON(clock_type >= ARRAY_SIZE(clock_names))) snd_iprintf(buffer, " Framing : tstamp\n" " Clock type : %s\n", clock_names[clock_type]); } } } } mutex_unlock(&rmidi->open_mutex); } /* * Register functions */ static const struct file_operations snd_rawmidi_f_ops = { .owner = THIS_MODULE, .read = snd_rawmidi_read, .write = snd_rawmidi_write, .open = snd_rawmidi_open, .release = snd_rawmidi_release, .llseek = no_llseek, .poll = snd_rawmidi_poll, .unlocked_ioctl = snd_rawmidi_ioctl, .compat_ioctl = snd_rawmidi_ioctl_compat, }; static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi, struct snd_rawmidi_str *stream, int direction, int count) { struct snd_rawmidi_substream *substream; int idx; for (idx = 0; idx < count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); if (!substream) return -ENOMEM; substream->stream = direction; substream->number = idx; substream->rmidi = rmidi; substream->pstr = stream; spin_lock_init(&substream->lock); list_add_tail(&substream->list, &stream->substreams); stream->substream_count++; } return 0; } /* used for both rawmidi and ump */ int snd_rawmidi_init(struct snd_rawmidi *rmidi, struct snd_card *card, char *id, int device, int output_count, int input_count, unsigned int info_flags) { int err; static const struct snd_device_ops ops = { .dev_free = snd_rawmidi_dev_free, .dev_register = snd_rawmidi_dev_register, .dev_disconnect = snd_rawmidi_dev_disconnect, }; rmidi->card = card; rmidi->device = device; mutex_init(&rmidi->open_mutex); init_waitqueue_head(&rmidi->open_wait); INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams); INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams); rmidi->info_flags = info_flags; if (id != NULL) strscpy(rmidi->id, id, sizeof(rmidi->id)); err = snd_device_alloc(&rmidi->dev, card); if (err < 0) return err; if (rawmidi_is_ump(rmidi)) dev_set_name(rmidi->dev, "umpC%iD%i", card->number, device); else dev_set_name(rmidi->dev, "midiC%iD%i", card->number, device); err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], SNDRV_RAWMIDI_STREAM_INPUT, input_count); if (err < 0) return err; err = snd_rawmidi_alloc_substreams(rmidi, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT], SNDRV_RAWMIDI_STREAM_OUTPUT, output_count); if (err < 0) return err; err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops); if (err < 0) return err; return 0; } EXPORT_SYMBOL_GPL(snd_rawmidi_init); /** * snd_rawmidi_new - create a rawmidi instance * @card: the card instance * @id: the id string * @device: the device index * @output_count: the number of output streams * @input_count: the number of input streams * @rrawmidi: the pointer to store the new rawmidi instance * * Creates a new rawmidi instance. * Use snd_rawmidi_set_ops() to set the operators to the new instance. * * Return: Zero if successful, or a negative error code on failure. */ int snd_rawmidi_new(struct snd_card *card, char *id, int device, int output_count, int input_count, struct snd_rawmidi **rrawmidi) { struct snd_rawmidi *rmidi; int err; if (rrawmidi) *rrawmidi = NULL; rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL); if (!rmidi) return -ENOMEM; err = snd_rawmidi_init(rmidi, card, id, device, output_count, input_count, 0); if (err < 0) { snd_rawmidi_free(rmidi); return err; } if (rrawmidi) *rrawmidi = rmidi; return 0; } EXPORT_SYMBOL(snd_rawmidi_new); static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream) { struct snd_rawmidi_substream *substream; while (!list_empty(&stream->substreams)) { substream = list_entry(stream->substreams.next, struct snd_rawmidi_substream, list); list_del(&substream->list); kfree(substream); } } /* called from ump.c, too */ int snd_rawmidi_free(struct snd_rawmidi *rmidi) { if (!rmidi) return 0; snd_info_free_entry(rmidi->proc_entry); rmidi->proc_entry = NULL; if (rmidi->ops && rmidi->ops->dev_unregister) rmidi->ops->dev_unregister(rmidi); snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]); snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); if (rmidi->private_free) rmidi->private_free(rmidi); put_device(rmidi->dev); kfree(rmidi); return 0; } EXPORT_SYMBOL_GPL(snd_rawmidi_free); static int snd_rawmidi_dev_free(struct snd_device *device) { struct snd_rawmidi *rmidi = device->device_data; return snd_rawmidi_free(rmidi); } #if IS_ENABLED(CONFIG_SND_SEQUENCER) static void snd_rawmidi_dev_seq_free(struct snd_seq_device *device) { struct snd_rawmidi *rmidi = device->private_data; rmidi->seq_dev = NULL; } #endif static int snd_rawmidi_dev_register(struct snd_device *device) { int err; struct snd_info_entry *entry; char name[16]; struct snd_rawmidi *rmidi = device->device_data; if (rmidi->device >= SNDRV_RAWMIDI_DEVICES) return -ENOMEM; err = 0; mutex_lock(&register_mutex); if (snd_rawmidi_search(rmidi->card, rmidi->device)) err = -EBUSY; else list_add_tail(&rmidi->list, &snd_rawmidi_devices); mutex_unlock(&register_mutex); if (err < 0) return err; err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device, &snd_rawmidi_f_ops, rmidi, rmidi->dev); if (err < 0) { rmidi_err(rmidi, "unable to register\n"); goto error; } if (rmidi->ops && rmidi->ops->dev_register) { err = rmidi->ops->dev_register(rmidi); if (err < 0) goto error_unregister; } #ifdef CONFIG_SND_OSSEMUL rmidi->ossreg = 0; if (!rawmidi_is_ump(rmidi) && (int)rmidi->device == midi_map[rmidi->card->number]) { if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 0, &snd_rawmidi_f_ops, rmidi) < 0) { rmidi_err(rmidi, "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 0); } else { rmidi->ossreg++; #ifdef SNDRV_OSS_INFO_DEV_MIDI snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number, rmidi->name); #endif } } if (!rawmidi_is_ump(rmidi) && (int)rmidi->device == amidi_map[rmidi->card->number]) { if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 1, &snd_rawmidi_f_ops, rmidi) < 0) { rmidi_err(rmidi, "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 1); } else { rmidi->ossreg++; } } #endif /* CONFIG_SND_OSSEMUL */ sprintf(name, "midi%d", rmidi->device); entry = snd_info_create_card_entry(rmidi->card, name, rmidi->card->proc_root); if (entry) { entry->private_data = rmidi; entry->c.text.read = snd_rawmidi_proc_info_read; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } } rmidi->proc_entry = entry; #if IS_ENABLED(CONFIG_SND_SEQUENCER) /* no own registration mechanism? */ if (!rmidi->ops || !rmidi->ops->dev_register) { if (snd_seq_device_new(rmidi->card, rmidi->device, SNDRV_SEQ_DEV_ID_MIDISYNTH, 0, &rmidi->seq_dev) >= 0) { rmidi->seq_dev->private_data = rmidi; rmidi->seq_dev->private_free = snd_rawmidi_dev_seq_free; sprintf(rmidi->seq_dev->name, "MIDI %d-%d", rmidi->card->number, rmidi->device); snd_device_register(rmidi->card, rmidi->seq_dev); } } #endif return 0; error_unregister: snd_unregister_device(rmidi->dev); error: mutex_lock(&register_mutex); list_del(&rmidi->list); mutex_unlock(&register_mutex); return err; } static int snd_rawmidi_dev_disconnect(struct snd_device *device) { struct snd_rawmidi *rmidi = device->device_data; int dir; mutex_lock(&register_mutex); mutex_lock(&rmidi->open_mutex); wake_up(&rmidi->open_wait); list_del_init(&rmidi->list); for (dir = 0; dir < 2; dir++) { struct snd_rawmidi_substream *s; list_for_each_entry(s, &rmidi->streams[dir].substreams, list) { if (s->runtime) wake_up(&s->runtime->sleep); } } #ifdef CONFIG_SND_OSSEMUL if (rmidi->ossreg) { if ((int)rmidi->device == midi_map[rmidi->card->number]) { snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 0); #ifdef SNDRV_OSS_INFO_DEV_MIDI snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number); #endif } if ((int)rmidi->device == amidi_map[rmidi->card->number]) snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 1); rmidi->ossreg = 0; } #endif /* CONFIG_SND_OSSEMUL */ snd_unregister_device(rmidi->dev); mutex_unlock(&rmidi->open_mutex); mutex_unlock(&register_mutex); return 0; } /** * snd_rawmidi_set_ops - set the rawmidi operators * @rmidi: the rawmidi instance * @stream: the stream direction, SNDRV_RAWMIDI_STREAM_XXX * @ops: the operator table * * Sets the rawmidi operators for the given stream direction. */ void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream, const struct snd_rawmidi_ops *ops) { struct snd_rawmidi_substream *substream; list_for_each_entry(substream, &rmidi->streams[stream].substreams, list) substream->ops = ops; } EXPORT_SYMBOL(snd_rawmidi_set_ops); /* * ENTRY functions */ static int __init alsa_rawmidi_init(void) { snd_ctl_register_ioctl(snd_rawmidi_control_ioctl); snd_ctl_register_ioctl_compat(snd_rawmidi_control_ioctl); #ifdef CONFIG_SND_OSSEMUL { int i; /* check device map table */ for (i = 0; i < SNDRV_CARDS; i++) { if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) { pr_err("ALSA: rawmidi: invalid midi_map[%d] = %d\n", i, midi_map[i]); midi_map[i] = 0; } if (amidi_map[i] < 0 || amidi_map[i] >= SNDRV_RAWMIDI_DEVICES) { pr_err("ALSA: rawmidi: invalid amidi_map[%d] = %d\n", i, amidi_map[i]); amidi_map[i] = 1; } } } #endif /* CONFIG_SND_OSSEMUL */ return 0; } static void __exit alsa_rawmidi_exit(void) { snd_ctl_unregister_ioctl(snd_rawmidi_control_ioctl); snd_ctl_unregister_ioctl_compat(snd_rawmidi_control_ioctl); } module_init(alsa_rawmidi_init) module_exit(alsa_rawmidi_exit)
linux-master
sound/core/rawmidi.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]> * * Misc memory accessors */ #include <linux/export.h> #include <linux/io.h> #include <linux/uaccess.h> #include <sound/core.h> #include <sound/pcm.h> /** * copy_to_user_fromio - copy data from mmio-space to user-space * @dst: the destination pointer on user-space * @src: the source pointer on mmio * @count: the data size to copy in bytes * * Copies the data from mmio-space to user-space. * * Return: Zero if successful, or non-zero on failure. */ int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count) { struct iov_iter iter; if (import_ubuf(ITER_DEST, dst, count, &iter)) return -EFAULT; return copy_to_iter_fromio(&iter, (const void __iomem *)src, count); } EXPORT_SYMBOL(copy_to_user_fromio); /** * copy_to_iter_fromio - copy data from mmio-space to iov_iter * @dst: the destination iov_iter * @src: the source pointer on mmio * @count: the data size to copy in bytes * * Copies the data from mmio-space to iov_iter. * * Return: Zero if successful, or non-zero on failure. */ int copy_to_iter_fromio(struct iov_iter *dst, const void __iomem *src, size_t count) { #if defined(__i386__) || defined(CONFIG_SPARC32) return copy_to_iter((const void __force *)src, count, dst) == count ? 0 : -EFAULT; #else char buf[256]; while (count) { size_t c = count; if (c > sizeof(buf)) c = sizeof(buf); memcpy_fromio(buf, (void __iomem *)src, c); if (copy_to_iter(buf, c, dst) != c) return -EFAULT; count -= c; src += c; } return 0; #endif } EXPORT_SYMBOL(copy_to_iter_fromio); /** * copy_from_user_toio - copy data from user-space to mmio-space * @dst: the destination pointer on mmio-space * @src: the source pointer on user-space * @count: the data size to copy in bytes * * Copies the data from user-space to mmio-space. * * Return: Zero if successful, or non-zero on failure. */ int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count) { struct iov_iter iter; if (import_ubuf(ITER_SOURCE, (void __user *)src, count, &iter)) return -EFAULT; return copy_from_iter_toio((void __iomem *)dst, &iter, count); } EXPORT_SYMBOL(copy_from_user_toio); /** * copy_from_iter_toio - copy data from iov_iter to mmio-space * @dst: the destination pointer on mmio-space * @src: the source iov_iter * @count: the data size to copy in bytes * * Copies the data from iov_iter to mmio-space. * * Return: Zero if successful, or non-zero on failure. */ int copy_from_iter_toio(void __iomem *dst, struct iov_iter *src, size_t count) { #if defined(__i386__) || defined(CONFIG_SPARC32) return copy_from_iter((void __force *)dst, count, src) == count ? 0 : -EFAULT; #else char buf[256]; while (count) { size_t c = count; if (c > sizeof(buf)) c = sizeof(buf); if (copy_from_iter(buf, c, src) != c) return -EFAULT; memcpy_toio(dst, buf, c); count -= c; dst += c; } return 0; #endif } EXPORT_SYMBOL(copy_from_iter_toio);
linux-master
sound/core/memory.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * 32bit -> 64bit ioctl wrapper for hwdep API * Copyright (c) by Takashi Iwai <[email protected]> */ /* This file is included from hwdep.c */ #include <linux/compat.h> struct snd_hwdep_dsp_image32 { u32 index; unsigned char name[64]; u32 image; /* pointer */ u32 length; u32 driver_data; } /* don't set packed attribute here */; static int snd_hwdep_dsp_load_compat(struct snd_hwdep *hw, struct snd_hwdep_dsp_image32 __user *src) { struct snd_hwdep_dsp_image info = {}; compat_caddr_t ptr; if (copy_from_user(&info, src, 4 + 64) || get_user(ptr, &src->image) || get_user(info.length, &src->length) || get_user(info.driver_data, &src->driver_data)) return -EFAULT; info.image = compat_ptr(ptr); return snd_hwdep_dsp_load(hw, &info); } enum { SNDRV_HWDEP_IOCTL_DSP_LOAD32 = _IOW('H', 0x03, struct snd_hwdep_dsp_image32) }; static long snd_hwdep_ioctl_compat(struct file * file, unsigned int cmd, unsigned long arg) { struct snd_hwdep *hw = file->private_data; void __user *argp = compat_ptr(arg); switch (cmd) { case SNDRV_HWDEP_IOCTL_PVERSION: case SNDRV_HWDEP_IOCTL_INFO: case SNDRV_HWDEP_IOCTL_DSP_STATUS: return snd_hwdep_ioctl(file, cmd, (unsigned long)argp); case SNDRV_HWDEP_IOCTL_DSP_LOAD32: return snd_hwdep_dsp_load_compat(hw, argp); } if (hw->ops.ioctl_compat) return hw->ops.ioctl_compat(hw, file, cmd, arg); return -ENOIOCTLCMD; }
linux-master
sound/core/hwdep_compat.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA sequencer device management * Copyright (c) 1999 by Takashi Iwai <[email protected]> * *---------------------------------------------------------------- * * This device handler separates the card driver module from sequencer * stuff (sequencer core, synth drivers, etc), so that user can avoid * to spend unnecessary resources e.g. if he needs only listening to * MP3s. * * The card (or lowlevel) driver creates a sequencer device entry * via snd_seq_device_new(). This is an entry pointer to communicate * with the sequencer device "driver", which is involved with the * actual part to communicate with the sequencer core. * Each sequencer device entry has an id string and the corresponding * driver with the same id is loaded when required. For example, * lowlevel codes to access emu8000 chip on sbawe card are included in * emu8000-synth module. To activate this module, the hardware * resources like i/o port are passed via snd_seq_device argument. */ #include <linux/device.h> #include <linux/init.h> #include <linux/module.h> #include <sound/core.h> #include <sound/info.h> #include <sound/seq_device.h> #include <sound/seq_kernel.h> #include <sound/initval.h> #include <linux/kmod.h> #include <linux/slab.h> #include <linux/mutex.h> MODULE_AUTHOR("Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("ALSA sequencer device management"); MODULE_LICENSE("GPL"); /* * bus definition */ static int snd_seq_bus_match(struct device *dev, struct device_driver *drv) { struct snd_seq_device *sdev = to_seq_dev(dev); struct snd_seq_driver *sdrv = to_seq_drv(drv); return strcmp(sdrv->id, sdev->id) == 0 && sdrv->argsize == sdev->argsize; } static struct bus_type snd_seq_bus_type = { .name = "snd_seq", .match = snd_seq_bus_match, }; /* * proc interface -- just for compatibility */ #ifdef CONFIG_SND_PROC_FS static struct snd_info_entry *info_entry; static int print_dev_info(struct device *dev, void *data) { struct snd_seq_device *sdev = to_seq_dev(dev); struct snd_info_buffer *buffer = data; snd_iprintf(buffer, "snd-%s,%s,%d\n", sdev->id, dev->driver ? "loaded" : "empty", dev->driver ? 1 : 0); return 0; } static void snd_seq_device_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { bus_for_each_dev(&snd_seq_bus_type, NULL, buffer, print_dev_info); } #endif /* * load all registered drivers (called from seq_clientmgr.c) */ #ifdef CONFIG_MODULES /* flag to block auto-loading */ static atomic_t snd_seq_in_init = ATOMIC_INIT(1); /* blocked as default */ static int request_seq_drv(struct device *dev, void *data) { struct snd_seq_device *sdev = to_seq_dev(dev); if (!dev->driver) request_module("snd-%s", sdev->id); return 0; } static void autoload_drivers(struct work_struct *work) { /* avoid reentrance */ if (atomic_inc_return(&snd_seq_in_init) == 1) bus_for_each_dev(&snd_seq_bus_type, NULL, NULL, request_seq_drv); atomic_dec(&snd_seq_in_init); } static DECLARE_WORK(autoload_work, autoload_drivers); static void queue_autoload_drivers(void) { schedule_work(&autoload_work); } void snd_seq_autoload_init(void) { atomic_dec(&snd_seq_in_init); #ifdef CONFIG_SND_SEQUENCER_MODULE /* initial autoload only when snd-seq is a module */ queue_autoload_drivers(); #endif } EXPORT_SYMBOL(snd_seq_autoload_init); void snd_seq_autoload_exit(void) { atomic_inc(&snd_seq_in_init); } EXPORT_SYMBOL(snd_seq_autoload_exit); void snd_seq_device_load_drivers(void) { queue_autoload_drivers(); flush_work(&autoload_work); } EXPORT_SYMBOL(snd_seq_device_load_drivers); static inline void cancel_autoload_drivers(void) { cancel_work_sync(&autoload_work); } #else static inline void queue_autoload_drivers(void) { } static inline void cancel_autoload_drivers(void) { } #endif /* * device management */ static int snd_seq_device_dev_free(struct snd_device *device) { struct snd_seq_device *dev = device->device_data; cancel_autoload_drivers(); if (dev->private_free) dev->private_free(dev); put_device(&dev->dev); return 0; } static int snd_seq_device_dev_register(struct snd_device *device) { struct snd_seq_device *dev = device->device_data; int err; err = device_add(&dev->dev); if (err < 0) return err; if (!dev->dev.driver) queue_autoload_drivers(); return 0; } static int snd_seq_device_dev_disconnect(struct snd_device *device) { struct snd_seq_device *dev = device->device_data; device_del(&dev->dev); return 0; } static void snd_seq_dev_release(struct device *dev) { kfree(to_seq_dev(dev)); } /* * register a sequencer device * card = card info * device = device number (if any) * id = id of driver * result = return pointer (NULL allowed if unnecessary) */ int snd_seq_device_new(struct snd_card *card, int device, const char *id, int argsize, struct snd_seq_device **result) { struct snd_seq_device *dev; int err; static const struct snd_device_ops dops = { .dev_free = snd_seq_device_dev_free, .dev_register = snd_seq_device_dev_register, .dev_disconnect = snd_seq_device_dev_disconnect, }; if (result) *result = NULL; if (snd_BUG_ON(!id)) return -EINVAL; dev = kzalloc(sizeof(*dev) + argsize, GFP_KERNEL); if (!dev) return -ENOMEM; /* set up device info */ dev->card = card; dev->device = device; dev->id = id; dev->argsize = argsize; device_initialize(&dev->dev); dev->dev.parent = &card->card_dev; dev->dev.bus = &snd_seq_bus_type; dev->dev.release = snd_seq_dev_release; dev_set_name(&dev->dev, "%s-%d-%d", dev->id, card->number, device); /* add this device to the list */ err = snd_device_new(card, SNDRV_DEV_SEQUENCER, dev, &dops); if (err < 0) { put_device(&dev->dev); return err; } if (result) *result = dev; return 0; } EXPORT_SYMBOL(snd_seq_device_new); /* * driver registration */ int __snd_seq_driver_register(struct snd_seq_driver *drv, struct module *mod) { if (WARN_ON(!drv->driver.name || !drv->id)) return -EINVAL; drv->driver.bus = &snd_seq_bus_type; drv->driver.owner = mod; return driver_register(&drv->driver); } EXPORT_SYMBOL_GPL(__snd_seq_driver_register); void snd_seq_driver_unregister(struct snd_seq_driver *drv) { driver_unregister(&drv->driver); } EXPORT_SYMBOL_GPL(snd_seq_driver_unregister); /* * module part */ static int __init seq_dev_proc_init(void) { #ifdef CONFIG_SND_PROC_FS info_entry = snd_info_create_module_entry(THIS_MODULE, "drivers", snd_seq_root); if (info_entry == NULL) return -ENOMEM; info_entry->content = SNDRV_INFO_CONTENT_TEXT; info_entry->c.text.read = snd_seq_device_info; if (snd_info_register(info_entry) < 0) { snd_info_free_entry(info_entry); return -ENOMEM; } #endif return 0; } static int __init alsa_seq_device_init(void) { int err; err = bus_register(&snd_seq_bus_type); if (err < 0) return err; err = seq_dev_proc_init(); if (err < 0) bus_unregister(&snd_seq_bus_type); return err; } static void __exit alsa_seq_device_exit(void) { #ifdef CONFIG_MODULES cancel_work_sync(&autoload_work); #endif #ifdef CONFIG_SND_PROC_FS snd_info_free_entry(info_entry); #endif bus_unregister(&snd_seq_bus_type); } subsys_initcall(alsa_seq_device_init) module_exit(alsa_seq_device_exit)
linux-master
sound/core/seq_device.c
/* * PCM Interface - misc routines * Copyright (c) 1998 by Jaroslav Kysela <[email protected]> * * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <linux/time.h> #include <linux/export.h> #include <sound/core.h> #include <sound/pcm.h> #include "pcm_local.h" #define SND_PCM_FORMAT_UNKNOWN (-1) /* NOTE: "signed" prefix must be given below since the default char is * unsigned on some architectures! */ struct pcm_format_data { unsigned char width; /* bit width */ unsigned char phys; /* physical bit width */ signed char le; /* 0 = big-endian, 1 = little-endian, -1 = others */ signed char signd; /* 0 = unsigned, 1 = signed, -1 = others */ unsigned char silence[8]; /* silence data to fill */ }; /* we do lots of calculations on snd_pcm_format_t; shut up sparse */ #define INT __force int static bool valid_format(snd_pcm_format_t format) { return (INT)format >= 0 && (INT)format <= (INT)SNDRV_PCM_FORMAT_LAST; } static const struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = { [SNDRV_PCM_FORMAT_S8] = { .width = 8, .phys = 8, .le = -1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U8] = { .width = 8, .phys = 8, .le = -1, .signd = 0, .silence = { 0x80 }, }, [SNDRV_PCM_FORMAT_S16_LE] = { .width = 16, .phys = 16, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S16_BE] = { .width = 16, .phys = 16, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U16_LE] = { .width = 16, .phys = 16, .le = 1, .signd = 0, .silence = { 0x00, 0x80 }, }, [SNDRV_PCM_FORMAT_U16_BE] = { .width = 16, .phys = 16, .le = 0, .signd = 0, .silence = { 0x80, 0x00 }, }, [SNDRV_PCM_FORMAT_S24_LE] = { .width = 24, .phys = 32, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S24_BE] = { .width = 24, .phys = 32, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U24_LE] = { .width = 24, .phys = 32, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x80 }, }, [SNDRV_PCM_FORMAT_U24_BE] = { .width = 24, .phys = 32, .le = 0, .signd = 0, .silence = { 0x00, 0x80, 0x00, 0x00 }, }, [SNDRV_PCM_FORMAT_S32_LE] = { .width = 32, .phys = 32, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S32_BE] = { .width = 32, .phys = 32, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U32_LE] = { .width = 32, .phys = 32, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x00, 0x80 }, }, [SNDRV_PCM_FORMAT_U32_BE] = { .width = 32, .phys = 32, .le = 0, .signd = 0, .silence = { 0x80, 0x00, 0x00, 0x00 }, }, [SNDRV_PCM_FORMAT_FLOAT_LE] = { .width = 32, .phys = 32, .le = 1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_FLOAT_BE] = { .width = 32, .phys = 32, .le = 0, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_FLOAT64_LE] = { .width = 64, .phys = 64, .le = 1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_FLOAT64_BE] = { .width = 64, .phys = 64, .le = 0, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE] = { .width = 32, .phys = 32, .le = 1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE] = { .width = 32, .phys = 32, .le = 0, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_MU_LAW] = { .width = 8, .phys = 8, .le = -1, .signd = -1, .silence = { 0x7f }, }, [SNDRV_PCM_FORMAT_A_LAW] = { .width = 8, .phys = 8, .le = -1, .signd = -1, .silence = { 0x55 }, }, [SNDRV_PCM_FORMAT_IMA_ADPCM] = { .width = 4, .phys = 4, .le = -1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_G723_24] = { .width = 3, .phys = 3, .le = -1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_G723_40] = { .width = 5, .phys = 5, .le = -1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_DSD_U8] = { .width = 8, .phys = 8, .le = 1, .signd = 0, .silence = { 0x69 }, }, [SNDRV_PCM_FORMAT_DSD_U16_LE] = { .width = 16, .phys = 16, .le = 1, .signd = 0, .silence = { 0x69, 0x69 }, }, [SNDRV_PCM_FORMAT_DSD_U32_LE] = { .width = 32, .phys = 32, .le = 1, .signd = 0, .silence = { 0x69, 0x69, 0x69, 0x69 }, }, [SNDRV_PCM_FORMAT_DSD_U16_BE] = { .width = 16, .phys = 16, .le = 0, .signd = 0, .silence = { 0x69, 0x69 }, }, [SNDRV_PCM_FORMAT_DSD_U32_BE] = { .width = 32, .phys = 32, .le = 0, .signd = 0, .silence = { 0x69, 0x69, 0x69, 0x69 }, }, /* FIXME: the following two formats are not defined properly yet */ [SNDRV_PCM_FORMAT_MPEG] = { .le = -1, .signd = -1, }, [SNDRV_PCM_FORMAT_GSM] = { .le = -1, .signd = -1, }, [SNDRV_PCM_FORMAT_S20_LE] = { .width = 20, .phys = 32, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S20_BE] = { .width = 20, .phys = 32, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U20_LE] = { .width = 20, .phys = 32, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x08, 0x00 }, }, [SNDRV_PCM_FORMAT_U20_BE] = { .width = 20, .phys = 32, .le = 0, .signd = 0, .silence = { 0x00, 0x08, 0x00, 0x00 }, }, /* FIXME: the following format is not defined properly yet */ [SNDRV_PCM_FORMAT_SPECIAL] = { .le = -1, .signd = -1, }, [SNDRV_PCM_FORMAT_S24_3LE] = { .width = 24, .phys = 24, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S24_3BE] = { .width = 24, .phys = 24, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U24_3LE] = { .width = 24, .phys = 24, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x80 }, }, [SNDRV_PCM_FORMAT_U24_3BE] = { .width = 24, .phys = 24, .le = 0, .signd = 0, .silence = { 0x80, 0x00, 0x00 }, }, [SNDRV_PCM_FORMAT_S20_3LE] = { .width = 20, .phys = 24, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S20_3BE] = { .width = 20, .phys = 24, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U20_3LE] = { .width = 20, .phys = 24, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x08 }, }, [SNDRV_PCM_FORMAT_U20_3BE] = { .width = 20, .phys = 24, .le = 0, .signd = 0, .silence = { 0x08, 0x00, 0x00 }, }, [SNDRV_PCM_FORMAT_S18_3LE] = { .width = 18, .phys = 24, .le = 1, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_S18_3BE] = { .width = 18, .phys = 24, .le = 0, .signd = 1, .silence = {}, }, [SNDRV_PCM_FORMAT_U18_3LE] = { .width = 18, .phys = 24, .le = 1, .signd = 0, .silence = { 0x00, 0x00, 0x02 }, }, [SNDRV_PCM_FORMAT_U18_3BE] = { .width = 18, .phys = 24, .le = 0, .signd = 0, .silence = { 0x02, 0x00, 0x00 }, }, [SNDRV_PCM_FORMAT_G723_24_1B] = { .width = 3, .phys = 8, .le = -1, .signd = -1, .silence = {}, }, [SNDRV_PCM_FORMAT_G723_40_1B] = { .width = 5, .phys = 8, .le = -1, .signd = -1, .silence = {}, }, }; /** * snd_pcm_format_signed - Check the PCM format is signed linear * @format: the format to check * * Return: 1 if the given PCM format is signed linear, 0 if unsigned * linear, and a negative error code for non-linear formats. */ int snd_pcm_format_signed(snd_pcm_format_t format) { int val; if (!valid_format(format)) return -EINVAL; val = pcm_formats[(INT)format].signd; if (val < 0) return -EINVAL; return val; } EXPORT_SYMBOL(snd_pcm_format_signed); /** * snd_pcm_format_unsigned - Check the PCM format is unsigned linear * @format: the format to check * * Return: 1 if the given PCM format is unsigned linear, 0 if signed * linear, and a negative error code for non-linear formats. */ int snd_pcm_format_unsigned(snd_pcm_format_t format) { int val; val = snd_pcm_format_signed(format); if (val < 0) return val; return !val; } EXPORT_SYMBOL(snd_pcm_format_unsigned); /** * snd_pcm_format_linear - Check the PCM format is linear * @format: the format to check * * Return: 1 if the given PCM format is linear, 0 if not. */ int snd_pcm_format_linear(snd_pcm_format_t format) { return snd_pcm_format_signed(format) >= 0; } EXPORT_SYMBOL(snd_pcm_format_linear); /** * snd_pcm_format_little_endian - Check the PCM format is little-endian * @format: the format to check * * Return: 1 if the given PCM format is little-endian, 0 if * big-endian, or a negative error code if endian not specified. */ int snd_pcm_format_little_endian(snd_pcm_format_t format) { int val; if (!valid_format(format)) return -EINVAL; val = pcm_formats[(INT)format].le; if (val < 0) return -EINVAL; return val; } EXPORT_SYMBOL(snd_pcm_format_little_endian); /** * snd_pcm_format_big_endian - Check the PCM format is big-endian * @format: the format to check * * Return: 1 if the given PCM format is big-endian, 0 if * little-endian, or a negative error code if endian not specified. */ int snd_pcm_format_big_endian(snd_pcm_format_t format) { int val; val = snd_pcm_format_little_endian(format); if (val < 0) return val; return !val; } EXPORT_SYMBOL(snd_pcm_format_big_endian); /** * snd_pcm_format_width - return the bit-width of the format * @format: the format to check * * Return: The bit-width of the format, or a negative error code * if unknown format. */ int snd_pcm_format_width(snd_pcm_format_t format) { int val; if (!valid_format(format)) return -EINVAL; val = pcm_formats[(INT)format].width; if (!val) return -EINVAL; return val; } EXPORT_SYMBOL(snd_pcm_format_width); /** * snd_pcm_format_physical_width - return the physical bit-width of the format * @format: the format to check * * Return: The physical bit-width of the format, or a negative error code * if unknown format. */ int snd_pcm_format_physical_width(snd_pcm_format_t format) { int val; if (!valid_format(format)) return -EINVAL; val = pcm_formats[(INT)format].phys; if (!val) return -EINVAL; return val; } EXPORT_SYMBOL(snd_pcm_format_physical_width); /** * snd_pcm_format_size - return the byte size of samples on the given format * @format: the format to check * @samples: sampling rate * * Return: The byte size of the given samples for the format, or a * negative error code if unknown format. */ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples) { int phys_width = snd_pcm_format_physical_width(format); if (phys_width < 0) return -EINVAL; return samples * phys_width / 8; } EXPORT_SYMBOL(snd_pcm_format_size); /** * snd_pcm_format_silence_64 - return the silent data in 8 bytes array * @format: the format to check * * Return: The format pattern to fill or %NULL if error. */ const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format) { if (!valid_format(format)) return NULL; if (! pcm_formats[(INT)format].phys) return NULL; return pcm_formats[(INT)format].silence; } EXPORT_SYMBOL(snd_pcm_format_silence_64); /** * snd_pcm_format_set_silence - set the silence data on the buffer * @format: the PCM format * @data: the buffer pointer * @samples: the number of samples to set silence * * Sets the silence data on the buffer for the given samples. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples) { int width; unsigned char *dst; const unsigned char *pat; if (!valid_format(format)) return -EINVAL; if (samples == 0) return 0; width = pcm_formats[(INT)format].phys; /* physical width */ pat = pcm_formats[(INT)format].silence; if (!width || !pat) return -EINVAL; /* signed or 1 byte data */ if (pcm_formats[(INT)format].signd == 1 || width <= 8) { unsigned int bytes = samples * width / 8; memset(data, *pat, bytes); return 0; } /* non-zero samples, fill using a loop */ width /= 8; dst = data; #if 0 while (samples--) { memcpy(dst, pat, width); dst += width; } #else /* a bit optimization for constant width */ switch (width) { case 2: while (samples--) { memcpy(dst, pat, 2); dst += 2; } break; case 3: while (samples--) { memcpy(dst, pat, 3); dst += 3; } break; case 4: while (samples--) { memcpy(dst, pat, 4); dst += 4; } break; case 8: while (samples--) { memcpy(dst, pat, 8); dst += 8; } break; } #endif return 0; } EXPORT_SYMBOL(snd_pcm_format_set_silence); /** * snd_pcm_hw_limit_rates - determine rate_min/rate_max fields * @hw: the pcm hw instance * * Determines the rate_min and rate_max fields from the rates bits of * the given hw. * * Return: Zero if successful. */ int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw) { int i; for (i = 0; i < (int)snd_pcm_known_rates.count; i++) { if (hw->rates & (1 << i)) { hw->rate_min = snd_pcm_known_rates.list[i]; break; } } for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) { if (hw->rates & (1 << i)) { hw->rate_max = snd_pcm_known_rates.list[i]; break; } } return 0; } EXPORT_SYMBOL(snd_pcm_hw_limit_rates); /** * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit * @rate: the sample rate to convert * * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate, or * SNDRV_PCM_RATE_KNOT for an unknown rate. */ unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate) { unsigned int i; for (i = 0; i < snd_pcm_known_rates.count; i++) if (snd_pcm_known_rates.list[i] == rate) return 1u << i; return SNDRV_PCM_RATE_KNOT; } EXPORT_SYMBOL(snd_pcm_rate_to_rate_bit); /** * snd_pcm_rate_bit_to_rate - converts SNDRV_PCM_RATE_xxx bit to sample rate * @rate_bit: the rate bit to convert * * Return: The sample rate that corresponds to the given SNDRV_PCM_RATE_xxx flag * or 0 for an unknown rate bit. */ unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit) { unsigned int i; for (i = 0; i < snd_pcm_known_rates.count; i++) if ((1u << i) == rate_bit) return snd_pcm_known_rates.list[i]; return 0; } EXPORT_SYMBOL(snd_pcm_rate_bit_to_rate); static unsigned int snd_pcm_rate_mask_sanitize(unsigned int rates) { if (rates & SNDRV_PCM_RATE_CONTINUOUS) return SNDRV_PCM_RATE_CONTINUOUS; else if (rates & SNDRV_PCM_RATE_KNOT) return SNDRV_PCM_RATE_KNOT; return rates; } /** * snd_pcm_rate_mask_intersect - computes the intersection between two rate masks * @rates_a: The first rate mask * @rates_b: The second rate mask * * This function computes the rates that are supported by both rate masks passed * to the function. It will take care of the special handling of * SNDRV_PCM_RATE_CONTINUOUS and SNDRV_PCM_RATE_KNOT. * * Return: A rate mask containing the rates that are supported by both rates_a * and rates_b. */ unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a, unsigned int rates_b) { rates_a = snd_pcm_rate_mask_sanitize(rates_a); rates_b = snd_pcm_rate_mask_sanitize(rates_b); if (rates_a & SNDRV_PCM_RATE_CONTINUOUS) return rates_b; else if (rates_b & SNDRV_PCM_RATE_CONTINUOUS) return rates_a; else if (rates_a & SNDRV_PCM_RATE_KNOT) return rates_b; else if (rates_b & SNDRV_PCM_RATE_KNOT) return rates_a; return rates_a & rates_b; } EXPORT_SYMBOL_GPL(snd_pcm_rate_mask_intersect); /** * snd_pcm_rate_range_to_bits - converts rate range to SNDRV_PCM_RATE_xxx bit * @rate_min: the minimum sample rate * @rate_max: the maximum sample rate * * This function has an implicit assumption: the rates in the given range have * only the pre-defined rates like 44100 or 16000. * * Return: The SNDRV_PCM_RATE_xxx flag that corresponds to the given rate range, * or SNDRV_PCM_RATE_KNOT for an unknown range. */ unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min, unsigned int rate_max) { unsigned int rates = 0; int i; for (i = 0; i < snd_pcm_known_rates.count; i++) { if (snd_pcm_known_rates.list[i] >= rate_min && snd_pcm_known_rates.list[i] <= rate_max) rates |= 1 << i; } if (!rates) rates = SNDRV_PCM_RATE_KNOT; return rates; } EXPORT_SYMBOL_GPL(snd_pcm_rate_range_to_bits);
linux-master
sound/core/pcm_misc.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Initialization routines * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/sched.h> #include <linux/module.h> #include <linux/device.h> #include <linux/file.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/ctype.h> #include <linux/pm.h> #include <linux/debugfs.h> #include <linux/completion.h> #include <linux/interrupt.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> /* monitor files for graceful shutdown (hotplug) */ struct snd_monitor_file { struct file *file; const struct file_operations *disconnected_f_op; struct list_head shutdown_list; /* still need to shutdown */ struct list_head list; /* link of monitor files */ }; static DEFINE_SPINLOCK(shutdown_lock); static LIST_HEAD(shutdown_files); static const struct file_operations snd_shutdown_f_ops; /* locked for registering/using */ static DECLARE_BITMAP(snd_cards_lock, SNDRV_CARDS); static struct snd_card *snd_cards[SNDRV_CARDS]; static DEFINE_MUTEX(snd_card_mutex); static char *slots[SNDRV_CARDS]; module_param_array(slots, charp, NULL, 0444); MODULE_PARM_DESC(slots, "Module names assigned to the slots."); /* return non-zero if the given index is reserved for the given * module via slots option */ static int module_slot_match(struct module *module, int idx) { int match = 1; #ifdef MODULE const char *s1, *s2; if (!module || !*module->name || !slots[idx]) return 0; s1 = module->name; s2 = slots[idx]; if (*s2 == '!') { match = 0; /* negative match */ s2++; } /* compare module name strings * hyphens are handled as equivalent with underscore */ for (;;) { char c1 = *s1++; char c2 = *s2++; if (c1 == '-') c1 = '_'; if (c2 == '-') c2 = '_'; if (c1 != c2) return !match; if (!c1) break; } #endif /* MODULE */ return match; } #if IS_ENABLED(CONFIG_SND_MIXER_OSS) int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag); EXPORT_SYMBOL(snd_mixer_oss_notify_callback); #endif static int check_empty_slot(struct module *module, int slot) { return !slots[slot] || !*slots[slot]; } /* return an empty slot number (>= 0) found in the given bitmask @mask. * @mask == -1 == 0xffffffff means: take any free slot up to 32 * when no slot is available, return the original @mask as is. */ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int), struct module *module) { int slot; for (slot = 0; slot < SNDRV_CARDS; slot++) { if (slot < 32 && !(mask & (1U << slot))) continue; if (!test_bit(slot, snd_cards_lock)) { if (check(module, slot)) return slot; /* found */ } } return mask; /* unchanged */ } /* the default release callback set in snd_device_alloc() */ static void default_release_alloc(struct device *dev) { kfree(dev); } /** * snd_device_alloc - Allocate and initialize struct device for sound devices * @dev_p: pointer to store the allocated device * @card: card to assign, optional * * For releasing the allocated device, call put_device(). */ int snd_device_alloc(struct device **dev_p, struct snd_card *card) { struct device *dev; *dev_p = NULL; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; device_initialize(dev); if (card) dev->parent = &card->card_dev; dev->class = &sound_class; dev->release = default_release_alloc; *dev_p = dev; return 0; } EXPORT_SYMBOL_GPL(snd_device_alloc); static int snd_card_init(struct snd_card *card, struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size); static int snd_card_do_free(struct snd_card *card); static const struct attribute_group card_dev_attr_group; static void release_card_device(struct device *dev) { snd_card_do_free(dev_to_snd_card(dev)); } /** * snd_card_new - create and initialize a soundcard structure * @parent: the parent device object * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] * @xid: card identification (ASCII string) * @module: top level module for locking * @extra_size: allocate this extra size after the main soundcard structure * @card_ret: the pointer to store the created card instance * * The function allocates snd_card instance via kzalloc with the given * space for the driver to use freely. The allocated struct is stored * in the given card_ret pointer. * * Return: Zero if successful or a negative error code. */ int snd_card_new(struct device *parent, int idx, const char *xid, struct module *module, int extra_size, struct snd_card **card_ret) { struct snd_card *card; int err; if (snd_BUG_ON(!card_ret)) return -EINVAL; *card_ret = NULL; if (extra_size < 0) extra_size = 0; card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); if (!card) return -ENOMEM; err = snd_card_init(card, parent, idx, xid, module, extra_size); if (err < 0) return err; /* card is freed by error handler */ *card_ret = card; return 0; } EXPORT_SYMBOL(snd_card_new); static void __snd_card_release(struct device *dev, void *data) { snd_card_free(data); } /** * snd_devm_card_new - managed snd_card object creation * @parent: the parent device object * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] * @xid: card identification (ASCII string) * @module: top level module for locking * @extra_size: allocate this extra size after the main soundcard structure * @card_ret: the pointer to store the created card instance * * This function works like snd_card_new() but manages the allocated resource * via devres, i.e. you don't need to free explicitly. * * When a snd_card object is created with this function and registered via * snd_card_register(), the very first devres action to call snd_card_free() * is added automatically. In that way, the resource disconnection is assured * at first, then released in the expected order. * * If an error happens at the probe before snd_card_register() is called and * there have been other devres resources, you'd need to free the card manually * via snd_card_free() call in the error; otherwise it may lead to UAF due to * devres call orders. You can use snd_card_free_on_error() helper for * handling it more easily. * * Return: zero if successful, or a negative error code */ int snd_devm_card_new(struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size, struct snd_card **card_ret) { struct snd_card *card; int err; *card_ret = NULL; card = devres_alloc(__snd_card_release, sizeof(*card) + extra_size, GFP_KERNEL); if (!card) return -ENOMEM; card->managed = true; err = snd_card_init(card, parent, idx, xid, module, extra_size); if (err < 0) { devres_free(card); /* in managed mode, we need to free manually */ return err; } devres_add(parent, card); *card_ret = card; return 0; } EXPORT_SYMBOL_GPL(snd_devm_card_new); /** * snd_card_free_on_error - a small helper for handling devm probe errors * @dev: the managed device object * @ret: the return code from the probe callback * * This function handles the explicit snd_card_free() call at the error from * the probe callback. It's just a small helper for simplifying the error * handling with the managed devices. * * Return: zero if successful, or a negative error code */ int snd_card_free_on_error(struct device *dev, int ret) { struct snd_card *card; if (!ret) return 0; card = devres_find(dev, __snd_card_release, NULL, NULL); if (card) snd_card_free(card); return ret; } EXPORT_SYMBOL_GPL(snd_card_free_on_error); static int snd_card_init(struct snd_card *card, struct device *parent, int idx, const char *xid, struct module *module, size_t extra_size) { int err; if (extra_size > 0) card->private_data = (char *)card + sizeof(struct snd_card); if (xid) strscpy(card->id, xid, sizeof(card->id)); err = 0; mutex_lock(&snd_card_mutex); if (idx < 0) /* first check the matching module-name slot */ idx = get_slot_from_bitmask(idx, module_slot_match, module); if (idx < 0) /* if not matched, assign an empty slot */ idx = get_slot_from_bitmask(idx, check_empty_slot, module); if (idx < 0) err = -ENODEV; else if (idx < snd_ecards_limit) { if (test_bit(idx, snd_cards_lock)) err = -EBUSY; /* invalid */ } else if (idx >= SNDRV_CARDS) err = -ENODEV; if (err < 0) { mutex_unlock(&snd_card_mutex); dev_err(parent, "cannot find the slot for index %d (range 0-%i), error: %d\n", idx, snd_ecards_limit - 1, err); if (!card->managed) kfree(card); /* manually free here, as no destructor called */ return err; } set_bit(idx, snd_cards_lock); /* lock it */ if (idx >= snd_ecards_limit) snd_ecards_limit = idx + 1; /* increase the limit */ mutex_unlock(&snd_card_mutex); card->dev = parent; card->number = idx; #ifdef MODULE WARN_ON(!module); card->module = module; #endif INIT_LIST_HEAD(&card->devices); init_rwsem(&card->controls_rwsem); rwlock_init(&card->ctl_files_rwlock); INIT_LIST_HEAD(&card->controls); INIT_LIST_HEAD(&card->ctl_files); #ifdef CONFIG_SND_CTL_FAST_LOOKUP xa_init(&card->ctl_numids); xa_init(&card->ctl_hash); #endif spin_lock_init(&card->files_lock); INIT_LIST_HEAD(&card->files_list); mutex_init(&card->memory_mutex); #ifdef CONFIG_PM init_waitqueue_head(&card->power_sleep); init_waitqueue_head(&card->power_ref_sleep); atomic_set(&card->power_ref, 0); #endif init_waitqueue_head(&card->remove_sleep); card->sync_irq = -1; device_initialize(&card->card_dev); card->card_dev.parent = parent; card->card_dev.class = &sound_class; card->card_dev.release = release_card_device; card->card_dev.groups = card->dev_groups; card->dev_groups[0] = &card_dev_attr_group; err = kobject_set_name(&card->card_dev.kobj, "card%d", idx); if (err < 0) goto __error; snprintf(card->irq_descr, sizeof(card->irq_descr), "%s:%s", dev_driver_string(card->dev), dev_name(&card->card_dev)); /* the control interface cannot be accessed from the user space until */ /* snd_cards_bitmask and snd_cards are set with snd_card_register */ err = snd_ctl_create(card); if (err < 0) { dev_err(parent, "unable to register control minors\n"); goto __error; } err = snd_info_card_create(card); if (err < 0) { dev_err(parent, "unable to create card info\n"); goto __error_ctl; } #ifdef CONFIG_SND_DEBUG card->debugfs_root = debugfs_create_dir(dev_name(&card->card_dev), sound_debugfs_root); #endif return 0; __error_ctl: snd_device_free_all(card); __error: put_device(&card->card_dev); return err; } /** * snd_card_ref - Get the card object from the index * @idx: the card index * * Returns a card object corresponding to the given index or NULL if not found. * Release the object via snd_card_unref(). * * Return: a card object or NULL */ struct snd_card *snd_card_ref(int idx) { struct snd_card *card; mutex_lock(&snd_card_mutex); card = snd_cards[idx]; if (card) get_device(&card->card_dev); mutex_unlock(&snd_card_mutex); return card; } EXPORT_SYMBOL_GPL(snd_card_ref); /* return non-zero if a card is already locked */ int snd_card_locked(int card) { int locked; mutex_lock(&snd_card_mutex); locked = test_bit(card, snd_cards_lock); mutex_unlock(&snd_card_mutex); return locked; } static loff_t snd_disconnect_llseek(struct file *file, loff_t offset, int orig) { return -ENODEV; } static ssize_t snd_disconnect_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { return -ENODEV; } static ssize_t snd_disconnect_write(struct file *file, const char __user *buf, size_t count, loff_t *offset) { return -ENODEV; } static int snd_disconnect_release(struct inode *inode, struct file *file) { struct snd_monitor_file *df = NULL, *_df; spin_lock(&shutdown_lock); list_for_each_entry(_df, &shutdown_files, shutdown_list) { if (_df->file == file) { df = _df; list_del_init(&df->shutdown_list); break; } } spin_unlock(&shutdown_lock); if (likely(df)) { if ((file->f_flags & FASYNC) && df->disconnected_f_op->fasync) df->disconnected_f_op->fasync(-1, file, 0); return df->disconnected_f_op->release(inode, file); } panic("%s(%p, %p) failed!", __func__, inode, file); } static __poll_t snd_disconnect_poll(struct file * file, poll_table * wait) { return EPOLLERR | EPOLLNVAL; } static long snd_disconnect_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return -ENODEV; } static int snd_disconnect_mmap(struct file *file, struct vm_area_struct *vma) { return -ENODEV; } static int snd_disconnect_fasync(int fd, struct file *file, int on) { return -ENODEV; } static const struct file_operations snd_shutdown_f_ops = { .owner = THIS_MODULE, .llseek = snd_disconnect_llseek, .read = snd_disconnect_read, .write = snd_disconnect_write, .release = snd_disconnect_release, .poll = snd_disconnect_poll, .unlocked_ioctl = snd_disconnect_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = snd_disconnect_ioctl, #endif .mmap = snd_disconnect_mmap, .fasync = snd_disconnect_fasync }; /** * snd_card_disconnect - disconnect all APIs from the file-operations (user space) * @card: soundcard structure * * Disconnects all APIs from the file-operations (user space). * * Return: Zero, otherwise a negative error code. * * Note: The current implementation replaces all active file->f_op with special * dummy file operations (they do nothing except release). */ void snd_card_disconnect(struct snd_card *card) { struct snd_monitor_file *mfile; if (!card) return; spin_lock(&card->files_lock); if (card->shutdown) { spin_unlock(&card->files_lock); return; } card->shutdown = 1; /* replace file->f_op with special dummy operations */ list_for_each_entry(mfile, &card->files_list, list) { /* it's critical part, use endless loop */ /* we have no room to fail */ mfile->disconnected_f_op = mfile->file->f_op; spin_lock(&shutdown_lock); list_add(&mfile->shutdown_list, &shutdown_files); spin_unlock(&shutdown_lock); mfile->file->f_op = &snd_shutdown_f_ops; fops_get(mfile->file->f_op); } spin_unlock(&card->files_lock); /* notify all connected devices about disconnection */ /* at this point, they cannot respond to any calls except release() */ #if IS_ENABLED(CONFIG_SND_MIXER_OSS) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_DISCONNECT); #endif /* notify all devices that we are disconnected */ snd_device_disconnect_all(card); if (card->sync_irq > 0) synchronize_irq(card->sync_irq); snd_info_card_disconnect(card); if (card->registered) { device_del(&card->card_dev); card->registered = false; } /* disable fops (user space) operations for ALSA API */ mutex_lock(&snd_card_mutex); snd_cards[card->number] = NULL; clear_bit(card->number, snd_cards_lock); mutex_unlock(&snd_card_mutex); #ifdef CONFIG_PM wake_up(&card->power_sleep); snd_power_sync_ref(card); #endif } EXPORT_SYMBOL(snd_card_disconnect); /** * snd_card_disconnect_sync - disconnect card and wait until files get closed * @card: card object to disconnect * * This calls snd_card_disconnect() for disconnecting all belonging components * and waits until all pending files get closed. * It assures that all accesses from user-space finished so that the driver * can release its resources gracefully. */ void snd_card_disconnect_sync(struct snd_card *card) { snd_card_disconnect(card); spin_lock_irq(&card->files_lock); wait_event_lock_irq(card->remove_sleep, list_empty(&card->files_list), card->files_lock); spin_unlock_irq(&card->files_lock); } EXPORT_SYMBOL_GPL(snd_card_disconnect_sync); static int snd_card_do_free(struct snd_card *card) { card->releasing = true; #if IS_ENABLED(CONFIG_SND_MIXER_OSS) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_FREE); #endif snd_device_free_all(card); if (card->private_free) card->private_free(card); if (snd_info_card_free(card) < 0) { dev_warn(card->dev, "unable to free card info\n"); /* Not fatal error */ } #ifdef CONFIG_SND_DEBUG debugfs_remove(card->debugfs_root); card->debugfs_root = NULL; #endif if (card->release_completion) complete(card->release_completion); if (!card->managed) kfree(card); return 0; } /** * snd_card_free_when_closed - Disconnect the card, free it later eventually * @card: soundcard structure * * Unlike snd_card_free(), this function doesn't try to release the card * resource immediately, but tries to disconnect at first. When the card * is still in use, the function returns before freeing the resources. * The card resources will be freed when the refcount gets to zero. * * Return: zero if successful, or a negative error code */ void snd_card_free_when_closed(struct snd_card *card) { if (!card) return; snd_card_disconnect(card); put_device(&card->card_dev); return; } EXPORT_SYMBOL(snd_card_free_when_closed); /** * snd_card_free - frees given soundcard structure * @card: soundcard structure * * This function releases the soundcard structure and the all assigned * devices automatically. That is, you don't have to release the devices * by yourself. * * This function waits until the all resources are properly released. * * Return: Zero. Frees all associated devices and frees the control * interface associated to given soundcard. */ void snd_card_free(struct snd_card *card) { DECLARE_COMPLETION_ONSTACK(released); /* The call of snd_card_free() is allowed from various code paths; * a manual call from the driver and the call via devres_free, and * we need to avoid double-free. Moreover, the release via devres * may call snd_card_free() twice due to its nature, we need to have * the check here at the beginning. */ if (card->releasing) return; card->release_completion = &released; snd_card_free_when_closed(card); /* wait, until all devices are ready for the free operation */ wait_for_completion(&released); } EXPORT_SYMBOL(snd_card_free); /* retrieve the last word of shortname or longname */ static const char *retrieve_id_from_card_name(const char *name) { const char *spos = name; while (*name) { if (isspace(*name) && isalnum(name[1])) spos = name + 1; name++; } return spos; } /* return true if the given id string doesn't conflict any other card ids */ static bool card_id_ok(struct snd_card *card, const char *id) { int i; if (!snd_info_check_reserved_words(id)) return false; for (i = 0; i < snd_ecards_limit; i++) { if (snd_cards[i] && snd_cards[i] != card && !strcmp(snd_cards[i]->id, id)) return false; } return true; } /* copy to card->id only with valid letters from nid */ static void copy_valid_id_string(struct snd_card *card, const char *src, const char *nid) { char *id = card->id; while (*nid && !isalnum(*nid)) nid++; if (isdigit(*nid)) *id++ = isalpha(*src) ? *src : 'D'; while (*nid && (size_t)(id - card->id) < sizeof(card->id) - 1) { if (isalnum(*nid)) *id++ = *nid; nid++; } *id = 0; } /* Set card->id from the given string * If the string conflicts with other ids, add a suffix to make it unique. */ static void snd_card_set_id_no_lock(struct snd_card *card, const char *src, const char *nid) { int len, loops; bool is_default = false; char *id; copy_valid_id_string(card, src, nid); id = card->id; again: /* use "Default" for obviously invalid strings * ("card" conflicts with proc directories) */ if (!*id || !strncmp(id, "card", 4)) { strcpy(id, "Default"); is_default = true; } len = strlen(id); for (loops = 0; loops < SNDRV_CARDS; loops++) { char *spos; char sfxstr[5]; /* "_012" */ int sfxlen; if (card_id_ok(card, id)) return; /* OK */ /* Add _XYZ suffix */ sprintf(sfxstr, "_%X", loops + 1); sfxlen = strlen(sfxstr); if (len + sfxlen >= sizeof(card->id)) spos = id + sizeof(card->id) - sfxlen - 1; else spos = id + len; strcpy(spos, sfxstr); } /* fallback to the default id */ if (!is_default) { *id = 0; goto again; } /* last resort... */ dev_err(card->dev, "unable to set card id (%s)\n", id); if (card->proc_root->name) strscpy(card->id, card->proc_root->name, sizeof(card->id)); } /** * snd_card_set_id - set card identification name * @card: soundcard structure * @nid: new identification string * * This function sets the card identification and checks for name * collisions. */ void snd_card_set_id(struct snd_card *card, const char *nid) { /* check if user specified own card->id */ if (card->id[0] != '\0') return; mutex_lock(&snd_card_mutex); snd_card_set_id_no_lock(card, nid, nid); mutex_unlock(&snd_card_mutex); } EXPORT_SYMBOL(snd_card_set_id); static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_card *card = container_of(dev, struct snd_card, card_dev); return sysfs_emit(buf, "%s\n", card->id); } static ssize_t id_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_card *card = container_of(dev, struct snd_card, card_dev); char buf1[sizeof(card->id)]; size_t copy = count > sizeof(card->id) - 1 ? sizeof(card->id) - 1 : count; size_t idx; int c; for (idx = 0; idx < copy; idx++) { c = buf[idx]; if (!isalnum(c) && c != '_' && c != '-') return -EINVAL; } memcpy(buf1, buf, copy); buf1[copy] = '\0'; mutex_lock(&snd_card_mutex); if (!card_id_ok(NULL, buf1)) { mutex_unlock(&snd_card_mutex); return -EEXIST; } strcpy(card->id, buf1); snd_info_card_id_change(card); mutex_unlock(&snd_card_mutex); return count; } static DEVICE_ATTR_RW(id); static ssize_t number_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_card *card = container_of(dev, struct snd_card, card_dev); return sysfs_emit(buf, "%i\n", card->number); } static DEVICE_ATTR_RO(number); static struct attribute *card_dev_attrs[] = { &dev_attr_id.attr, &dev_attr_number.attr, NULL }; static const struct attribute_group card_dev_attr_group = { .attrs = card_dev_attrs, }; /** * snd_card_add_dev_attr - Append a new sysfs attribute group to card * @card: card instance * @group: attribute group to append * * Return: zero if successful, or a negative error code */ int snd_card_add_dev_attr(struct snd_card *card, const struct attribute_group *group) { int i; /* loop for (arraysize-1) here to keep NULL at the last entry */ for (i = 0; i < ARRAY_SIZE(card->dev_groups) - 1; i++) { if (!card->dev_groups[i]) { card->dev_groups[i] = group; return 0; } } dev_err(card->dev, "Too many groups assigned\n"); return -ENOSPC; } EXPORT_SYMBOL_GPL(snd_card_add_dev_attr); static void trigger_card_free(void *data) { snd_card_free(data); } /** * snd_card_register - register the soundcard * @card: soundcard structure * * This function registers all the devices assigned to the soundcard. * Until calling this, the ALSA control interface is blocked from the * external accesses. Thus, you should call this function at the end * of the initialization of the card. * * Return: Zero otherwise a negative error code if the registration failed. */ int snd_card_register(struct snd_card *card) { int err; if (snd_BUG_ON(!card)) return -EINVAL; if (!card->registered) { err = device_add(&card->card_dev); if (err < 0) return err; card->registered = true; } else { if (card->managed) devm_remove_action(card->dev, trigger_card_free, card); } if (card->managed) { err = devm_add_action(card->dev, trigger_card_free, card); if (err < 0) return err; } err = snd_device_register_all(card); if (err < 0) return err; mutex_lock(&snd_card_mutex); if (snd_cards[card->number]) { /* already registered */ mutex_unlock(&snd_card_mutex); return snd_info_card_register(card); /* register pending info */ } if (*card->id) { /* make a unique id name from the given string */ char tmpid[sizeof(card->id)]; memcpy(tmpid, card->id, sizeof(card->id)); snd_card_set_id_no_lock(card, tmpid, tmpid); } else { /* create an id from either shortname or longname */ const char *src; src = *card->shortname ? card->shortname : card->longname; snd_card_set_id_no_lock(card, src, retrieve_id_from_card_name(src)); } snd_cards[card->number] = card; mutex_unlock(&snd_card_mutex); err = snd_info_card_register(card); if (err < 0) return err; #if IS_ENABLED(CONFIG_SND_MIXER_OSS) if (snd_mixer_oss_notify_callback) snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER); #endif return 0; } EXPORT_SYMBOL(snd_card_register); #ifdef CONFIG_SND_PROC_FS static void snd_card_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { int idx, count; struct snd_card *card; for (idx = count = 0; idx < SNDRV_CARDS; idx++) { mutex_lock(&snd_card_mutex); card = snd_cards[idx]; if (card) { count++; snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n", idx, card->id, card->driver, card->shortname); snd_iprintf(buffer, " %s\n", card->longname); } mutex_unlock(&snd_card_mutex); } if (!count) snd_iprintf(buffer, "--- no soundcards ---\n"); } #ifdef CONFIG_SND_OSSEMUL void snd_card_info_read_oss(struct snd_info_buffer *buffer) { int idx, count; struct snd_card *card; for (idx = count = 0; idx < SNDRV_CARDS; idx++) { mutex_lock(&snd_card_mutex); card = snd_cards[idx]; if (card) { count++; snd_iprintf(buffer, "%s\n", card->longname); } mutex_unlock(&snd_card_mutex); } if (!count) { snd_iprintf(buffer, "--- no soundcards ---\n"); } } #endif #ifdef MODULE static void snd_card_module_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { int idx; struct snd_card *card; for (idx = 0; idx < SNDRV_CARDS; idx++) { mutex_lock(&snd_card_mutex); card = snd_cards[idx]; if (card) snd_iprintf(buffer, "%2i %s\n", idx, card->module->name); mutex_unlock(&snd_card_mutex); } } #endif int __init snd_card_info_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "cards", NULL); if (! entry) return -ENOMEM; entry->c.text.read = snd_card_info_read; if (snd_info_register(entry) < 0) return -ENOMEM; /* freed in error path */ #ifdef MODULE entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL); if (!entry) return -ENOMEM; entry->c.text.read = snd_card_module_info_read; if (snd_info_register(entry) < 0) return -ENOMEM; /* freed in error path */ #endif return 0; } #endif /* CONFIG_SND_PROC_FS */ /** * snd_component_add - add a component string * @card: soundcard structure * @component: the component id string * * This function adds the component id string to the supported list. * The component can be referred from the alsa-lib. * * Return: Zero otherwise a negative error code. */ int snd_component_add(struct snd_card *card, const char *component) { char *ptr; int len = strlen(component); ptr = strstr(card->components, component); if (ptr != NULL) { if (ptr[len] == '\0' || ptr[len] == ' ') /* already there */ return 1; } if (strlen(card->components) + 1 + len + 1 > sizeof(card->components)) { snd_BUG(); return -ENOMEM; } if (card->components[0] != '\0') strcat(card->components, " "); strcat(card->components, component); return 0; } EXPORT_SYMBOL(snd_component_add); /** * snd_card_file_add - add the file to the file list of the card * @card: soundcard structure * @file: file pointer * * This function adds the file to the file linked-list of the card. * This linked-list is used to keep tracking the connection state, * and to avoid the release of busy resources by hotplug. * * Return: zero or a negative error code. */ int snd_card_file_add(struct snd_card *card, struct file *file) { struct snd_monitor_file *mfile; mfile = kmalloc(sizeof(*mfile), GFP_KERNEL); if (mfile == NULL) return -ENOMEM; mfile->file = file; mfile->disconnected_f_op = NULL; INIT_LIST_HEAD(&mfile->shutdown_list); spin_lock(&card->files_lock); if (card->shutdown) { spin_unlock(&card->files_lock); kfree(mfile); return -ENODEV; } list_add(&mfile->list, &card->files_list); get_device(&card->card_dev); spin_unlock(&card->files_lock); return 0; } EXPORT_SYMBOL(snd_card_file_add); /** * snd_card_file_remove - remove the file from the file list * @card: soundcard structure * @file: file pointer * * This function removes the file formerly added to the card via * snd_card_file_add() function. * If all files are removed and snd_card_free_when_closed() was * called beforehand, it processes the pending release of * resources. * * Return: Zero or a negative error code. */ int snd_card_file_remove(struct snd_card *card, struct file *file) { struct snd_monitor_file *mfile, *found = NULL; spin_lock(&card->files_lock); list_for_each_entry(mfile, &card->files_list, list) { if (mfile->file == file) { list_del(&mfile->list); spin_lock(&shutdown_lock); list_del(&mfile->shutdown_list); spin_unlock(&shutdown_lock); if (mfile->disconnected_f_op) fops_put(mfile->disconnected_f_op); found = mfile; break; } } if (list_empty(&card->files_list)) wake_up_all(&card->remove_sleep); spin_unlock(&card->files_lock); if (!found) { dev_err(card->dev, "card file remove problem (%p)\n", file); return -ENOENT; } kfree(found); put_device(&card->card_dev); return 0; } EXPORT_SYMBOL(snd_card_file_remove); #ifdef CONFIG_PM /** * snd_power_ref_and_wait - wait until the card gets powered up * @card: soundcard structure * * Take the power_ref reference count of the given card, and * wait until the card gets powered up to SNDRV_CTL_POWER_D0 state. * The refcount is down again while sleeping until power-up, hence this * function can be used for syncing the floating control ops accesses, * typically around calling control ops. * * The caller needs to pull down the refcount via snd_power_unref() later * no matter whether the error is returned from this function or not. * * Return: Zero if successful, or a negative error code. */ int snd_power_ref_and_wait(struct snd_card *card) { snd_power_ref(card); if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) return 0; wait_event_cmd(card->power_sleep, card->shutdown || snd_power_get_state(card) == SNDRV_CTL_POWER_D0, snd_power_unref(card), snd_power_ref(card)); return card->shutdown ? -ENODEV : 0; } EXPORT_SYMBOL_GPL(snd_power_ref_and_wait); /** * snd_power_wait - wait until the card gets powered up (old form) * @card: soundcard structure * * Wait until the card gets powered up to SNDRV_CTL_POWER_D0 state. * * Return: Zero if successful, or a negative error code. */ int snd_power_wait(struct snd_card *card) { int ret; ret = snd_power_ref_and_wait(card); snd_power_unref(card); return ret; } EXPORT_SYMBOL(snd_power_wait); #endif /* CONFIG_PM */
linux-master
sound/core/init.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Information interface for ALSA driver * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/time.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/module.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/info.h> #include <linux/utsname.h> #include <linux/proc_fs.h> #include <linux/mutex.h> int snd_info_check_reserved_words(const char *str) { static const char * const reserved[] = { "version", "meminfo", "memdebug", "detect", "devices", "oss", "cards", "timers", "synth", "pcm", "seq", NULL }; const char * const *xstr = reserved; while (*xstr) { if (!strcmp(*xstr, str)) return 0; xstr++; } if (!strncmp(str, "card", 4)) return 0; return 1; } static DEFINE_MUTEX(info_mutex); struct snd_info_private_data { struct snd_info_buffer *rbuffer; struct snd_info_buffer *wbuffer; struct snd_info_entry *entry; void *file_private_data; }; static int snd_info_version_init(void); static void snd_info_disconnect(struct snd_info_entry *entry); /* */ static struct snd_info_entry *snd_proc_root; struct snd_info_entry *snd_seq_root; EXPORT_SYMBOL(snd_seq_root); #ifdef CONFIG_SND_OSSEMUL struct snd_info_entry *snd_oss_root; #endif static int alloc_info_private(struct snd_info_entry *entry, struct snd_info_private_data **ret) { struct snd_info_private_data *data; if (!entry || !entry->p) return -ENODEV; if (!try_module_get(entry->module)) return -EFAULT; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { module_put(entry->module); return -ENOMEM; } data->entry = entry; *ret = data; return 0; } static bool valid_pos(loff_t pos, size_t count) { if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) return false; if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos) return false; return true; } /* * file ops for binary proc files */ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) { struct snd_info_private_data *data; struct snd_info_entry *entry; loff_t ret = -EINVAL, size; data = file->private_data; entry = data->entry; mutex_lock(&entry->access); if (entry->c.ops->llseek) { ret = entry->c.ops->llseek(entry, data->file_private_data, file, offset, orig); goto out; } size = entry->size; switch (orig) { case SEEK_SET: break; case SEEK_CUR: offset += file->f_pos; break; case SEEK_END: if (!size) goto out; offset += size; break; default: goto out; } if (offset < 0) goto out; if (size && offset > size) offset = size; file->f_pos = offset; ret = offset; out: mutex_unlock(&entry->access); return ret; } static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, size_t count, loff_t * offset) { struct snd_info_private_data *data = file->private_data; struct snd_info_entry *entry = data->entry; size_t size; loff_t pos; pos = *offset; if (!valid_pos(pos, count)) return -EIO; if (pos >= entry->size) return 0; size = entry->size - pos; size = min(count, size); size = entry->c.ops->read(entry, data->file_private_data, file, buffer, size, pos); if ((ssize_t) size > 0) *offset = pos + size; return size; } static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer, size_t count, loff_t * offset) { struct snd_info_private_data *data = file->private_data; struct snd_info_entry *entry = data->entry; ssize_t size = 0; loff_t pos; pos = *offset; if (!valid_pos(pos, count)) return -EIO; if (count > 0) { size_t maxsize = entry->size - pos; count = min(count, maxsize); size = entry->c.ops->write(entry, data->file_private_data, file, buffer, count, pos); } if (size > 0) *offset = pos + size; return size; } static __poll_t snd_info_entry_poll(struct file *file, poll_table *wait) { struct snd_info_private_data *data = file->private_data; struct snd_info_entry *entry = data->entry; __poll_t mask = 0; if (entry->c.ops->poll) return entry->c.ops->poll(entry, data->file_private_data, file, wait); if (entry->c.ops->read) mask |= EPOLLIN | EPOLLRDNORM; if (entry->c.ops->write) mask |= EPOLLOUT | EPOLLWRNORM; return mask; } static long snd_info_entry_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_info_private_data *data = file->private_data; struct snd_info_entry *entry = data->entry; if (!entry->c.ops->ioctl) return -ENOTTY; return entry->c.ops->ioctl(entry, data->file_private_data, file, cmd, arg); } static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma) { struct inode *inode = file_inode(file); struct snd_info_private_data *data; struct snd_info_entry *entry; data = file->private_data; if (data == NULL) return 0; entry = data->entry; if (!entry->c.ops->mmap) return -ENXIO; return entry->c.ops->mmap(entry, data->file_private_data, inode, file, vma); } static int snd_info_entry_open(struct inode *inode, struct file *file) { struct snd_info_entry *entry = pde_data(inode); struct snd_info_private_data *data; int mode, err; mutex_lock(&info_mutex); err = alloc_info_private(entry, &data); if (err < 0) goto unlock; mode = file->f_flags & O_ACCMODE; if (((mode == O_RDONLY || mode == O_RDWR) && !entry->c.ops->read) || ((mode == O_WRONLY || mode == O_RDWR) && !entry->c.ops->write)) { err = -ENODEV; goto error; } if (entry->c.ops->open) { err = entry->c.ops->open(entry, mode, &data->file_private_data); if (err < 0) goto error; } file->private_data = data; mutex_unlock(&info_mutex); return 0; error: kfree(data); module_put(entry->module); unlock: mutex_unlock(&info_mutex); return err; } static int snd_info_entry_release(struct inode *inode, struct file *file) { struct snd_info_private_data *data = file->private_data; struct snd_info_entry *entry = data->entry; if (entry->c.ops->release) entry->c.ops->release(entry, file->f_flags & O_ACCMODE, data->file_private_data); module_put(entry->module); kfree(data); return 0; } static const struct proc_ops snd_info_entry_operations = { .proc_lseek = snd_info_entry_llseek, .proc_read = snd_info_entry_read, .proc_write = snd_info_entry_write, .proc_poll = snd_info_entry_poll, .proc_ioctl = snd_info_entry_ioctl, .proc_mmap = snd_info_entry_mmap, .proc_open = snd_info_entry_open, .proc_release = snd_info_entry_release, }; /* * file ops for text proc files */ static ssize_t snd_info_text_entry_write(struct file *file, const char __user *buffer, size_t count, loff_t *offset) { struct seq_file *m = file->private_data; struct snd_info_private_data *data = m->private; struct snd_info_entry *entry = data->entry; struct snd_info_buffer *buf; loff_t pos; size_t next; int err = 0; if (!entry->c.text.write) return -EIO; pos = *offset; if (!valid_pos(pos, count)) return -EIO; next = pos + count; /* don't handle too large text inputs */ if (next > 16 * 1024) return -EIO; mutex_lock(&entry->access); buf = data->wbuffer; if (!buf) { data->wbuffer = buf = kzalloc(sizeof(*buf), GFP_KERNEL); if (!buf) { err = -ENOMEM; goto error; } } if (next > buf->len) { char *nbuf = kvzalloc(PAGE_ALIGN(next), GFP_KERNEL); if (!nbuf) { err = -ENOMEM; goto error; } kvfree(buf->buffer); buf->buffer = nbuf; buf->len = PAGE_ALIGN(next); } if (copy_from_user(buf->buffer + pos, buffer, count)) { err = -EFAULT; goto error; } buf->size = next; error: mutex_unlock(&entry->access); if (err < 0) return err; *offset = next; return count; } static int snd_info_seq_show(struct seq_file *seq, void *p) { struct snd_info_private_data *data = seq->private; struct snd_info_entry *entry = data->entry; if (!entry->c.text.read) { return -EIO; } else { data->rbuffer->buffer = (char *)seq; /* XXX hack! */ entry->c.text.read(entry, data->rbuffer); } return 0; } static int snd_info_text_entry_open(struct inode *inode, struct file *file) { struct snd_info_entry *entry = pde_data(inode); struct snd_info_private_data *data; int err; mutex_lock(&info_mutex); err = alloc_info_private(entry, &data); if (err < 0) goto unlock; data->rbuffer = kzalloc(sizeof(*data->rbuffer), GFP_KERNEL); if (!data->rbuffer) { err = -ENOMEM; goto error; } if (entry->size) err = single_open_size(file, snd_info_seq_show, data, entry->size); else err = single_open(file, snd_info_seq_show, data); if (err < 0) goto error; mutex_unlock(&info_mutex); return 0; error: kfree(data->rbuffer); kfree(data); module_put(entry->module); unlock: mutex_unlock(&info_mutex); return err; } static int snd_info_text_entry_release(struct inode *inode, struct file *file) { struct seq_file *m = file->private_data; struct snd_info_private_data *data = m->private; struct snd_info_entry *entry = data->entry; if (data->wbuffer && entry->c.text.write) entry->c.text.write(entry, data->wbuffer); single_release(inode, file); kfree(data->rbuffer); if (data->wbuffer) { kvfree(data->wbuffer->buffer); kfree(data->wbuffer); } module_put(entry->module); kfree(data); return 0; } static const struct proc_ops snd_info_text_entry_ops = { .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, .proc_write = snd_info_text_entry_write, .proc_lseek = seq_lseek, .proc_read = seq_read, }; static struct snd_info_entry *create_subdir(struct module *mod, const char *name) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(mod, name, NULL); if (!entry) return NULL; entry->mode = S_IFDIR | 0555; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); return NULL; } return entry; } static struct snd_info_entry * snd_info_create_entry(const char *name, struct snd_info_entry *parent, struct module *module); int __init snd_info_init(void) { snd_proc_root = snd_info_create_entry("asound", NULL, THIS_MODULE); if (!snd_proc_root) return -ENOMEM; snd_proc_root->mode = S_IFDIR | 0555; snd_proc_root->p = proc_mkdir("asound", NULL); if (!snd_proc_root->p) goto error; #ifdef CONFIG_SND_OSSEMUL snd_oss_root = create_subdir(THIS_MODULE, "oss"); if (!snd_oss_root) goto error; #endif #if IS_ENABLED(CONFIG_SND_SEQUENCER) snd_seq_root = create_subdir(THIS_MODULE, "seq"); if (!snd_seq_root) goto error; #endif if (snd_info_version_init() < 0 || snd_minor_info_init() < 0 || snd_minor_info_oss_init() < 0 || snd_card_info_init() < 0 || snd_info_minor_register() < 0) goto error; return 0; error: snd_info_free_entry(snd_proc_root); return -ENOMEM; } int __exit snd_info_done(void) { snd_info_free_entry(snd_proc_root); return 0; } static void snd_card_id_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_card *card = entry->private_data; snd_iprintf(buffer, "%s\n", card->id); } /* * create a card proc file * called from init.c */ int snd_info_card_create(struct snd_card *card) { char str[8]; struct snd_info_entry *entry; if (snd_BUG_ON(!card)) return -ENXIO; sprintf(str, "card%i", card->number); entry = create_subdir(card->module, str); if (!entry) return -ENOMEM; card->proc_root = entry; return snd_card_ro_proc_new(card, "id", card, snd_card_id_read); } /* * register the card proc file * called from init.c * can be called multiple times for reinitialization */ int snd_info_card_register(struct snd_card *card) { struct proc_dir_entry *p; int err; if (snd_BUG_ON(!card)) return -ENXIO; err = snd_info_register(card->proc_root); if (err < 0) return err; if (!strcmp(card->id, card->proc_root->name)) return 0; if (card->proc_root_link) return 0; p = proc_symlink(card->id, snd_proc_root->p, card->proc_root->name); if (!p) return -ENOMEM; card->proc_root_link = p; return 0; } /* * called on card->id change */ void snd_info_card_id_change(struct snd_card *card) { mutex_lock(&info_mutex); if (card->proc_root_link) { proc_remove(card->proc_root_link); card->proc_root_link = NULL; } if (strcmp(card->id, card->proc_root->name)) card->proc_root_link = proc_symlink(card->id, snd_proc_root->p, card->proc_root->name); mutex_unlock(&info_mutex); } /* * de-register the card proc file * called from init.c */ void snd_info_card_disconnect(struct snd_card *card) { if (!card) return; mutex_lock(&info_mutex); proc_remove(card->proc_root_link); card->proc_root_link = NULL; if (card->proc_root) snd_info_disconnect(card->proc_root); mutex_unlock(&info_mutex); } /* * release the card proc file resources * called from init.c */ int snd_info_card_free(struct snd_card *card) { if (!card) return 0; snd_info_free_entry(card->proc_root); card->proc_root = NULL; return 0; } /** * snd_info_get_line - read one line from the procfs buffer * @buffer: the procfs buffer * @line: the buffer to store * @len: the max. buffer size * * Reads one line from the buffer and stores the string. * * Return: Zero if successful, or 1 if error or EOF. */ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { int c; if (snd_BUG_ON(!buffer)) return 1; if (!buffer->buffer) return 1; if (len <= 0 || buffer->stop || buffer->error) return 1; while (!buffer->stop) { c = buffer->buffer[buffer->curr++]; if (buffer->curr >= buffer->size) buffer->stop = 1; if (c == '\n') break; if (len > 1) { len--; *line++ = c; } } *line = '\0'; return 0; } EXPORT_SYMBOL(snd_info_get_line); /** * snd_info_get_str - parse a string token * @dest: the buffer to store the string token * @src: the original string * @len: the max. length of token - 1 * * Parses the original string and copy a token to the given * string buffer. * * Return: The updated pointer of the original string so that * it can be used for the next call. */ const char *snd_info_get_str(char *dest, const char *src, int len) { int c; while (*src == ' ' || *src == '\t') src++; if (*src == '"' || *src == '\'') { c = *src++; while (--len > 0 && *src && *src != c) { *dest++ = *src++; } if (*src == c) src++; } else { while (--len > 0 && *src && *src != ' ' && *src != '\t') { *dest++ = *src++; } } *dest = 0; while (*src == ' ' || *src == '\t') src++; return src; } EXPORT_SYMBOL(snd_info_get_str); /* * snd_info_create_entry - create an info entry * @name: the proc file name * @parent: the parent directory * * Creates an info entry with the given file name and initializes as * the default state. * * Usually called from other functions such as * snd_info_create_card_entry(). * * Return: The pointer of the new instance, or %NULL on failure. */ static struct snd_info_entry * snd_info_create_entry(const char *name, struct snd_info_entry *parent, struct module *module) { struct snd_info_entry *entry; entry = kzalloc(sizeof(*entry), GFP_KERNEL); if (entry == NULL) return NULL; entry->name = kstrdup(name, GFP_KERNEL); if (entry->name == NULL) { kfree(entry); return NULL; } entry->mode = S_IFREG | 0444; entry->content = SNDRV_INFO_CONTENT_TEXT; mutex_init(&entry->access); INIT_LIST_HEAD(&entry->children); INIT_LIST_HEAD(&entry->list); entry->parent = parent; entry->module = module; if (parent) { mutex_lock(&parent->access); list_add_tail(&entry->list, &parent->children); mutex_unlock(&parent->access); } return entry; } /** * snd_info_create_module_entry - create an info entry for the given module * @module: the module pointer * @name: the file name * @parent: the parent directory * * Creates a new info entry and assigns it to the given module. * * Return: The pointer of the new instance, or %NULL on failure. */ struct snd_info_entry *snd_info_create_module_entry(struct module * module, const char *name, struct snd_info_entry *parent) { if (!parent) parent = snd_proc_root; return snd_info_create_entry(name, parent, module); } EXPORT_SYMBOL(snd_info_create_module_entry); /** * snd_info_create_card_entry - create an info entry for the given card * @card: the card instance * @name: the file name * @parent: the parent directory * * Creates a new info entry and assigns it to the given card. * * Return: The pointer of the new instance, or %NULL on failure. */ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry * parent) { if (!parent) parent = card->proc_root; return snd_info_create_entry(name, parent, card->module); } EXPORT_SYMBOL(snd_info_create_card_entry); static void snd_info_disconnect(struct snd_info_entry *entry) { struct snd_info_entry *p; if (!entry->p) return; list_for_each_entry(p, &entry->children, list) snd_info_disconnect(p); proc_remove(entry->p); entry->p = NULL; } /** * snd_info_free_entry - release the info entry * @entry: the info entry * * Releases the info entry. */ void snd_info_free_entry(struct snd_info_entry * entry) { struct snd_info_entry *p, *n; if (!entry) return; if (entry->p) { mutex_lock(&info_mutex); snd_info_disconnect(entry); mutex_unlock(&info_mutex); } /* free all children at first */ list_for_each_entry_safe(p, n, &entry->children, list) snd_info_free_entry(p); p = entry->parent; if (p) { mutex_lock(&p->access); list_del(&entry->list); mutex_unlock(&p->access); } kfree(entry->name); if (entry->private_free) entry->private_free(entry); kfree(entry); } EXPORT_SYMBOL(snd_info_free_entry); static int __snd_info_register(struct snd_info_entry *entry) { struct proc_dir_entry *root, *p = NULL; if (snd_BUG_ON(!entry)) return -ENXIO; root = entry->parent == NULL ? snd_proc_root->p : entry->parent->p; mutex_lock(&info_mutex); if (entry->p || !root) goto unlock; if (S_ISDIR(entry->mode)) { p = proc_mkdir_mode(entry->name, entry->mode, root); if (!p) { mutex_unlock(&info_mutex); return -ENOMEM; } } else { const struct proc_ops *ops; if (entry->content == SNDRV_INFO_CONTENT_DATA) ops = &snd_info_entry_operations; else ops = &snd_info_text_entry_ops; p = proc_create_data(entry->name, entry->mode, root, ops, entry); if (!p) { mutex_unlock(&info_mutex); return -ENOMEM; } proc_set_size(p, entry->size); } entry->p = p; unlock: mutex_unlock(&info_mutex); return 0; } /** * snd_info_register - register the info entry * @entry: the info entry * * Registers the proc info entry. * The all children entries are registered recursively. * * Return: Zero if successful, or a negative error code on failure. */ int snd_info_register(struct snd_info_entry *entry) { struct snd_info_entry *p; int err; if (!entry->p) { err = __snd_info_register(entry); if (err < 0) return err; } list_for_each_entry(p, &entry->children, list) { err = snd_info_register(p); if (err < 0) return err; } return 0; } EXPORT_SYMBOL(snd_info_register); /** * snd_card_rw_proc_new - Create a read/write text proc file entry for the card * @card: the card instance * @name: the file name * @private_data: the arbitrary private data * @read: the read callback * @write: the write callback, NULL for read-only * * This proc file entry will be registered via snd_card_register() call, and * it will be removed automatically at the card removal, too. * * Return: zero if successful, or a negative error code */ int snd_card_rw_proc_new(struct snd_card *card, const char *name, void *private_data, void (*read)(struct snd_info_entry *, struct snd_info_buffer *), void (*write)(struct snd_info_entry *entry, struct snd_info_buffer *buffer)) { struct snd_info_entry *entry; entry = snd_info_create_card_entry(card, name, card->proc_root); if (!entry) return -ENOMEM; snd_info_set_text_ops(entry, private_data, read); if (write) { entry->mode |= 0200; entry->c.text.write = write; } return 0; } EXPORT_SYMBOL_GPL(snd_card_rw_proc_new); /* */ static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_iprintf(buffer, "Advanced Linux Sound Architecture Driver Version k%s.\n", init_utsname()->release); } static int __init snd_info_version_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL); if (entry == NULL) return -ENOMEM; entry->c.text.read = snd_info_version_read; return snd_info_register(entry); /* freed in error path */ }
linux-master
sound/core/info.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Hardware dependent layer * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/major.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/mutex.h> #include <linux/module.h> #include <linux/sched/signal.h> #include <sound/core.h> #include <sound/control.h> #include <sound/minors.h> #include <sound/hwdep.h> #include <sound/info.h> MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Hardware dependent layer"); MODULE_LICENSE("GPL"); static LIST_HEAD(snd_hwdep_devices); static DEFINE_MUTEX(register_mutex); static int snd_hwdep_dev_free(struct snd_device *device); static int snd_hwdep_dev_register(struct snd_device *device); static int snd_hwdep_dev_disconnect(struct snd_device *device); static struct snd_hwdep *snd_hwdep_search(struct snd_card *card, int device) { struct snd_hwdep *hwdep; list_for_each_entry(hwdep, &snd_hwdep_devices, list) if (hwdep->card == card && hwdep->device == device) return hwdep; return NULL; } static loff_t snd_hwdep_llseek(struct file * file, loff_t offset, int orig) { struct snd_hwdep *hw = file->private_data; if (hw->ops.llseek) return hw->ops.llseek(hw, file, offset, orig); return -ENXIO; } static ssize_t snd_hwdep_read(struct file * file, char __user *buf, size_t count, loff_t *offset) { struct snd_hwdep *hw = file->private_data; if (hw->ops.read) return hw->ops.read(hw, buf, count, offset); return -ENXIO; } static ssize_t snd_hwdep_write(struct file * file, const char __user *buf, size_t count, loff_t *offset) { struct snd_hwdep *hw = file->private_data; if (hw->ops.write) return hw->ops.write(hw, buf, count, offset); return -ENXIO; } static int snd_hwdep_open(struct inode *inode, struct file * file) { int major = imajor(inode); struct snd_hwdep *hw; int err; wait_queue_entry_t wait; if (major == snd_major) { hw = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_HWDEP); #ifdef CONFIG_SND_OSSEMUL } else if (major == SOUND_MAJOR) { hw = snd_lookup_oss_minor_data(iminor(inode), SNDRV_OSS_DEVICE_TYPE_DMFM); #endif } else return -ENXIO; if (hw == NULL) return -ENODEV; if (!try_module_get(hw->card->module)) { snd_card_unref(hw->card); return -EFAULT; } init_waitqueue_entry(&wait, current); add_wait_queue(&hw->open_wait, &wait); mutex_lock(&hw->open_mutex); while (1) { if (hw->exclusive && hw->used > 0) { err = -EBUSY; break; } if (!hw->ops.open) { err = 0; break; } err = hw->ops.open(hw, file); if (err >= 0) break; if (err == -EAGAIN) { if (file->f_flags & O_NONBLOCK) { err = -EBUSY; break; } } else break; set_current_state(TASK_INTERRUPTIBLE); mutex_unlock(&hw->open_mutex); schedule(); mutex_lock(&hw->open_mutex); if (hw->card->shutdown) { err = -ENODEV; break; } if (signal_pending(current)) { err = -ERESTARTSYS; break; } } remove_wait_queue(&hw->open_wait, &wait); if (err >= 0) { err = snd_card_file_add(hw->card, file); if (err >= 0) { file->private_data = hw; hw->used++; } else { if (hw->ops.release) hw->ops.release(hw, file); } } mutex_unlock(&hw->open_mutex); if (err < 0) module_put(hw->card->module); snd_card_unref(hw->card); return err; } static int snd_hwdep_release(struct inode *inode, struct file * file) { int err = 0; struct snd_hwdep *hw = file->private_data; struct module *mod = hw->card->module; mutex_lock(&hw->open_mutex); if (hw->ops.release) err = hw->ops.release(hw, file); if (hw->used > 0) hw->used--; mutex_unlock(&hw->open_mutex); wake_up(&hw->open_wait); snd_card_file_remove(hw->card, file); module_put(mod); return err; } static __poll_t snd_hwdep_poll(struct file * file, poll_table * wait) { struct snd_hwdep *hw = file->private_data; if (hw->ops.poll) return hw->ops.poll(hw, file, wait); return 0; } static int snd_hwdep_info(struct snd_hwdep *hw, struct snd_hwdep_info __user *_info) { struct snd_hwdep_info info; memset(&info, 0, sizeof(info)); info.card = hw->card->number; strscpy(info.id, hw->id, sizeof(info.id)); strscpy(info.name, hw->name, sizeof(info.name)); info.iface = hw->iface; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return 0; } static int snd_hwdep_dsp_status(struct snd_hwdep *hw, struct snd_hwdep_dsp_status __user *_info) { struct snd_hwdep_dsp_status info; int err; if (! hw->ops.dsp_status) return -ENXIO; memset(&info, 0, sizeof(info)); info.dsp_loaded = hw->dsp_loaded; err = hw->ops.dsp_status(hw, &info); if (err < 0) return err; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return 0; } static int snd_hwdep_dsp_load(struct snd_hwdep *hw, struct snd_hwdep_dsp_image *info) { int err; if (! hw->ops.dsp_load) return -ENXIO; if (info->index >= 32) return -EINVAL; /* check whether the dsp was already loaded */ if (hw->dsp_loaded & (1u << info->index)) return -EBUSY; err = hw->ops.dsp_load(hw, info); if (err < 0) return err; hw->dsp_loaded |= (1u << info->index); return 0; } static int snd_hwdep_dsp_load_user(struct snd_hwdep *hw, struct snd_hwdep_dsp_image __user *_info) { struct snd_hwdep_dsp_image info = {}; if (copy_from_user(&info, _info, sizeof(info))) return -EFAULT; return snd_hwdep_dsp_load(hw, &info); } static long snd_hwdep_ioctl(struct file * file, unsigned int cmd, unsigned long arg) { struct snd_hwdep *hw = file->private_data; void __user *argp = (void __user *)arg; switch (cmd) { case SNDRV_HWDEP_IOCTL_PVERSION: return put_user(SNDRV_HWDEP_VERSION, (int __user *)argp); case SNDRV_HWDEP_IOCTL_INFO: return snd_hwdep_info(hw, argp); case SNDRV_HWDEP_IOCTL_DSP_STATUS: return snd_hwdep_dsp_status(hw, argp); case SNDRV_HWDEP_IOCTL_DSP_LOAD: return snd_hwdep_dsp_load_user(hw, argp); } if (hw->ops.ioctl) return hw->ops.ioctl(hw, file, cmd, arg); return -ENOTTY; } static int snd_hwdep_mmap(struct file * file, struct vm_area_struct * vma) { struct snd_hwdep *hw = file->private_data; if (hw->ops.mmap) return hw->ops.mmap(hw, file, vma); return -ENXIO; } static int snd_hwdep_control_ioctl(struct snd_card *card, struct snd_ctl_file * control, unsigned int cmd, unsigned long arg) { switch (cmd) { case SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE: { int device; if (get_user(device, (int __user *)arg)) return -EFAULT; mutex_lock(&register_mutex); if (device < 0) device = 0; else if (device < SNDRV_MINOR_HWDEPS) device++; else device = SNDRV_MINOR_HWDEPS; while (device < SNDRV_MINOR_HWDEPS) { if (snd_hwdep_search(card, device)) break; device++; } if (device >= SNDRV_MINOR_HWDEPS) device = -1; mutex_unlock(&register_mutex); if (put_user(device, (int __user *)arg)) return -EFAULT; return 0; } case SNDRV_CTL_IOCTL_HWDEP_INFO: { struct snd_hwdep_info __user *info = (struct snd_hwdep_info __user *)arg; int device, err; struct snd_hwdep *hwdep; if (get_user(device, &info->device)) return -EFAULT; mutex_lock(&register_mutex); hwdep = snd_hwdep_search(card, device); if (hwdep) err = snd_hwdep_info(hwdep, info); else err = -ENXIO; mutex_unlock(&register_mutex); return err; } } return -ENOIOCTLCMD; } #ifdef CONFIG_COMPAT #include "hwdep_compat.c" #else #define snd_hwdep_ioctl_compat NULL #endif /* */ static const struct file_operations snd_hwdep_f_ops = { .owner = THIS_MODULE, .llseek = snd_hwdep_llseek, .read = snd_hwdep_read, .write = snd_hwdep_write, .open = snd_hwdep_open, .release = snd_hwdep_release, .poll = snd_hwdep_poll, .unlocked_ioctl = snd_hwdep_ioctl, .compat_ioctl = snd_hwdep_ioctl_compat, .mmap = snd_hwdep_mmap, }; static void snd_hwdep_free(struct snd_hwdep *hwdep) { if (!hwdep) return; if (hwdep->private_free) hwdep->private_free(hwdep); put_device(hwdep->dev); kfree(hwdep); } /** * snd_hwdep_new - create a new hwdep instance * @card: the card instance * @id: the id string * @device: the device index (zero-based) * @rhwdep: the pointer to store the new hwdep instance * * Creates a new hwdep instance with the given index on the card. * The callbacks (hwdep->ops) must be set on the returned instance * after this call manually by the caller. * * Return: Zero if successful, or a negative error code on failure. */ int snd_hwdep_new(struct snd_card *card, char *id, int device, struct snd_hwdep **rhwdep) { struct snd_hwdep *hwdep; int err; static const struct snd_device_ops ops = { .dev_free = snd_hwdep_dev_free, .dev_register = snd_hwdep_dev_register, .dev_disconnect = snd_hwdep_dev_disconnect, }; if (snd_BUG_ON(!card)) return -ENXIO; if (rhwdep) *rhwdep = NULL; hwdep = kzalloc(sizeof(*hwdep), GFP_KERNEL); if (!hwdep) return -ENOMEM; init_waitqueue_head(&hwdep->open_wait); mutex_init(&hwdep->open_mutex); hwdep->card = card; hwdep->device = device; if (id) strscpy(hwdep->id, id, sizeof(hwdep->id)); err = snd_device_alloc(&hwdep->dev, card); if (err < 0) { snd_hwdep_free(hwdep); return err; } dev_set_name(hwdep->dev, "hwC%iD%i", card->number, device); #ifdef CONFIG_SND_OSSEMUL hwdep->oss_type = -1; #endif err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops); if (err < 0) { snd_hwdep_free(hwdep); return err; } if (rhwdep) *rhwdep = hwdep; return 0; } EXPORT_SYMBOL(snd_hwdep_new); static int snd_hwdep_dev_free(struct snd_device *device) { snd_hwdep_free(device->device_data); return 0; } static int snd_hwdep_dev_register(struct snd_device *device) { struct snd_hwdep *hwdep = device->device_data; struct snd_card *card = hwdep->card; int err; mutex_lock(&register_mutex); if (snd_hwdep_search(card, hwdep->device)) { mutex_unlock(&register_mutex); return -EBUSY; } list_add_tail(&hwdep->list, &snd_hwdep_devices); err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP, hwdep->card, hwdep->device, &snd_hwdep_f_ops, hwdep, hwdep->dev); if (err < 0) { dev_err(hwdep->dev, "unable to register\n"); list_del(&hwdep->list); mutex_unlock(&register_mutex); return err; } #ifdef CONFIG_SND_OSSEMUL hwdep->ossreg = 0; if (hwdep->oss_type >= 0) { if (hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM && hwdep->device) dev_warn(hwdep->dev, "only hwdep device 0 can be registered as OSS direct FM device!\n"); else if (snd_register_oss_device(hwdep->oss_type, card, hwdep->device, &snd_hwdep_f_ops, hwdep) < 0) dev_warn(hwdep->dev, "unable to register OSS compatibility device\n"); else hwdep->ossreg = 1; } #endif mutex_unlock(&register_mutex); return 0; } static int snd_hwdep_dev_disconnect(struct snd_device *device) { struct snd_hwdep *hwdep = device->device_data; if (snd_BUG_ON(!hwdep)) return -ENXIO; mutex_lock(&register_mutex); if (snd_hwdep_search(hwdep->card, hwdep->device) != hwdep) { mutex_unlock(&register_mutex); return -EINVAL; } mutex_lock(&hwdep->open_mutex); wake_up(&hwdep->open_wait); #ifdef CONFIG_SND_OSSEMUL if (hwdep->ossreg) snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device); #endif snd_unregister_device(hwdep->dev); list_del_init(&hwdep->list); mutex_unlock(&hwdep->open_mutex); mutex_unlock(&register_mutex); return 0; } #ifdef CONFIG_SND_PROC_FS /* * Info interface */ static void snd_hwdep_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_hwdep *hwdep; mutex_lock(&register_mutex); list_for_each_entry(hwdep, &snd_hwdep_devices, list) snd_iprintf(buffer, "%02i-%02i: %s\n", hwdep->card->number, hwdep->device, hwdep->name); mutex_unlock(&register_mutex); } static struct snd_info_entry *snd_hwdep_proc_entry; static void __init snd_hwdep_proc_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "hwdep", NULL); if (entry) { entry->c.text.read = snd_hwdep_proc_read; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } } snd_hwdep_proc_entry = entry; } static void __exit snd_hwdep_proc_done(void) { snd_info_free_entry(snd_hwdep_proc_entry); } #else /* !CONFIG_SND_PROC_FS */ #define snd_hwdep_proc_init() #define snd_hwdep_proc_done() #endif /* CONFIG_SND_PROC_FS */ /* * ENTRY functions */ static int __init alsa_hwdep_init(void) { snd_hwdep_proc_init(); snd_ctl_register_ioctl(snd_hwdep_control_ioctl); snd_ctl_register_ioctl_compat(snd_hwdep_control_ioctl); return 0; } static void __exit alsa_hwdep_exit(void) { snd_ctl_unregister_ioctl(snd_hwdep_control_ioctl); snd_ctl_unregister_ioctl_compat(snd_hwdep_control_ioctl); snd_hwdep_proc_done(); } module_init(alsa_hwdep_init) module_exit(alsa_hwdep_exit)
linux-master
sound/core/hwdep.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Digital Audio (PCM) abstract layer * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/time.h> #include <linux/mutex.h> #include <linux/device.h> #include <linux/nospec.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/pcm.h> #include <sound/timer.h> #include <sound/control.h> #include <sound/info.h> #include "pcm_local.h" MODULE_AUTHOR("Jaroslav Kysela <[email protected]>, Abramo Bagnara <[email protected]>"); MODULE_DESCRIPTION("Midlevel PCM code for ALSA."); MODULE_LICENSE("GPL"); static LIST_HEAD(snd_pcm_devices); static DEFINE_MUTEX(register_mutex); #if IS_ENABLED(CONFIG_SND_PCM_OSS) static LIST_HEAD(snd_pcm_notify_list); #endif static int snd_pcm_free(struct snd_pcm *pcm); static int snd_pcm_dev_free(struct snd_device *device); static int snd_pcm_dev_register(struct snd_device *device); static int snd_pcm_dev_disconnect(struct snd_device *device); static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device) { struct snd_pcm *pcm; list_for_each_entry(pcm, &snd_pcm_devices, list) { if (pcm->card == card && pcm->device == device) return pcm; } return NULL; } static int snd_pcm_next(struct snd_card *card, int device) { struct snd_pcm *pcm; list_for_each_entry(pcm, &snd_pcm_devices, list) { if (pcm->card == card && pcm->device > device) return pcm->device; else if (pcm->card->number > card->number) return -1; } return -1; } static int snd_pcm_add(struct snd_pcm *newpcm) { struct snd_pcm *pcm; if (newpcm->internal) return 0; list_for_each_entry(pcm, &snd_pcm_devices, list) { if (pcm->card == newpcm->card && pcm->device == newpcm->device) return -EBUSY; if (pcm->card->number > newpcm->card->number || (pcm->card == newpcm->card && pcm->device > newpcm->device)) { list_add(&newpcm->list, pcm->list.prev); return 0; } } list_add_tail(&newpcm->list, &snd_pcm_devices); return 0; } static int snd_pcm_control_ioctl(struct snd_card *card, struct snd_ctl_file *control, unsigned int cmd, unsigned long arg) { switch (cmd) { case SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE: { int device; if (get_user(device, (int __user *)arg)) return -EFAULT; mutex_lock(&register_mutex); device = snd_pcm_next(card, device); mutex_unlock(&register_mutex); if (put_user(device, (int __user *)arg)) return -EFAULT; return 0; } case SNDRV_CTL_IOCTL_PCM_INFO: { struct snd_pcm_info __user *info; unsigned int device, subdevice; int stream; struct snd_pcm *pcm; struct snd_pcm_str *pstr; struct snd_pcm_substream *substream; int err; info = (struct snd_pcm_info __user *)arg; if (get_user(device, &info->device)) return -EFAULT; if (get_user(stream, &info->stream)) return -EFAULT; if (stream < 0 || stream > 1) return -EINVAL; stream = array_index_nospec(stream, 2); if (get_user(subdevice, &info->subdevice)) return -EFAULT; mutex_lock(&register_mutex); pcm = snd_pcm_get(card, device); if (pcm == NULL) { err = -ENXIO; goto _error; } pstr = &pcm->streams[stream]; if (pstr->substream_count == 0) { err = -ENOENT; goto _error; } if (subdevice >= pstr->substream_count) { err = -ENXIO; goto _error; } for (substream = pstr->substream; substream; substream = substream->next) if (substream->number == (int)subdevice) break; if (substream == NULL) { err = -ENXIO; goto _error; } mutex_lock(&pcm->open_mutex); err = snd_pcm_info_user(substream, info); mutex_unlock(&pcm->open_mutex); _error: mutex_unlock(&register_mutex); return err; } case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE: { int val; if (get_user(val, (int __user *)arg)) return -EFAULT; control->preferred_subdevice[SND_CTL_SUBDEV_PCM] = val; return 0; } } return -ENOIOCTLCMD; } #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v static const char * const snd_pcm_format_names[] = { FORMAT(S8), FORMAT(U8), FORMAT(S16_LE), FORMAT(S16_BE), FORMAT(U16_LE), FORMAT(U16_BE), FORMAT(S24_LE), FORMAT(S24_BE), FORMAT(U24_LE), FORMAT(U24_BE), FORMAT(S32_LE), FORMAT(S32_BE), FORMAT(U32_LE), FORMAT(U32_BE), FORMAT(FLOAT_LE), FORMAT(FLOAT_BE), FORMAT(FLOAT64_LE), FORMAT(FLOAT64_BE), FORMAT(IEC958_SUBFRAME_LE), FORMAT(IEC958_SUBFRAME_BE), FORMAT(MU_LAW), FORMAT(A_LAW), FORMAT(IMA_ADPCM), FORMAT(MPEG), FORMAT(GSM), FORMAT(SPECIAL), FORMAT(S24_3LE), FORMAT(S24_3BE), FORMAT(U24_3LE), FORMAT(U24_3BE), FORMAT(S20_3LE), FORMAT(S20_3BE), FORMAT(U20_3LE), FORMAT(U20_3BE), FORMAT(S18_3LE), FORMAT(S18_3BE), FORMAT(U18_3LE), FORMAT(U18_3BE), FORMAT(G723_24), FORMAT(G723_24_1B), FORMAT(G723_40), FORMAT(G723_40_1B), FORMAT(DSD_U8), FORMAT(DSD_U16_LE), FORMAT(DSD_U32_LE), FORMAT(DSD_U16_BE), FORMAT(DSD_U32_BE), }; /** * snd_pcm_format_name - Return a name string for the given PCM format * @format: PCM format * * Return: the format name string */ const char *snd_pcm_format_name(snd_pcm_format_t format) { if ((__force unsigned int)format >= ARRAY_SIZE(snd_pcm_format_names)) return "Unknown"; return snd_pcm_format_names[(__force unsigned int)format]; } EXPORT_SYMBOL_GPL(snd_pcm_format_name); #ifdef CONFIG_SND_VERBOSE_PROCFS #define STATE(v) [SNDRV_PCM_STATE_##v] = #v #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v #define READY(v) [SNDRV_PCM_READY_##v] = #v #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v #define START(v) [SNDRV_PCM_START_##v] = #v #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v static const char * const snd_pcm_stream_names[] = { STREAM(PLAYBACK), STREAM(CAPTURE), }; static const char * const snd_pcm_state_names[] = { STATE(OPEN), STATE(SETUP), STATE(PREPARED), STATE(RUNNING), STATE(XRUN), STATE(DRAINING), STATE(PAUSED), STATE(SUSPENDED), }; static const char * const snd_pcm_access_names[] = { ACCESS(MMAP_INTERLEAVED), ACCESS(MMAP_NONINTERLEAVED), ACCESS(MMAP_COMPLEX), ACCESS(RW_INTERLEAVED), ACCESS(RW_NONINTERLEAVED), }; static const char * const snd_pcm_subformat_names[] = { SUBFORMAT(STD), }; static const char * const snd_pcm_tstamp_mode_names[] = { TSTAMP(NONE), TSTAMP(ENABLE), }; static const char *snd_pcm_stream_name(int stream) { return snd_pcm_stream_names[stream]; } static const char *snd_pcm_access_name(snd_pcm_access_t access) { return snd_pcm_access_names[(__force int)access]; } static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat) { return snd_pcm_subformat_names[(__force int)subformat]; } static const char *snd_pcm_tstamp_mode_name(int mode) { return snd_pcm_tstamp_mode_names[mode]; } static const char *snd_pcm_state_name(snd_pcm_state_t state) { return snd_pcm_state_names[(__force int)state]; } #if IS_ENABLED(CONFIG_SND_PCM_OSS) #include <linux/soundcard.h> static const char *snd_pcm_oss_format_name(int format) { switch (format) { case AFMT_MU_LAW: return "MU_LAW"; case AFMT_A_LAW: return "A_LAW"; case AFMT_IMA_ADPCM: return "IMA_ADPCM"; case AFMT_U8: return "U8"; case AFMT_S16_LE: return "S16_LE"; case AFMT_S16_BE: return "S16_BE"; case AFMT_S8: return "S8"; case AFMT_U16_LE: return "U16_LE"; case AFMT_U16_BE: return "U16_BE"; case AFMT_MPEG: return "MPEG"; default: return "unknown"; } } #endif static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream, struct snd_info_buffer *buffer) { struct snd_pcm_info *info; int err; if (! substream) return; info = kmalloc(sizeof(*info), GFP_KERNEL); if (!info) return; err = snd_pcm_info(substream, info); if (err < 0) { snd_iprintf(buffer, "error %d\n", err); kfree(info); return; } snd_iprintf(buffer, "card: %d\n", info->card); snd_iprintf(buffer, "device: %d\n", info->device); snd_iprintf(buffer, "subdevice: %d\n", info->subdevice); snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream)); snd_iprintf(buffer, "id: %s\n", info->id); snd_iprintf(buffer, "name: %s\n", info->name); snd_iprintf(buffer, "subname: %s\n", info->subname); snd_iprintf(buffer, "class: %d\n", info->dev_class); snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass); snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count); snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail); kfree(info); } static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream, buffer); } static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_pcm_proc_info_read(entry->private_data, buffer); } static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_substream *substream = entry->private_data; struct snd_pcm_runtime *runtime; mutex_lock(&substream->pcm->open_mutex); runtime = substream->runtime; if (!runtime) { snd_iprintf(buffer, "closed\n"); goto unlock; } if (runtime->state == SNDRV_PCM_STATE_OPEN) { snd_iprintf(buffer, "no setup\n"); goto unlock; } snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access)); snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format)); snd_iprintf(buffer, "subformat: %s\n", snd_pcm_subformat_name(runtime->subformat)); snd_iprintf(buffer, "channels: %u\n", runtime->channels); snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den); snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size); snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size); #if IS_ENABLED(CONFIG_SND_PCM_OSS) if (substream->oss.oss) { snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format)); snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels); snd_iprintf(buffer, "OSS rate: %u\n", runtime->oss.rate); snd_iprintf(buffer, "OSS period bytes: %lu\n", (unsigned long)runtime->oss.period_bytes); snd_iprintf(buffer, "OSS periods: %u\n", runtime->oss.periods); snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames); } #endif unlock: mutex_unlock(&substream->pcm->open_mutex); } static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_substream *substream = entry->private_data; struct snd_pcm_runtime *runtime; mutex_lock(&substream->pcm->open_mutex); runtime = substream->runtime; if (!runtime) { snd_iprintf(buffer, "closed\n"); goto unlock; } if (runtime->state == SNDRV_PCM_STATE_OPEN) { snd_iprintf(buffer, "no setup\n"); goto unlock; } snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode)); snd_iprintf(buffer, "period_step: %u\n", runtime->period_step); snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min); snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold); snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold); snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold); snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size); snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary); unlock: mutex_unlock(&substream->pcm->open_mutex); } static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_substream *substream = entry->private_data; struct snd_pcm_runtime *runtime; struct snd_pcm_status64 status; int err; mutex_lock(&substream->pcm->open_mutex); runtime = substream->runtime; if (!runtime) { snd_iprintf(buffer, "closed\n"); goto unlock; } memset(&status, 0, sizeof(status)); err = snd_pcm_status64(substream, &status); if (err < 0) { snd_iprintf(buffer, "error %d\n", err); goto unlock; } snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state)); snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid)); snd_iprintf(buffer, "trigger_time: %lld.%09lld\n", status.trigger_tstamp_sec, status.trigger_tstamp_nsec); snd_iprintf(buffer, "tstamp : %lld.%09lld\n", status.tstamp_sec, status.tstamp_nsec); snd_iprintf(buffer, "delay : %ld\n", status.delay); snd_iprintf(buffer, "avail : %ld\n", status.avail); snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max); snd_iprintf(buffer, "-----\n"); snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr); snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr); unlock: mutex_unlock(&substream->pcm->open_mutex); } #ifdef CONFIG_SND_PCM_XRUN_DEBUG static void snd_pcm_xrun_injection_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_substream *substream = entry->private_data; snd_pcm_stop_xrun(substream); } static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_str *pstr = entry->private_data; snd_iprintf(buffer, "%d\n", pstr->xrun_debug); } static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm_str *pstr = entry->private_data; char line[64]; if (!snd_info_get_line(buffer, line, sizeof(line))) pstr->xrun_debug = simple_strtoul(line, NULL, 10); } #endif static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { struct snd_pcm *pcm = pstr->pcm; struct snd_info_entry *entry; char name[16]; sprintf(name, "pcm%i%c", pcm->device, pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c'); entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root); if (!entry) return -ENOMEM; entry->mode = S_IFDIR | 0555; pstr->proc_root = entry; entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root); if (entry) snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read); #ifdef CONFIG_SND_PCM_XRUN_DEBUG entry = snd_info_create_card_entry(pcm->card, "xrun_debug", pstr->proc_root); if (entry) { snd_info_set_text_ops(entry, pstr, snd_pcm_xrun_debug_read); entry->c.text.write = snd_pcm_xrun_debug_write; entry->mode |= 0200; } #endif return 0; } static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { snd_info_free_entry(pstr->proc_root); pstr->proc_root = NULL; return 0; } static struct snd_info_entry * create_substream_info_entry(struct snd_pcm_substream *substream, const char *name, void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) { struct snd_info_entry *entry; entry = snd_info_create_card_entry(substream->pcm->card, name, substream->proc_root); if (entry) snd_info_set_text_ops(entry, substream, read); return entry; } static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { struct snd_info_entry *entry; struct snd_card *card; char name[16]; card = substream->pcm->card; sprintf(name, "sub%i", substream->number); entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root); if (!entry) return -ENOMEM; entry->mode = S_IFDIR | 0555; substream->proc_root = entry; create_substream_info_entry(substream, "info", snd_pcm_substream_proc_info_read); create_substream_info_entry(substream, "hw_params", snd_pcm_substream_proc_hw_params_read); create_substream_info_entry(substream, "sw_params", snd_pcm_substream_proc_sw_params_read); create_substream_info_entry(substream, "status", snd_pcm_substream_proc_status_read); #ifdef CONFIG_SND_PCM_XRUN_DEBUG entry = create_substream_info_entry(substream, "xrun_injection", NULL); if (entry) { entry->c.text.write = snd_pcm_xrun_injection_write; entry->mode = S_IFREG | 0200; } #endif /* CONFIG_SND_PCM_XRUN_DEBUG */ return 0; } #else /* !CONFIG_SND_VERBOSE_PROCFS */ static inline int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { return 0; } static inline int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { return 0; } static inline int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { return 0; } #endif /* CONFIG_SND_VERBOSE_PROCFS */ static const struct attribute_group *pcm_dev_attr_groups[]; /* * PM callbacks: we need to deal only with suspend here, as the resume is * triggered either from user-space or the driver's resume callback */ #ifdef CONFIG_PM_SLEEP static int do_pcm_suspend(struct device *dev) { struct snd_pcm_str *pstr = dev_get_drvdata(dev); if (!pstr->pcm->no_device_suspend) snd_pcm_suspend_all(pstr->pcm); return 0; } #endif static const struct dev_pm_ops pcm_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(do_pcm_suspend, NULL) }; /* device type for PCM -- basically only for passing PM callbacks */ static const struct device_type pcm_dev_type = { .name = "pcm", .pm = &pcm_dev_pm_ops, }; /** * snd_pcm_new_stream - create a new PCM stream * @pcm: the pcm instance * @stream: the stream direction, SNDRV_PCM_STREAM_XXX * @substream_count: the number of substreams * * Creates a new stream for the pcm. * The corresponding stream on the pcm must have been empty before * calling this, i.e. zero must be given to the argument of * snd_pcm_new(). * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) { int idx, err; struct snd_pcm_str *pstr = &pcm->streams[stream]; struct snd_pcm_substream *substream, *prev; #if IS_ENABLED(CONFIG_SND_PCM_OSS) mutex_init(&pstr->oss.setup_mutex); #endif pstr->stream = stream; pstr->pcm = pcm; pstr->substream_count = substream_count; if (!substream_count) return 0; err = snd_device_alloc(&pstr->dev, pcm->card); if (err < 0) return err; dev_set_name(pstr->dev, "pcmC%iD%i%c", pcm->card->number, pcm->device, stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c'); pstr->dev->groups = pcm_dev_attr_groups; pstr->dev->type = &pcm_dev_type; dev_set_drvdata(pstr->dev, pstr); if (!pcm->internal) { err = snd_pcm_stream_proc_init(pstr); if (err < 0) { pcm_err(pcm, "Error in snd_pcm_stream_proc_init\n"); return err; } } prev = NULL; for (idx = 0, prev = NULL; idx < substream_count; idx++) { substream = kzalloc(sizeof(*substream), GFP_KERNEL); if (!substream) return -ENOMEM; substream->pcm = pcm; substream->pstr = pstr; substream->number = idx; substream->stream = stream; sprintf(substream->name, "subdevice #%i", idx); substream->buffer_bytes_max = UINT_MAX; if (prev == NULL) pstr->substream = substream; else prev->next = substream; if (!pcm->internal) { err = snd_pcm_substream_proc_init(substream); if (err < 0) { pcm_err(pcm, "Error in snd_pcm_stream_proc_init\n"); if (prev == NULL) pstr->substream = NULL; else prev->next = NULL; kfree(substream); return err; } } substream->group = &substream->self_group; snd_pcm_group_init(&substream->self_group); list_add_tail(&substream->link_list, &substream->self_group.substreams); atomic_set(&substream->mmap_count, 0); prev = substream; } return 0; } EXPORT_SYMBOL(snd_pcm_new_stream); static int _snd_pcm_new(struct snd_card *card, const char *id, int device, int playback_count, int capture_count, bool internal, struct snd_pcm **rpcm) { struct snd_pcm *pcm; int err; static const struct snd_device_ops ops = { .dev_free = snd_pcm_dev_free, .dev_register = snd_pcm_dev_register, .dev_disconnect = snd_pcm_dev_disconnect, }; static const struct snd_device_ops internal_ops = { .dev_free = snd_pcm_dev_free, }; if (snd_BUG_ON(!card)) return -ENXIO; if (rpcm) *rpcm = NULL; pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); if (!pcm) return -ENOMEM; pcm->card = card; pcm->device = device; pcm->internal = internal; mutex_init(&pcm->open_mutex); init_waitqueue_head(&pcm->open_wait); INIT_LIST_HEAD(&pcm->list); if (id) strscpy(pcm->id, id, sizeof(pcm->id)); err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count); if (err < 0) goto free_pcm; err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count); if (err < 0) goto free_pcm; err = snd_device_new(card, SNDRV_DEV_PCM, pcm, internal ? &internal_ops : &ops); if (err < 0) goto free_pcm; if (rpcm) *rpcm = pcm; return 0; free_pcm: snd_pcm_free(pcm); return err; } /** * snd_pcm_new - create a new PCM instance * @card: the card instance * @id: the id string * @device: the device index (zero based) * @playback_count: the number of substreams for playback * @capture_count: the number of substreams for capture * @rpcm: the pointer to store the new pcm instance * * Creates a new PCM instance. * * The pcm operators have to be set afterwards to the new instance * via snd_pcm_set_ops(). * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_new(struct snd_card *card, const char *id, int device, int playback_count, int capture_count, struct snd_pcm **rpcm) { return _snd_pcm_new(card, id, device, playback_count, capture_count, false, rpcm); } EXPORT_SYMBOL(snd_pcm_new); /** * snd_pcm_new_internal - create a new internal PCM instance * @card: the card instance * @id: the id string * @device: the device index (zero based - shared with normal PCMs) * @playback_count: the number of substreams for playback * @capture_count: the number of substreams for capture * @rpcm: the pointer to store the new pcm instance * * Creates a new internal PCM instance with no userspace device or procfs * entries. This is used by ASoC Back End PCMs in order to create a PCM that * will only be used internally by kernel drivers. i.e. it cannot be opened * by userspace. It provides existing ASoC components drivers with a substream * and access to any private data. * * The pcm operators have to be set afterwards to the new instance * via snd_pcm_set_ops(). * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_new_internal(struct snd_card *card, const char *id, int device, int playback_count, int capture_count, struct snd_pcm **rpcm) { return _snd_pcm_new(card, id, device, playback_count, capture_count, true, rpcm); } EXPORT_SYMBOL(snd_pcm_new_internal); static void free_chmap(struct snd_pcm_str *pstr) { if (pstr->chmap_kctl) { struct snd_card *card = pstr->pcm->card; snd_ctl_remove(card, pstr->chmap_kctl); pstr->chmap_kctl = NULL; } } static void snd_pcm_free_stream(struct snd_pcm_str * pstr) { struct snd_pcm_substream *substream, *substream_next; #if IS_ENABLED(CONFIG_SND_PCM_OSS) struct snd_pcm_oss_setup *setup, *setupn; #endif /* free all proc files under the stream */ snd_pcm_stream_proc_done(pstr); substream = pstr->substream; while (substream) { substream_next = substream->next; snd_pcm_timer_done(substream); kfree(substream); substream = substream_next; } #if IS_ENABLED(CONFIG_SND_PCM_OSS) for (setup = pstr->oss.setup_list; setup; setup = setupn) { setupn = setup->next; kfree(setup->task_name); kfree(setup); } #endif free_chmap(pstr); if (pstr->substream_count) put_device(pstr->dev); } #if IS_ENABLED(CONFIG_SND_PCM_OSS) #define pcm_call_notify(pcm, call) \ do { \ struct snd_pcm_notify *_notify; \ list_for_each_entry(_notify, &snd_pcm_notify_list, list) \ _notify->call(pcm); \ } while (0) #else #define pcm_call_notify(pcm, call) do {} while (0) #endif static int snd_pcm_free(struct snd_pcm *pcm) { if (!pcm) return 0; if (!pcm->internal) pcm_call_notify(pcm, n_unregister); if (pcm->private_free) pcm->private_free(pcm); snd_pcm_lib_preallocate_free_for_all(pcm); snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]); snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]); kfree(pcm); return 0; } static int snd_pcm_dev_free(struct snd_device *device) { struct snd_pcm *pcm = device->device_data; return snd_pcm_free(pcm); } int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream) { struct snd_pcm_str * pstr; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; struct snd_card *card; int prefer_subdevice; size_t size; if (snd_BUG_ON(!pcm || !rsubstream)) return -ENXIO; if (snd_BUG_ON(stream != SNDRV_PCM_STREAM_PLAYBACK && stream != SNDRV_PCM_STREAM_CAPTURE)) return -EINVAL; *rsubstream = NULL; pstr = &pcm->streams[stream]; if (pstr->substream == NULL || pstr->substream_count == 0) return -ENODEV; card = pcm->card; prefer_subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_PCM); if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { int opposite = !stream; for (substream = pcm->streams[opposite].substream; substream; substream = substream->next) { if (SUBSTREAM_BUSY(substream)) return -EAGAIN; } } if (file->f_flags & O_APPEND) { if (prefer_subdevice < 0) { if (pstr->substream_count > 1) return -EINVAL; /* must be unique */ substream = pstr->substream; } else { for (substream = pstr->substream; substream; substream = substream->next) if (substream->number == prefer_subdevice) break; } if (! substream) return -ENODEV; if (! SUBSTREAM_BUSY(substream)) return -EBADFD; substream->ref_count++; *rsubstream = substream; return 0; } for (substream = pstr->substream; substream; substream = substream->next) { if (!SUBSTREAM_BUSY(substream) && (prefer_subdevice == -1 || substream->number == prefer_subdevice)) break; } if (substream == NULL) return -EAGAIN; runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); if (runtime == NULL) return -ENOMEM; size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)); runtime->status = alloc_pages_exact(size, GFP_KERNEL); if (runtime->status == NULL) { kfree(runtime); return -ENOMEM; } memset(runtime->status, 0, size); size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)); runtime->control = alloc_pages_exact(size, GFP_KERNEL); if (runtime->control == NULL) { free_pages_exact(runtime->status, PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); kfree(runtime); return -ENOMEM; } memset(runtime->control, 0, size); init_waitqueue_head(&runtime->sleep); init_waitqueue_head(&runtime->tsleep); __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_OPEN); mutex_init(&runtime->buffer_mutex); atomic_set(&runtime->buffer_accessing, 0); substream->runtime = runtime; substream->private_data = pcm->private_data; substream->ref_count = 1; substream->f_flags = file->f_flags; substream->pid = get_pid(task_pid(current)); pstr->substream_opened++; *rsubstream = substream; return 0; } void snd_pcm_detach_substream(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; if (PCM_RUNTIME_CHECK(substream)) return; runtime = substream->runtime; if (runtime->private_free != NULL) runtime->private_free(runtime); free_pages_exact(runtime->status, PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); free_pages_exact(runtime->control, PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); kfree(runtime->hw_constraints.rules); /* Avoid concurrent access to runtime via PCM timer interface */ if (substream->timer) { spin_lock_irq(&substream->timer->lock); substream->runtime = NULL; spin_unlock_irq(&substream->timer->lock); } else { substream->runtime = NULL; } mutex_destroy(&runtime->buffer_mutex); snd_fasync_free(runtime->fasync); kfree(runtime); put_pid(substream->pid); substream->pid = NULL; substream->pstr->substream_opened--; } static ssize_t pcm_class_show(struct device *dev, struct device_attribute *attr, char *buf) { struct snd_pcm_str *pstr = dev_get_drvdata(dev); struct snd_pcm *pcm = pstr->pcm; const char *str; static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = { [SNDRV_PCM_CLASS_GENERIC] = "generic", [SNDRV_PCM_CLASS_MULTI] = "multi", [SNDRV_PCM_CLASS_MODEM] = "modem", [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer", }; if (pcm->dev_class > SNDRV_PCM_CLASS_LAST) str = "none"; else str = strs[pcm->dev_class]; return sysfs_emit(buf, "%s\n", str); } static DEVICE_ATTR_RO(pcm_class); static struct attribute *pcm_dev_attrs[] = { &dev_attr_pcm_class.attr, NULL }; static const struct attribute_group pcm_dev_attr_group = { .attrs = pcm_dev_attrs, }; static const struct attribute_group *pcm_dev_attr_groups[] = { &pcm_dev_attr_group, NULL }; static int snd_pcm_dev_register(struct snd_device *device) { int cidx, err; struct snd_pcm_substream *substream; struct snd_pcm *pcm; if (snd_BUG_ON(!device || !device->device_data)) return -ENXIO; pcm = device->device_data; mutex_lock(&register_mutex); err = snd_pcm_add(pcm); if (err) goto unlock; for (cidx = 0; cidx < 2; cidx++) { int devtype = -1; if (pcm->streams[cidx].substream == NULL) continue; switch (cidx) { case SNDRV_PCM_STREAM_PLAYBACK: devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK; break; case SNDRV_PCM_STREAM_CAPTURE: devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE; break; } /* register pcm */ err = snd_register_device(devtype, pcm->card, pcm->device, &snd_pcm_f_ops[cidx], pcm, pcm->streams[cidx].dev); if (err < 0) { list_del_init(&pcm->list); goto unlock; } for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) snd_pcm_timer_init(substream); } pcm_call_notify(pcm, n_register); unlock: mutex_unlock(&register_mutex); return err; } static int snd_pcm_dev_disconnect(struct snd_device *device) { struct snd_pcm *pcm = device->device_data; struct snd_pcm_substream *substream; int cidx; mutex_lock(&register_mutex); mutex_lock(&pcm->open_mutex); wake_up(&pcm->open_wait); list_del_init(&pcm->list); for_each_pcm_substream(pcm, cidx, substream) { snd_pcm_stream_lock_irq(substream); if (substream->runtime) { if (snd_pcm_running(substream)) snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED); /* to be sure, set the state unconditionally */ __snd_pcm_set_state(substream->runtime, SNDRV_PCM_STATE_DISCONNECTED); wake_up(&substream->runtime->sleep); wake_up(&substream->runtime->tsleep); } snd_pcm_stream_unlock_irq(substream); } for_each_pcm_substream(pcm, cidx, substream) snd_pcm_sync_stop(substream, false); pcm_call_notify(pcm, n_disconnect); for (cidx = 0; cidx < 2; cidx++) { if (pcm->streams[cidx].dev) snd_unregister_device(pcm->streams[cidx].dev); free_chmap(&pcm->streams[cidx]); } mutex_unlock(&pcm->open_mutex); mutex_unlock(&register_mutex); return 0; } #if IS_ENABLED(CONFIG_SND_PCM_OSS) /** * snd_pcm_notify - Add/remove the notify list * @notify: PCM notify list * @nfree: 0 = register, 1 = unregister * * This adds the given notifier to the global list so that the callback is * called for each registered PCM devices. This exists only for PCM OSS * emulation, so far. * * Return: zero if successful, or a negative error code */ int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree) { struct snd_pcm *pcm; if (snd_BUG_ON(!notify || !notify->n_register || !notify->n_unregister || !notify->n_disconnect)) return -EINVAL; mutex_lock(&register_mutex); if (nfree) { list_del(&notify->list); list_for_each_entry(pcm, &snd_pcm_devices, list) notify->n_unregister(pcm); } else { list_add_tail(&notify->list, &snd_pcm_notify_list); list_for_each_entry(pcm, &snd_pcm_devices, list) notify->n_register(pcm); } mutex_unlock(&register_mutex); return 0; } EXPORT_SYMBOL(snd_pcm_notify); #endif /* CONFIG_SND_PCM_OSS */ #ifdef CONFIG_SND_PROC_FS /* * Info interface */ static void snd_pcm_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_pcm *pcm; mutex_lock(&register_mutex); list_for_each_entry(pcm, &snd_pcm_devices, list) { snd_iprintf(buffer, "%02i-%02i: %s : %s", pcm->card->number, pcm->device, pcm->id, pcm->name); if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) snd_iprintf(buffer, " : playback %i", pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count); if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) snd_iprintf(buffer, " : capture %i", pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count); snd_iprintf(buffer, "\n"); } mutex_unlock(&register_mutex); } static struct snd_info_entry *snd_pcm_proc_entry; static void snd_pcm_proc_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL); if (entry) { snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read); if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } } snd_pcm_proc_entry = entry; } static void snd_pcm_proc_done(void) { snd_info_free_entry(snd_pcm_proc_entry); } #else /* !CONFIG_SND_PROC_FS */ #define snd_pcm_proc_init() #define snd_pcm_proc_done() #endif /* CONFIG_SND_PROC_FS */ /* * ENTRY functions */ static int __init alsa_pcm_init(void) { snd_ctl_register_ioctl(snd_pcm_control_ioctl); snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl); snd_pcm_proc_init(); return 0; } static void __exit alsa_pcm_exit(void) { snd_ctl_unregister_ioctl(snd_pcm_control_ioctl); snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl); snd_pcm_proc_done(); } module_init(alsa_pcm_init) module_exit(alsa_pcm_exit)
linux-master
sound/core/pcm.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Advanced Linux Sound Architecture * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/time.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/info.h> #include <linux/sound.h> #include <linux/mutex.h> #define SNDRV_OSS_MINORS 256 static struct snd_minor *snd_oss_minors[SNDRV_OSS_MINORS]; static DEFINE_MUTEX(sound_oss_mutex); /* NOTE: This function increments the refcount of the associated card like * snd_lookup_minor_data(); the caller must call snd_card_unref() appropriately */ void *snd_lookup_oss_minor_data(unsigned int minor, int type) { struct snd_minor *mreg; void *private_data; if (minor >= ARRAY_SIZE(snd_oss_minors)) return NULL; mutex_lock(&sound_oss_mutex); mreg = snd_oss_minors[minor]; if (mreg && mreg->type == type) { private_data = mreg->private_data; if (private_data && mreg->card_ptr) get_device(&mreg->card_ptr->card_dev); } else private_data = NULL; mutex_unlock(&sound_oss_mutex); return private_data; } EXPORT_SYMBOL(snd_lookup_oss_minor_data); static int snd_oss_kernel_minor(int type, struct snd_card *card, int dev) { int minor; switch (type) { case SNDRV_OSS_DEVICE_TYPE_MIXER: if (snd_BUG_ON(!card || dev < 0 || dev > 1)) return -EINVAL; minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIXER1 : SNDRV_MINOR_OSS_MIXER)); break; case SNDRV_OSS_DEVICE_TYPE_SEQUENCER: minor = SNDRV_MINOR_OSS_SEQUENCER; break; case SNDRV_OSS_DEVICE_TYPE_MUSIC: minor = SNDRV_MINOR_OSS_MUSIC; break; case SNDRV_OSS_DEVICE_TYPE_PCM: if (snd_BUG_ON(!card || dev < 0 || dev > 1)) return -EINVAL; minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_PCM1 : SNDRV_MINOR_OSS_PCM)); break; case SNDRV_OSS_DEVICE_TYPE_MIDI: if (snd_BUG_ON(!card || dev < 0 || dev > 1)) return -EINVAL; minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIDI1 : SNDRV_MINOR_OSS_MIDI)); break; case SNDRV_OSS_DEVICE_TYPE_DMFM: minor = SNDRV_MINOR_OSS(card->number, SNDRV_MINOR_OSS_DMFM); break; case SNDRV_OSS_DEVICE_TYPE_SNDSTAT: minor = SNDRV_MINOR_OSS_SNDSTAT; break; default: return -EINVAL; } if (minor < 0 || minor >= SNDRV_OSS_MINORS) return -EINVAL; return minor; } int snd_register_oss_device(int type, struct snd_card *card, int dev, const struct file_operations *f_ops, void *private_data) { int minor = snd_oss_kernel_minor(type, card, dev); int minor_unit; struct snd_minor *preg; int cidx = SNDRV_MINOR_OSS_CARD(minor); int track2 = -1; int register1 = -1, register2 = -1; struct device *carddev = snd_card_get_device_link(card); if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) return 0; /* ignore silently */ if (minor < 0) return minor; preg = kmalloc(sizeof(struct snd_minor), GFP_KERNEL); if (preg == NULL) return -ENOMEM; preg->type = type; preg->card = card ? card->number : -1; preg->device = dev; preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; mutex_lock(&sound_oss_mutex); snd_oss_minors[minor] = preg; minor_unit = SNDRV_MINOR_OSS_DEVICE(minor); switch (minor_unit) { case SNDRV_MINOR_OSS_PCM: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO); break; case SNDRV_MINOR_OSS_MIDI: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI); break; case SNDRV_MINOR_OSS_MIDI1: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1); break; } register1 = register_sound_special_device(f_ops, minor, carddev); if (register1 != minor) goto __end; if (track2 >= 0) { register2 = register_sound_special_device(f_ops, track2, carddev); if (register2 != track2) goto __end; snd_oss_minors[track2] = preg; } mutex_unlock(&sound_oss_mutex); return 0; __end: if (register2 >= 0) unregister_sound_special(register2); if (register1 >= 0) unregister_sound_special(register1); snd_oss_minors[minor] = NULL; mutex_unlock(&sound_oss_mutex); kfree(preg); return -EBUSY; } EXPORT_SYMBOL(snd_register_oss_device); int snd_unregister_oss_device(int type, struct snd_card *card, int dev) { int minor = snd_oss_kernel_minor(type, card, dev); int cidx = SNDRV_MINOR_OSS_CARD(minor); int track2 = -1; struct snd_minor *mptr; if (card && card->number >= SNDRV_MINOR_OSS_DEVICES) return 0; if (minor < 0) return minor; mutex_lock(&sound_oss_mutex); mptr = snd_oss_minors[minor]; if (mptr == NULL) { mutex_unlock(&sound_oss_mutex); return -ENOENT; } switch (SNDRV_MINOR_OSS_DEVICE(minor)) { case SNDRV_MINOR_OSS_PCM: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO); break; case SNDRV_MINOR_OSS_MIDI: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI); break; case SNDRV_MINOR_OSS_MIDI1: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1); break; } if (track2 >= 0) snd_oss_minors[track2] = NULL; snd_oss_minors[minor] = NULL; mutex_unlock(&sound_oss_mutex); /* call unregister_sound_special() outside sound_oss_mutex; * otherwise may deadlock, as it can trigger the release of a card */ unregister_sound_special(minor); if (track2 >= 0) unregister_sound_special(track2); kfree(mptr); return 0; } EXPORT_SYMBOL(snd_unregister_oss_device); /* * INFO PART */ #ifdef CONFIG_SND_PROC_FS static const char *snd_oss_device_type_name(int type) { switch (type) { case SNDRV_OSS_DEVICE_TYPE_MIXER: return "mixer"; case SNDRV_OSS_DEVICE_TYPE_SEQUENCER: case SNDRV_OSS_DEVICE_TYPE_MUSIC: return "sequencer"; case SNDRV_OSS_DEVICE_TYPE_PCM: return "digital audio"; case SNDRV_OSS_DEVICE_TYPE_MIDI: return "raw midi"; case SNDRV_OSS_DEVICE_TYPE_DMFM: return "hardware dependent"; default: return "?"; } } static void snd_minor_info_oss_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { int minor; struct snd_minor *mptr; mutex_lock(&sound_oss_mutex); for (minor = 0; minor < SNDRV_OSS_MINORS; ++minor) { mptr = snd_oss_minors[minor]; if (!mptr) continue; if (mptr->card >= 0) snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", minor, mptr->card, mptr->device, snd_oss_device_type_name(mptr->type)); else snd_iprintf(buffer, "%3i: : %s\n", minor, snd_oss_device_type_name(mptr->type)); } mutex_unlock(&sound_oss_mutex); } int __init snd_minor_info_oss_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root); if (!entry) return -ENOMEM; entry->c.text.read = snd_minor_info_oss_read; return snd_info_register(entry); /* freed in error path */ } #endif /* CONFIG_SND_PROC_FS */
linux-master
sound/core/sound_oss.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Jack abstraction layer * * Copyright 2008 Wolfson Microelectronics */ #include <linux/input.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/ctype.h> #include <linux/mm.h> #include <linux/debugfs.h> #include <sound/jack.h> #include <sound/core.h> #include <sound/control.h> struct snd_jack_kctl { struct snd_kcontrol *kctl; struct list_head list; /* list of controls belong to the same jack */ unsigned int mask_bits; /* only masked status bits are reported via kctl */ struct snd_jack *jack; /* pointer to struct snd_jack */ bool sw_inject_enable; /* allow to inject plug event via debugfs */ #ifdef CONFIG_SND_JACK_INJECTION_DEBUG struct dentry *jack_debugfs_root; /* jack_kctl debugfs root */ #endif }; #ifdef CONFIG_SND_JACK_INPUT_DEV static const int jack_switch_types[SND_JACK_SWITCH_TYPES] = { SW_HEADPHONE_INSERT, SW_MICROPHONE_INSERT, SW_LINEOUT_INSERT, SW_JACK_PHYSICAL_INSERT, SW_VIDEOOUT_INSERT, SW_LINEIN_INSERT, }; #endif /* CONFIG_SND_JACK_INPUT_DEV */ static int snd_jack_dev_disconnect(struct snd_device *device) { #ifdef CONFIG_SND_JACK_INPUT_DEV struct snd_jack *jack = device->device_data; mutex_lock(&jack->input_dev_lock); if (!jack->input_dev) { mutex_unlock(&jack->input_dev_lock); return 0; } /* If the input device is registered with the input subsystem * then we need to use a different deallocator. */ if (jack->registered) input_unregister_device(jack->input_dev); else input_free_device(jack->input_dev); jack->input_dev = NULL; mutex_unlock(&jack->input_dev_lock); #endif /* CONFIG_SND_JACK_INPUT_DEV */ return 0; } static int snd_jack_dev_free(struct snd_device *device) { struct snd_jack *jack = device->device_data; struct snd_card *card = device->card; struct snd_jack_kctl *jack_kctl, *tmp_jack_kctl; list_for_each_entry_safe(jack_kctl, tmp_jack_kctl, &jack->kctl_list, list) { list_del_init(&jack_kctl->list); snd_ctl_remove(card, jack_kctl->kctl); } if (jack->private_free) jack->private_free(jack); snd_jack_dev_disconnect(device); kfree(jack->id); kfree(jack); return 0; } #ifdef CONFIG_SND_JACK_INPUT_DEV static int snd_jack_dev_register(struct snd_device *device) { struct snd_jack *jack = device->device_data; struct snd_card *card = device->card; int err, i; snprintf(jack->name, sizeof(jack->name), "%s %s", card->shortname, jack->id); mutex_lock(&jack->input_dev_lock); if (!jack->input_dev) { mutex_unlock(&jack->input_dev_lock); return 0; } jack->input_dev->name = jack->name; /* Default to the sound card device. */ if (!jack->input_dev->dev.parent) jack->input_dev->dev.parent = snd_card_get_device_link(card); /* Add capabilities for any keys that are enabled */ for (i = 0; i < ARRAY_SIZE(jack->key); i++) { int testbit = SND_JACK_BTN_0 >> i; if (!(jack->type & testbit)) continue; if (!jack->key[i]) jack->key[i] = BTN_0 + i; input_set_capability(jack->input_dev, EV_KEY, jack->key[i]); } err = input_register_device(jack->input_dev); if (err == 0) jack->registered = 1; mutex_unlock(&jack->input_dev_lock); return err; } #endif /* CONFIG_SND_JACK_INPUT_DEV */ #ifdef CONFIG_SND_JACK_INJECTION_DEBUG static void snd_jack_inject_report(struct snd_jack_kctl *jack_kctl, int status) { struct snd_jack *jack; #ifdef CONFIG_SND_JACK_INPUT_DEV int i; #endif if (!jack_kctl) return; jack = jack_kctl->jack; if (jack_kctl->sw_inject_enable) snd_kctl_jack_report(jack->card, jack_kctl->kctl, status & jack_kctl->mask_bits); #ifdef CONFIG_SND_JACK_INPUT_DEV if (!jack->input_dev) return; for (i = 0; i < ARRAY_SIZE(jack->key); i++) { int testbit = ((SND_JACK_BTN_0 >> i) & jack_kctl->mask_bits); if (jack->type & testbit) input_report_key(jack->input_dev, jack->key[i], status & testbit); } for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) { int testbit = ((1 << i) & jack_kctl->mask_bits); if (jack->type & testbit) input_report_switch(jack->input_dev, jack_switch_types[i], status & testbit); } input_sync(jack->input_dev); #endif /* CONFIG_SND_JACK_INPUT_DEV */ } static ssize_t sw_inject_enable_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; int len, ret; char buf[128]; len = scnprintf(buf, sizeof(buf), "%s: %s\t\t%s: %i\n", "Jack", jack_kctl->kctl->id.name, "Inject Enabled", jack_kctl->sw_inject_enable); ret = simple_read_from_buffer(to, count, ppos, buf, len); return ret; } static ssize_t sw_inject_enable_write(struct file *file, const char __user *from, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; int ret, err; unsigned long enable; char buf[8] = { 0 }; ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); err = kstrtoul(buf, 0, &enable); if (err) return err; if (jack_kctl->sw_inject_enable == (!!enable)) return ret; jack_kctl->sw_inject_enable = !!enable; if (!jack_kctl->sw_inject_enable) snd_jack_report(jack_kctl->jack, jack_kctl->jack->hw_status_cache); return ret; } static ssize_t jackin_inject_write(struct file *file, const char __user *from, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; int ret, err; unsigned long enable; char buf[8] = { 0 }; if (!jack_kctl->sw_inject_enable) return -EINVAL; ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, from, count); err = kstrtoul(buf, 0, &enable); if (err) return err; snd_jack_inject_report(jack_kctl, !!enable ? jack_kctl->mask_bits : 0); return ret; } static ssize_t jack_kctl_id_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; char buf[64]; int len, ret; len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->id.name); ret = simple_read_from_buffer(to, count, ppos, buf, len); return ret; } /* the bit definition is aligned with snd_jack_types in jack.h */ static const char * const jack_events_name[] = { "HEADPHONE(0x0001)", "MICROPHONE(0x0002)", "LINEOUT(0x0004)", "MECHANICAL(0x0008)", "VIDEOOUT(0x0010)", "LINEIN(0x0020)", "", "", "", "BTN_5(0x0200)", "BTN_4(0x0400)", "BTN_3(0x0800)", "BTN_2(0x1000)", "BTN_1(0x2000)", "BTN_0(0x4000)", "", }; /* the recommended buffer size is 256 */ static int parse_mask_bits(unsigned int mask_bits, char *buf, size_t buf_size) { int i; scnprintf(buf, buf_size, "0x%04x", mask_bits); for (i = 0; i < ARRAY_SIZE(jack_events_name); i++) if (mask_bits & (1 << i)) { strlcat(buf, " ", buf_size); strlcat(buf, jack_events_name[i], buf_size); } strlcat(buf, "\n", buf_size); return strlen(buf); } static ssize_t jack_kctl_mask_bits_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; char buf[256]; int len, ret; len = parse_mask_bits(jack_kctl->mask_bits, buf, sizeof(buf)); ret = simple_read_from_buffer(to, count, ppos, buf, len); return ret; } static ssize_t jack_kctl_status_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; char buf[16]; int len, ret; len = scnprintf(buf, sizeof(buf), "%s\n", jack_kctl->kctl->private_value ? "Plugged" : "Unplugged"); ret = simple_read_from_buffer(to, count, ppos, buf, len); return ret; } #ifdef CONFIG_SND_JACK_INPUT_DEV static ssize_t jack_type_read(struct file *file, char __user *to, size_t count, loff_t *ppos) { struct snd_jack_kctl *jack_kctl = file->private_data; char buf[256]; int len, ret; len = parse_mask_bits(jack_kctl->jack->type, buf, sizeof(buf)); ret = simple_read_from_buffer(to, count, ppos, buf, len); return ret; } static const struct file_operations jack_type_fops = { .open = simple_open, .read = jack_type_read, .llseek = default_llseek, }; #endif static const struct file_operations sw_inject_enable_fops = { .open = simple_open, .read = sw_inject_enable_read, .write = sw_inject_enable_write, .llseek = default_llseek, }; static const struct file_operations jackin_inject_fops = { .open = simple_open, .write = jackin_inject_write, .llseek = default_llseek, }; static const struct file_operations jack_kctl_id_fops = { .open = simple_open, .read = jack_kctl_id_read, .llseek = default_llseek, }; static const struct file_operations jack_kctl_mask_bits_fops = { .open = simple_open, .read = jack_kctl_mask_bits_read, .llseek = default_llseek, }; static const struct file_operations jack_kctl_status_fops = { .open = simple_open, .read = jack_kctl_status_read, .llseek = default_llseek, }; static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack, struct snd_jack_kctl *jack_kctl) { char *tname; int i; /* Don't create injection interface for Phantom jacks */ if (strstr(jack_kctl->kctl->id.name, "Phantom")) return 0; tname = kstrdup(jack_kctl->kctl->id.name, GFP_KERNEL); if (!tname) return -ENOMEM; /* replace the chars which are not suitable for folder's name with _ */ for (i = 0; tname[i]; i++) if (!isalnum(tname[i])) tname[i] = '_'; jack_kctl->jack_debugfs_root = debugfs_create_dir(tname, jack->card->debugfs_root); kfree(tname); debugfs_create_file("sw_inject_enable", 0644, jack_kctl->jack_debugfs_root, jack_kctl, &sw_inject_enable_fops); debugfs_create_file("jackin_inject", 0200, jack_kctl->jack_debugfs_root, jack_kctl, &jackin_inject_fops); debugfs_create_file("kctl_id", 0444, jack_kctl->jack_debugfs_root, jack_kctl, &jack_kctl_id_fops); debugfs_create_file("mask_bits", 0444, jack_kctl->jack_debugfs_root, jack_kctl, &jack_kctl_mask_bits_fops); debugfs_create_file("status", 0444, jack_kctl->jack_debugfs_root, jack_kctl, &jack_kctl_status_fops); #ifdef CONFIG_SND_JACK_INPUT_DEV debugfs_create_file("type", 0444, jack_kctl->jack_debugfs_root, jack_kctl, &jack_type_fops); #endif return 0; } static void snd_jack_debugfs_clear_inject_node(struct snd_jack_kctl *jack_kctl) { debugfs_remove(jack_kctl->jack_debugfs_root); jack_kctl->jack_debugfs_root = NULL; } #else /* CONFIG_SND_JACK_INJECTION_DEBUG */ static int snd_jack_debugfs_add_inject_node(struct snd_jack *jack, struct snd_jack_kctl *jack_kctl) { return 0; } static void snd_jack_debugfs_clear_inject_node(struct snd_jack_kctl *jack_kctl) { } #endif /* CONFIG_SND_JACK_INJECTION_DEBUG */ static void snd_jack_kctl_private_free(struct snd_kcontrol *kctl) { struct snd_jack_kctl *jack_kctl; jack_kctl = kctl->private_data; if (jack_kctl) { snd_jack_debugfs_clear_inject_node(jack_kctl); list_del(&jack_kctl->list); kfree(jack_kctl); } } static void snd_jack_kctl_add(struct snd_jack *jack, struct snd_jack_kctl *jack_kctl) { jack_kctl->jack = jack; list_add_tail(&jack_kctl->list, &jack->kctl_list); snd_jack_debugfs_add_inject_node(jack, jack_kctl); } static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const char *name, unsigned int mask) { struct snd_kcontrol *kctl; struct snd_jack_kctl *jack_kctl; int err; kctl = snd_kctl_jack_new(name, card); if (!kctl) return NULL; err = snd_ctl_add(card, kctl); if (err < 0) return NULL; jack_kctl = kzalloc(sizeof(*jack_kctl), GFP_KERNEL); if (!jack_kctl) goto error; jack_kctl->kctl = kctl; jack_kctl->mask_bits = mask; kctl->private_data = jack_kctl; kctl->private_free = snd_jack_kctl_private_free; return jack_kctl; error: snd_ctl_free_one(kctl); return NULL; } /** * snd_jack_add_new_kctl - Create a new snd_jack_kctl and add it to jack * @jack: the jack instance which the kctl will attaching to * @name: the name for the snd_kcontrol object * @mask: a bitmask of enum snd_jack_type values that can be detected * by this snd_jack_kctl object. * * Creates a new snd_kcontrol object and adds it to the jack kctl_list. * * Return: Zero if successful, or a negative error code on failure. */ int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask) { struct snd_jack_kctl *jack_kctl; jack_kctl = snd_jack_kctl_new(jack->card, name, mask); if (!jack_kctl) return -ENOMEM; snd_jack_kctl_add(jack, jack_kctl); return 0; } EXPORT_SYMBOL(snd_jack_add_new_kctl); /** * snd_jack_new - Create a new jack * @card: the card instance * @id: an identifying string for this jack * @type: a bitmask of enum snd_jack_type values that can be detected by * this jack * @jjack: Used to provide the allocated jack object to the caller. * @initial_kctl: if true, create a kcontrol and add it to the jack list. * @phantom_jack: Don't create a input device for phantom jacks. * * Creates a new jack object. * * Return: Zero if successful, or a negative error code on failure. * On success @jjack will be initialised. */ int snd_jack_new(struct snd_card *card, const char *id, int type, struct snd_jack **jjack, bool initial_kctl, bool phantom_jack) { struct snd_jack *jack; struct snd_jack_kctl *jack_kctl = NULL; int err; static const struct snd_device_ops ops = { .dev_free = snd_jack_dev_free, #ifdef CONFIG_SND_JACK_INPUT_DEV .dev_register = snd_jack_dev_register, .dev_disconnect = snd_jack_dev_disconnect, #endif /* CONFIG_SND_JACK_INPUT_DEV */ }; if (initial_kctl) { jack_kctl = snd_jack_kctl_new(card, id, type); if (!jack_kctl) return -ENOMEM; } jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL); if (jack == NULL) return -ENOMEM; jack->id = kstrdup(id, GFP_KERNEL); if (jack->id == NULL) { kfree(jack); return -ENOMEM; } #ifdef CONFIG_SND_JACK_INPUT_DEV mutex_init(&jack->input_dev_lock); /* don't create input device for phantom jack */ if (!phantom_jack) { int i; jack->input_dev = input_allocate_device(); if (jack->input_dev == NULL) { err = -ENOMEM; goto fail_input; } jack->input_dev->phys = "ALSA"; jack->type = type; for (i = 0; i < SND_JACK_SWITCH_TYPES; i++) if (type & (1 << i)) input_set_capability(jack->input_dev, EV_SW, jack_switch_types[i]); } #endif /* CONFIG_SND_JACK_INPUT_DEV */ err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); if (err < 0) goto fail_input; jack->card = card; INIT_LIST_HEAD(&jack->kctl_list); if (initial_kctl) snd_jack_kctl_add(jack, jack_kctl); *jjack = jack; return 0; fail_input: #ifdef CONFIG_SND_JACK_INPUT_DEV input_free_device(jack->input_dev); #endif kfree(jack->id); kfree(jack); return err; } EXPORT_SYMBOL(snd_jack_new); #ifdef CONFIG_SND_JACK_INPUT_DEV /** * snd_jack_set_parent - Set the parent device for a jack * * @jack: The jack to configure * @parent: The device to set as parent for the jack. * * Set the parent for the jack devices in the device tree. This * function is only valid prior to registration of the jack. If no * parent is configured then the parent device will be the sound card. */ void snd_jack_set_parent(struct snd_jack *jack, struct device *parent) { WARN_ON(jack->registered); mutex_lock(&jack->input_dev_lock); if (!jack->input_dev) { mutex_unlock(&jack->input_dev_lock); return; } jack->input_dev->dev.parent = parent; mutex_unlock(&jack->input_dev_lock); } EXPORT_SYMBOL(snd_jack_set_parent); /** * snd_jack_set_key - Set a key mapping on a jack * * @jack: The jack to configure * @type: Jack report type for this key * @keytype: Input layer key type to be reported * * Map a SND_JACK_BTN_* button type to an input layer key, allowing * reporting of keys on accessories via the jack abstraction. If no * mapping is provided but keys are enabled in the jack type then * BTN_n numeric buttons will be reported. * * If jacks are not reporting via the input API this call will have no * effect. * * Note that this is intended to be use by simple devices with small * numbers of keys that can be reported. It is also possible to * access the input device directly - devices with complex input * capabilities on accessories should consider doing this rather than * using this abstraction. * * This function may only be called prior to registration of the jack. * * Return: Zero if successful, or a negative error code on failure. */ int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type, int keytype) { int key = fls(SND_JACK_BTN_0) - fls(type); WARN_ON(jack->registered); if (!keytype || key >= ARRAY_SIZE(jack->key)) return -EINVAL; jack->type |= type; jack->key[key] = keytype; return 0; } EXPORT_SYMBOL(snd_jack_set_key); #endif /* CONFIG_SND_JACK_INPUT_DEV */ /** * snd_jack_report - Report the current status of a jack * Note: This function uses mutexes and should be called from a * context which can sleep (such as a workqueue). * * @jack: The jack to report status for * @status: The current status of the jack */ void snd_jack_report(struct snd_jack *jack, int status) { struct snd_jack_kctl *jack_kctl; unsigned int mask_bits = 0; #ifdef CONFIG_SND_JACK_INPUT_DEV struct input_dev *idev; int i; #endif if (!jack) return; jack->hw_status_cache = status; list_for_each_entry(jack_kctl, &jack->kctl_list, list) if (jack_kctl->sw_inject_enable) mask_bits |= jack_kctl->mask_bits; else snd_kctl_jack_report(jack->card, jack_kctl->kctl, status & jack_kctl->mask_bits); #ifdef CONFIG_SND_JACK_INPUT_DEV idev = input_get_device(jack->input_dev); if (!idev) return; for (i = 0; i < ARRAY_SIZE(jack->key); i++) { int testbit = ((SND_JACK_BTN_0 >> i) & ~mask_bits); if (jack->type & testbit) input_report_key(idev, jack->key[i], status & testbit); } for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) { int testbit = ((1 << i) & ~mask_bits); if (jack->type & testbit) input_report_switch(idev, jack_switch_types[i], status & testbit); } input_sync(idev); input_put_device(idev); #endif /* CONFIG_SND_JACK_INPUT_DEV */ } EXPORT_SYMBOL(snd_jack_report);
linux-master
sound/core/jack.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) by Jaroslav Kysela <[email protected]> * Takashi Iwai <[email protected]> * * Generic memory allocators */ #include <linux/slab.h> #include <linux/mm.h> #include <linux/dma-mapping.h> #include <linux/dma-map-ops.h> #include <linux/genalloc.h> #include <linux/highmem.h> #include <linux/vmalloc.h> #ifdef CONFIG_X86 #include <asm/set_memory.h> #endif #include <sound/memalloc.h> #include "memalloc_local.h" #define DEFAULT_GFP \ (GFP_KERNEL | \ __GFP_RETRY_MAYFAIL | /* don't trigger OOM-killer */ \ __GFP_NOWARN) /* no stack trace print - this call is non-critical */ static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab); #ifdef CONFIG_SND_DMA_SGBUF static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size); #endif static void *__snd_dma_alloc_pages(struct snd_dma_buffer *dmab, size_t size) { const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); if (WARN_ON_ONCE(!ops || !ops->alloc)) return NULL; return ops->alloc(dmab, size); } /** * snd_dma_alloc_dir_pages - allocate the buffer area according to the given * type and direction * @type: the DMA buffer type * @device: the device pointer * @dir: DMA direction * @size: the buffer size to allocate * @dmab: buffer allocation record to store the allocated data * * Calls the memory-allocator function for the corresponding * buffer type. * * Return: Zero if the buffer with the given size is allocated successfully, * otherwise a negative value on error. */ int snd_dma_alloc_dir_pages(int type, struct device *device, enum dma_data_direction dir, size_t size, struct snd_dma_buffer *dmab) { if (WARN_ON(!size)) return -ENXIO; if (WARN_ON(!dmab)) return -ENXIO; size = PAGE_ALIGN(size); dmab->dev.type = type; dmab->dev.dev = device; dmab->dev.dir = dir; dmab->bytes = 0; dmab->addr = 0; dmab->private_data = NULL; dmab->area = __snd_dma_alloc_pages(dmab, size); if (!dmab->area) return -ENOMEM; dmab->bytes = size; return 0; } EXPORT_SYMBOL(snd_dma_alloc_dir_pages); /** * snd_dma_alloc_pages_fallback - allocate the buffer area according to the given type with fallback * @type: the DMA buffer type * @device: the device pointer * @size: the buffer size to allocate * @dmab: buffer allocation record to store the allocated data * * Calls the memory-allocator function for the corresponding * buffer type. When no space is left, this function reduces the size and * tries to allocate again. The size actually allocated is stored in * res_size argument. * * Return: Zero if the buffer with the given size is allocated successfully, * otherwise a negative value on error. */ int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size, struct snd_dma_buffer *dmab) { int err; while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) { if (err != -ENOMEM) return err; if (size <= PAGE_SIZE) return -ENOMEM; size >>= 1; size = PAGE_SIZE << get_order(size); } if (! dmab->area) return -ENOMEM; return 0; } EXPORT_SYMBOL(snd_dma_alloc_pages_fallback); /** * snd_dma_free_pages - release the allocated buffer * @dmab: the buffer allocation record to release * * Releases the allocated buffer via snd_dma_alloc_pages(). */ void snd_dma_free_pages(struct snd_dma_buffer *dmab) { const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); if (ops && ops->free) ops->free(dmab); } EXPORT_SYMBOL(snd_dma_free_pages); /* called by devres */ static void __snd_release_pages(struct device *dev, void *res) { snd_dma_free_pages(res); } /** * snd_devm_alloc_dir_pages - allocate the buffer and manage with devres * @dev: the device pointer * @type: the DMA buffer type * @dir: DMA direction * @size: the buffer size to allocate * * Allocate buffer pages depending on the given type and manage using devres. * The pages will be released automatically at the device removal. * * Unlike snd_dma_alloc_pages(), this function requires the real device pointer, * hence it can't work with SNDRV_DMA_TYPE_CONTINUOUS or * SNDRV_DMA_TYPE_VMALLOC type. * * Return: the snd_dma_buffer object at success, or NULL if failed */ struct snd_dma_buffer * snd_devm_alloc_dir_pages(struct device *dev, int type, enum dma_data_direction dir, size_t size) { struct snd_dma_buffer *dmab; int err; if (WARN_ON(type == SNDRV_DMA_TYPE_CONTINUOUS || type == SNDRV_DMA_TYPE_VMALLOC)) return NULL; dmab = devres_alloc(__snd_release_pages, sizeof(*dmab), GFP_KERNEL); if (!dmab) return NULL; err = snd_dma_alloc_dir_pages(type, dev, dir, size, dmab); if (err < 0) { devres_free(dmab); return NULL; } devres_add(dev, dmab); return dmab; } EXPORT_SYMBOL_GPL(snd_devm_alloc_dir_pages); /** * snd_dma_buffer_mmap - perform mmap of the given DMA buffer * @dmab: buffer allocation information * @area: VM area information * * Return: zero if successful, or a negative error code */ int snd_dma_buffer_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { const struct snd_malloc_ops *ops; if (!dmab) return -ENOENT; ops = snd_dma_get_ops(dmab); if (ops && ops->mmap) return ops->mmap(dmab, area); else return -ENOENT; } EXPORT_SYMBOL(snd_dma_buffer_mmap); #ifdef CONFIG_HAS_DMA /** * snd_dma_buffer_sync - sync DMA buffer between CPU and device * @dmab: buffer allocation information * @mode: sync mode */ void snd_dma_buffer_sync(struct snd_dma_buffer *dmab, enum snd_dma_sync_mode mode) { const struct snd_malloc_ops *ops; if (!dmab || !dmab->dev.need_sync) return; ops = snd_dma_get_ops(dmab); if (ops && ops->sync) ops->sync(dmab, mode); } EXPORT_SYMBOL_GPL(snd_dma_buffer_sync); #endif /* CONFIG_HAS_DMA */ /** * snd_sgbuf_get_addr - return the physical address at the corresponding offset * @dmab: buffer allocation information * @offset: offset in the ring buffer * * Return: the physical address */ dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset) { const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); if (ops && ops->get_addr) return ops->get_addr(dmab, offset); else return dmab->addr + offset; } EXPORT_SYMBOL(snd_sgbuf_get_addr); /** * snd_sgbuf_get_page - return the physical page at the corresponding offset * @dmab: buffer allocation information * @offset: offset in the ring buffer * * Return: the page pointer */ struct page *snd_sgbuf_get_page(struct snd_dma_buffer *dmab, size_t offset) { const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); if (ops && ops->get_page) return ops->get_page(dmab, offset); else return virt_to_page(dmab->area + offset); } EXPORT_SYMBOL(snd_sgbuf_get_page); /** * snd_sgbuf_get_chunk_size - compute the max chunk size with continuous pages * on sg-buffer * @dmab: buffer allocation information * @ofs: offset in the ring buffer * @size: the requested size * * Return: the chunk size */ unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab, unsigned int ofs, unsigned int size) { const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); if (ops && ops->get_chunk_size) return ops->get_chunk_size(dmab, ofs, size); else return size; } EXPORT_SYMBOL(snd_sgbuf_get_chunk_size); /* * Continuous pages allocator */ static void *do_alloc_pages(struct device *dev, size_t size, dma_addr_t *addr, bool wc) { void *p; gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; again: p = alloc_pages_exact(size, gfp); if (!p) return NULL; *addr = page_to_phys(virt_to_page(p)); if (!dev) return p; if ((*addr + size - 1) & ~dev->coherent_dma_mask) { if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & GFP_DMA32)) { gfp |= GFP_DMA32; goto again; } if (IS_ENABLED(CONFIG_ZONE_DMA) && !(gfp & GFP_DMA)) { gfp = (gfp & ~GFP_DMA32) | GFP_DMA; goto again; } } #ifdef CONFIG_X86 if (wc) set_memory_wc((unsigned long)(p), size >> PAGE_SHIFT); #endif return p; } static void do_free_pages(void *p, size_t size, bool wc) { #ifdef CONFIG_X86 if (wc) set_memory_wb((unsigned long)(p), size >> PAGE_SHIFT); #endif free_pages_exact(p, size); } static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size) { return do_alloc_pages(dmab->dev.dev, size, &dmab->addr, false); } static void snd_dma_continuous_free(struct snd_dma_buffer *dmab) { do_free_pages(dmab->area, dmab->bytes, false); } static int snd_dma_continuous_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { return remap_pfn_range(area, area->vm_start, dmab->addr >> PAGE_SHIFT, area->vm_end - area->vm_start, area->vm_page_prot); } static const struct snd_malloc_ops snd_dma_continuous_ops = { .alloc = snd_dma_continuous_alloc, .free = snd_dma_continuous_free, .mmap = snd_dma_continuous_mmap, }; /* * VMALLOC allocator */ static void *snd_dma_vmalloc_alloc(struct snd_dma_buffer *dmab, size_t size) { return vmalloc(size); } static void snd_dma_vmalloc_free(struct snd_dma_buffer *dmab) { vfree(dmab->area); } static int snd_dma_vmalloc_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { return remap_vmalloc_range(area, dmab->area, 0); } #define get_vmalloc_page_addr(dmab, offset) \ page_to_phys(vmalloc_to_page((dmab)->area + (offset))) static dma_addr_t snd_dma_vmalloc_get_addr(struct snd_dma_buffer *dmab, size_t offset) { return get_vmalloc_page_addr(dmab, offset) + offset % PAGE_SIZE; } static struct page *snd_dma_vmalloc_get_page(struct snd_dma_buffer *dmab, size_t offset) { return vmalloc_to_page(dmab->area + offset); } static unsigned int snd_dma_vmalloc_get_chunk_size(struct snd_dma_buffer *dmab, unsigned int ofs, unsigned int size) { unsigned int start, end; unsigned long addr; start = ALIGN_DOWN(ofs, PAGE_SIZE); end = ofs + size - 1; /* the last byte address */ /* check page continuity */ addr = get_vmalloc_page_addr(dmab, start); for (;;) { start += PAGE_SIZE; if (start > end) break; addr += PAGE_SIZE; if (get_vmalloc_page_addr(dmab, start) != addr) return start - ofs; } /* ok, all on continuous pages */ return size; } static const struct snd_malloc_ops snd_dma_vmalloc_ops = { .alloc = snd_dma_vmalloc_alloc, .free = snd_dma_vmalloc_free, .mmap = snd_dma_vmalloc_mmap, .get_addr = snd_dma_vmalloc_get_addr, .get_page = snd_dma_vmalloc_get_page, .get_chunk_size = snd_dma_vmalloc_get_chunk_size, }; #ifdef CONFIG_HAS_DMA /* * IRAM allocator */ #ifdef CONFIG_GENERIC_ALLOCATOR static void *snd_dma_iram_alloc(struct snd_dma_buffer *dmab, size_t size) { struct device *dev = dmab->dev.dev; struct gen_pool *pool; void *p; if (dev->of_node) { pool = of_gen_pool_get(dev->of_node, "iram", 0); /* Assign the pool into private_data field */ dmab->private_data = pool; p = gen_pool_dma_alloc_align(pool, size, &dmab->addr, PAGE_SIZE); if (p) return p; } /* Internal memory might have limited size and no enough space, * so if we fail to malloc, try to fetch memory traditionally. */ dmab->dev.type = SNDRV_DMA_TYPE_DEV; return __snd_dma_alloc_pages(dmab, size); } static void snd_dma_iram_free(struct snd_dma_buffer *dmab) { struct gen_pool *pool = dmab->private_data; if (pool && dmab->area) gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes); } static int snd_dma_iram_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); return remap_pfn_range(area, area->vm_start, dmab->addr >> PAGE_SHIFT, area->vm_end - area->vm_start, area->vm_page_prot); } static const struct snd_malloc_ops snd_dma_iram_ops = { .alloc = snd_dma_iram_alloc, .free = snd_dma_iram_free, .mmap = snd_dma_iram_mmap, }; #endif /* CONFIG_GENERIC_ALLOCATOR */ /* * Coherent device pages allocator */ static void *snd_dma_dev_alloc(struct snd_dma_buffer *dmab, size_t size) { return dma_alloc_coherent(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP); } static void snd_dma_dev_free(struct snd_dma_buffer *dmab) { dma_free_coherent(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); } static int snd_dma_dev_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { return dma_mmap_coherent(dmab->dev.dev, area, dmab->area, dmab->addr, dmab->bytes); } static const struct snd_malloc_ops snd_dma_dev_ops = { .alloc = snd_dma_dev_alloc, .free = snd_dma_dev_free, .mmap = snd_dma_dev_mmap, }; /* * Write-combined pages */ /* x86-specific allocations */ #ifdef CONFIG_SND_DMA_SGBUF static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size) { return do_alloc_pages(dmab->dev.dev, size, &dmab->addr, true); } static void snd_dma_wc_free(struct snd_dma_buffer *dmab) { do_free_pages(dmab->area, dmab->bytes, true); } static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); return snd_dma_continuous_mmap(dmab, area); } #else static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size) { return dma_alloc_wc(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP); } static void snd_dma_wc_free(struct snd_dma_buffer *dmab) { dma_free_wc(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); } static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { return dma_mmap_wc(dmab->dev.dev, area, dmab->area, dmab->addr, dmab->bytes); } #endif /* CONFIG_SND_DMA_SGBUF */ static const struct snd_malloc_ops snd_dma_wc_ops = { .alloc = snd_dma_wc_alloc, .free = snd_dma_wc_free, .mmap = snd_dma_wc_mmap, }; /* * Non-contiguous pages allocator */ static void *snd_dma_noncontig_alloc(struct snd_dma_buffer *dmab, size_t size) { struct sg_table *sgt; void *p; #ifdef CONFIG_SND_DMA_SGBUF if (cpu_feature_enabled(X86_FEATURE_XENPV)) return snd_dma_sg_fallback_alloc(dmab, size); #endif sgt = dma_alloc_noncontiguous(dmab->dev.dev, size, dmab->dev.dir, DEFAULT_GFP, 0); #ifdef CONFIG_SND_DMA_SGBUF if (!sgt && !get_dma_ops(dmab->dev.dev)) return snd_dma_sg_fallback_alloc(dmab, size); #endif if (!sgt) return NULL; dmab->dev.need_sync = dma_need_sync(dmab->dev.dev, sg_dma_address(sgt->sgl)); p = dma_vmap_noncontiguous(dmab->dev.dev, size, sgt); if (p) { dmab->private_data = sgt; /* store the first page address for convenience */ dmab->addr = snd_sgbuf_get_addr(dmab, 0); } else { dma_free_noncontiguous(dmab->dev.dev, size, sgt, dmab->dev.dir); } return p; } static void snd_dma_noncontig_free(struct snd_dma_buffer *dmab) { dma_vunmap_noncontiguous(dmab->dev.dev, dmab->area); dma_free_noncontiguous(dmab->dev.dev, dmab->bytes, dmab->private_data, dmab->dev.dir); } static int snd_dma_noncontig_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { return dma_mmap_noncontiguous(dmab->dev.dev, area, dmab->bytes, dmab->private_data); } static void snd_dma_noncontig_sync(struct snd_dma_buffer *dmab, enum snd_dma_sync_mode mode) { if (mode == SNDRV_DMA_SYNC_CPU) { if (dmab->dev.dir == DMA_TO_DEVICE) return; invalidate_kernel_vmap_range(dmab->area, dmab->bytes); dma_sync_sgtable_for_cpu(dmab->dev.dev, dmab->private_data, dmab->dev.dir); } else { if (dmab->dev.dir == DMA_FROM_DEVICE) return; flush_kernel_vmap_range(dmab->area, dmab->bytes); dma_sync_sgtable_for_device(dmab->dev.dev, dmab->private_data, dmab->dev.dir); } } static inline void snd_dma_noncontig_iter_set(struct snd_dma_buffer *dmab, struct sg_page_iter *piter, size_t offset) { struct sg_table *sgt = dmab->private_data; __sg_page_iter_start(piter, sgt->sgl, sgt->orig_nents, offset >> PAGE_SHIFT); } static dma_addr_t snd_dma_noncontig_get_addr(struct snd_dma_buffer *dmab, size_t offset) { struct sg_dma_page_iter iter; snd_dma_noncontig_iter_set(dmab, &iter.base, offset); __sg_page_iter_dma_next(&iter); return sg_page_iter_dma_address(&iter) + offset % PAGE_SIZE; } static struct page *snd_dma_noncontig_get_page(struct snd_dma_buffer *dmab, size_t offset) { struct sg_page_iter iter; snd_dma_noncontig_iter_set(dmab, &iter, offset); __sg_page_iter_next(&iter); return sg_page_iter_page(&iter); } static unsigned int snd_dma_noncontig_get_chunk_size(struct snd_dma_buffer *dmab, unsigned int ofs, unsigned int size) { struct sg_dma_page_iter iter; unsigned int start, end; unsigned long addr; start = ALIGN_DOWN(ofs, PAGE_SIZE); end = ofs + size - 1; /* the last byte address */ snd_dma_noncontig_iter_set(dmab, &iter.base, start); if (!__sg_page_iter_dma_next(&iter)) return 0; /* check page continuity */ addr = sg_page_iter_dma_address(&iter); for (;;) { start += PAGE_SIZE; if (start > end) break; addr += PAGE_SIZE; if (!__sg_page_iter_dma_next(&iter) || sg_page_iter_dma_address(&iter) != addr) return start - ofs; } /* ok, all on continuous pages */ return size; } static const struct snd_malloc_ops snd_dma_noncontig_ops = { .alloc = snd_dma_noncontig_alloc, .free = snd_dma_noncontig_free, .mmap = snd_dma_noncontig_mmap, .sync = snd_dma_noncontig_sync, .get_addr = snd_dma_noncontig_get_addr, .get_page = snd_dma_noncontig_get_page, .get_chunk_size = snd_dma_noncontig_get_chunk_size, }; /* x86-specific SG-buffer with WC pages */ #ifdef CONFIG_SND_DMA_SGBUF #define sg_wc_address(it) ((unsigned long)page_address(sg_page_iter_page(it))) static void *snd_dma_sg_wc_alloc(struct snd_dma_buffer *dmab, size_t size) { void *p = snd_dma_noncontig_alloc(dmab, size); struct sg_table *sgt = dmab->private_data; struct sg_page_iter iter; if (!p) return NULL; if (dmab->dev.type != SNDRV_DMA_TYPE_DEV_WC_SG) return p; for_each_sgtable_page(sgt, &iter, 0) set_memory_wc(sg_wc_address(&iter), 1); return p; } static void snd_dma_sg_wc_free(struct snd_dma_buffer *dmab) { struct sg_table *sgt = dmab->private_data; struct sg_page_iter iter; for_each_sgtable_page(sgt, &iter, 0) set_memory_wb(sg_wc_address(&iter), 1); snd_dma_noncontig_free(dmab); } static int snd_dma_sg_wc_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); return dma_mmap_noncontiguous(dmab->dev.dev, area, dmab->bytes, dmab->private_data); } static const struct snd_malloc_ops snd_dma_sg_wc_ops = { .alloc = snd_dma_sg_wc_alloc, .free = snd_dma_sg_wc_free, .mmap = snd_dma_sg_wc_mmap, .sync = snd_dma_noncontig_sync, .get_addr = snd_dma_noncontig_get_addr, .get_page = snd_dma_noncontig_get_page, .get_chunk_size = snd_dma_noncontig_get_chunk_size, }; /* Fallback SG-buffer allocations for x86 */ struct snd_dma_sg_fallback { bool use_dma_alloc_coherent; size_t count; struct page **pages; /* DMA address array; the first page contains #pages in ~PAGE_MASK */ dma_addr_t *addrs; }; static void __snd_dma_sg_fallback_free(struct snd_dma_buffer *dmab, struct snd_dma_sg_fallback *sgbuf) { size_t i, size; if (sgbuf->pages && sgbuf->addrs) { i = 0; while (i < sgbuf->count) { if (!sgbuf->pages[i] || !sgbuf->addrs[i]) break; size = sgbuf->addrs[i] & ~PAGE_MASK; if (WARN_ON(!size)) break; if (sgbuf->use_dma_alloc_coherent) dma_free_coherent(dmab->dev.dev, size << PAGE_SHIFT, page_address(sgbuf->pages[i]), sgbuf->addrs[i] & PAGE_MASK); else do_free_pages(page_address(sgbuf->pages[i]), size << PAGE_SHIFT, false); i += size; } } kvfree(sgbuf->pages); kvfree(sgbuf->addrs); kfree(sgbuf); } static void *snd_dma_sg_fallback_alloc(struct snd_dma_buffer *dmab, size_t size) { struct snd_dma_sg_fallback *sgbuf; struct page **pagep, *curp; size_t chunk, npages; dma_addr_t *addrp; dma_addr_t addr; void *p; /* correct the type */ if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) dmab->dev.type = SNDRV_DMA_TYPE_DEV_SG_FALLBACK; else if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG) dmab->dev.type = SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK; sgbuf = kzalloc(sizeof(*sgbuf), GFP_KERNEL); if (!sgbuf) return NULL; sgbuf->use_dma_alloc_coherent = cpu_feature_enabled(X86_FEATURE_XENPV); size = PAGE_ALIGN(size); sgbuf->count = size >> PAGE_SHIFT; sgbuf->pages = kvcalloc(sgbuf->count, sizeof(*sgbuf->pages), GFP_KERNEL); sgbuf->addrs = kvcalloc(sgbuf->count, sizeof(*sgbuf->addrs), GFP_KERNEL); if (!sgbuf->pages || !sgbuf->addrs) goto error; pagep = sgbuf->pages; addrp = sgbuf->addrs; chunk = (PAGE_SIZE - 1) << PAGE_SHIFT; /* to fit in low bits in addrs */ while (size > 0) { chunk = min(size, chunk); if (sgbuf->use_dma_alloc_coherent) p = dma_alloc_coherent(dmab->dev.dev, chunk, &addr, DEFAULT_GFP); else p = do_alloc_pages(dmab->dev.dev, chunk, &addr, false); if (!p) { if (chunk <= PAGE_SIZE) goto error; chunk >>= 1; chunk = PAGE_SIZE << get_order(chunk); continue; } size -= chunk; /* fill pages */ npages = chunk >> PAGE_SHIFT; *addrp = npages; /* store in lower bits */ curp = virt_to_page(p); while (npages--) { *pagep++ = curp++; *addrp++ |= addr; addr += PAGE_SIZE; } } p = vmap(sgbuf->pages, sgbuf->count, VM_MAP, PAGE_KERNEL); if (!p) goto error; if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK) set_pages_array_wc(sgbuf->pages, sgbuf->count); dmab->private_data = sgbuf; /* store the first page address for convenience */ dmab->addr = sgbuf->addrs[0] & PAGE_MASK; return p; error: __snd_dma_sg_fallback_free(dmab, sgbuf); return NULL; } static void snd_dma_sg_fallback_free(struct snd_dma_buffer *dmab) { struct snd_dma_sg_fallback *sgbuf = dmab->private_data; if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK) set_pages_array_wb(sgbuf->pages, sgbuf->count); vunmap(dmab->area); __snd_dma_sg_fallback_free(dmab, dmab->private_data); } static dma_addr_t snd_dma_sg_fallback_get_addr(struct snd_dma_buffer *dmab, size_t offset) { struct snd_dma_sg_fallback *sgbuf = dmab->private_data; size_t index = offset >> PAGE_SHIFT; return (sgbuf->addrs[index] & PAGE_MASK) | (offset & ~PAGE_MASK); } static int snd_dma_sg_fallback_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { struct snd_dma_sg_fallback *sgbuf = dmab->private_data; if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK) area->vm_page_prot = pgprot_writecombine(area->vm_page_prot); return vm_map_pages(area, sgbuf->pages, sgbuf->count); } static const struct snd_malloc_ops snd_dma_sg_fallback_ops = { .alloc = snd_dma_sg_fallback_alloc, .free = snd_dma_sg_fallback_free, .mmap = snd_dma_sg_fallback_mmap, .get_addr = snd_dma_sg_fallback_get_addr, /* reuse vmalloc helpers */ .get_page = snd_dma_vmalloc_get_page, .get_chunk_size = snd_dma_vmalloc_get_chunk_size, }; #endif /* CONFIG_SND_DMA_SGBUF */ /* * Non-coherent pages allocator */ static void *snd_dma_noncoherent_alloc(struct snd_dma_buffer *dmab, size_t size) { void *p; p = dma_alloc_noncoherent(dmab->dev.dev, size, &dmab->addr, dmab->dev.dir, DEFAULT_GFP); if (p) dmab->dev.need_sync = dma_need_sync(dmab->dev.dev, dmab->addr); return p; } static void snd_dma_noncoherent_free(struct snd_dma_buffer *dmab) { dma_free_noncoherent(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr, dmab->dev.dir); } static int snd_dma_noncoherent_mmap(struct snd_dma_buffer *dmab, struct vm_area_struct *area) { area->vm_page_prot = vm_get_page_prot(area->vm_flags); return dma_mmap_pages(dmab->dev.dev, area, area->vm_end - area->vm_start, virt_to_page(dmab->area)); } static void snd_dma_noncoherent_sync(struct snd_dma_buffer *dmab, enum snd_dma_sync_mode mode) { if (mode == SNDRV_DMA_SYNC_CPU) { if (dmab->dev.dir != DMA_TO_DEVICE) dma_sync_single_for_cpu(dmab->dev.dev, dmab->addr, dmab->bytes, dmab->dev.dir); } else { if (dmab->dev.dir != DMA_FROM_DEVICE) dma_sync_single_for_device(dmab->dev.dev, dmab->addr, dmab->bytes, dmab->dev.dir); } } static const struct snd_malloc_ops snd_dma_noncoherent_ops = { .alloc = snd_dma_noncoherent_alloc, .free = snd_dma_noncoherent_free, .mmap = snd_dma_noncoherent_mmap, .sync = snd_dma_noncoherent_sync, }; #endif /* CONFIG_HAS_DMA */ /* * Entry points */ static const struct snd_malloc_ops *snd_dma_ops[] = { [SNDRV_DMA_TYPE_CONTINUOUS] = &snd_dma_continuous_ops, [SNDRV_DMA_TYPE_VMALLOC] = &snd_dma_vmalloc_ops, #ifdef CONFIG_HAS_DMA [SNDRV_DMA_TYPE_DEV] = &snd_dma_dev_ops, [SNDRV_DMA_TYPE_DEV_WC] = &snd_dma_wc_ops, [SNDRV_DMA_TYPE_NONCONTIG] = &snd_dma_noncontig_ops, [SNDRV_DMA_TYPE_NONCOHERENT] = &snd_dma_noncoherent_ops, #ifdef CONFIG_SND_DMA_SGBUF [SNDRV_DMA_TYPE_DEV_WC_SG] = &snd_dma_sg_wc_ops, #endif #ifdef CONFIG_GENERIC_ALLOCATOR [SNDRV_DMA_TYPE_DEV_IRAM] = &snd_dma_iram_ops, #endif /* CONFIG_GENERIC_ALLOCATOR */ #ifdef CONFIG_SND_DMA_SGBUF [SNDRV_DMA_TYPE_DEV_SG_FALLBACK] = &snd_dma_sg_fallback_ops, [SNDRV_DMA_TYPE_DEV_WC_SG_FALLBACK] = &snd_dma_sg_fallback_ops, #endif #endif /* CONFIG_HAS_DMA */ }; static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab) { if (WARN_ON_ONCE(!dmab)) return NULL; if (WARN_ON_ONCE(dmab->dev.type <= SNDRV_DMA_TYPE_UNKNOWN || dmab->dev.type >= ARRAY_SIZE(snd_dma_ops))) return NULL; return snd_dma_ops[dmab->dev.type]; }
linux-master
sound/core/memalloc.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Digital Audio (PCM) abstract layer * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/compat.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/file.h> #include <linux/slab.h> #include <linux/sched/signal.h> #include <linux/time.h> #include <linux/pm_qos.h> #include <linux/io.h> #include <linux/dma-mapping.h> #include <linux/vmalloc.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/timer.h> #include <sound/minors.h> #include <linux/uio.h> #include <linux/delay.h> #include "pcm_local.h" #ifdef CONFIG_SND_DEBUG #define CREATE_TRACE_POINTS #include "pcm_param_trace.h" #else #define trace_hw_mask_param_enabled() 0 #define trace_hw_interval_param_enabled() 0 #define trace_hw_mask_param(substream, type, index, prev, curr) #define trace_hw_interval_param(substream, type, index, prev, curr) #endif /* * Compatibility */ struct snd_pcm_hw_params_old { unsigned int flags; unsigned int masks[SNDRV_PCM_HW_PARAM_SUBFORMAT - SNDRV_PCM_HW_PARAM_ACCESS + 1]; struct snd_interval intervals[SNDRV_PCM_HW_PARAM_TICK_TIME - SNDRV_PCM_HW_PARAM_SAMPLE_BITS + 1]; unsigned int rmask; unsigned int cmask; unsigned int info; unsigned int msbits; unsigned int rate_num; unsigned int rate_den; snd_pcm_uframes_t fifo_size; unsigned char reserved[64]; }; #ifdef CONFIG_SND_SUPPORT_OLD_API #define SNDRV_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct snd_pcm_hw_params_old) #define SNDRV_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct snd_pcm_hw_params_old) static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams); static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams); #endif static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream); /* * */ static DECLARE_RWSEM(snd_pcm_link_rwsem); void snd_pcm_group_init(struct snd_pcm_group *group) { spin_lock_init(&group->lock); mutex_init(&group->mutex); INIT_LIST_HEAD(&group->substreams); refcount_set(&group->refs, 1); } /* define group lock helpers */ #define DEFINE_PCM_GROUP_LOCK(action, mutex_action) \ static void snd_pcm_group_ ## action(struct snd_pcm_group *group, bool nonatomic) \ { \ if (nonatomic) \ mutex_ ## mutex_action(&group->mutex); \ else \ spin_ ## action(&group->lock); \ } DEFINE_PCM_GROUP_LOCK(lock, lock); DEFINE_PCM_GROUP_LOCK(unlock, unlock); DEFINE_PCM_GROUP_LOCK(lock_irq, lock); DEFINE_PCM_GROUP_LOCK(unlock_irq, unlock); /** * snd_pcm_stream_lock - Lock the PCM stream * @substream: PCM substream * * This locks the PCM stream's spinlock or mutex depending on the nonatomic * flag of the given substream. This also takes the global link rw lock * (or rw sem), too, for avoiding the race with linked streams. */ void snd_pcm_stream_lock(struct snd_pcm_substream *substream) { snd_pcm_group_lock(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_lock); /** * snd_pcm_stream_unlock - Unlock the PCM stream * @substream: PCM substream * * This unlocks the PCM stream that has been locked via snd_pcm_stream_lock(). */ void snd_pcm_stream_unlock(struct snd_pcm_substream *substream) { snd_pcm_group_unlock(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock); /** * snd_pcm_stream_lock_irq - Lock the PCM stream * @substream: PCM substream * * This locks the PCM stream like snd_pcm_stream_lock() and disables the local * IRQ (only when nonatomic is false). In nonatomic case, this is identical * as snd_pcm_stream_lock(). */ void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream) { snd_pcm_group_lock_irq(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq); static void snd_pcm_stream_lock_nested(struct snd_pcm_substream *substream) { struct snd_pcm_group *group = &substream->self_group; if (substream->pcm->nonatomic) mutex_lock_nested(&group->mutex, SINGLE_DEPTH_NESTING); else spin_lock_nested(&group->lock, SINGLE_DEPTH_NESTING); } /** * snd_pcm_stream_unlock_irq - Unlock the PCM stream * @substream: PCM substream * * This is a counter-part of snd_pcm_stream_lock_irq(). */ void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream) { snd_pcm_group_unlock_irq(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq); unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream) { unsigned long flags = 0; if (substream->pcm->nonatomic) mutex_lock(&substream->self_group.mutex); else spin_lock_irqsave(&substream->self_group.lock, flags); return flags; } EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave); unsigned long _snd_pcm_stream_lock_irqsave_nested(struct snd_pcm_substream *substream) { unsigned long flags = 0; if (substream->pcm->nonatomic) mutex_lock_nested(&substream->self_group.mutex, SINGLE_DEPTH_NESTING); else spin_lock_irqsave_nested(&substream->self_group.lock, flags, SINGLE_DEPTH_NESTING); return flags; } EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave_nested); /** * snd_pcm_stream_unlock_irqrestore - Unlock the PCM stream * @substream: PCM substream * @flags: irq flags * * This is a counter-part of snd_pcm_stream_lock_irqsave(). */ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream, unsigned long flags) { if (substream->pcm->nonatomic) mutex_unlock(&substream->self_group.mutex); else spin_unlock_irqrestore(&substream->self_group.lock, flags); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore); /* Run PCM ioctl ops */ static int snd_pcm_ops_ioctl(struct snd_pcm_substream *substream, unsigned cmd, void *arg) { if (substream->ops->ioctl) return substream->ops->ioctl(substream, cmd, arg); else return snd_pcm_lib_ioctl(substream, cmd, arg); } int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) { struct snd_pcm *pcm = substream->pcm; struct snd_pcm_str *pstr = substream->pstr; memset(info, 0, sizeof(*info)); info->card = pcm->card->number; info->device = pcm->device; info->stream = substream->stream; info->subdevice = substream->number; strscpy(info->id, pcm->id, sizeof(info->id)); strscpy(info->name, pcm->name, sizeof(info->name)); info->dev_class = pcm->dev_class; info->dev_subclass = pcm->dev_subclass; info->subdevices_count = pstr->substream_count; info->subdevices_avail = pstr->substream_count - pstr->substream_opened; strscpy(info->subname, substream->name, sizeof(info->subname)); return 0; } int snd_pcm_info_user(struct snd_pcm_substream *substream, struct snd_pcm_info __user * _info) { struct snd_pcm_info *info; int err; info = kmalloc(sizeof(*info), GFP_KERNEL); if (! info) return -ENOMEM; err = snd_pcm_info(substream, info); if (err >= 0) { if (copy_to_user(_info, info, sizeof(*info))) err = -EFAULT; } kfree(info); return err; } /* macro for simplified cast */ #define PARAM_MASK_BIT(b) (1U << (__force int)(b)) static bool hw_support_mmap(struct snd_pcm_substream *substream) { struct snd_dma_buffer *dmabuf; if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP)) return false; if (substream->ops->mmap || substream->ops->page) return true; dmabuf = snd_pcm_get_dma_buf(substream); if (!dmabuf) dmabuf = &substream->dma_buffer; switch (dmabuf->dev.type) { case SNDRV_DMA_TYPE_UNKNOWN: /* we can't know the device, so just assume that the driver does * everything right */ return true; case SNDRV_DMA_TYPE_CONTINUOUS: case SNDRV_DMA_TYPE_VMALLOC: return true; default: return dma_can_mmap(dmabuf->dev.dev); } } static int constrain_mask_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; struct snd_mask *m; unsigned int k; struct snd_mask old_mask __maybe_unused; int changed; for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { m = hw_param_mask(params, k); if (snd_mask_empty(m)) return -EINVAL; /* This parameter is not requested to change by a caller. */ if (!(params->rmask & PARAM_MASK_BIT(k))) continue; if (trace_hw_mask_param_enabled()) old_mask = *m; changed = snd_mask_refine(m, constrs_mask(constrs, k)); if (changed < 0) return changed; if (changed == 0) continue; /* Set corresponding flag so that the caller gets it. */ trace_hw_mask_param(substream, k, 0, &old_mask, m); params->cmask |= PARAM_MASK_BIT(k); } return 0; } static int constrain_interval_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; struct snd_interval *i; unsigned int k; struct snd_interval old_interval __maybe_unused; int changed; for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { i = hw_param_interval(params, k); if (snd_interval_empty(i)) return -EINVAL; /* This parameter is not requested to change by a caller. */ if (!(params->rmask & PARAM_MASK_BIT(k))) continue; if (trace_hw_interval_param_enabled()) old_interval = *i; changed = snd_interval_refine(i, constrs_interval(constrs, k)); if (changed < 0) return changed; if (changed == 0) continue; /* Set corresponding flag so that the caller gets it. */ trace_hw_interval_param(substream, k, 0, &old_interval, i); params->cmask |= PARAM_MASK_BIT(k); } return 0; } static int constrain_params_by_rules(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; unsigned int k; unsigned int *rstamps; unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1]; unsigned int stamp; struct snd_pcm_hw_rule *r; unsigned int d; struct snd_mask old_mask __maybe_unused; struct snd_interval old_interval __maybe_unused; bool again; int changed, err = 0; /* * Each application of rule has own sequence number. * * Each member of 'rstamps' array represents the sequence number of * recent application of corresponding rule. */ rstamps = kcalloc(constrs->rules_num, sizeof(unsigned int), GFP_KERNEL); if (!rstamps) return -ENOMEM; /* * Each member of 'vstamps' array represents the sequence number of * recent application of rule in which corresponding parameters were * changed. * * In initial state, elements corresponding to parameters requested by * a caller is 1. For unrequested parameters, corresponding members * have 0 so that the parameters are never changed anymore. */ for (k = 0; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) vstamps[k] = (params->rmask & PARAM_MASK_BIT(k)) ? 1 : 0; /* Due to the above design, actual sequence number starts at 2. */ stamp = 2; retry: /* Apply all rules in order. */ again = false; for (k = 0; k < constrs->rules_num; k++) { r = &constrs->rules[k]; /* * Check condition bits of this rule. When the rule has * some condition bits, parameter without the bits is * never processed. SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP * is an example of the condition bits. */ if (r->cond && !(r->cond & params->flags)) continue; /* * The 'deps' array includes maximum four dependencies * to SNDRV_PCM_HW_PARAM_XXXs for this rule. The fifth * member of this array is a sentinel and should be * negative value. * * This rule should be processed in this time when dependent * parameters were changed at former applications of the other * rules. */ for (d = 0; r->deps[d] >= 0; d++) { if (vstamps[r->deps[d]] > rstamps[k]) break; } if (r->deps[d] < 0) continue; if (trace_hw_mask_param_enabled()) { if (hw_is_mask(r->var)) old_mask = *hw_param_mask(params, r->var); } if (trace_hw_interval_param_enabled()) { if (hw_is_interval(r->var)) old_interval = *hw_param_interval(params, r->var); } changed = r->func(params, r); if (changed < 0) { err = changed; goto out; } /* * When the parameter is changed, notify it to the caller * by corresponding returned bit, then preparing for next * iteration. */ if (changed && r->var >= 0) { if (hw_is_mask(r->var)) { trace_hw_mask_param(substream, r->var, k + 1, &old_mask, hw_param_mask(params, r->var)); } if (hw_is_interval(r->var)) { trace_hw_interval_param(substream, r->var, k + 1, &old_interval, hw_param_interval(params, r->var)); } params->cmask |= PARAM_MASK_BIT(r->var); vstamps[r->var] = stamp; again = true; } rstamps[k] = stamp++; } /* Iterate to evaluate all rules till no parameters are changed. */ if (again) goto retry; out: kfree(rstamps); return err; } static int fixup_unreferenced_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { const struct snd_interval *i; const struct snd_mask *m; int err; if (!params->msbits) { i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); if (snd_interval_single(i)) params->msbits = snd_interval_value(i); } if (!params->rate_den) { i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); if (snd_interval_single(i)) { params->rate_num = snd_interval_value(i); params->rate_den = 1; } } if (!params->fifo_size) { m = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); if (snd_mask_single(m) && snd_interval_single(i)) { err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_FIFO_SIZE, params); if (err < 0) return err; } } if (!params->info) { params->info = substream->runtime->hw.info; params->info &= ~(SNDRV_PCM_INFO_FIFO_IN_FRAMES | SNDRV_PCM_INFO_DRAIN_TRIGGER); if (!hw_support_mmap(substream)) params->info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID); } return 0; } int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { int err; params->info = 0; params->fifo_size = 0; if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_SAMPLE_BITS)) params->msbits = 0; if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_RATE)) { params->rate_num = 0; params->rate_den = 0; } err = constrain_mask_params(substream, params); if (err < 0) return err; err = constrain_interval_params(substream, params); if (err < 0) return err; err = constrain_params_by_rules(substream, params); if (err < 0) return err; params->rmask = 0; return 0; } EXPORT_SYMBOL(snd_pcm_hw_refine); static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params __user * _params) { struct snd_pcm_hw_params *params; int err; params = memdup_user(_params, sizeof(*params)); if (IS_ERR(params)) return PTR_ERR(params); err = snd_pcm_hw_refine(substream, params); if (err < 0) goto end; err = fixup_unreferenced_params(substream, params); if (err < 0) goto end; if (copy_to_user(_params, params, sizeof(*params))) err = -EFAULT; end: kfree(params); return err; } static int period_to_usecs(struct snd_pcm_runtime *runtime) { int usecs; if (! runtime->rate) return -1; /* invalid */ /* take 75% of period time as the deadline */ usecs = (750000 / runtime->rate) * runtime->period_size; usecs += ((750000 % runtime->rate) * runtime->period_size) / runtime->rate; return usecs; } static void snd_pcm_set_state(struct snd_pcm_substream *substream, snd_pcm_state_t state) { snd_pcm_stream_lock_irq(substream); if (substream->runtime->state != SNDRV_PCM_STATE_DISCONNECTED) __snd_pcm_set_state(substream->runtime, state); snd_pcm_stream_unlock_irq(substream); } static inline void snd_pcm_timer_notify(struct snd_pcm_substream *substream, int event) { #ifdef CONFIG_SND_PCM_TIMER if (substream->timer) snd_timer_notify(substream->timer, event, &substream->runtime->trigger_tstamp); #endif } void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq) { if (substream->runtime && substream->runtime->stop_operating) { substream->runtime->stop_operating = false; if (substream->ops && substream->ops->sync_stop) substream->ops->sync_stop(substream); else if (sync_irq && substream->pcm->card->sync_irq > 0) synchronize_irq(substream->pcm->card->sync_irq); } } /** * snd_pcm_hw_params_choose - choose a configuration defined by @params * @pcm: PCM instance * @params: the hw_params instance * * Choose one configuration from configuration space defined by @params. * The configuration chosen is that obtained fixing in this order: * first access, first format, first subformat, min channels, * min rate, min period time, max buffer size, min tick time * * Return: Zero if successful, or a negative error code on failure. */ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params) { static const int vars[] = { SNDRV_PCM_HW_PARAM_ACCESS, SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT, SNDRV_PCM_HW_PARAM_CHANNELS, SNDRV_PCM_HW_PARAM_RATE, SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_TICK_TIME, -1 }; const int *v; struct snd_mask old_mask __maybe_unused; struct snd_interval old_interval __maybe_unused; int changed; for (v = vars; *v != -1; v++) { /* Keep old parameter to trace. */ if (trace_hw_mask_param_enabled()) { if (hw_is_mask(*v)) old_mask = *hw_param_mask(params, *v); } if (trace_hw_interval_param_enabled()) { if (hw_is_interval(*v)) old_interval = *hw_param_interval(params, *v); } if (*v != SNDRV_PCM_HW_PARAM_BUFFER_SIZE) changed = snd_pcm_hw_param_first(pcm, params, *v, NULL); else changed = snd_pcm_hw_param_last(pcm, params, *v, NULL); if (changed < 0) return changed; if (changed == 0) continue; /* Trace the changed parameter. */ if (hw_is_mask(*v)) { trace_hw_mask_param(pcm, *v, 0, &old_mask, hw_param_mask(params, *v)); } if (hw_is_interval(*v)) { trace_hw_interval_param(pcm, *v, 0, &old_interval, hw_param_interval(params, *v)); } } return 0; } /* acquire buffer_mutex; if it's in r/w operation, return -EBUSY, otherwise * block the further r/w operations */ static int snd_pcm_buffer_access_lock(struct snd_pcm_runtime *runtime) { if (!atomic_dec_unless_positive(&runtime->buffer_accessing)) return -EBUSY; mutex_lock(&runtime->buffer_mutex); return 0; /* keep buffer_mutex, unlocked by below */ } /* release buffer_mutex and clear r/w access flag */ static void snd_pcm_buffer_access_unlock(struct snd_pcm_runtime *runtime) { mutex_unlock(&runtime->buffer_mutex); atomic_inc(&runtime->buffer_accessing); } #if IS_ENABLED(CONFIG_SND_PCM_OSS) #define is_oss_stream(substream) ((substream)->oss.oss) #else #define is_oss_stream(substream) false #endif static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; int err, usecs; unsigned int bits; snd_pcm_uframes_t frames; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; err = snd_pcm_buffer_access_lock(runtime); if (err < 0) return err; snd_pcm_stream_lock_irq(substream); switch (runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: if (!is_oss_stream(substream) && atomic_read(&substream->mmap_count)) err = -EBADFD; break; default: err = -EBADFD; break; } snd_pcm_stream_unlock_irq(substream); if (err) goto unlock; snd_pcm_sync_stop(substream, true); params->rmask = ~0U; err = snd_pcm_hw_refine(substream, params); if (err < 0) goto _error; err = snd_pcm_hw_params_choose(substream, params); if (err < 0) goto _error; err = fixup_unreferenced_params(substream, params); if (err < 0) goto _error; if (substream->managed_buffer_alloc) { err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); if (err < 0) goto _error; runtime->buffer_changed = err > 0; } if (substream->ops->hw_params != NULL) { err = substream->ops->hw_params(substream, params); if (err < 0) goto _error; } runtime->access = params_access(params); runtime->format = params_format(params); runtime->subformat = params_subformat(params); runtime->channels = params_channels(params); runtime->rate = params_rate(params); runtime->period_size = params_period_size(params); runtime->periods = params_periods(params); runtime->buffer_size = params_buffer_size(params); runtime->info = params->info; runtime->rate_num = params->rate_num; runtime->rate_den = params->rate_den; runtime->no_period_wakeup = (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); bits = snd_pcm_format_physical_width(runtime->format); runtime->sample_bits = bits; bits *= runtime->channels; runtime->frame_bits = bits; frames = 1; while (bits % 8 != 0) { bits *= 2; frames *= 2; } runtime->byte_align = bits / 8; runtime->min_align = frames; /* Default sw params */ runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; runtime->period_step = 1; runtime->control->avail_min = runtime->period_size; runtime->start_threshold = 1; runtime->stop_threshold = runtime->buffer_size; runtime->silence_threshold = 0; runtime->silence_size = 0; runtime->boundary = runtime->buffer_size; while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) runtime->boundary *= 2; /* clear the buffer for avoiding possible kernel info leaks */ if (runtime->dma_area && !substream->ops->copy) { size_t size = runtime->dma_bytes; if (runtime->info & SNDRV_PCM_INFO_MMAP) size = PAGE_ALIGN(size); memset(runtime->dma_area, 0, size); } snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); usecs = period_to_usecs(runtime); if (usecs >= 0) cpu_latency_qos_add_request(&substream->latency_pm_qos_req, usecs); err = 0; _error: if (err) { /* hardware might be unusable from this time, * so we force application to retry to set * the correct hardware parameter settings */ snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); if (substream->ops->hw_free != NULL) substream->ops->hw_free(substream); if (substream->managed_buffer_alloc) snd_pcm_lib_free_pages(substream); } unlock: snd_pcm_buffer_access_unlock(runtime); return err; } static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params __user * _params) { struct snd_pcm_hw_params *params; int err; params = memdup_user(_params, sizeof(*params)); if (IS_ERR(params)) return PTR_ERR(params); err = snd_pcm_hw_params(substream, params); if (err < 0) goto end; if (copy_to_user(_params, params, sizeof(*params))) err = -EFAULT; end: kfree(params); return err; } static int do_hw_free(struct snd_pcm_substream *substream) { int result = 0; snd_pcm_sync_stop(substream, true); if (substream->ops->hw_free) result = substream->ops->hw_free(substream); if (substream->managed_buffer_alloc) snd_pcm_lib_free_pages(substream); return result; } static int snd_pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; int result = 0; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; result = snd_pcm_buffer_access_lock(runtime); if (result < 0) return result; snd_pcm_stream_lock_irq(substream); switch (runtime->state) { case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: if (atomic_read(&substream->mmap_count)) result = -EBADFD; break; default: result = -EBADFD; break; } snd_pcm_stream_unlock_irq(substream); if (result) goto unlock; result = do_hw_free(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); unlock: snd_pcm_buffer_access_unlock(runtime); return result; } static int snd_pcm_sw_params(struct snd_pcm_substream *substream, struct snd_pcm_sw_params *params) { struct snd_pcm_runtime *runtime; int err; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); if (runtime->state == SNDRV_PCM_STATE_OPEN) { snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); if (params->tstamp_mode < 0 || params->tstamp_mode > SNDRV_PCM_TSTAMP_LAST) return -EINVAL; if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12) && params->tstamp_type > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; if (params->avail_min == 0) return -EINVAL; if (params->silence_size >= runtime->boundary) { if (params->silence_threshold != 0) return -EINVAL; } else { if (params->silence_size > params->silence_threshold) return -EINVAL; if (params->silence_threshold > runtime->buffer_size) return -EINVAL; } err = 0; snd_pcm_stream_lock_irq(substream); runtime->tstamp_mode = params->tstamp_mode; if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12)) runtime->tstamp_type = params->tstamp_type; runtime->period_step = params->period_step; runtime->control->avail_min = params->avail_min; runtime->start_threshold = params->start_threshold; runtime->stop_threshold = params->stop_threshold; runtime->silence_threshold = params->silence_threshold; runtime->silence_size = params->silence_size; params->boundary = runtime->boundary; if (snd_pcm_running(substream)) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); err = snd_pcm_update_state(substream, runtime); } snd_pcm_stream_unlock_irq(substream); return err; } static int snd_pcm_sw_params_user(struct snd_pcm_substream *substream, struct snd_pcm_sw_params __user * _params) { struct snd_pcm_sw_params params; int err; if (copy_from_user(&params, _params, sizeof(params))) return -EFAULT; err = snd_pcm_sw_params(substream, &params); if (copy_to_user(_params, &params, sizeof(params))) return -EFAULT; return err; } static inline snd_pcm_uframes_t snd_pcm_calc_delay(struct snd_pcm_substream *substream) { snd_pcm_uframes_t delay; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) delay = snd_pcm_playback_hw_avail(substream->runtime); else delay = snd_pcm_capture_avail(substream->runtime); return delay + substream->runtime->delay; } int snd_pcm_status64(struct snd_pcm_substream *substream, struct snd_pcm_status64 *status) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); snd_pcm_unpack_audio_tstamp_config(status->audio_tstamp_data, &runtime->audio_tstamp_config); /* backwards compatible behavior */ if (runtime->audio_tstamp_config.type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT) { if (runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK) runtime->audio_tstamp_config.type_requested = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; else runtime->audio_tstamp_config.type_requested = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; runtime->audio_tstamp_report.valid = 0; } else runtime->audio_tstamp_report.valid = 1; status->state = runtime->state; status->suspended_state = runtime->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp_sec = runtime->status->tstamp.tv_sec; status->tstamp_nsec = runtime->status->tstamp.tv_nsec; status->driver_tstamp_sec = runtime->driver_tstamp.tv_sec; status->driver_tstamp_nsec = runtime->driver_tstamp.tv_nsec; status->audio_tstamp_sec = runtime->status->audio_tstamp.tv_sec; status->audio_tstamp_nsec = runtime->status->audio_tstamp.tv_nsec; if (runtime->audio_tstamp_report.valid == 1) /* backwards compatibility, no report provided in COMPAT mode */ snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data, &status->audio_tstamp_accuracy, &runtime->audio_tstamp_report); goto _tstamp_end; } } else { /* get tstamp only in fallback mode and only if enabled */ if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); status->tstamp_sec = tstamp.tv_sec; status->tstamp_nsec = tstamp.tv_nsec; } } _tstamp_end: status->appl_ptr = runtime->control->appl_ptr; status->hw_ptr = runtime->status->hw_ptr; status->avail = snd_pcm_avail(substream); status->delay = snd_pcm_running(substream) ? snd_pcm_calc_delay(substream) : 0; status->avail_max = runtime->avail_max; status->overrange = runtime->overrange; runtime->avail_max = 0; runtime->overrange = 0; _end: snd_pcm_stream_unlock_irq(substream); return 0; } static int snd_pcm_status_user64(struct snd_pcm_substream *substream, struct snd_pcm_status64 __user * _status, bool ext) { struct snd_pcm_status64 status; int res; memset(&status, 0, sizeof(status)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, * ignore rest of status structure */ if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&_status->audio_tstamp_data))) return -EFAULT; res = snd_pcm_status64(substream, &status); if (res < 0) return res; if (copy_to_user(_status, &status, sizeof(status))) return -EFAULT; return 0; } static int snd_pcm_status_user32(struct snd_pcm_substream *substream, struct snd_pcm_status32 __user * _status, bool ext) { struct snd_pcm_status64 status64; struct snd_pcm_status32 status32; int res; memset(&status64, 0, sizeof(status64)); memset(&status32, 0, sizeof(status32)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, * ignore rest of status structure */ if (ext && get_user(status64.audio_tstamp_data, (u32 __user *)(&_status->audio_tstamp_data))) return -EFAULT; res = snd_pcm_status64(substream, &status64); if (res < 0) return res; status32 = (struct snd_pcm_status32) { .state = status64.state, .trigger_tstamp_sec = status64.trigger_tstamp_sec, .trigger_tstamp_nsec = status64.trigger_tstamp_nsec, .tstamp_sec = status64.tstamp_sec, .tstamp_nsec = status64.tstamp_nsec, .appl_ptr = status64.appl_ptr, .hw_ptr = status64.hw_ptr, .delay = status64.delay, .avail = status64.avail, .avail_max = status64.avail_max, .overrange = status64.overrange, .suspended_state = status64.suspended_state, .audio_tstamp_data = status64.audio_tstamp_data, .audio_tstamp_sec = status64.audio_tstamp_sec, .audio_tstamp_nsec = status64.audio_tstamp_nsec, .driver_tstamp_sec = status64.audio_tstamp_sec, .driver_tstamp_nsec = status64.audio_tstamp_nsec, .audio_tstamp_accuracy = status64.audio_tstamp_accuracy, }; if (copy_to_user(_status, &status32, sizeof(status32))) return -EFAULT; return 0; } static int snd_pcm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info * info) { struct snd_pcm_runtime *runtime; unsigned int channel; channel = info->channel; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); if (runtime->state == SNDRV_PCM_STATE_OPEN) { snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); if (channel >= runtime->channels) return -EINVAL; memset(info, 0, sizeof(*info)); info->channel = channel; return snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_CHANNEL_INFO, info); } static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, struct snd_pcm_channel_info __user * _info) { struct snd_pcm_channel_info info; int res; if (copy_from_user(&info, _info, sizeof(info))) return -EFAULT; res = snd_pcm_channel_info(substream, &info); if (res < 0) return res; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return 0; } static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master == NULL) return; if (runtime->trigger_master == substream) { if (!runtime->trigger_tstamp_latched) snd_pcm_gettime(runtime, &runtime->trigger_tstamp); } else { snd_pcm_trigger_tstamp(runtime->trigger_master); runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp; } runtime->trigger_master = NULL; } #define ACTION_ARG_IGNORE (__force snd_pcm_state_t)0 struct action_ops { int (*pre_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); int (*do_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); void (*undo_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); void (*post_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); }; /* * this functions is core for handling of linked stream * Note: the stream state might be changed also on failure * Note2: call with calling stream lock + link lock */ static int snd_pcm_action_group(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state, bool stream_lock) { struct snd_pcm_substream *s = NULL; struct snd_pcm_substream *s1; int res = 0, depth = 1; snd_pcm_group_for_each_entry(s, substream) { if (s != substream) { if (!stream_lock) mutex_lock_nested(&s->runtime->buffer_mutex, depth); else if (s->pcm->nonatomic) mutex_lock_nested(&s->self_group.mutex, depth); else spin_lock_nested(&s->self_group.lock, depth); depth++; } res = ops->pre_action(s, state); if (res < 0) goto _unlock; } snd_pcm_group_for_each_entry(s, substream) { res = ops->do_action(s, state); if (res < 0) { if (ops->undo_action) { snd_pcm_group_for_each_entry(s1, substream) { if (s1 == s) /* failed stream */ break; ops->undo_action(s1, state); } } s = NULL; /* unlock all */ goto _unlock; } } snd_pcm_group_for_each_entry(s, substream) { ops->post_action(s, state); } _unlock: /* unlock streams */ snd_pcm_group_for_each_entry(s1, substream) { if (s1 != substream) { if (!stream_lock) mutex_unlock(&s1->runtime->buffer_mutex); else if (s1->pcm->nonatomic) mutex_unlock(&s1->self_group.mutex); else spin_unlock(&s1->self_group.lock); } if (s1 == s) /* end */ break; } return res; } /* * Note: call with stream lock */ static int snd_pcm_action_single(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; res = ops->pre_action(substream, state); if (res < 0) return res; res = ops->do_action(substream, state); if (res == 0) ops->post_action(substream, state); else if (ops->undo_action) ops->undo_action(substream, state); return res; } static void snd_pcm_group_assign(struct snd_pcm_substream *substream, struct snd_pcm_group *new_group) { substream->group = new_group; list_move(&substream->link_list, &new_group->substreams); } /* * Unref and unlock the group, but keep the stream lock; * when the group becomes empty and no longer referred, destroy itself */ static void snd_pcm_group_unref(struct snd_pcm_group *group, struct snd_pcm_substream *substream) { bool do_free; if (!group) return; do_free = refcount_dec_and_test(&group->refs); snd_pcm_group_unlock(group, substream->pcm->nonatomic); if (do_free) kfree(group); } /* * Lock the group inside a stream lock and reference it; * return the locked group object, or NULL if not linked */ static struct snd_pcm_group * snd_pcm_stream_group_ref(struct snd_pcm_substream *substream) { bool nonatomic = substream->pcm->nonatomic; struct snd_pcm_group *group; bool trylock; for (;;) { if (!snd_pcm_stream_linked(substream)) return NULL; group = substream->group; /* block freeing the group object */ refcount_inc(&group->refs); trylock = nonatomic ? mutex_trylock(&group->mutex) : spin_trylock(&group->lock); if (trylock) break; /* OK */ /* re-lock for avoiding ABBA deadlock */ snd_pcm_stream_unlock(substream); snd_pcm_group_lock(group, nonatomic); snd_pcm_stream_lock(substream); /* check the group again; the above opens a small race window */ if (substream->group == group) break; /* OK */ /* group changed, try again */ snd_pcm_group_unref(group, substream); } return group; } /* * Note: call with stream lock */ static int snd_pcm_action(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_group *group; int res; group = snd_pcm_stream_group_ref(substream); if (group) res = snd_pcm_action_group(ops, substream, state, true); else res = snd_pcm_action_single(ops, substream, state); snd_pcm_group_unref(group, substream); return res; } /* * Note: don't use any locks before */ static int snd_pcm_action_lock_irq(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; snd_pcm_stream_lock_irq(substream); res = snd_pcm_action(ops, substream, state); snd_pcm_stream_unlock_irq(substream); return res; } /* */ static int snd_pcm_action_nonatomic(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; /* Guarantee the group members won't change during non-atomic action */ down_read(&snd_pcm_link_rwsem); res = snd_pcm_buffer_access_lock(substream->runtime); if (res < 0) goto unlock; if (snd_pcm_stream_linked(substream)) res = snd_pcm_action_group(ops, substream, state, false); else res = snd_pcm_action_single(ops, substream, state); snd_pcm_buffer_access_unlock(substream->runtime); unlock: up_read(&snd_pcm_link_rwsem); return res; } /* * start callbacks */ static int snd_pcm_pre_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->state != SNDRV_PCM_STATE_PREPARED) return -EBADFD; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data(substream)) return -EPIPE; runtime->trigger_tstamp_latched = false; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { int err; if (substream->runtime->trigger_master != substream) return 0; err = substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); /* XRUN happened during the start */ if (err == -EPIPE) __snd_pcm_set_state(substream->runtime, SNDRV_PCM_STATE_XRUN); return err; } static void snd_pcm_undo_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); substream->runtime->stop_operating = true; } } static void snd_pcm_post_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); runtime->hw_ptr_jiffies = jiffies; runtime->hw_ptr_buffer_jiffies = (runtime->buffer_size * HZ) / runtime->rate; __snd_pcm_set_state(runtime, state); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTART); } static const struct action_ops snd_pcm_action_start = { .pre_action = snd_pcm_pre_start, .do_action = snd_pcm_do_start, .undo_action = snd_pcm_undo_start, .post_action = snd_pcm_post_start }; /** * snd_pcm_start - start all linked streams * @substream: the PCM substream instance * * Return: Zero if successful, or a negative error code. * The stream lock must be acquired before calling this function. */ int snd_pcm_start(struct snd_pcm_substream *substream) { return snd_pcm_action(&snd_pcm_action_start, substream, SNDRV_PCM_STATE_RUNNING); } /* take the stream lock and start the streams */ static int snd_pcm_start_lock_irq(struct snd_pcm_substream *substream) { return snd_pcm_action_lock_irq(&snd_pcm_action_start, substream, SNDRV_PCM_STATE_RUNNING); } /* * stop callbacks */ static int snd_pcm_pre_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream && snd_pcm_running(substream)) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); substream->runtime->stop_operating = true; } return 0; /* unconditionally stop all substreams */ } static void snd_pcm_post_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->state != state) { snd_pcm_trigger_tstamp(substream); __snd_pcm_set_state(runtime, state); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTOP); } wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } static const struct action_ops snd_pcm_action_stop = { .pre_action = snd_pcm_pre_stop, .do_action = snd_pcm_do_stop, .post_action = snd_pcm_post_stop }; /** * snd_pcm_stop - try to stop all running streams in the substream group * @substream: the PCM substream instance * @state: PCM state after stopping the stream * * The state of each stream is then changed to the given state unconditionally. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { return snd_pcm_action(&snd_pcm_action_stop, substream, state); } EXPORT_SYMBOL(snd_pcm_stop); /** * snd_pcm_drain_done - stop the DMA only when the given stream is playback * @substream: the PCM substream * * After stopping, the state is changed to SETUP. * Unlike snd_pcm_stop(), this affects only the given stream. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_drain_done(struct snd_pcm_substream *substream) { return snd_pcm_action_single(&snd_pcm_action_stop, substream, SNDRV_PCM_STATE_SETUP); } /** * snd_pcm_stop_xrun - stop the running streams as XRUN * @substream: the PCM substream instance * * This stops the given running substream (and all linked substreams) as XRUN. * Unlike snd_pcm_stop(), this function takes the substream lock by itself. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_stop_xrun(struct snd_pcm_substream *substream) { unsigned long flags; snd_pcm_stream_lock_irqsave(substream, flags); if (substream->runtime && snd_pcm_running(substream)) __snd_pcm_xrun(substream); snd_pcm_stream_unlock_irqrestore(substream, flags); return 0; } EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun); /* * pause callbacks: pass boolean (to start pause or resume) as state argument */ #define pause_pushed(state) (__force bool)(state) static int snd_pcm_pre_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (!(runtime->info & SNDRV_PCM_INFO_PAUSE)) return -ENOSYS; if (pause_pushed(state)) { if (runtime->state != SNDRV_PCM_STATE_RUNNING) return -EBADFD; } else if (runtime->state != SNDRV_PCM_STATE_PAUSED) return -EBADFD; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master != substream) return 0; /* The jiffies check in snd_pcm_update_hw_ptr*() is done by * a delta between the current jiffies, this gives a large enough * delta, effectively to skip the check once. */ substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000; return substream->ops->trigger(substream, pause_pushed(state) ? SNDRV_PCM_TRIGGER_PAUSE_PUSH : SNDRV_PCM_TRIGGER_PAUSE_RELEASE); } static void snd_pcm_undo_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream) substream->ops->trigger(substream, pause_pushed(state) ? SNDRV_PCM_TRIGGER_PAUSE_RELEASE : SNDRV_PCM_TRIGGER_PAUSE_PUSH); } static void snd_pcm_post_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); if (pause_pushed(state)) { __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_PAUSED); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MPAUSE); wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } else { __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_RUNNING); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MCONTINUE); } } static const struct action_ops snd_pcm_action_pause = { .pre_action = snd_pcm_pre_pause, .do_action = snd_pcm_do_pause, .undo_action = snd_pcm_undo_pause, .post_action = snd_pcm_post_pause }; /* * Push/release the pause for all linked streams. */ static int snd_pcm_pause(struct snd_pcm_substream *substream, bool push) { return snd_pcm_action(&snd_pcm_action_pause, substream, (__force snd_pcm_state_t)push); } static int snd_pcm_pause_lock_irq(struct snd_pcm_substream *substream, bool push) { return snd_pcm_action_lock_irq(&snd_pcm_action_pause, substream, (__force snd_pcm_state_t)push); } #ifdef CONFIG_PM /* suspend callback: state argument ignored */ static int snd_pcm_pre_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->state) { case SNDRV_PCM_STATE_SUSPENDED: return -EBUSY; /* unresumable PCM state; return -EBUSY for skipping suspend */ case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_DISCONNECTED: return -EBUSY; } runtime->trigger_master = substream; return 0; } static int snd_pcm_do_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master != substream) return 0; if (! snd_pcm_running(substream)) return 0; substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); runtime->stop_operating = true; return 0; /* suspend unconditionally */ } static void snd_pcm_post_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); runtime->suspended_state = runtime->state; runtime->status->suspended_state = runtime->suspended_state; __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_SUSPENDED); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSUSPEND); wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } static const struct action_ops snd_pcm_action_suspend = { .pre_action = snd_pcm_pre_suspend, .do_action = snd_pcm_do_suspend, .post_action = snd_pcm_post_suspend }; /* * snd_pcm_suspend - trigger SUSPEND to all linked streams * @substream: the PCM substream * * After this call, all streams are changed to SUSPENDED state. * * Return: Zero if successful, or a negative error code. */ static int snd_pcm_suspend(struct snd_pcm_substream *substream) { int err; unsigned long flags; snd_pcm_stream_lock_irqsave(substream, flags); err = snd_pcm_action(&snd_pcm_action_suspend, substream, ACTION_ARG_IGNORE); snd_pcm_stream_unlock_irqrestore(substream, flags); return err; } /** * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm * @pcm: the PCM instance * * After this call, all streams are changed to SUSPENDED state. * * Return: Zero if successful (or @pcm is %NULL), or a negative error code. */ int snd_pcm_suspend_all(struct snd_pcm *pcm) { struct snd_pcm_substream *substream; int stream, err = 0; if (! pcm) return 0; for_each_pcm_substream(pcm, stream, substream) { /* FIXME: the open/close code should lock this as well */ if (!substream->runtime) continue; /* * Skip BE dai link PCM's that are internal and may * not have their substream ops set. */ if (!substream->ops) continue; err = snd_pcm_suspend(substream); if (err < 0 && err != -EBUSY) return err; } for_each_pcm_substream(pcm, stream, substream) snd_pcm_sync_stop(substream, false); return 0; } EXPORT_SYMBOL(snd_pcm_suspend_all); /* resume callbacks: state argument ignored */ static int snd_pcm_pre_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (!(runtime->info & SNDRV_PCM_INFO_RESUME)) return -ENOSYS; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master != substream) return 0; /* DMA not running previously? */ if (runtime->suspended_state != SNDRV_PCM_STATE_RUNNING && (runtime->suspended_state != SNDRV_PCM_STATE_DRAINING || substream->stream != SNDRV_PCM_STREAM_PLAYBACK)) return 0; return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME); } static void snd_pcm_undo_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream && snd_pcm_running(substream)) substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); } static void snd_pcm_post_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); __snd_pcm_set_state(runtime, runtime->suspended_state); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MRESUME); } static const struct action_ops snd_pcm_action_resume = { .pre_action = snd_pcm_pre_resume, .do_action = snd_pcm_do_resume, .undo_action = snd_pcm_undo_resume, .post_action = snd_pcm_post_resume }; static int snd_pcm_resume(struct snd_pcm_substream *substream) { return snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, ACTION_ARG_IGNORE); } #else static int snd_pcm_resume(struct snd_pcm_substream *substream) { return -ENOSYS; } #endif /* CONFIG_PM */ /* * xrun ioctl * * Change the RUNNING stream(s) to XRUN state. */ static int snd_pcm_xrun(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; int result; snd_pcm_stream_lock_irq(substream); switch (runtime->state) { case SNDRV_PCM_STATE_XRUN: result = 0; /* already there */ break; case SNDRV_PCM_STATE_RUNNING: __snd_pcm_xrun(substream); result = 0; break; default: result = -EBADFD; } snd_pcm_stream_unlock_irq(substream); return result; } /* * reset ioctl */ /* reset callbacks: state argument ignored */ static int snd_pcm_pre_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->state) { case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: case SNDRV_PCM_STATE_SUSPENDED: return 0; default: return -EBADFD; } } static int snd_pcm_do_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL); if (err < 0) return err; snd_pcm_stream_lock_irq(substream); runtime->hw_ptr_base = 0; runtime->hw_ptr_interrupt = runtime->status->hw_ptr - runtime->status->hw_ptr % runtime->period_size; runtime->silence_start = runtime->status->hw_ptr; runtime->silence_filled = 0; snd_pcm_stream_unlock_irq(substream); return 0; } static void snd_pcm_post_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); runtime->control->appl_ptr = runtime->status->hw_ptr; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); snd_pcm_stream_unlock_irq(substream); } static const struct action_ops snd_pcm_action_reset = { .pre_action = snd_pcm_pre_reset, .do_action = snd_pcm_do_reset, .post_action = snd_pcm_post_reset }; static int snd_pcm_reset(struct snd_pcm_substream *substream) { return snd_pcm_action_nonatomic(&snd_pcm_action_reset, substream, ACTION_ARG_IGNORE); } /* * prepare ioctl */ /* pass f_flags as state argument */ static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; int f_flags = (__force int)state; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (snd_pcm_running(substream)) return -EBUSY; substream->f_flags = f_flags; return 0; } static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { int err; snd_pcm_sync_stop(substream, true); err = substream->ops->prepare(substream); if (err < 0) return err; return snd_pcm_do_reset(substream, state); } static void snd_pcm_post_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; runtime->control->appl_ptr = runtime->status->hw_ptr; snd_pcm_set_state(substream, SNDRV_PCM_STATE_PREPARED); } static const struct action_ops snd_pcm_action_prepare = { .pre_action = snd_pcm_pre_prepare, .do_action = snd_pcm_do_prepare, .post_action = snd_pcm_post_prepare }; /** * snd_pcm_prepare - prepare the PCM substream to be triggerable * @substream: the PCM substream instance * @file: file to refer f_flags * * Return: Zero if successful, or a negative error code. */ static int snd_pcm_prepare(struct snd_pcm_substream *substream, struct file *file) { int f_flags; if (file) f_flags = file->f_flags; else f_flags = substream->f_flags; snd_pcm_stream_lock_irq(substream); switch (substream->runtime->state) { case SNDRV_PCM_STATE_PAUSED: snd_pcm_pause(substream, false); fallthrough; case SNDRV_PCM_STATE_SUSPENDED: snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); break; } snd_pcm_stream_unlock_irq(substream); return snd_pcm_action_nonatomic(&snd_pcm_action_prepare, substream, (__force snd_pcm_state_t)f_flags); } /* * drain ioctl */ /* drain init callbacks: state argument ignored */ static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_DISCONNECTED: case SNDRV_PCM_STATE_SUSPENDED: return -EBADFD; } runtime->trigger_master = substream; return 0; } static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { switch (runtime->state) { case SNDRV_PCM_STATE_PREPARED: /* start playback stream if possible */ if (! snd_pcm_playback_empty(substream)) { snd_pcm_do_start(substream, SNDRV_PCM_STATE_DRAINING); snd_pcm_post_start(substream, SNDRV_PCM_STATE_DRAINING); } else { __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_SETUP); } break; case SNDRV_PCM_STATE_RUNNING: __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_DRAINING); break; case SNDRV_PCM_STATE_XRUN: __snd_pcm_set_state(runtime, SNDRV_PCM_STATE_SETUP); break; default: break; } } else { /* stop running stream */ if (runtime->state == SNDRV_PCM_STATE_RUNNING) { snd_pcm_state_t new_state; new_state = snd_pcm_capture_avail(runtime) > 0 ? SNDRV_PCM_STATE_DRAINING : SNDRV_PCM_STATE_SETUP; snd_pcm_do_stop(substream, new_state); snd_pcm_post_stop(substream, new_state); } } if (runtime->state == SNDRV_PCM_STATE_DRAINING && runtime->trigger_master == substream && (runtime->hw.info & SNDRV_PCM_INFO_DRAIN_TRIGGER)) return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_DRAIN); return 0; } static void snd_pcm_post_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { } static const struct action_ops snd_pcm_action_drain_init = { .pre_action = snd_pcm_pre_drain_init, .do_action = snd_pcm_do_drain_init, .post_action = snd_pcm_post_drain_init }; /* * Drain the stream(s). * When the substream is linked, sync until the draining of all playback streams * is finished. * After this call, all streams are supposed to be either SETUP or DRAINING * (capture only) state. */ static int snd_pcm_drain(struct snd_pcm_substream *substream, struct file *file) { struct snd_card *card; struct snd_pcm_runtime *runtime; struct snd_pcm_substream *s; struct snd_pcm_group *group; wait_queue_entry_t wait; int result = 0; int nonblock = 0; card = substream->pcm->card; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (file) { if (file->f_flags & O_NONBLOCK) nonblock = 1; } else if (substream->f_flags & O_NONBLOCK) nonblock = 1; snd_pcm_stream_lock_irq(substream); /* resume pause */ if (runtime->state == SNDRV_PCM_STATE_PAUSED) snd_pcm_pause(substream, false); /* pre-start/stop - all running streams are changed to DRAINING state */ result = snd_pcm_action(&snd_pcm_action_drain_init, substream, ACTION_ARG_IGNORE); if (result < 0) goto unlock; /* in non-blocking, we don't wait in ioctl but let caller poll */ if (nonblock) { result = -EAGAIN; goto unlock; } for (;;) { long tout; struct snd_pcm_runtime *to_check; if (signal_pending(current)) { result = -ERESTARTSYS; break; } /* find a substream to drain */ to_check = NULL; group = snd_pcm_stream_group_ref(substream); snd_pcm_group_for_each_entry(s, substream) { if (s->stream != SNDRV_PCM_STREAM_PLAYBACK) continue; runtime = s->runtime; if (runtime->state == SNDRV_PCM_STATE_DRAINING) { to_check = runtime; break; } } snd_pcm_group_unref(group, substream); if (!to_check) break; /* all drained */ init_waitqueue_entry(&wait, current); set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&to_check->sleep, &wait); snd_pcm_stream_unlock_irq(substream); if (runtime->no_period_wakeup) tout = MAX_SCHEDULE_TIMEOUT; else { tout = 100; if (runtime->rate) { long t = runtime->buffer_size * 1100 / runtime->rate; tout = max(t, tout); } tout = msecs_to_jiffies(tout); } tout = schedule_timeout(tout); snd_pcm_stream_lock_irq(substream); group = snd_pcm_stream_group_ref(substream); snd_pcm_group_for_each_entry(s, substream) { if (s->runtime == to_check) { remove_wait_queue(&to_check->sleep, &wait); break; } } snd_pcm_group_unref(group, substream); if (card->shutdown) { result = -ENODEV; break; } if (tout == 0) { if (substream->runtime->state == SNDRV_PCM_STATE_SUSPENDED) result = -ESTRPIPE; else { dev_dbg(substream->pcm->card->dev, "playback drain timeout (DMA or IRQ trouble?)\n"); snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); result = -EIO; } break; } } unlock: snd_pcm_stream_unlock_irq(substream); return result; } /* * drop ioctl * * Immediately put all linked substreams into SETUP state. */ static int snd_pcm_drop(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; int result = 0; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; snd_pcm_stream_lock_irq(substream); /* resume pause */ if (runtime->state == SNDRV_PCM_STATE_PAUSED) snd_pcm_pause(substream, false); snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); /* runtime->control->appl_ptr = runtime->status->hw_ptr; */ snd_pcm_stream_unlock_irq(substream); return result; } static bool is_pcm_file(struct file *file) { struct inode *inode = file_inode(file); struct snd_pcm *pcm; unsigned int minor; if (!S_ISCHR(inode->i_mode) || imajor(inode) != snd_major) return false; minor = iminor(inode); pcm = snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_PLAYBACK); if (!pcm) pcm = snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_CAPTURE); if (!pcm) return false; snd_card_unref(pcm->card); return true; } /* * PCM link handling */ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd) { int res = 0; struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream1; struct snd_pcm_group *group, *target_group; bool nonatomic = substream->pcm->nonatomic; struct fd f = fdget(fd); if (!f.file) return -EBADFD; if (!is_pcm_file(f.file)) { res = -EBADFD; goto _badf; } pcm_file = f.file->private_data; substream1 = pcm_file->substream; if (substream == substream1) { res = -EINVAL; goto _badf; } group = kzalloc(sizeof(*group), GFP_KERNEL); if (!group) { res = -ENOMEM; goto _nolock; } snd_pcm_group_init(group); down_write(&snd_pcm_link_rwsem); if (substream->runtime->state == SNDRV_PCM_STATE_OPEN || substream->runtime->state != substream1->runtime->state || substream->pcm->nonatomic != substream1->pcm->nonatomic) { res = -EBADFD; goto _end; } if (snd_pcm_stream_linked(substream1)) { res = -EALREADY; goto _end; } snd_pcm_stream_lock_irq(substream); if (!snd_pcm_stream_linked(substream)) { snd_pcm_group_assign(substream, group); group = NULL; /* assigned, don't free this one below */ } target_group = substream->group; snd_pcm_stream_unlock_irq(substream); snd_pcm_group_lock_irq(target_group, nonatomic); snd_pcm_stream_lock_nested(substream1); snd_pcm_group_assign(substream1, target_group); refcount_inc(&target_group->refs); snd_pcm_stream_unlock(substream1); snd_pcm_group_unlock_irq(target_group, nonatomic); _end: up_write(&snd_pcm_link_rwsem); _nolock: kfree(group); _badf: fdput(f); return res; } static void relink_to_local(struct snd_pcm_substream *substream) { snd_pcm_stream_lock_nested(substream); snd_pcm_group_assign(substream, &substream->self_group); snd_pcm_stream_unlock(substream); } static int snd_pcm_unlink(struct snd_pcm_substream *substream) { struct snd_pcm_group *group; bool nonatomic = substream->pcm->nonatomic; bool do_free = false; int res = 0; down_write(&snd_pcm_link_rwsem); if (!snd_pcm_stream_linked(substream)) { res = -EALREADY; goto _end; } group = substream->group; snd_pcm_group_lock_irq(group, nonatomic); relink_to_local(substream); refcount_dec(&group->refs); /* detach the last stream, too */ if (list_is_singular(&group->substreams)) { relink_to_local(list_first_entry(&group->substreams, struct snd_pcm_substream, link_list)); do_free = refcount_dec_and_test(&group->refs); } snd_pcm_group_unlock_irq(group, nonatomic); if (do_free) kfree(group); _end: up_write(&snd_pcm_link_rwsem); return res; } /* * hw configurator */ static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_mul(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_div(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_muldivk(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), (unsigned long) rule->private, &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_mulkdiv(hw_param_interval_c(params, rule->deps[0]), (unsigned long) rule->private, hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { snd_pcm_format_t k; const struct snd_interval *i = hw_param_interval_c(params, rule->deps[0]); struct snd_mask m; struct snd_mask *mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); snd_mask_any(&m); pcm_for_each_format(k) { int bits; if (!snd_mask_test_format(mask, k)) continue; bits = snd_pcm_format_physical_width(k); if (bits <= 0) continue; /* ignore invalid formats */ if ((unsigned)bits < i->min || (unsigned)bits > i->max) snd_mask_reset(&m, (__force unsigned)k); } return snd_mask_refine(mask, &m); } static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_pcm_format_t k; t.min = UINT_MAX; t.max = 0; t.openmin = 0; t.openmax = 0; pcm_for_each_format(k) { int bits; if (!snd_mask_test_format(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), k)) continue; bits = snd_pcm_format_physical_width(k); if (bits <= 0) continue; /* ignore invalid formats */ if (t.min > (unsigned)bits) t.min = bits; if (t.max < (unsigned)bits) t.max = bits; } t.integer = 1; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12 #error "Change this table" #endif static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000, 352800, 384000 }; const struct snd_pcm_hw_constraint_list snd_pcm_known_rates = { .count = ARRAY_SIZE(rates), .list = rates, }; static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_pcm_hardware *hw = rule->private; return snd_interval_list(hw_param_interval(params, rule->var), snd_pcm_known_rates.count, snd_pcm_known_rates.list, hw->rates); } static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; struct snd_pcm_substream *substream = rule->private; t.min = 0; t.max = substream->buffer_bytes_max; t.openmin = 0; t.openmax = 0; t.integer = 1; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; int k, err; for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { snd_mask_any(constrs_mask(constrs, k)); } for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { snd_interval_any(constrs_interval(constrs, k)); } snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_CHANNELS)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_FRAME_BITS)); err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, snd_pcm_hw_rule_format, NULL, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, snd_pcm_hw_rule_sample_bits, NULL, SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mul, NULL, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_TIME, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_BUFFER_TIME, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_muldivk, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_mul, NULL, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_muldivk, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, snd_pcm_hw_rule_muldivk, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, snd_pcm_hw_rule_muldivk, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; return 0; } static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; int err; unsigned int mask = 0; if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_INTERLEAVED); if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_NONINTERLEAVED); if (hw_support_mmap(substream)) { if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED); if (hw->info & SNDRV_PCM_INFO_COMPLEX) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_COMPLEX); } err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask); if (err < 0) return err; err = snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, hw->formats); if (err < 0) return err; err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, PARAM_MASK_BIT(SNDRV_PCM_SUBFORMAT_STD)); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, hw->channels_min, hw->channels_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, hw->rate_min, hw->rate_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, hw->period_bytes_min, hw->period_bytes_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS, hw->periods_min, hw->periods_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, hw->period_bytes_min, hw->buffer_bytes_max); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, snd_pcm_hw_rule_buffer_bytes_max, substream, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1); if (err < 0) return err; /* FIXME: remove */ if (runtime->dma_bytes) { err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes); if (err < 0) return err; } if (!(hw->rates & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))) { err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_rate, hw, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; } /* FIXME: this belong to lowlevel */ snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return 0; } static void pcm_release_private(struct snd_pcm_substream *substream) { if (snd_pcm_stream_linked(substream)) snd_pcm_unlink(substream); } void snd_pcm_release_substream(struct snd_pcm_substream *substream) { substream->ref_count--; if (substream->ref_count > 0) return; snd_pcm_drop(substream); if (substream->hw_opened) { if (substream->runtime->state != SNDRV_PCM_STATE_OPEN) do_hw_free(substream); substream->ops->close(substream); substream->hw_opened = 0; } if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); if (substream->pcm_release) { substream->pcm_release(substream); substream->pcm_release = NULL; } snd_pcm_detach_substream(substream); } EXPORT_SYMBOL(snd_pcm_release_substream); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream) { struct snd_pcm_substream *substream; int err; err = snd_pcm_attach_substream(pcm, stream, file, &substream); if (err < 0) return err; if (substream->ref_count > 1) { *rsubstream = substream; return 0; } err = snd_pcm_hw_constraints_init(substream); if (err < 0) { pcm_dbg(pcm, "snd_pcm_hw_constraints_init failed\n"); goto error; } err = substream->ops->open(substream); if (err < 0) goto error; substream->hw_opened = 1; err = snd_pcm_hw_constraints_complete(substream); if (err < 0) { pcm_dbg(pcm, "snd_pcm_hw_constraints_complete failed\n"); goto error; } /* automatically set EXPLICIT_SYNC flag in the managed mode whenever * the DMA buffer requires it */ if (substream->managed_buffer_alloc && substream->dma_buffer.dev.need_sync) substream->runtime->hw.info |= SNDRV_PCM_INFO_EXPLICIT_SYNC; *rsubstream = substream; return 0; error: snd_pcm_release_substream(substream); return err; } EXPORT_SYMBOL(snd_pcm_open_substream); static int snd_pcm_open_file(struct file *file, struct snd_pcm *pcm, int stream) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; int err; err = snd_pcm_open_substream(pcm, stream, file, &substream); if (err < 0) return err; pcm_file = kzalloc(sizeof(*pcm_file), GFP_KERNEL); if (pcm_file == NULL) { snd_pcm_release_substream(substream); return -ENOMEM; } pcm_file->substream = substream; if (substream->ref_count == 1) substream->pcm_release = pcm_release_private; file->private_data = pcm_file; return 0; } static int snd_pcm_playback_open(struct inode *inode, struct file *file) { struct snd_pcm *pcm; int err = nonseekable_open(inode, file); if (err < 0) return err; pcm = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_PCM_PLAYBACK); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); if (pcm) snd_card_unref(pcm->card); return err; } static int snd_pcm_capture_open(struct inode *inode, struct file *file) { struct snd_pcm *pcm; int err = nonseekable_open(inode, file); if (err < 0) return err; pcm = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_PCM_CAPTURE); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); if (pcm) snd_card_unref(pcm->card); return err; } static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) { int err; wait_queue_entry_t wait; if (pcm == NULL) { err = -ENODEV; goto __error1; } err = snd_card_file_add(pcm->card, file); if (err < 0) goto __error1; if (!try_module_get(pcm->card->module)) { err = -EFAULT; goto __error2; } init_waitqueue_entry(&wait, current); add_wait_queue(&pcm->open_wait, &wait); mutex_lock(&pcm->open_mutex); while (1) { err = snd_pcm_open_file(file, pcm, stream); if (err >= 0) break; if (err == -EAGAIN) { if (file->f_flags & O_NONBLOCK) { err = -EBUSY; break; } } else break; set_current_state(TASK_INTERRUPTIBLE); mutex_unlock(&pcm->open_mutex); schedule(); mutex_lock(&pcm->open_mutex); if (pcm->card->shutdown) { err = -ENODEV; break; } if (signal_pending(current)) { err = -ERESTARTSYS; break; } } remove_wait_queue(&pcm->open_wait, &wait); mutex_unlock(&pcm->open_mutex); if (err < 0) goto __error; return err; __error: module_put(pcm->card->module); __error2: snd_card_file_remove(pcm->card, file); __error1: return err; } static int snd_pcm_release(struct inode *inode, struct file *file) { struct snd_pcm *pcm; struct snd_pcm_substream *substream; struct snd_pcm_file *pcm_file; pcm_file = file->private_data; substream = pcm_file->substream; if (snd_BUG_ON(!substream)) return -ENXIO; pcm = substream->pcm; /* block until the device gets woken up as it may touch the hardware */ snd_power_wait(pcm->card); mutex_lock(&pcm->open_mutex); snd_pcm_release_substream(substream); kfree(pcm_file); mutex_unlock(&pcm->open_mutex); wake_up(&pcm->open_wait); module_put(pcm->card->module); snd_card_file_remove(pcm->card, file); return 0; } /* check and update PCM state; return 0 or a negative error * call this inside PCM lock */ static int do_pcm_hwsync(struct snd_pcm_substream *substream) { switch (substream->runtime->state) { case SNDRV_PCM_STATE_DRAINING: if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) return -EBADFD; fallthrough; case SNDRV_PCM_STATE_RUNNING: return snd_pcm_update_hw_ptr(substream); case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: return 0; case SNDRV_PCM_STATE_SUSPENDED: return -ESTRPIPE; case SNDRV_PCM_STATE_XRUN: return -EPIPE; default: return -EBADFD; } } /* increase the appl_ptr; returns the processed frames or a negative error */ static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames, snd_pcm_sframes_t avail) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t appl_ptr; int ret; if (avail <= 0) return 0; if (frames > (snd_pcm_uframes_t)avail) frames = avail; appl_ptr = runtime->control->appl_ptr + frames; if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) appl_ptr -= runtime->boundary; ret = pcm_lib_apply_appl_ptr(substream, appl_ptr); return ret < 0 ? ret : frames; } /* decrease the appl_ptr; returns the processed frames or zero for error */ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames, snd_pcm_sframes_t avail) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t appl_ptr; int ret; if (avail <= 0) return 0; if (frames > (snd_pcm_uframes_t)avail) frames = avail; appl_ptr = runtime->control->appl_ptr - frames; if (appl_ptr < 0) appl_ptr += runtime->boundary; ret = pcm_lib_apply_appl_ptr(substream, appl_ptr); /* NOTE: we return zero for errors because PulseAudio gets depressed * upon receiving an error from rewind ioctl and stops processing * any longer. Returning zero means that no rewind is done, so * it's not absolutely wrong to answer like that. */ return ret < 0 ? 0 : frames; } static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { snd_pcm_sframes_t ret; if (frames == 0) return 0; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) ret = rewind_appl_ptr(substream, frames, snd_pcm_hw_avail(substream)); snd_pcm_stream_unlock_irq(substream); if (ret >= 0) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); return ret; } static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { snd_pcm_sframes_t ret; if (frames == 0) return 0; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) ret = forward_appl_ptr(substream, frames, snd_pcm_avail(substream)); snd_pcm_stream_unlock_irq(substream); if (ret >= 0) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); return ret; } static int snd_pcm_delay(struct snd_pcm_substream *substream, snd_pcm_sframes_t *delay) { int err; snd_pcm_stream_lock_irq(substream); err = do_pcm_hwsync(substream); if (delay && !err) *delay = snd_pcm_calc_delay(substream); snd_pcm_stream_unlock_irq(substream); snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU); return err; } static inline int snd_pcm_hwsync(struct snd_pcm_substream *substream) { return snd_pcm_delay(substream, NULL); } static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr __user *_sync_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_sync_ptr sync_ptr; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; int err; memset(&sync_ptr, 0, sizeof(sync_ptr)); if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) return -EFAULT; if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control))) return -EFAULT; status = runtime->status; control = runtime->control; if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } snd_pcm_stream_lock_irq(substream); if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, sync_ptr.c.control.appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else { sync_ptr.c.control.appl_ptr = control->appl_ptr; } if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = sync_ptr.c.control.avail_min; else sync_ptr.c.control.avail_min = control->avail_min; sync_ptr.s.status.state = status->state; sync_ptr.s.status.hw_ptr = status->hw_ptr; sync_ptr.s.status.tstamp = status->tstamp; sync_ptr.s.status.suspended_state = status->suspended_state; sync_ptr.s.status.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; return 0; } struct snd_pcm_mmap_status32 { snd_pcm_state_t state; s32 pad1; u32 hw_ptr; s32 tstamp_sec; s32 tstamp_nsec; snd_pcm_state_t suspended_state; s32 audio_tstamp_sec; s32 audio_tstamp_nsec; } __attribute__((packed)); struct snd_pcm_mmap_control32 { u32 appl_ptr; u32 avail_min; }; struct snd_pcm_sync_ptr32 { u32 flags; union { struct snd_pcm_mmap_status32 status; unsigned char reserved[64]; } s; union { struct snd_pcm_mmap_control32 control; unsigned char reserved[64]; } c; } __attribute__((packed)); /* recalcuate the boundary within 32bit */ static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) { snd_pcm_uframes_t boundary; if (! runtime->buffer_size) return 0; boundary = runtime->buffer_size; while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) boundary *= 2; return boundary; } static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr32 __user *src) { struct snd_pcm_runtime *runtime = substream->runtime; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; u32 sflags; struct snd_pcm_mmap_control scontrol; struct snd_pcm_mmap_status sstatus; snd_pcm_uframes_t boundary; int err; if (snd_BUG_ON(!runtime)) return -EINVAL; if (get_user(sflags, &src->flags) || get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || get_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } status = runtime->status; control = runtime->control; boundary = recalculate_boundary(runtime); if (! boundary) boundary = 0x7fffffff; snd_pcm_stream_lock_irq(substream); /* FIXME: we should consider the boundary for the sync from app */ if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, scontrol.appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else scontrol.appl_ptr = control->appl_ptr % boundary; if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = scontrol.avail_min; else scontrol.avail_min = control->avail_min; sstatus.state = status->state; sstatus.hw_ptr = status->hw_ptr % boundary; sstatus.tstamp = status->tstamp; sstatus.suspended_state = status->suspended_state; sstatus.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) || put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) || put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; return 0; } #define __SNDRV_PCM_IOCTL_SYNC_PTR32 _IOWR('A', 0x23, struct snd_pcm_sync_ptr32) static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { struct snd_pcm_runtime *runtime = substream->runtime; int arg; if (get_user(arg, _arg)) return -EFAULT; if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; runtime->tstamp_type = arg; return 0; } static int snd_pcm_xferi_frames_ioctl(struct snd_pcm_substream *substream, struct snd_xferi __user *_xferi) { struct snd_xferi xferi; struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t result; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (put_user(0, &_xferi->result)) return -EFAULT; if (copy_from_user(&xferi, _xferi, sizeof(xferi))) return -EFAULT; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) result = snd_pcm_lib_write(substream, xferi.buf, xferi.frames); else result = snd_pcm_lib_read(substream, xferi.buf, xferi.frames); if (put_user(result, &_xferi->result)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream, struct snd_xfern __user *_xfern) { struct snd_xfern xfern; struct snd_pcm_runtime *runtime = substream->runtime; void *bufs; snd_pcm_sframes_t result; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (runtime->channels > 128) return -EINVAL; if (put_user(0, &_xfern->result)) return -EFAULT; if (copy_from_user(&xfern, _xfern, sizeof(xfern))) return -EFAULT; bufs = memdup_user(xfern.bufs, sizeof(void *) * runtime->channels); if (IS_ERR(bufs)) return PTR_ERR(bufs); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) result = snd_pcm_lib_writev(substream, bufs, xfern.frames); else result = snd_pcm_lib_readv(substream, bufs, xfern.frames); kfree(bufs); if (put_user(result, &_xfern->result)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_rewind_ioctl(struct snd_pcm_substream *substream, snd_pcm_uframes_t __user *_frames) { snd_pcm_uframes_t frames; snd_pcm_sframes_t result; if (get_user(frames, _frames)) return -EFAULT; if (put_user(0, _frames)) return -EFAULT; result = snd_pcm_rewind(substream, frames); if (put_user(result, _frames)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_forward_ioctl(struct snd_pcm_substream *substream, snd_pcm_uframes_t __user *_frames) { snd_pcm_uframes_t frames; snd_pcm_sframes_t result; if (get_user(frames, _frames)) return -EFAULT; if (put_user(0, _frames)) return -EFAULT; result = snd_pcm_forward(substream, frames); if (put_user(result, _frames)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_common_ioctl(struct file *file, struct snd_pcm_substream *substream, unsigned int cmd, void __user *arg) { struct snd_pcm_file *pcm_file = file->private_data; int res; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; res = snd_power_wait(substream->pcm->card); if (res < 0) return res; switch (cmd) { case SNDRV_PCM_IOCTL_PVERSION: return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0; case SNDRV_PCM_IOCTL_INFO: return snd_pcm_info_user(substream, arg); case SNDRV_PCM_IOCTL_TSTAMP: /* just for compatibility */ return 0; case SNDRV_PCM_IOCTL_TTSTAMP: return snd_pcm_tstamp(substream, arg); case SNDRV_PCM_IOCTL_USER_PVERSION: if (get_user(pcm_file->user_pversion, (unsigned int __user *)arg)) return -EFAULT; return 0; case SNDRV_PCM_IOCTL_HW_REFINE: return snd_pcm_hw_refine_user(substream, arg); case SNDRV_PCM_IOCTL_HW_PARAMS: return snd_pcm_hw_params_user(substream, arg); case SNDRV_PCM_IOCTL_HW_FREE: return snd_pcm_hw_free(substream); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params_user(substream, arg); case SNDRV_PCM_IOCTL_STATUS32: return snd_pcm_status_user32(substream, arg, false); case SNDRV_PCM_IOCTL_STATUS_EXT32: return snd_pcm_status_user32(substream, arg, true); case SNDRV_PCM_IOCTL_STATUS64: return snd_pcm_status_user64(substream, arg, false); case SNDRV_PCM_IOCTL_STATUS_EXT64: return snd_pcm_status_user64(substream, arg, true); case SNDRV_PCM_IOCTL_CHANNEL_INFO: return snd_pcm_channel_info_user(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: return snd_pcm_prepare(substream, file); case SNDRV_PCM_IOCTL_RESET: return snd_pcm_reset(substream); case SNDRV_PCM_IOCTL_START: return snd_pcm_start_lock_irq(substream); case SNDRV_PCM_IOCTL_LINK: return snd_pcm_link(substream, (int)(unsigned long) arg); case SNDRV_PCM_IOCTL_UNLINK: return snd_pcm_unlink(substream); case SNDRV_PCM_IOCTL_RESUME: return snd_pcm_resume(substream); case SNDRV_PCM_IOCTL_XRUN: return snd_pcm_xrun(substream); case SNDRV_PCM_IOCTL_HWSYNC: return snd_pcm_hwsync(substream); case SNDRV_PCM_IOCTL_DELAY: { snd_pcm_sframes_t delay = 0; snd_pcm_sframes_t __user *res = arg; int err; err = snd_pcm_delay(substream, &delay); if (err) return err; if (put_user(delay, res)) return -EFAULT; return 0; } case __SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_ioctl_sync_ptr_compat(substream, arg); case __SNDRV_PCM_IOCTL_SYNC_PTR64: return snd_pcm_sync_ptr(substream, arg); #ifdef CONFIG_SND_SUPPORT_OLD_API case SNDRV_PCM_IOCTL_HW_REFINE_OLD: return snd_pcm_hw_refine_old_user(substream, arg); case SNDRV_PCM_IOCTL_HW_PARAMS_OLD: return snd_pcm_hw_params_old_user(substream, arg); #endif case SNDRV_PCM_IOCTL_DRAIN: return snd_pcm_drain(substream, file); case SNDRV_PCM_IOCTL_DROP: return snd_pcm_drop(substream); case SNDRV_PCM_IOCTL_PAUSE: return snd_pcm_pause_lock_irq(substream, (unsigned long)arg); case SNDRV_PCM_IOCTL_WRITEI_FRAMES: case SNDRV_PCM_IOCTL_READI_FRAMES: return snd_pcm_xferi_frames_ioctl(substream, arg); case SNDRV_PCM_IOCTL_WRITEN_FRAMES: case SNDRV_PCM_IOCTL_READN_FRAMES: return snd_pcm_xfern_frames_ioctl(substream, arg); case SNDRV_PCM_IOCTL_REWIND: return snd_pcm_rewind_ioctl(substream, arg); case SNDRV_PCM_IOCTL_FORWARD: return snd_pcm_forward_ioctl(substream, arg); } pcm_dbg(substream->pcm, "unknown ioctl = 0x%x\n", cmd); return -ENOTTY; } static long snd_pcm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_pcm_file *pcm_file; pcm_file = file->private_data; if (((cmd >> 8) & 0xff) != 'A') return -ENOTTY; return snd_pcm_common_ioctl(file, pcm_file->substream, cmd, (void __user *)arg); } /** * snd_pcm_kernel_ioctl - Execute PCM ioctl in the kernel-space * @substream: PCM substream * @cmd: IOCTL cmd * @arg: IOCTL argument * * The function is provided primarily for OSS layer and USB gadget drivers, * and it allows only the limited set of ioctls (hw_params, sw_params, * prepare, start, drain, drop, forward). * * Return: zero if successful, or a negative error code */ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { snd_pcm_uframes_t *frames = arg; snd_pcm_sframes_t result; if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; switch (cmd) { case SNDRV_PCM_IOCTL_FORWARD: { /* provided only for OSS; capture-only and no value returned */ if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) return -EINVAL; result = snd_pcm_forward(substream, *frames); return result < 0 ? result : 0; } case SNDRV_PCM_IOCTL_HW_PARAMS: return snd_pcm_hw_params(substream, arg); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: return snd_pcm_prepare(substream, NULL); case SNDRV_PCM_IOCTL_START: return snd_pcm_start_lock_irq(substream); case SNDRV_PCM_IOCTL_DRAIN: return snd_pcm_drain(substream, NULL); case SNDRV_PCM_IOCTL_DROP: return snd_pcm_drop(substream); case SNDRV_PCM_IOCTL_DELAY: return snd_pcm_delay(substream, frames); default: return -EINVAL; } } EXPORT_SYMBOL(snd_pcm_kernel_ioctl); static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count, loff_t * offset) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (!frame_aligned(runtime, count)) return -EINVAL; count = bytes_to_frames(runtime, count); result = snd_pcm_lib_read(substream, buf, count); if (result > 0) result = frames_to_bytes(runtime, result); return result; } static ssize_t snd_pcm_write(struct file *file, const char __user *buf, size_t count, loff_t * offset) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (!frame_aligned(runtime, count)) return -EINVAL; count = bytes_to_frames(runtime, count); result = snd_pcm_lib_write(substream, buf, count); if (result > 0) result = frames_to_bytes(runtime, result); return result; } static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; const struct iovec *iov = iter_iov(to); pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (!to->user_backed) return -EINVAL; if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) return -EINVAL; if (!frame_aligned(runtime, iov->iov_len)) return -EINVAL; frames = bytes_to_samples(runtime, iov->iov_len); bufs = kmalloc_array(to->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; for (i = 0; i < to->nr_segs; ++i) { bufs[i] = iov->iov_base; iov++; } result = snd_pcm_lib_readv(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); kfree(bufs); return result; } static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; const struct iovec *iov = iter_iov(from); pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (!from->user_backed) return -EINVAL; if (from->nr_segs > 128 || from->nr_segs != runtime->channels || !frame_aligned(runtime, iov->iov_len)) return -EINVAL; frames = bytes_to_samples(runtime, iov->iov_len); bufs = kmalloc_array(from->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; for (i = 0; i < from->nr_segs; ++i) { bufs[i] = iov->iov_base; iov++; } result = snd_pcm_lib_writev(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); kfree(bufs); return result; } static __poll_t snd_pcm_poll(struct file *file, poll_table *wait) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; __poll_t mask, ok; snd_pcm_uframes_t avail; pcm_file = file->private_data; substream = pcm_file->substream; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ok = EPOLLOUT | EPOLLWRNORM; else ok = EPOLLIN | EPOLLRDNORM; if (PCM_RUNTIME_CHECK(substream)) return ok | EPOLLERR; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return ok | EPOLLERR; poll_wait(file, &runtime->sleep, wait); mask = 0; snd_pcm_stream_lock_irq(substream); avail = snd_pcm_avail(substream); switch (runtime->state) { case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: if (avail >= runtime->control->avail_min) mask = ok; break; case SNDRV_PCM_STATE_DRAINING: if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { mask = ok; if (!avail) mask |= EPOLLERR; } break; default: mask = ok | EPOLLERR; break; } snd_pcm_stream_unlock_irq(substream); return mask; } /* * mmap support */ /* * Only on coherent architectures, we can mmap the status and the control records * for effcient data transfer. On others, we have to use HWSYNC ioctl... */ #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA) /* * mmap status record */ static vm_fault_t snd_pcm_mmap_status_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; vmf->page = virt_to_page(runtime->status); get_page(vmf->page); return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_status = { .fault = snd_pcm_mmap_status_fault, }; static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { long size; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_status; area->vm_private_data = substream; vm_flags_mod(area, VM_DONTEXPAND | VM_DONTDUMP, VM_WRITE | VM_MAYWRITE); return 0; } /* * mmap control record */ static vm_fault_t snd_pcm_mmap_control_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; vmf->page = virt_to_page(runtime->control); get_page(vmf->page); return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_control = { .fault = snd_pcm_mmap_control_fault, }; static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { long size; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_control; area->vm_private_data = substream; vm_flags_set(area, VM_DONTEXPAND | VM_DONTDUMP); return 0; } static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file) { /* If drivers require the explicit sync (typically for non-coherent * pages), we have to disable the mmap of status and control data * to enforce the control via SYNC_PTR ioctl. */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC) return false; /* See pcm_control_mmap_allowed() below. * Since older alsa-lib requires both status and control mmaps to be * coupled, we have to disable the status mmap for old alsa-lib, too. */ if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) && (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)) return false; return true; } static bool pcm_control_mmap_allowed(struct snd_pcm_file *pcm_file) { if (pcm_file->no_compat_mmap) return false; /* see above */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC) return false; /* Disallow the control mmap when SYNC_APPLPTR flag is set; * it enforces the user-space to fall back to snd_pcm_sync_ptr(), * thus it effectively assures the manual update of appl_ptr. */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR) return false; return true; } #else /* ! coherent mmap */ /* * don't support mmap for status and control records. */ #define pcm_status_mmap_allowed(pcm_file) false #define pcm_control_mmap_allowed(pcm_file) false static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } #endif /* coherent mmap */ /* * fault callback for mmapping a RAM page */ static vm_fault_t snd_pcm_mmap_data_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; unsigned long offset; struct page * page; size_t dma_bytes; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; offset = vmf->pgoff << PAGE_SHIFT; dma_bytes = PAGE_ALIGN(runtime->dma_bytes); if (offset > dma_bytes - PAGE_SIZE) return VM_FAULT_SIGBUS; if (substream->ops->page) page = substream->ops->page(substream, offset); else if (!snd_pcm_get_dma_buf(substream)) page = virt_to_page(runtime->dma_area + offset); else page = snd_sgbuf_get_page(snd_pcm_get_dma_buf(substream), offset); if (!page) return VM_FAULT_SIGBUS; get_page(page); vmf->page = page; return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_data = { .open = snd_pcm_mmap_data_open, .close = snd_pcm_mmap_data_close, }; static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = { .open = snd_pcm_mmap_data_open, .close = snd_pcm_mmap_data_close, .fault = snd_pcm_mmap_data_fault, }; /* * mmap the DMA buffer on RAM */ /** * snd_pcm_lib_default_mmap - Default PCM data mmap function * @substream: PCM substream * @area: VMA * * This is the default mmap handler for PCM data. When mmap pcm_ops is NULL, * this function is invoked implicitly. * * Return: zero if successful, or a negative error code */ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *area) { vm_flags_set(area, VM_DONTEXPAND | VM_DONTDUMP); if (!substream->ops->page && !snd_dma_buffer_mmap(snd_pcm_get_dma_buf(substream), area)) return 0; /* mmap with fault handler */ area->vm_ops = &snd_pcm_vm_ops_data_fault; return 0; } EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap); /* * mmap the DMA buffer on I/O memory area */ #if SNDRV_PCM_INFO_MMAP_IOMEM /** * snd_pcm_lib_mmap_iomem - Default PCM data mmap function for I/O mem * @substream: PCM substream * @area: VMA * * When your hardware uses the iomapped pages as the hardware buffer and * wants to mmap it, pass this function as mmap pcm_ops. Note that this * is supposed to work only on limited architectures. * * Return: zero if successful, or a negative error code */ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area) { struct snd_pcm_runtime *runtime = substream->runtime; area->vm_page_prot = pgprot_noncached(area->vm_page_prot); return vm_iomap_memory(area, runtime->dma_addr, runtime->dma_bytes); } EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem); #endif /* SNDRV_PCM_INFO_MMAP */ /* * mmap DMA buffer */ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { struct snd_pcm_runtime *runtime; long size; unsigned long offset; size_t dma_bytes; int err; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (!(area->vm_flags & (VM_WRITE|VM_READ))) return -EINVAL; } else { if (!(area->vm_flags & VM_READ)) return -EINVAL; } runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) return -ENXIO; if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) return -EINVAL; size = area->vm_end - area->vm_start; offset = area->vm_pgoff << PAGE_SHIFT; dma_bytes = PAGE_ALIGN(runtime->dma_bytes); if ((size_t)size > dma_bytes) return -EINVAL; if (offset > dma_bytes - size) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_data; area->vm_private_data = substream; if (substream->ops->mmap) err = substream->ops->mmap(substream, area); else err = snd_pcm_lib_default_mmap(substream, area); if (!err) atomic_inc(&substream->mmap_count); return err; } EXPORT_SYMBOL(snd_pcm_mmap_data); static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) { struct snd_pcm_file * pcm_file; struct snd_pcm_substream *substream; unsigned long offset; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; offset = area->vm_pgoff << PAGE_SHIFT; switch (offset) { case SNDRV_PCM_MMAP_OFFSET_STATUS_OLD: if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) return -ENXIO; fallthrough; case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: if (!pcm_status_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_status(substream, file, area); case SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD: if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) return -ENXIO; fallthrough; case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: if (!pcm_control_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_control(substream, file, area); default: return snd_pcm_mmap_data(substream, file, area); } return 0; } static int snd_pcm_fasync(int fd, struct file * file, int on) { struct snd_pcm_file * pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; return snd_fasync_helper(fd, file, on, &runtime->fasync); } /* * ioctl32 compat */ #ifdef CONFIG_COMPAT #include "pcm_compat.c" #else #define snd_pcm_ioctl_compat NULL #endif /* * To be removed helpers to keep binary compatibility */ #ifdef CONFIG_SND_SUPPORT_OLD_API #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5)) #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5)) static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params *params, struct snd_pcm_hw_params_old *oparams) { unsigned int i; memset(params, 0, sizeof(*params)); params->flags = oparams->flags; for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) params->masks[i].bits[0] = oparams->masks[i]; memcpy(params->intervals, oparams->intervals, sizeof(oparams->intervals)); params->rmask = __OLD_TO_NEW_MASK(oparams->rmask); params->cmask = __OLD_TO_NEW_MASK(oparams->cmask); params->info = oparams->info; params->msbits = oparams->msbits; params->rate_num = oparams->rate_num; params->rate_den = oparams->rate_den; params->fifo_size = oparams->fifo_size; } static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old *oparams, struct snd_pcm_hw_params *params) { unsigned int i; memset(oparams, 0, sizeof(*oparams)); oparams->flags = params->flags; for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) oparams->masks[i] = params->masks[i].bits[0]; memcpy(oparams->intervals, params->intervals, sizeof(oparams->intervals)); oparams->rmask = __NEW_TO_OLD_MASK(params->rmask); oparams->cmask = __NEW_TO_OLD_MASK(params->cmask); oparams->info = params->info; oparams->msbits = params->msbits; oparams->rate_num = params->rate_num; oparams->rate_den = params->rate_den; oparams->fifo_size = params->fifo_size; } static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams) { struct snd_pcm_hw_params *params; struct snd_pcm_hw_params_old *oparams = NULL; int err; params = kmalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; oparams = memdup_user(_oparams, sizeof(*oparams)); if (IS_ERR(oparams)) { err = PTR_ERR(oparams); goto out; } snd_pcm_hw_convert_from_old_params(params, oparams); err = snd_pcm_hw_refine(substream, params); if (err < 0) goto out_old; err = fixup_unreferenced_params(substream, params); if (err < 0) goto out_old; snd_pcm_hw_convert_to_old_params(oparams, params); if (copy_to_user(_oparams, oparams, sizeof(*oparams))) err = -EFAULT; out_old: kfree(oparams); out: kfree(params); return err; } static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams) { struct snd_pcm_hw_params *params; struct snd_pcm_hw_params_old *oparams = NULL; int err; params = kmalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; oparams = memdup_user(_oparams, sizeof(*oparams)); if (IS_ERR(oparams)) { err = PTR_ERR(oparams); goto out; } snd_pcm_hw_convert_from_old_params(params, oparams); err = snd_pcm_hw_params(substream, params); if (err < 0) goto out_old; snd_pcm_hw_convert_to_old_params(oparams, params); if (copy_to_user(_oparams, oparams, sizeof(*oparams))) err = -EFAULT; out_old: kfree(oparams); out: kfree(params); return err; } #endif /* CONFIG_SND_SUPPORT_OLD_API */ #ifndef CONFIG_MMU static unsigned long snd_pcm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct snd_pcm_file *pcm_file = file->private_data; struct snd_pcm_substream *substream = pcm_file->substream; struct snd_pcm_runtime *runtime = substream->runtime; unsigned long offset = pgoff << PAGE_SHIFT; switch (offset) { case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: return (unsigned long)runtime->status; case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: return (unsigned long)runtime->control; default: return (unsigned long)runtime->dma_area + offset; } } #else # define snd_pcm_get_unmapped_area NULL #endif /* * Register section */ const struct file_operations snd_pcm_f_ops[2] = { { .owner = THIS_MODULE, .write = snd_pcm_write, .write_iter = snd_pcm_writev, .open = snd_pcm_playback_open, .release = snd_pcm_release, .llseek = no_llseek, .poll = snd_pcm_poll, .unlocked_ioctl = snd_pcm_ioctl, .compat_ioctl = snd_pcm_ioctl_compat, .mmap = snd_pcm_mmap, .fasync = snd_pcm_fasync, .get_unmapped_area = snd_pcm_get_unmapped_area, }, { .owner = THIS_MODULE, .read = snd_pcm_read, .read_iter = snd_pcm_readv, .open = snd_pcm_capture_open, .release = snd_pcm_release, .llseek = no_llseek, .poll = snd_pcm_poll, .unlocked_ioctl = snd_pcm_ioctl, .compat_ioctl = snd_pcm_ioctl_compat, .mmap = snd_pcm_mmap, .fasync = snd_pcm_fasync, .get_unmapped_area = snd_pcm_get_unmapped_area, } };
linux-master
sound/core/pcm_native.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * 32bit -> 64bit ioctl wrapper for timer API * Copyright (c) by Takashi Iwai <[email protected]> */ /* This file included from timer.c */ #include <linux/compat.h> /* * ILP32/LP64 has different size for 'long' type. Additionally, the size * of storage alignment differs depending on architectures. Here, '__packed' * qualifier is used so that the size of this structure is multiple of 4 and * it fits to any architectures with 32 bit storage alignment. */ struct snd_timer_gparams32 { struct snd_timer_id tid; u32 period_num; u32 period_den; unsigned char reserved[32]; } __packed; struct snd_timer_info32 { u32 flags; s32 card; unsigned char id[64]; unsigned char name[80]; u32 reserved0; u32 resolution; unsigned char reserved[64]; }; static int snd_timer_user_gparams_compat(struct file *file, struct snd_timer_gparams32 __user *user) { struct snd_timer_gparams gparams; if (copy_from_user(&gparams.tid, &user->tid, sizeof(gparams.tid)) || get_user(gparams.period_num, &user->period_num) || get_user(gparams.period_den, &user->period_den)) return -EFAULT; return timer_set_gparams(&gparams); } static int snd_timer_user_info_compat(struct file *file, struct snd_timer_info32 __user *_info) { struct snd_timer_user *tu; struct snd_timer_info32 info; struct snd_timer *t; tu = file->private_data; if (!tu->timeri) return -EBADFD; t = tu->timeri->timer; if (!t) return -EBADFD; memset(&info, 0, sizeof(info)); info.card = t->card ? t->card->number : -1; if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) info.flags |= SNDRV_TIMER_FLG_SLAVE; strscpy(info.id, t->id, sizeof(info.id)); strscpy(info.name, t->name, sizeof(info.name)); info.resolution = t->hw.resolution; if (copy_to_user(_info, &info, sizeof(*_info))) return -EFAULT; return 0; } enum { SNDRV_TIMER_IOCTL_GPARAMS32 = _IOW('T', 0x04, struct snd_timer_gparams32), SNDRV_TIMER_IOCTL_INFO32 = _IOR('T', 0x11, struct snd_timer_info32), SNDRV_TIMER_IOCTL_STATUS_COMPAT32 = _IOW('T', 0x14, struct snd_timer_status32), SNDRV_TIMER_IOCTL_STATUS_COMPAT64 = _IOW('T', 0x14, struct snd_timer_status64), }; static long __snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = compat_ptr(arg); switch (cmd) { case SNDRV_TIMER_IOCTL_PVERSION: case SNDRV_TIMER_IOCTL_TREAD_OLD: case SNDRV_TIMER_IOCTL_TREAD64: case SNDRV_TIMER_IOCTL_GINFO: case SNDRV_TIMER_IOCTL_GSTATUS: case SNDRV_TIMER_IOCTL_SELECT: case SNDRV_TIMER_IOCTL_PARAMS: case SNDRV_TIMER_IOCTL_START: case SNDRV_TIMER_IOCTL_START_OLD: case SNDRV_TIMER_IOCTL_STOP: case SNDRV_TIMER_IOCTL_STOP_OLD: case SNDRV_TIMER_IOCTL_CONTINUE: case SNDRV_TIMER_IOCTL_CONTINUE_OLD: case SNDRV_TIMER_IOCTL_PAUSE: case SNDRV_TIMER_IOCTL_PAUSE_OLD: case SNDRV_TIMER_IOCTL_NEXT_DEVICE: return __snd_timer_user_ioctl(file, cmd, (unsigned long)argp, true); case SNDRV_TIMER_IOCTL_GPARAMS32: return snd_timer_user_gparams_compat(file, argp); case SNDRV_TIMER_IOCTL_INFO32: return snd_timer_user_info_compat(file, argp); case SNDRV_TIMER_IOCTL_STATUS_COMPAT32: return snd_timer_user_status32(file, argp); case SNDRV_TIMER_IOCTL_STATUS_COMPAT64: return snd_timer_user_status64(file, argp); } return -ENOIOCTLCMD; } static long snd_timer_user_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_timer_user *tu = file->private_data; long ret; mutex_lock(&tu->ioctl_lock); ret = __snd_timer_user_ioctl_compat(file, cmd, arg); mutex_unlock(&tu->ioctl_lock); return ret; }
linux-master
sound/core/timer_compat.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Routines for driver control interface * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/threads.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/time.h> #include <linux/mm.h> #include <linux/math64.h> #include <linux/sched/signal.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/info.h> #include <sound/control.h> // Max allocation size for user controls. static int max_user_ctl_alloc_size = 8 * 1024 * 1024; module_param_named(max_user_ctl_alloc_size, max_user_ctl_alloc_size, int, 0444); MODULE_PARM_DESC(max_user_ctl_alloc_size, "Max allocation size for user controls"); #define MAX_CONTROL_COUNT 1028 struct snd_kctl_ioctl { struct list_head list; /* list of all ioctls */ snd_kctl_ioctl_func_t fioctl; }; static DECLARE_RWSEM(snd_ioctl_rwsem); static DECLARE_RWSEM(snd_ctl_layer_rwsem); static LIST_HEAD(snd_control_ioctls); #ifdef CONFIG_COMPAT static LIST_HEAD(snd_control_compat_ioctls); #endif static struct snd_ctl_layer_ops *snd_ctl_layer; static int snd_ctl_remove_locked(struct snd_card *card, struct snd_kcontrol *kcontrol); static int snd_ctl_open(struct inode *inode, struct file *file) { unsigned long flags; struct snd_card *card; struct snd_ctl_file *ctl; int i, err; err = stream_open(inode, file); if (err < 0) return err; card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL); if (!card) { err = -ENODEV; goto __error1; } err = snd_card_file_add(card, file); if (err < 0) { err = -ENODEV; goto __error1; } if (!try_module_get(card->module)) { err = -EFAULT; goto __error2; } ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); if (ctl == NULL) { err = -ENOMEM; goto __error; } INIT_LIST_HEAD(&ctl->events); init_waitqueue_head(&ctl->change_sleep); spin_lock_init(&ctl->read_lock); ctl->card = card; for (i = 0; i < SND_CTL_SUBDEV_ITEMS; i++) ctl->preferred_subdevice[i] = -1; ctl->pid = get_pid(task_pid(current)); file->private_data = ctl; write_lock_irqsave(&card->ctl_files_rwlock, flags); list_add_tail(&ctl->list, &card->ctl_files); write_unlock_irqrestore(&card->ctl_files_rwlock, flags); snd_card_unref(card); return 0; __error: module_put(card->module); __error2: snd_card_file_remove(card, file); __error1: if (card) snd_card_unref(card); return err; } static void snd_ctl_empty_read_queue(struct snd_ctl_file * ctl) { unsigned long flags; struct snd_kctl_event *cread; spin_lock_irqsave(&ctl->read_lock, flags); while (!list_empty(&ctl->events)) { cread = snd_kctl_event(ctl->events.next); list_del(&cread->list); kfree(cread); } spin_unlock_irqrestore(&ctl->read_lock, flags); } static int snd_ctl_release(struct inode *inode, struct file *file) { unsigned long flags; struct snd_card *card; struct snd_ctl_file *ctl; struct snd_kcontrol *control; unsigned int idx; ctl = file->private_data; file->private_data = NULL; card = ctl->card; write_lock_irqsave(&card->ctl_files_rwlock, flags); list_del(&ctl->list); write_unlock_irqrestore(&card->ctl_files_rwlock, flags); down_write(&card->controls_rwsem); list_for_each_entry(control, &card->controls, list) for (idx = 0; idx < control->count; idx++) if (control->vd[idx].owner == ctl) control->vd[idx].owner = NULL; up_write(&card->controls_rwsem); snd_fasync_free(ctl->fasync); snd_ctl_empty_read_queue(ctl); put_pid(ctl->pid); kfree(ctl); module_put(card->module); snd_card_file_remove(card, file); return 0; } /** * snd_ctl_notify - Send notification to user-space for a control change * @card: the card to send notification * @mask: the event mask, SNDRV_CTL_EVENT_* * @id: the ctl element id to send notification * * This function adds an event record with the given id and mask, appends * to the list and wakes up the user-space for notification. This can be * called in the atomic context. */ void snd_ctl_notify(struct snd_card *card, unsigned int mask, struct snd_ctl_elem_id *id) { unsigned long flags; struct snd_ctl_file *ctl; struct snd_kctl_event *ev; if (snd_BUG_ON(!card || !id)) return; if (card->shutdown) return; read_lock_irqsave(&card->ctl_files_rwlock, flags); #if IS_ENABLED(CONFIG_SND_MIXER_OSS) card->mixer_oss_change_count++; #endif list_for_each_entry(ctl, &card->ctl_files, list) { if (!ctl->subscribed) continue; spin_lock(&ctl->read_lock); list_for_each_entry(ev, &ctl->events, list) { if (ev->id.numid == id->numid) { ev->mask |= mask; goto _found; } } ev = kzalloc(sizeof(*ev), GFP_ATOMIC); if (ev) { ev->id = *id; ev->mask = mask; list_add_tail(&ev->list, &ctl->events); } else { dev_err(card->dev, "No memory available to allocate event\n"); } _found: wake_up(&ctl->change_sleep); spin_unlock(&ctl->read_lock); snd_kill_fasync(ctl->fasync, SIGIO, POLL_IN); } read_unlock_irqrestore(&card->ctl_files_rwlock, flags); } EXPORT_SYMBOL(snd_ctl_notify); /** * snd_ctl_notify_one - Send notification to user-space for a control change * @card: the card to send notification * @mask: the event mask, SNDRV_CTL_EVENT_* * @kctl: the pointer with the control instance * @ioff: the additional offset to the control index * * This function calls snd_ctl_notify() and does additional jobs * like LED state changes. */ void snd_ctl_notify_one(struct snd_card *card, unsigned int mask, struct snd_kcontrol *kctl, unsigned int ioff) { struct snd_ctl_elem_id id = kctl->id; struct snd_ctl_layer_ops *lops; id.index += ioff; id.numid += ioff; snd_ctl_notify(card, mask, &id); down_read(&snd_ctl_layer_rwsem); for (lops = snd_ctl_layer; lops; lops = lops->next) lops->lnotify(card, mask, kctl, ioff); up_read(&snd_ctl_layer_rwsem); } EXPORT_SYMBOL(snd_ctl_notify_one); /** * snd_ctl_new - create a new control instance with some elements * @kctl: the pointer to store new control instance * @count: the number of elements in this control * @access: the default access flags for elements in this control * @file: given when locking these elements * * Allocates a memory object for a new control instance. The instance has * elements as many as the given number (@count). Each element has given * access permissions (@access). Each element is locked when @file is given. * * Return: 0 on success, error code on failure */ static int snd_ctl_new(struct snd_kcontrol **kctl, unsigned int count, unsigned int access, struct snd_ctl_file *file) { unsigned int idx; if (count == 0 || count > MAX_CONTROL_COUNT) return -EINVAL; *kctl = kzalloc(struct_size(*kctl, vd, count), GFP_KERNEL); if (!*kctl) return -ENOMEM; for (idx = 0; idx < count; idx++) { (*kctl)->vd[idx].access = access; (*kctl)->vd[idx].owner = file; } (*kctl)->count = count; return 0; } /** * snd_ctl_new1 - create a control instance from the template * @ncontrol: the initialization record * @private_data: the private data to set * * Allocates a new struct snd_kcontrol instance and initialize from the given * template. When the access field of ncontrol is 0, it's assumed as * READWRITE access. When the count field is 0, it's assumes as one. * * Return: The pointer of the newly generated instance, or %NULL on failure. */ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, void *private_data) { struct snd_kcontrol *kctl; unsigned int count; unsigned int access; int err; if (snd_BUG_ON(!ncontrol || !ncontrol->info)) return NULL; count = ncontrol->count; if (count == 0) count = 1; access = ncontrol->access; if (access == 0) access = SNDRV_CTL_ELEM_ACCESS_READWRITE; access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_INACTIVE | SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK | SNDRV_CTL_ELEM_ACCESS_LED_MASK | SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK); err = snd_ctl_new(&kctl, count, access, NULL); if (err < 0) return NULL; /* The 'numid' member is decided when calling snd_ctl_add(). */ kctl->id.iface = ncontrol->iface; kctl->id.device = ncontrol->device; kctl->id.subdevice = ncontrol->subdevice; if (ncontrol->name) { strscpy(kctl->id.name, ncontrol->name, sizeof(kctl->id.name)); if (strcmp(ncontrol->name, kctl->id.name) != 0) pr_warn("ALSA: Control name '%s' truncated to '%s'\n", ncontrol->name, kctl->id.name); } kctl->id.index = ncontrol->index; kctl->info = ncontrol->info; kctl->get = ncontrol->get; kctl->put = ncontrol->put; kctl->tlv.p = ncontrol->tlv.p; kctl->private_value = ncontrol->private_value; kctl->private_data = private_data; return kctl; } EXPORT_SYMBOL(snd_ctl_new1); /** * snd_ctl_free_one - release the control instance * @kcontrol: the control instance * * Releases the control instance created via snd_ctl_new() * or snd_ctl_new1(). * Don't call this after the control was added to the card. */ void snd_ctl_free_one(struct snd_kcontrol *kcontrol) { if (kcontrol) { if (kcontrol->private_free) kcontrol->private_free(kcontrol); kfree(kcontrol); } } EXPORT_SYMBOL(snd_ctl_free_one); static bool snd_ctl_remove_numid_conflict(struct snd_card *card, unsigned int count) { struct snd_kcontrol *kctl; /* Make sure that the ids assigned to the control do not wrap around */ if (card->last_numid >= UINT_MAX - count) card->last_numid = 0; list_for_each_entry(kctl, &card->controls, list) { if (kctl->id.numid < card->last_numid + 1 + count && kctl->id.numid + kctl->count > card->last_numid + 1) { card->last_numid = kctl->id.numid + kctl->count - 1; return true; } } return false; } static int snd_ctl_find_hole(struct snd_card *card, unsigned int count) { unsigned int iter = 100000; while (snd_ctl_remove_numid_conflict(card, count)) { if (--iter == 0) { /* this situation is very unlikely */ dev_err(card->dev, "unable to allocate new control numid\n"); return -ENOMEM; } } return 0; } /* check whether the given id is contained in the given kctl */ static bool elem_id_matches(const struct snd_kcontrol *kctl, const struct snd_ctl_elem_id *id) { return kctl->id.iface == id->iface && kctl->id.device == id->device && kctl->id.subdevice == id->subdevice && !strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)) && kctl->id.index <= id->index && kctl->id.index + kctl->count > id->index; } #ifdef CONFIG_SND_CTL_FAST_LOOKUP /* Compute a hash key for the corresponding ctl id * It's for the name lookup, hence the numid is excluded. * The hash key is bound in LONG_MAX to be used for Xarray key. */ #define MULTIPLIER 37 static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id) { int i; unsigned long h; h = id->iface; h = MULTIPLIER * h + id->device; h = MULTIPLIER * h + id->subdevice; for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++) h = MULTIPLIER * h + id->name[i]; h = MULTIPLIER * h + id->index; h &= LONG_MAX; return h; } /* add hash entries to numid and ctl xarray tables */ static void add_hash_entries(struct snd_card *card, struct snd_kcontrol *kcontrol) { struct snd_ctl_elem_id id = kcontrol->id; int i; xa_store_range(&card->ctl_numids, kcontrol->id.numid, kcontrol->id.numid + kcontrol->count - 1, kcontrol, GFP_KERNEL); for (i = 0; i < kcontrol->count; i++) { id.index = kcontrol->id.index + i; if (xa_insert(&card->ctl_hash, get_ctl_id_hash(&id), kcontrol, GFP_KERNEL)) { /* skip hash for this entry, noting we had collision */ card->ctl_hash_collision = true; dev_dbg(card->dev, "ctl_hash collision %d:%s:%d\n", id.iface, id.name, id.index); } } } /* remove hash entries that have been added */ static void remove_hash_entries(struct snd_card *card, struct snd_kcontrol *kcontrol) { struct snd_ctl_elem_id id = kcontrol->id; struct snd_kcontrol *matched; unsigned long h; int i; for (i = 0; i < kcontrol->count; i++) { xa_erase(&card->ctl_numids, id.numid); h = get_ctl_id_hash(&id); matched = xa_load(&card->ctl_hash, h); if (matched && (matched == kcontrol || elem_id_matches(matched, &id))) xa_erase(&card->ctl_hash, h); id.index++; id.numid++; } } #else /* CONFIG_SND_CTL_FAST_LOOKUP */ static inline void add_hash_entries(struct snd_card *card, struct snd_kcontrol *kcontrol) { } static inline void remove_hash_entries(struct snd_card *card, struct snd_kcontrol *kcontrol) { } #endif /* CONFIG_SND_CTL_FAST_LOOKUP */ enum snd_ctl_add_mode { CTL_ADD_EXCLUSIVE, CTL_REPLACE, CTL_ADD_ON_REPLACE, }; /* add/replace a new kcontrol object; call with card->controls_rwsem locked */ static int __snd_ctl_add_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, enum snd_ctl_add_mode mode) { struct snd_ctl_elem_id id; unsigned int idx; struct snd_kcontrol *old; int err; lockdep_assert_held_write(&card->controls_rwsem); id = kcontrol->id; if (id.index > UINT_MAX - kcontrol->count) return -EINVAL; old = snd_ctl_find_id_locked(card, &id); if (!old) { if (mode == CTL_REPLACE) return -EINVAL; } else { if (mode == CTL_ADD_EXCLUSIVE) { dev_err(card->dev, "control %i:%i:%i:%s:%i is already present\n", id.iface, id.device, id.subdevice, id.name, id.index); return -EBUSY; } err = snd_ctl_remove_locked(card, old); if (err < 0) return err; } if (snd_ctl_find_hole(card, kcontrol->count) < 0) return -ENOMEM; list_add_tail(&kcontrol->list, &card->controls); card->controls_count += kcontrol->count; kcontrol->id.numid = card->last_numid + 1; card->last_numid += kcontrol->count; add_hash_entries(card, kcontrol); for (idx = 0; idx < kcontrol->count; idx++) snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_ADD, kcontrol, idx); return 0; } static int snd_ctl_add_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, enum snd_ctl_add_mode mode) { int err = -EINVAL; if (! kcontrol) return err; if (snd_BUG_ON(!card || !kcontrol->info)) goto error; down_write(&card->controls_rwsem); err = __snd_ctl_add_replace(card, kcontrol, mode); up_write(&card->controls_rwsem); if (err < 0) goto error; return 0; error: snd_ctl_free_one(kcontrol); return err; } /** * snd_ctl_add - add the control instance to the card * @card: the card instance * @kcontrol: the control instance to add * * Adds the control instance created via snd_ctl_new() or * snd_ctl_new1() to the given card. Assigns also an unique * numid used for fast search. * * It frees automatically the control which cannot be added. * * Return: Zero if successful, or a negative error code on failure. * */ int snd_ctl_add(struct snd_card *card, struct snd_kcontrol *kcontrol) { return snd_ctl_add_replace(card, kcontrol, CTL_ADD_EXCLUSIVE); } EXPORT_SYMBOL(snd_ctl_add); /** * snd_ctl_replace - replace the control instance of the card * @card: the card instance * @kcontrol: the control instance to replace * @add_on_replace: add the control if not already added * * Replaces the given control. If the given control does not exist * and the add_on_replace flag is set, the control is added. If the * control exists, it is destroyed first. * * It frees automatically the control which cannot be added or replaced. * * Return: Zero if successful, or a negative error code on failure. */ int snd_ctl_replace(struct snd_card *card, struct snd_kcontrol *kcontrol, bool add_on_replace) { return snd_ctl_add_replace(card, kcontrol, add_on_replace ? CTL_ADD_ON_REPLACE : CTL_REPLACE); } EXPORT_SYMBOL(snd_ctl_replace); static int __snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol, bool remove_hash) { unsigned int idx; lockdep_assert_held_write(&card->controls_rwsem); if (snd_BUG_ON(!card || !kcontrol)) return -EINVAL; list_del(&kcontrol->list); if (remove_hash) remove_hash_entries(card, kcontrol); card->controls_count -= kcontrol->count; for (idx = 0; idx < kcontrol->count; idx++) snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx); snd_ctl_free_one(kcontrol); return 0; } static inline int snd_ctl_remove_locked(struct snd_card *card, struct snd_kcontrol *kcontrol) { return __snd_ctl_remove(card, kcontrol, true); } /** * snd_ctl_remove - remove the control from the card and release it * @card: the card instance * @kcontrol: the control instance to remove * * Removes the control from the card and then releases the instance. * You don't need to call snd_ctl_free_one(). * * Return: 0 if successful, or a negative error code on failure. * * Note that this function takes card->controls_rwsem lock internally. */ int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol) { int ret; down_write(&card->controls_rwsem); ret = snd_ctl_remove_locked(card, kcontrol); up_write(&card->controls_rwsem); return ret; } EXPORT_SYMBOL(snd_ctl_remove); /** * snd_ctl_remove_id - remove the control of the given id and release it * @card: the card instance * @id: the control id to remove * * Finds the control instance with the given id, removes it from the * card list and releases it. * * Return: 0 if successful, or a negative error code on failure. */ int snd_ctl_remove_id(struct snd_card *card, struct snd_ctl_elem_id *id) { struct snd_kcontrol *kctl; int ret; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); if (kctl == NULL) { up_write(&card->controls_rwsem); return -ENOENT; } ret = snd_ctl_remove_locked(card, kctl); up_write(&card->controls_rwsem); return ret; } EXPORT_SYMBOL(snd_ctl_remove_id); /** * snd_ctl_remove_user_ctl - remove and release the unlocked user control * @file: active control handle * @id: the control id to remove * * Finds the control instance with the given id, removes it from the * card list and releases it. * * Return: 0 if successful, or a negative error code on failure. */ static int snd_ctl_remove_user_ctl(struct snd_ctl_file * file, struct snd_ctl_elem_id *id) { struct snd_card *card = file->card; struct snd_kcontrol *kctl; int idx, ret; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); if (kctl == NULL) { ret = -ENOENT; goto error; } if (!(kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_USER)) { ret = -EINVAL; goto error; } for (idx = 0; idx < kctl->count; idx++) if (kctl->vd[idx].owner != NULL && kctl->vd[idx].owner != file) { ret = -EBUSY; goto error; } ret = snd_ctl_remove_locked(card, kctl); error: up_write(&card->controls_rwsem); return ret; } /** * snd_ctl_activate_id - activate/inactivate the control of the given id * @card: the card instance * @id: the control id to activate/inactivate * @active: non-zero to activate * * Finds the control instance with the given id, and activate or * inactivate the control together with notification, if changed. * The given ID data is filled with full information. * * Return: 0 if unchanged, 1 if changed, or a negative error code on failure. */ int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, int active) { struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; unsigned int index_offset; int ret; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); if (kctl == NULL) { ret = -ENOENT; goto unlock; } index_offset = snd_ctl_get_ioff(kctl, id); vd = &kctl->vd[index_offset]; ret = 0; if (active) { if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)) goto unlock; vd->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; } else { if (vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE) goto unlock; vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; } snd_ctl_build_ioff(id, kctl, index_offset); downgrade_write(&card->controls_rwsem); snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_INFO, kctl, index_offset); up_read(&card->controls_rwsem); return 1; unlock: up_write(&card->controls_rwsem); return ret; } EXPORT_SYMBOL_GPL(snd_ctl_activate_id); /** * snd_ctl_rename_id - replace the id of a control on the card * @card: the card instance * @src_id: the old id * @dst_id: the new id * * Finds the control with the old id from the card, and replaces the * id with the new one. * * The function tries to keep the already assigned numid while replacing * the rest. * * Note that this function should be used only in the card initialization * phase. Calling after the card instantiation may cause issues with * user-space expecting persistent numids. * * Return: Zero if successful, or a negative error code on failure. */ int snd_ctl_rename_id(struct snd_card *card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id) { struct snd_kcontrol *kctl; int saved_numid; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, src_id); if (kctl == NULL) { up_write(&card->controls_rwsem); return -ENOENT; } saved_numid = kctl->id.numid; remove_hash_entries(card, kctl); kctl->id = *dst_id; kctl->id.numid = saved_numid; add_hash_entries(card, kctl); up_write(&card->controls_rwsem); return 0; } EXPORT_SYMBOL(snd_ctl_rename_id); /** * snd_ctl_rename - rename the control on the card * @card: the card instance * @kctl: the control to rename * @name: the new name * * Renames the specified control on the card to the new name. * * Note that this function takes card->controls_rwsem lock internally. */ void snd_ctl_rename(struct snd_card *card, struct snd_kcontrol *kctl, const char *name) { down_write(&card->controls_rwsem); remove_hash_entries(card, kctl); if (strscpy(kctl->id.name, name, sizeof(kctl->id.name)) < 0) pr_warn("ALSA: Renamed control new name '%s' truncated to '%s'\n", name, kctl->id.name); add_hash_entries(card, kctl); up_write(&card->controls_rwsem); } EXPORT_SYMBOL(snd_ctl_rename); #ifndef CONFIG_SND_CTL_FAST_LOOKUP static struct snd_kcontrol * snd_ctl_find_numid_slow(struct snd_card *card, unsigned int numid) { struct snd_kcontrol *kctl; list_for_each_entry(kctl, &card->controls, list) { if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid) return kctl; } return NULL; } #endif /* !CONFIG_SND_CTL_FAST_LOOKUP */ /** * snd_ctl_find_numid_locked - find the control instance with the given number-id * @card: the card instance * @numid: the number-id to search * * Finds the control instance with the given number-id from the card. * * The caller must down card->controls_rwsem before calling this function * (if the race condition can happen). * * Return: The pointer of the instance if found, or %NULL if not. */ struct snd_kcontrol * snd_ctl_find_numid_locked(struct snd_card *card, unsigned int numid) { if (snd_BUG_ON(!card || !numid)) return NULL; lockdep_assert_held(&card->controls_rwsem); #ifdef CONFIG_SND_CTL_FAST_LOOKUP return xa_load(&card->ctl_numids, numid); #else return snd_ctl_find_numid_slow(card, numid); #endif } EXPORT_SYMBOL(snd_ctl_find_numid_locked); /** * snd_ctl_find_numid - find the control instance with the given number-id * @card: the card instance * @numid: the number-id to search * * Finds the control instance with the given number-id from the card. * * Return: The pointer of the instance if found, or %NULL if not. * * Note that this function takes card->controls_rwsem lock internally. */ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid) { struct snd_kcontrol *kctl; down_read(&card->controls_rwsem); kctl = snd_ctl_find_numid_locked(card, numid); up_read(&card->controls_rwsem); return kctl; } EXPORT_SYMBOL(snd_ctl_find_numid); /** * snd_ctl_find_id_locked - find the control instance with the given id * @card: the card instance * @id: the id to search * * Finds the control instance with the given id from the card. * * The caller must down card->controls_rwsem before calling this function * (if the race condition can happen). * * Return: The pointer of the instance if found, or %NULL if not. */ struct snd_kcontrol *snd_ctl_find_id_locked(struct snd_card *card, const struct snd_ctl_elem_id *id) { struct snd_kcontrol *kctl; if (snd_BUG_ON(!card || !id)) return NULL; lockdep_assert_held(&card->controls_rwsem); if (id->numid != 0) return snd_ctl_find_numid_locked(card, id->numid); #ifdef CONFIG_SND_CTL_FAST_LOOKUP kctl = xa_load(&card->ctl_hash, get_ctl_id_hash(id)); if (kctl && elem_id_matches(kctl, id)) return kctl; if (!card->ctl_hash_collision) return NULL; /* we can rely on only hash table */ #endif /* no matching in hash table - try all as the last resort */ list_for_each_entry(kctl, &card->controls, list) if (elem_id_matches(kctl, id)) return kctl; return NULL; } EXPORT_SYMBOL(snd_ctl_find_id_locked); /** * snd_ctl_find_id - find the control instance with the given id * @card: the card instance * @id: the id to search * * Finds the control instance with the given id from the card. * * Return: The pointer of the instance if found, or %NULL if not. * * Note that this function takes card->controls_rwsem lock internally. */ struct snd_kcontrol *snd_ctl_find_id(struct snd_card *card, const struct snd_ctl_elem_id *id) { struct snd_kcontrol *kctl; down_read(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); up_read(&card->controls_rwsem); return kctl; } EXPORT_SYMBOL(snd_ctl_find_id); static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl, unsigned int cmd, void __user *arg) { struct snd_ctl_card_info *info; info = kzalloc(sizeof(*info), GFP_KERNEL); if (! info) return -ENOMEM; down_read(&snd_ioctl_rwsem); info->card = card->number; strscpy(info->id, card->id, sizeof(info->id)); strscpy(info->driver, card->driver, sizeof(info->driver)); strscpy(info->name, card->shortname, sizeof(info->name)); strscpy(info->longname, card->longname, sizeof(info->longname)); strscpy(info->mixername, card->mixername, sizeof(info->mixername)); strscpy(info->components, card->components, sizeof(info->components)); up_read(&snd_ioctl_rwsem); if (copy_to_user(arg, info, sizeof(struct snd_ctl_card_info))) { kfree(info); return -EFAULT; } kfree(info); return 0; } static int snd_ctl_elem_list(struct snd_card *card, struct snd_ctl_elem_list *list) { struct snd_kcontrol *kctl; struct snd_ctl_elem_id id; unsigned int offset, space, jidx; int err = 0; offset = list->offset; space = list->space; down_read(&card->controls_rwsem); list->count = card->controls_count; list->used = 0; if (space > 0) { list_for_each_entry(kctl, &card->controls, list) { if (offset >= kctl->count) { offset -= kctl->count; continue; } for (jidx = offset; jidx < kctl->count; jidx++) { snd_ctl_build_ioff(&id, kctl, jidx); if (copy_to_user(list->pids + list->used, &id, sizeof(id))) { err = -EFAULT; goto out; } list->used++; if (!--space) goto out; } offset = 0; } } out: up_read(&card->controls_rwsem); return err; } static int snd_ctl_elem_list_user(struct snd_card *card, struct snd_ctl_elem_list __user *_list) { struct snd_ctl_elem_list list; int err; if (copy_from_user(&list, _list, sizeof(list))) return -EFAULT; err = snd_ctl_elem_list(card, &list); if (err) return err; if (copy_to_user(_list, &list, sizeof(list))) return -EFAULT; return 0; } /* Check whether the given kctl info is valid */ static int snd_ctl_check_elem_info(struct snd_card *card, const struct snd_ctl_elem_info *info) { static const unsigned int max_value_counts[] = { [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = 128, [SNDRV_CTL_ELEM_TYPE_INTEGER] = 128, [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = 128, [SNDRV_CTL_ELEM_TYPE_BYTES] = 512, [SNDRV_CTL_ELEM_TYPE_IEC958] = 1, [SNDRV_CTL_ELEM_TYPE_INTEGER64] = 64, }; if (info->type < SNDRV_CTL_ELEM_TYPE_BOOLEAN || info->type > SNDRV_CTL_ELEM_TYPE_INTEGER64) { if (card) dev_err(card->dev, "control %i:%i:%i:%s:%i: invalid type %d\n", info->id.iface, info->id.device, info->id.subdevice, info->id.name, info->id.index, info->type); return -EINVAL; } if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED && info->value.enumerated.items == 0) { if (card) dev_err(card->dev, "control %i:%i:%i:%s:%i: zero enum items\n", info->id.iface, info->id.device, info->id.subdevice, info->id.name, info->id.index); return -EINVAL; } if (info->count > max_value_counts[info->type]) { if (card) dev_err(card->dev, "control %i:%i:%i:%s:%i: invalid count %d\n", info->id.iface, info->id.device, info->id.subdevice, info->id.name, info->id.index, info->count); return -EINVAL; } return 0; } /* The capacity of struct snd_ctl_elem_value.value.*/ static const unsigned int value_sizes[] = { [SNDRV_CTL_ELEM_TYPE_BOOLEAN] = sizeof(long), [SNDRV_CTL_ELEM_TYPE_INTEGER] = sizeof(long), [SNDRV_CTL_ELEM_TYPE_ENUMERATED] = sizeof(unsigned int), [SNDRV_CTL_ELEM_TYPE_BYTES] = sizeof(unsigned char), [SNDRV_CTL_ELEM_TYPE_IEC958] = sizeof(struct snd_aes_iec958), [SNDRV_CTL_ELEM_TYPE_INTEGER64] = sizeof(long long), }; /* fill the remaining snd_ctl_elem_value data with the given pattern */ static void fill_remaining_elem_value(struct snd_ctl_elem_value *control, struct snd_ctl_elem_info *info, u32 pattern) { size_t offset = value_sizes[info->type] * info->count; offset = DIV_ROUND_UP(offset, sizeof(u32)); memset32((u32 *)control->value.bytes.data + offset, pattern, sizeof(control->value) / sizeof(u32) - offset); } /* check whether the given integer ctl value is valid */ static int sanity_check_int_value(struct snd_card *card, const struct snd_ctl_elem_value *control, const struct snd_ctl_elem_info *info, int i, bool print_error) { long long lval, lmin, lmax, lstep; u64 rem; switch (info->type) { default: case SNDRV_CTL_ELEM_TYPE_BOOLEAN: lval = control->value.integer.value[i]; lmin = 0; lmax = 1; lstep = 0; break; case SNDRV_CTL_ELEM_TYPE_INTEGER: lval = control->value.integer.value[i]; lmin = info->value.integer.min; lmax = info->value.integer.max; lstep = info->value.integer.step; break; case SNDRV_CTL_ELEM_TYPE_INTEGER64: lval = control->value.integer64.value[i]; lmin = info->value.integer64.min; lmax = info->value.integer64.max; lstep = info->value.integer64.step; break; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: lval = control->value.enumerated.item[i]; lmin = 0; lmax = info->value.enumerated.items - 1; lstep = 0; break; } if (lval < lmin || lval > lmax) { if (print_error) dev_err(card->dev, "control %i:%i:%i:%s:%i: value out of range %lld (%lld/%lld) at count %i\n", control->id.iface, control->id.device, control->id.subdevice, control->id.name, control->id.index, lval, lmin, lmax, i); return -EINVAL; } if (lstep) { div64_u64_rem(lval, lstep, &rem); if (rem) { if (print_error) dev_err(card->dev, "control %i:%i:%i:%s:%i: unaligned value %lld (step %lld) at count %i\n", control->id.iface, control->id.device, control->id.subdevice, control->id.name, control->id.index, lval, lstep, i); return -EINVAL; } } return 0; } /* check whether the all input values are valid for the given elem value */ static int sanity_check_input_values(struct snd_card *card, const struct snd_ctl_elem_value *control, const struct snd_ctl_elem_info *info, bool print_error) { int i, ret; switch (info->type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: case SNDRV_CTL_ELEM_TYPE_INTEGER: case SNDRV_CTL_ELEM_TYPE_INTEGER64: case SNDRV_CTL_ELEM_TYPE_ENUMERATED: for (i = 0; i < info->count; i++) { ret = sanity_check_int_value(card, control, info, i, print_error); if (ret < 0) return ret; } break; default: break; } return 0; } /* perform sanity checks to the given snd_ctl_elem_value object */ static int sanity_check_elem_value(struct snd_card *card, const struct snd_ctl_elem_value *control, const struct snd_ctl_elem_info *info, u32 pattern) { size_t offset; int ret; u32 *p; ret = sanity_check_input_values(card, control, info, true); if (ret < 0) return ret; /* check whether the remaining area kept untouched */ offset = value_sizes[info->type] * info->count; offset = DIV_ROUND_UP(offset, sizeof(u32)); p = (u32 *)control->value.bytes.data + offset; for (; offset < sizeof(control->value) / sizeof(u32); offset++, p++) { if (*p != pattern) { ret = -EINVAL; break; } *p = 0; /* clear the checked area */ } return ret; } static int __snd_ctl_elem_info(struct snd_card *card, struct snd_kcontrol *kctl, struct snd_ctl_elem_info *info, struct snd_ctl_file *ctl) { struct snd_kcontrol_volatile *vd; unsigned int index_offset; int result; #ifdef CONFIG_SND_DEBUG info->access = 0; #endif result = snd_power_ref_and_wait(card); if (!result) result = kctl->info(kctl, info); snd_power_unref(card); if (result >= 0) { snd_BUG_ON(info->access); index_offset = snd_ctl_get_ioff(kctl, &info->id); vd = &kctl->vd[index_offset]; snd_ctl_build_ioff(&info->id, kctl, index_offset); info->access = vd->access; if (vd->owner) { info->access |= SNDRV_CTL_ELEM_ACCESS_LOCK; if (vd->owner == ctl) info->access |= SNDRV_CTL_ELEM_ACCESS_OWNER; info->owner = pid_vnr(vd->owner->pid); } else { info->owner = -1; } if (!snd_ctl_skip_validation(info) && snd_ctl_check_elem_info(card, info) < 0) result = -EINVAL; } return result; } static int snd_ctl_elem_info(struct snd_ctl_file *ctl, struct snd_ctl_elem_info *info) { struct snd_card *card = ctl->card; struct snd_kcontrol *kctl; int result; down_read(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, &info->id); if (kctl == NULL) result = -ENOENT; else result = __snd_ctl_elem_info(card, kctl, info, ctl); up_read(&card->controls_rwsem); return result; } static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl, struct snd_ctl_elem_info __user *_info) { struct snd_ctl_elem_info info; int result; if (copy_from_user(&info, _info, sizeof(info))) return -EFAULT; result = snd_ctl_elem_info(ctl, &info); if (result < 0) return result; /* drop internal access flags */ info.access &= ~(SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK| SNDRV_CTL_ELEM_ACCESS_LED_MASK); if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return result; } static int snd_ctl_elem_read(struct snd_card *card, struct snd_ctl_elem_value *control) { struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; unsigned int index_offset; struct snd_ctl_elem_info info; const u32 pattern = 0xdeadbeef; int ret; down_read(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, &control->id); if (kctl == NULL) { ret = -ENOENT; goto unlock; } index_offset = snd_ctl_get_ioff(kctl, &control->id); vd = &kctl->vd[index_offset]; if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_READ) || kctl->get == NULL) { ret = -EPERM; goto unlock; } snd_ctl_build_ioff(&control->id, kctl, index_offset); #ifdef CONFIG_SND_CTL_DEBUG /* info is needed only for validation */ memset(&info, 0, sizeof(info)); info.id = control->id; ret = __snd_ctl_elem_info(card, kctl, &info, NULL); if (ret < 0) goto unlock; #endif if (!snd_ctl_skip_validation(&info)) fill_remaining_elem_value(control, &info, pattern); ret = snd_power_ref_and_wait(card); if (!ret) ret = kctl->get(kctl, control); snd_power_unref(card); if (ret < 0) goto unlock; if (!snd_ctl_skip_validation(&info) && sanity_check_elem_value(card, control, &info, pattern) < 0) { dev_err(card->dev, "control %i:%i:%i:%s:%i: access overflow\n", control->id.iface, control->id.device, control->id.subdevice, control->id.name, control->id.index); ret = -EINVAL; goto unlock; } unlock: up_read(&card->controls_rwsem); return ret; } static int snd_ctl_elem_read_user(struct snd_card *card, struct snd_ctl_elem_value __user *_control) { struct snd_ctl_elem_value *control; int result; control = memdup_user(_control, sizeof(*control)); if (IS_ERR(control)) return PTR_ERR(control); result = snd_ctl_elem_read(card, control); if (result < 0) goto error; if (copy_to_user(_control, control, sizeof(*control))) result = -EFAULT; error: kfree(control); return result; } static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file, struct snd_ctl_elem_value *control) { struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; unsigned int index_offset; int result; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, &control->id); if (kctl == NULL) { up_write(&card->controls_rwsem); return -ENOENT; } index_offset = snd_ctl_get_ioff(kctl, &control->id); vd = &kctl->vd[index_offset]; if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_WRITE) || kctl->put == NULL || (file && vd->owner && vd->owner != file)) { up_write(&card->controls_rwsem); return -EPERM; } snd_ctl_build_ioff(&control->id, kctl, index_offset); result = snd_power_ref_and_wait(card); /* validate input values */ if (IS_ENABLED(CONFIG_SND_CTL_INPUT_VALIDATION) && !result) { struct snd_ctl_elem_info info; memset(&info, 0, sizeof(info)); info.id = control->id; result = __snd_ctl_elem_info(card, kctl, &info, NULL); if (!result) result = sanity_check_input_values(card, control, &info, false); } if (!result) result = kctl->put(kctl, control); snd_power_unref(card); if (result < 0) { up_write(&card->controls_rwsem); return result; } if (result > 0) { downgrade_write(&card->controls_rwsem); snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_VALUE, kctl, index_offset); up_read(&card->controls_rwsem); } else { up_write(&card->controls_rwsem); } return 0; } static int snd_ctl_elem_write_user(struct snd_ctl_file *file, struct snd_ctl_elem_value __user *_control) { struct snd_ctl_elem_value *control; struct snd_card *card; int result; control = memdup_user(_control, sizeof(*control)); if (IS_ERR(control)) return PTR_ERR(control); card = file->card; result = snd_ctl_elem_write(card, file, control); if (result < 0) goto error; if (copy_to_user(_control, control, sizeof(*control))) result = -EFAULT; error: kfree(control); return result; } static int snd_ctl_elem_lock(struct snd_ctl_file *file, struct snd_ctl_elem_id __user *_id) { struct snd_card *card = file->card; struct snd_ctl_elem_id id; struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; int result; if (copy_from_user(&id, _id, sizeof(id))) return -EFAULT; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, &id); if (kctl == NULL) { result = -ENOENT; } else { vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; if (vd->owner != NULL) result = -EBUSY; else { vd->owner = file; result = 0; } } up_write(&card->controls_rwsem); return result; } static int snd_ctl_elem_unlock(struct snd_ctl_file *file, struct snd_ctl_elem_id __user *_id) { struct snd_card *card = file->card; struct snd_ctl_elem_id id; struct snd_kcontrol *kctl; struct snd_kcontrol_volatile *vd; int result; if (copy_from_user(&id, _id, sizeof(id))) return -EFAULT; down_write(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, &id); if (kctl == NULL) { result = -ENOENT; } else { vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; if (vd->owner == NULL) result = -EINVAL; else if (vd->owner != file) result = -EPERM; else { vd->owner = NULL; result = 0; } } up_write(&card->controls_rwsem); return result; } struct user_element { struct snd_ctl_elem_info info; struct snd_card *card; char *elem_data; /* element data */ unsigned long elem_data_size; /* size of element data in bytes */ void *tlv_data; /* TLV data */ unsigned long tlv_data_size; /* TLV data size */ void *priv_data; /* private data (like strings for enumerated type) */ }; // check whether the addition (in bytes) of user ctl element may overflow the limit. static bool check_user_elem_overflow(struct snd_card *card, ssize_t add) { return (ssize_t)card->user_ctl_alloc_size + add > max_user_ctl_alloc_size; } static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct user_element *ue = kcontrol->private_data; unsigned int offset; offset = snd_ctl_get_ioff(kcontrol, &uinfo->id); *uinfo = ue->info; snd_ctl_build_ioff(&uinfo->id, kcontrol, offset); return 0; } static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct user_element *ue = kcontrol->private_data; const char *names; unsigned int item; unsigned int offset; item = uinfo->value.enumerated.item; offset = snd_ctl_get_ioff(kcontrol, &uinfo->id); *uinfo = ue->info; snd_ctl_build_ioff(&uinfo->id, kcontrol, offset); item = min(item, uinfo->value.enumerated.items - 1); uinfo->value.enumerated.item = item; names = ue->priv_data; for (; item > 0; --item) names += strlen(names) + 1; strcpy(uinfo->value.enumerated.name, names); return 0; } static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct user_element *ue = kcontrol->private_data; unsigned int size = ue->elem_data_size; char *src = ue->elem_data + snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size; memcpy(&ucontrol->value, src, size); return 0; } static int snd_ctl_elem_user_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { int change; struct user_element *ue = kcontrol->private_data; unsigned int size = ue->elem_data_size; char *dst = ue->elem_data + snd_ctl_get_ioff(kcontrol, &ucontrol->id) * size; change = memcmp(&ucontrol->value, dst, size) != 0; if (change) memcpy(dst, &ucontrol->value, size); return change; } /* called in controls_rwsem write lock */ static int replace_user_tlv(struct snd_kcontrol *kctl, unsigned int __user *buf, unsigned int size) { struct user_element *ue = kctl->private_data; unsigned int *container; unsigned int mask = 0; int i; int change; lockdep_assert_held_write(&ue->card->controls_rwsem); if (size > 1024 * 128) /* sane value */ return -EINVAL; // does the TLV size change cause overflow? if (check_user_elem_overflow(ue->card, (ssize_t)(size - ue->tlv_data_size))) return -ENOMEM; container = vmemdup_user(buf, size); if (IS_ERR(container)) return PTR_ERR(container); change = ue->tlv_data_size != size; if (!change) change = memcmp(ue->tlv_data, container, size) != 0; if (!change) { kvfree(container); return 0; } if (ue->tlv_data == NULL) { /* Now TLV data is available. */ for (i = 0; i < kctl->count; ++i) kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; mask = SNDRV_CTL_EVENT_MASK_INFO; } else { ue->card->user_ctl_alloc_size -= ue->tlv_data_size; ue->tlv_data_size = 0; kvfree(ue->tlv_data); } ue->tlv_data = container; ue->tlv_data_size = size; // decremented at private_free. ue->card->user_ctl_alloc_size += size; mask |= SNDRV_CTL_EVENT_MASK_TLV; for (i = 0; i < kctl->count; ++i) snd_ctl_notify_one(ue->card, mask, kctl, i); return change; } static int read_user_tlv(struct snd_kcontrol *kctl, unsigned int __user *buf, unsigned int size) { struct user_element *ue = kctl->private_data; if (ue->tlv_data_size == 0 || ue->tlv_data == NULL) return -ENXIO; if (size < ue->tlv_data_size) return -ENOSPC; if (copy_to_user(buf, ue->tlv_data, ue->tlv_data_size)) return -EFAULT; return 0; } static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kctl, int op_flag, unsigned int size, unsigned int __user *buf) { if (op_flag == SNDRV_CTL_TLV_OP_WRITE) return replace_user_tlv(kctl, buf, size); else return read_user_tlv(kctl, buf, size); } /* called in controls_rwsem write lock */ static int snd_ctl_elem_init_enum_names(struct user_element *ue) { char *names, *p; size_t buf_len, name_len; unsigned int i; const uintptr_t user_ptrval = ue->info.value.enumerated.names_ptr; lockdep_assert_held_write(&ue->card->controls_rwsem); buf_len = ue->info.value.enumerated.names_length; if (buf_len > 64 * 1024) return -EINVAL; if (check_user_elem_overflow(ue->card, buf_len)) return -ENOMEM; names = vmemdup_user((const void __user *)user_ptrval, buf_len); if (IS_ERR(names)) return PTR_ERR(names); /* check that there are enough valid names */ p = names; for (i = 0; i < ue->info.value.enumerated.items; ++i) { name_len = strnlen(p, buf_len); if (name_len == 0 || name_len >= 64 || name_len == buf_len) { kvfree(names); return -EINVAL; } p += name_len + 1; buf_len -= name_len + 1; } ue->priv_data = names; ue->info.value.enumerated.names_ptr = 0; // increment the allocation size; decremented again at private_free. ue->card->user_ctl_alloc_size += ue->info.value.enumerated.names_length; return 0; } static size_t compute_user_elem_size(size_t size, unsigned int count) { return sizeof(struct user_element) + size * count; } static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol) { struct user_element *ue = kcontrol->private_data; // decrement the allocation size. ue->card->user_ctl_alloc_size -= compute_user_elem_size(ue->elem_data_size, kcontrol->count); ue->card->user_ctl_alloc_size -= ue->tlv_data_size; if (ue->priv_data) ue->card->user_ctl_alloc_size -= ue->info.value.enumerated.names_length; kvfree(ue->tlv_data); kvfree(ue->priv_data); kfree(ue); } static int snd_ctl_elem_add(struct snd_ctl_file *file, struct snd_ctl_elem_info *info, int replace) { struct snd_card *card = file->card; struct snd_kcontrol *kctl; unsigned int count; unsigned int access; long private_size; size_t alloc_size; struct user_element *ue; unsigned int offset; int err; if (!*info->id.name) return -EINVAL; if (strnlen(info->id.name, sizeof(info->id.name)) >= sizeof(info->id.name)) return -EINVAL; /* Delete a control to replace them if needed. */ if (replace) { info->id.numid = 0; err = snd_ctl_remove_user_ctl(file, &info->id); if (err) return err; } /* Check the number of elements for this userspace control. */ count = info->owner; if (count == 0) count = 1; /* Arrange access permissions if needed. */ access = info->access; if (access == 0) access = SNDRV_CTL_ELEM_ACCESS_READWRITE; access &= (SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE | SNDRV_CTL_ELEM_ACCESS_TLV_WRITE); /* In initial state, nothing is available as TLV container. */ if (access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) access |= SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; access |= SNDRV_CTL_ELEM_ACCESS_USER; /* * Check information and calculate the size of data specific to * this userspace control. */ /* pass NULL to card for suppressing error messages */ err = snd_ctl_check_elem_info(NULL, info); if (err < 0) return err; /* user-space control doesn't allow zero-size data */ if (info->count < 1) return -EINVAL; private_size = value_sizes[info->type] * info->count; alloc_size = compute_user_elem_size(private_size, count); down_write(&card->controls_rwsem); if (check_user_elem_overflow(card, alloc_size)) { err = -ENOMEM; goto unlock; } /* * Keep memory object for this userspace control. After passing this * code block, the instance should be freed by snd_ctl_free_one(). * * Note that these elements in this control are locked. */ err = snd_ctl_new(&kctl, count, access, file); if (err < 0) goto unlock; memcpy(&kctl->id, &info->id, sizeof(kctl->id)); ue = kzalloc(alloc_size, GFP_KERNEL); if (!ue) { kfree(kctl); err = -ENOMEM; goto unlock; } kctl->private_data = ue; kctl->private_free = snd_ctl_elem_user_free; // increment the allocated size; decremented again at private_free. card->user_ctl_alloc_size += alloc_size; /* Set private data for this userspace control. */ ue->card = card; ue->info = *info; ue->info.access = 0; ue->elem_data = (char *)ue + sizeof(*ue); ue->elem_data_size = private_size; if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) { err = snd_ctl_elem_init_enum_names(ue); if (err < 0) { snd_ctl_free_one(kctl); goto unlock; } } /* Set callback functions. */ if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) kctl->info = snd_ctl_elem_user_enum_info; else kctl->info = snd_ctl_elem_user_info; if (access & SNDRV_CTL_ELEM_ACCESS_READ) kctl->get = snd_ctl_elem_user_get; if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) kctl->put = snd_ctl_elem_user_put; if (access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) kctl->tlv.c = snd_ctl_elem_user_tlv; /* This function manage to free the instance on failure. */ err = __snd_ctl_add_replace(card, kctl, CTL_ADD_EXCLUSIVE); if (err < 0) { snd_ctl_free_one(kctl); goto unlock; } offset = snd_ctl_get_ioff(kctl, &info->id); snd_ctl_build_ioff(&info->id, kctl, offset); /* * Here we cannot fill any field for the number of elements added by * this operation because there're no specific fields. The usage of * 'owner' field for this purpose may cause any bugs to userspace * applications because the field originally means PID of a process * which locks the element. */ unlock: up_write(&card->controls_rwsem); return err; } static int snd_ctl_elem_add_user(struct snd_ctl_file *file, struct snd_ctl_elem_info __user *_info, int replace) { struct snd_ctl_elem_info info; int err; if (copy_from_user(&info, _info, sizeof(info))) return -EFAULT; err = snd_ctl_elem_add(file, &info, replace); if (err < 0) return err; if (copy_to_user(_info, &info, sizeof(info))) { snd_ctl_remove_user_ctl(file, &info.id); return -EFAULT; } return 0; } static int snd_ctl_elem_remove(struct snd_ctl_file *file, struct snd_ctl_elem_id __user *_id) { struct snd_ctl_elem_id id; if (copy_from_user(&id, _id, sizeof(id))) return -EFAULT; return snd_ctl_remove_user_ctl(file, &id); } static int snd_ctl_subscribe_events(struct snd_ctl_file *file, int __user *ptr) { int subscribe; if (get_user(subscribe, ptr)) return -EFAULT; if (subscribe < 0) { subscribe = file->subscribed; if (put_user(subscribe, ptr)) return -EFAULT; return 0; } if (subscribe) { file->subscribed = 1; return 0; } else if (file->subscribed) { snd_ctl_empty_read_queue(file); file->subscribed = 0; } return 0; } static int call_tlv_handler(struct snd_ctl_file *file, int op_flag, struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id, unsigned int __user *buf, unsigned int size) { static const struct { int op; int perm; } pairs[] = { {SNDRV_CTL_TLV_OP_READ, SNDRV_CTL_ELEM_ACCESS_TLV_READ}, {SNDRV_CTL_TLV_OP_WRITE, SNDRV_CTL_ELEM_ACCESS_TLV_WRITE}, {SNDRV_CTL_TLV_OP_CMD, SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND}, }; struct snd_kcontrol_volatile *vd = &kctl->vd[snd_ctl_get_ioff(kctl, id)]; int i, ret; /* Check support of the request for this element. */ for (i = 0; i < ARRAY_SIZE(pairs); ++i) { if (op_flag == pairs[i].op && (vd->access & pairs[i].perm)) break; } if (i == ARRAY_SIZE(pairs)) return -ENXIO; if (kctl->tlv.c == NULL) return -ENXIO; /* Write and command operations are not allowed for locked element. */ if (op_flag != SNDRV_CTL_TLV_OP_READ && vd->owner != NULL && vd->owner != file) return -EPERM; ret = snd_power_ref_and_wait(file->card); if (!ret) ret = kctl->tlv.c(kctl, op_flag, size, buf); snd_power_unref(file->card); return ret; } static int read_tlv_buf(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id, unsigned int __user *buf, unsigned int size) { struct snd_kcontrol_volatile *vd = &kctl->vd[snd_ctl_get_ioff(kctl, id)]; unsigned int len; if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)) return -ENXIO; if (kctl->tlv.p == NULL) return -ENXIO; len = sizeof(unsigned int) * 2 + kctl->tlv.p[1]; if (size < len) return -ENOMEM; if (copy_to_user(buf, kctl->tlv.p, len)) return -EFAULT; return 0; } static int snd_ctl_tlv_ioctl(struct snd_ctl_file *file, struct snd_ctl_tlv __user *buf, int op_flag) { struct snd_ctl_tlv header; unsigned int __user *container; unsigned int container_size; struct snd_kcontrol *kctl; struct snd_ctl_elem_id id; struct snd_kcontrol_volatile *vd; lockdep_assert_held(&file->card->controls_rwsem); if (copy_from_user(&header, buf, sizeof(header))) return -EFAULT; /* In design of control core, numerical ID starts at 1. */ if (header.numid == 0) return -EINVAL; /* At least, container should include type and length fields. */ if (header.length < sizeof(unsigned int) * 2) return -EINVAL; container_size = header.length; container = buf->tlv; kctl = snd_ctl_find_numid_locked(file->card, header.numid); if (kctl == NULL) return -ENOENT; /* Calculate index of the element in this set. */ id = kctl->id; snd_ctl_build_ioff(&id, kctl, header.numid - id.numid); vd = &kctl->vd[snd_ctl_get_ioff(kctl, &id)]; if (vd->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { return call_tlv_handler(file, op_flag, kctl, &id, container, container_size); } else { if (op_flag == SNDRV_CTL_TLV_OP_READ) { return read_tlv_buf(kctl, &id, container, container_size); } } /* Not supported. */ return -ENXIO; } static long snd_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_ctl_file *ctl; struct snd_card *card; struct snd_kctl_ioctl *p; void __user *argp = (void __user *)arg; int __user *ip = argp; int err; ctl = file->private_data; card = ctl->card; if (snd_BUG_ON(!card)) return -ENXIO; switch (cmd) { case SNDRV_CTL_IOCTL_PVERSION: return put_user(SNDRV_CTL_VERSION, ip) ? -EFAULT : 0; case SNDRV_CTL_IOCTL_CARD_INFO: return snd_ctl_card_info(card, ctl, cmd, argp); case SNDRV_CTL_IOCTL_ELEM_LIST: return snd_ctl_elem_list_user(card, argp); case SNDRV_CTL_IOCTL_ELEM_INFO: return snd_ctl_elem_info_user(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_READ: return snd_ctl_elem_read_user(card, argp); case SNDRV_CTL_IOCTL_ELEM_WRITE: return snd_ctl_elem_write_user(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_LOCK: return snd_ctl_elem_lock(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_UNLOCK: return snd_ctl_elem_unlock(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_ADD: return snd_ctl_elem_add_user(ctl, argp, 0); case SNDRV_CTL_IOCTL_ELEM_REPLACE: return snd_ctl_elem_add_user(ctl, argp, 1); case SNDRV_CTL_IOCTL_ELEM_REMOVE: return snd_ctl_elem_remove(ctl, argp); case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS: return snd_ctl_subscribe_events(ctl, ip); case SNDRV_CTL_IOCTL_TLV_READ: down_read(&ctl->card->controls_rwsem); err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_READ); up_read(&ctl->card->controls_rwsem); return err; case SNDRV_CTL_IOCTL_TLV_WRITE: down_write(&ctl->card->controls_rwsem); err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_WRITE); up_write(&ctl->card->controls_rwsem); return err; case SNDRV_CTL_IOCTL_TLV_COMMAND: down_write(&ctl->card->controls_rwsem); err = snd_ctl_tlv_ioctl(ctl, argp, SNDRV_CTL_TLV_OP_CMD); up_write(&ctl->card->controls_rwsem); return err; case SNDRV_CTL_IOCTL_POWER: return -ENOPROTOOPT; case SNDRV_CTL_IOCTL_POWER_STATE: return put_user(SNDRV_CTL_POWER_D0, ip) ? -EFAULT : 0; } down_read(&snd_ioctl_rwsem); list_for_each_entry(p, &snd_control_ioctls, list) { err = p->fioctl(card, ctl, cmd, arg); if (err != -ENOIOCTLCMD) { up_read(&snd_ioctl_rwsem); return err; } } up_read(&snd_ioctl_rwsem); dev_dbg(card->dev, "unknown ioctl = 0x%x\n", cmd); return -ENOTTY; } static ssize_t snd_ctl_read(struct file *file, char __user *buffer, size_t count, loff_t * offset) { struct snd_ctl_file *ctl; int err = 0; ssize_t result = 0; ctl = file->private_data; if (snd_BUG_ON(!ctl || !ctl->card)) return -ENXIO; if (!ctl->subscribed) return -EBADFD; if (count < sizeof(struct snd_ctl_event)) return -EINVAL; spin_lock_irq(&ctl->read_lock); while (count >= sizeof(struct snd_ctl_event)) { struct snd_ctl_event ev; struct snd_kctl_event *kev; while (list_empty(&ctl->events)) { wait_queue_entry_t wait; if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) { err = -EAGAIN; goto __end_lock; } init_waitqueue_entry(&wait, current); add_wait_queue(&ctl->change_sleep, &wait); set_current_state(TASK_INTERRUPTIBLE); spin_unlock_irq(&ctl->read_lock); schedule(); remove_wait_queue(&ctl->change_sleep, &wait); if (ctl->card->shutdown) return -ENODEV; if (signal_pending(current)) return -ERESTARTSYS; spin_lock_irq(&ctl->read_lock); } kev = snd_kctl_event(ctl->events.next); ev.type = SNDRV_CTL_EVENT_ELEM; ev.data.elem.mask = kev->mask; ev.data.elem.id = kev->id; list_del(&kev->list); spin_unlock_irq(&ctl->read_lock); kfree(kev); if (copy_to_user(buffer, &ev, sizeof(struct snd_ctl_event))) { err = -EFAULT; goto __end; } spin_lock_irq(&ctl->read_lock); buffer += sizeof(struct snd_ctl_event); count -= sizeof(struct snd_ctl_event); result += sizeof(struct snd_ctl_event); } __end_lock: spin_unlock_irq(&ctl->read_lock); __end: return result > 0 ? result : err; } static __poll_t snd_ctl_poll(struct file *file, poll_table * wait) { __poll_t mask; struct snd_ctl_file *ctl; ctl = file->private_data; if (!ctl->subscribed) return 0; poll_wait(file, &ctl->change_sleep, wait); mask = 0; if (!list_empty(&ctl->events)) mask |= EPOLLIN | EPOLLRDNORM; return mask; } /* * register the device-specific control-ioctls. * called from each device manager like pcm.c, hwdep.c, etc. */ static int _snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head *lists) { struct snd_kctl_ioctl *pn; pn = kzalloc(sizeof(struct snd_kctl_ioctl), GFP_KERNEL); if (pn == NULL) return -ENOMEM; pn->fioctl = fcn; down_write(&snd_ioctl_rwsem); list_add_tail(&pn->list, lists); up_write(&snd_ioctl_rwsem); return 0; } /** * snd_ctl_register_ioctl - register the device-specific control-ioctls * @fcn: ioctl callback function * * called from each device manager like pcm.c, hwdep.c, etc. * * Return: zero if successful, or a negative error code */ int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn) { return _snd_ctl_register_ioctl(fcn, &snd_control_ioctls); } EXPORT_SYMBOL(snd_ctl_register_ioctl); #ifdef CONFIG_COMPAT /** * snd_ctl_register_ioctl_compat - register the device-specific 32bit compat * control-ioctls * @fcn: ioctl callback function * * Return: zero if successful, or a negative error code */ int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn) { return _snd_ctl_register_ioctl(fcn, &snd_control_compat_ioctls); } EXPORT_SYMBOL(snd_ctl_register_ioctl_compat); #endif /* * de-register the device-specific control-ioctls. */ static int _snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn, struct list_head *lists) { struct snd_kctl_ioctl *p; if (snd_BUG_ON(!fcn)) return -EINVAL; down_write(&snd_ioctl_rwsem); list_for_each_entry(p, lists, list) { if (p->fioctl == fcn) { list_del(&p->list); up_write(&snd_ioctl_rwsem); kfree(p); return 0; } } up_write(&snd_ioctl_rwsem); snd_BUG(); return -EINVAL; } /** * snd_ctl_unregister_ioctl - de-register the device-specific control-ioctls * @fcn: ioctl callback function to unregister * * Return: zero if successful, or a negative error code */ int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn) { return _snd_ctl_unregister_ioctl(fcn, &snd_control_ioctls); } EXPORT_SYMBOL(snd_ctl_unregister_ioctl); #ifdef CONFIG_COMPAT /** * snd_ctl_unregister_ioctl_compat - de-register the device-specific compat * 32bit control-ioctls * @fcn: ioctl callback function to unregister * * Return: zero if successful, or a negative error code */ int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn) { return _snd_ctl_unregister_ioctl(fcn, &snd_control_compat_ioctls); } EXPORT_SYMBOL(snd_ctl_unregister_ioctl_compat); #endif static int snd_ctl_fasync(int fd, struct file * file, int on) { struct snd_ctl_file *ctl; ctl = file->private_data; return snd_fasync_helper(fd, file, on, &ctl->fasync); } /* return the preferred subdevice number if already assigned; * otherwise return -1 */ int snd_ctl_get_preferred_subdevice(struct snd_card *card, int type) { struct snd_ctl_file *kctl; int subdevice = -1; unsigned long flags; read_lock_irqsave(&card->ctl_files_rwlock, flags); list_for_each_entry(kctl, &card->ctl_files, list) { if (kctl->pid == task_pid(current)) { subdevice = kctl->preferred_subdevice[type]; if (subdevice != -1) break; } } read_unlock_irqrestore(&card->ctl_files_rwlock, flags); return subdevice; } EXPORT_SYMBOL_GPL(snd_ctl_get_preferred_subdevice); /* * ioctl32 compat */ #ifdef CONFIG_COMPAT #include "control_compat.c" #else #define snd_ctl_ioctl_compat NULL #endif /* * control layers (audio LED etc.) */ /** * snd_ctl_request_layer - request to use the layer * @module_name: Name of the kernel module (NULL == build-in) * * Return: zero if successful, or an error code when the module cannot be loaded */ int snd_ctl_request_layer(const char *module_name) { struct snd_ctl_layer_ops *lops; if (module_name == NULL) return 0; down_read(&snd_ctl_layer_rwsem); for (lops = snd_ctl_layer; lops; lops = lops->next) if (strcmp(lops->module_name, module_name) == 0) break; up_read(&snd_ctl_layer_rwsem); if (lops) return 0; return request_module(module_name); } EXPORT_SYMBOL_GPL(snd_ctl_request_layer); /** * snd_ctl_register_layer - register new control layer * @lops: operation structure * * The new layer can track all control elements and do additional * operations on top (like audio LED handling). */ void snd_ctl_register_layer(struct snd_ctl_layer_ops *lops) { struct snd_card *card; int card_number; down_write(&snd_ctl_layer_rwsem); lops->next = snd_ctl_layer; snd_ctl_layer = lops; up_write(&snd_ctl_layer_rwsem); for (card_number = 0; card_number < SNDRV_CARDS; card_number++) { card = snd_card_ref(card_number); if (card) { down_read(&card->controls_rwsem); lops->lregister(card); up_read(&card->controls_rwsem); snd_card_unref(card); } } } EXPORT_SYMBOL_GPL(snd_ctl_register_layer); /** * snd_ctl_disconnect_layer - disconnect control layer * @lops: operation structure * * It is expected that the information about tracked cards * is freed before this call (the disconnect callback is * not called here). */ void snd_ctl_disconnect_layer(struct snd_ctl_layer_ops *lops) { struct snd_ctl_layer_ops *lops2, *prev_lops2; down_write(&snd_ctl_layer_rwsem); for (lops2 = snd_ctl_layer, prev_lops2 = NULL; lops2; lops2 = lops2->next) { if (lops2 == lops) { if (!prev_lops2) snd_ctl_layer = lops->next; else prev_lops2->next = lops->next; break; } prev_lops2 = lops2; } up_write(&snd_ctl_layer_rwsem); } EXPORT_SYMBOL_GPL(snd_ctl_disconnect_layer); /* * INIT PART */ static const struct file_operations snd_ctl_f_ops = { .owner = THIS_MODULE, .read = snd_ctl_read, .open = snd_ctl_open, .release = snd_ctl_release, .llseek = no_llseek, .poll = snd_ctl_poll, .unlocked_ioctl = snd_ctl_ioctl, .compat_ioctl = snd_ctl_ioctl_compat, .fasync = snd_ctl_fasync, }; /* * registration of the control device */ static int snd_ctl_dev_register(struct snd_device *device) { struct snd_card *card = device->device_data; struct snd_ctl_layer_ops *lops; int err; err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, &snd_ctl_f_ops, card, card->ctl_dev); if (err < 0) return err; down_read(&card->controls_rwsem); down_read(&snd_ctl_layer_rwsem); for (lops = snd_ctl_layer; lops; lops = lops->next) lops->lregister(card); up_read(&snd_ctl_layer_rwsem); up_read(&card->controls_rwsem); return 0; } /* * disconnection of the control device */ static int snd_ctl_dev_disconnect(struct snd_device *device) { struct snd_card *card = device->device_data; struct snd_ctl_file *ctl; struct snd_ctl_layer_ops *lops; unsigned long flags; read_lock_irqsave(&card->ctl_files_rwlock, flags); list_for_each_entry(ctl, &card->ctl_files, list) { wake_up(&ctl->change_sleep); snd_kill_fasync(ctl->fasync, SIGIO, POLL_ERR); } read_unlock_irqrestore(&card->ctl_files_rwlock, flags); down_read(&card->controls_rwsem); down_read(&snd_ctl_layer_rwsem); for (lops = snd_ctl_layer; lops; lops = lops->next) lops->ldisconnect(card); up_read(&snd_ctl_layer_rwsem); up_read(&card->controls_rwsem); return snd_unregister_device(card->ctl_dev); } /* * free all controls */ static int snd_ctl_dev_free(struct snd_device *device) { struct snd_card *card = device->device_data; struct snd_kcontrol *control; down_write(&card->controls_rwsem); while (!list_empty(&card->controls)) { control = snd_kcontrol(card->controls.next); __snd_ctl_remove(card, control, false); } #ifdef CONFIG_SND_CTL_FAST_LOOKUP xa_destroy(&card->ctl_numids); xa_destroy(&card->ctl_hash); #endif up_write(&card->controls_rwsem); put_device(card->ctl_dev); return 0; } /* * create control core: * called from init.c */ int snd_ctl_create(struct snd_card *card) { static const struct snd_device_ops ops = { .dev_free = snd_ctl_dev_free, .dev_register = snd_ctl_dev_register, .dev_disconnect = snd_ctl_dev_disconnect, }; int err; if (snd_BUG_ON(!card)) return -ENXIO; if (snd_BUG_ON(card->number < 0 || card->number >= SNDRV_CARDS)) return -ENXIO; err = snd_device_alloc(&card->ctl_dev, card); if (err < 0) return err; dev_set_name(card->ctl_dev, "controlC%d", card->number); err = snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); if (err < 0) put_device(card->ctl_dev); return err; } /* * Frequently used control callbacks/helpers */ /** * snd_ctl_boolean_mono_info - Helper function for a standard boolean info * callback with a mono channel * @kcontrol: the kcontrol instance * @uinfo: info to store * * This is a function that can be used as info callback for a standard * boolean control with a single mono channel. * * Return: Zero (always successful) */ int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } EXPORT_SYMBOL(snd_ctl_boolean_mono_info); /** * snd_ctl_boolean_stereo_info - Helper function for a standard boolean info * callback with stereo two channels * @kcontrol: the kcontrol instance * @uinfo: info to store * * This is a function that can be used as info callback for a standard * boolean control with stereo two channels. * * Return: Zero (always successful) */ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0; } EXPORT_SYMBOL(snd_ctl_boolean_stereo_info); /** * snd_ctl_enum_info - fills the info structure for an enumerated control * @info: the structure to be filled * @channels: the number of the control's channels; often one * @items: the number of control values; also the size of @names * @names: an array containing the names of all control values * * Sets all required fields in @info to their appropriate values. * If the control's accessibility is not the default (readable and writable), * the caller has to fill @info->access. * * Return: Zero (always successful) */ int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, unsigned int items, const char *const names[]) { info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; info->count = channels; info->value.enumerated.items = items; if (!items) return 0; if (info->value.enumerated.item >= items) info->value.enumerated.item = items - 1; WARN(strlen(names[info->value.enumerated.item]) >= sizeof(info->value.enumerated.name), "ALSA: too long item name '%s'\n", names[info->value.enumerated.item]); strscpy(info->value.enumerated.name, names[info->value.enumerated.item], sizeof(info->value.enumerated.name)); return 0; } EXPORT_SYMBOL(snd_ctl_enum_info);
linux-master
sound/core/control.c
// SPDX-License-Identifier: GPL-2.0-only /* * PCM DRM helpers */ #include <linux/export.h> #include <linux/types.h> #include <sound/asoundef.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/pcm_iec958.h> /** * snd_pcm_create_iec958_consumer_default - create default consumer format IEC958 channel status * @cs: channel status buffer, at least four bytes * @len: length of channel status buffer * * Create the consumer format channel status data in @cs of maximum size * @len. When relevant, the configuration-dependant bits will be set as * unspecified. * * Drivers should then call einter snd_pcm_fill_iec958_consumer() or * snd_pcm_fill_iec958_consumer_hw_params() to replace these unspecified * bits by their actual values. * * Drivers may wish to tweak the contents of the buffer after creation. * * Returns: length of buffer, or negative error code if something failed. */ int snd_pcm_create_iec958_consumer_default(u8 *cs, size_t len) { if (len < 4) return -EINVAL; memset(cs, 0, len); cs[0] = IEC958_AES0_CON_NOT_COPYRIGHT | IEC958_AES0_CON_EMPHASIS_NONE; cs[1] = IEC958_AES1_CON_GENERAL; cs[2] = IEC958_AES2_CON_SOURCE_UNSPEC | IEC958_AES2_CON_CHANNEL_UNSPEC; cs[3] = IEC958_AES3_CON_CLOCK_1000PPM | IEC958_AES3_CON_FS_NOTID; if (len > 4) cs[4] = IEC958_AES4_CON_WORDLEN_NOTID; return len; } EXPORT_SYMBOL_GPL(snd_pcm_create_iec958_consumer_default); static int fill_iec958_consumer(uint rate, uint sample_width, u8 *cs, size_t len) { if (len < 4) return -EINVAL; if ((cs[3] & IEC958_AES3_CON_FS) == IEC958_AES3_CON_FS_NOTID) { unsigned int fs; switch (rate) { case 32000: fs = IEC958_AES3_CON_FS_32000; break; case 44100: fs = IEC958_AES3_CON_FS_44100; break; case 48000: fs = IEC958_AES3_CON_FS_48000; break; case 88200: fs = IEC958_AES3_CON_FS_88200; break; case 96000: fs = IEC958_AES3_CON_FS_96000; break; case 176400: fs = IEC958_AES3_CON_FS_176400; break; case 192000: fs = IEC958_AES3_CON_FS_192000; break; default: return -EINVAL; } cs[3] &= ~IEC958_AES3_CON_FS; cs[3] |= fs; } if (len > 4 && (cs[4] & IEC958_AES4_CON_WORDLEN) == IEC958_AES4_CON_WORDLEN_NOTID) { unsigned int ws; switch (sample_width) { case 16: ws = IEC958_AES4_CON_WORDLEN_20_16; break; case 18: ws = IEC958_AES4_CON_WORDLEN_22_18; break; case 20: ws = IEC958_AES4_CON_WORDLEN_20_16 | IEC958_AES4_CON_MAX_WORDLEN_24; break; case 24: case 32: /* Assume 24-bit width for 32-bit samples. */ ws = IEC958_AES4_CON_WORDLEN_24_20 | IEC958_AES4_CON_MAX_WORDLEN_24; break; default: return -EINVAL; } cs[4] &= ~IEC958_AES4_CON_WORDLEN; cs[4] |= ws; } return len; } /** * snd_pcm_fill_iec958_consumer - Fill consumer format IEC958 channel status * @runtime: pcm runtime structure with ->rate filled in * @cs: channel status buffer, at least four bytes * @len: length of channel status buffer * * Fill the unspecified bits in an IEC958 status bits array using the * parameters of the PCM runtime @runtime. * * Drivers may wish to tweak the contents of the buffer after its been * filled. * * Returns: length of buffer, or negative error code if something failed. */ int snd_pcm_fill_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs, size_t len) { return fill_iec958_consumer(runtime->rate, snd_pcm_format_width(runtime->format), cs, len); } EXPORT_SYMBOL_GPL(snd_pcm_fill_iec958_consumer); /** * snd_pcm_fill_iec958_consumer_hw_params - Fill consumer format IEC958 channel status * @params: the hw_params instance for extracting rate and sample format * @cs: channel status buffer, at least four bytes * @len: length of channel status buffer * * Fill the unspecified bits in an IEC958 status bits array using the * parameters of the PCM hardware parameters @params. * * Drivers may wish to tweak the contents of the buffer after its been * filled.. * * Returns: length of buffer, or negative error code if something failed. */ int snd_pcm_fill_iec958_consumer_hw_params(struct snd_pcm_hw_params *params, u8 *cs, size_t len) { return fill_iec958_consumer(params_rate(params), params_width(params), cs, len); } EXPORT_SYMBOL_GPL(snd_pcm_fill_iec958_consumer_hw_params); /** * snd_pcm_create_iec958_consumer - create consumer format IEC958 channel status * @runtime: pcm runtime structure with ->rate filled in * @cs: channel status buffer, at least four bytes * @len: length of channel status buffer * * Create the consumer format channel status data in @cs of maximum size * @len corresponding to the parameters of the PCM runtime @runtime. * * Drivers may wish to tweak the contents of the buffer after creation. * * Returns: length of buffer, or negative error code if something failed. */ int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs, size_t len) { int ret; ret = snd_pcm_create_iec958_consumer_default(cs, len); if (ret < 0) return ret; return snd_pcm_fill_iec958_consumer(runtime, cs, len); } EXPORT_SYMBOL(snd_pcm_create_iec958_consumer); /** * snd_pcm_create_iec958_consumer_hw_params - create IEC958 channel status * @params: the hw_params instance for extracting rate and sample format * @cs: channel status buffer, at least four bytes * @len: length of channel status buffer * * Create the consumer format channel status data in @cs of maximum size * @len corresponding to the parameters of the PCM runtime @runtime. * * Drivers may wish to tweak the contents of the buffer after creation. * * Returns: length of buffer, or negative error code if something failed. */ int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params, u8 *cs, size_t len) { int ret; ret = snd_pcm_create_iec958_consumer_default(cs, len); if (ret < 0) return ret; return fill_iec958_consumer(params_rate(params), params_width(params), cs, len); } EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params);
linux-master
sound/core/pcm_iec958.c
// SPDX-License-Identifier: GPL-2.0-only /* * PCM DRM helpers */ #include <linux/bitfield.h> #include <linux/export.h> #include <linux/hdmi.h> #include <drm/drm_edid.h> #include <sound/pcm.h> #include <sound/pcm_drm_eld.h> #define SAD0_CHANNELS_MASK GENMASK(2, 0) /* max number of channels - 1 */ #define SAD0_FORMAT_MASK GENMASK(6, 3) /* audio format */ #define SAD1_RATE_MASK GENMASK(6, 0) /* bitfield of supported rates */ #define SAD1_RATE_32000_MASK BIT(0) #define SAD1_RATE_44100_MASK BIT(1) #define SAD1_RATE_48000_MASK BIT(2) #define SAD1_RATE_88200_MASK BIT(3) #define SAD1_RATE_96000_MASK BIT(4) #define SAD1_RATE_176400_MASK BIT(5) #define SAD1_RATE_192000_MASK BIT(6) static const unsigned int eld_rates[] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, }; static unsigned int map_rate_families(const u8 *sad, unsigned int mask_32000, unsigned int mask_44100, unsigned int mask_48000) { unsigned int rate_mask = 0; if (sad[1] & SAD1_RATE_32000_MASK) rate_mask |= mask_32000; if (sad[1] & (SAD1_RATE_44100_MASK | SAD1_RATE_88200_MASK | SAD1_RATE_176400_MASK)) rate_mask |= mask_44100; if (sad[1] & (SAD1_RATE_48000_MASK | SAD1_RATE_96000_MASK | SAD1_RATE_192000_MASK)) rate_mask |= mask_48000; return rate_mask; } static unsigned int sad_rate_mask(const u8 *sad) { switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) { case HDMI_AUDIO_CODING_TYPE_PCM: return sad[1] & SAD1_RATE_MASK; case HDMI_AUDIO_CODING_TYPE_AC3: case HDMI_AUDIO_CODING_TYPE_DTS: return map_rate_families(sad, SAD1_RATE_32000_MASK, SAD1_RATE_44100_MASK, SAD1_RATE_48000_MASK); case HDMI_AUDIO_CODING_TYPE_EAC3: case HDMI_AUDIO_CODING_TYPE_DTS_HD: case HDMI_AUDIO_CODING_TYPE_MLP: return map_rate_families(sad, 0, SAD1_RATE_176400_MASK, SAD1_RATE_192000_MASK); default: /* TODO adjust for other compressed formats as well */ return sad[1] & SAD1_RATE_MASK; } } static unsigned int sad_max_channels(const u8 *sad) { switch (FIELD_GET(SAD0_FORMAT_MASK, sad[0])) { case HDMI_AUDIO_CODING_TYPE_PCM: return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]); case HDMI_AUDIO_CODING_TYPE_AC3: case HDMI_AUDIO_CODING_TYPE_DTS: case HDMI_AUDIO_CODING_TYPE_EAC3: return 2; case HDMI_AUDIO_CODING_TYPE_DTS_HD: case HDMI_AUDIO_CODING_TYPE_MLP: return 8; default: /* TODO adjust for other compressed formats as well */ return 1 + FIELD_GET(SAD0_CHANNELS_MASK, sad[0]); } } static int eld_limit_rates(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval *r = hw_param_interval(params, rule->var); const struct snd_interval *c; unsigned int rate_mask = 7, i; const u8 *sad, *eld = rule->private; sad = drm_eld_sad(eld); if (sad) { c = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3) { unsigned max_channels = sad_max_channels(sad); /* * Exclude SADs which do not include the * requested number of channels. */ if (c->min <= max_channels) rate_mask |= sad_rate_mask(sad); } } return snd_interval_list(r, ARRAY_SIZE(eld_rates), eld_rates, rate_mask); } static int eld_limit_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval *c = hw_param_interval(params, rule->var); const struct snd_interval *r; struct snd_interval t = { .min = 1, .max = 2, .integer = 1, }; unsigned int i; const u8 *sad, *eld = rule->private; sad = drm_eld_sad(eld); if (sad) { unsigned int rate_mask = 0; /* Convert the rate interval to a mask */ r = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); for (i = 0; i < ARRAY_SIZE(eld_rates); i++) if (r->min <= eld_rates[i] && r->max >= eld_rates[i]) rate_mask |= BIT(i); for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3) if (rate_mask & sad_rate_mask(sad)) t.max = max(t.max, sad_max_channels(sad)); } return snd_interval_refine(c, &t); } int snd_pcm_hw_constraint_eld(struct snd_pcm_runtime *runtime, void *eld) { int ret; ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, eld_limit_rates, eld, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (ret < 0) return ret; ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, eld_limit_channels, eld, SNDRV_PCM_HW_PARAM_RATE, -1); return ret; } EXPORT_SYMBOL_GPL(snd_pcm_hw_constraint_eld);
linux-master
sound/core/pcm_drm_eld.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Digital Audio (PCM) abstract layer * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/time.h> #include <linux/gcd.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/timer.h> #include "pcm_local.h" /* * Timer functions */ void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream) { unsigned long rate, mult, fsize, l, post; struct snd_pcm_runtime *runtime = substream->runtime; mult = 1000000000; rate = runtime->rate; if (snd_BUG_ON(!rate)) return; l = gcd(mult, rate); mult /= l; rate /= l; fsize = runtime->period_size; if (snd_BUG_ON(!fsize)) return; l = gcd(rate, fsize); rate /= l; fsize /= l; post = 1; while ((mult * fsize) / fsize != mult) { mult /= 2; post *= 2; } if (rate == 0) { pcm_err(substream->pcm, "pcm timer resolution out of range (rate = %u, period_size = %lu)\n", runtime->rate, runtime->period_size); runtime->timer_resolution = -1; return; } runtime->timer_resolution = (mult * fsize / rate) * post; } static unsigned long snd_pcm_timer_resolution(struct snd_timer * timer) { struct snd_pcm_substream *substream; substream = timer->private_data; return substream->runtime ? substream->runtime->timer_resolution : 0; } static int snd_pcm_timer_start(struct snd_timer * timer) { struct snd_pcm_substream *substream; substream = snd_timer_chip(timer); substream->timer_running = 1; return 0; } static int snd_pcm_timer_stop(struct snd_timer * timer) { struct snd_pcm_substream *substream; substream = snd_timer_chip(timer); substream->timer_running = 0; return 0; } static const struct snd_timer_hardware snd_pcm_timer = { .flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_SLAVE, .resolution = 0, .ticks = 1, .c_resolution = snd_pcm_timer_resolution, .start = snd_pcm_timer_start, .stop = snd_pcm_timer_stop, }; /* * Init functions */ static void snd_pcm_timer_free(struct snd_timer *timer) { struct snd_pcm_substream *substream = timer->private_data; substream->timer = NULL; } void snd_pcm_timer_init(struct snd_pcm_substream *substream) { struct snd_timer_id tid; struct snd_timer *timer; tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; tid.dev_class = SNDRV_TIMER_CLASS_PCM; tid.card = substream->pcm->card->number; tid.device = substream->pcm->device; tid.subdevice = (substream->number << 1) | (substream->stream & 1); if (snd_timer_new(substream->pcm->card, "PCM", &tid, &timer) < 0) return; sprintf(timer->name, "PCM %s %i-%i-%i", substream->stream == SNDRV_PCM_STREAM_CAPTURE ? "capture" : "playback", tid.card, tid.device, tid.subdevice); timer->hw = snd_pcm_timer; if (snd_device_register(timer->card, timer) < 0) { snd_device_free(timer->card, timer); return; } timer->private_data = substream; timer->private_free = snd_pcm_timer_free; substream->timer = timer; } void snd_pcm_timer_done(struct snd_pcm_substream *substream) { if (substream->timer) { snd_device_free(substream->pcm->card, substream->timer); substream->timer = NULL; } }
linux-master
sound/core/pcm_timer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Advanced Linux Sound Architecture * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/slab.h> #include <linux/time.h> #include <linux/device.h> #include <linux/module.h> #include <linux/debugfs.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/info.h> #include <sound/control.h> #include <sound/initval.h> #include <linux/kmod.h> #include <linux/mutex.h> static int major = CONFIG_SND_MAJOR; int snd_major; EXPORT_SYMBOL(snd_major); static int cards_limit = 1; MODULE_AUTHOR("Jaroslav Kysela <[email protected]>"); MODULE_DESCRIPTION("Advanced Linux Sound Architecture driver for soundcards."); MODULE_LICENSE("GPL"); module_param(major, int, 0444); MODULE_PARM_DESC(major, "Major # for sound driver."); module_param(cards_limit, int, 0444); MODULE_PARM_DESC(cards_limit, "Count of auto-loadable soundcards."); MODULE_ALIAS_CHARDEV_MAJOR(CONFIG_SND_MAJOR); /* this one holds the actual max. card number currently available. * as default, it's identical with cards_limit option. when more * modules are loaded manually, this limit number increases, too. */ int snd_ecards_limit; EXPORT_SYMBOL(snd_ecards_limit); #ifdef CONFIG_SND_DEBUG struct dentry *sound_debugfs_root; EXPORT_SYMBOL_GPL(sound_debugfs_root); #endif static struct snd_minor *snd_minors[SNDRV_OS_MINORS]; static DEFINE_MUTEX(sound_mutex); #ifdef CONFIG_MODULES /** * snd_request_card - try to load the card module * @card: the card number * * Tries to load the module "snd-card-X" for the given card number * via request_module. Returns immediately if already loaded. */ void snd_request_card(int card) { if (snd_card_locked(card)) return; if (card < 0 || card >= cards_limit) return; request_module("snd-card-%i", card); } EXPORT_SYMBOL(snd_request_card); static void snd_request_other(int minor) { char *str; switch (minor) { case SNDRV_MINOR_SEQUENCER: str = "snd-seq"; break; case SNDRV_MINOR_TIMER: str = "snd-timer"; break; default: return; } request_module(str); } #endif /* modular kernel */ /** * snd_lookup_minor_data - get user data of a registered device * @minor: the minor number * @type: device type (SNDRV_DEVICE_TYPE_XXX) * * Checks that a minor device with the specified type is registered, and returns * its user data pointer. * * This function increments the reference counter of the card instance * if an associated instance with the given minor number and type is found. * The caller must call snd_card_unref() appropriately later. * * Return: The user data pointer if the specified device is found. %NULL * otherwise. */ void *snd_lookup_minor_data(unsigned int minor, int type) { struct snd_minor *mreg; void *private_data; if (minor >= ARRAY_SIZE(snd_minors)) return NULL; mutex_lock(&sound_mutex); mreg = snd_minors[minor]; if (mreg && mreg->type == type) { private_data = mreg->private_data; if (private_data && mreg->card_ptr) get_device(&mreg->card_ptr->card_dev); } else private_data = NULL; mutex_unlock(&sound_mutex); return private_data; } EXPORT_SYMBOL(snd_lookup_minor_data); #ifdef CONFIG_MODULES static struct snd_minor *autoload_device(unsigned int minor) { int dev; mutex_unlock(&sound_mutex); /* release lock temporarily */ dev = SNDRV_MINOR_DEVICE(minor); if (dev == SNDRV_MINOR_CONTROL) { /* /dev/aloadC? */ int card = SNDRV_MINOR_CARD(minor); struct snd_card *ref = snd_card_ref(card); if (!ref) snd_request_card(card); else snd_card_unref(ref); } else if (dev == SNDRV_MINOR_GLOBAL) { /* /dev/aloadSEQ */ snd_request_other(minor); } mutex_lock(&sound_mutex); /* reacuire lock */ return snd_minors[minor]; } #else /* !CONFIG_MODULES */ #define autoload_device(minor) NULL #endif /* CONFIG_MODULES */ static int snd_open(struct inode *inode, struct file *file) { unsigned int minor = iminor(inode); struct snd_minor *mptr = NULL; const struct file_operations *new_fops; int err = 0; if (minor >= ARRAY_SIZE(snd_minors)) return -ENODEV; mutex_lock(&sound_mutex); mptr = snd_minors[minor]; if (mptr == NULL) { mptr = autoload_device(minor); if (!mptr) { mutex_unlock(&sound_mutex); return -ENODEV; } } new_fops = fops_get(mptr->f_ops); mutex_unlock(&sound_mutex); if (!new_fops) return -ENODEV; replace_fops(file, new_fops); if (file->f_op->open) err = file->f_op->open(inode, file); return err; } static const struct file_operations snd_fops = { .owner = THIS_MODULE, .open = snd_open, .llseek = noop_llseek, }; #ifdef CONFIG_SND_DYNAMIC_MINORS static int snd_find_free_minor(int type, struct snd_card *card, int dev) { int minor; /* static minors for module auto loading */ if (type == SNDRV_DEVICE_TYPE_SEQUENCER) return SNDRV_MINOR_SEQUENCER; if (type == SNDRV_DEVICE_TYPE_TIMER) return SNDRV_MINOR_TIMER; for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) { /* skip static minors still used for module auto loading */ if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL) continue; if (minor == SNDRV_MINOR_SEQUENCER || minor == SNDRV_MINOR_TIMER) continue; if (!snd_minors[minor]) return minor; } return -EBUSY; } #else static int snd_find_free_minor(int type, struct snd_card *card, int dev) { int minor; switch (type) { case SNDRV_DEVICE_TYPE_SEQUENCER: case SNDRV_DEVICE_TYPE_TIMER: minor = type; break; case SNDRV_DEVICE_TYPE_CONTROL: if (snd_BUG_ON(!card)) return -EINVAL; minor = SNDRV_MINOR(card->number, type); break; case SNDRV_DEVICE_TYPE_HWDEP: case SNDRV_DEVICE_TYPE_RAWMIDI: case SNDRV_DEVICE_TYPE_PCM_PLAYBACK: case SNDRV_DEVICE_TYPE_PCM_CAPTURE: case SNDRV_DEVICE_TYPE_COMPRESS: if (snd_BUG_ON(!card)) return -EINVAL; minor = SNDRV_MINOR(card->number, type + dev); break; default: return -EINVAL; } if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS)) return -EINVAL; if (snd_minors[minor]) return -EBUSY; return minor; } #endif /** * snd_register_device - Register the ALSA device file for the card * @type: the device type, SNDRV_DEVICE_TYPE_XXX * @card: the card instance * @dev: the device index * @f_ops: the file operations * @private_data: user pointer for f_ops->open() * @device: the device to register * * Registers an ALSA device file for the given card. * The operators have to be set in reg parameter. * * Return: Zero if successful, or a negative error code on failure. */ int snd_register_device(int type, struct snd_card *card, int dev, const struct file_operations *f_ops, void *private_data, struct device *device) { int minor; int err = 0; struct snd_minor *preg; if (snd_BUG_ON(!device)) return -EINVAL; preg = kmalloc(sizeof *preg, GFP_KERNEL); if (preg == NULL) return -ENOMEM; preg->type = type; preg->card = card ? card->number : -1; preg->device = dev; preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; mutex_lock(&sound_mutex); minor = snd_find_free_minor(type, card, dev); if (minor < 0) { err = minor; goto error; } preg->dev = device; device->devt = MKDEV(major, minor); err = device_add(device); if (err < 0) goto error; snd_minors[minor] = preg; error: mutex_unlock(&sound_mutex); if (err < 0) kfree(preg); return err; } EXPORT_SYMBOL(snd_register_device); /** * snd_unregister_device - unregister the device on the given card * @dev: the device instance * * Unregisters the device file already registered via * snd_register_device(). * * Return: Zero if successful, or a negative error code on failure. */ int snd_unregister_device(struct device *dev) { int minor; struct snd_minor *preg; mutex_lock(&sound_mutex); for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) { preg = snd_minors[minor]; if (preg && preg->dev == dev) { snd_minors[minor] = NULL; device_del(dev); kfree(preg); break; } } mutex_unlock(&sound_mutex); if (minor >= ARRAY_SIZE(snd_minors)) return -ENOENT; return 0; } EXPORT_SYMBOL(snd_unregister_device); #ifdef CONFIG_SND_PROC_FS /* * INFO PART */ static const char *snd_device_type_name(int type) { switch (type) { case SNDRV_DEVICE_TYPE_CONTROL: return "control"; case SNDRV_DEVICE_TYPE_HWDEP: return "hardware dependent"; case SNDRV_DEVICE_TYPE_RAWMIDI: return "raw midi"; case SNDRV_DEVICE_TYPE_PCM_PLAYBACK: return "digital audio playback"; case SNDRV_DEVICE_TYPE_PCM_CAPTURE: return "digital audio capture"; case SNDRV_DEVICE_TYPE_SEQUENCER: return "sequencer"; case SNDRV_DEVICE_TYPE_TIMER: return "timer"; case SNDRV_DEVICE_TYPE_COMPRESS: return "compress"; default: return "?"; } } static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { int minor; struct snd_minor *mptr; mutex_lock(&sound_mutex); for (minor = 0; minor < SNDRV_OS_MINORS; ++minor) { mptr = snd_minors[minor]; if (!mptr) continue; if (mptr->card >= 0) { if (mptr->device >= 0) snd_iprintf(buffer, "%3i: [%2i-%2i]: %s\n", minor, mptr->card, mptr->device, snd_device_type_name(mptr->type)); else snd_iprintf(buffer, "%3i: [%2i] : %s\n", minor, mptr->card, snd_device_type_name(mptr->type)); } else snd_iprintf(buffer, "%3i: : %s\n", minor, snd_device_type_name(mptr->type)); } mutex_unlock(&sound_mutex); } int __init snd_minor_info_init(void) { struct snd_info_entry *entry; entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL); if (!entry) return -ENOMEM; entry->c.text.read = snd_minor_info_read; return snd_info_register(entry); /* freed in error path */ } #endif /* CONFIG_SND_PROC_FS */ /* * INIT PART */ static int __init alsa_sound_init(void) { snd_major = major; snd_ecards_limit = cards_limit; if (register_chrdev(major, "alsa", &snd_fops)) { pr_err("ALSA core: unable to register native major device number %d\n", major); return -EIO; } if (snd_info_init() < 0) { unregister_chrdev(major, "alsa"); return -ENOMEM; } #ifdef CONFIG_SND_DEBUG sound_debugfs_root = debugfs_create_dir("sound", NULL); #endif #ifndef MODULE pr_info("Advanced Linux Sound Architecture Driver Initialized.\n"); #endif return 0; } static void __exit alsa_sound_exit(void) { #ifdef CONFIG_SND_DEBUG debugfs_remove(sound_debugfs_root); #endif snd_info_done(); unregister_chrdev(major, "alsa"); } subsys_initcall(alsa_sound_init); module_exit(alsa_sound_exit);
linux-master
sound/core/sound.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Helper functions for jack-detection kcontrols * * Copyright (c) 2011 Takashi Iwai <[email protected]> */ #include <linux/kernel.h> #include <linux/export.h> #include <sound/core.h> #include <sound/control.h> #define jack_detect_kctl_info snd_ctl_boolean_mono_info static int jack_detect_kctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { ucontrol->value.integer.value[0] = kcontrol->private_value; return 0; } static const struct snd_kcontrol_new jack_detect_kctl = { /* name is filled later */ .iface = SNDRV_CTL_ELEM_IFACE_CARD, .access = SNDRV_CTL_ELEM_ACCESS_READ, .info = jack_detect_kctl_info, .get = jack_detect_kctl_get, }; static int get_available_index(struct snd_card *card, const char *name) { struct snd_ctl_elem_id sid; memset(&sid, 0, sizeof(sid)); sid.index = 0; sid.iface = SNDRV_CTL_ELEM_IFACE_CARD; strscpy(sid.name, name, sizeof(sid.name)); while (snd_ctl_find_id(card, &sid)) { sid.index++; /* reset numid; otherwise snd_ctl_find_id() hits this again */ sid.numid = 0; } return sid.index; } static void jack_kctl_name_gen(char *name, const char *src_name, int size) { size_t count = strlen(src_name); bool need_cat = true; /* remove redundant " Jack" from src_name */ if (count >= 5) need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false; snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name); } struct snd_kcontrol * snd_kctl_jack_new(const char *name, struct snd_card *card) { struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&jack_detect_kctl, NULL); if (!kctl) return NULL; jack_kctl_name_gen(kctl->id.name, name, sizeof(kctl->id.name)); kctl->id.index = get_available_index(card, kctl->id.name); kctl->private_value = 0; return kctl; } void snd_kctl_jack_report(struct snd_card *card, struct snd_kcontrol *kctl, bool status) { if (kctl->private_value == status) return; kctl->private_value = status; snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); }
linux-master
sound/core/ctljack.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Helpers for UMP <-> MIDI 1.0 byte stream conversion */ #include <linux/module.h> #include <linux/export.h> #include <sound/core.h> #include <sound/asound.h> #include <sound/ump.h> #include <sound/ump_convert.h> /* * Upgrade / downgrade value bits */ static u8 downscale_32_to_7bit(u32 src) { return src >> 25; } static u16 downscale_32_to_14bit(u32 src) { return src >> 18; } static u8 downscale_16_to_7bit(u16 src) { return src >> 9; } static u16 upscale_7_to_16bit(u8 src) { u16 val, repeat; val = (u16)src << 9; if (src <= 0x40) return val; repeat = src & 0x3f; return val | (repeat << 3) | (repeat >> 3); } static u32 upscale_7_to_32bit(u8 src) { u32 val, repeat; val = src << 25; if (src <= 0x40) return val; repeat = src & 0x3f; return val | (repeat << 19) | (repeat << 13) | (repeat << 7) | (repeat << 1) | (repeat >> 5); } static u32 upscale_14_to_32bit(u16 src) { u32 val, repeat; val = src << 18; if (src <= 0x2000) return val; repeat = src & 0x1fff; return val | (repeat << 5) | (repeat >> 8); } /* * UMP -> MIDI 1 byte stream conversion */ /* convert a UMP System message to MIDI 1.0 byte stream */ static int cvt_ump_system_to_legacy(u32 data, unsigned char *buf) { buf[0] = ump_message_status_channel(data); switch (ump_message_status_code(data)) { case UMP_SYSTEM_STATUS_MIDI_TIME_CODE: case UMP_SYSTEM_STATUS_SONG_SELECT: buf[1] = (data >> 8) & 0x7f; return 2; case UMP_SYSTEM_STATUS_SONG_POSITION: buf[1] = (data >> 8) & 0x7f; buf[2] = data & 0x7f; return 3; default: return 1; } } /* convert a UMP MIDI 1.0 Channel Voice message to MIDI 1.0 byte stream */ static int cvt_ump_midi1_to_legacy(u32 data, unsigned char *buf) { buf[0] = ump_message_status_channel(data); buf[1] = (data >> 8) & 0xff; switch (ump_message_status_code(data)) { case UMP_MSG_STATUS_PROGRAM: case UMP_MSG_STATUS_CHANNEL_PRESSURE: return 2; default: buf[2] = data & 0xff; return 3; } } /* convert a UMP MIDI 2.0 Channel Voice message to MIDI 1.0 byte stream */ static int cvt_ump_midi2_to_legacy(const union snd_ump_midi2_msg *midi2, unsigned char *buf) { unsigned char status = midi2->note.status; unsigned char channel = midi2->note.channel; u16 v; buf[0] = (status << 4) | channel; switch (status) { case UMP_MSG_STATUS_NOTE_OFF: case UMP_MSG_STATUS_NOTE_ON: buf[1] = midi2->note.note; buf[2] = downscale_16_to_7bit(midi2->note.velocity); if (status == UMP_MSG_STATUS_NOTE_ON && !buf[2]) buf[2] = 1; return 3; case UMP_MSG_STATUS_POLY_PRESSURE: buf[1] = midi2->paf.note; buf[2] = downscale_32_to_7bit(midi2->paf.data); return 3; case UMP_MSG_STATUS_CC: buf[1] = midi2->cc.index; buf[2] = downscale_32_to_7bit(midi2->cc.data); return 3; case UMP_MSG_STATUS_CHANNEL_PRESSURE: buf[1] = downscale_32_to_7bit(midi2->caf.data); return 2; case UMP_MSG_STATUS_PROGRAM: if (midi2->pg.bank_valid) { buf[0] = channel | (UMP_MSG_STATUS_CC << 4); buf[1] = UMP_CC_BANK_SELECT; buf[2] = midi2->pg.bank_msb; buf[3] = channel | (UMP_MSG_STATUS_CC << 4); buf[4] = UMP_CC_BANK_SELECT_LSB; buf[5] = midi2->pg.bank_lsb; buf[6] = channel | (UMP_MSG_STATUS_PROGRAM << 4); buf[7] = midi2->pg.program; return 8; } buf[1] = midi2->pg.program; return 2; case UMP_MSG_STATUS_PITCH_BEND: v = downscale_32_to_14bit(midi2->pb.data); buf[1] = v & 0x7f; buf[2] = v >> 7; return 3; case UMP_MSG_STATUS_RPN: case UMP_MSG_STATUS_NRPN: buf[0] = channel | (UMP_MSG_STATUS_CC << 4); buf[1] = status == UMP_MSG_STATUS_RPN ? UMP_CC_RPN_MSB : UMP_CC_NRPN_MSB; buf[2] = midi2->rpn.bank; buf[3] = buf[0]; buf[4] = status == UMP_MSG_STATUS_RPN ? UMP_CC_RPN_LSB : UMP_CC_NRPN_LSB; buf[5] = midi2->rpn.index; buf[6] = buf[0]; buf[7] = UMP_CC_DATA; v = downscale_32_to_14bit(midi2->rpn.data); buf[8] = v >> 7; buf[9] = buf[0]; buf[10] = UMP_CC_DATA_LSB; buf[11] = v & 0x7f; return 12; default: return 0; } } /* convert a UMP 7-bit SysEx message to MIDI 1.0 byte stream */ static int cvt_ump_sysex7_to_legacy(const u32 *data, unsigned char *buf) { unsigned char status; unsigned char bytes; int size, offset; status = ump_sysex_message_status(*data); if (status > UMP_SYSEX_STATUS_END) return 0; // unsupported, skip bytes = ump_sysex_message_length(*data); if (bytes > 6) return 0; // skip size = 0; if (status == UMP_SYSEX_STATUS_SINGLE || status == UMP_SYSEX_STATUS_START) { buf[0] = UMP_MIDI1_MSG_SYSEX_START; size = 1; } offset = 8; for (; bytes; bytes--, size++) { buf[size] = (*data >> offset) & 0x7f; if (!offset) { offset = 24; data++; } else { offset -= 8; } } if (status == UMP_SYSEX_STATUS_SINGLE || status == UMP_SYSEX_STATUS_END) buf[size++] = UMP_MIDI1_MSG_SYSEX_END; return size; } /** * snd_ump_convert_from_ump - convert from UMP to legacy MIDI * @data: UMP packet * @buf: buffer to store legacy MIDI data * @group_ret: pointer to store the target group * * Convert from a UMP packet @data to MIDI 1.0 bytes at @buf. * The target group is stored at @group_ret. * * The function returns the number of bytes of MIDI 1.0 stream. */ int snd_ump_convert_from_ump(const u32 *data, unsigned char *buf, unsigned char *group_ret) { *group_ret = ump_message_group(*data); switch (ump_message_type(*data)) { case UMP_MSG_TYPE_SYSTEM: return cvt_ump_system_to_legacy(*data, buf); case UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE: return cvt_ump_midi1_to_legacy(*data, buf); case UMP_MSG_TYPE_MIDI2_CHANNEL_VOICE: return cvt_ump_midi2_to_legacy((const union snd_ump_midi2_msg *)data, buf); case UMP_MSG_TYPE_DATA: return cvt_ump_sysex7_to_legacy(data, buf); } return 0; } EXPORT_SYMBOL_GPL(snd_ump_convert_from_ump); /* * MIDI 1 byte stream -> UMP conversion */ /* convert MIDI 1.0 SysEx to a UMP packet */ static int cvt_legacy_sysex_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group, u32 *data, bool finish) { unsigned char status; bool start = cvt->in_sysex == 1; int i, offset; if (start && finish) status = UMP_SYSEX_STATUS_SINGLE; else if (start) status = UMP_SYSEX_STATUS_START; else if (finish) status = UMP_SYSEX_STATUS_END; else status = UMP_SYSEX_STATUS_CONTINUE; *data = ump_compose(UMP_MSG_TYPE_DATA, group, status, cvt->len); offset = 8; for (i = 0; i < cvt->len; i++) { *data |= cvt->buf[i] << offset; if (!offset) { offset = 24; data++; } else offset -= 8; } cvt->len = 0; if (finish) cvt->in_sysex = 0; else cvt->in_sysex++; return 8; } /* convert to a UMP System message */ static int cvt_legacy_system_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group, u32 *data) { data[0] = ump_compose(UMP_MSG_TYPE_SYSTEM, group, 0, cvt->buf[0]); if (cvt->cmd_bytes > 1) data[0] |= cvt->buf[1] << 8; if (cvt->cmd_bytes > 2) data[0] |= cvt->buf[2]; return 4; } static void fill_rpn(struct ump_cvt_to_ump_bank *cc, union snd_ump_midi2_msg *midi2) { if (cc->rpn_set) { midi2->rpn.status = UMP_MSG_STATUS_RPN; midi2->rpn.bank = cc->cc_rpn_msb; midi2->rpn.index = cc->cc_rpn_lsb; cc->rpn_set = 0; cc->cc_rpn_msb = cc->cc_rpn_lsb = 0; } else { midi2->rpn.status = UMP_MSG_STATUS_NRPN; midi2->rpn.bank = cc->cc_nrpn_msb; midi2->rpn.index = cc->cc_nrpn_lsb; cc->nrpn_set = 0; cc->cc_nrpn_msb = cc->cc_nrpn_lsb = 0; } midi2->rpn.data = upscale_14_to_32bit((cc->cc_data_msb << 7) | cc->cc_data_lsb); cc->cc_data_msb = cc->cc_data_lsb = 0; } /* convert to a MIDI 1.0 Channel Voice message */ static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group, unsigned int protocol, u32 *data, unsigned char bytes) { const unsigned char *buf = cvt->buf; struct ump_cvt_to_ump_bank *cc; union snd_ump_midi2_msg *midi2 = (union snd_ump_midi2_msg *)data; unsigned char status, channel; BUILD_BUG_ON(sizeof(union snd_ump_midi1_msg) != 4); BUILD_BUG_ON(sizeof(union snd_ump_midi2_msg) != 8); /* for MIDI 1.0 UMP, it's easy, just pack it into UMP */ if (protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI1) { data[0] = ump_compose(UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE, group, 0, buf[0]); data[0] |= buf[1] << 8; if (bytes > 2) data[0] |= buf[2]; return 4; } status = *buf >> 4; channel = *buf & 0x0f; cc = &cvt->bank[channel]; /* special handling: treat note-on with 0 velocity as note-off */ if (status == UMP_MSG_STATUS_NOTE_ON && !buf[2]) status = UMP_MSG_STATUS_NOTE_OFF; /* initialize the packet */ data[0] = ump_compose(UMP_MSG_TYPE_MIDI2_CHANNEL_VOICE, group, status, channel); data[1] = 0; switch (status) { case UMP_MSG_STATUS_NOTE_ON: case UMP_MSG_STATUS_NOTE_OFF: midi2->note.note = buf[1]; midi2->note.velocity = upscale_7_to_16bit(buf[2]); break; case UMP_MSG_STATUS_POLY_PRESSURE: midi2->paf.note = buf[1]; midi2->paf.data = upscale_7_to_32bit(buf[2]); break; case UMP_MSG_STATUS_CC: switch (buf[1]) { case UMP_CC_RPN_MSB: cc->rpn_set = 1; cc->cc_rpn_msb = buf[2]; return 0; // skip case UMP_CC_RPN_LSB: cc->rpn_set = 1; cc->cc_rpn_lsb = buf[2]; return 0; // skip case UMP_CC_NRPN_MSB: cc->nrpn_set = 1; cc->cc_nrpn_msb = buf[2]; return 0; // skip case UMP_CC_NRPN_LSB: cc->nrpn_set = 1; cc->cc_nrpn_lsb = buf[2]; return 0; // skip case UMP_CC_DATA: cc->cc_data_msb = buf[2]; return 0; // skip case UMP_CC_BANK_SELECT: cc->bank_set = 1; cc->cc_bank_msb = buf[2]; return 0; // skip case UMP_CC_BANK_SELECT_LSB: cc->bank_set = 1; cc->cc_bank_lsb = buf[2]; return 0; // skip case UMP_CC_DATA_LSB: cc->cc_data_lsb = buf[2]; if (cc->rpn_set || cc->nrpn_set) fill_rpn(cc, midi2); else return 0; // skip break; default: midi2->cc.index = buf[1]; midi2->cc.data = upscale_7_to_32bit(buf[2]); break; } break; case UMP_MSG_STATUS_PROGRAM: midi2->pg.program = buf[1]; if (cc->bank_set) { midi2->pg.bank_valid = 1; midi2->pg.bank_msb = cc->cc_bank_msb; midi2->pg.bank_lsb = cc->cc_bank_lsb; cc->bank_set = 0; cc->cc_bank_msb = cc->cc_bank_lsb = 0; } break; case UMP_MSG_STATUS_CHANNEL_PRESSURE: midi2->caf.data = upscale_7_to_32bit(buf[1]); break; case UMP_MSG_STATUS_PITCH_BEND: midi2->pb.data = upscale_14_to_32bit(buf[1] | (buf[2] << 7)); break; default: return 0; } return 8; } static int do_convert_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group, unsigned int protocol, unsigned char c, u32 *data) { /* bytes for 0x80-0xf0 */ static unsigned char cmd_bytes[8] = { 3, 3, 3, 3, 2, 2, 3, 0 }; /* bytes for 0xf0-0xff */ static unsigned char system_bytes[16] = { 0, 2, 3, 2, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1 }; unsigned char bytes; if (c == UMP_MIDI1_MSG_SYSEX_START) { cvt->in_sysex = 1; cvt->len = 0; return 0; } if (c == UMP_MIDI1_MSG_SYSEX_END) { if (!cvt->in_sysex) return 0; /* skip */ return cvt_legacy_sysex_to_ump(cvt, group, data, true); } if ((c & 0xf0) == UMP_MIDI1_MSG_REALTIME) { bytes = system_bytes[c & 0x0f]; if (!bytes) return 0; /* skip */ if (bytes == 1) { data[0] = ump_compose(UMP_MSG_TYPE_SYSTEM, group, 0, c); return 4; } cvt->buf[0] = c; cvt->len = 1; cvt->cmd_bytes = bytes; cvt->in_sysex = 0; /* abort SysEx */ return 0; } if (c & 0x80) { bytes = cmd_bytes[(c >> 4) & 7]; cvt->buf[0] = c; cvt->len = 1; cvt->cmd_bytes = bytes; cvt->in_sysex = 0; /* abort SysEx */ return 0; } if (cvt->in_sysex) { cvt->buf[cvt->len++] = c; if (cvt->len == 6) return cvt_legacy_sysex_to_ump(cvt, group, data, false); return 0; } if (!cvt->len) return 0; cvt->buf[cvt->len++] = c; if (cvt->len < cvt->cmd_bytes) return 0; cvt->len = 1; if ((cvt->buf[0] & 0xf0) == UMP_MIDI1_MSG_REALTIME) return cvt_legacy_system_to_ump(cvt, group, data); return cvt_legacy_cmd_to_ump(cvt, group, protocol, data, cvt->cmd_bytes); } /** * snd_ump_convert_to_ump - convert legacy MIDI byte to UMP packet * @cvt: converter context * @group: target UMP group * @protocol: target UMP protocol * @c: MIDI 1.0 byte data * * Feed a MIDI 1.0 byte @c and convert to a UMP packet if completed. * The result is stored in the buffer in @cvt. */ void snd_ump_convert_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group, unsigned int protocol, unsigned char c) { cvt->ump_bytes = do_convert_to_ump(cvt, group, protocol, c, cvt->ump); } EXPORT_SYMBOL_GPL(snd_ump_convert_to_ump);
linux-master
sound/core/ump_convert.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * compat ioctls for control API * * Copyright (c) by Takashi Iwai <[email protected]> */ /* this file included from control.c */ #include <linux/compat.h> #include <linux/slab.h> struct snd_ctl_elem_list32 { u32 offset; u32 space; u32 used; u32 count; u32 pids; unsigned char reserved[50]; } /* don't set packed attribute here */; static int snd_ctl_elem_list_compat(struct snd_card *card, struct snd_ctl_elem_list32 __user *data32) { struct snd_ctl_elem_list data = {}; compat_caddr_t ptr; int err; /* offset, space, used, count */ if (copy_from_user(&data, data32, 4 * sizeof(u32))) return -EFAULT; /* pids */ if (get_user(ptr, &data32->pids)) return -EFAULT; data.pids = compat_ptr(ptr); err = snd_ctl_elem_list(card, &data); if (err < 0) return err; /* copy the result */ if (copy_to_user(data32, &data, 4 * sizeof(u32))) return -EFAULT; return 0; } /* * control element info * it uses union, so the things are not easy.. */ struct snd_ctl_elem_info32 { struct snd_ctl_elem_id id; // the size of struct is same s32 type; u32 access; u32 count; s32 owner; union { struct { s32 min; s32 max; s32 step; } integer; struct { u64 min; u64 max; u64 step; } integer64; struct { u32 items; u32 item; char name[64]; u64 names_ptr; u32 names_length; } enumerated; unsigned char reserved[128]; } value; unsigned char reserved[64]; } __attribute__((packed)); static int snd_ctl_elem_info_compat(struct snd_ctl_file *ctl, struct snd_ctl_elem_info32 __user *data32) { struct snd_ctl_elem_info *data; int err; data = kzalloc(sizeof(*data), GFP_KERNEL); if (! data) return -ENOMEM; err = -EFAULT; /* copy id */ if (copy_from_user(&data->id, &data32->id, sizeof(data->id))) goto error; /* we need to copy the item index. * hope this doesn't break anything.. */ if (get_user(data->value.enumerated.item, &data32->value.enumerated.item)) goto error; err = snd_ctl_elem_info(ctl, data); if (err < 0) goto error; /* restore info to 32bit */ err = -EFAULT; /* id, type, access, count */ if (copy_to_user(&data32->id, &data->id, sizeof(data->id)) || copy_to_user(&data32->type, &data->type, 3 * sizeof(u32))) goto error; if (put_user(data->owner, &data32->owner)) goto error; switch (data->type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: case SNDRV_CTL_ELEM_TYPE_INTEGER: if (put_user(data->value.integer.min, &data32->value.integer.min) || put_user(data->value.integer.max, &data32->value.integer.max) || put_user(data->value.integer.step, &data32->value.integer.step)) goto error; break; case SNDRV_CTL_ELEM_TYPE_INTEGER64: if (copy_to_user(&data32->value.integer64, &data->value.integer64, sizeof(data->value.integer64))) goto error; break; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: if (copy_to_user(&data32->value.enumerated, &data->value.enumerated, sizeof(data->value.enumerated))) goto error; break; default: break; } err = 0; error: kfree(data); return err; } /* read / write */ struct snd_ctl_elem_value32 { struct snd_ctl_elem_id id; unsigned int indirect; /* bit-field causes misalignment */ union { s32 integer[128]; unsigned char data[512]; #ifndef CONFIG_X86_64 s64 integer64[64]; #endif } value; unsigned char reserved[128]; }; #ifdef CONFIG_X86_X32_ABI /* x32 has a different alignment for 64bit values from ia32 */ struct snd_ctl_elem_value_x32 { struct snd_ctl_elem_id id; unsigned int indirect; /* bit-field causes misalignment */ union { s32 integer[128]; unsigned char data[512]; s64 integer64[64]; } value; unsigned char reserved[128]; }; #endif /* CONFIG_X86_X32_ABI */ /* get the value type and count of the control */ static int get_ctl_type(struct snd_card *card, struct snd_ctl_elem_id *id, int *countp) { struct snd_kcontrol *kctl; struct snd_ctl_elem_info *info; int err; down_read(&card->controls_rwsem); kctl = snd_ctl_find_id_locked(card, id); if (! kctl) { up_read(&card->controls_rwsem); return -ENOENT; } info = kzalloc(sizeof(*info), GFP_KERNEL); if (info == NULL) { up_read(&card->controls_rwsem); return -ENOMEM; } info->id = *id; err = snd_power_ref_and_wait(card); if (!err) err = kctl->info(kctl, info); snd_power_unref(card); up_read(&card->controls_rwsem); if (err >= 0) { err = info->type; *countp = info->count; } kfree(info); return err; } static int get_elem_size(snd_ctl_elem_type_t type, int count) { switch (type) { case SNDRV_CTL_ELEM_TYPE_INTEGER64: return sizeof(s64) * count; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return sizeof(int) * count; case SNDRV_CTL_ELEM_TYPE_BYTES: return 512; case SNDRV_CTL_ELEM_TYPE_IEC958: return sizeof(struct snd_aes_iec958); default: return -1; } } static int copy_ctl_value_from_user(struct snd_card *card, struct snd_ctl_elem_value *data, void __user *userdata, void __user *valuep, int *typep, int *countp) { struct snd_ctl_elem_value32 __user *data32 = userdata; int i, type, size; int count; unsigned int indirect; if (copy_from_user(&data->id, &data32->id, sizeof(data->id))) return -EFAULT; if (get_user(indirect, &data32->indirect)) return -EFAULT; if (indirect) return -EINVAL; type = get_ctl_type(card, &data->id, &count); if (type < 0) return type; if (type == (__force int)SNDRV_CTL_ELEM_TYPE_BOOLEAN || type == (__force int)SNDRV_CTL_ELEM_TYPE_INTEGER) { for (i = 0; i < count; i++) { s32 __user *intp = valuep; int val; if (get_user(val, &intp[i])) return -EFAULT; data->value.integer.value[i] = val; } } else { size = get_elem_size((__force snd_ctl_elem_type_t)type, count); if (size < 0) { dev_err(card->dev, "snd_ioctl32_ctl_elem_value: unknown type %d\n", type); return -EINVAL; } if (copy_from_user(data->value.bytes.data, valuep, size)) return -EFAULT; } *typep = type; *countp = count; return 0; } /* restore the value to 32bit */ static int copy_ctl_value_to_user(void __user *userdata, void __user *valuep, struct snd_ctl_elem_value *data, int type, int count) { struct snd_ctl_elem_value32 __user *data32 = userdata; int i, size; if (type == (__force int)SNDRV_CTL_ELEM_TYPE_BOOLEAN || type == (__force int)SNDRV_CTL_ELEM_TYPE_INTEGER) { for (i = 0; i < count; i++) { s32 __user *intp = valuep; int val; val = data->value.integer.value[i]; if (put_user(val, &intp[i])) return -EFAULT; } } else { size = get_elem_size((__force snd_ctl_elem_type_t)type, count); if (copy_to_user(valuep, data->value.bytes.data, size)) return -EFAULT; } if (copy_to_user(&data32->id, &data->id, sizeof(data32->id))) return -EFAULT; return 0; } static int ctl_elem_read_user(struct snd_card *card, void __user *userdata, void __user *valuep) { struct snd_ctl_elem_value *data; int err, type, count; data = kzalloc(sizeof(*data), GFP_KERNEL); if (data == NULL) return -ENOMEM; err = copy_ctl_value_from_user(card, data, userdata, valuep, &type, &count); if (err < 0) goto error; err = snd_ctl_elem_read(card, data); if (err < 0) goto error; err = copy_ctl_value_to_user(userdata, valuep, data, type, count); error: kfree(data); return err; } static int ctl_elem_write_user(struct snd_ctl_file *file, void __user *userdata, void __user *valuep) { struct snd_ctl_elem_value *data; struct snd_card *card = file->card; int err, type, count; data = kzalloc(sizeof(*data), GFP_KERNEL); if (data == NULL) return -ENOMEM; err = copy_ctl_value_from_user(card, data, userdata, valuep, &type, &count); if (err < 0) goto error; err = snd_ctl_elem_write(card, file, data); if (err < 0) goto error; err = copy_ctl_value_to_user(userdata, valuep, data, type, count); error: kfree(data); return err; } static int snd_ctl_elem_read_user_compat(struct snd_card *card, struct snd_ctl_elem_value32 __user *data32) { return ctl_elem_read_user(card, data32, &data32->value); } static int snd_ctl_elem_write_user_compat(struct snd_ctl_file *file, struct snd_ctl_elem_value32 __user *data32) { return ctl_elem_write_user(file, data32, &data32->value); } #ifdef CONFIG_X86_X32_ABI static int snd_ctl_elem_read_user_x32(struct snd_card *card, struct snd_ctl_elem_value_x32 __user *data32) { return ctl_elem_read_user(card, data32, &data32->value); } static int snd_ctl_elem_write_user_x32(struct snd_ctl_file *file, struct snd_ctl_elem_value_x32 __user *data32) { return ctl_elem_write_user(file, data32, &data32->value); } #endif /* CONFIG_X86_X32_ABI */ /* add or replace a user control */ static int snd_ctl_elem_add_compat(struct snd_ctl_file *file, struct snd_ctl_elem_info32 __user *data32, int replace) { struct snd_ctl_elem_info *data; int err; data = kzalloc(sizeof(*data), GFP_KERNEL); if (! data) return -ENOMEM; err = -EFAULT; /* id, type, access, count */ \ if (copy_from_user(&data->id, &data32->id, sizeof(data->id)) || copy_from_user(&data->type, &data32->type, 3 * sizeof(u32))) goto error; if (get_user(data->owner, &data32->owner)) goto error; switch (data->type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: case SNDRV_CTL_ELEM_TYPE_INTEGER: if (get_user(data->value.integer.min, &data32->value.integer.min) || get_user(data->value.integer.max, &data32->value.integer.max) || get_user(data->value.integer.step, &data32->value.integer.step)) goto error; break; case SNDRV_CTL_ELEM_TYPE_INTEGER64: if (copy_from_user(&data->value.integer64, &data32->value.integer64, sizeof(data->value.integer64))) goto error; break; case SNDRV_CTL_ELEM_TYPE_ENUMERATED: if (copy_from_user(&data->value.enumerated, &data32->value.enumerated, sizeof(data->value.enumerated))) goto error; data->value.enumerated.names_ptr = (uintptr_t)compat_ptr(data->value.enumerated.names_ptr); break; default: break; } err = snd_ctl_elem_add(file, data, replace); error: kfree(data); return err; } enum { SNDRV_CTL_IOCTL_ELEM_LIST32 = _IOWR('U', 0x10, struct snd_ctl_elem_list32), SNDRV_CTL_IOCTL_ELEM_INFO32 = _IOWR('U', 0x11, struct snd_ctl_elem_info32), SNDRV_CTL_IOCTL_ELEM_READ32 = _IOWR('U', 0x12, struct snd_ctl_elem_value32), SNDRV_CTL_IOCTL_ELEM_WRITE32 = _IOWR('U', 0x13, struct snd_ctl_elem_value32), SNDRV_CTL_IOCTL_ELEM_ADD32 = _IOWR('U', 0x17, struct snd_ctl_elem_info32), SNDRV_CTL_IOCTL_ELEM_REPLACE32 = _IOWR('U', 0x18, struct snd_ctl_elem_info32), #ifdef CONFIG_X86_X32_ABI SNDRV_CTL_IOCTL_ELEM_READ_X32 = _IOWR('U', 0x12, struct snd_ctl_elem_value_x32), SNDRV_CTL_IOCTL_ELEM_WRITE_X32 = _IOWR('U', 0x13, struct snd_ctl_elem_value_x32), #endif /* CONFIG_X86_X32_ABI */ }; static inline long snd_ctl_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_ctl_file *ctl; struct snd_kctl_ioctl *p; void __user *argp = compat_ptr(arg); int err; ctl = file->private_data; if (snd_BUG_ON(!ctl || !ctl->card)) return -ENXIO; switch (cmd) { case SNDRV_CTL_IOCTL_PVERSION: case SNDRV_CTL_IOCTL_CARD_INFO: case SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS: case SNDRV_CTL_IOCTL_POWER: case SNDRV_CTL_IOCTL_POWER_STATE: case SNDRV_CTL_IOCTL_ELEM_LOCK: case SNDRV_CTL_IOCTL_ELEM_UNLOCK: case SNDRV_CTL_IOCTL_ELEM_REMOVE: case SNDRV_CTL_IOCTL_TLV_READ: case SNDRV_CTL_IOCTL_TLV_WRITE: case SNDRV_CTL_IOCTL_TLV_COMMAND: return snd_ctl_ioctl(file, cmd, (unsigned long)argp); case SNDRV_CTL_IOCTL_ELEM_LIST32: return snd_ctl_elem_list_compat(ctl->card, argp); case SNDRV_CTL_IOCTL_ELEM_INFO32: return snd_ctl_elem_info_compat(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_READ32: return snd_ctl_elem_read_user_compat(ctl->card, argp); case SNDRV_CTL_IOCTL_ELEM_WRITE32: return snd_ctl_elem_write_user_compat(ctl, argp); case SNDRV_CTL_IOCTL_ELEM_ADD32: return snd_ctl_elem_add_compat(ctl, argp, 0); case SNDRV_CTL_IOCTL_ELEM_REPLACE32: return snd_ctl_elem_add_compat(ctl, argp, 1); #ifdef CONFIG_X86_X32_ABI case SNDRV_CTL_IOCTL_ELEM_READ_X32: return snd_ctl_elem_read_user_x32(ctl->card, argp); case SNDRV_CTL_IOCTL_ELEM_WRITE_X32: return snd_ctl_elem_write_user_x32(ctl, argp); #endif /* CONFIG_X86_X32_ABI */ } down_read(&snd_ioctl_rwsem); list_for_each_entry(p, &snd_control_compat_ioctls, list) { if (p->fioctl) { err = p->fioctl(ctl->card, ctl, cmd, arg); if (err != -ENOIOCTLCMD) { up_read(&snd_ioctl_rwsem); return err; } } } up_read(&snd_ioctl_rwsem); return -ENOIOCTLCMD; }
linux-master
sound/core/control_compat.c
// SPDX-License-Identifier: GPL-2.0-only /* * Virtual master and follower controls * * Copyright (c) 2008 by Takashi Iwai <[email protected]> */ #include <linux/slab.h> #include <linux/export.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h> /* * a subset of information returned via ctl info callback */ struct link_ctl_info { snd_ctl_elem_type_t type; /* value type */ int count; /* item count */ int min_val, max_val; /* min, max values */ }; /* * link master - this contains a list of follower controls that are * identical types, i.e. info returns the same value type and value * ranges, but may have different number of counts. * * The master control is so far only mono volume/switch for simplicity. * The same value will be applied to all followers. */ struct link_master { struct list_head followers; struct link_ctl_info info; int val; /* the master value */ unsigned int tlv[4]; void (*hook)(void *private_data, int); void *hook_private_data; }; /* * link follower - this contains a follower control element * * It fakes the control callbacks with additional attenuation by the * master control. A follower may have either one or two channels. */ struct link_follower { struct list_head list; struct link_master *master; struct link_ctl_info info; int vals[2]; /* current values */ unsigned int flags; struct snd_kcontrol *kctl; /* original kcontrol pointer */ struct snd_kcontrol follower; /* the copy of original control entry */ }; static int follower_update(struct link_follower *follower) { struct snd_ctl_elem_value *uctl; int err, ch; uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); if (!uctl) return -ENOMEM; uctl->id = follower->follower.id; err = follower->follower.get(&follower->follower, uctl); if (err < 0) goto error; for (ch = 0; ch < follower->info.count; ch++) follower->vals[ch] = uctl->value.integer.value[ch]; error: kfree(uctl); return err < 0 ? err : 0; } /* get the follower ctl info and save the initial values */ static int follower_init(struct link_follower *follower) { struct snd_ctl_elem_info *uinfo; int err; if (follower->info.count) { /* already initialized */ if (follower->flags & SND_CTL_FOLLOWER_NEED_UPDATE) return follower_update(follower); return 0; } uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL); if (!uinfo) return -ENOMEM; uinfo->id = follower->follower.id; err = follower->follower.info(&follower->follower, uinfo); if (err < 0) { kfree(uinfo); return err; } follower->info.type = uinfo->type; follower->info.count = uinfo->count; if (follower->info.count > 2 || (follower->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER && follower->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) { pr_err("ALSA: vmaster: invalid follower element\n"); kfree(uinfo); return -EINVAL; } follower->info.min_val = uinfo->value.integer.min; follower->info.max_val = uinfo->value.integer.max; kfree(uinfo); return follower_update(follower); } /* initialize master volume */ static int master_init(struct link_master *master) { struct link_follower *follower; if (master->info.count) return 0; /* already initialized */ list_for_each_entry(follower, &master->followers, list) { int err = follower_init(follower); if (err < 0) return err; master->info = follower->info; master->info.count = 1; /* always mono */ /* set full volume as default (= no attenuation) */ master->val = master->info.max_val; if (master->hook) master->hook(master->hook_private_data, master->val); return 1; } return -ENOENT; } static int follower_get_val(struct link_follower *follower, struct snd_ctl_elem_value *ucontrol) { int err, ch; err = follower_init(follower); if (err < 0) return err; for (ch = 0; ch < follower->info.count; ch++) ucontrol->value.integer.value[ch] = follower->vals[ch]; return 0; } static int follower_put_val(struct link_follower *follower, struct snd_ctl_elem_value *ucontrol) { int err, ch, vol; err = master_init(follower->master); if (err < 0) return err; switch (follower->info.type) { case SNDRV_CTL_ELEM_TYPE_BOOLEAN: for (ch = 0; ch < follower->info.count; ch++) ucontrol->value.integer.value[ch] &= !!follower->master->val; break; case SNDRV_CTL_ELEM_TYPE_INTEGER: for (ch = 0; ch < follower->info.count; ch++) { /* max master volume is supposed to be 0 dB */ vol = ucontrol->value.integer.value[ch]; vol += follower->master->val - follower->master->info.max_val; if (vol < follower->info.min_val) vol = follower->info.min_val; else if (vol > follower->info.max_val) vol = follower->info.max_val; ucontrol->value.integer.value[ch] = vol; } break; } return follower->follower.put(&follower->follower, ucontrol); } /* * ctl callbacks for followers */ static int follower_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct link_follower *follower = snd_kcontrol_chip(kcontrol); return follower->follower.info(&follower->follower, uinfo); } static int follower_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct link_follower *follower = snd_kcontrol_chip(kcontrol); return follower_get_val(follower, ucontrol); } static int follower_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct link_follower *follower = snd_kcontrol_chip(kcontrol); int err, ch, changed = 0; err = follower_init(follower); if (err < 0) return err; for (ch = 0; ch < follower->info.count; ch++) { if (follower->vals[ch] != ucontrol->value.integer.value[ch]) { changed = 1; follower->vals[ch] = ucontrol->value.integer.value[ch]; } } if (!changed) return 0; err = follower_put_val(follower, ucontrol); if (err < 0) return err; return 1; } static int follower_tlv_cmd(struct snd_kcontrol *kcontrol, int op_flag, unsigned int size, unsigned int __user *tlv) { struct link_follower *follower = snd_kcontrol_chip(kcontrol); /* FIXME: this assumes that the max volume is 0 dB */ return follower->follower.tlv.c(&follower->follower, op_flag, size, tlv); } static void follower_free(struct snd_kcontrol *kcontrol) { struct link_follower *follower = snd_kcontrol_chip(kcontrol); if (follower->follower.private_free) follower->follower.private_free(&follower->follower); if (follower->master) list_del(&follower->list); kfree(follower); } /* * Add a follower control to the group with the given master control * * All followers must be the same type (returning the same information * via info callback). The function doesn't check it, so it's your * responsibility. * * Also, some additional limitations: * - at most two channels * - logarithmic volume control (dB level), no linear volume * - master can only attenuate the volume, no gain */ int _snd_ctl_add_follower(struct snd_kcontrol *master, struct snd_kcontrol *follower, unsigned int flags) { struct link_master *master_link = snd_kcontrol_chip(master); struct link_follower *srec; srec = kzalloc(struct_size(srec, follower.vd, follower->count), GFP_KERNEL); if (!srec) return -ENOMEM; srec->kctl = follower; srec->follower = *follower; memcpy(srec->follower.vd, follower->vd, follower->count * sizeof(*follower->vd)); srec->master = master_link; srec->flags = flags; /* override callbacks */ follower->info = follower_info; follower->get = follower_get; follower->put = follower_put; if (follower->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) follower->tlv.c = follower_tlv_cmd; follower->private_data = srec; follower->private_free = follower_free; list_add_tail(&srec->list, &master_link->followers); return 0; } EXPORT_SYMBOL(_snd_ctl_add_follower); /** * snd_ctl_add_followers - add multiple followers to vmaster * @card: card instance * @master: the target vmaster kcontrol object * @list: NULL-terminated list of name strings of followers to be added * * Adds the multiple follower kcontrols with the given names. * Returns 0 for success or a negative error code. */ int snd_ctl_add_followers(struct snd_card *card, struct snd_kcontrol *master, const char * const *list) { struct snd_kcontrol *follower; int err; for (; *list; list++) { follower = snd_ctl_find_id_mixer(card, *list); if (follower) { err = snd_ctl_add_follower(master, follower); if (err < 0) return err; } } return 0; } EXPORT_SYMBOL_GPL(snd_ctl_add_followers); /* * ctl callbacks for master controls */ static int master_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct link_master *master = snd_kcontrol_chip(kcontrol); int ret; ret = master_init(master); if (ret < 0) return ret; uinfo->type = master->info.type; uinfo->count = master->info.count; uinfo->value.integer.min = master->info.min_val; uinfo->value.integer.max = master->info.max_val; return 0; } static int master_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct link_master *master = snd_kcontrol_chip(kcontrol); int err = master_init(master); if (err < 0) return err; ucontrol->value.integer.value[0] = master->val; return 0; } static int sync_followers(struct link_master *master, int old_val, int new_val) { struct link_follower *follower; struct snd_ctl_elem_value *uval; uval = kmalloc(sizeof(*uval), GFP_KERNEL); if (!uval) return -ENOMEM; list_for_each_entry(follower, &master->followers, list) { master->val = old_val; uval->id = follower->follower.id; follower_get_val(follower, uval); master->val = new_val; follower_put_val(follower, uval); } kfree(uval); return 0; } static int master_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct link_master *master = snd_kcontrol_chip(kcontrol); int err, new_val, old_val; bool first_init; err = master_init(master); if (err < 0) return err; first_init = err; old_val = master->val; new_val = ucontrol->value.integer.value[0]; if (new_val == old_val) return 0; err = sync_followers(master, old_val, new_val); if (err < 0) return err; if (master->hook && !first_init) master->hook(master->hook_private_data, master->val); return 1; } static void master_free(struct snd_kcontrol *kcontrol) { struct link_master *master = snd_kcontrol_chip(kcontrol); struct link_follower *follower, *n; /* free all follower links and retore the original follower kctls */ list_for_each_entry_safe(follower, n, &master->followers, list) { struct snd_kcontrol *sctl = follower->kctl; struct list_head olist = sctl->list; memcpy(sctl, &follower->follower, sizeof(*sctl)); memcpy(sctl->vd, follower->follower.vd, sctl->count * sizeof(*sctl->vd)); sctl->list = olist; /* keep the current linked-list */ kfree(follower); } kfree(master); } /** * snd_ctl_make_virtual_master - Create a virtual master control * @name: name string of the control element to create * @tlv: optional TLV int array for dB information * * Creates a virtual master control with the given name string. * * After creating a vmaster element, you can add the follower controls * via snd_ctl_add_follower() or snd_ctl_add_follower_uncached(). * * The optional argument @tlv can be used to specify the TLV information * for dB scale of the master control. It should be a single element * with #SNDRV_CTL_TLVT_DB_SCALE, #SNDRV_CTL_TLV_DB_MINMAX or * #SNDRV_CTL_TLVT_DB_MINMAX_MUTE type, and should be the max 0dB. * * Return: The created control element, or %NULL for errors (ENOMEM). */ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, const unsigned int *tlv) { struct link_master *master; struct snd_kcontrol *kctl; struct snd_kcontrol_new knew; memset(&knew, 0, sizeof(knew)); knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; knew.name = name; knew.info = master_info; master = kzalloc(sizeof(*master), GFP_KERNEL); if (!master) return NULL; INIT_LIST_HEAD(&master->followers); kctl = snd_ctl_new1(&knew, master); if (!kctl) { kfree(master); return NULL; } /* override some callbacks */ kctl->info = master_info; kctl->get = master_get; kctl->put = master_put; kctl->private_free = master_free; /* additional (constant) TLV read */ if (tlv) { unsigned int type = tlv[SNDRV_CTL_TLVO_TYPE]; if (type == SNDRV_CTL_TLVT_DB_SCALE || type == SNDRV_CTL_TLVT_DB_MINMAX || type == SNDRV_CTL_TLVT_DB_MINMAX_MUTE) { kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; memcpy(master->tlv, tlv, sizeof(master->tlv)); kctl->tlv.p = master->tlv; } } return kctl; } EXPORT_SYMBOL(snd_ctl_make_virtual_master); /** * snd_ctl_add_vmaster_hook - Add a hook to a vmaster control * @kcontrol: vmaster kctl element * @hook: the hook function * @private_data: the private_data pointer to be saved * * Adds the given hook to the vmaster control element so that it's called * at each time when the value is changed. * * Return: Zero. */ int snd_ctl_add_vmaster_hook(struct snd_kcontrol *kcontrol, void (*hook)(void *private_data, int), void *private_data) { struct link_master *master = snd_kcontrol_chip(kcontrol); master->hook = hook; master->hook_private_data = private_data; return 0; } EXPORT_SYMBOL_GPL(snd_ctl_add_vmaster_hook); /** * snd_ctl_sync_vmaster - Sync the vmaster followers and hook * @kcontrol: vmaster kctl element * @hook_only: sync only the hook * * Forcibly call the put callback of each follower and call the hook function * to synchronize with the current value of the given vmaster element. * NOP when NULL is passed to @kcontrol. */ void snd_ctl_sync_vmaster(struct snd_kcontrol *kcontrol, bool hook_only) { struct link_master *master; bool first_init = false; if (!kcontrol) return; master = snd_kcontrol_chip(kcontrol); if (!hook_only) { int err = master_init(master); if (err < 0) return; first_init = err; err = sync_followers(master, master->val, master->val); if (err < 0) return; } if (master->hook && !first_init) master->hook(master->hook_private_data, master->val); } EXPORT_SYMBOL_GPL(snd_ctl_sync_vmaster); /** * snd_ctl_apply_vmaster_followers - Apply function to each vmaster follower * @kctl: vmaster kctl element * @func: function to apply * @arg: optional function argument * * Apply the function @func to each follower kctl of the given vmaster kctl. * * Return: 0 if successful, or a negative error code */ int snd_ctl_apply_vmaster_followers(struct snd_kcontrol *kctl, int (*func)(struct snd_kcontrol *vfollower, struct snd_kcontrol *follower, void *arg), void *arg) { struct link_master *master; struct link_follower *follower; int err; master = snd_kcontrol_chip(kctl); err = master_init(master); if (err < 0) return err; list_for_each_entry(follower, &master->followers, list) { err = func(follower->kctl, &follower->follower, arg); if (err < 0) return err; } return 0; } EXPORT_SYMBOL_GPL(snd_ctl_apply_vmaster_followers);
linux-master
sound/core/vmaster.c
// SPDX-License-Identifier: GPL-2.0-only /* * compress_core.c - compress offload core * * Copyright (C) 2011 Intel Corporation * Authors: Vinod Koul <[email protected]> * Pierre-Louis Bossart <[email protected]> * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #define FORMAT(fmt) "%s: %d: " fmt, __func__, __LINE__ #define pr_fmt(fmt) KBUILD_MODNAME ": " FORMAT(fmt) #include <linux/file.h> #include <linux/fs.h> #include <linux/list.h> #include <linux/math64.h> #include <linux/mm.h> #include <linux/mutex.h> #include <linux/poll.h> #include <linux/slab.h> #include <linux/sched.h> #include <linux/types.h> #include <linux/uio.h> #include <linux/uaccess.h> #include <linux/module.h> #include <linux/compat.h> #include <sound/core.h> #include <sound/initval.h> #include <sound/info.h> #include <sound/compress_params.h> #include <sound/compress_offload.h> #include <sound/compress_driver.h> /* struct snd_compr_codec_caps overflows the ioctl bit size for some * architectures, so we need to disable the relevant ioctls. */ #if _IOC_SIZEBITS < 14 #define COMPR_CODEC_CAPS_OVERFLOW #endif /* TODO: * - add substream support for multiple devices in case of * SND_DYNAMIC_MINORS is not used * - Multiple node representation * driver should be able to register multiple nodes */ struct snd_compr_file { unsigned long caps; struct snd_compr_stream stream; }; static void error_delayed_work(struct work_struct *work); /* * a note on stream states used: * we use following states in the compressed core * SNDRV_PCM_STATE_OPEN: When stream has been opened. * SNDRV_PCM_STATE_SETUP: When stream has been initialized. This is done by * calling SNDRV_COMPRESS_SET_PARAMS. Running streams will come to this * state at stop by calling SNDRV_COMPRESS_STOP, or at end of drain. * SNDRV_PCM_STATE_PREPARED: When a stream has been written to (for * playback only). User after setting up stream writes the data buffer * before starting the stream. * SNDRV_PCM_STATE_RUNNING: When stream has been started and is * decoding/encoding and rendering/capturing data. * SNDRV_PCM_STATE_DRAINING: When stream is draining current data. This is done * by calling SNDRV_COMPRESS_DRAIN. * SNDRV_PCM_STATE_PAUSED: When stream is paused. This is done by calling * SNDRV_COMPRESS_PAUSE. It can be stopped or resumed by calling * SNDRV_COMPRESS_STOP or SNDRV_COMPRESS_RESUME respectively. */ static int snd_compr_open(struct inode *inode, struct file *f) { struct snd_compr *compr; struct snd_compr_file *data; struct snd_compr_runtime *runtime; enum snd_compr_direction dirn; int maj = imajor(inode); int ret; if ((f->f_flags & O_ACCMODE) == O_WRONLY) dirn = SND_COMPRESS_PLAYBACK; else if ((f->f_flags & O_ACCMODE) == O_RDONLY) dirn = SND_COMPRESS_CAPTURE; else return -EINVAL; if (maj == snd_major) compr = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_COMPRESS); else return -EBADFD; if (compr == NULL) { pr_err("no device data!!!\n"); return -ENODEV; } if (dirn != compr->direction) { pr_err("this device doesn't support this direction\n"); snd_card_unref(compr->card); return -EINVAL; } data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { snd_card_unref(compr->card); return -ENOMEM; } INIT_DELAYED_WORK(&data->stream.error_work, error_delayed_work); data->stream.ops = compr->ops; data->stream.direction = dirn; data->stream.private_data = compr->private_data; data->stream.device = compr; runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); if (!runtime) { kfree(data); snd_card_unref(compr->card); return -ENOMEM; } runtime->state = SNDRV_PCM_STATE_OPEN; init_waitqueue_head(&runtime->sleep); data->stream.runtime = runtime; f->private_data = (void *)data; mutex_lock(&compr->lock); ret = compr->ops->open(&data->stream); mutex_unlock(&compr->lock); if (ret) { kfree(runtime); kfree(data); } snd_card_unref(compr->card); return ret; } static int snd_compr_free(struct inode *inode, struct file *f) { struct snd_compr_file *data = f->private_data; struct snd_compr_runtime *runtime = data->stream.runtime; cancel_delayed_work_sync(&data->stream.error_work); switch (runtime->state) { case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_DRAINING: case SNDRV_PCM_STATE_PAUSED: data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP); break; default: break; } data->stream.ops->free(&data->stream); if (!data->stream.runtime->dma_buffer_p) kfree(data->stream.runtime->buffer); kfree(data->stream.runtime); kfree(data); return 0; } static int snd_compr_update_tstamp(struct snd_compr_stream *stream, struct snd_compr_tstamp *tstamp) { if (!stream->ops->pointer) return -ENOTSUPP; stream->ops->pointer(stream, tstamp); pr_debug("dsp consumed till %d total %d bytes\n", tstamp->byte_offset, tstamp->copied_total); if (stream->direction == SND_COMPRESS_PLAYBACK) stream->runtime->total_bytes_transferred = tstamp->copied_total; else stream->runtime->total_bytes_available = tstamp->copied_total; return 0; } static size_t snd_compr_calc_avail(struct snd_compr_stream *stream, struct snd_compr_avail *avail) { memset(avail, 0, sizeof(*avail)); snd_compr_update_tstamp(stream, &avail->tstamp); /* Still need to return avail even if tstamp can't be filled in */ if (stream->runtime->total_bytes_available == 0 && stream->runtime->state == SNDRV_PCM_STATE_SETUP && stream->direction == SND_COMPRESS_PLAYBACK) { pr_debug("detected init and someone forgot to do a write\n"); return stream->runtime->buffer_size; } pr_debug("app wrote %lld, DSP consumed %lld\n", stream->runtime->total_bytes_available, stream->runtime->total_bytes_transferred); if (stream->runtime->total_bytes_available == stream->runtime->total_bytes_transferred) { if (stream->direction == SND_COMPRESS_PLAYBACK) { pr_debug("both pointers are same, returning full avail\n"); return stream->runtime->buffer_size; } else { pr_debug("both pointers are same, returning no avail\n"); return 0; } } avail->avail = stream->runtime->total_bytes_available - stream->runtime->total_bytes_transferred; if (stream->direction == SND_COMPRESS_PLAYBACK) avail->avail = stream->runtime->buffer_size - avail->avail; pr_debug("ret avail as %lld\n", avail->avail); return avail->avail; } static inline size_t snd_compr_get_avail(struct snd_compr_stream *stream) { struct snd_compr_avail avail; return snd_compr_calc_avail(stream, &avail); } static int snd_compr_ioctl_avail(struct snd_compr_stream *stream, unsigned long arg) { struct snd_compr_avail ioctl_avail; size_t avail; avail = snd_compr_calc_avail(stream, &ioctl_avail); ioctl_avail.avail = avail; switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: return -EBADFD; case SNDRV_PCM_STATE_XRUN: return -EPIPE; default: break; } if (copy_to_user((__u64 __user *)arg, &ioctl_avail, sizeof(ioctl_avail))) return -EFAULT; return 0; } static int snd_compr_write_data(struct snd_compr_stream *stream, const char __user *buf, size_t count) { void *dstn; size_t copy; struct snd_compr_runtime *runtime = stream->runtime; /* 64-bit Modulus */ u64 app_pointer = div64_u64(runtime->total_bytes_available, runtime->buffer_size); app_pointer = runtime->total_bytes_available - (app_pointer * runtime->buffer_size); dstn = runtime->buffer + app_pointer; pr_debug("copying %ld at %lld\n", (unsigned long)count, app_pointer); if (count < runtime->buffer_size - app_pointer) { if (copy_from_user(dstn, buf, count)) return -EFAULT; } else { copy = runtime->buffer_size - app_pointer; if (copy_from_user(dstn, buf, copy)) return -EFAULT; if (copy_from_user(runtime->buffer, buf + copy, count - copy)) return -EFAULT; } /* if DSP cares, let it know data has been written */ if (stream->ops->ack) stream->ops->ack(stream, count); return count; } static ssize_t snd_compr_write(struct file *f, const char __user *buf, size_t count, loff_t *offset) { struct snd_compr_file *data = f->private_data; struct snd_compr_stream *stream; size_t avail; int retval; if (snd_BUG_ON(!data)) return -EFAULT; stream = &data->stream; mutex_lock(&stream->device->lock); /* write is allowed when stream is running or has been steup */ switch (stream->runtime->state) { case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_RUNNING: break; default: mutex_unlock(&stream->device->lock); return -EBADFD; } avail = snd_compr_get_avail(stream); pr_debug("avail returned %ld\n", (unsigned long)avail); /* calculate how much we can write to buffer */ if (avail > count) avail = count; if (stream->ops->copy) { char __user* cbuf = (char __user*)buf; retval = stream->ops->copy(stream, cbuf, avail); } else { retval = snd_compr_write_data(stream, buf, avail); } if (retval > 0) stream->runtime->total_bytes_available += retval; /* while initiating the stream, write should be called before START * call, so in setup move state */ if (stream->runtime->state == SNDRV_PCM_STATE_SETUP) { stream->runtime->state = SNDRV_PCM_STATE_PREPARED; pr_debug("stream prepared, Houston we are good to go\n"); } mutex_unlock(&stream->device->lock); return retval; } static ssize_t snd_compr_read(struct file *f, char __user *buf, size_t count, loff_t *offset) { struct snd_compr_file *data = f->private_data; struct snd_compr_stream *stream; size_t avail; int retval; if (snd_BUG_ON(!data)) return -EFAULT; stream = &data->stream; mutex_lock(&stream->device->lock); /* read is allowed when stream is running, paused, draining and setup * (yes setup is state which we transition to after stop, so if user * wants to read data after stop we allow that) */ switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_SUSPENDED: case SNDRV_PCM_STATE_DISCONNECTED: retval = -EBADFD; goto out; case SNDRV_PCM_STATE_XRUN: retval = -EPIPE; goto out; } avail = snd_compr_get_avail(stream); pr_debug("avail returned %ld\n", (unsigned long)avail); /* calculate how much we can read from buffer */ if (avail > count) avail = count; if (stream->ops->copy) { retval = stream->ops->copy(stream, buf, avail); } else { retval = -ENXIO; goto out; } if (retval > 0) stream->runtime->total_bytes_transferred += retval; out: mutex_unlock(&stream->device->lock); return retval; } static int snd_compr_mmap(struct file *f, struct vm_area_struct *vma) { return -ENXIO; } static __poll_t snd_compr_get_poll(struct snd_compr_stream *stream) { if (stream->direction == SND_COMPRESS_PLAYBACK) return EPOLLOUT | EPOLLWRNORM; else return EPOLLIN | EPOLLRDNORM; } static __poll_t snd_compr_poll(struct file *f, poll_table *wait) { struct snd_compr_file *data = f->private_data; struct snd_compr_stream *stream; size_t avail; __poll_t retval = 0; if (snd_BUG_ON(!data)) return EPOLLERR; stream = &data->stream; mutex_lock(&stream->device->lock); switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_XRUN: retval = snd_compr_get_poll(stream) | EPOLLERR; goto out; default: break; } poll_wait(f, &stream->runtime->sleep, wait); avail = snd_compr_get_avail(stream); pr_debug("avail is %ld\n", (unsigned long)avail); /* check if we have at least one fragment to fill */ switch (stream->runtime->state) { case SNDRV_PCM_STATE_DRAINING: /* stream has been woken up after drain is complete * draining done so set stream state to stopped */ retval = snd_compr_get_poll(stream); stream->runtime->state = SNDRV_PCM_STATE_SETUP; break; case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: if (avail >= stream->runtime->fragment_size) retval = snd_compr_get_poll(stream); break; default: retval = snd_compr_get_poll(stream) | EPOLLERR; break; } out: mutex_unlock(&stream->device->lock); return retval; } static int snd_compr_get_caps(struct snd_compr_stream *stream, unsigned long arg) { int retval; struct snd_compr_caps caps; if (!stream->ops->get_caps) return -ENXIO; memset(&caps, 0, sizeof(caps)); retval = stream->ops->get_caps(stream, &caps); if (retval) goto out; if (copy_to_user((void __user *)arg, &caps, sizeof(caps))) retval = -EFAULT; out: return retval; } #ifndef COMPR_CODEC_CAPS_OVERFLOW static int snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) { int retval; struct snd_compr_codec_caps *caps; if (!stream->ops->get_codec_caps) return -ENXIO; caps = kzalloc(sizeof(*caps), GFP_KERNEL); if (!caps) return -ENOMEM; retval = stream->ops->get_codec_caps(stream, caps); if (retval) goto out; if (copy_to_user((void __user *)arg, caps, sizeof(*caps))) retval = -EFAULT; out: kfree(caps); return retval; } #endif /* !COMPR_CODEC_CAPS_OVERFLOW */ int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size) { struct snd_dma_buffer *dmab; int ret; if (snd_BUG_ON(!(stream) || !(stream)->runtime)) return -EINVAL; dmab = kzalloc(sizeof(*dmab), GFP_KERNEL); if (!dmab) return -ENOMEM; dmab->dev = stream->dma_buffer.dev; ret = snd_dma_alloc_pages(dmab->dev.type, dmab->dev.dev, size, dmab); if (ret < 0) { kfree(dmab); return ret; } snd_compr_set_runtime_buffer(stream, dmab); stream->runtime->dma_bytes = size; return 1; } EXPORT_SYMBOL(snd_compr_malloc_pages); int snd_compr_free_pages(struct snd_compr_stream *stream) { struct snd_compr_runtime *runtime; if (snd_BUG_ON(!(stream) || !(stream)->runtime)) return -EINVAL; runtime = stream->runtime; if (runtime->dma_area == NULL) return 0; if (runtime->dma_buffer_p != &stream->dma_buffer) { /* It's a newly allocated buffer. Release it now. */ snd_dma_free_pages(runtime->dma_buffer_p); kfree(runtime->dma_buffer_p); } snd_compr_set_runtime_buffer(stream, NULL); return 0; } EXPORT_SYMBOL(snd_compr_free_pages); /* revisit this with snd_pcm_preallocate_xxx */ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, struct snd_compr_params *params) { unsigned int buffer_size; void *buffer = NULL; buffer_size = params->buffer.fragment_size * params->buffer.fragments; if (stream->ops->copy) { buffer = NULL; /* if copy is defined the driver will be required to copy * the data from core */ } else { if (stream->runtime->dma_buffer_p) { if (buffer_size > stream->runtime->dma_buffer_p->bytes) dev_err(stream->device->dev, "Not enough DMA buffer"); else buffer = stream->runtime->dma_buffer_p->area; } else { buffer = kmalloc(buffer_size, GFP_KERNEL); } if (!buffer) return -ENOMEM; } stream->runtime->fragment_size = params->buffer.fragment_size; stream->runtime->fragments = params->buffer.fragments; stream->runtime->buffer = buffer; stream->runtime->buffer_size = buffer_size; return 0; } static int snd_compress_check_input(struct snd_compr_params *params) { /* first let's check the buffer parameter's */ if (params->buffer.fragment_size == 0 || params->buffer.fragments > U32_MAX / params->buffer.fragment_size || params->buffer.fragments == 0) return -EINVAL; /* now codec parameters */ if (params->codec.id == 0 || params->codec.id > SND_AUDIOCODEC_MAX) return -EINVAL; if (params->codec.ch_in == 0 || params->codec.ch_out == 0) return -EINVAL; return 0; } static int snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) { struct snd_compr_params *params; int retval; if (stream->runtime->state == SNDRV_PCM_STATE_OPEN || stream->next_track) { /* * we should allow parameter change only when stream has been * opened not in other cases */ params = memdup_user((void __user *)arg, sizeof(*params)); if (IS_ERR(params)) return PTR_ERR(params); retval = snd_compress_check_input(params); if (retval) goto out; retval = snd_compr_allocate_buffer(stream, params); if (retval) { retval = -ENOMEM; goto out; } retval = stream->ops->set_params(stream, params); if (retval) goto out; if (stream->next_track) goto out; stream->metadata_set = false; stream->next_track = false; stream->runtime->state = SNDRV_PCM_STATE_SETUP; } else { return -EPERM; } out: kfree(params); return retval; } static int snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg) { struct snd_codec *params; int retval; if (!stream->ops->get_params) return -EBADFD; params = kzalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; retval = stream->ops->get_params(stream, params); if (retval) goto out; if (copy_to_user((char __user *)arg, params, sizeof(*params))) retval = -EFAULT; out: kfree(params); return retval; } static int snd_compr_get_metadata(struct snd_compr_stream *stream, unsigned long arg) { struct snd_compr_metadata metadata; int retval; if (!stream->ops->get_metadata) return -ENXIO; if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata))) return -EFAULT; retval = stream->ops->get_metadata(stream, &metadata); if (retval != 0) return retval; if (copy_to_user((void __user *)arg, &metadata, sizeof(metadata))) return -EFAULT; return 0; } static int snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) { struct snd_compr_metadata metadata; int retval; if (!stream->ops->set_metadata) return -ENXIO; /* * we should allow parameter change only when stream has been * opened not in other cases */ if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata))) return -EFAULT; retval = stream->ops->set_metadata(stream, &metadata); stream->metadata_set = true; return retval; } static inline int snd_compr_tstamp(struct snd_compr_stream *stream, unsigned long arg) { struct snd_compr_tstamp tstamp = {0}; int ret; ret = snd_compr_update_tstamp(stream, &tstamp); if (ret == 0) ret = copy_to_user((struct snd_compr_tstamp __user *)arg, &tstamp, sizeof(tstamp)) ? -EFAULT : 0; return ret; } static int snd_compr_pause(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_RUNNING: retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); if (!retval) stream->runtime->state = SNDRV_PCM_STATE_PAUSED; break; case SNDRV_PCM_STATE_DRAINING: if (!stream->device->use_pause_in_draining) return -EPERM; retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); if (!retval) stream->pause_in_draining = true; break; default: return -EPERM; } return retval; } static int snd_compr_resume(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_PAUSED: retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); if (!retval) stream->runtime->state = SNDRV_PCM_STATE_RUNNING; break; case SNDRV_PCM_STATE_DRAINING: if (!stream->pause_in_draining) return -EPERM; retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); if (!retval) stream->pause_in_draining = false; break; default: return -EPERM; } return retval; } static int snd_compr_start(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_SETUP: if (stream->direction != SND_COMPRESS_CAPTURE) return -EPERM; break; case SNDRV_PCM_STATE_PREPARED: break; default: return -EPERM; } retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_START); if (!retval) stream->runtime->state = SNDRV_PCM_STATE_RUNNING; return retval; } static int snd_compr_stop(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: return -EPERM; default: break; } retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); if (!retval) { /* clear flags and stop any drain wait */ stream->partial_drain = false; stream->metadata_set = false; stream->pause_in_draining = false; snd_compr_drain_notify(stream); stream->runtime->total_bytes_available = 0; stream->runtime->total_bytes_transferred = 0; } return retval; } static void error_delayed_work(struct work_struct *work) { struct snd_compr_stream *stream; stream = container_of(work, struct snd_compr_stream, error_work.work); mutex_lock(&stream->device->lock); stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); wake_up(&stream->runtime->sleep); mutex_unlock(&stream->device->lock); } /** * snd_compr_stop_error: Report a fatal error on a stream * @stream: pointer to stream * @state: state to transition the stream to * * Stop the stream and set its state. * * Should be called with compressed device lock held. * * Return: zero if successful, or a negative error code */ int snd_compr_stop_error(struct snd_compr_stream *stream, snd_pcm_state_t state) { if (stream->runtime->state == state) return 0; stream->runtime->state = state; pr_debug("Changing state to: %d\n", state); queue_delayed_work(system_power_efficient_wq, &stream->error_work, 0); return 0; } EXPORT_SYMBOL_GPL(snd_compr_stop_error); static int snd_compress_wait_for_drain(struct snd_compr_stream *stream) { int ret; /* * We are called with lock held. So drop the lock while we wait for * drain complete notification from the driver * * It is expected that driver will notify the drain completion and then * stream will be moved to SETUP state, even if draining resulted in an * error. We can trigger next track after this. */ stream->runtime->state = SNDRV_PCM_STATE_DRAINING; mutex_unlock(&stream->device->lock); /* we wait for drain to complete here, drain can return when * interruption occurred, wait returned error or success. * For the first two cases we don't do anything different here and * return after waking up */ ret = wait_event_interruptible(stream->runtime->sleep, (stream->runtime->state != SNDRV_PCM_STATE_DRAINING)); if (ret == -ERESTARTSYS) pr_debug("wait aborted by a signal\n"); else if (ret) pr_debug("wait for drain failed with %d\n", ret); wake_up(&stream->runtime->sleep); mutex_lock(&stream->device->lock); return ret; } static int snd_compr_drain(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: return -EPERM; case SNDRV_PCM_STATE_XRUN: return -EPIPE; default: break; } retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); if (retval) { pr_debug("SND_COMPR_TRIGGER_DRAIN failed %d\n", retval); wake_up(&stream->runtime->sleep); return retval; } return snd_compress_wait_for_drain(stream); } static int snd_compr_next_track(struct snd_compr_stream *stream) { int retval; /* only a running stream can transition to next track */ if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) return -EPERM; /* next track doesn't have any meaning for capture streams */ if (stream->direction == SND_COMPRESS_CAPTURE) return -EPERM; /* you can signal next track if this is intended to be a gapless stream * and current track metadata is set */ if (stream->metadata_set == false) return -EPERM; retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_NEXT_TRACK); if (retval != 0) return retval; stream->metadata_set = false; stream->next_track = true; return 0; } static int snd_compr_partial_drain(struct snd_compr_stream *stream) { int retval; switch (stream->runtime->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: return -EPERM; case SNDRV_PCM_STATE_XRUN: return -EPIPE; default: break; } /* partial drain doesn't have any meaning for capture streams */ if (stream->direction == SND_COMPRESS_CAPTURE) return -EPERM; /* stream can be drained only when next track has been signalled */ if (stream->next_track == false) return -EPERM; stream->partial_drain = true; retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_PARTIAL_DRAIN); if (retval) { pr_debug("Partial drain returned failure\n"); wake_up(&stream->runtime->sleep); return retval; } stream->next_track = false; return snd_compress_wait_for_drain(stream); } static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg) { struct snd_compr_file *data = f->private_data; struct snd_compr_stream *stream; int retval = -ENOTTY; if (snd_BUG_ON(!data)) return -EFAULT; stream = &data->stream; mutex_lock(&stream->device->lock); switch (_IOC_NR(cmd)) { case _IOC_NR(SNDRV_COMPRESS_IOCTL_VERSION): retval = put_user(SNDRV_COMPRESS_VERSION, (int __user *)arg) ? -EFAULT : 0; break; case _IOC_NR(SNDRV_COMPRESS_GET_CAPS): retval = snd_compr_get_caps(stream, arg); break; #ifndef COMPR_CODEC_CAPS_OVERFLOW case _IOC_NR(SNDRV_COMPRESS_GET_CODEC_CAPS): retval = snd_compr_get_codec_caps(stream, arg); break; #endif case _IOC_NR(SNDRV_COMPRESS_SET_PARAMS): retval = snd_compr_set_params(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS): retval = snd_compr_get_params(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_SET_METADATA): retval = snd_compr_set_metadata(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_GET_METADATA): retval = snd_compr_get_metadata(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_TSTAMP): retval = snd_compr_tstamp(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_AVAIL): retval = snd_compr_ioctl_avail(stream, arg); break; case _IOC_NR(SNDRV_COMPRESS_PAUSE): retval = snd_compr_pause(stream); break; case _IOC_NR(SNDRV_COMPRESS_RESUME): retval = snd_compr_resume(stream); break; case _IOC_NR(SNDRV_COMPRESS_START): retval = snd_compr_start(stream); break; case _IOC_NR(SNDRV_COMPRESS_STOP): retval = snd_compr_stop(stream); break; case _IOC_NR(SNDRV_COMPRESS_DRAIN): retval = snd_compr_drain(stream); break; case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN): retval = snd_compr_partial_drain(stream); break; case _IOC_NR(SNDRV_COMPRESS_NEXT_TRACK): retval = snd_compr_next_track(stream); break; } mutex_unlock(&stream->device->lock); return retval; } /* support of 32bit userspace on 64bit platforms */ #ifdef CONFIG_COMPAT static long snd_compr_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { return snd_compr_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } #endif static const struct file_operations snd_compr_file_ops = { .owner = THIS_MODULE, .open = snd_compr_open, .release = snd_compr_free, .write = snd_compr_write, .read = snd_compr_read, .unlocked_ioctl = snd_compr_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl = snd_compr_ioctl_compat, #endif .mmap = snd_compr_mmap, .poll = snd_compr_poll, }; static int snd_compress_dev_register(struct snd_device *device) { int ret; struct snd_compr *compr; if (snd_BUG_ON(!device || !device->device_data)) return -EBADFD; compr = device->device_data; pr_debug("reg device %s, direction %d\n", compr->name, compr->direction); /* register compressed device */ ret = snd_register_device(SNDRV_DEVICE_TYPE_COMPRESS, compr->card, compr->device, &snd_compr_file_ops, compr, compr->dev); if (ret < 0) { pr_err("snd_register_device failed %d\n", ret); return ret; } return ret; } static int snd_compress_dev_disconnect(struct snd_device *device) { struct snd_compr *compr; compr = device->device_data; snd_unregister_device(compr->dev); return 0; } #ifdef CONFIG_SND_VERBOSE_PROCFS static void snd_compress_proc_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_compr *compr = (struct snd_compr *)entry->private_data; snd_iprintf(buffer, "card: %d\n", compr->card->number); snd_iprintf(buffer, "device: %d\n", compr->device); snd_iprintf(buffer, "stream: %s\n", compr->direction == SND_COMPRESS_PLAYBACK ? "PLAYBACK" : "CAPTURE"); snd_iprintf(buffer, "id: %s\n", compr->id); } static int snd_compress_proc_init(struct snd_compr *compr) { struct snd_info_entry *entry; char name[16]; sprintf(name, "compr%i", compr->device); entry = snd_info_create_card_entry(compr->card, name, compr->card->proc_root); if (!entry) return -ENOMEM; entry->mode = S_IFDIR | 0555; compr->proc_root = entry; entry = snd_info_create_card_entry(compr->card, "info", compr->proc_root); if (entry) snd_info_set_text_ops(entry, compr, snd_compress_proc_info_read); compr->proc_info_entry = entry; return 0; } static void snd_compress_proc_done(struct snd_compr *compr) { snd_info_free_entry(compr->proc_info_entry); compr->proc_info_entry = NULL; snd_info_free_entry(compr->proc_root); compr->proc_root = NULL; } static inline void snd_compress_set_id(struct snd_compr *compr, const char *id) { strscpy(compr->id, id, sizeof(compr->id)); } #else static inline int snd_compress_proc_init(struct snd_compr *compr) { return 0; } static inline void snd_compress_proc_done(struct snd_compr *compr) { } static inline void snd_compress_set_id(struct snd_compr *compr, const char *id) { } #endif static int snd_compress_dev_free(struct snd_device *device) { struct snd_compr *compr; compr = device->device_data; snd_compress_proc_done(compr); put_device(compr->dev); return 0; } /** * snd_compress_new: create new compress device * @card: sound card pointer * @device: device number * @dirn: device direction, should be of type enum snd_compr_direction * @id: ID string * @compr: compress device pointer * * Return: zero if successful, or a negative error code */ int snd_compress_new(struct snd_card *card, int device, int dirn, const char *id, struct snd_compr *compr) { static const struct snd_device_ops ops = { .dev_free = snd_compress_dev_free, .dev_register = snd_compress_dev_register, .dev_disconnect = snd_compress_dev_disconnect, }; int ret; compr->card = card; compr->device = device; compr->direction = dirn; mutex_init(&compr->lock); snd_compress_set_id(compr, id); ret = snd_device_alloc(&compr->dev, card); if (ret) return ret; dev_set_name(compr->dev, "comprC%iD%i", card->number, device); ret = snd_device_new(card, SNDRV_DEV_COMPRESS, compr, &ops); if (ret == 0) snd_compress_proc_init(compr); else put_device(compr->dev); return ret; } EXPORT_SYMBOL_GPL(snd_compress_new); MODULE_DESCRIPTION("ALSA Compressed offload framework"); MODULE_AUTHOR("Vinod Koul <[email protected]>"); MODULE_LICENSE("GPL v2");
linux-master
sound/core/compress_offload.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Device management routines * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/slab.h> #include <linux/time.h> #include <linux/export.h> #include <linux/errno.h> #include <sound/core.h> /** * snd_device_new - create an ALSA device component * @card: the card instance * @type: the device type, SNDRV_DEV_XXX * @device_data: the data pointer of this device * @ops: the operator table * * Creates a new device component for the given data pointer. * The device will be assigned to the card and managed together * by the card. * * The data pointer plays a role as the identifier, too, so the * pointer address must be unique and unchanged. * * Return: Zero if successful, or a negative error code on failure. */ int snd_device_new(struct snd_card *card, enum snd_device_type type, void *device_data, const struct snd_device_ops *ops) { struct snd_device *dev; struct list_head *p; if (snd_BUG_ON(!card || !device_data || !ops)) return -ENXIO; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; INIT_LIST_HEAD(&dev->list); dev->card = card; dev->type = type; dev->state = SNDRV_DEV_BUILD; dev->device_data = device_data; dev->ops = ops; /* insert the entry in an incrementally sorted list */ list_for_each_prev(p, &card->devices) { struct snd_device *pdev = list_entry(p, struct snd_device, list); if ((unsigned int)pdev->type <= (unsigned int)type) break; } list_add(&dev->list, p); return 0; } EXPORT_SYMBOL(snd_device_new); static void __snd_device_disconnect(struct snd_device *dev) { if (dev->state == SNDRV_DEV_REGISTERED) { if (dev->ops->dev_disconnect && dev->ops->dev_disconnect(dev)) dev_err(dev->card->dev, "device disconnect failure\n"); dev->state = SNDRV_DEV_DISCONNECTED; } } static void __snd_device_free(struct snd_device *dev) { /* unlink */ list_del(&dev->list); __snd_device_disconnect(dev); if (dev->ops->dev_free) { if (dev->ops->dev_free(dev)) dev_err(dev->card->dev, "device free failure\n"); } kfree(dev); } static struct snd_device *look_for_dev(struct snd_card *card, void *device_data) { struct snd_device *dev; list_for_each_entry(dev, &card->devices, list) if (dev->device_data == device_data) return dev; return NULL; } /** * snd_device_disconnect - disconnect the device * @card: the card instance * @device_data: the data pointer to disconnect * * Turns the device into the disconnection state, invoking * dev_disconnect callback, if the device was already registered. * * Usually called from snd_card_disconnect(). * * Return: Zero if successful, or a negative error code on failure or if the * device not found. */ void snd_device_disconnect(struct snd_card *card, void *device_data) { struct snd_device *dev; if (snd_BUG_ON(!card || !device_data)) return; dev = look_for_dev(card, device_data); if (dev) __snd_device_disconnect(dev); else dev_dbg(card->dev, "device disconnect %p (from %pS), not found\n", device_data, __builtin_return_address(0)); } EXPORT_SYMBOL_GPL(snd_device_disconnect); /** * snd_device_free - release the device from the card * @card: the card instance * @device_data: the data pointer to release * * Removes the device from the list on the card and invokes the * callbacks, dev_disconnect and dev_free, corresponding to the state. * Then release the device. */ void snd_device_free(struct snd_card *card, void *device_data) { struct snd_device *dev; if (snd_BUG_ON(!card || !device_data)) return; dev = look_for_dev(card, device_data); if (dev) __snd_device_free(dev); else dev_dbg(card->dev, "device free %p (from %pS), not found\n", device_data, __builtin_return_address(0)); } EXPORT_SYMBOL(snd_device_free); static int __snd_device_register(struct snd_device *dev) { if (dev->state == SNDRV_DEV_BUILD) { if (dev->ops->dev_register) { int err = dev->ops->dev_register(dev); if (err < 0) return err; } dev->state = SNDRV_DEV_REGISTERED; } return 0; } /** * snd_device_register - register the device * @card: the card instance * @device_data: the data pointer to register * * Registers the device which was already created via * snd_device_new(). Usually this is called from snd_card_register(), * but it can be called later if any new devices are created after * invocation of snd_card_register(). * * Return: Zero if successful, or a negative error code on failure or if the * device not found. */ int snd_device_register(struct snd_card *card, void *device_data) { struct snd_device *dev; if (snd_BUG_ON(!card || !device_data)) return -ENXIO; dev = look_for_dev(card, device_data); if (dev) return __snd_device_register(dev); snd_BUG(); return -ENXIO; } EXPORT_SYMBOL(snd_device_register); /* * register all the devices on the card. * called from init.c */ int snd_device_register_all(struct snd_card *card) { struct snd_device *dev; int err; if (snd_BUG_ON(!card)) return -ENXIO; list_for_each_entry(dev, &card->devices, list) { err = __snd_device_register(dev); if (err < 0) return err; } return 0; } /* * disconnect all the devices on the card. * called from init.c */ void snd_device_disconnect_all(struct snd_card *card) { struct snd_device *dev; if (snd_BUG_ON(!card)) return; list_for_each_entry_reverse(dev, &card->devices, list) __snd_device_disconnect(dev); } /* * release all the devices on the card. * called from init.c */ void snd_device_free_all(struct snd_card *card) { struct snd_device *dev, *next; if (snd_BUG_ON(!card)) return; list_for_each_entry_safe_reverse(dev, next, &card->devices, list) { /* exception: free ctl and lowlevel stuff later */ if (dev->type == SNDRV_DEV_CONTROL || dev->type == SNDRV_DEV_LOWLEVEL) continue; __snd_device_free(dev); } /* free all */ list_for_each_entry_safe_reverse(dev, next, &card->devices, list) __snd_device_free(dev); } /** * snd_device_get_state - Get the current state of the given device * @card: the card instance * @device_data: the data pointer to release * * Returns the current state of the given device object. For the valid * device, either @SNDRV_DEV_BUILD, @SNDRV_DEV_REGISTERED or * @SNDRV_DEV_DISCONNECTED is returned. * Or for a non-existing device, -1 is returned as an error. * * Return: the current state, or -1 if not found */ int snd_device_get_state(struct snd_card *card, void *device_data) { struct snd_device *dev; dev = look_for_dev(card, device_data); if (dev) return dev->state; return -1; } EXPORT_SYMBOL_GPL(snd_device_get_state);
linux-master
sound/core/device.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2012, Analog Devices Inc. * Author: Lars-Peter Clausen <[email protected]> * * Based on: * imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <[email protected]> * mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc. * ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <[email protected]> * Copyright (C) 2006 Applied Data Systems */ #include <linux/module.h> #include <linux/init.h> #include <linux/dmaengine.h> #include <linux/slab.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/soc.h> #include <sound/dmaengine_pcm.h> struct dmaengine_pcm_runtime_data { struct dma_chan *dma_chan; dma_cookie_t cookie; unsigned int pos; }; static inline struct dmaengine_pcm_runtime_data *substream_to_prtd( const struct snd_pcm_substream *substream) { return substream->runtime->private_data; } struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); return prtd->dma_chan; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_get_chan); /** * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config * @substream: PCM substream * @params: hw_params * @slave_config: DMA slave config * * This function can be used to initialize a dma_slave_config from a substream * and hw_params in a dmaengine based PCM driver implementation. * * Return: zero if successful, or a negative error code */ int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream, const struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config) { enum dma_slave_buswidth buswidth; int bits; bits = params_physical_width(params); if (bits < 8 || bits > 64) return -EINVAL; else if (bits == 8) buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; else if (bits == 16) buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; else if (bits == 24) buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES; else if (bits <= 32) buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; else buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { slave_config->direction = DMA_MEM_TO_DEV; slave_config->dst_addr_width = buswidth; } else { slave_config->direction = DMA_DEV_TO_MEM; slave_config->src_addr_width = buswidth; } slave_config->device_fc = false; return 0; } EXPORT_SYMBOL_GPL(snd_hwparams_to_dma_slave_config); /** * snd_dmaengine_pcm_set_config_from_dai_data() - Initializes a dma slave config * using DAI DMA data. * @substream: PCM substream * @dma_data: DAI DMA data * @slave_config: DMA slave configuration * * Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width * fields of the DMA slave config from the same fields of the DAI DMA * data struct. The src and dst fields will be initialized depending on the * direction of the substream. If the substream is a playback stream the dst * fields will be initialized, if it is a capture stream the src fields will be * initialized. The {dst,src}_addr_width field will only be initialized if the * SND_DMAENGINE_PCM_DAI_FLAG_PACK flag is set or if the addr_width field of * the DAI DMA data struct is not equal to DMA_SLAVE_BUSWIDTH_UNDEFINED. If * both conditions are met the latter takes priority. */ void snd_dmaengine_pcm_set_config_from_dai_data( const struct snd_pcm_substream *substream, const struct snd_dmaengine_dai_dma_data *dma_data, struct dma_slave_config *slave_config) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { slave_config->dst_addr = dma_data->addr; slave_config->dst_maxburst = dma_data->maxburst; if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK) slave_config->dst_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED) slave_config->dst_addr_width = dma_data->addr_width; } else { slave_config->src_addr = dma_data->addr; slave_config->src_maxburst = dma_data->maxburst; if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK) slave_config->src_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED) slave_config->src_addr_width = dma_data->addr_width; } slave_config->peripheral_config = dma_data->peripheral_config; slave_config->peripheral_size = dma_data->peripheral_size; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data); static void dmaengine_pcm_dma_complete(void *arg) { unsigned int new_pos; struct snd_pcm_substream *substream = arg; struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); new_pos = prtd->pos + snd_pcm_lib_period_bytes(substream); if (new_pos >= snd_pcm_lib_buffer_bytes(substream)) new_pos = 0; prtd->pos = new_pos; snd_pcm_period_elapsed(substream); } static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); struct dma_chan *chan = prtd->dma_chan; struct dma_async_tx_descriptor *desc; enum dma_transfer_direction direction; unsigned long flags = DMA_CTRL_ACK; direction = snd_pcm_substream_to_dma_direction(substream); if (!substream->runtime->no_period_wakeup) flags |= DMA_PREP_INTERRUPT; prtd->pos = 0; desc = dmaengine_prep_dma_cyclic(chan, substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream), direction, flags); if (!desc) return -ENOMEM; desc->callback = dmaengine_pcm_dma_complete; desc->callback_param = substream; prtd->cookie = dmaengine_submit(desc); return 0; } /** * snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation * @substream: PCM substream * @cmd: Trigger command * * This function can be used as the PCM trigger callback for dmaengine based PCM * driver implementations. * * Return: 0 on success, a negative error code otherwise */ int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); struct snd_pcm_runtime *runtime = substream->runtime; int ret; switch (cmd) { case SNDRV_PCM_TRIGGER_START: ret = dmaengine_pcm_prepare_and_submit(substream); if (ret) return ret; dma_async_issue_pending(prtd->dma_chan); break; case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: dmaengine_resume(prtd->dma_chan); break; case SNDRV_PCM_TRIGGER_SUSPEND: if (runtime->info & SNDRV_PCM_INFO_PAUSE) dmaengine_pause(prtd->dma_chan); else dmaengine_terminate_async(prtd->dma_chan); break; case SNDRV_PCM_TRIGGER_PAUSE_PUSH: dmaengine_pause(prtd->dma_chan); break; case SNDRV_PCM_TRIGGER_STOP: dmaengine_terminate_async(prtd->dma_chan); break; default: return -EINVAL; } return 0; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger); /** * snd_dmaengine_pcm_pointer_no_residue - dmaengine based PCM pointer implementation * @substream: PCM substream * * This function is deprecated and should not be used by new drivers, as its * results may be unreliable. * * Return: PCM position in frames */ snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); return bytes_to_frames(substream->runtime, prtd->pos); } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue); /** * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation * @substream: PCM substream * * This function can be used as the PCM pointer callback for dmaengine based PCM * driver implementations. * * Return: PCM position in frames */ snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct dma_tx_state state; enum dma_status status; unsigned int buf_size; unsigned int pos = 0; status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) { buf_size = snd_pcm_lib_buffer_bytes(substream); if (state.residue > 0 && state.residue <= buf_size) pos = buf_size - state.residue; runtime->delay = bytes_to_frames(runtime, state.in_flight_bytes); } return bytes_to_frames(runtime, pos); } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer); /** * snd_dmaengine_pcm_request_channel - Request channel for the dmaengine PCM * @filter_fn: Filter function used to request the DMA channel * @filter_data: Data passed to the DMA filter function * * This function request a DMA channel for usage with dmaengine PCM. * * Return: NULL or the requested DMA channel */ struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn, void *filter_data) { dma_cap_mask_t mask; dma_cap_zero(mask); dma_cap_set(DMA_SLAVE, mask); dma_cap_set(DMA_CYCLIC, mask); return dma_request_channel(mask, filter_fn, filter_data); } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel); /** * snd_dmaengine_pcm_open - Open a dmaengine based PCM substream * @substream: PCM substream * @chan: DMA channel to use for data transfers * * The function should usually be called from the pcm open callback. Note that * this function will use private_data field of the substream's runtime. So it * is not available to your pcm driver implementation. * * Return: 0 on success, a negative error code otherwise */ int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream, struct dma_chan *chan) { struct dmaengine_pcm_runtime_data *prtd; int ret; if (!chan) return -ENXIO; ret = snd_pcm_hw_constraint_integer(substream->runtime, SNDRV_PCM_HW_PARAM_PERIODS); if (ret < 0) return ret; prtd = kzalloc(sizeof(*prtd), GFP_KERNEL); if (!prtd) return -ENOMEM; prtd->dma_chan = chan; substream->runtime->private_data = prtd; return 0; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open); /** * snd_dmaengine_pcm_open_request_chan - Open a dmaengine based PCM substream and request channel * @substream: PCM substream * @filter_fn: Filter function used to request the DMA channel * @filter_data: Data passed to the DMA filter function * * This function will request a DMA channel using the passed filter function and * data. The function should usually be called from the pcm open callback. Note * that this function will use private_data field of the substream's runtime. So * it is not available to your pcm driver implementation. * * Return: 0 on success, a negative error code otherwise */ int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, dma_filter_fn filter_fn, void *filter_data) { return snd_dmaengine_pcm_open(substream, snd_dmaengine_pcm_request_channel(filter_fn, filter_data)); } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan); /** * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream * @substream: PCM substream * * Return: 0 on success, a negative error code otherwise */ int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); dmaengine_synchronize(prtd->dma_chan); kfree(prtd); return 0; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close); /** * snd_dmaengine_pcm_close_release_chan - Close a dmaengine based PCM * substream and release channel * @substream: PCM substream * * Releases the DMA channel associated with the PCM substream. * * Return: zero if successful, or a negative error code */ int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream) { struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); dmaengine_synchronize(prtd->dma_chan); dma_release_channel(prtd->dma_chan); kfree(prtd); return 0; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan); /** * snd_dmaengine_pcm_refine_runtime_hwparams - Refine runtime hw params * @substream: PCM substream * @dma_data: DAI DMA data * @hw: PCM hw params * @chan: DMA channel to use for data transfers * * This function will query DMA capability, then refine the pcm hardware * parameters. * * Return: 0 on success, a negative error code otherwise */ int snd_dmaengine_pcm_refine_runtime_hwparams( struct snd_pcm_substream *substream, struct snd_dmaengine_dai_dma_data *dma_data, struct snd_pcm_hardware *hw, struct dma_chan *chan) { struct dma_slave_caps dma_caps; u32 addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); snd_pcm_format_t i; int ret = 0; if (!hw || !chan || !dma_data) return -EINVAL; ret = dma_get_slave_caps(chan, &dma_caps); if (ret == 0) { if (dma_caps.cmd_pause && dma_caps.cmd_resume) hw->info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME; if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT) hw->info |= SNDRV_PCM_INFO_BATCH; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) addr_widths = dma_caps.dst_addr_widths; else addr_widths = dma_caps.src_addr_widths; } /* * If SND_DMAENGINE_PCM_DAI_FLAG_PACK is set keep * hw.formats set to 0, meaning no restrictions are in place. * In this case it's the responsibility of the DAI driver to * provide the supported format information. */ if (!(dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK)) /* * Prepare formats mask for valid/allowed sample types. If the * dma does not have support for the given physical word size, * it needs to be masked out so user space can not use the * format which produces corrupted audio. * In case the dma driver does not implement the slave_caps the * default assumption is that it supports 1, 2 and 4 bytes * widths. */ pcm_for_each_format(i) { int bits = snd_pcm_format_physical_width(i); /* * Enable only samples with DMA supported physical * widths */ switch (bits) { case 8: case 16: case 24: case 32: case 64: if (addr_widths & (1 << (bits / 8))) hw->formats |= pcm_format_to_bits(i); break; default: /* Unsupported types */ break; } } return ret; } EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_refine_runtime_hwparams); MODULE_LICENSE("GPL");
linux-master
sound/core/pcm_dmaengine.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Universal MIDI Packet (UMP) support */ #include <linux/list.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/export.h> #include <linux/mm.h> #include <sound/core.h> #include <sound/rawmidi.h> #include <sound/ump.h> #include <sound/ump_convert.h> #define ump_err(ump, fmt, args...) dev_err((ump)->core.dev, fmt, ##args) #define ump_warn(ump, fmt, args...) dev_warn((ump)->core.dev, fmt, ##args) #define ump_info(ump, fmt, args...) dev_info((ump)->core.dev, fmt, ##args) #define ump_dbg(ump, fmt, args...) dev_dbg((ump)->core.dev, fmt, ##args) static int snd_ump_dev_register(struct snd_rawmidi *rmidi); static int snd_ump_dev_unregister(struct snd_rawmidi *rmidi); static long snd_ump_ioctl(struct snd_rawmidi *rmidi, unsigned int cmd, void __user *argp); static void snd_ump_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer); static int snd_ump_rawmidi_open(struct snd_rawmidi_substream *substream); static int snd_ump_rawmidi_close(struct snd_rawmidi_substream *substream); static void snd_ump_rawmidi_trigger(struct snd_rawmidi_substream *substream, int up); static void snd_ump_rawmidi_drain(struct snd_rawmidi_substream *substream); static void ump_handle_stream_msg(struct snd_ump_endpoint *ump, const u32 *buf, int size); #if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI) static int process_legacy_output(struct snd_ump_endpoint *ump, u32 *buffer, int count); static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src, int words); #else static inline int process_legacy_output(struct snd_ump_endpoint *ump, u32 *buffer, int count) { return 0; } static inline void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src, int words) { } #endif static const struct snd_rawmidi_global_ops snd_ump_rawmidi_ops = { .dev_register = snd_ump_dev_register, .dev_unregister = snd_ump_dev_unregister, .ioctl = snd_ump_ioctl, .proc_read = snd_ump_proc_read, }; static const struct snd_rawmidi_ops snd_ump_rawmidi_input_ops = { .open = snd_ump_rawmidi_open, .close = snd_ump_rawmidi_close, .trigger = snd_ump_rawmidi_trigger, }; static const struct snd_rawmidi_ops snd_ump_rawmidi_output_ops = { .open = snd_ump_rawmidi_open, .close = snd_ump_rawmidi_close, .trigger = snd_ump_rawmidi_trigger, .drain = snd_ump_rawmidi_drain, }; static void snd_ump_endpoint_free(struct snd_rawmidi *rmidi) { struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi); struct snd_ump_block *fb; while (!list_empty(&ump->block_list)) { fb = list_first_entry(&ump->block_list, struct snd_ump_block, list); list_del(&fb->list); if (fb->private_free) fb->private_free(fb); kfree(fb); } if (ump->private_free) ump->private_free(ump); #if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI) kfree(ump->out_cvts); #endif } /** * snd_ump_endpoint_new - create a UMP Endpoint object * @card: the card instance * @id: the id string for rawmidi * @device: the device index for rawmidi * @output: 1 for enabling output * @input: 1 for enabling input * @ump_ret: the pointer to store the new UMP instance * * Creates a new UMP Endpoint object. A UMP Endpoint is tied with one rawmidi * instance with one input and/or one output rawmidi stream (either uni- * or bi-directional). A UMP Endpoint may contain one or multiple UMP Blocks * that consist of one or multiple UMP Groups. * * Use snd_rawmidi_set_ops() to set the operators to the new instance. * Unlike snd_rawmidi_new(), this function sets up the info_flags by itself * depending on the given @output and @input. * * The device has SNDRV_RAWMIDI_INFO_UMP flag set and a different device * file ("umpCxDx") than a standard MIDI 1.x device ("midiCxDx") is * created. * * Return: Zero if successful, or a negative error code on failure. */ int snd_ump_endpoint_new(struct snd_card *card, char *id, int device, int output, int input, struct snd_ump_endpoint **ump_ret) { unsigned int info_flags = SNDRV_RAWMIDI_INFO_UMP; struct snd_ump_endpoint *ump; int err; if (input) info_flags |= SNDRV_RAWMIDI_INFO_INPUT; if (output) info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT; if (input && output) info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX; ump = kzalloc(sizeof(*ump), GFP_KERNEL); if (!ump) return -ENOMEM; INIT_LIST_HEAD(&ump->block_list); mutex_init(&ump->open_mutex); init_waitqueue_head(&ump->stream_wait); #if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI) spin_lock_init(&ump->legacy_locks[0]); spin_lock_init(&ump->legacy_locks[1]); #endif err = snd_rawmidi_init(&ump->core, card, id, device, output, input, info_flags); if (err < 0) { snd_rawmidi_free(&ump->core); return err; } ump->info.card = card->number; ump->info.device = device; ump->core.private_free = snd_ump_endpoint_free; ump->core.ops = &snd_ump_rawmidi_ops; if (input) snd_rawmidi_set_ops(&ump->core, SNDRV_RAWMIDI_STREAM_INPUT, &snd_ump_rawmidi_input_ops); if (output) snd_rawmidi_set_ops(&ump->core, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_ump_rawmidi_output_ops); ump_dbg(ump, "Created a UMP EP #%d (%s)\n", device, id); *ump_ret = ump; return 0; } EXPORT_SYMBOL_GPL(snd_ump_endpoint_new); /* * Device register / unregister hooks; * do nothing, placeholders for avoiding the default rawmidi handling */ #if IS_ENABLED(CONFIG_SND_SEQUENCER) static void snd_ump_dev_seq_free(struct snd_seq_device *device) { struct snd_ump_endpoint *ump = device->private_data; ump->seq_dev = NULL; } #endif static int snd_ump_dev_register(struct snd_rawmidi *rmidi) { #if IS_ENABLED(CONFIG_SND_SEQUENCER) struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi); int err; err = snd_seq_device_new(ump->core.card, ump->core.device, SNDRV_SEQ_DEV_ID_UMP, 0, &ump->seq_dev); if (err < 0) return err; ump->seq_dev->private_data = ump; ump->seq_dev->private_free = snd_ump_dev_seq_free; snd_device_register(ump->core.card, ump->seq_dev); #endif return 0; } static int snd_ump_dev_unregister(struct snd_rawmidi *rmidi) { return 0; } static struct snd_ump_block * snd_ump_get_block(struct snd_ump_endpoint *ump, unsigned char id) { struct snd_ump_block *fb; list_for_each_entry(fb, &ump->block_list, list) { if (fb->info.block_id == id) return fb; } return NULL; } /* * rawmidi ops for UMP endpoint */ static int snd_ump_rawmidi_open(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi); int dir = substream->stream; int err; if (ump->substreams[dir]) return -EBUSY; err = ump->ops->open(ump, dir); if (err < 0) return err; ump->substreams[dir] = substream; return 0; } static int snd_ump_rawmidi_close(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi); int dir = substream->stream; ump->substreams[dir] = NULL; ump->ops->close(ump, dir); return 0; } static void snd_ump_rawmidi_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi); int dir = substream->stream; ump->ops->trigger(ump, dir, up); } static void snd_ump_rawmidi_drain(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = rawmidi_to_ump(substream->rmidi); if (ump->ops->drain) ump->ops->drain(ump, SNDRV_RAWMIDI_STREAM_OUTPUT); } /* number of 32bit words per message type */ static unsigned char ump_packet_words[0x10] = { 1, 1, 1, 2, 2, 4, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4 }; /** * snd_ump_receive_ump_val - parse the UMP packet data * @ump: UMP endpoint * @val: UMP packet data * * The data is copied onto ump->input_buf[]. * When a full packet is completed, returns the number of words (from 1 to 4). * OTOH, if the packet is incomplete, returns 0. */ int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val) { int words; if (!ump->input_pending) ump->input_pending = ump_packet_words[ump_message_type(val)]; ump->input_buf[ump->input_buf_head++] = val; ump->input_pending--; if (!ump->input_pending) { words = ump->input_buf_head; ump->input_buf_head = 0; return words; } return 0; } EXPORT_SYMBOL_GPL(snd_ump_receive_ump_val); /** * snd_ump_receive - transfer UMP packets from the device * @ump: the UMP endpoint * @buffer: the buffer pointer to transfer * @count: byte size to transfer * * Called from the driver to submit the received UMP packets from the device * to user-space. It's essentially a wrapper of rawmidi_receive(). * The data to receive is in CPU-native endianness. */ int snd_ump_receive(struct snd_ump_endpoint *ump, const u32 *buffer, int count) { struct snd_rawmidi_substream *substream; const u32 *p = buffer; int n, words = count >> 2; while (words--) { n = snd_ump_receive_ump_val(ump, *p++); if (!n) continue; ump_handle_stream_msg(ump, ump->input_buf, n); #if IS_ENABLED(CONFIG_SND_SEQUENCER) if (ump->seq_ops) ump->seq_ops->input_receive(ump, ump->input_buf, n); #endif process_legacy_input(ump, ump->input_buf, n); } substream = ump->substreams[SNDRV_RAWMIDI_STREAM_INPUT]; if (!substream) return 0; return snd_rawmidi_receive(substream, (const char *)buffer, count); } EXPORT_SYMBOL_GPL(snd_ump_receive); /** * snd_ump_transmit - transmit UMP packets * @ump: the UMP endpoint * @buffer: the buffer pointer to transfer * @count: byte size to transfer * * Called from the driver to obtain the UMP packets from user-space to the * device. It's essentially a wrapper of rawmidi_transmit(). * The data to transmit is in CPU-native endianness. */ int snd_ump_transmit(struct snd_ump_endpoint *ump, u32 *buffer, int count) { struct snd_rawmidi_substream *substream = ump->substreams[SNDRV_RAWMIDI_STREAM_OUTPUT]; int err; if (!substream) return -ENODEV; err = snd_rawmidi_transmit(substream, (char *)buffer, count); /* received either data or an error? */ if (err) return err; return process_legacy_output(ump, buffer, count); } EXPORT_SYMBOL_GPL(snd_ump_transmit); /** * snd_ump_block_new - Create a UMP block * @ump: UMP object * @blk: block ID number to create * @direction: direction (in/out/bidirection) * @first_group: the first group ID (0-based) * @num_groups: the number of groups in this block * @blk_ret: the pointer to store the resultant block object */ int snd_ump_block_new(struct snd_ump_endpoint *ump, unsigned int blk, unsigned int direction, unsigned int first_group, unsigned int num_groups, struct snd_ump_block **blk_ret) { struct snd_ump_block *fb, *p; if (blk < 0 || blk >= SNDRV_UMP_MAX_BLOCKS) return -EINVAL; if (snd_ump_get_block(ump, blk)) return -EBUSY; fb = kzalloc(sizeof(*fb), GFP_KERNEL); if (!fb) return -ENOMEM; fb->ump = ump; fb->info.card = ump->info.card; fb->info.device = ump->info.device; fb->info.block_id = blk; if (blk >= ump->info.num_blocks) ump->info.num_blocks = blk + 1; fb->info.direction = direction; fb->info.active = 1; fb->info.first_group = first_group; fb->info.num_groups = num_groups; /* fill the default name, may be overwritten to a better name */ snprintf(fb->info.name, sizeof(fb->info.name), "Group %d-%d", first_group + 1, first_group + num_groups); /* put the entry in the ordered list */ list_for_each_entry(p, &ump->block_list, list) { if (p->info.block_id > blk) { list_add_tail(&fb->list, &p->list); goto added; } } list_add_tail(&fb->list, &ump->block_list); added: ump_dbg(ump, "Created a UMP Block #%d (%s)\n", blk, fb->info.name); *blk_ret = fb; return 0; } EXPORT_SYMBOL_GPL(snd_ump_block_new); static int snd_ump_ioctl_block(struct snd_ump_endpoint *ump, struct snd_ump_block_info __user *argp) { struct snd_ump_block *fb; unsigned char id; if (get_user(id, &argp->block_id)) return -EFAULT; fb = snd_ump_get_block(ump, id); if (!fb) return -ENOENT; if (copy_to_user(argp, &fb->info, sizeof(fb->info))) return -EFAULT; return 0; } /* * Handle UMP-specific ioctls; called from snd_rawmidi_ioctl() */ static long snd_ump_ioctl(struct snd_rawmidi *rmidi, unsigned int cmd, void __user *argp) { struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi); switch (cmd) { case SNDRV_UMP_IOCTL_ENDPOINT_INFO: if (copy_to_user(argp, &ump->info, sizeof(ump->info))) return -EFAULT; return 0; case SNDRV_UMP_IOCTL_BLOCK_INFO: return snd_ump_ioctl_block(ump, argp); default: ump_dbg(ump, "rawmidi: unknown command = 0x%x\n", cmd); return -ENOTTY; } } static const char *ump_direction_string(int dir) { switch (dir) { case SNDRV_UMP_DIR_INPUT: return "input"; case SNDRV_UMP_DIR_OUTPUT: return "output"; case SNDRV_UMP_DIR_BIDIRECTION: return "bidirection"; default: return "unknown"; } } static const char *ump_ui_hint_string(int dir) { switch (dir) { case SNDRV_UMP_BLOCK_UI_HINT_RECEIVER: return "receiver"; case SNDRV_UMP_BLOCK_UI_HINT_SENDER: return "sender"; case SNDRV_UMP_BLOCK_UI_HINT_BOTH: return "both"; default: return "unknown"; } } /* Additional proc file output */ static void snd_ump_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_rawmidi *rmidi = entry->private_data; struct snd_ump_endpoint *ump = rawmidi_to_ump(rmidi); struct snd_ump_block *fb; snd_iprintf(buffer, "EP Name: %s\n", ump->info.name); snd_iprintf(buffer, "EP Product ID: %s\n", ump->info.product_id); snd_iprintf(buffer, "UMP Version: 0x%04x\n", ump->info.version); snd_iprintf(buffer, "Protocol Caps: 0x%08x\n", ump->info.protocol_caps); snd_iprintf(buffer, "Protocol: 0x%08x\n", ump->info.protocol); if (ump->info.version) { snd_iprintf(buffer, "Manufacturer ID: 0x%08x\n", ump->info.manufacturer_id); snd_iprintf(buffer, "Family ID: 0x%04x\n", ump->info.family_id); snd_iprintf(buffer, "Model ID: 0x%04x\n", ump->info.model_id); snd_iprintf(buffer, "SW Revision: 0x%02x%02x%02x%02x\n", ump->info.sw_revision[0], ump->info.sw_revision[1], ump->info.sw_revision[2], ump->info.sw_revision[3]); } snd_iprintf(buffer, "Static Blocks: %s\n", (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) ? "Yes" : "No"); snd_iprintf(buffer, "Num Blocks: %d\n\n", ump->info.num_blocks); list_for_each_entry(fb, &ump->block_list, list) { snd_iprintf(buffer, "Block %d (%s)\n", fb->info.block_id, fb->info.name); snd_iprintf(buffer, " Direction: %s\n", ump_direction_string(fb->info.direction)); snd_iprintf(buffer, " Active: %s\n", fb->info.active ? "Yes" : "No"); snd_iprintf(buffer, " Groups: %d-%d\n", fb->info.first_group + 1, fb->info.first_group + fb->info.num_groups); snd_iprintf(buffer, " Is MIDI1: %s%s\n", (fb->info.flags & SNDRV_UMP_BLOCK_IS_MIDI1) ? "Yes" : "No", (fb->info.flags & SNDRV_UMP_BLOCK_IS_LOWSPEED) ? " (Low Speed)" : ""); if (ump->info.version) { snd_iprintf(buffer, " MIDI-CI Version: %d\n", fb->info.midi_ci_version); snd_iprintf(buffer, " Sysex8 Streams: %d\n", fb->info.sysex8_streams); snd_iprintf(buffer, " UI Hint: %s\n", ump_ui_hint_string(fb->info.ui_hint)); } snd_iprintf(buffer, "\n"); } } /* * UMP endpoint and function block handling */ /* open / close UMP streams for the internal stream msg communication */ static int ump_request_open(struct snd_ump_endpoint *ump) { return snd_rawmidi_kernel_open(&ump->core, 0, SNDRV_RAWMIDI_LFLG_OUTPUT, &ump->stream_rfile); } static void ump_request_close(struct snd_ump_endpoint *ump) { snd_rawmidi_kernel_release(&ump->stream_rfile); } /* request a command and wait for the given response; * @req1 and @req2 are u32 commands * @reply is the expected UMP stream status */ static int ump_req_msg(struct snd_ump_endpoint *ump, u32 req1, u32 req2, u32 reply) { u32 buf[4]; ump_dbg(ump, "%s: request %08x %08x, wait-for %08x\n", __func__, req1, req2, reply); memset(buf, 0, sizeof(buf)); buf[0] = req1; buf[1] = req2; ump->stream_finished = 0; ump->stream_wait_for = reply; snd_rawmidi_kernel_write(ump->stream_rfile.output, (unsigned char *)&buf, 16); wait_event_timeout(ump->stream_wait, ump->stream_finished, msecs_to_jiffies(500)); if (!READ_ONCE(ump->stream_finished)) { ump_dbg(ump, "%s: request timed out\n", __func__); return -ETIMEDOUT; } ump->stream_finished = 0; ump_dbg(ump, "%s: reply: %08x %08x %08x %08x\n", __func__, buf[0], buf[1], buf[2], buf[3]); return 0; } /* append the received letters via UMP packet to the given string buffer; * return 1 if the full string is received or 0 to continue */ static int ump_append_string(struct snd_ump_endpoint *ump, char *dest, int maxsize, const u32 *buf, int offset) { unsigned char format; int c; format = ump_stream_message_format(buf[0]); if (format == UMP_STREAM_MSG_FORMAT_SINGLE || format == UMP_STREAM_MSG_FORMAT_START) { c = 0; } else { c = strlen(dest); if (c >= maxsize - 1) return 1; } for (; offset < 16; offset++) { dest[c] = buf[offset / 4] >> (3 - (offset % 4)) * 8; if (!dest[c]) break; if (++c >= maxsize - 1) break; } dest[c] = 0; return (format == UMP_STREAM_MSG_FORMAT_SINGLE || format == UMP_STREAM_MSG_FORMAT_END); } /* handle EP info stream message; update the UMP attributes */ static int ump_handle_ep_info_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { ump->info.version = (buf->ep_info.ump_version_major << 8) | buf->ep_info.ump_version_minor; ump->info.num_blocks = buf->ep_info.num_function_blocks; if (ump->info.num_blocks > SNDRV_UMP_MAX_BLOCKS) { ump_info(ump, "Invalid function blocks %d, fallback to 1\n", ump->info.num_blocks); ump->info.num_blocks = 1; } if (buf->ep_info.static_function_block) ump->info.flags |= SNDRV_UMP_EP_INFO_STATIC_BLOCKS; ump->info.protocol_caps = (buf->ep_info.protocol << 8) | buf->ep_info.jrts; ump_dbg(ump, "EP info: version=%x, num_blocks=%x, proto_caps=%x\n", ump->info.version, ump->info.num_blocks, ump->info.protocol_caps); return 1; /* finished */ } /* handle EP device info stream message; update the UMP attributes */ static int ump_handle_device_info_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { ump->info.manufacturer_id = buf->device_info.manufacture_id & 0x7f7f7f; ump->info.family_id = (buf->device_info.family_msb << 8) | buf->device_info.family_lsb; ump->info.model_id = (buf->device_info.model_msb << 8) | buf->device_info.model_lsb; ump->info.sw_revision[0] = (buf->device_info.sw_revision >> 24) & 0x7f; ump->info.sw_revision[1] = (buf->device_info.sw_revision >> 16) & 0x7f; ump->info.sw_revision[2] = (buf->device_info.sw_revision >> 8) & 0x7f; ump->info.sw_revision[3] = buf->device_info.sw_revision & 0x7f; ump_dbg(ump, "EP devinfo: manid=%08x, family=%04x, model=%04x, sw=%02x%02x%02x%02x\n", ump->info.manufacturer_id, ump->info.family_id, ump->info.model_id, ump->info.sw_revision[0], ump->info.sw_revision[1], ump->info.sw_revision[2], ump->info.sw_revision[3]); return 1; /* finished */ } /* handle EP name stream message; update the UMP name string */ static int ump_handle_ep_name_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { return ump_append_string(ump, ump->info.name, sizeof(ump->info.name), buf->raw, 2); } /* handle EP product id stream message; update the UMP product_id string */ static int ump_handle_product_id_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { return ump_append_string(ump, ump->info.product_id, sizeof(ump->info.product_id), buf->raw, 2); } /* notify the protocol change to sequencer */ static void seq_notify_protocol(struct snd_ump_endpoint *ump) { #if IS_ENABLED(CONFIG_SND_SEQUENCER) if (ump->seq_ops && ump->seq_ops->switch_protocol) ump->seq_ops->switch_protocol(ump); #endif /* CONFIG_SND_SEQUENCER */ } /** * snd_ump_switch_protocol - switch MIDI protocol * @ump: UMP endpoint * @protocol: protocol to switch to * * Returns 1 if the protocol is actually switched, 0 if unchanged */ int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol) { protocol &= ump->info.protocol_caps; if (protocol == ump->info.protocol) return 0; ump->info.protocol = protocol; ump_dbg(ump, "New protocol = %x (caps = %x)\n", protocol, ump->info.protocol_caps); seq_notify_protocol(ump); return 1; } EXPORT_SYMBOL_GPL(snd_ump_switch_protocol); /* handle EP stream config message; update the UMP protocol */ static int ump_handle_stream_cfg_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { unsigned int protocol = (buf->stream_cfg.protocol << 8) | buf->stream_cfg.jrts; snd_ump_switch_protocol(ump, protocol); return 1; /* finished */ } /* Extract Function Block info from UMP packet */ static void fill_fb_info(struct snd_ump_endpoint *ump, struct snd_ump_block_info *info, const union snd_ump_stream_msg *buf) { info->direction = buf->fb_info.direction; info->ui_hint = buf->fb_info.ui_hint; info->first_group = buf->fb_info.first_group; info->num_groups = buf->fb_info.num_groups; info->flags = buf->fb_info.midi_10; info->active = buf->fb_info.active; info->midi_ci_version = buf->fb_info.midi_ci_version; info->sysex8_streams = buf->fb_info.sysex8_streams; ump_dbg(ump, "FB %d: dir=%d, active=%d, first_gp=%d, num_gp=%d, midici=%d, sysex8=%d, flags=0x%x\n", info->block_id, info->direction, info->active, info->first_group, info->num_groups, info->midi_ci_version, info->sysex8_streams, info->flags); } /* check whether the FB info gets updated by the current message */ static bool is_fb_info_updated(struct snd_ump_endpoint *ump, struct snd_ump_block *fb, const union snd_ump_stream_msg *buf) { char tmpbuf[offsetof(struct snd_ump_block_info, name)]; if (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) { ump_info(ump, "Skipping static FB info update (blk#%d)\n", fb->info.block_id); return 0; } memcpy(tmpbuf, &fb->info, sizeof(tmpbuf)); fill_fb_info(ump, (struct snd_ump_block_info *)tmpbuf, buf); return memcmp(&fb->info, tmpbuf, sizeof(tmpbuf)) != 0; } /* notify the FB info/name change to sequencer */ static void seq_notify_fb_change(struct snd_ump_endpoint *ump, struct snd_ump_block *fb) { #if IS_ENABLED(CONFIG_SND_SEQUENCER) if (ump->seq_ops && ump->seq_ops->notify_fb_change) ump->seq_ops->notify_fb_change(ump, fb); #endif } /* handle FB info message; update FB info if the block is present */ static int ump_handle_fb_info_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { unsigned char blk; struct snd_ump_block *fb; blk = buf->fb_info.function_block_id; fb = snd_ump_get_block(ump, blk); /* complain only if updated after parsing */ if (!fb && ump->parsed) { ump_info(ump, "Function Block Info Update for non-existing block %d\n", blk); return -ENODEV; } /* When updated after the initial parse, check the FB info update */ if (ump->parsed && !is_fb_info_updated(ump, fb, buf)) return 1; /* no content change */ if (fb) { fill_fb_info(ump, &fb->info, buf); if (ump->parsed) seq_notify_fb_change(ump, fb); } return 1; /* finished */ } /* handle FB name message; update the FB name string */ static int ump_handle_fb_name_msg(struct snd_ump_endpoint *ump, const union snd_ump_stream_msg *buf) { unsigned char blk; struct snd_ump_block *fb; int ret; blk = buf->fb_name.function_block_id; fb = snd_ump_get_block(ump, blk); if (!fb) return -ENODEV; ret = ump_append_string(ump, fb->info.name, sizeof(fb->info.name), buf->raw, 3); /* notify the FB name update to sequencer, too */ if (ret > 0 && ump->parsed) seq_notify_fb_change(ump, fb); return ret; } static int create_block_from_fb_info(struct snd_ump_endpoint *ump, int blk) { struct snd_ump_block *fb; unsigned char direction, first_group, num_groups; const union snd_ump_stream_msg *buf = (const union snd_ump_stream_msg *)ump->input_buf; u32 msg; int err; /* query the FB info once */ msg = ump_stream_compose(UMP_STREAM_MSG_STATUS_FB_DISCOVERY, 0) | (blk << 8) | UMP_STREAM_MSG_REQUEST_FB_INFO; err = ump_req_msg(ump, msg, 0, UMP_STREAM_MSG_STATUS_FB_INFO); if (err < 0) { ump_dbg(ump, "Unable to get FB info for block %d\n", blk); return err; } /* the last input must be the FB info */ if (buf->fb_info.status != UMP_STREAM_MSG_STATUS_FB_INFO) { ump_dbg(ump, "Inconsistent input: 0x%x\n", *buf->raw); return -EINVAL; } direction = buf->fb_info.direction; first_group = buf->fb_info.first_group; num_groups = buf->fb_info.num_groups; err = snd_ump_block_new(ump, blk, direction, first_group, num_groups, &fb); if (err < 0) return err; fill_fb_info(ump, &fb->info, buf); msg = ump_stream_compose(UMP_STREAM_MSG_STATUS_FB_DISCOVERY, 0) | (blk << 8) | UMP_STREAM_MSG_REQUEST_FB_NAME; err = ump_req_msg(ump, msg, 0, UMP_STREAM_MSG_STATUS_FB_NAME); if (err) ump_dbg(ump, "Unable to get UMP FB name string #%d\n", blk); return 0; } /* handle stream messages, called from snd_ump_receive() */ static void ump_handle_stream_msg(struct snd_ump_endpoint *ump, const u32 *buf, int size) { const union snd_ump_stream_msg *msg; unsigned int status; int ret; /* UMP stream message suppressed (for gadget UMP)? */ if (ump->no_process_stream) return; BUILD_BUG_ON(sizeof(*msg) != 16); ump_dbg(ump, "Stream msg: %08x %08x %08x %08x\n", buf[0], buf[1], buf[2], buf[3]); if (size != 4 || ump_message_type(*buf) != UMP_MSG_TYPE_STREAM) return; msg = (const union snd_ump_stream_msg *)buf; status = ump_stream_message_status(*buf); switch (status) { case UMP_STREAM_MSG_STATUS_EP_INFO: ret = ump_handle_ep_info_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_DEVICE_INFO: ret = ump_handle_device_info_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_EP_NAME: ret = ump_handle_ep_name_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_PRODUCT_ID: ret = ump_handle_product_id_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_STREAM_CFG: ret = ump_handle_stream_cfg_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_FB_INFO: ret = ump_handle_fb_info_msg(ump, msg); break; case UMP_STREAM_MSG_STATUS_FB_NAME: ret = ump_handle_fb_name_msg(ump, msg); break; default: return; } /* when the message has been processed fully, wake up */ if (ret > 0 && ump->stream_wait_for == status) { WRITE_ONCE(ump->stream_finished, 1); wake_up(&ump->stream_wait); } } /** * snd_ump_parse_endpoint - parse endpoint and create function blocks * @ump: UMP object * * Returns 0 for successful parse, -ENODEV if device doesn't respond * (or the query is unsupported), or other error code for serious errors. */ int snd_ump_parse_endpoint(struct snd_ump_endpoint *ump) { int blk, err; u32 msg; if (!(ump->core.info_flags & SNDRV_RAWMIDI_INFO_DUPLEX)) return -ENODEV; err = ump_request_open(ump); if (err < 0) { ump_dbg(ump, "Unable to open rawmidi device: %d\n", err); return err; } /* Check Endpoint Information */ msg = ump_stream_compose(UMP_STREAM_MSG_STATUS_EP_DISCOVERY, 0) | 0x0101; /* UMP version 1.1 */ err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_EP_INFO, UMP_STREAM_MSG_STATUS_EP_INFO); if (err < 0) { ump_dbg(ump, "Unable to get UMP EP info\n"); goto error; } /* Request Endpoint Device Info */ err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_DEVICE_INFO, UMP_STREAM_MSG_STATUS_DEVICE_INFO); if (err < 0) ump_dbg(ump, "Unable to get UMP EP device info\n"); /* Request Endpoint Name */ err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_EP_NAME, UMP_STREAM_MSG_STATUS_EP_NAME); if (err < 0) ump_dbg(ump, "Unable to get UMP EP name string\n"); /* Request Endpoint Product ID */ err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_PRODUCT_ID, UMP_STREAM_MSG_STATUS_PRODUCT_ID); if (err < 0) ump_dbg(ump, "Unable to get UMP EP product ID string\n"); /* Get the current stream configuration */ err = ump_req_msg(ump, msg, UMP_STREAM_MSG_REQUEST_STREAM_CFG, UMP_STREAM_MSG_STATUS_STREAM_CFG); if (err < 0) ump_dbg(ump, "Unable to get UMP EP stream config\n"); /* Query and create blocks from Function Blocks */ for (blk = 0; blk < ump->info.num_blocks; blk++) { err = create_block_from_fb_info(ump, blk); if (err < 0) continue; } error: ump->parsed = true; ump_request_close(ump); if (err == -ETIMEDOUT) err = -ENODEV; return err; } EXPORT_SYMBOL_GPL(snd_ump_parse_endpoint); #if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI) /* * Legacy rawmidi support */ static int snd_ump_legacy_open(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = substream->rmidi->private_data; int dir = substream->stream; int group = ump->legacy_mapping[substream->number]; int err; mutex_lock(&ump->open_mutex); if (ump->legacy_substreams[dir][group]) { err = -EBUSY; goto unlock; } if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { if (!ump->legacy_out_opens) { err = snd_rawmidi_kernel_open(&ump->core, 0, SNDRV_RAWMIDI_LFLG_OUTPUT | SNDRV_RAWMIDI_LFLG_APPEND, &ump->legacy_out_rfile); if (err < 0) goto unlock; } ump->legacy_out_opens++; snd_ump_convert_reset(&ump->out_cvts[group]); } spin_lock_irq(&ump->legacy_locks[dir]); ump->legacy_substreams[dir][group] = substream; spin_unlock_irq(&ump->legacy_locks[dir]); unlock: mutex_unlock(&ump->open_mutex); return 0; } static int snd_ump_legacy_close(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = substream->rmidi->private_data; int dir = substream->stream; int group = ump->legacy_mapping[substream->number]; mutex_lock(&ump->open_mutex); spin_lock_irq(&ump->legacy_locks[dir]); ump->legacy_substreams[dir][group] = NULL; spin_unlock_irq(&ump->legacy_locks[dir]); if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { if (!--ump->legacy_out_opens) snd_rawmidi_kernel_release(&ump->legacy_out_rfile); } mutex_unlock(&ump->open_mutex); return 0; } static void snd_ump_legacy_trigger(struct snd_rawmidi_substream *substream, int up) { struct snd_ump_endpoint *ump = substream->rmidi->private_data; int dir = substream->stream; ump->ops->trigger(ump, dir, up); } static void snd_ump_legacy_drain(struct snd_rawmidi_substream *substream) { struct snd_ump_endpoint *ump = substream->rmidi->private_data; if (ump->ops->drain) ump->ops->drain(ump, SNDRV_RAWMIDI_STREAM_OUTPUT); } static int snd_ump_legacy_dev_register(struct snd_rawmidi *rmidi) { /* dummy, just for avoiding create superfluous seq clients */ return 0; } static const struct snd_rawmidi_ops snd_ump_legacy_input_ops = { .open = snd_ump_legacy_open, .close = snd_ump_legacy_close, .trigger = snd_ump_legacy_trigger, }; static const struct snd_rawmidi_ops snd_ump_legacy_output_ops = { .open = snd_ump_legacy_open, .close = snd_ump_legacy_close, .trigger = snd_ump_legacy_trigger, .drain = snd_ump_legacy_drain, }; static const struct snd_rawmidi_global_ops snd_ump_legacy_ops = { .dev_register = snd_ump_legacy_dev_register, }; static int process_legacy_output(struct snd_ump_endpoint *ump, u32 *buffer, int count) { struct snd_rawmidi_substream *substream; struct ump_cvt_to_ump *ctx; const int dir = SNDRV_RAWMIDI_STREAM_OUTPUT; unsigned char c; int group, size = 0; unsigned long flags; if (!ump->out_cvts || !ump->legacy_out_opens) return 0; spin_lock_irqsave(&ump->legacy_locks[dir], flags); for (group = 0; group < SNDRV_UMP_MAX_GROUPS; group++) { substream = ump->legacy_substreams[dir][group]; if (!substream) continue; ctx = &ump->out_cvts[group]; while (!ctx->ump_bytes && snd_rawmidi_transmit(substream, &c, 1) > 0) snd_ump_convert_to_ump(ctx, group, ump->info.protocol, c); if (ctx->ump_bytes && ctx->ump_bytes <= count) { size = ctx->ump_bytes; memcpy(buffer, ctx->ump, size); ctx->ump_bytes = 0; break; } } spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); return size; } static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src, int words) { struct snd_rawmidi_substream *substream; unsigned char buf[16]; unsigned char group; unsigned long flags; const int dir = SNDRV_RAWMIDI_STREAM_INPUT; int size; size = snd_ump_convert_from_ump(src, buf, &group); if (size <= 0) return; spin_lock_irqsave(&ump->legacy_locks[dir], flags); substream = ump->legacy_substreams[dir][group]; if (substream) snd_rawmidi_receive(substream, buf, size); spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); } /* Fill ump->legacy_mapping[] for groups to be used for legacy rawmidi */ static int fill_legacy_mapping(struct snd_ump_endpoint *ump) { struct snd_ump_block *fb; unsigned int group_maps = 0; int i, num; if (ump->info.flags & SNDRV_UMP_EP_INFO_STATIC_BLOCKS) { list_for_each_entry(fb, &ump->block_list, list) { for (i = 0; i < fb->info.num_groups; i++) group_maps |= 1U << (fb->info.first_group + i); } if (!group_maps) ump_info(ump, "No UMP Group is found in FB\n"); } /* use all groups for non-static case */ if (!group_maps) group_maps = (1U << SNDRV_UMP_MAX_GROUPS) - 1; num = 0; for (i = 0; i < SNDRV_UMP_MAX_GROUPS; i++) if (group_maps & (1U << i)) ump->legacy_mapping[num++] = i; return num; } static void fill_substream_names(struct snd_ump_endpoint *ump, struct snd_rawmidi *rmidi, int dir) { struct snd_rawmidi_substream *s; list_for_each_entry(s, &rmidi->streams[dir].substreams, list) snprintf(s->name, sizeof(s->name), "Group %d (%.16s)", ump->legacy_mapping[s->number] + 1, ump->info.name); } int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump, char *id, int device) { struct snd_rawmidi *rmidi; bool input, output; int err, num; ump->out_cvts = kcalloc(SNDRV_UMP_MAX_GROUPS, sizeof(*ump->out_cvts), GFP_KERNEL); if (!ump->out_cvts) return -ENOMEM; num = fill_legacy_mapping(ump); input = ump->core.info_flags & SNDRV_RAWMIDI_INFO_INPUT; output = ump->core.info_flags & SNDRV_RAWMIDI_INFO_OUTPUT; err = snd_rawmidi_new(ump->core.card, id, device, output ? num : 0, input ? num : 0, &rmidi); if (err < 0) { kfree(ump->out_cvts); return err; } if (input) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_ump_legacy_input_ops); if (output) snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_ump_legacy_output_ops); snprintf(rmidi->name, sizeof(rmidi->name), "%.68s (MIDI 1.0)", ump->info.name); rmidi->info_flags = ump->core.info_flags & ~SNDRV_RAWMIDI_INFO_UMP; rmidi->ops = &snd_ump_legacy_ops; rmidi->private_data = ump; ump->legacy_rmidi = rmidi; if (input) fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_INPUT); if (output) fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT); ump_dbg(ump, "Created a legacy rawmidi #%d (%s)\n", device, id); return 0; } EXPORT_SYMBOL_GPL(snd_ump_attach_legacy_rawmidi); #endif /* CONFIG_SND_UMP_LEGACY_RAWMIDI */ MODULE_DESCRIPTION("Universal MIDI Packet (UMP) Core Driver"); MODULE_LICENSE("GPL");
linux-master
sound/core/ump.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Misc and compatibility things * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/init.h> #include <linux/export.h> #include <linux/moduleparam.h> #include <linux/time.h> #include <linux/slab.h> #include <linux/ioport.h> #include <linux/fs.h> #include <sound/core.h> #ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG_VERBOSE #define DEFAULT_DEBUG_LEVEL 2 #else #define DEFAULT_DEBUG_LEVEL 1 #endif static int debug = DEFAULT_DEBUG_LEVEL; module_param(debug, int, 0644); MODULE_PARM_DESC(debug, "Debug level (0 = disable)"); #endif /* CONFIG_SND_DEBUG */ void release_and_free_resource(struct resource *res) { if (res) { release_resource(res); kfree(res); } } EXPORT_SYMBOL(release_and_free_resource); #ifdef CONFIG_SND_VERBOSE_PRINTK /* strip the leading path if the given path is absolute */ static const char *sanity_file_name(const char *path) { if (*path == '/') return strrchr(path, '/') + 1; else return path; } #endif #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK) void __snd_printk(unsigned int level, const char *path, int line, const char *format, ...) { va_list args; #ifdef CONFIG_SND_VERBOSE_PRINTK int kern_level; struct va_format vaf; char verbose_fmt[] = KERN_DEFAULT "ALSA %s:%d %pV"; bool level_found = false; #endif #ifdef CONFIG_SND_DEBUG if (debug < level) return; #endif va_start(args, format); #ifdef CONFIG_SND_VERBOSE_PRINTK vaf.fmt = format; vaf.va = &args; while ((kern_level = printk_get_level(vaf.fmt)) != 0) { const char *end_of_header = printk_skip_level(vaf.fmt); /* Ignore KERN_CONT. We print filename:line for each piece. */ if (kern_level >= '0' && kern_level <= '7') { memcpy(verbose_fmt, vaf.fmt, end_of_header - vaf.fmt); level_found = true; } vaf.fmt = end_of_header; } if (!level_found && level) memcpy(verbose_fmt, KERN_DEBUG, sizeof(KERN_DEBUG) - 1); printk(verbose_fmt, sanity_file_name(path), line, &vaf); #else vprintk(format, args); #endif va_end(args); } EXPORT_SYMBOL_GPL(__snd_printk); #endif #ifdef CONFIG_PCI #include <linux/pci.h> /** * snd_pci_quirk_lookup_id - look up a PCI SSID quirk list * @vendor: PCI SSV id * @device: PCI SSD id * @list: quirk list, terminated by a null entry * * Look through the given quirk list and finds a matching entry * with the same PCI SSID. When subdevice is 0, all subdevice * values may match. * * Returns the matched entry pointer, or NULL if nothing matched. */ const struct snd_pci_quirk * snd_pci_quirk_lookup_id(u16 vendor, u16 device, const struct snd_pci_quirk *list) { const struct snd_pci_quirk *q; for (q = list; q->subvendor || q->subdevice; q++) { if (q->subvendor != vendor) continue; if (!q->subdevice || (device & q->subdevice_mask) == q->subdevice) return q; } return NULL; } EXPORT_SYMBOL(snd_pci_quirk_lookup_id); /** * snd_pci_quirk_lookup - look up a PCI SSID quirk list * @pci: pci_dev handle * @list: quirk list, terminated by a null entry * * Look through the given quirk list and finds a matching entry * with the same PCI SSID. When subdevice is 0, all subdevice * values may match. * * Returns the matched entry pointer, or NULL if nothing matched. */ const struct snd_pci_quirk * snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list) { if (!pci) return NULL; return snd_pci_quirk_lookup_id(pci->subsystem_vendor, pci->subsystem_device, list); } EXPORT_SYMBOL(snd_pci_quirk_lookup); #endif /* * Deferred async signal helpers * * Below are a few helper functions to wrap the async signal handling * in the deferred work. The main purpose is to avoid the messy deadlock * around tasklist_lock and co at the kill_fasync() invocation. * fasync_helper() and kill_fasync() are replaced with snd_fasync_helper() * and snd_kill_fasync(), respectively. In addition, snd_fasync_free() has * to be called at releasing the relevant file object. */ struct snd_fasync { struct fasync_struct *fasync; int signal; int poll; int on; struct list_head list; }; static DEFINE_SPINLOCK(snd_fasync_lock); static LIST_HEAD(snd_fasync_list); static void snd_fasync_work_fn(struct work_struct *work) { struct snd_fasync *fasync; spin_lock_irq(&snd_fasync_lock); while (!list_empty(&snd_fasync_list)) { fasync = list_first_entry(&snd_fasync_list, struct snd_fasync, list); list_del_init(&fasync->list); spin_unlock_irq(&snd_fasync_lock); if (fasync->on) kill_fasync(&fasync->fasync, fasync->signal, fasync->poll); spin_lock_irq(&snd_fasync_lock); } spin_unlock_irq(&snd_fasync_lock); } static DECLARE_WORK(snd_fasync_work, snd_fasync_work_fn); int snd_fasync_helper(int fd, struct file *file, int on, struct snd_fasync **fasyncp) { struct snd_fasync *fasync = NULL; if (on) { fasync = kzalloc(sizeof(*fasync), GFP_KERNEL); if (!fasync) return -ENOMEM; INIT_LIST_HEAD(&fasync->list); } spin_lock_irq(&snd_fasync_lock); if (*fasyncp) { kfree(fasync); fasync = *fasyncp; } else { if (!fasync) { spin_unlock_irq(&snd_fasync_lock); return 0; } *fasyncp = fasync; } fasync->on = on; spin_unlock_irq(&snd_fasync_lock); return fasync_helper(fd, file, on, &fasync->fasync); } EXPORT_SYMBOL_GPL(snd_fasync_helper); void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll) { unsigned long flags; if (!fasync || !fasync->on) return; spin_lock_irqsave(&snd_fasync_lock, flags); fasync->signal = signal; fasync->poll = poll; list_move(&fasync->list, &snd_fasync_list); schedule_work(&snd_fasync_work); spin_unlock_irqrestore(&snd_fasync_lock, flags); } EXPORT_SYMBOL_GPL(snd_kill_fasync); void snd_fasync_free(struct snd_fasync *fasync) { if (!fasync) return; fasync->on = 0; flush_work(&snd_fasync_work); kfree(fasync); } EXPORT_SYMBOL_GPL(snd_fasync_free);
linux-master
sound/core/misc.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * 32bit -> 64bit ioctl wrapper for raw MIDI API * Copyright (c) by Takashi Iwai <[email protected]> */ /* This file included from rawmidi.c */ #include <linux/compat.h> struct snd_rawmidi_params32 { s32 stream; u32 buffer_size; u32 avail_min; unsigned int no_active_sensing; /* avoid bit-field */ unsigned int mode; unsigned char reserved[12]; } __attribute__((packed)); static int snd_rawmidi_ioctl_params_compat(struct snd_rawmidi_file *rfile, struct snd_rawmidi_params32 __user *src) { struct snd_rawmidi_params params; unsigned int val; if (get_user(params.stream, &src->stream) || get_user(params.buffer_size, &src->buffer_size) || get_user(params.avail_min, &src->avail_min) || get_user(params.mode, &src->mode) || get_user(val, &src->no_active_sensing)) return -EFAULT; params.no_active_sensing = val; switch (params.stream) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (!rfile->output) return -EINVAL; return snd_rawmidi_output_params(rfile->output, &params); case SNDRV_RAWMIDI_STREAM_INPUT: if (!rfile->input) return -EINVAL; return snd_rawmidi_input_params(rfile->input, &params); } return -EINVAL; } struct compat_snd_rawmidi_status64 { s32 stream; u8 rsvd[4]; /* alignment */ s64 tstamp_sec; s64 tstamp_nsec; u32 avail; u32 xruns; unsigned char reserved[16]; } __attribute__((packed)); static int snd_rawmidi_ioctl_status_compat64(struct snd_rawmidi_file *rfile, struct compat_snd_rawmidi_status64 __user *src) { int err; struct snd_rawmidi_status64 status; struct compat_snd_rawmidi_status64 compat_status; if (get_user(status.stream, &src->stream)) return -EFAULT; switch (status.stream) { case SNDRV_RAWMIDI_STREAM_OUTPUT: if (!rfile->output) return -EINVAL; err = snd_rawmidi_output_status(rfile->output, &status); break; case SNDRV_RAWMIDI_STREAM_INPUT: if (!rfile->input) return -EINVAL; err = snd_rawmidi_input_status(rfile->input, &status); break; default: return -EINVAL; } if (err < 0) return err; compat_status = (struct compat_snd_rawmidi_status64) { .stream = status.stream, .tstamp_sec = status.tstamp_sec, .tstamp_nsec = status.tstamp_nsec, .avail = status.avail, .xruns = status.xruns, }; if (copy_to_user(src, &compat_status, sizeof(*src))) return -EFAULT; return 0; } enum { SNDRV_RAWMIDI_IOCTL_PARAMS32 = _IOWR('W', 0x10, struct snd_rawmidi_params32), SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32 = _IOWR('W', 0x20, struct snd_rawmidi_status32), SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64 = _IOWR('W', 0x20, struct compat_snd_rawmidi_status64), }; static long snd_rawmidi_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_rawmidi_file *rfile; void __user *argp = compat_ptr(arg); rfile = file->private_data; switch (cmd) { case SNDRV_RAWMIDI_IOCTL_PVERSION: case SNDRV_RAWMIDI_IOCTL_INFO: case SNDRV_RAWMIDI_IOCTL_DROP: case SNDRV_RAWMIDI_IOCTL_DRAIN: #if IS_ENABLED(CONFIG_SND_UMP) case SNDRV_UMP_IOCTL_ENDPOINT_INFO: case SNDRV_UMP_IOCTL_BLOCK_INFO: #endif return snd_rawmidi_ioctl(file, cmd, (unsigned long)argp); case SNDRV_RAWMIDI_IOCTL_PARAMS32: return snd_rawmidi_ioctl_params_compat(rfile, argp); case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT32: return snd_rawmidi_ioctl_status32(rfile, argp); case SNDRV_RAWMIDI_IOCTL_STATUS_COMPAT64: return snd_rawmidi_ioctl_status_compat64(rfile, argp); } return -ENOIOCTLCMD; }
linux-master
sound/core/rawmidi_compat.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ALSA timer back-end using hrtimer * Copyright (C) 2008 Takashi Iwai */ #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/hrtimer.h> #include <sound/core.h> #include <sound/timer.h> MODULE_AUTHOR("Takashi Iwai <[email protected]>"); MODULE_DESCRIPTION("ALSA hrtimer backend"); MODULE_LICENSE("GPL"); MODULE_ALIAS("snd-timer-" __stringify(SNDRV_TIMER_GLOBAL_HRTIMER)); #define NANO_SEC 1000000000UL /* 10^9 in sec */ static unsigned int resolution; struct snd_hrtimer { struct snd_timer *timer; struct hrtimer hrt; bool in_callback; }; static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt) { struct snd_hrtimer *stime = container_of(hrt, struct snd_hrtimer, hrt); struct snd_timer *t = stime->timer; ktime_t delta; unsigned long ticks; enum hrtimer_restart ret = HRTIMER_NORESTART; spin_lock(&t->lock); if (!t->running) goto out; /* fast path */ stime->in_callback = true; ticks = t->sticks; spin_unlock(&t->lock); /* calculate the drift */ delta = ktime_sub(hrt->base->get_time(), hrtimer_get_expires(hrt)); if (delta > 0) ticks += ktime_divns(delta, ticks * resolution); snd_timer_interrupt(stime->timer, ticks); spin_lock(&t->lock); if (t->running) { hrtimer_add_expires_ns(hrt, t->sticks * resolution); ret = HRTIMER_RESTART; } stime->in_callback = false; out: spin_unlock(&t->lock); return ret; } static int snd_hrtimer_open(struct snd_timer *t) { struct snd_hrtimer *stime; stime = kzalloc(sizeof(*stime), GFP_KERNEL); if (!stime) return -ENOMEM; hrtimer_init(&stime->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL); stime->timer = t; stime->hrt.function = snd_hrtimer_callback; t->private_data = stime; return 0; } static int snd_hrtimer_close(struct snd_timer *t) { struct snd_hrtimer *stime = t->private_data; if (stime) { spin_lock_irq(&t->lock); t->running = 0; /* just to be sure */ stime->in_callback = 1; /* skip start/stop */ spin_unlock_irq(&t->lock); hrtimer_cancel(&stime->hrt); kfree(stime); t->private_data = NULL; } return 0; } static int snd_hrtimer_start(struct snd_timer *t) { struct snd_hrtimer *stime = t->private_data; if (stime->in_callback) return 0; hrtimer_start(&stime->hrt, ns_to_ktime(t->sticks * resolution), HRTIMER_MODE_REL); return 0; } static int snd_hrtimer_stop(struct snd_timer *t) { struct snd_hrtimer *stime = t->private_data; if (stime->in_callback) return 0; hrtimer_try_to_cancel(&stime->hrt); return 0; } static const struct snd_timer_hardware hrtimer_hw __initconst = { .flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_WORK, .open = snd_hrtimer_open, .close = snd_hrtimer_close, .start = snd_hrtimer_start, .stop = snd_hrtimer_stop, }; /* * entry functions */ static struct snd_timer *mytimer; static int __init snd_hrtimer_init(void) { struct snd_timer *timer; int err; resolution = hrtimer_resolution; /* Create a new timer and set up the fields */ err = snd_timer_global_new("hrtimer", SNDRV_TIMER_GLOBAL_HRTIMER, &timer); if (err < 0) return err; timer->module = THIS_MODULE; strcpy(timer->name, "HR timer"); timer->hw = hrtimer_hw; timer->hw.resolution = resolution; timer->hw.ticks = NANO_SEC / resolution; timer->max_instances = 100; /* lower the limit */ err = snd_timer_global_register(timer); if (err < 0) { snd_timer_global_free(timer); return err; } mytimer = timer; /* remember this */ return 0; } static void __exit snd_hrtimer_exit(void) { if (mytimer) { snd_timer_global_free(mytimer); mytimer = NULL; } } module_init(snd_hrtimer_init); module_exit(snd_hrtimer_exit);
linux-master
sound/core/hrtimer.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Digital Audio (PCM) abstract layer * Copyright (c) by Jaroslav Kysela <[email protected]> * Abramo Bagnara <[email protected]> */ #include <linux/slab.h> #include <linux/sched/signal.h> #include <linux/time.h> #include <linux/math64.h> #include <linux/export.h> #include <sound/core.h> #include <sound/control.h> #include <sound/tlv.h> #include <sound/info.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/timer.h> #include "pcm_local.h" #ifdef CONFIG_SND_PCM_XRUN_DEBUG #define CREATE_TRACE_POINTS #include "pcm_trace.h" #else #define trace_hwptr(substream, pos, in_interrupt) #define trace_xrun(substream) #define trace_hw_ptr_error(substream, reason) #define trace_applptr(substream, prev, curr) #endif static int fill_silence_frames(struct snd_pcm_substream *substream, snd_pcm_uframes_t off, snd_pcm_uframes_t frames); static inline void update_silence_vars(struct snd_pcm_runtime *runtime, snd_pcm_uframes_t ptr, snd_pcm_uframes_t new_ptr) { snd_pcm_sframes_t delta; delta = new_ptr - ptr; if (delta == 0) return; if (delta < 0) delta += runtime->boundary; if ((snd_pcm_uframes_t)delta < runtime->silence_filled) runtime->silence_filled -= delta; else runtime->silence_filled = 0; runtime->silence_start = new_ptr; } /* * fill ring buffer with silence * runtime->silence_start: starting pointer to silence area * runtime->silence_filled: size filled with silence * runtime->silence_threshold: threshold from application * runtime->silence_size: maximal size from application * * when runtime->silence_size >= runtime->boundary - fill processed area with silence immediately */ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t frames, ofs, transfer; int err; if (runtime->silence_size < runtime->boundary) { snd_pcm_sframes_t noise_dist; snd_pcm_uframes_t appl_ptr = READ_ONCE(runtime->control->appl_ptr); update_silence_vars(runtime, runtime->silence_start, appl_ptr); /* initialization outside pointer updates */ if (new_hw_ptr == ULONG_MAX) new_hw_ptr = runtime->status->hw_ptr; /* get hw_avail with the boundary crossing */ noise_dist = appl_ptr - new_hw_ptr; if (noise_dist < 0) noise_dist += runtime->boundary; /* total noise distance */ noise_dist += runtime->silence_filled; if (noise_dist >= (snd_pcm_sframes_t) runtime->silence_threshold) return; frames = runtime->silence_threshold - noise_dist; if (frames > runtime->silence_size) frames = runtime->silence_size; } else { /* * This filling mode aims at free-running mode (used for example by dmix), * which doesn't update the application pointer. */ snd_pcm_uframes_t hw_ptr = runtime->status->hw_ptr; if (new_hw_ptr == ULONG_MAX) { /* * Initialization, fill the whole unused buffer with silence. * * Usually, this is entered while stopped, before data is queued, * so both pointers are expected to be zero. */ snd_pcm_sframes_t avail = runtime->control->appl_ptr - hw_ptr; if (avail < 0) avail += runtime->boundary; /* * In free-running mode, appl_ptr will be zero even while running, * so we end up with a huge number. There is no useful way to * handle this, so we just clear the whole buffer. */ runtime->silence_filled = avail > runtime->buffer_size ? 0 : avail; runtime->silence_start = hw_ptr; } else { /* Silence the just played area immediately */ update_silence_vars(runtime, hw_ptr, new_hw_ptr); } /* * In this mode, silence_filled actually includes the valid * sample data from the user. */ frames = runtime->buffer_size - runtime->silence_filled; } if (snd_BUG_ON(frames > runtime->buffer_size)) return; if (frames == 0) return; ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size; do { transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames; err = fill_silence_frames(substream, ofs, transfer); snd_BUG_ON(err < 0); runtime->silence_filled += transfer; frames -= transfer; ofs = 0; } while (frames > 0); snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); } #ifdef CONFIG_SND_DEBUG void snd_pcm_debug_name(struct snd_pcm_substream *substream, char *name, size_t len) { snprintf(name, len, "pcmC%dD%d%c:%d", substream->pcm->card->number, substream->pcm->device, substream->stream ? 'c' : 'p', substream->number); } EXPORT_SYMBOL(snd_pcm_debug_name); #endif #define XRUN_DEBUG_BASIC (1<<0) #define XRUN_DEBUG_STACK (1<<1) /* dump also stack */ #define XRUN_DEBUG_JIFFIESCHECK (1<<2) /* do jiffies check */ #ifdef CONFIG_SND_PCM_XRUN_DEBUG #define xrun_debug(substream, mask) \ ((substream)->pstr->xrun_debug & (mask)) #else #define xrun_debug(substream, mask) 0 #endif #define dump_stack_on_xrun(substream) do { \ if (xrun_debug(substream, XRUN_DEBUG_STACK)) \ dump_stack(); \ } while (0) /* call with stream lock held */ void __snd_pcm_xrun(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; trace_xrun(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); runtime->status->tstamp.tv_sec = tstamp.tv_sec; runtime->status->tstamp.tv_nsec = tstamp.tv_nsec; } snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { char name[16]; snd_pcm_debug_name(substream, name, sizeof(name)); pcm_warn(substream->pcm, "XRUN: %s\n", name); dump_stack_on_xrun(substream); } } #ifdef CONFIG_SND_PCM_XRUN_DEBUG #define hw_ptr_error(substream, in_interrupt, reason, fmt, args...) \ do { \ trace_hw_ptr_error(substream, reason); \ if (xrun_debug(substream, XRUN_DEBUG_BASIC)) { \ pr_err_ratelimited("ALSA: PCM: [%c] " reason ": " fmt, \ (in_interrupt) ? 'Q' : 'P', ##args); \ dump_stack_on_xrun(substream); \ } \ } while (0) #else /* ! CONFIG_SND_PCM_XRUN_DEBUG */ #define hw_ptr_error(substream, fmt, args...) do { } while (0) #endif int snd_pcm_update_state(struct snd_pcm_substream *substream, struct snd_pcm_runtime *runtime) { snd_pcm_uframes_t avail; avail = snd_pcm_avail(substream); if (avail > runtime->avail_max) runtime->avail_max = avail; if (runtime->state == SNDRV_PCM_STATE_DRAINING) { if (avail >= runtime->buffer_size) { snd_pcm_drain_done(substream); return -EPIPE; } } else { if (avail >= runtime->stop_threshold) { __snd_pcm_xrun(substream); return -EPIPE; } } if (runtime->twake) { if (avail >= runtime->twake) wake_up(&runtime->tsleep); } else if (avail >= runtime->control->avail_min) wake_up(&runtime->sleep); return 0; } static void update_audio_tstamp(struct snd_pcm_substream *substream, struct timespec64 *curr_tstamp, struct timespec64 *audio_tstamp) { struct snd_pcm_runtime *runtime = substream->runtime; u64 audio_frames, audio_nsecs; struct timespec64 driver_tstamp; if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE) return; if (!(substream->ops->get_time_info) || (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) { /* * provide audio timestamp derived from pointer position * add delay only if requested */ audio_frames = runtime->hw_ptr_wrap + runtime->status->hw_ptr; if (runtime->audio_tstamp_config.report_delay) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) audio_frames -= runtime->delay; else audio_frames += runtime->delay; } audio_nsecs = div_u64(audio_frames * 1000000000LL, runtime->rate); *audio_tstamp = ns_to_timespec64(audio_nsecs); } if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec || runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) { runtime->status->audio_tstamp.tv_sec = audio_tstamp->tv_sec; runtime->status->audio_tstamp.tv_nsec = audio_tstamp->tv_nsec; runtime->status->tstamp.tv_sec = curr_tstamp->tv_sec; runtime->status->tstamp.tv_nsec = curr_tstamp->tv_nsec; } /* * re-take a driver timestamp to let apps detect if the reference tstamp * read by low-level hardware was provided with a delay */ snd_pcm_gettime(substream->runtime, &driver_tstamp); runtime->driver_tstamp = driver_tstamp; } static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, unsigned int in_interrupt) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t pos; snd_pcm_uframes_t old_hw_ptr, new_hw_ptr, hw_base; snd_pcm_sframes_t hdelta, delta; unsigned long jdelta; unsigned long curr_jiffies; struct timespec64 curr_tstamp; struct timespec64 audio_tstamp; int crossed_boundary = 0; old_hw_ptr = runtime->status->hw_ptr; /* * group pointer, time and jiffies reads to allow for more * accurate correlations/corrections. * The values are stored at the end of this routine after * corrections for hw_ptr position */ pos = substream->ops->pointer(substream); curr_jiffies = jiffies; if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { if ((substream->ops->get_time_info) && (runtime->audio_tstamp_config.type_requested != SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)) { substream->ops->get_time_info(substream, &curr_tstamp, &audio_tstamp, &runtime->audio_tstamp_config, &runtime->audio_tstamp_report); /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */ if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT) snd_pcm_gettime(runtime, &curr_tstamp); } else snd_pcm_gettime(runtime, &curr_tstamp); } if (pos == SNDRV_PCM_POS_XRUN) { __snd_pcm_xrun(substream); return -EPIPE; } if (pos >= runtime->buffer_size) { if (printk_ratelimit()) { char name[16]; snd_pcm_debug_name(substream, name, sizeof(name)); pcm_err(substream->pcm, "invalid position: %s, pos = %ld, buffer size = %ld, period size = %ld\n", name, pos, runtime->buffer_size, runtime->period_size); } pos = 0; } pos -= pos % runtime->min_align; trace_hwptr(substream, pos, in_interrupt); hw_base = runtime->hw_ptr_base; new_hw_ptr = hw_base + pos; if (in_interrupt) { /* we know that one period was processed */ /* delta = "expected next hw_ptr" for in_interrupt != 0 */ delta = runtime->hw_ptr_interrupt + runtime->period_size; if (delta > new_hw_ptr) { /* check for double acknowledged interrupts */ hdelta = curr_jiffies - runtime->hw_ptr_jiffies; if (hdelta > runtime->hw_ptr_buffer_jiffies/2 + 1) { hw_base += runtime->buffer_size; if (hw_base >= runtime->boundary) { hw_base = 0; crossed_boundary++; } new_hw_ptr = hw_base + pos; goto __delta; } } } /* new_hw_ptr might be lower than old_hw_ptr in case when */ /* pointer crosses the end of the ring buffer */ if (new_hw_ptr < old_hw_ptr) { hw_base += runtime->buffer_size; if (hw_base >= runtime->boundary) { hw_base = 0; crossed_boundary++; } new_hw_ptr = hw_base + pos; } __delta: delta = new_hw_ptr - old_hw_ptr; if (delta < 0) delta += runtime->boundary; if (runtime->no_period_wakeup) { snd_pcm_sframes_t xrun_threshold; /* * Without regular period interrupts, we have to check * the elapsed time to detect xruns. */ jdelta = curr_jiffies - runtime->hw_ptr_jiffies; if (jdelta < runtime->hw_ptr_buffer_jiffies / 2) goto no_delta_check; hdelta = jdelta - delta * HZ / runtime->rate; xrun_threshold = runtime->hw_ptr_buffer_jiffies / 2 + 1; while (hdelta > xrun_threshold) { delta += runtime->buffer_size; hw_base += runtime->buffer_size; if (hw_base >= runtime->boundary) { hw_base = 0; crossed_boundary++; } new_hw_ptr = hw_base + pos; hdelta -= runtime->hw_ptr_buffer_jiffies; } goto no_delta_check; } /* something must be really wrong */ if (delta >= runtime->buffer_size + runtime->period_size) { hw_ptr_error(substream, in_interrupt, "Unexpected hw_ptr", "(stream=%i, pos=%ld, new_hw_ptr=%ld, old_hw_ptr=%ld)\n", substream->stream, (long)pos, (long)new_hw_ptr, (long)old_hw_ptr); return 0; } /* Do jiffies check only in xrun_debug mode */ if (!xrun_debug(substream, XRUN_DEBUG_JIFFIESCHECK)) goto no_jiffies_check; /* Skip the jiffies check for hardwares with BATCH flag. * Such hardware usually just increases the position at each IRQ, * thus it can't give any strange position. */ if (runtime->hw.info & SNDRV_PCM_INFO_BATCH) goto no_jiffies_check; hdelta = delta; if (hdelta < runtime->delay) goto no_jiffies_check; hdelta -= runtime->delay; jdelta = curr_jiffies - runtime->hw_ptr_jiffies; if (((hdelta * HZ) / runtime->rate) > jdelta + HZ/100) { delta = jdelta / (((runtime->period_size * HZ) / runtime->rate) + HZ/100); /* move new_hw_ptr according jiffies not pos variable */ new_hw_ptr = old_hw_ptr; hw_base = delta; /* use loop to avoid checks for delta overflows */ /* the delta value is small or zero in most cases */ while (delta > 0) { new_hw_ptr += runtime->period_size; if (new_hw_ptr >= runtime->boundary) { new_hw_ptr -= runtime->boundary; crossed_boundary--; } delta--; } /* align hw_base to buffer_size */ hw_ptr_error(substream, in_interrupt, "hw_ptr skipping", "(pos=%ld, delta=%ld, period=%ld, jdelta=%lu/%lu/%lu, hw_ptr=%ld/%ld)\n", (long)pos, (long)hdelta, (long)runtime->period_size, jdelta, ((hdelta * HZ) / runtime->rate), hw_base, (unsigned long)old_hw_ptr, (unsigned long)new_hw_ptr); /* reset values to proper state */ delta = 0; hw_base = new_hw_ptr - (new_hw_ptr % runtime->buffer_size); } no_jiffies_check: if (delta > runtime->period_size + runtime->period_size / 2) { hw_ptr_error(substream, in_interrupt, "Lost interrupts?", "(stream=%i, delta=%ld, new_hw_ptr=%ld, old_hw_ptr=%ld)\n", substream->stream, (long)delta, (long)new_hw_ptr, (long)old_hw_ptr); } no_delta_check: if (runtime->status->hw_ptr == new_hw_ptr) { runtime->hw_ptr_jiffies = curr_jiffies; update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp); return 0; } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, new_hw_ptr); if (in_interrupt) { delta = new_hw_ptr - runtime->hw_ptr_interrupt; if (delta < 0) delta += runtime->boundary; delta -= (snd_pcm_uframes_t)delta % runtime->period_size; runtime->hw_ptr_interrupt += delta; if (runtime->hw_ptr_interrupt >= runtime->boundary) runtime->hw_ptr_interrupt -= runtime->boundary; } runtime->hw_ptr_base = hw_base; runtime->status->hw_ptr = new_hw_ptr; runtime->hw_ptr_jiffies = curr_jiffies; if (crossed_boundary) { snd_BUG_ON(crossed_boundary != 1); runtime->hw_ptr_wrap += runtime->boundary; } update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp); return snd_pcm_update_state(substream, runtime); } /* CAUTION: call it with irq disabled */ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream) { return snd_pcm_update_hw_ptr0(substream, 0); } /** * snd_pcm_set_ops - set the PCM operators * @pcm: the pcm instance * @direction: stream direction, SNDRV_PCM_STREAM_XXX * @ops: the operator table * * Sets the given PCM operators to the pcm instance. */ void snd_pcm_set_ops(struct snd_pcm *pcm, int direction, const struct snd_pcm_ops *ops) { struct snd_pcm_str *stream = &pcm->streams[direction]; struct snd_pcm_substream *substream; for (substream = stream->substream; substream != NULL; substream = substream->next) substream->ops = ops; } EXPORT_SYMBOL(snd_pcm_set_ops); /** * snd_pcm_set_sync - set the PCM sync id * @substream: the pcm substream * * Sets the PCM sync identifier for the card. */ void snd_pcm_set_sync(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; runtime->sync.id32[0] = substream->pcm->card->number; runtime->sync.id32[1] = -1; runtime->sync.id32[2] = -1; runtime->sync.id32[3] = -1; } EXPORT_SYMBOL(snd_pcm_set_sync); /* * Standard ioctl routine */ static inline unsigned int div32(unsigned int a, unsigned int b, unsigned int *r) { if (b == 0) { *r = 0; return UINT_MAX; } *r = a % b; return a / b; } static inline unsigned int div_down(unsigned int a, unsigned int b) { if (b == 0) return UINT_MAX; return a / b; } static inline unsigned int div_up(unsigned int a, unsigned int b) { unsigned int r; unsigned int q; if (b == 0) return UINT_MAX; q = div32(a, b, &r); if (r) ++q; return q; } static inline unsigned int mul(unsigned int a, unsigned int b) { if (a == 0) return 0; if (div_down(UINT_MAX, a) < b) return UINT_MAX; return a * b; } static inline unsigned int muldiv32(unsigned int a, unsigned int b, unsigned int c, unsigned int *r) { u_int64_t n = (u_int64_t) a * b; if (c == 0) { *r = 0; return UINT_MAX; } n = div_u64_rem(n, c, r); if (n >= UINT_MAX) { *r = 0; return UINT_MAX; } return n; } /** * snd_interval_refine - refine the interval value of configurator * @i: the interval value to refine * @v: the interval value to refer to * * Refines the interval value with the reference value. * The interval is changed to the range satisfying both intervals. * The interval status (min, max, integer, etc.) are evaluated. * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v) { int changed = 0; if (snd_BUG_ON(snd_interval_empty(i))) return -EINVAL; if (i->min < v->min) { i->min = v->min; i->openmin = v->openmin; changed = 1; } else if (i->min == v->min && !i->openmin && v->openmin) { i->openmin = 1; changed = 1; } if (i->max > v->max) { i->max = v->max; i->openmax = v->openmax; changed = 1; } else if (i->max == v->max && !i->openmax && v->openmax) { i->openmax = 1; changed = 1; } if (!i->integer && v->integer) { i->integer = 1; changed = 1; } if (i->integer) { if (i->openmin) { i->min++; i->openmin = 0; } if (i->openmax) { i->max--; i->openmax = 0; } } else if (!i->openmin && !i->openmax && i->min == i->max) i->integer = 1; if (snd_interval_checkempty(i)) { snd_interval_none(i); return -EINVAL; } return changed; } EXPORT_SYMBOL(snd_interval_refine); static int snd_interval_refine_first(struct snd_interval *i) { const unsigned int last_max = i->max; if (snd_BUG_ON(snd_interval_empty(i))) return -EINVAL; if (snd_interval_single(i)) return 0; i->max = i->min; if (i->openmin) i->max++; /* only exclude max value if also excluded before refine */ i->openmax = (i->openmax && i->max >= last_max); return 1; } static int snd_interval_refine_last(struct snd_interval *i) { const unsigned int last_min = i->min; if (snd_BUG_ON(snd_interval_empty(i))) return -EINVAL; if (snd_interval_single(i)) return 0; i->min = i->max; if (i->openmax) i->min--; /* only exclude min value if also excluded before refine */ i->openmin = (i->openmin && i->min <= last_min); return 1; } void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c) { if (a->empty || b->empty) { snd_interval_none(c); return; } c->empty = 0; c->min = mul(a->min, b->min); c->openmin = (a->openmin || b->openmin); c->max = mul(a->max, b->max); c->openmax = (a->openmax || b->openmax); c->integer = (a->integer && b->integer); } /** * snd_interval_div - refine the interval value with division * @a: dividend * @b: divisor * @c: quotient * * c = a / b * * Returns non-zero if the value is changed, zero if not changed. */ void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c) { unsigned int r; if (a->empty || b->empty) { snd_interval_none(c); return; } c->empty = 0; c->min = div32(a->min, b->max, &r); c->openmin = (r || a->openmin || b->openmax); if (b->min > 0) { c->max = div32(a->max, b->min, &r); if (r) { c->max++; c->openmax = 1; } else c->openmax = (a->openmax || b->openmin); } else { c->max = UINT_MAX; c->openmax = 0; } c->integer = 0; } /** * snd_interval_muldivk - refine the interval value * @a: dividend 1 * @b: dividend 2 * @k: divisor (as integer) * @c: result * * c = a * b / k * * Returns non-zero if the value is changed, zero if not changed. */ void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b, unsigned int k, struct snd_interval *c) { unsigned int r; if (a->empty || b->empty) { snd_interval_none(c); return; } c->empty = 0; c->min = muldiv32(a->min, b->min, k, &r); c->openmin = (r || a->openmin || b->openmin); c->max = muldiv32(a->max, b->max, k, &r); if (r) { c->max++; c->openmax = 1; } else c->openmax = (a->openmax || b->openmax); c->integer = 0; } /** * snd_interval_mulkdiv - refine the interval value * @a: dividend 1 * @k: dividend 2 (as integer) * @b: divisor * @c: result * * c = a * k / b * * Returns non-zero if the value is changed, zero if not changed. */ void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k, const struct snd_interval *b, struct snd_interval *c) { unsigned int r; if (a->empty || b->empty) { snd_interval_none(c); return; } c->empty = 0; c->min = muldiv32(a->min, k, b->max, &r); c->openmin = (r || a->openmin || b->openmax); if (b->min > 0) { c->max = muldiv32(a->max, k, b->min, &r); if (r) { c->max++; c->openmax = 1; } else c->openmax = (a->openmax || b->openmin); } else { c->max = UINT_MAX; c->openmax = 0; } c->integer = 0; } /* ---- */ /** * snd_interval_ratnum - refine the interval value * @i: interval to refine * @rats_count: number of ratnum_t * @rats: ratnum_t array * @nump: pointer to store the resultant numerator * @denp: pointer to store the resultant denominator * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_interval_ratnum(struct snd_interval *i, unsigned int rats_count, const struct snd_ratnum *rats, unsigned int *nump, unsigned int *denp) { unsigned int best_num, best_den; int best_diff; unsigned int k; struct snd_interval t; int err; unsigned int result_num, result_den; int result_diff; best_num = best_den = best_diff = 0; for (k = 0; k < rats_count; ++k) { unsigned int num = rats[k].num; unsigned int den; unsigned int q = i->min; int diff; if (q == 0) q = 1; den = div_up(num, q); if (den < rats[k].den_min) continue; if (den > rats[k].den_max) den = rats[k].den_max; else { unsigned int r; r = (den - rats[k].den_min) % rats[k].den_step; if (r != 0) den -= r; } diff = num - q * den; if (diff < 0) diff = -diff; if (best_num == 0 || diff * best_den < best_diff * den) { best_diff = diff; best_den = den; best_num = num; } } if (best_den == 0) { i->empty = 1; return -EINVAL; } t.min = div_down(best_num, best_den); t.openmin = !!(best_num % best_den); result_num = best_num; result_diff = best_diff; result_den = best_den; best_num = best_den = best_diff = 0; for (k = 0; k < rats_count; ++k) { unsigned int num = rats[k].num; unsigned int den; unsigned int q = i->max; int diff; if (q == 0) { i->empty = 1; return -EINVAL; } den = div_down(num, q); if (den > rats[k].den_max) continue; if (den < rats[k].den_min) den = rats[k].den_min; else { unsigned int r; r = (den - rats[k].den_min) % rats[k].den_step; if (r != 0) den += rats[k].den_step - r; } diff = q * den - num; if (diff < 0) diff = -diff; if (best_num == 0 || diff * best_den < best_diff * den) { best_diff = diff; best_den = den; best_num = num; } } if (best_den == 0) { i->empty = 1; return -EINVAL; } t.max = div_up(best_num, best_den); t.openmax = !!(best_num % best_den); t.integer = 0; err = snd_interval_refine(i, &t); if (err < 0) return err; if (snd_interval_single(i)) { if (best_diff * result_den < result_diff * best_den) { result_num = best_num; result_den = best_den; } if (nump) *nump = result_num; if (denp) *denp = result_den; } return err; } EXPORT_SYMBOL(snd_interval_ratnum); /** * snd_interval_ratden - refine the interval value * @i: interval to refine * @rats_count: number of struct ratden * @rats: struct ratden array * @nump: pointer to store the resultant numerator * @denp: pointer to store the resultant denominator * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ static int snd_interval_ratden(struct snd_interval *i, unsigned int rats_count, const struct snd_ratden *rats, unsigned int *nump, unsigned int *denp) { unsigned int best_num, best_diff, best_den; unsigned int k; struct snd_interval t; int err; best_num = best_den = best_diff = 0; for (k = 0; k < rats_count; ++k) { unsigned int num; unsigned int den = rats[k].den; unsigned int q = i->min; int diff; num = mul(q, den); if (num > rats[k].num_max) continue; if (num < rats[k].num_min) num = rats[k].num_max; else { unsigned int r; r = (num - rats[k].num_min) % rats[k].num_step; if (r != 0) num += rats[k].num_step - r; } diff = num - q * den; if (best_num == 0 || diff * best_den < best_diff * den) { best_diff = diff; best_den = den; best_num = num; } } if (best_den == 0) { i->empty = 1; return -EINVAL; } t.min = div_down(best_num, best_den); t.openmin = !!(best_num % best_den); best_num = best_den = best_diff = 0; for (k = 0; k < rats_count; ++k) { unsigned int num; unsigned int den = rats[k].den; unsigned int q = i->max; int diff; num = mul(q, den); if (num < rats[k].num_min) continue; if (num > rats[k].num_max) num = rats[k].num_max; else { unsigned int r; r = (num - rats[k].num_min) % rats[k].num_step; if (r != 0) num -= r; } diff = q * den - num; if (best_num == 0 || diff * best_den < best_diff * den) { best_diff = diff; best_den = den; best_num = num; } } if (best_den == 0) { i->empty = 1; return -EINVAL; } t.max = div_up(best_num, best_den); t.openmax = !!(best_num % best_den); t.integer = 0; err = snd_interval_refine(i, &t); if (err < 0) return err; if (snd_interval_single(i)) { if (nump) *nump = best_num; if (denp) *denp = best_den; } return err; } /** * snd_interval_list - refine the interval value from the list * @i: the interval value to refine * @count: the number of elements in the list * @list: the value list * @mask: the bit-mask to evaluate * * Refines the interval value from the list. * When mask is non-zero, only the elements corresponding to bit 1 are * evaluated. * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_interval_list(struct snd_interval *i, unsigned int count, const unsigned int *list, unsigned int mask) { unsigned int k; struct snd_interval list_range; if (!count) { i->empty = 1; return -EINVAL; } snd_interval_any(&list_range); list_range.min = UINT_MAX; list_range.max = 0; for (k = 0; k < count; k++) { if (mask && !(mask & (1 << k))) continue; if (!snd_interval_test(i, list[k])) continue; list_range.min = min(list_range.min, list[k]); list_range.max = max(list_range.max, list[k]); } return snd_interval_refine(i, &list_range); } EXPORT_SYMBOL(snd_interval_list); /** * snd_interval_ranges - refine the interval value from the list of ranges * @i: the interval value to refine * @count: the number of elements in the list of ranges * @ranges: the ranges list * @mask: the bit-mask to evaluate * * Refines the interval value from the list of ranges. * When mask is non-zero, only the elements corresponding to bit 1 are * evaluated. * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_interval_ranges(struct snd_interval *i, unsigned int count, const struct snd_interval *ranges, unsigned int mask) { unsigned int k; struct snd_interval range_union; struct snd_interval range; if (!count) { snd_interval_none(i); return -EINVAL; } snd_interval_any(&range_union); range_union.min = UINT_MAX; range_union.max = 0; for (k = 0; k < count; k++) { if (mask && !(mask & (1 << k))) continue; snd_interval_copy(&range, &ranges[k]); if (snd_interval_refine(&range, i) < 0) continue; if (snd_interval_empty(&range)) continue; if (range.min < range_union.min) { range_union.min = range.min; range_union.openmin = 1; } if (range.min == range_union.min && !range.openmin) range_union.openmin = 0; if (range.max > range_union.max) { range_union.max = range.max; range_union.openmax = 1; } if (range.max == range_union.max && !range.openmax) range_union.openmax = 0; } return snd_interval_refine(i, &range_union); } EXPORT_SYMBOL(snd_interval_ranges); static int snd_interval_step(struct snd_interval *i, unsigned int step) { unsigned int n; int changed = 0; n = i->min % step; if (n != 0 || i->openmin) { i->min += step - n; i->openmin = 0; changed = 1; } n = i->max % step; if (n != 0 || i->openmax) { i->max -= n; i->openmax = 0; changed = 1; } if (snd_interval_checkempty(i)) { i->empty = 1; return -EINVAL; } return changed; } /* Info constraints helpers */ /** * snd_pcm_hw_rule_add - add the hw-constraint rule * @runtime: the pcm runtime instance * @cond: condition bits * @var: the variable to evaluate * @func: the evaluation function * @private: the private data pointer passed to function * @dep: the dependent variables * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, unsigned int cond, int var, snd_pcm_hw_rule_func_t func, void *private, int dep, ...) { struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; struct snd_pcm_hw_rule *c; unsigned int k; va_list args; va_start(args, dep); if (constrs->rules_num >= constrs->rules_all) { struct snd_pcm_hw_rule *new; unsigned int new_rules = constrs->rules_all + 16; new = krealloc_array(constrs->rules, new_rules, sizeof(*c), GFP_KERNEL); if (!new) { va_end(args); return -ENOMEM; } constrs->rules = new; constrs->rules_all = new_rules; } c = &constrs->rules[constrs->rules_num]; c->cond = cond; c->func = func; c->var = var; c->private = private; k = 0; while (1) { if (snd_BUG_ON(k >= ARRAY_SIZE(c->deps))) { va_end(args); return -EINVAL; } c->deps[k++] = dep; if (dep < 0) break; dep = va_arg(args, int); } constrs->rules_num++; va_end(args); return 0; } EXPORT_SYMBOL(snd_pcm_hw_rule_add); /** * snd_pcm_hw_constraint_mask - apply the given bitmap mask constraint * @runtime: PCM runtime instance * @var: hw_params variable to apply the mask * @mask: the bitmap mask * * Apply the constraint of the given bitmap mask to a 32-bit mask parameter. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, u_int32_t mask) { struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; struct snd_mask *maskp = constrs_mask(constrs, var); *maskp->bits &= mask; memset(maskp->bits + 1, 0, (SNDRV_MASK_MAX-32) / 8); /* clear rest */ if (*maskp->bits == 0) return -EINVAL; return 0; } /** * snd_pcm_hw_constraint_mask64 - apply the given bitmap mask constraint * @runtime: PCM runtime instance * @var: hw_params variable to apply the mask * @mask: the 64bit bitmap mask * * Apply the constraint of the given bitmap mask to a 64-bit mask parameter. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, u_int64_t mask) { struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; struct snd_mask *maskp = constrs_mask(constrs, var); maskp->bits[0] &= (u_int32_t)mask; maskp->bits[1] &= (u_int32_t)(mask >> 32); memset(maskp->bits + 2, 0, (SNDRV_MASK_MAX-64) / 8); /* clear rest */ if (! maskp->bits[0] && ! maskp->bits[1]) return -EINVAL; return 0; } EXPORT_SYMBOL(snd_pcm_hw_constraint_mask64); /** * snd_pcm_hw_constraint_integer - apply an integer constraint to an interval * @runtime: PCM runtime instance * @var: hw_params variable to apply the integer constraint * * Apply the constraint of integer to an interval parameter. * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var) { struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; return snd_interval_setinteger(constrs_interval(constrs, var)); } EXPORT_SYMBOL(snd_pcm_hw_constraint_integer); /** * snd_pcm_hw_constraint_minmax - apply a min/max range constraint to an interval * @runtime: PCM runtime instance * @var: hw_params variable to apply the range * @min: the minimal value * @max: the maximal value * * Apply the min/max range constraint to an interval parameter. * * Return: Positive if the value is changed, zero if it's not changed, or a * negative error code. */ int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var, unsigned int min, unsigned int max) { struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; struct snd_interval t; t.min = min; t.max = max; t.openmin = t.openmax = 0; t.integer = 0; return snd_interval_refine(constrs_interval(constrs, var), &t); } EXPORT_SYMBOL(snd_pcm_hw_constraint_minmax); static int snd_pcm_hw_rule_list(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_pcm_hw_constraint_list *list = rule->private; return snd_interval_list(hw_param_interval(params, rule->var), list->count, list->list, list->mask); } /** * snd_pcm_hw_constraint_list - apply a list of constraints to a parameter * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the list constraint * @l: list * * Apply the list of constraints to an interval parameter. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var, const struct snd_pcm_hw_constraint_list *l) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_list, (void *)l, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_list); static int snd_pcm_hw_rule_ranges(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_pcm_hw_constraint_ranges *r = rule->private; return snd_interval_ranges(hw_param_interval(params, rule->var), r->count, r->ranges, r->mask); } /** * snd_pcm_hw_constraint_ranges - apply list of range constraints to a parameter * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the list of range constraints * @r: ranges * * Apply the list of range constraints to an interval parameter. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var, const struct snd_pcm_hw_constraint_ranges *r) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_ranges, (void *)r, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_ranges); static int snd_pcm_hw_rule_ratnums(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { const struct snd_pcm_hw_constraint_ratnums *r = rule->private; unsigned int num = 0, den = 0; int err; err = snd_interval_ratnum(hw_param_interval(params, rule->var), r->nrats, r->rats, &num, &den); if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) { params->rate_num = num; params->rate_den = den; } return err; } /** * snd_pcm_hw_constraint_ratnums - apply ratnums constraint to a parameter * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the ratnums constraint * @r: struct snd_ratnums constriants * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var, const struct snd_pcm_hw_constraint_ratnums *r) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_ratnums, (void *)r, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_ratnums); static int snd_pcm_hw_rule_ratdens(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { const struct snd_pcm_hw_constraint_ratdens *r = rule->private; unsigned int num = 0, den = 0; int err = snd_interval_ratden(hw_param_interval(params, rule->var), r->nrats, r->rats, &num, &den); if (err >= 0 && den && rule->var == SNDRV_PCM_HW_PARAM_RATE) { params->rate_num = num; params->rate_den = den; } return err; } /** * snd_pcm_hw_constraint_ratdens - apply ratdens constraint to a parameter * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the ratdens constraint * @r: struct snd_ratdens constriants * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var, const struct snd_pcm_hw_constraint_ratdens *r) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_ratdens, (void *)r, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_ratdens); static int snd_pcm_hw_rule_msbits(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned int l = (unsigned long) rule->private; int width = l & 0xffff; unsigned int msbits = l >> 16; const struct snd_interval *i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); if (!snd_interval_single(i)) return 0; if ((snd_interval_value(i) == width) || (width == 0 && snd_interval_value(i) > msbits)) params->msbits = min_not_zero(params->msbits, msbits); return 0; } /** * snd_pcm_hw_constraint_msbits - add a hw constraint msbits rule * @runtime: PCM runtime instance * @cond: condition bits * @width: sample bits width * @msbits: msbits width * * This constraint will set the number of most significant bits (msbits) if a * sample format with the specified width has been select. If width is set to 0 * the msbits will be set for any sample format with a width larger than the * specified msbits. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime, unsigned int cond, unsigned int width, unsigned int msbits) { unsigned long l = (msbits << 16) | width; return snd_pcm_hw_rule_add(runtime, cond, -1, snd_pcm_hw_rule_msbits, (void*) l, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_msbits); static int snd_pcm_hw_rule_step(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned long step = (unsigned long) rule->private; return snd_interval_step(hw_param_interval(params, rule->var), step); } /** * snd_pcm_hw_constraint_step - add a hw constraint step rule * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the step constraint * @step: step size * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var, unsigned long step) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_step, (void *) step, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_step); static int snd_pcm_hw_rule_pow2(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { static const unsigned int pow2_sizes[] = { 1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7, 1<<8, 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15, 1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23, 1<<24, 1<<25, 1<<26, 1<<27, 1<<28, 1<<29, 1<<30 }; return snd_interval_list(hw_param_interval(params, rule->var), ARRAY_SIZE(pow2_sizes), pow2_sizes, 0); } /** * snd_pcm_hw_constraint_pow2 - add a hw constraint power-of-2 rule * @runtime: PCM runtime instance * @cond: condition bits * @var: hw_params variable to apply the power-of-2 constraint * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, unsigned int cond, snd_pcm_hw_param_t var) { return snd_pcm_hw_rule_add(runtime, cond, var, snd_pcm_hw_rule_pow2, NULL, var, -1); } EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2); static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { unsigned int base_rate = (unsigned int)(uintptr_t)rule->private; struct snd_interval *rate; rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); return snd_interval_list(rate, 1, &base_rate, 0); } /** * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling * @runtime: PCM runtime instance * @base_rate: the rate at which the hardware does not resample * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime, unsigned int base_rate) { return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_noresample_func, (void *)(uintptr_t)base_rate, SNDRV_PCM_HW_PARAM_RATE, -1); } EXPORT_SYMBOL(snd_pcm_hw_rule_noresample); static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var) { if (hw_is_mask(var)) { snd_mask_any(hw_param_mask(params, var)); params->cmask |= 1 << var; params->rmask |= 1 << var; return; } if (hw_is_interval(var)) { snd_interval_any(hw_param_interval(params, var)); params->cmask |= 1 << var; params->rmask |= 1 << var; return; } snd_BUG(); } void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params) { unsigned int k; memset(params, 0, sizeof(*params)); for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) _snd_pcm_hw_param_any(params, k); for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) _snd_pcm_hw_param_any(params, k); params->info = ~0U; } EXPORT_SYMBOL(_snd_pcm_hw_params_any); /** * snd_pcm_hw_param_value - return @params field @var value * @params: the hw_params instance * @var: parameter to retrieve * @dir: pointer to the direction (-1,0,1) or %NULL * * Return: The value for field @var if it's fixed in configuration space * defined by @params. -%EINVAL otherwise. */ int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir) { if (hw_is_mask(var)) { const struct snd_mask *mask = hw_param_mask_c(params, var); if (!snd_mask_single(mask)) return -EINVAL; if (dir) *dir = 0; return snd_mask_value(mask); } if (hw_is_interval(var)) { const struct snd_interval *i = hw_param_interval_c(params, var); if (!snd_interval_single(i)) return -EINVAL; if (dir) *dir = i->openmin; return snd_interval_value(i); } return -EINVAL; } EXPORT_SYMBOL(snd_pcm_hw_param_value); void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var) { if (hw_is_mask(var)) { snd_mask_none(hw_param_mask(params, var)); params->cmask |= 1 << var; params->rmask |= 1 << var; } else if (hw_is_interval(var)) { snd_interval_none(hw_param_interval(params, var)); params->cmask |= 1 << var; params->rmask |= 1 << var; } else { snd_BUG(); } } EXPORT_SYMBOL(_snd_pcm_hw_param_setempty); static int _snd_pcm_hw_param_first(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var) { int changed; if (hw_is_mask(var)) changed = snd_mask_refine_first(hw_param_mask(params, var)); else if (hw_is_interval(var)) changed = snd_interval_refine_first(hw_param_interval(params, var)); else return -EINVAL; if (changed > 0) { params->cmask |= 1 << var; params->rmask |= 1 << var; } return changed; } /** * snd_pcm_hw_param_first - refine config space and return minimum value * @pcm: PCM instance * @params: the hw_params instance * @var: parameter to retrieve * @dir: pointer to the direction (-1,0,1) or %NULL * * Inside configuration space defined by @params remove from @var all * values > minimum. Reduce configuration space accordingly. * * Return: The minimum, or a negative error code on failure. */ int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir) { int changed = _snd_pcm_hw_param_first(params, var); if (changed < 0) return changed; if (params->rmask) { int err = snd_pcm_hw_refine(pcm, params); if (err < 0) return err; } return snd_pcm_hw_param_value(params, var, dir); } EXPORT_SYMBOL(snd_pcm_hw_param_first); static int _snd_pcm_hw_param_last(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var) { int changed; if (hw_is_mask(var)) changed = snd_mask_refine_last(hw_param_mask(params, var)); else if (hw_is_interval(var)) changed = snd_interval_refine_last(hw_param_interval(params, var)); else return -EINVAL; if (changed > 0) { params->cmask |= 1 << var; params->rmask |= 1 << var; } return changed; } /** * snd_pcm_hw_param_last - refine config space and return maximum value * @pcm: PCM instance * @params: the hw_params instance * @var: parameter to retrieve * @dir: pointer to the direction (-1,0,1) or %NULL * * Inside configuration space defined by @params remove from @var all * values < maximum. Reduce configuration space accordingly. * * Return: The maximum, or a negative error code on failure. */ int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var, int *dir) { int changed = _snd_pcm_hw_param_last(params, var); if (changed < 0) return changed; if (params->rmask) { int err = snd_pcm_hw_refine(pcm, params); if (err < 0) return err; } return snd_pcm_hw_param_value(params, var, dir); } EXPORT_SYMBOL(snd_pcm_hw_param_last); static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream, void *arg) { struct snd_pcm_runtime *runtime = substream->runtime; unsigned long flags; snd_pcm_stream_lock_irqsave(substream, flags); if (snd_pcm_running(substream) && snd_pcm_update_hw_ptr(substream) >= 0) runtime->status->hw_ptr %= runtime->buffer_size; else { runtime->status->hw_ptr = 0; runtime->hw_ptr_wrap = 0; } snd_pcm_stream_unlock_irqrestore(substream, flags); return 0; } static int snd_pcm_lib_ioctl_channel_info(struct snd_pcm_substream *substream, void *arg) { struct snd_pcm_channel_info *info = arg; struct snd_pcm_runtime *runtime = substream->runtime; int width; if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) { info->offset = -1; return 0; } width = snd_pcm_format_physical_width(runtime->format); if (width < 0) return width; info->offset = 0; switch (runtime->access) { case SNDRV_PCM_ACCESS_MMAP_INTERLEAVED: case SNDRV_PCM_ACCESS_RW_INTERLEAVED: info->first = info->channel * width; info->step = runtime->channels * width; break; case SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED: case SNDRV_PCM_ACCESS_RW_NONINTERLEAVED: { size_t size = runtime->dma_bytes / runtime->channels; info->first = info->channel * size * 8; info->step = width; break; } default: snd_BUG(); break; } return 0; } static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream, void *arg) { struct snd_pcm_hw_params *params = arg; snd_pcm_format_t format; int channels; ssize_t frame_size; params->fifo_size = substream->runtime->hw.fifo_size; if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_FIFO_IN_FRAMES)) { format = params_format(params); channels = params_channels(params); frame_size = snd_pcm_format_size(format, channels); if (frame_size > 0) params->fifo_size /= frame_size; } return 0; } /** * snd_pcm_lib_ioctl - a generic PCM ioctl callback * @substream: the pcm substream instance * @cmd: ioctl command * @arg: ioctl argument * * Processes the generic ioctl commands for PCM. * Can be passed as the ioctl callback for PCM ops. * * Return: Zero if successful, or a negative error code on failure. */ int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { switch (cmd) { case SNDRV_PCM_IOCTL1_RESET: return snd_pcm_lib_ioctl_reset(substream, arg); case SNDRV_PCM_IOCTL1_CHANNEL_INFO: return snd_pcm_lib_ioctl_channel_info(substream, arg); case SNDRV_PCM_IOCTL1_FIFO_SIZE: return snd_pcm_lib_ioctl_fifo_size(substream, arg); } return -ENXIO; } EXPORT_SYMBOL(snd_pcm_lib_ioctl); /** * snd_pcm_period_elapsed_under_stream_lock() - update the status of runtime for the next period * under acquired lock of PCM substream. * @substream: the instance of pcm substream. * * This function is called when the batch of audio data frames as the same size as the period of * buffer is already processed in audio data transmission. * * The call of function updates the status of runtime with the latest position of audio data * transmission, checks overrun and underrun over buffer, awaken user processes from waiting for * available audio data frames, sampling audio timestamp, and performs stop or drain the PCM * substream according to configured threshold. * * The function is intended to use for the case that PCM driver operates audio data frames under * acquired lock of PCM substream; e.g. in callback of any operation of &snd_pcm_ops in process * context. In any interrupt context, it's preferrable to use ``snd_pcm_period_elapsed()`` instead * since lock of PCM substream should be acquired in advance. * * Developer should pay enough attention that some callbacks in &snd_pcm_ops are done by the call of * function: * * - .pointer - to retrieve current position of audio data transmission by frame count or XRUN state. * - .trigger - with SNDRV_PCM_TRIGGER_STOP at XRUN or DRAINING state. * - .get_time_info - to retrieve audio time stamp if needed. * * Even if more than one periods have elapsed since the last call, you have to call this only once. */ void snd_pcm_period_elapsed_under_stream_lock(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; if (PCM_RUNTIME_CHECK(substream)) return; runtime = substream->runtime; if (!snd_pcm_running(substream) || snd_pcm_update_hw_ptr0(substream, 1) < 0) goto _end; #ifdef CONFIG_SND_PCM_TIMER if (substream->timer_running) snd_timer_interrupt(substream->timer, 1); #endif _end: snd_kill_fasync(runtime->fasync, SIGIO, POLL_IN); } EXPORT_SYMBOL(snd_pcm_period_elapsed_under_stream_lock); /** * snd_pcm_period_elapsed() - update the status of runtime for the next period by acquiring lock of * PCM substream. * @substream: the instance of PCM substream. * * This function is mostly similar to ``snd_pcm_period_elapsed_under_stream_lock()`` except for * acquiring lock of PCM substream voluntarily. * * It's typically called by any type of IRQ handler when hardware IRQ occurs to notify event that * the batch of audio data frames as the same size as the period of buffer is already processed in * audio data transmission. */ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) { unsigned long flags; if (snd_BUG_ON(!substream)) return; snd_pcm_stream_lock_irqsave(substream, flags); snd_pcm_period_elapsed_under_stream_lock(substream); snd_pcm_stream_unlock_irqrestore(substream, flags); } EXPORT_SYMBOL(snd_pcm_period_elapsed); /* * Wait until avail_min data becomes available * Returns a negative error code if any error occurs during operation. * The available space is stored on availp. When err = 0 and avail = 0 * on the capture stream, it indicates the stream is in DRAINING state. */ static int wait_for_avail(struct snd_pcm_substream *substream, snd_pcm_uframes_t *availp) { struct snd_pcm_runtime *runtime = substream->runtime; int is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; wait_queue_entry_t wait; int err = 0; snd_pcm_uframes_t avail = 0; long wait_time, tout; init_waitqueue_entry(&wait, current); set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&runtime->tsleep, &wait); if (runtime->no_period_wakeup) wait_time = MAX_SCHEDULE_TIMEOUT; else { /* use wait time from substream if available */ if (substream->wait_time) { wait_time = substream->wait_time; } else { wait_time = 100; if (runtime->rate) { long t = runtime->buffer_size * 1100 / runtime->rate; wait_time = max(t, wait_time); } } wait_time = msecs_to_jiffies(wait_time); } for (;;) { if (signal_pending(current)) { err = -ERESTARTSYS; break; } /* * We need to check if space became available already * (and thus the wakeup happened already) first to close * the race of space already having become available. * This check must happen after been added to the waitqueue * and having current state be INTERRUPTIBLE. */ avail = snd_pcm_avail(substream); if (avail >= runtime->twake) break; snd_pcm_stream_unlock_irq(substream); tout = schedule_timeout(wait_time); snd_pcm_stream_lock_irq(substream); set_current_state(TASK_INTERRUPTIBLE); switch (runtime->state) { case SNDRV_PCM_STATE_SUSPENDED: err = -ESTRPIPE; goto _endloop; case SNDRV_PCM_STATE_XRUN: err = -EPIPE; goto _endloop; case SNDRV_PCM_STATE_DRAINING: if (is_playback) err = -EPIPE; else avail = 0; /* indicate draining */ goto _endloop; case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_DISCONNECTED: err = -EBADFD; goto _endloop; case SNDRV_PCM_STATE_PAUSED: continue; } if (!tout) { pcm_dbg(substream->pcm, "%s timeout (DMA or IRQ trouble?)\n", is_playback ? "playback write" : "capture read"); err = -EIO; break; } } _endloop: set_current_state(TASK_RUNNING); remove_wait_queue(&runtime->tsleep, &wait); *availp = avail; return err; } typedef int (*pcm_transfer_f)(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, struct iov_iter *iter, unsigned long bytes); typedef int (*pcm_copy_f)(struct snd_pcm_substream *, snd_pcm_uframes_t, void *, snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f, bool); /* calculate the target DMA-buffer position to be written/read */ static void *get_dma_ptr(struct snd_pcm_runtime *runtime, int channel, unsigned long hwoff) { return runtime->dma_area + hwoff + channel * (runtime->dma_bytes / runtime->channels); } /* default copy ops for write; used for both interleaved and non- modes */ static int default_write_copy(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, struct iov_iter *iter, unsigned long bytes) { if (copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff), bytes, iter) != bytes) return -EFAULT; return 0; } /* fill silence instead of copy data; called as a transfer helper * from __snd_pcm_lib_write() or directly from noninterleaved_copy() when * a NULL buffer is passed */ static int fill_silence(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, struct iov_iter *iter, unsigned long bytes) { struct snd_pcm_runtime *runtime = substream->runtime; if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) return 0; if (substream->ops->fill_silence) return substream->ops->fill_silence(substream, channel, hwoff, bytes); snd_pcm_format_set_silence(runtime->format, get_dma_ptr(runtime, channel, hwoff), bytes_to_samples(runtime, bytes)); return 0; } /* default copy ops for read; used for both interleaved and non- modes */ static int default_read_copy(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, struct iov_iter *iter, unsigned long bytes) { if (copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff), bytes, iter) != bytes) return -EFAULT; return 0; } /* call transfer with the filled iov_iter */ static int do_transfer(struct snd_pcm_substream *substream, int c, unsigned long hwoff, void *data, unsigned long bytes, pcm_transfer_f transfer, bool in_kernel) { struct iov_iter iter; int err, type; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) type = ITER_SOURCE; else type = ITER_DEST; if (in_kernel) { struct kvec kvec = { data, bytes }; iov_iter_kvec(&iter, type, &kvec, 1, bytes); return transfer(substream, c, hwoff, &iter, bytes); } err = import_ubuf(type, (__force void __user *)data, bytes, &iter); if (err) return err; return transfer(substream, c, hwoff, &iter, bytes); } /* call transfer function with the converted pointers and sizes; * for interleaved mode, it's one shot for all samples */ static int interleaved_copy(struct snd_pcm_substream *substream, snd_pcm_uframes_t hwoff, void *data, snd_pcm_uframes_t off, snd_pcm_uframes_t frames, pcm_transfer_f transfer, bool in_kernel) { struct snd_pcm_runtime *runtime = substream->runtime; /* convert to bytes */ hwoff = frames_to_bytes(runtime, hwoff); off = frames_to_bytes(runtime, off); frames = frames_to_bytes(runtime, frames); return do_transfer(substream, 0, hwoff, data + off, frames, transfer, in_kernel); } /* call transfer function with the converted pointers and sizes for each * non-interleaved channel; when buffer is NULL, silencing instead of copying */ static int noninterleaved_copy(struct snd_pcm_substream *substream, snd_pcm_uframes_t hwoff, void *data, snd_pcm_uframes_t off, snd_pcm_uframes_t frames, pcm_transfer_f transfer, bool in_kernel) { struct snd_pcm_runtime *runtime = substream->runtime; int channels = runtime->channels; void **bufs = data; int c, err; /* convert to bytes; note that it's not frames_to_bytes() here. * in non-interleaved mode, we copy for each channel, thus * each copy is n_samples bytes x channels = whole frames. */ off = samples_to_bytes(runtime, off); frames = samples_to_bytes(runtime, frames); hwoff = samples_to_bytes(runtime, hwoff); for (c = 0; c < channels; ++c, ++bufs) { if (!data || !*bufs) err = fill_silence(substream, c, hwoff, NULL, frames); else err = do_transfer(substream, c, hwoff, *bufs + off, frames, transfer, in_kernel); if (err < 0) return err; } return 0; } /* fill silence on the given buffer position; * called from snd_pcm_playback_silence() */ static int fill_silence_frames(struct snd_pcm_substream *substream, snd_pcm_uframes_t off, snd_pcm_uframes_t frames) { if (substream->runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || substream->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) return interleaved_copy(substream, off, NULL, 0, frames, fill_silence, true); else return noninterleaved_copy(substream, off, NULL, 0, frames, fill_silence, true); } /* sanity-check for read/write methods */ static int pcm_sanity_check(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area)) return -EINVAL; if (runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; return 0; } static int pcm_accessible_state(struct snd_pcm_runtime *runtime) { switch (runtime->state) { case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PAUSED: return 0; case SNDRV_PCM_STATE_XRUN: return -EPIPE; case SNDRV_PCM_STATE_SUSPENDED: return -ESTRPIPE; default: return -EBADFD; } } /* update to the given appl_ptr and call ack callback if needed; * when an error is returned, take back to the original value */ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream, snd_pcm_uframes_t appl_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t old_appl_ptr = runtime->control->appl_ptr; snd_pcm_sframes_t diff; int ret; if (old_appl_ptr == appl_ptr) return 0; if (appl_ptr >= runtime->boundary) return -EINVAL; /* * check if a rewind is requested by the application */ if (substream->runtime->info & SNDRV_PCM_INFO_NO_REWINDS) { diff = appl_ptr - old_appl_ptr; if (diff >= 0) { if (diff > runtime->buffer_size) return -EINVAL; } else { if (runtime->boundary + diff > runtime->buffer_size) return -EINVAL; } } runtime->control->appl_ptr = appl_ptr; if (substream->ops->ack) { ret = substream->ops->ack(substream); if (ret < 0) { runtime->control->appl_ptr = old_appl_ptr; if (ret == -EPIPE) __snd_pcm_xrun(substream); return ret; } } trace_applptr(substream, old_appl_ptr, appl_ptr); return 0; } /* the common loop for read/write data */ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream, void *data, bool interleaved, snd_pcm_uframes_t size, bool in_kernel) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t xfer = 0; snd_pcm_uframes_t offset = 0; snd_pcm_uframes_t avail; pcm_copy_f writer; pcm_transfer_f transfer; bool nonblock; bool is_playback; int err; err = pcm_sanity_check(substream); if (err < 0) return err; is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; if (interleaved) { if (runtime->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED && runtime->channels > 1) return -EINVAL; writer = interleaved_copy; } else { if (runtime->access != SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) return -EINVAL; writer = noninterleaved_copy; } if (!data) { if (is_playback) transfer = fill_silence; else return -EINVAL; } else { if (substream->ops->copy) transfer = substream->ops->copy; else transfer = is_playback ? default_write_copy : default_read_copy; } if (size == 0) return 0; nonblock = !!(substream->f_flags & O_NONBLOCK); snd_pcm_stream_lock_irq(substream); err = pcm_accessible_state(runtime); if (err < 0) goto _end_unlock; runtime->twake = runtime->control->avail_min ? : 1; if (runtime->state == SNDRV_PCM_STATE_RUNNING) snd_pcm_update_hw_ptr(substream); /* * If size < start_threshold, wait indefinitely. Another * thread may start capture */ if (!is_playback && runtime->state == SNDRV_PCM_STATE_PREPARED && size >= runtime->start_threshold) { err = snd_pcm_start(substream); if (err < 0) goto _end_unlock; } avail = snd_pcm_avail(substream); while (size > 0) { snd_pcm_uframes_t frames, appl_ptr, appl_ofs; snd_pcm_uframes_t cont; if (!avail) { if (!is_playback && runtime->state == SNDRV_PCM_STATE_DRAINING) { snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); goto _end_unlock; } if (nonblock) { err = -EAGAIN; goto _end_unlock; } runtime->twake = min_t(snd_pcm_uframes_t, size, runtime->control->avail_min ? : 1); err = wait_for_avail(substream, &avail); if (err < 0) goto _end_unlock; if (!avail) continue; /* draining */ } frames = size > avail ? avail : size; appl_ptr = READ_ONCE(runtime->control->appl_ptr); appl_ofs = appl_ptr % runtime->buffer_size; cont = runtime->buffer_size - appl_ofs; if (frames > cont) frames = cont; if (snd_BUG_ON(!frames)) { err = -EINVAL; goto _end_unlock; } if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) { err = -EBUSY; goto _end_unlock; } snd_pcm_stream_unlock_irq(substream); if (!is_playback) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU); err = writer(substream, appl_ofs, data, offset, frames, transfer, in_kernel); if (is_playback) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); snd_pcm_stream_lock_irq(substream); atomic_dec(&runtime->buffer_accessing); if (err < 0) goto _end_unlock; err = pcm_accessible_state(runtime); if (err < 0) goto _end_unlock; appl_ptr += frames; if (appl_ptr >= runtime->boundary) appl_ptr -= runtime->boundary; err = pcm_lib_apply_appl_ptr(substream, appl_ptr); if (err < 0) goto _end_unlock; offset += frames; size -= frames; xfer += frames; avail -= frames; if (is_playback && runtime->state == SNDRV_PCM_STATE_PREPARED && snd_pcm_playback_hw_avail(runtime) >= (snd_pcm_sframes_t)runtime->start_threshold) { err = snd_pcm_start(substream); if (err < 0) goto _end_unlock; } } _end_unlock: runtime->twake = 0; if (xfer > 0 && err >= 0) snd_pcm_update_state(substream, runtime); snd_pcm_stream_unlock_irq(substream); return xfer > 0 ? (snd_pcm_sframes_t)xfer : err; } EXPORT_SYMBOL(__snd_pcm_lib_xfer); /* * standard channel mapping helpers */ /* default channel maps for multi-channel playbacks, up to 8 channels */ const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[] = { { .channels = 1, .map = { SNDRV_CHMAP_MONO } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, { .channels = 6, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE } }, { .channels = 8, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, SNDRV_CHMAP_SL, SNDRV_CHMAP_SR } }, { } }; EXPORT_SYMBOL_GPL(snd_pcm_std_chmaps); /* alternative channel maps with CLFE <-> surround swapped for 6/8 channels */ const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[] = { { .channels = 1, .map = { SNDRV_CHMAP_MONO } }, { .channels = 2, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, { .channels = 4, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, { .channels = 6, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, { .channels = 8, .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_FC, SNDRV_CHMAP_LFE, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, SNDRV_CHMAP_SL, SNDRV_CHMAP_SR } }, { } }; EXPORT_SYMBOL_GPL(snd_pcm_alt_chmaps); static bool valid_chmap_channels(const struct snd_pcm_chmap *info, int ch) { if (ch > info->max_channels) return false; return !info->channel_mask || (info->channel_mask & (1U << ch)); } static int pcm_chmap_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = info->max_channels; uinfo->value.integer.min = 0; uinfo->value.integer.max = SNDRV_CHMAP_LAST; return 0; } /* get callback for channel map ctl element * stores the channel position firstly matching with the current channels */ static int pcm_chmap_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); struct snd_pcm_substream *substream; const struct snd_pcm_chmap_elem *map; if (!info->chmap) return -EINVAL; substream = snd_pcm_chmap_substream(info, idx); if (!substream) return -ENODEV; memset(ucontrol->value.integer.value, 0, sizeof(long) * info->max_channels); if (!substream->runtime) return 0; /* no channels set */ for (map = info->chmap; map->channels; map++) { int i; if (map->channels == substream->runtime->channels && valid_chmap_channels(info, map->channels)) { for (i = 0; i < map->channels; i++) ucontrol->value.integer.value[i] = map->map[i]; return 0; } } return -EINVAL; } /* tlv callback for channel map ctl element * expands the pre-defined channel maps in a form of TLV */ static int pcm_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag, unsigned int size, unsigned int __user *tlv) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); const struct snd_pcm_chmap_elem *map; unsigned int __user *dst; int c, count = 0; if (!info->chmap) return -EINVAL; if (size < 8) return -ENOMEM; if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv)) return -EFAULT; size -= 8; dst = tlv + 2; for (map = info->chmap; map->channels; map++) { int chs_bytes = map->channels * 4; if (!valid_chmap_channels(info, map->channels)) continue; if (size < 8) return -ENOMEM; if (put_user(SNDRV_CTL_TLVT_CHMAP_FIXED, dst) || put_user(chs_bytes, dst + 1)) return -EFAULT; dst += 2; size -= 8; count += 8; if (size < chs_bytes) return -ENOMEM; size -= chs_bytes; count += chs_bytes; for (c = 0; c < map->channels; c++) { if (put_user(map->map[c], dst)) return -EFAULT; dst++; } } if (put_user(count, tlv + 1)) return -EFAULT; return 0; } static void pcm_chmap_ctl_private_free(struct snd_kcontrol *kcontrol) { struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); info->pcm->streams[info->stream].chmap_kctl = NULL; kfree(info); } /** * snd_pcm_add_chmap_ctls - create channel-mapping control elements * @pcm: the assigned PCM instance * @stream: stream direction * @chmap: channel map elements (for query) * @max_channels: the max number of channels for the stream * @private_value: the value passed to each kcontrol's private_value field * @info_ret: store struct snd_pcm_chmap instance if non-NULL * * Create channel-mapping control elements assigned to the given PCM stream(s). * Return: Zero if successful, or a negative error value. */ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream, const struct snd_pcm_chmap_elem *chmap, int max_channels, unsigned long private_value, struct snd_pcm_chmap **info_ret) { struct snd_pcm_chmap *info; struct snd_kcontrol_new knew = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, .info = pcm_chmap_ctl_info, .get = pcm_chmap_ctl_get, .tlv.c = pcm_chmap_ctl_tlv, }; int err; if (WARN_ON(pcm->streams[stream].chmap_kctl)) return -EBUSY; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) return -ENOMEM; info->pcm = pcm; info->stream = stream; info->chmap = chmap; info->max_channels = max_channels; if (stream == SNDRV_PCM_STREAM_PLAYBACK) knew.name = "Playback Channel Map"; else knew.name = "Capture Channel Map"; knew.device = pcm->device; knew.count = pcm->streams[stream].substream_count; knew.private_value = private_value; info->kctl = snd_ctl_new1(&knew, info); if (!info->kctl) { kfree(info); return -ENOMEM; } info->kctl->private_free = pcm_chmap_ctl_private_free; err = snd_ctl_add(pcm->card, info->kctl); if (err < 0) return err; pcm->streams[stream].chmap_kctl = info->kctl; if (info_ret) *info_ret = info; return 0; } EXPORT_SYMBOL_GPL(snd_pcm_add_chmap_ctls);
linux-master
sound/core/pcm_lib.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * 32bit -> 64bit ioctl wrapper for PCM API * Copyright (c) by Takashi Iwai <[email protected]> */ /* This file included from pcm_native.c */ #include <linux/compat.h> #include <linux/slab.h> static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream, s32 __user *src) { snd_pcm_sframes_t delay; int err; err = snd_pcm_delay(substream, &delay); if (err) return err; if (put_user(delay, src)) return -EFAULT; return 0; } static int snd_pcm_ioctl_rewind_compat(struct snd_pcm_substream *substream, u32 __user *src) { snd_pcm_uframes_t frames; int err; if (get_user(frames, src)) return -EFAULT; err = snd_pcm_rewind(substream, frames); if (put_user(err, src)) return -EFAULT; return err < 0 ? err : 0; } static int snd_pcm_ioctl_forward_compat(struct snd_pcm_substream *substream, u32 __user *src) { snd_pcm_uframes_t frames; int err; if (get_user(frames, src)) return -EFAULT; err = snd_pcm_forward(substream, frames); if (put_user(err, src)) return -EFAULT; return err < 0 ? err : 0; } struct snd_pcm_hw_params32 { u32 flags; struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; /* this must be identical */ struct snd_mask mres[5]; /* reserved masks */ struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1]; struct snd_interval ires[9]; /* reserved intervals */ u32 rmask; u32 cmask; u32 info; u32 msbits; u32 rate_num; u32 rate_den; u32 fifo_size; unsigned char reserved[64]; }; struct snd_pcm_sw_params32 { s32 tstamp_mode; u32 period_step; u32 sleep_min; u32 avail_min; u32 xfer_align; u32 start_threshold; u32 stop_threshold; u32 silence_threshold; u32 silence_size; u32 boundary; u32 proto; u32 tstamp_type; unsigned char reserved[56]; }; static int snd_pcm_ioctl_sw_params_compat(struct snd_pcm_substream *substream, struct snd_pcm_sw_params32 __user *src) { struct snd_pcm_sw_params params; snd_pcm_uframes_t boundary; int err; memset(&params, 0, sizeof(params)); if (get_user(params.tstamp_mode, &src->tstamp_mode) || get_user(params.period_step, &src->period_step) || get_user(params.sleep_min, &src->sleep_min) || get_user(params.avail_min, &src->avail_min) || get_user(params.xfer_align, &src->xfer_align) || get_user(params.start_threshold, &src->start_threshold) || get_user(params.stop_threshold, &src->stop_threshold) || get_user(params.silence_threshold, &src->silence_threshold) || get_user(params.silence_size, &src->silence_size) || get_user(params.tstamp_type, &src->tstamp_type) || get_user(params.proto, &src->proto)) return -EFAULT; /* * Check silent_size parameter. Since we have 64bit boundary, * silence_size must be compared with the 32bit boundary. */ boundary = recalculate_boundary(substream->runtime); if (boundary && params.silence_size >= boundary) params.silence_size = substream->runtime->boundary; err = snd_pcm_sw_params(substream, &params); if (err < 0) return err; if (boundary && put_user(boundary, &src->boundary)) return -EFAULT; return err; } struct snd_pcm_channel_info32 { u32 channel; u32 offset; u32 first; u32 step; }; static int snd_pcm_ioctl_channel_info_compat(struct snd_pcm_substream *substream, struct snd_pcm_channel_info32 __user *src) { struct snd_pcm_channel_info info; int err; if (get_user(info.channel, &src->channel) || get_user(info.offset, &src->offset) || get_user(info.first, &src->first) || get_user(info.step, &src->step)) return -EFAULT; err = snd_pcm_channel_info(substream, &info); if (err < 0) return err; if (put_user(info.channel, &src->channel) || put_user(info.offset, &src->offset) || put_user(info.first, &src->first) || put_user(info.step, &src->step)) return -EFAULT; return err; } #ifdef CONFIG_X86_X32_ABI /* X32 ABI has the same struct as x86-64 for snd_pcm_channel_info */ static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, struct snd_pcm_channel_info __user *src); #define snd_pcm_ioctl_channel_info_x32(s, p) \ snd_pcm_channel_info_user(s, p) #endif /* CONFIG_X86_X32_ABI */ struct compat_snd_pcm_status64 { snd_pcm_state_t state; u8 rsvd[4]; /* alignment */ s64 trigger_tstamp_sec; s64 trigger_tstamp_nsec; s64 tstamp_sec; s64 tstamp_nsec; u32 appl_ptr; u32 hw_ptr; s32 delay; u32 avail; u32 avail_max; u32 overrange; snd_pcm_state_t suspended_state; u32 audio_tstamp_data; s64 audio_tstamp_sec; s64 audio_tstamp_nsec; s64 driver_tstamp_sec; s64 driver_tstamp_nsec; u32 audio_tstamp_accuracy; unsigned char reserved[52-4*sizeof(s64)]; } __packed; static int snd_pcm_status_user_compat64(struct snd_pcm_substream *substream, struct compat_snd_pcm_status64 __user *src, bool ext) { struct snd_pcm_status64 status; struct compat_snd_pcm_status64 compat_status64; int err; memset(&status, 0, sizeof(status)); memset(&compat_status64, 0, sizeof(compat_status64)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, * ignore rest of status structure */ if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&src->audio_tstamp_data))) return -EFAULT; err = snd_pcm_status64(substream, &status); if (err < 0) return err; if (clear_user(src, sizeof(*src))) return -EFAULT; compat_status64 = (struct compat_snd_pcm_status64) { .state = status.state, .trigger_tstamp_sec = status.trigger_tstamp_sec, .trigger_tstamp_nsec = status.trigger_tstamp_nsec, .tstamp_sec = status.tstamp_sec, .tstamp_nsec = status.tstamp_nsec, .appl_ptr = status.appl_ptr, .hw_ptr = status.hw_ptr, .delay = status.delay, .avail = status.avail, .avail_max = status.avail_max, .overrange = status.overrange, .suspended_state = status.suspended_state, .audio_tstamp_data = status.audio_tstamp_data, .audio_tstamp_sec = status.audio_tstamp_sec, .audio_tstamp_nsec = status.audio_tstamp_nsec, .driver_tstamp_sec = status.audio_tstamp_sec, .driver_tstamp_nsec = status.audio_tstamp_nsec, .audio_tstamp_accuracy = status.audio_tstamp_accuracy, }; if (copy_to_user(src, &compat_status64, sizeof(compat_status64))) return -EFAULT; return err; } /* both for HW_PARAMS and HW_REFINE */ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream, int refine, struct snd_pcm_hw_params32 __user *data32) { struct snd_pcm_hw_params *data; struct snd_pcm_runtime *runtime; int err; runtime = substream->runtime; if (!runtime) return -ENOTTY; data = kmalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; /* only fifo_size (RO from userspace) is different, so just copy all */ if (copy_from_user(data, data32, sizeof(*data32))) { err = -EFAULT; goto error; } if (refine) { err = snd_pcm_hw_refine(substream, data); if (err < 0) goto error; err = fixup_unreferenced_params(substream, data); } else { err = snd_pcm_hw_params(substream, data); } if (err < 0) goto error; if (copy_to_user(data32, data, sizeof(*data32)) || put_user(data->fifo_size, &data32->fifo_size)) { err = -EFAULT; goto error; } if (! refine) { unsigned int new_boundary = recalculate_boundary(runtime); if (new_boundary) runtime->boundary = new_boundary; } error: kfree(data); return err; } /* */ struct snd_xferi32 { s32 result; u32 buf; u32 frames; }; static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream, int dir, struct snd_xferi32 __user *data32) { compat_caddr_t buf; u32 frames; int err; if (! substream->runtime) return -ENOTTY; if (substream->stream != dir) return -EINVAL; if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (get_user(buf, &data32->buf) || get_user(frames, &data32->frames)) return -EFAULT; if (dir == SNDRV_PCM_STREAM_PLAYBACK) err = snd_pcm_lib_write(substream, compat_ptr(buf), frames); else err = snd_pcm_lib_read(substream, compat_ptr(buf), frames); if (err < 0) return err; /* copy the result */ if (put_user(err, &data32->result)) return -EFAULT; return 0; } /* snd_xfern needs remapping of bufs */ struct snd_xfern32 { s32 result; u32 bufs; /* this is void **; */ u32 frames; }; /* * xfern ioctl nees to copy (up to) 128 pointers on stack. * although we may pass the copied pointers through f_op->ioctl, but the ioctl * handler there expands again the same 128 pointers on stack, so it is better * to handle the function (calling pcm_readv/writev) directly in this handler. */ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream, int dir, struct snd_xfern32 __user *data32) { compat_caddr_t buf; compat_caddr_t __user *bufptr; u32 frames; void __user **bufs; int err, ch, i; if (! substream->runtime) return -ENOTTY; if (substream->stream != dir) return -EINVAL; if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; ch = substream->runtime->channels; if (ch > 128) return -EINVAL; if (get_user(buf, &data32->bufs) || get_user(frames, &data32->frames)) return -EFAULT; bufptr = compat_ptr(buf); bufs = kmalloc_array(ch, sizeof(void __user *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; for (i = 0; i < ch; i++) { u32 ptr; if (get_user(ptr, bufptr)) { kfree(bufs); return -EFAULT; } bufs[i] = compat_ptr(ptr); bufptr++; } if (dir == SNDRV_PCM_STREAM_PLAYBACK) err = snd_pcm_lib_writev(substream, bufs, frames); else err = snd_pcm_lib_readv(substream, bufs, frames); if (err >= 0) { if (put_user(err, &data32->result)) err = -EFAULT; } kfree(bufs); return err; } #ifdef CONFIG_X86_X32_ABI /* X32 ABI has 64bit timespec and 64bit alignment */ struct snd_pcm_mmap_status_x32 { snd_pcm_state_t state; s32 pad1; u32 hw_ptr; u32 pad2; /* alignment */ s64 tstamp_sec; s64 tstamp_nsec; snd_pcm_state_t suspended_state; s32 pad3; s64 audio_tstamp_sec; s64 audio_tstamp_nsec; } __packed; struct snd_pcm_mmap_control_x32 { u32 appl_ptr; u32 avail_min; }; struct snd_pcm_sync_ptr_x32 { u32 flags; u32 rsvd; /* alignment */ union { struct snd_pcm_mmap_status_x32 status; unsigned char reserved[64]; } s; union { struct snd_pcm_mmap_control_x32 control; unsigned char reserved[64]; } c; } __packed; static int snd_pcm_ioctl_sync_ptr_x32(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr_x32 __user *src) { struct snd_pcm_runtime *runtime = substream->runtime; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; u32 sflags; struct snd_pcm_mmap_control scontrol; struct snd_pcm_mmap_status sstatus; snd_pcm_uframes_t boundary; int err; if (snd_BUG_ON(!runtime)) return -EINVAL; if (get_user(sflags, &src->flags) || get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || get_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } status = runtime->status; control = runtime->control; boundary = recalculate_boundary(runtime); if (!boundary) boundary = 0x7fffffff; snd_pcm_stream_lock_irq(substream); /* FIXME: we should consider the boundary for the sync from app */ if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) control->appl_ptr = scontrol.appl_ptr; else scontrol.appl_ptr = control->appl_ptr % boundary; if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = scontrol.avail_min; else scontrol.avail_min = control->avail_min; sstatus.state = status->state; sstatus.hw_ptr = status->hw_ptr % boundary; sstatus.tstamp = status->tstamp; sstatus.suspended_state = status->suspended_state; sstatus.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) || put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) || put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; return 0; } #endif /* CONFIG_X86_X32_ABI */ #ifdef __BIG_ENDIAN typedef char __pad_before_u32[4]; typedef char __pad_after_u32[0]; #else typedef char __pad_before_u32[0]; typedef char __pad_after_u32[4]; #endif /* PCM 2.0.15 API definition had a bug in mmap control; it puts the avail_min * at the wrong offset due to a typo in padding type. * The bug hits only 32bit. * A workaround for incorrect read/write is needed only in 32bit compat mode. */ struct __snd_pcm_mmap_control64_buggy { __pad_before_u32 __pad1; __u32 appl_ptr; __pad_before_u32 __pad2; /* SiC! here is the bug */ __pad_before_u32 __pad3; __u32 avail_min; __pad_after_uframe __pad4; }; static int snd_pcm_ioctl_sync_ptr_buggy(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr __user *_sync_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_sync_ptr sync_ptr; struct __snd_pcm_mmap_control64_buggy *sync_cp; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; int err; memset(&sync_ptr, 0, sizeof(sync_ptr)); sync_cp = (struct __snd_pcm_mmap_control64_buggy *)&sync_ptr.c.control; if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) return -EFAULT; if (copy_from_user(sync_cp, &(_sync_ptr->c.control), sizeof(*sync_cp))) return -EFAULT; status = runtime->status; control = runtime->control; if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } snd_pcm_stream_lock_irq(substream); if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, sync_cp->appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else { sync_cp->appl_ptr = control->appl_ptr; } if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = sync_cp->avail_min; else sync_cp->avail_min = control->avail_min; sync_ptr.s.status.state = status->state; sync_ptr.s.status.hw_ptr = status->hw_ptr; sync_ptr.s.status.tstamp = status->tstamp; sync_ptr.s.status.suspended_state = status->suspended_state; sync_ptr.s.status.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; return 0; } /* */ enum { SNDRV_PCM_IOCTL_HW_REFINE32 = _IOWR('A', 0x10, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_HW_PARAMS32 = _IOWR('A', 0x11, struct snd_pcm_hw_params32), SNDRV_PCM_IOCTL_SW_PARAMS32 = _IOWR('A', 0x13, struct snd_pcm_sw_params32), SNDRV_PCM_IOCTL_STATUS_COMPAT32 = _IOR('A', 0x20, struct snd_pcm_status32), SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32 = _IOWR('A', 0x24, struct snd_pcm_status32), SNDRV_PCM_IOCTL_DELAY32 = _IOR('A', 0x21, s32), SNDRV_PCM_IOCTL_CHANNEL_INFO32 = _IOR('A', 0x32, struct snd_pcm_channel_info32), SNDRV_PCM_IOCTL_REWIND32 = _IOW('A', 0x46, u32), SNDRV_PCM_IOCTL_FORWARD32 = _IOW('A', 0x49, u32), SNDRV_PCM_IOCTL_WRITEI_FRAMES32 = _IOW('A', 0x50, struct snd_xferi32), SNDRV_PCM_IOCTL_READI_FRAMES32 = _IOR('A', 0x51, struct snd_xferi32), SNDRV_PCM_IOCTL_WRITEN_FRAMES32 = _IOW('A', 0x52, struct snd_xfern32), SNDRV_PCM_IOCTL_READN_FRAMES32 = _IOR('A', 0x53, struct snd_xfern32), SNDRV_PCM_IOCTL_STATUS_COMPAT64 = _IOR('A', 0x20, struct compat_snd_pcm_status64), SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64 = _IOWR('A', 0x24, struct compat_snd_pcm_status64), #ifdef CONFIG_X86_X32_ABI SNDRV_PCM_IOCTL_CHANNEL_INFO_X32 = _IOR('A', 0x32, struct snd_pcm_channel_info), SNDRV_PCM_IOCTL_SYNC_PTR_X32 = _IOWR('A', 0x23, struct snd_pcm_sync_ptr_x32), #endif /* CONFIG_X86_X32_ABI */ }; static long snd_pcm_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; void __user *argp = compat_ptr(arg); pcm_file = file->private_data; if (! pcm_file) return -ENOTTY; substream = pcm_file->substream; if (! substream) return -ENOTTY; /* * When PCM is used on 32bit mode, we need to disable * mmap of the old PCM status/control records because * of the size incompatibility. */ pcm_file->no_compat_mmap = 1; switch (cmd) { case SNDRV_PCM_IOCTL_PVERSION: case SNDRV_PCM_IOCTL_INFO: case SNDRV_PCM_IOCTL_TSTAMP: case SNDRV_PCM_IOCTL_TTSTAMP: case SNDRV_PCM_IOCTL_USER_PVERSION: case SNDRV_PCM_IOCTL_HWSYNC: case SNDRV_PCM_IOCTL_PREPARE: case SNDRV_PCM_IOCTL_RESET: case SNDRV_PCM_IOCTL_START: case SNDRV_PCM_IOCTL_DROP: case SNDRV_PCM_IOCTL_DRAIN: case SNDRV_PCM_IOCTL_PAUSE: case SNDRV_PCM_IOCTL_HW_FREE: case SNDRV_PCM_IOCTL_RESUME: case SNDRV_PCM_IOCTL_XRUN: case SNDRV_PCM_IOCTL_LINK: case SNDRV_PCM_IOCTL_UNLINK: case __SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_common_ioctl(file, substream, cmd, argp); case __SNDRV_PCM_IOCTL_SYNC_PTR64: #ifdef CONFIG_X86_X32_ABI if (in_x32_syscall()) return snd_pcm_ioctl_sync_ptr_x32(substream, argp); #endif /* CONFIG_X86_X32_ABI */ return snd_pcm_ioctl_sync_ptr_buggy(substream, argp); case SNDRV_PCM_IOCTL_HW_REFINE32: return snd_pcm_ioctl_hw_params_compat(substream, 1, argp); case SNDRV_PCM_IOCTL_HW_PARAMS32: return snd_pcm_ioctl_hw_params_compat(substream, 0, argp); case SNDRV_PCM_IOCTL_SW_PARAMS32: return snd_pcm_ioctl_sw_params_compat(substream, argp); case SNDRV_PCM_IOCTL_STATUS_COMPAT32: return snd_pcm_status_user32(substream, argp, false); case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT32: return snd_pcm_status_user32(substream, argp, true); case SNDRV_PCM_IOCTL_CHANNEL_INFO32: return snd_pcm_ioctl_channel_info_compat(substream, argp); case SNDRV_PCM_IOCTL_WRITEI_FRAMES32: return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp); case SNDRV_PCM_IOCTL_READI_FRAMES32: return snd_pcm_ioctl_xferi_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp); case SNDRV_PCM_IOCTL_WRITEN_FRAMES32: return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_PLAYBACK, argp); case SNDRV_PCM_IOCTL_READN_FRAMES32: return snd_pcm_ioctl_xfern_compat(substream, SNDRV_PCM_STREAM_CAPTURE, argp); case SNDRV_PCM_IOCTL_DELAY32: return snd_pcm_ioctl_delay_compat(substream, argp); case SNDRV_PCM_IOCTL_REWIND32: return snd_pcm_ioctl_rewind_compat(substream, argp); case SNDRV_PCM_IOCTL_FORWARD32: return snd_pcm_ioctl_forward_compat(substream, argp); case SNDRV_PCM_IOCTL_STATUS_COMPAT64: return snd_pcm_status_user_compat64(substream, argp, false); case SNDRV_PCM_IOCTL_STATUS_EXT_COMPAT64: return snd_pcm_status_user_compat64(substream, argp, true); #ifdef CONFIG_X86_X32_ABI case SNDRV_PCM_IOCTL_CHANNEL_INFO_X32: return snd_pcm_ioctl_channel_info_x32(substream, argp); #endif /* CONFIG_X86_X32_ABI */ } return -ENOIOCTLCMD; }
linux-master
sound/core/pcm_compat.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * Information interface for ALSA driver * Copyright (c) by Jaroslav Kysela <[email protected]> */ #include <linux/slab.h> #include <linux/time.h> #include <linux/string.h> #include <linux/export.h> #include <sound/core.h> #include <sound/minors.h> #include <sound/info.h> #include <linux/utsname.h> #include <linux/mutex.h> /* * OSS compatible part */ static DEFINE_MUTEX(strings); static char *snd_sndstat_strings[SNDRV_CARDS][SNDRV_OSS_INFO_DEV_COUNT]; int snd_oss_info_register(int dev, int num, char *string) { char *x; if (snd_BUG_ON(dev < 0 || dev >= SNDRV_OSS_INFO_DEV_COUNT)) return -ENXIO; if (snd_BUG_ON(num < 0 || num >= SNDRV_CARDS)) return -ENXIO; mutex_lock(&strings); if (string == NULL) { x = snd_sndstat_strings[num][dev]; kfree(x); x = NULL; } else { x = kstrdup(string, GFP_KERNEL); if (x == NULL) { mutex_unlock(&strings); return -ENOMEM; } } snd_sndstat_strings[num][dev] = x; mutex_unlock(&strings); return 0; } EXPORT_SYMBOL(snd_oss_info_register); static int snd_sndstat_show_strings(struct snd_info_buffer *buf, char *id, int dev) { int idx, ok = -1; char *str; snd_iprintf(buf, "\n%s:", id); mutex_lock(&strings); for (idx = 0; idx < SNDRV_CARDS; idx++) { str = snd_sndstat_strings[idx][dev]; if (str) { if (ok < 0) { snd_iprintf(buf, "\n"); ok++; } snd_iprintf(buf, "%i: %s\n", idx, str); } } mutex_unlock(&strings); if (ok < 0) snd_iprintf(buf, " NOT ENABLED IN CONFIG\n"); return ok; } static void snd_sndstat_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA emulation code)\n"); snd_iprintf(buffer, "Kernel: %s %s %s %s %s\n", init_utsname()->sysname, init_utsname()->nodename, init_utsname()->release, init_utsname()->version, init_utsname()->machine); snd_iprintf(buffer, "Config options: 0\n"); snd_iprintf(buffer, "\nInstalled drivers: \n"); snd_iprintf(buffer, "Type 10: ALSA emulation\n"); snd_iprintf(buffer, "\nCard config: \n"); snd_card_info_read_oss(buffer); snd_sndstat_show_strings(buffer, "Audio devices", SNDRV_OSS_INFO_DEV_AUDIO); snd_sndstat_show_strings(buffer, "Synth devices", SNDRV_OSS_INFO_DEV_SYNTH); snd_sndstat_show_strings(buffer, "Midi devices", SNDRV_OSS_INFO_DEV_MIDI); snd_sndstat_show_strings(buffer, "Timers", SNDRV_OSS_INFO_DEV_TIMERS); snd_sndstat_show_strings(buffer, "Mixers", SNDRV_OSS_INFO_DEV_MIXERS); } int __init snd_info_minor_register(void) { struct snd_info_entry *entry; memset(snd_sndstat_strings, 0, sizeof(snd_sndstat_strings)); entry = snd_info_create_module_entry(THIS_MODULE, "sndstat", snd_oss_root); if (!entry) return -ENOMEM; entry->c.text.read = snd_sndstat_proc_read; return snd_info_register(entry); /* freed in error path */ }
linux-master
sound/core/info_oss.c
// SPDX-License-Identifier: GPL-2.0-or-later /* * ISA DMA support functions * Copyright (c) by Jaroslav Kysela <[email protected]> */ /* * Defining following add some delay. Maybe this helps for some broken * ISA DMA controllers. */ #undef HAVE_REALLY_SLOW_DMA_CONTROLLER #include <linux/export.h> #include <linux/isa-dma.h> #include <sound/core.h> /** * snd_dma_program - program an ISA DMA transfer * @dma: the dma number * @addr: the physical address of the buffer * @size: the DMA transfer size * @mode: the DMA transfer mode, DMA_MODE_XXX * * Programs an ISA DMA transfer for the given buffer. */ void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode) { unsigned long flags; flags = claim_dma_lock(); disable_dma(dma); clear_dma_ff(dma); set_dma_mode(dma, mode); set_dma_addr(dma, addr); set_dma_count(dma, size); if (!(mode & DMA_MODE_NO_ENABLE)) enable_dma(dma); release_dma_lock(flags); } EXPORT_SYMBOL(snd_dma_program); /** * snd_dma_disable - stop the ISA DMA transfer * @dma: the dma number * * Stops the ISA DMA transfer. */ void snd_dma_disable(unsigned long dma) { unsigned long flags; flags = claim_dma_lock(); clear_dma_ff(dma); disable_dma(dma); release_dma_lock(flags); } EXPORT_SYMBOL(snd_dma_disable); /** * snd_dma_pointer - return the current pointer to DMA transfer buffer in bytes * @dma: the dma number * @size: the dma transfer size * * Return: The current pointer in DMA transfer buffer in bytes. */ unsigned int snd_dma_pointer(unsigned long dma, unsigned int size) { unsigned long flags; unsigned int result, result1; flags = claim_dma_lock(); clear_dma_ff(dma); if (!isa_dma_bridge_buggy) disable_dma(dma); result = get_dma_residue(dma); /* * HACK - read the counter again and choose higher value in order to * avoid reading during counter lower byte roll over if the * isa_dma_bridge_buggy is set. */ result1 = get_dma_residue(dma); if (!isa_dma_bridge_buggy) enable_dma(dma); release_dma_lock(flags); if (unlikely(result < result1)) result = result1; #ifdef CONFIG_SND_DEBUG if (result > size) pr_err("ALSA: pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size); #endif if (result >= size || result == 0) return 0; else return size - result; } EXPORT_SYMBOL(snd_dma_pointer); struct snd_dma_data { int dma; }; static void __snd_release_dma(struct device *dev, void *data) { struct snd_dma_data *p = data; snd_dma_disable(p->dma); free_dma(p->dma); } /** * snd_devm_request_dma - the managed version of request_dma() * @dev: the device pointer * @dma: the dma number * @name: the name string of the requester * * The requested DMA will be automatically released at unbinding via devres. * * Return: zero on success, or a negative error code */ int snd_devm_request_dma(struct device *dev, int dma, const char *name) { struct snd_dma_data *p; if (request_dma(dma, name)) return -EBUSY; p = devres_alloc(__snd_release_dma, sizeof(*p), GFP_KERNEL); if (!p) { free_dma(dma); return -ENOMEM; } p->dma = dma; devres_add(dev, p); return 0; } EXPORT_SYMBOL_GPL(snd_devm_request_dma);
linux-master
sound/core/isadma.c