X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fymfpci%2Fymfpci_main.c;h=7881944a19576d56345d3440fb40ff26863bd3e3;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=1449d685bc76ba46e018f75e00235eaa8a11c017;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c index 1449d685b..7881944a1 100644 --- a/sound/pci/ymfpci/ymfpci_main.c +++ b/sound/pci/ymfpci/ymfpci_main.c @@ -36,14 +36,13 @@ #include #include #include +#include #include #include #include #include -#define chip_t ymfpci_t - /* * constants */ @@ -52,57 +51,57 @@ * common I/O routines */ -static void snd_ymfpci_irq_wait(ymfpci_t *chip); +static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip); -static inline u8 snd_ymfpci_readb(ymfpci_t *chip, u32 offset) +static inline u8 snd_ymfpci_readb(struct snd_ymfpci *chip, u32 offset) { return readb(chip->reg_area_virt + offset); } -static inline void snd_ymfpci_writeb(ymfpci_t *chip, u32 offset, u8 val) +static inline void snd_ymfpci_writeb(struct snd_ymfpci *chip, u32 offset, u8 val) { writeb(val, chip->reg_area_virt + offset); } -static inline u16 snd_ymfpci_readw(ymfpci_t *chip, u32 offset) +static inline u16 snd_ymfpci_readw(struct snd_ymfpci *chip, u32 offset) { return readw(chip->reg_area_virt + offset); } -static inline void snd_ymfpci_writew(ymfpci_t *chip, u32 offset, u16 val) +static inline void snd_ymfpci_writew(struct snd_ymfpci *chip, u32 offset, u16 val) { writew(val, chip->reg_area_virt + offset); } -static inline u32 snd_ymfpci_readl(ymfpci_t *chip, u32 offset) +static inline u32 snd_ymfpci_readl(struct snd_ymfpci *chip, u32 offset) { return readl(chip->reg_area_virt + offset); } -static inline void snd_ymfpci_writel(ymfpci_t *chip, u32 offset, u32 val) +static inline void snd_ymfpci_writel(struct snd_ymfpci *chip, u32 offset, u32 val) { writel(val, chip->reg_area_virt + offset); } -static int snd_ymfpci_codec_ready(ymfpci_t *chip, int secondary) +static int snd_ymfpci_codec_ready(struct snd_ymfpci *chip, int secondary) { - signed long end_time; + unsigned long end_time; u32 reg = secondary ? YDSXGR_SECSTATUSADR : YDSXGR_PRISTATUSADR; - end_time = (jiffies + ((3 * HZ) / 4)) + 1; + end_time = jiffies + msecs_to_jiffies(750); do { if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) return 0; set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(1); - } while (end_time - (signed long)jiffies >= 0); - snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); + schedule_timeout_uninterruptible(1); + } while (time_before(jiffies, end_time)); + snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); return -EBUSY; } -static void snd_ymfpci_codec_write(ac97_t *ac97, u16 reg, u16 val) +static void snd_ymfpci_codec_write(struct snd_ac97 *ac97, u16 reg, u16 val) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, ac97->private_data, return); + struct snd_ymfpci *chip = ac97->private_data; u32 cmd; snd_ymfpci_codec_ready(chip, 0); @@ -110,9 +109,9 @@ static void snd_ymfpci_codec_write(ac97_t *ac97, u16 reg, u16 val) snd_ymfpci_writel(chip, YDSXGR_AC97CMDDATA, cmd); } -static u16 snd_ymfpci_codec_read(ac97_t *ac97, u16 reg) +static u16 snd_ymfpci_codec_read(struct snd_ac97 *ac97, u16 reg) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, ac97->private_data, return -ENXIO); + struct snd_ymfpci *chip = ac97->private_data; if (snd_ymfpci_codec_ready(chip, 0)) return ~0; @@ -184,7 +183,7 @@ static u32 snd_ymfpci_calc_lpfQ(u32 rate) * Hardware start management */ -static void snd_ymfpci_hw_start(ymfpci_t *chip) +static void snd_ymfpci_hw_start(struct snd_ymfpci *chip) { unsigned long flags; @@ -198,7 +197,7 @@ static void snd_ymfpci_hw_start(ymfpci_t *chip) spin_unlock_irqrestore(&chip->reg_lock, flags); } -static void snd_ymfpci_hw_stop(ymfpci_t *chip) +static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip) { unsigned long flags; long timeout = 1000; @@ -224,9 +223,11 @@ static void snd_ymfpci_hw_stop(ymfpci_t *chip) * Playback voice management */ -static int voice_alloc(ymfpci_t *chip, ymfpci_voice_type_t type, int pair, ymfpci_voice_t **rvoice) +static int voice_alloc(struct snd_ymfpci *chip, + enum snd_ymfpci_voice_type type, int pair, + struct snd_ymfpci_voice **rvoice) { - ymfpci_voice_t *voice, *voice2; + struct snd_ymfpci_voice *voice, *voice2; int idx; *rvoice = NULL; @@ -260,7 +261,9 @@ static int voice_alloc(ymfpci_t *chip, ymfpci_voice_type_t type, int pair, ymfpc return -ENOMEM; } -int snd_ymfpci_voice_alloc(ymfpci_t *chip, ymfpci_voice_type_t type, int pair, ymfpci_voice_t **rvoice) +static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip, + enum snd_ymfpci_voice_type type, int pair, + struct snd_ymfpci_voice **rvoice) { unsigned long flags; int result; @@ -280,7 +283,7 @@ int snd_ymfpci_voice_alloc(ymfpci_t *chip, ymfpci_voice_type_t type, int pair, y return result; } -int snd_ymfpci_voice_free(ymfpci_t *chip, ymfpci_voice_t *pvoice) +static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voice *pvoice) { unsigned long flags; @@ -298,9 +301,9 @@ int snd_ymfpci_voice_free(ymfpci_t *chip, ymfpci_voice_t *pvoice) * PCM part */ -static void snd_ymfpci_pcm_interrupt(ymfpci_t *chip, ymfpci_voice_t *voice) +static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_voice *voice) { - ymfpci_pcm_t *ypcm; + struct snd_ymfpci_pcm *ypcm; u32 pos, delta; if ((ypcm = voice->ypcm) == NULL) @@ -323,15 +326,35 @@ static void snd_ymfpci_pcm_interrupt(ymfpci_t *chip, ymfpci_voice_t *voice) snd_pcm_period_elapsed(ypcm->substream); spin_lock(&chip->reg_lock); } + + if (unlikely(ypcm->update_pcm_vol)) { + unsigned int subs = ypcm->substream->number; + unsigned int next_bank = 1 - chip->active_bank; + struct snd_ymfpci_playback_bank *bank; + u32 volume; + + bank = &voice->bank[next_bank]; + volume = cpu_to_le32(chip->pcm_mixer[subs].left << 15); + bank->left_gain_end = volume; + if (ypcm->output_rear) + bank->eff2_gain_end = volume; + if (ypcm->voices[1]) + bank = &ypcm->voices[1]->bank[next_bank]; + volume = cpu_to_le32(chip->pcm_mixer[subs].right << 15); + bank->right_gain_end = volume; + if (ypcm->output_rear) + bank->eff3_gain_end = volume; + ypcm->update_pcm_vol--; + } } spin_unlock(&chip->reg_lock); } -static void snd_ymfpci_pcm_capture_interrupt(snd_pcm_substream_t *substream) +static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream) { - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return); - ymfpci_t *chip = ypcm->chip; + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; + struct snd_ymfpci *chip = ypcm->chip; u32 pos, delta; spin_lock(&chip->reg_lock); @@ -354,11 +377,11 @@ static void snd_ymfpci_pcm_capture_interrupt(snd_pcm_substream_t *substream) spin_unlock(&chip->reg_lock); } -static int snd_ymfpci_playback_trigger(snd_pcm_substream_t * substream, +static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream, int cmd) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, substream->runtime->private_data, return -ENXIO); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; int result = 0; spin_lock(&chip->reg_lock); @@ -391,11 +414,11 @@ static int snd_ymfpci_playback_trigger(snd_pcm_substream_t * substream, spin_unlock(&chip->reg_lock); return result; } -static int snd_ymfpci_capture_trigger(snd_pcm_substream_t * substream, +static int snd_ymfpci_capture_trigger(struct snd_pcm_substream *substream, int cmd) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, substream->runtime->private_data, return -ENXIO); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; int result = 0; u32 tmp; @@ -423,7 +446,7 @@ static int snd_ymfpci_capture_trigger(snd_pcm_substream_t * substream, return result; } -static int snd_ymfpci_pcm_voice_alloc(ymfpci_pcm_t *ypcm, int voices) +static int snd_ymfpci_pcm_voice_alloc(struct snd_ymfpci_pcm *ypcm, int voices) { int err; @@ -453,95 +476,98 @@ static int snd_ymfpci_pcm_voice_alloc(ymfpci_pcm_t *ypcm, int voices) return 0; } -static void snd_ymfpci_pcm_init_voice(ymfpci_voice_t *voice, int stereo, - int rate, int w_16, unsigned long addr, - unsigned int end, - int output_front, int output_rear) +static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm *ypcm, unsigned int voiceidx, + struct snd_pcm_runtime *runtime, + int has_pcm_volume) { + struct snd_ymfpci_voice *voice = ypcm->voices[voiceidx]; u32 format; - u32 delta = snd_ymfpci_calc_delta(rate); - u32 lpfQ = snd_ymfpci_calc_lpfQ(rate); - u32 lpfK = snd_ymfpci_calc_lpfK(rate); - snd_ymfpci_playback_bank_t *bank; + u32 delta = snd_ymfpci_calc_delta(runtime->rate); + u32 lpfQ = snd_ymfpci_calc_lpfQ(runtime->rate); + u32 lpfK = snd_ymfpci_calc_lpfK(runtime->rate); + struct snd_ymfpci_playback_bank *bank; unsigned int nbank; + u32 vol_left, vol_right; + u8 use_left, use_right; snd_assert(voice != NULL, return); - format = (stereo ? 0x00010000 : 0) | (w_16 ? 0 : 0x80000000); + if (runtime->channels == 1) { + use_left = 1; + use_right = 1; + } else { + use_left = (voiceidx & 1) == 0; + use_right = !use_left; + } + if (has_pcm_volume) { + vol_left = cpu_to_le32(ypcm->chip->pcm_mixer + [ypcm->substream->number].left << 15); + vol_right = cpu_to_le32(ypcm->chip->pcm_mixer + [ypcm->substream->number].right << 15); + } else { + vol_left = cpu_to_le32(0x40000000); + vol_right = cpu_to_le32(0x40000000); + } + format = runtime->channels == 2 ? 0x00010000 : 0; + if (snd_pcm_format_width(runtime->format) == 8) + format |= 0x80000000; + if (runtime->channels == 2 && (voiceidx & 1) != 0) + format |= 1; for (nbank = 0; nbank < 2; nbank++) { bank = &voice->bank[nbank]; + memset(bank, 0, sizeof(*bank)); bank->format = cpu_to_le32(format); - bank->loop_default = 0; - bank->base = cpu_to_le32(addr); - bank->loop_start = 0; - bank->loop_end = cpu_to_le32(end); - bank->loop_frac = 0; - bank->eg_gain_end = cpu_to_le32(0x40000000); + bank->base = cpu_to_le32(runtime->dma_addr); + bank->loop_end = cpu_to_le32(ypcm->buffer_size); bank->lpfQ = cpu_to_le32(lpfQ); - bank->status = 0; - bank->num_of_frames = 0; - bank->loop_count = 0; - bank->start = 0; - bank->start_frac = 0; bank->delta = bank->delta_end = cpu_to_le32(delta); bank->lpfK = bank->lpfK_end = cpu_to_le32(lpfK); - bank->eg_gain = cpu_to_le32(0x40000000); - bank->lpfD1 = - bank->lpfD2 = 0; - - bank->left_gain = - bank->right_gain = - bank->left_gain_end = - bank->right_gain_end = - bank->eff1_gain = - bank->eff2_gain = - bank->eff3_gain = - bank->eff1_gain_end = - bank->eff2_gain_end = - bank->eff3_gain_end = 0; - - if (!stereo) { - if (output_front) { - bank->left_gain = - bank->right_gain = - bank->left_gain_end = - bank->right_gain_end = cpu_to_le32(0x40000000); - } - if (output_rear) { - bank->eff2_gain = - bank->eff2_gain_end = - bank->eff3_gain = - bank->eff3_gain_end = cpu_to_le32(0x40000000); - } - } else { - if (output_front) { - if ((voice->number & 1) == 0) { - bank->left_gain = - bank->left_gain_end = cpu_to_le32(0x40000000); - } else { - bank->format |= cpu_to_le32(1); - bank->right_gain = - bank->right_gain_end = cpu_to_le32(0x40000000); - } + bank->eg_gain = + bank->eg_gain_end = cpu_to_le32(0x40000000); + + if (ypcm->output_front) { + if (use_left) { + bank->left_gain = + bank->left_gain_end = vol_left; } - if (output_rear) { - if ((voice->number & 1) == 0) { - bank->eff3_gain = - bank->eff3_gain_end = cpu_to_le32(0x40000000); - } else { - bank->format |= cpu_to_le32(1); - bank->eff2_gain = - bank->eff2_gain_end = cpu_to_le32(0x40000000); - } + if (use_right) { + bank->right_gain = + bank->right_gain_end = vol_right; } } + if (ypcm->output_rear) { + if (!ypcm->swap_rear) { + if (use_left) { + bank->eff2_gain = + bank->eff2_gain_end = vol_left; + } + if (use_right) { + bank->eff3_gain = + bank->eff3_gain_end = vol_right; + } + } else { + /* The SPDIF out channels seem to be swapped, so we have + * to swap them here, too. The rear analog out channels + * will be wrong, but otherwise AC3 would not work. + */ + if (use_left) { + bank->eff3_gain = + bank->eff3_gain_end = vol_left; + } + if (use_right) { + bank->eff2_gain = + bank->eff2_gain_end = vol_right; + } + } + } } } -static int __devinit snd_ymfpci_ac3_init(ymfpci_t *chip) +static int __devinit snd_ymfpci_ac3_init(struct snd_ymfpci *chip) { - if (snd_dma_alloc_pages(&chip->dma_dev, 4096, &chip->ac3_tmp_base) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + 4096, &chip->ac3_tmp_base) < 0) return -ENOMEM; chip->bank_effect[3][0]->base = @@ -560,7 +586,7 @@ static int __devinit snd_ymfpci_ac3_init(ymfpci_t *chip) return 0; } -static int snd_ymfpci_ac3_done(ymfpci_t *chip) +static int snd_ymfpci_ac3_done(struct snd_ymfpci *chip) { spin_lock_irq(&chip->reg_lock); snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, @@ -568,17 +594,17 @@ static int snd_ymfpci_ac3_done(ymfpci_t *chip) spin_unlock_irq(&chip->reg_lock); // snd_ymfpci_irq_wait(chip); if (chip->ac3_tmp_base.area) { - snd_dma_free_pages(&chip->dma_dev, &chip->ac3_tmp_base); + snd_dma_free_pages(&chip->ac3_tmp_base); chip->ac3_tmp_base.area = NULL; } return 0; } -static int snd_ymfpci_playback_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_ymfpci_playback_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; int err; if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) @@ -588,15 +614,15 @@ static int snd_ymfpci_playback_hw_params(snd_pcm_substream_t * substream, return 0; } -static int snd_ymfpci_playback_hw_free(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_hw_free(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; if (runtime->private_data == NULL) return 0; - ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); + ypcm = runtime->private_data; /* wait, until the PCI operations are not finished */ snd_ymfpci_irq_wait(chip); @@ -612,11 +638,11 @@ static int snd_ymfpci_playback_hw_free(snd_pcm_substream_t * substream) return 0; } -static int snd_ymfpci_playback_prepare(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_prepare(struct snd_pcm_substream *substream) { - // ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; unsigned int nvoice; ypcm->period_size = runtime->period_size; @@ -624,38 +650,32 @@ static int snd_ymfpci_playback_prepare(snd_pcm_substream_t * substream) ypcm->period_pos = 0; ypcm->last_pos = 0; for (nvoice = 0; nvoice < runtime->channels; nvoice++) - snd_ymfpci_pcm_init_voice(ypcm->voices[nvoice], - runtime->channels == 2, - runtime->rate, - snd_pcm_format_width(runtime->format) == 16, - runtime->dma_addr, - ypcm->buffer_size, - ypcm->output_front, - ypcm->output_rear); + snd_ymfpci_pcm_init_voice(ypcm, nvoice, runtime, + substream->pcm == chip->pcm); return 0; } -static int snd_ymfpci_capture_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_ymfpci_capture_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); } -static int snd_ymfpci_capture_hw_free(snd_pcm_substream_t * substream) +static int snd_ymfpci_capture_hw_free(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); /* wait, until the PCI operations are not finished */ snd_ymfpci_irq_wait(chip); return snd_pcm_lib_free_pages(substream); } -static int snd_ymfpci_capture_prepare(snd_pcm_substream_t * substream) +static int snd_ymfpci_capture_prepare(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); - snd_ymfpci_capture_bank_t * bank; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; + struct snd_ymfpci_capture_bank * bank; int nbank; u32 rate, format; @@ -694,30 +714,30 @@ static int snd_ymfpci_capture_prepare(snd_pcm_substream_t * substream) return 0; } -static snd_pcm_uframes_t snd_ymfpci_playback_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_ymfpci_playback_pointer(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); - ymfpci_voice_t *voice = ypcm->voices[0]; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; + struct snd_ymfpci_voice *voice = ypcm->voices[0]; if (!(ypcm->running && voice)) return 0; return le32_to_cpu(voice->bank[chip->active_bank].start); } -static snd_pcm_uframes_t snd_ymfpci_capture_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_ymfpci_capture_pointer(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; if (!ypcm->running) return 0; return le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift; } -static void snd_ymfpci_irq_wait(ymfpci_t *chip) +static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip) { wait_queue_t wait; int loops = 4; @@ -728,17 +748,16 @@ static void snd_ymfpci_irq_wait(ymfpci_t *chip) init_waitqueue_entry(&wait, current); add_wait_queue(&chip->interrupt_sleep, &wait); atomic_inc(&chip->interrupt_sleep_count); - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(HZ/20); + schedule_timeout_uninterruptible(msecs_to_jiffies(50)); remove_wait_queue(&chip->interrupt_sleep, &wait); } } -static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, dev_id, return IRQ_NONE); + struct snd_ymfpci *chip = dev_id; u32 status, nvoice, mode; - ymfpci_voice_t *voice; + struct snd_ymfpci_voice *voice; status = snd_ymfpci_readl(chip, YDSXGR_STATUS); if (status & 0x80000000) { @@ -780,11 +799,11 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id, struct pt_regs *r snd_ymfpci_writew(chip, YDSXGR_INTFLAG, status); if (chip->rawmidi) - snd_mpu401_uart_interrupt(irq, chip->rawmidi->private_data, regs); + snd_mpu401_uart_interrupt(irq, chip->rawmidi->private_data); return IRQ_HANDLED; } -static snd_pcm_hardware_t snd_ymfpci_playback = +static struct snd_pcm_hardware snd_ymfpci_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -806,7 +825,7 @@ static snd_pcm_hardware_t snd_ymfpci_playback = .fifo_size = 0, }; -static snd_pcm_hardware_t snd_ymfpci_capture = +static struct snd_pcm_hardware snd_ymfpci_capture = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -828,21 +847,18 @@ static snd_pcm_hardware_t snd_ymfpci_capture = .fifo_size = 0, }; -static void snd_ymfpci_pcm_free_substream(snd_pcm_runtime_t *runtime) +static void snd_ymfpci_pcm_free_substream(struct snd_pcm_runtime *runtime) { - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return); - - if (ypcm) - snd_magic_kfree(ypcm); + kfree(runtime->private_data); } -static int snd_ymfpci_playback_open_1(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; - ypcm = snd_magic_kcalloc(ymfpci_pcm_t, 0, GFP_KERNEL); + ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); if (ypcm == NULL) return -ENOMEM; ypcm->chip = chip; @@ -857,7 +873,7 @@ static int snd_ymfpci_playback_open_1(snd_pcm_substream_t * substream) } /* call with spinlock held */ -static void ymfpci_open_extension(ymfpci_t *chip) +static void ymfpci_open_extension(struct snd_ymfpci *chip) { if (! chip->rear_opened) { if (! chip->spdif_opened) /* set AC3 */ @@ -870,7 +886,7 @@ static void ymfpci_open_extension(ymfpci_t *chip) } /* call with spinlock held */ -static void ymfpci_close_extension(ymfpci_t *chip) +static void ymfpci_close_extension(struct snd_ymfpci *chip) { if (! chip->rear_opened) { if (! chip->spdif_opened) @@ -881,49 +897,54 @@ static void ymfpci_close_extension(ymfpci_t *chip) } } -static int snd_ymfpci_playback_open(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_open(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; + struct snd_kcontrol *kctl; int err; if ((err = snd_ymfpci_playback_open_1(substream)) < 0) return err; - ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return 0); + ypcm = runtime->private_data; ypcm->output_front = 1; ypcm->output_rear = chip->mode_dup4ch ? 1 : 0; - spin_lock_irqsave(&chip->reg_lock, flags); + ypcm->swap_rear = 0; + spin_lock_irq(&chip->reg_lock); if (ypcm->output_rear) { ymfpci_open_extension(chip); chip->rear_opened++; } - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); + + kctl = chip->pcm_mixer[substream->number].ctl; + kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; + snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); return 0; } -static int snd_ymfpci_playback_spdif_open(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_spdif_open(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; int err; if ((err = snd_ymfpci_playback_open_1(substream)) < 0) return err; - ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return 0); + ypcm = runtime->private_data; ypcm->output_front = 0; ypcm->output_rear = 1; - spin_lock_irqsave(&chip->reg_lock, flags); + ypcm->swap_rear = 1; + spin_lock_irq(&chip->reg_lock); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) | 2); ymfpci_open_extension(chip); chip->spdif_pcm_bits = chip->spdif_bits; snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); chip->spdif_opened++; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); chip->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | @@ -931,34 +952,34 @@ static int snd_ymfpci_playback_spdif_open(snd_pcm_substream_t * substream) return 0; } -static int snd_ymfpci_playback_4ch_open(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_4ch_open(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; int err; if ((err = snd_ymfpci_playback_open_1(substream)) < 0) return err; - ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return 0); + ypcm = runtime->private_data; ypcm->output_front = 0; ypcm->output_rear = 1; - spin_lock_irqsave(&chip->reg_lock, flags); + ypcm->swap_rear = 0; + spin_lock_irq(&chip->reg_lock); ymfpci_open_extension(chip); chip->rear_opened++; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return 0; } -static int snd_ymfpci_capture_open(snd_pcm_substream_t * substream, +static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream, u32 capture_bank_number) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm; - ypcm = snd_magic_kcalloc(ymfpci_pcm_t, 0, GFP_KERNEL); + ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); if (ypcm == NULL) return -ENOMEM; ypcm->chip = chip; @@ -975,73 +996,74 @@ static int snd_ymfpci_capture_open(snd_pcm_substream_t * substream, return 0; } -static int snd_ymfpci_capture_rec_open(snd_pcm_substream_t * substream) +static int snd_ymfpci_capture_rec_open(struct snd_pcm_substream *substream) { return snd_ymfpci_capture_open(substream, 0); } -static int snd_ymfpci_capture_ac97_open(snd_pcm_substream_t * substream) +static int snd_ymfpci_capture_ac97_open(struct snd_pcm_substream *substream) { return snd_ymfpci_capture_open(substream, 1); } -static int snd_ymfpci_playback_close_1(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_close_1(struct snd_pcm_substream *substream) { return 0; } -static int snd_ymfpci_playback_close(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_close(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, substream->runtime->private_data, return -ENXIO); - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; + struct snd_kcontrol *kctl; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); if (ypcm->output_rear && chip->rear_opened > 0) { chip->rear_opened--; ymfpci_close_extension(chip); } - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); + kctl = chip->pcm_mixer[substream->number].ctl; + kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; + snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); return snd_ymfpci_playback_close_1(substream); } -static int snd_ymfpci_playback_spdif_close(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_spdif_close(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); chip->spdif_opened = 0; ymfpci_close_extension(chip); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & ~2); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); chip->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id); return snd_ymfpci_playback_close_1(substream); } -static int snd_ymfpci_playback_4ch_close(snd_pcm_substream_t * substream) +static int snd_ymfpci_playback_4ch_close(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - unsigned long flags; + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); if (chip->rear_opened > 0) { chip->rear_opened--; ymfpci_close_extension(chip); } - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return snd_ymfpci_playback_close_1(substream); } -static int snd_ymfpci_capture_close(snd_pcm_substream_t * substream) +static int snd_ymfpci_capture_close(struct snd_pcm_substream *substream) { - ymfpci_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - ymfpci_pcm_t *ypcm = snd_magic_cast(ymfpci_pcm_t, runtime->private_data, return -ENXIO); + struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_ymfpci_pcm *ypcm = runtime->private_data; if (ypcm != NULL) { chip->capture_substream[ypcm->capture_bank_number] = NULL; @@ -1050,7 +1072,7 @@ static int snd_ymfpci_capture_close(snd_pcm_substream_t * substream) return 0; } -static snd_pcm_ops_t snd_ymfpci_playback_ops = { +static struct snd_pcm_ops snd_ymfpci_playback_ops = { .open = snd_ymfpci_playback_open, .close = snd_ymfpci_playback_close, .ioctl = snd_pcm_lib_ioctl, @@ -1061,7 +1083,7 @@ static snd_pcm_ops_t snd_ymfpci_playback_ops = { .pointer = snd_ymfpci_playback_pointer, }; -static snd_pcm_ops_t snd_ymfpci_capture_rec_ops = { +static struct snd_pcm_ops snd_ymfpci_capture_rec_ops = { .open = snd_ymfpci_capture_rec_open, .close = snd_ymfpci_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -1072,16 +1094,9 @@ static snd_pcm_ops_t snd_ymfpci_capture_rec_ops = { .pointer = snd_ymfpci_capture_pointer, }; -static void snd_ymfpci_pcm_free(snd_pcm_t *pcm) -{ - ymfpci_t *chip = snd_magic_cast(ymfpci_t, pcm->private_data, return); - chip->pcm = NULL; - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -int __devinit snd_ymfpci_pcm(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) +int __devinit snd_ymfpci_pcm(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if (rpcm) @@ -1089,7 +1104,6 @@ int __devinit snd_ymfpci_pcm(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) if ((err = snd_pcm_new(chip->card, "YMFPCI", device, 32, 1, &pcm)) < 0) return err; pcm->private_data = chip; - pcm->private_free = snd_ymfpci_pcm_free; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ymfpci_capture_rec_ops); @@ -1107,7 +1121,7 @@ int __devinit snd_ymfpci_pcm(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) return 0; } -static snd_pcm_ops_t snd_ymfpci_capture_ac97_ops = { +static struct snd_pcm_ops snd_ymfpci_capture_ac97_ops = { .open = snd_ymfpci_capture_ac97_open, .close = snd_ymfpci_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -1118,16 +1132,9 @@ static snd_pcm_ops_t snd_ymfpci_capture_ac97_ops = { .pointer = snd_ymfpci_capture_pointer, }; -static void snd_ymfpci_pcm2_free(snd_pcm_t *pcm) -{ - ymfpci_t *chip = snd_magic_cast(ymfpci_t, pcm->private_data, return); - chip->pcm2 = NULL; - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -int __devinit snd_ymfpci_pcm2(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) +int __devinit snd_ymfpci_pcm2(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if (rpcm) @@ -1135,7 +1142,6 @@ int __devinit snd_ymfpci_pcm2(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) if ((err = snd_pcm_new(chip->card, "YMFPCI - PCM2", device, 0, 1, &pcm)) < 0) return err; pcm->private_data = chip; - pcm->private_free = snd_ymfpci_pcm2_free; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ymfpci_capture_ac97_ops); @@ -1153,7 +1159,7 @@ int __devinit snd_ymfpci_pcm2(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) return 0; } -static snd_pcm_ops_t snd_ymfpci_playback_spdif_ops = { +static struct snd_pcm_ops snd_ymfpci_playback_spdif_ops = { .open = snd_ymfpci_playback_spdif_open, .close = snd_ymfpci_playback_spdif_close, .ioctl = snd_pcm_lib_ioctl, @@ -1164,16 +1170,9 @@ static snd_pcm_ops_t snd_ymfpci_playback_spdif_ops = { .pointer = snd_ymfpci_playback_pointer, }; -static void snd_ymfpci_pcm_spdif_free(snd_pcm_t *pcm) +int __devinit snd_ymfpci_pcm_spdif(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, pcm->private_data, return); - chip->pcm_spdif = NULL; - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -int __devinit snd_ymfpci_pcm_spdif(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) -{ - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if (rpcm) @@ -1181,7 +1180,6 @@ int __devinit snd_ymfpci_pcm_spdif(ymfpci_t *chip, int device, snd_pcm_t ** rpcm if ((err = snd_pcm_new(chip->card, "YMFPCI - IEC958", device, 1, 0, &pcm)) < 0) return err; pcm->private_data = chip; - pcm->private_free = snd_ymfpci_pcm_spdif_free; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_spdif_ops); @@ -1198,7 +1196,7 @@ int __devinit snd_ymfpci_pcm_spdif(ymfpci_t *chip, int device, snd_pcm_t ** rpcm return 0; } -static snd_pcm_ops_t snd_ymfpci_playback_4ch_ops = { +static struct snd_pcm_ops snd_ymfpci_playback_4ch_ops = { .open = snd_ymfpci_playback_4ch_open, .close = snd_ymfpci_playback_4ch_close, .ioctl = snd_pcm_lib_ioctl, @@ -1209,16 +1207,9 @@ static snd_pcm_ops_t snd_ymfpci_playback_4ch_ops = { .pointer = snd_ymfpci_playback_pointer, }; -static void snd_ymfpci_pcm_4ch_free(snd_pcm_t *pcm) -{ - ymfpci_t *chip = snd_magic_cast(ymfpci_t, pcm->private_data, return); - chip->pcm_4ch = NULL; - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -int __devinit snd_ymfpci_pcm_4ch(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) +int __devinit snd_ymfpci_pcm_4ch(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if (rpcm) @@ -1226,7 +1217,6 @@ int __devinit snd_ymfpci_pcm_4ch(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) if ((err = snd_pcm_new(chip->card, "YMFPCI - Rear", device, 1, 0, &pcm)) < 0) return err; pcm->private_data = chip; - pcm->private_free = snd_ymfpci_pcm_4ch_free; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_4ch_ops); @@ -1243,46 +1233,45 @@ int __devinit snd_ymfpci_pcm_4ch(ymfpci_t *chip, int device, snd_pcm_t ** rpcm) return 0; } -static int snd_ymfpci_spdif_default_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_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_ymfpci_spdif_default_get(snd_kcontrol_t * kcontrol, - snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_spdif_default_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); ucontrol->value.iec958.status[0] = (chip->spdif_bits >> 0) & 0xff; ucontrol->value.iec958.status[1] = (chip->spdif_bits >> 8) & 0xff; - spin_unlock_irqrestore(&chip->reg_lock, flags); + ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; + spin_unlock_irq(&chip->reg_lock); return 0; } -static int snd_ymfpci_spdif_default_put(snd_kcontrol_t * kcontrol, - snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_spdif_default_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | (ucontrol->value.iec958.status[1] << 8); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); change = chip->spdif_bits != val; chip->spdif_bits = val; if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 1) && chip->pcm_spdif == NULL) snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return change; } -static snd_kcontrol_new_t snd_ymfpci_spdif_default __devinitdata = +static struct snd_kcontrol_new snd_ymfpci_spdif_default __devinitdata = { .iface = SNDRV_CTL_ELEM_IFACE_PCM, .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), @@ -1291,27 +1280,26 @@ static snd_kcontrol_new_t snd_ymfpci_spdif_default __devinitdata = .put = snd_ymfpci_spdif_default_put }; -static int snd_ymfpci_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_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_ymfpci_spdif_mask_get(snd_kcontrol_t * kcontrol, - snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_spdif_mask_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); ucontrol->value.iec958.status[0] = 0x3e; ucontrol->value.iec958.status[1] = 0xff; - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return 0; } -static snd_kcontrol_new_t snd_ymfpci_spdif_mask __devinitdata = +static struct snd_kcontrol_new snd_ymfpci_spdif_mask __devinitdata = { .access = SNDRV_CTL_ELEM_ACCESS_READ, .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -1320,46 +1308,45 @@ static snd_kcontrol_new_t snd_ymfpci_spdif_mask __devinitdata = .get = snd_ymfpci_spdif_mask_get, }; -static int snd_ymfpci_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_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_ymfpci_spdif_stream_get(snd_kcontrol_t * kcontrol, - snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_spdif_stream_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); ucontrol->value.iec958.status[0] = (chip->spdif_pcm_bits >> 0) & 0xff; ucontrol->value.iec958.status[1] = (chip->spdif_pcm_bits >> 8) & 0xff; - spin_unlock_irqrestore(&chip->reg_lock, flags); + ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; + spin_unlock_irq(&chip->reg_lock); return 0; } -static int snd_ymfpci_spdif_stream_put(snd_kcontrol_t * kcontrol, - snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_spdif_stream_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); unsigned int val; int change; val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | (ucontrol->value.iec958.status[1] << 8); - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); change = chip->spdif_pcm_bits != val; chip->spdif_pcm_bits = val; if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 2)) snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return change; } -static snd_kcontrol_new_t snd_ymfpci_spdif_stream __devinitdata = +static struct snd_kcontrol_new snd_ymfpci_spdif_stream __devinitdata = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, .iface = SNDRV_CTL_ELEM_IFACE_PCM, @@ -1369,7 +1356,7 @@ static snd_kcontrol_new_t snd_ymfpci_spdif_stream __devinitdata = .put = snd_ymfpci_spdif_stream_put }; -static int snd_ymfpci_drec_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *info) +static int snd_ymfpci_drec_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *info) { static char *texts[3] = {"AC'97", "IEC958", "ZV Port"}; @@ -1382,15 +1369,14 @@ static int snd_ymfpci_drec_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_in return 0; } -static int snd_ymfpci_drec_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_ymfpci_drec_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); u16 reg; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); if (!(reg & 0x100)) value->value.enumerated.item[0] = 0; else @@ -1398,24 +1384,23 @@ static int snd_ymfpci_drec_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_val return 0; } -static int snd_ymfpci_drec_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *value) +static int snd_ymfpci_drec_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); u16 reg, old_reg; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); old_reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); if (value->value.enumerated.item[0] == 0) reg = old_reg & ~0x100; else reg = (old_reg & ~0x300) | 0x100 | ((value->value.enumerated.item[0] == 2) << 9); snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, reg); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return reg != old_reg; } -static snd_kcontrol_new_t snd_ymfpci_drec_source __devinitdata = { +static struct snd_kcontrol_new snd_ymfpci_drec_source __devinitdata = { .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Direct Recording Source", @@ -1428,120 +1413,118 @@ static snd_kcontrol_new_t snd_ymfpci_drec_source __devinitdata = { * Mixer controls */ -#define YMFPCI_SINGLE(xname, xindex, reg) \ +#define YMFPCI_SINGLE(xname, xindex, reg, shift) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ .info = snd_ymfpci_info_single, \ .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \ - .private_value = reg } + .private_value = ((reg) | ((shift) << 16)) } -static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_info_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { - unsigned int mask = 1; + int reg = kcontrol->private_value & 0xffff; - switch (kcontrol->private_value) { + switch (reg) { case YDSXGR_SPDIFOUTCTRL: break; case YDSXGR_SPDIFINCTRL: break; default: return -EINVAL; } - uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; - uinfo->value.integer.max = mask; + uinfo->value.integer.max = 1; return 0; } -static int snd_ymfpci_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_get_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - int reg = kcontrol->private_value; - unsigned int shift = 0, mask = 1, invert = 0; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); + int reg = kcontrol->private_value & 0xffff; + unsigned int shift = (kcontrol->private_value >> 16) & 0xff; + unsigned int mask = 1; - switch (kcontrol->private_value) { + switch (reg) { case YDSXGR_SPDIFOUTCTRL: break; case YDSXGR_SPDIFINCTRL: break; default: return -EINVAL; } - ucontrol->value.integer.value[0] = (snd_ymfpci_readl(chip, reg) >> shift) & mask; - if (invert) - ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; + ucontrol->value.integer.value[0] = + (snd_ymfpci_readl(chip, reg) >> shift) & mask; return 0; } -static int snd_ymfpci_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_put_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; - int reg = kcontrol->private_value; - unsigned int shift = 0, mask = 1, invert = 0; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); + int reg = kcontrol->private_value & 0xffff; + unsigned int shift = (kcontrol->private_value >> 16) & 0xff; + unsigned int mask = 1; int change; unsigned int val, oval; - switch (kcontrol->private_value) { + switch (reg) { case YDSXGR_SPDIFOUTCTRL: break; case YDSXGR_SPDIFINCTRL: break; default: return -EINVAL; } val = (ucontrol->value.integer.value[0] & mask); - if (invert) - val = mask - val; val <<= shift; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); oval = snd_ymfpci_readl(chip, reg); val = (oval & ~(mask << shift)) | val; change = val != oval; snd_ymfpci_writel(chip, reg, val); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return change; } +static DECLARE_TLV_DB_LINEAR(db_scale_native, TLV_DB_GAIN_MUTE, 0); + #define YMFPCI_DOUBLE(xname, xindex, reg) \ { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ .info = snd_ymfpci_info_double, \ .get = snd_ymfpci_get_double, .put = snd_ymfpci_put_double, \ - .private_value = reg } + .private_value = reg, \ + .tlv = { .p = db_scale_native } } -static int snd_ymfpci_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { unsigned int reg = kcontrol->private_value; - unsigned int mask = 16383; if (reg < 0x80 || reg >= 0xc0) return -EINVAL; - uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; - uinfo->value.integer.max = mask; + uinfo->value.integer.max = 16383; return 0; } -static int snd_ymfpci_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); unsigned int reg = kcontrol->private_value; - unsigned int shift_left = 0, shift_right = 16, mask = 16383, invert = 0; + unsigned int shift_left = 0, shift_right = 16, mask = 16383; unsigned int val; if (reg < 0x80 || reg >= 0xc0) return -EINVAL; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); val = snd_ymfpci_readl(chip, reg); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); ucontrol->value.integer.value[0] = (val >> shift_left) & mask; ucontrol->value.integer.value[1] = (val >> shift_right) & mask; - if (invert) { - ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; - ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; - } return 0; } -static int snd_ymfpci_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); - unsigned long flags; + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); unsigned int reg = kcontrol->private_value; - unsigned int shift_left = 0, shift_right = 16, mask = 16383, invert = 0; + unsigned int shift_left = 0, shift_right = 16, mask = 16383; int change; unsigned int val1, val2, oval; @@ -1549,25 +1532,21 @@ static int snd_ymfpci_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t return -EINVAL; val1 = ucontrol->value.integer.value[0] & mask; val2 = ucontrol->value.integer.value[1] & mask; - if (invert) { - val1 = mask - val1; - val2 = mask - val2; - } val1 <<= shift_left; val2 <<= shift_right; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); oval = snd_ymfpci_readl(chip, reg); val1 = (oval & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; change = val1 != oval; snd_ymfpci_writel(chip, reg, val1); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return change; } /* * 4ch duplication */ -static int snd_ymfpci_info_dup4ch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_ymfpci_info_dup4ch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; @@ -1576,16 +1555,16 @@ static int snd_ymfpci_info_dup4ch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_ymfpci_get_dup4ch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_get_dup4ch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = chip->mode_dup4ch; return 0; } -static int snd_ymfpci_put_dup4ch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_ymfpci_put_dup4ch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); int change; change = (ucontrol->value.integer.value[0] != chip->mode_dup4ch); if (change) @@ -1594,9 +1573,7 @@ static int snd_ymfpci_put_dup4ch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t } -#define YMFPCI_CONTROLS (sizeof(snd_ymfpci_controls)/sizeof(snd_kcontrol_new_t)) - -static snd_kcontrol_new_t snd_ymfpci_controls[] __devinitdata = { +static struct snd_kcontrol_new snd_ymfpci_controls[] __devinitdata = { YMFPCI_DOUBLE("Wave Playback Volume", 0, YDSXGR_NATIVEDACOUTVOL), YMFPCI_DOUBLE("Wave Capture Volume", 0, YDSXGR_NATIVEDACLOOPVOL), YMFPCI_DOUBLE("Digital Capture Volume", 0, YDSXGR_NATIVEDACINVOL), @@ -1610,8 +1587,9 @@ YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVO YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL), -YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL), -YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL), +YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL, 0), +YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL, 0), +YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE,NONE), 0, YDSXGR_SPDIFINCTRL, 4), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "4ch Duplication", @@ -1626,7 +1604,7 @@ YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL), * GPIO */ -static int snd_ymfpci_get_gpio_out(ymfpci_t *chip, int pin) +static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin) { u16 reg, mode; unsigned long flags; @@ -1646,7 +1624,7 @@ static int snd_ymfpci_get_gpio_out(ymfpci_t *chip, int pin) return (mode >> pin) & 1; } -static int snd_ymfpci_set_gpio_out(ymfpci_t *chip, int pin, int enable) +static int snd_ymfpci_set_gpio_out(struct snd_ymfpci *chip, int pin, int enable) { u16 reg; unsigned long flags; @@ -1663,7 +1641,7 @@ static int snd_ymfpci_set_gpio_out(ymfpci_t *chip, int pin, int enable) return 0; } -static int snd_ymfpci_gpio_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) +static int snd_ymfpci_gpio_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; @@ -1672,17 +1650,17 @@ static int snd_ymfpci_gpio_sw_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_ymfpci_gpio_sw_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_ymfpci_gpio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); int pin = (int)kcontrol->private_value; ucontrol->value.integer.value[0] = snd_ymfpci_get_gpio_out(chip, pin); return 0; } -static int snd_ymfpci_gpio_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_ymfpci_gpio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - ymfpci_t *chip = snd_kcontrol_chip(kcontrol); + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); int pin = (int)kcontrol->private_value; if (snd_ymfpci_get_gpio_out(chip, pin) != ucontrol->value.integer.value[0]) { @@ -1693,7 +1671,7 @@ static int snd_ymfpci_gpio_sw_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t return 0; } -static snd_kcontrol_new_t snd_ymfpci_rear_shared __devinitdata = { +static struct snd_kcontrol_new snd_ymfpci_rear_shared __devinitdata = { .name = "Shared Rear/Line-In Switch", .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .info = snd_ymfpci_gpio_sw_info, @@ -1702,38 +1680,99 @@ static snd_kcontrol_new_t snd_ymfpci_rear_shared __devinitdata = { .private_value = 2, }; +/* + * PCM voice volume + */ + +static int snd_ymfpci_pcm_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 = 0x8000; + return 0; +} + +static int snd_ymfpci_pcm_vol_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); + unsigned int subs = kcontrol->id.subdevice; + + ucontrol->value.integer.value[0] = chip->pcm_mixer[subs].left; + ucontrol->value.integer.value[1] = chip->pcm_mixer[subs].right; + return 0; +} + +static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); + unsigned int subs = kcontrol->id.subdevice; + struct snd_pcm_substream *substream; + unsigned long flags; + + if (ucontrol->value.integer.value[0] != chip->pcm_mixer[subs].left || + ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) { + chip->pcm_mixer[subs].left = ucontrol->value.integer.value[0]; + chip->pcm_mixer[subs].right = ucontrol->value.integer.value[1]; + + substream = (struct snd_pcm_substream *)kcontrol->private_value; + spin_lock_irqsave(&chip->voice_lock, flags); + if (substream->runtime && substream->runtime->private_data) { + struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; + ypcm->update_pcm_vol = 2; + } + spin_unlock_irqrestore(&chip->voice_lock, flags); + return 1; + } + return 0; +} + +static struct snd_kcontrol_new snd_ymfpci_pcm_volume __devinitdata = { + .iface = SNDRV_CTL_ELEM_IFACE_PCM, + .name = "PCM Playback Volume", + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | + SNDRV_CTL_ELEM_ACCESS_INACTIVE, + .info = snd_ymfpci_pcm_vol_info, + .get = snd_ymfpci_pcm_vol_get, + .put = snd_ymfpci_pcm_vol_put, +}; + /* * Mixer routines */ -static void snd_ymfpci_mixer_free_ac97_bus(ac97_bus_t *bus) +static void snd_ymfpci_mixer_free_ac97_bus(struct snd_ac97_bus *bus) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, bus->private_data, return); + struct snd_ymfpci *chip = bus->private_data; chip->ac97_bus = NULL; } -static void snd_ymfpci_mixer_free_ac97(ac97_t *ac97) +static void snd_ymfpci_mixer_free_ac97(struct snd_ac97 *ac97) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, ac97->private_data, return); + struct snd_ymfpci *chip = ac97->private_data; chip->ac97 = NULL; } -int __devinit snd_ymfpci_mixer(ymfpci_t *chip, int rear_switch) +int __devinit snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch) { - ac97_bus_t bus; - ac97_t ac97; - snd_kcontrol_t *kctl; + struct snd_ac97_template ac97; + struct snd_kcontrol *kctl; + struct snd_pcm_substream *substream; unsigned int idx; int err; + static struct snd_ac97_bus_ops ops = { + .write = snd_ymfpci_codec_write, + .read = snd_ymfpci_codec_read, + }; - memset(&bus, 0, sizeof(bus)); - bus.write = snd_ymfpci_codec_write; - bus.read = snd_ymfpci_codec_read; - bus.private_data = chip; - bus.private_free = snd_ymfpci_mixer_free_ac97_bus; - if ((err = snd_ac97_bus(chip->card, &bus, &chip->ac97_bus)) < 0) + if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) return err; + chip->ac97_bus->private_free = snd_ymfpci_mixer_free_ac97_bus; + chip->ac97_bus->no_vra = 1; /* YMFPCI doesn't need VRA */ memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; @@ -1741,7 +1780,11 @@ int __devinit snd_ymfpci_mixer(ymfpci_t *chip, int rear_switch) if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) return err; - for (idx = 0; idx < YMFPCI_CONTROLS; idx++) { + /* to be sure */ + snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, + AC97_EA_VRA|AC97_EA_VRM, 0); + + for (idx = 0; idx < ARRAY_SIZE(snd_ymfpci_controls); idx++) { if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_ymfpci_controls[idx], chip))) < 0) return err; } @@ -1772,6 +1815,23 @@ int __devinit snd_ymfpci_mixer(ymfpci_t *chip, int rear_switch) return err; } + /* per-voice volume */ + substream = chip->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; + for (idx = 0; idx < 32; ++idx) { + kctl = snd_ctl_new1(&snd_ymfpci_pcm_volume, chip); + if (!kctl) + return -ENOMEM; + kctl->id.device = chip->pcm->device; + kctl->id.subdevice = idx; + kctl->private_value = (unsigned long)substream; + if ((err = snd_ctl_add(chip->card, kctl)) < 0) + return err; + chip->pcm_mixer[idx].left = 0x8000; + chip->pcm_mixer[idx].right = 0x8000; + chip->pcm_mixer[idx].ctl = kctl; + substream = substream->next; + } + return 0; } @@ -1780,16 +1840,14 @@ int __devinit snd_ymfpci_mixer(ymfpci_t *chip, int rear_switch) * timer */ -static int snd_ymfpci_timer_start(snd_timer_t *timer) +static int snd_ymfpci_timer_start(struct snd_timer *timer) { - ymfpci_t *chip; + struct snd_ymfpci *chip; unsigned long flags; unsigned int count; chip = snd_timer_chip(timer); - count = timer->sticks - 1; - if (count == 0) /* minimum time is 20.8 us */ - count = 1; + count = (timer->sticks << 1) - 1; spin_lock_irqsave(&chip->reg_lock, flags); snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); @@ -1797,9 +1855,9 @@ static int snd_ymfpci_timer_start(snd_timer_t *timer) return 0; } -static int snd_ymfpci_timer_stop(snd_timer_t *timer) +static int snd_ymfpci_timer_stop(struct snd_timer *timer) { - ymfpci_t *chip; + struct snd_ymfpci *chip; unsigned long flags; chip = snd_timer_chip(timer); @@ -1809,27 +1867,27 @@ static int snd_ymfpci_timer_stop(snd_timer_t *timer) return 0; } -static int snd_ymfpci_timer_precise_resolution(snd_timer_t *timer, +static int snd_ymfpci_timer_precise_resolution(struct snd_timer *timer, unsigned long *num, unsigned long *den) { *num = 1; - *den = 96000; + *den = 48000; return 0; } -static struct _snd_timer_hardware snd_ymfpci_timer_hw = { +static struct snd_timer_hardware snd_ymfpci_timer_hw = { .flags = SNDRV_TIMER_HW_AUTO, - .resolution = 10417, /* 1/2fs = 10.41666...us */ - .ticks = 65536, + .resolution = 20833, /* 1/fs = 20.8333...us */ + .ticks = 0x8000, .start = snd_ymfpci_timer_start, .stop = snd_ymfpci_timer_stop, .precise_resolution = snd_ymfpci_timer_precise_resolution, }; -int __devinit snd_ymfpci_timer(ymfpci_t *chip, int device) +int __devinit snd_ymfpci_timer(struct snd_ymfpci *chip, int device) { - snd_timer_t *timer = NULL; - snd_timer_id_t tid; + struct snd_timer *timer = NULL; + struct snd_timer_id tid; int err; tid.dev_class = SNDRV_TIMER_CLASS_CARD; @@ -1851,10 +1909,10 @@ int __devinit snd_ymfpci_timer(ymfpci_t *chip, int device) * proc interface */ -static void snd_ymfpci_proc_read(snd_info_entry_t *entry, - snd_info_buffer_t * buffer) +static void snd_ymfpci_proc_read(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, entry->private_data, return); + struct snd_ymfpci *chip = entry->private_data; int i; snd_iprintf(buffer, "YMFPCI\n\n"); @@ -1862,12 +1920,12 @@ static void snd_ymfpci_proc_read(snd_info_entry_t *entry, snd_iprintf(buffer, "%04x: %04x\n", i, snd_ymfpci_readl(chip, i)); } -static int __devinit snd_ymfpci_proc_init(snd_card_t * card, ymfpci_t *chip) +static int __devinit snd_ymfpci_proc_init(struct snd_card *card, struct snd_ymfpci *chip) { - snd_info_entry_t *entry; + struct snd_info_entry *entry; if (! snd_card_proc_new(card, "ymfpci", &entry)) - snd_info_set_text_ops(entry, chip, 1024, snd_ymfpci_proc_read); + snd_info_set_text_ops(entry, chip, snd_ymfpci_proc_read); return 0; } @@ -1893,12 +1951,12 @@ static void snd_ymfpci_aclink_reset(struct pci_dev * pci) #endif } -static void snd_ymfpci_enable_dsp(ymfpci_t *chip) +static void snd_ymfpci_enable_dsp(struct snd_ymfpci *chip) { snd_ymfpci_writel(chip, YDSXGR_CONFIG, 0x00000001); } -static void snd_ymfpci_disable_dsp(ymfpci_t *chip) +static void snd_ymfpci_disable_dsp(struct snd_ymfpci *chip) { u32 val; int timeout = 1000; @@ -1915,7 +1973,7 @@ static void snd_ymfpci_disable_dsp(ymfpci_t *chip) #include "ymfpci_image.h" -static void snd_ymfpci_download_image(ymfpci_t *chip) +static void snd_ymfpci_download_image(struct snd_ymfpci *chip) { int i; u16 ctrl; @@ -1955,7 +2013,7 @@ static void snd_ymfpci_download_image(ymfpci_t *chip) snd_ymfpci_enable_dsp(chip); } -static int __devinit snd_ymfpci_memalloc(ymfpci_t *chip) +static int __devinit snd_ymfpci_memalloc(struct snd_ymfpci *chip) { long size, playback_ctrl_size; int voice, bank, reg; @@ -1968,14 +2026,15 @@ static int __devinit snd_ymfpci_memalloc(ymfpci_t *chip) chip->bank_size_effect = snd_ymfpci_readl(chip, YDSXGR_EFFCTRLSIZE) << 2; chip->work_size = YDSXG_DEFAULT_WORK_SIZE; - size = ((playback_ctrl_size + 0x00ff) & ~0x00ff) + - ((chip->bank_size_playback * 2 * YDSXG_PLAYBACK_VOICES + 0x00ff) & ~0x00ff) + - ((chip->bank_size_capture * 2 * YDSXG_CAPTURE_VOICES + 0x00ff) & ~0x00ff) + - ((chip->bank_size_effect * 2 * YDSXG_EFFECT_VOICES + 0x00ff) & ~0x00ff) + + size = ALIGN(playback_ctrl_size, 0x100) + + ALIGN(chip->bank_size_playback * 2 * YDSXG_PLAYBACK_VOICES, 0x100) + + ALIGN(chip->bank_size_capture * 2 * YDSXG_CAPTURE_VOICES, 0x100) + + ALIGN(chip->bank_size_effect * 2 * YDSXG_EFFECT_VOICES, 0x100) + chip->work_size; /* work_ptr must be aligned to 256 bytes, but it's already covered with the kernel page allocation mechanism */ - if (snd_dma_alloc_pages(&chip->dma_dev, size, &chip->work_ptr) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + size, &chip->work_ptr) < 0) return -ENOMEM; ptr = chip->work_ptr.area; ptr_addr = chip->work_ptr.addr; @@ -1985,40 +2044,40 @@ static int __devinit snd_ymfpci_memalloc(ymfpci_t *chip) chip->bank_base_playback_addr = ptr_addr; chip->ctrl_playback = (u32 *)ptr; chip->ctrl_playback[0] = cpu_to_le32(YDSXG_PLAYBACK_VOICES); - ptr += (playback_ctrl_size + 0x00ff) & ~0x00ff; - ptr_addr += (playback_ctrl_size + 0x00ff) & ~0x00ff; + ptr += ALIGN(playback_ctrl_size, 0x100); + ptr_addr += ALIGN(playback_ctrl_size, 0x100); for (voice = 0; voice < YDSXG_PLAYBACK_VOICES; voice++) { chip->voices[voice].number = voice; - chip->voices[voice].bank = (snd_ymfpci_playback_bank_t *)ptr; + chip->voices[voice].bank = (struct snd_ymfpci_playback_bank *)ptr; chip->voices[voice].bank_addr = ptr_addr; for (bank = 0; bank < 2; bank++) { - chip->bank_playback[voice][bank] = (snd_ymfpci_playback_bank_t *)ptr; + chip->bank_playback[voice][bank] = (struct snd_ymfpci_playback_bank *)ptr; ptr += chip->bank_size_playback; ptr_addr += chip->bank_size_playback; } } - ptr = (char *)(((unsigned long)ptr + 0x00ff) & ~0x00ff); - ptr_addr = (ptr_addr + 0x00ff) & ~0x00ff; + ptr = (char *)ALIGN((unsigned long)ptr, 0x100); + ptr_addr = ALIGN(ptr_addr, 0x100); chip->bank_base_capture = ptr; chip->bank_base_capture_addr = ptr_addr; for (voice = 0; voice < YDSXG_CAPTURE_VOICES; voice++) for (bank = 0; bank < 2; bank++) { - chip->bank_capture[voice][bank] = (snd_ymfpci_capture_bank_t *)ptr; + chip->bank_capture[voice][bank] = (struct snd_ymfpci_capture_bank *)ptr; ptr += chip->bank_size_capture; ptr_addr += chip->bank_size_capture; } - ptr = (char *)(((unsigned long)ptr + 0x00ff) & ~0x00ff); - ptr_addr = (ptr_addr + 0x00ff) & ~0x00ff; + ptr = (char *)ALIGN((unsigned long)ptr, 0x100); + ptr_addr = ALIGN(ptr_addr, 0x100); chip->bank_base_effect = ptr; chip->bank_base_effect_addr = ptr_addr; for (voice = 0; voice < YDSXG_EFFECT_VOICES; voice++) for (bank = 0; bank < 2; bank++) { - chip->bank_effect[voice][bank] = (snd_ymfpci_effect_bank_t *)ptr; + chip->bank_effect[voice][bank] = (struct snd_ymfpci_effect_bank *)ptr; ptr += chip->bank_size_effect; ptr_addr += chip->bank_size_effect; } - ptr = (char *)(((unsigned long)ptr + 0x00ff) & ~0x00ff); - ptr_addr = (ptr_addr + 0x00ff) & ~0x00ff; + ptr = (char *)ALIGN((unsigned long)ptr, 0x100); + ptr_addr = ALIGN(ptr_addr, 0x100); chip->work_base = ptr; chip->work_base_addr = ptr_addr; @@ -2052,7 +2111,7 @@ static int __devinit snd_ymfpci_memalloc(ymfpci_t *chip) return 0; } -static int snd_ymfpci_free(ymfpci_t *chip) +static int snd_ymfpci_free(struct snd_ymfpci *chip) { u16 ctrl; @@ -2084,46 +2143,30 @@ static int snd_ymfpci_free(ymfpci_t *chip) #endif #ifdef CONFIG_PM - if (chip->saved_regs) - vfree(chip->saved_regs); -#endif - if (chip->mpu_res) { - release_resource(chip->mpu_res); - kfree_nocheck(chip->mpu_res); - } - if (chip->fm_res) { - release_resource(chip->fm_res); - kfree_nocheck(chip->fm_res); - } -#ifdef SUPPORT_JOYSTICK - if (chip->joystick_res) { - if (chip->gameport.io) - gameport_unregister_port(&chip->gameport); - release_resource(chip->joystick_res); - kfree_nocheck(chip->joystick_res); - } + vfree(chip->saved_regs); #endif + release_and_free_resource(chip->mpu_res); + release_and_free_resource(chip->fm_res); + snd_ymfpci_free_gameport(chip); if (chip->reg_area_virt) - iounmap((void *)chip->reg_area_virt); + iounmap(chip->reg_area_virt); if (chip->work_ptr.area) - snd_dma_free_pages(&chip->dma_dev, &chip->work_ptr); + snd_dma_free_pages(&chip->work_ptr); if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); - if (chip->res_reg_area) { - release_resource(chip->res_reg_area); - kfree_nocheck(chip->res_reg_area); - } + free_irq(chip->irq, chip); + release_and_free_resource(chip->res_reg_area); pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); - snd_magic_kfree(chip); + pci_disable_device(chip->pci); + kfree(chip); return 0; } -static int snd_ymfpci_dev_free(snd_device_t *device) +static int snd_ymfpci_dev_free(struct snd_device *device) { - ymfpci_t *chip = snd_magic_cast(ymfpci_t, device->device_data, return -ENXIO); + struct snd_ymfpci *chip = device->device_data; return snd_ymfpci_free(chip); } @@ -2157,36 +2200,45 @@ static int saved_regs_index[] = { }; #define YDSXGR_NUM_SAVED_REGS ARRAY_SIZE(saved_regs_index) -void snd_ymfpci_suspend(ymfpci_t *chip) +int snd_ymfpci_suspend(struct pci_dev *pci, pm_message_t state) { - snd_card_t *card = chip->card; + struct snd_card *card = pci_get_drvdata(pci); + struct snd_ymfpci *chip = card->private_data; unsigned int i; - if (card->power_state == SNDRV_CTL_POWER_D3hot) - return; + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_pcm_suspend_all(chip->pcm); snd_pcm_suspend_all(chip->pcm2); snd_pcm_suspend_all(chip->pcm_spdif); snd_pcm_suspend_all(chip->pcm_4ch); + snd_ac97_suspend(chip->ac97); for (i = 0; i < YDSXGR_NUM_SAVED_REGS; i++) chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]); chip->saved_ydsxgr_mode = snd_ymfpci_readl(chip, YDSXGR_MODE); snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0); snd_ymfpci_disable_dsp(chip); - snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + pci_disable_device(pci); + pci_save_state(pci); + pci_set_power_state(pci, pci_choose_state(pci, state)); + return 0; } -void snd_ymfpci_resume(ymfpci_t *chip) +int snd_ymfpci_resume(struct pci_dev *pci) { - snd_card_t *card = chip->card; + struct snd_card *card = pci_get_drvdata(pci); + struct snd_ymfpci *chip = card->private_data; unsigned int i; - if (card->power_state == SNDRV_CTL_POWER_D0) - return; - - pci_enable_device(chip->pci); - pci_set_master(chip->pci); - snd_ymfpci_aclink_reset(chip->pci); + pci_set_power_state(pci, PCI_D0); + pci_restore_state(pci); + if (pci_enable_device(pci) < 0) { + printk(KERN_ERR "ymfpci: pci_enable_device failed, " + "disabling device\n"); + snd_card_disconnect(card); + return -EIO; + } + pci_set_master(pci); + snd_ymfpci_aclink_reset(pci); snd_ymfpci_codec_ready(chip, 0); snd_ymfpci_download_image(chip); udelay(100); @@ -2198,44 +2250,24 @@ void snd_ymfpci_resume(ymfpci_t *chip) /* start hw again */ if (chip->start_count > 0) { - unsigned long flags; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); snd_ymfpci_writel(chip, YDSXGR_MODE, chip->saved_ydsxgr_mode); chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); } snd_power_change_state(card, SNDRV_CTL_POWER_D0); -} - -static int snd_ymfpci_set_power_state(snd_card_t *card, unsigned int power_state) -{ - ymfpci_t *chip = snd_magic_cast(ymfpci_t, card->power_state_private_data, return -ENXIO); - - switch (power_state) { - case SNDRV_CTL_POWER_D0: - case SNDRV_CTL_POWER_D1: - case SNDRV_CTL_POWER_D2: - snd_ymfpci_resume(chip); - break; - case SNDRV_CTL_POWER_D3hot: - case SNDRV_CTL_POWER_D3cold: - snd_ymfpci_suspend(chip); - break; - default: - return -EINVAL; - } return 0; } #endif /* CONFIG_PM */ -int __devinit snd_ymfpci_create(snd_card_t * card, +int __devinit snd_ymfpci_create(struct snd_card *card, struct pci_dev * pci, unsigned short old_legacy_ctrl, - ymfpci_t ** rchip) + struct snd_ymfpci ** rchip) { - ymfpci_t *chip; + struct snd_ymfpci *chip; int err; - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_ymfpci_dev_free, }; @@ -2245,9 +2277,11 @@ int __devinit snd_ymfpci_create(snd_card_t * card, if ((err = pci_enable_device(pci)) < 0) return err; - chip = snd_magic_kcalloc(ymfpci_t, 0, GFP_KERNEL); - if (chip == NULL) + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (chip == NULL) { + pci_disable_device(pci); return -ENOMEM; + } chip->old_legacy_ctrl = old_legacy_ctrl; spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->voice_lock); @@ -2257,27 +2291,24 @@ int __devinit snd_ymfpci_create(snd_card_t * card, chip->pci = pci; chip->irq = -1; chip->device_id = pci->device; - pci_read_config_byte(pci, PCI_REVISION_ID, (u8 *)&chip->rev); + pci_read_config_byte(pci, PCI_REVISION_ID, &chip->rev); chip->reg_area_phys = pci_resource_start(pci, 0); - chip->reg_area_virt = (unsigned long)ioremap_nocache(chip->reg_area_phys, 0x8000); + chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000); pci_set_master(pci); if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) { - snd_printk("unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); + snd_printk(KERN_ERR "unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); snd_ymfpci_free(chip); return -EBUSY; } - if (request_irq(pci->irq, snd_ymfpci_interrupt, SA_INTERRUPT|SA_SHIRQ, "YMFPCI", (void *) chip)) { - snd_printk("unable to grab IRQ %d\n", pci->irq); + if (request_irq(pci->irq, snd_ymfpci_interrupt, IRQF_SHARED, + "YMFPCI", chip)) { + snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); snd_ymfpci_free(chip); return -EBUSY; } chip->irq = pci->irq; - memset(&chip->dma_dev, 0, sizeof(chip->dma_dev)); - chip->dma_dev.type = SNDRV_DMA_TYPE_DEV; - chip->dma_dev.dev = snd_dma_pci_data(pci); - snd_ymfpci_aclink_reset(pci); if (snd_ymfpci_codec_ready(chip, 0) < 0) { snd_ymfpci_free(chip); @@ -2304,17 +2335,15 @@ int __devinit snd_ymfpci_create(snd_card_t * card, snd_ymfpci_free(chip); return -ENOMEM; } - card->set_power_state = snd_ymfpci_set_power_state; - card->power_state_private_data = chip; #endif - snd_ymfpci_proc_init(card, chip); - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { snd_ymfpci_free(chip); return err; } + snd_ymfpci_proc_init(card, chip); + snd_card_set_dev(card, &pci->dev); *rchip = chip;