Lines Matching +full:min +full:- +full:sample +full:- +full:rate +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-or-later
151 if (pcm->spdif) in get_slot_reg()
153 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK) in get_slot_reg()
154 return rate_reg_tables[dbl][pcm->r[dbl].rate_table[cidx]][slot - 3]; in get_slot_reg()
156 return rate_cregs[slot - 3]; in get_slot_reg()
159 static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate) in set_spdif_rate() argument
164 if (! (ac97->ext_id & AC97_EI_SPDIF)) in set_spdif_rate()
165 return -ENODEV; in set_spdif_rate()
167 /* TODO: double rate support */ in set_spdif_rate()
168 if (ac97->flags & AC97_CS_SPDIF) { in set_spdif_rate()
169 switch (rate) { in set_spdif_rate()
172 default: /* invalid - disable output */ in set_spdif_rate()
174 return -EINVAL; in set_spdif_rate()
179 if (ac97->id == AC97_ID_CM9739 && rate != 48000) { in set_spdif_rate()
181 return -EINVAL; in set_spdif_rate()
183 switch (rate) { in set_spdif_rate()
187 default: /* invalid - disable output */ in set_spdif_rate()
189 return -EINVAL; in set_spdif_rate()
195 mutex_lock(&ac97->reg_mutex); in set_spdif_rate()
201 sbits = ac97->spdif_status; in set_spdif_rate()
204 switch (rate) { in set_spdif_rate()
211 switch (rate) { in set_spdif_rate()
217 ac97->spdif_status = sbits; in set_spdif_rate()
220 mutex_unlock(&ac97->reg_mutex); in set_spdif_rate()
225 * snd_ac97_set_rate - change the rate of the given input/output.
228 * @rate: the sample rate to set
230 * Changes the rate of the given input/output on the codec.
231 * If the codec doesn't support VAR, the rate must be 48000 (except
243 int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate) in snd_ac97_set_rate() argument
248 dbl = rate > 48000; in snd_ac97_set_rate()
250 if (!(ac97->flags & AC97_DOUBLE_RATE)) in snd_ac97_set_rate()
251 return -EINVAL; in snd_ac97_set_rate()
253 return -EINVAL; in snd_ac97_set_rate()
259 if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRM) == 0) /* MIC VRA */ in snd_ac97_set_rate()
260 if (rate != 48000) in snd_ac97_set_rate()
261 return -EINVAL; in snd_ac97_set_rate()
265 if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRA) == 0) /* VRA */ in snd_ac97_set_rate()
266 if (rate != 48000 && rate != 96000) in snd_ac97_set_rate()
267 return -EINVAL; in snd_ac97_set_rate()
270 if (! (ac97->scaps & AC97_SCAP_SURROUND_DAC)) in snd_ac97_set_rate()
271 return -EINVAL; in snd_ac97_set_rate()
274 if (! (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) in snd_ac97_set_rate()
275 return -EINVAL; in snd_ac97_set_rate()
279 return set_spdif_rate(ac97, rate); in snd_ac97_set_rate()
281 return -EINVAL; in snd_ac97_set_rate()
284 rate /= 2; in snd_ac97_set_rate()
285 tmp = (rate * ac97->bus->clock) / 48000; in snd_ac97_set_rate()
287 return -EINVAL; in snd_ac97_set_rate()
288 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) in snd_ac97_set_rate()
293 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) { in snd_ac97_set_rate()
294 /* Intel controllers require double rate data to be put in in snd_ac97_set_rate()
316 es = ac97->regs[AC97_EXTENDED_ID] &= ~AC97_EI_DACS_SLOT_MASK; in get_pslots()
317 switch (ac97->addr) { in get_pslots()
324 switch (ac97->addr) { in get_pslots()
327 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) in get_pslots()
329 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) in get_pslots()
331 if (ac97->ext_id & AC97_EI_SPDIF) { in get_pslots()
332 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) in get_pslots()
334 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) in get_pslots()
344 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) in get_pslots()
346 if (ac97->ext_id & AC97_EI_SPDIF) { in get_pslots()
347 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) in get_pslots()
356 if (ac97->ext_id & AC97_EI_SPDIF) in get_pslots()
365 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) in get_pslots()
367 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) in get_pslots()
369 if (ac97->ext_id & AC97_EI_SPDIF) { in get_pslots()
370 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC)) in get_pslots()
372 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)) in get_pslots()
411 rates &= pcm->r[dbl].codec[cidx]->rates[idx]; in get_rates()
420 * snd_ac97_pcm_assign - assign AC97 slots to given PCM streams
426 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
447 return -ENOMEM; in snd_ac97_pcm_assign()
452 codec = bus->codec[i]; in snd_ac97_pcm_assign()
457 if (!(codec->scaps & AC97_SCAP_INDEP_SDIN)) { in snd_ac97_pcm_assign()
459 if (bus->codec[j]) in snd_ac97_pcm_assign()
464 /* first step - exclusive devices */ in snd_ac97_pcm_assign()
468 /* low-level driver thinks that it's more clever */ in snd_ac97_pcm_assign()
469 if (pcm->copy_flag) { in snd_ac97_pcm_assign()
473 rpcm->stream = pcm->stream; in snd_ac97_pcm_assign()
474 rpcm->exclusive = pcm->exclusive; in snd_ac97_pcm_assign()
475 rpcm->spdif = pcm->spdif; in snd_ac97_pcm_assign()
476 rpcm->private_value = pcm->private_value; in snd_ac97_pcm_assign()
477 rpcm->bus = bus; in snd_ac97_pcm_assign()
478 rpcm->rates = ~0; in snd_ac97_pcm_assign()
479 slots = pcm->r[0].slots; in snd_ac97_pcm_assign()
481 if (!bus->codec[j]) in snd_ac97_pcm_assign()
484 if (pcm->spdif && pcm->stream == 0) in snd_ac97_pcm_assign()
487 tmp = avail_slots[pcm->stream][j]; in snd_ac97_pcm_assign()
488 if (pcm->exclusive) { in snd_ac97_pcm_assign()
492 if (rpcm->stream == rpcms[k].stream) in snd_ac97_pcm_assign()
496 /* non-exclusive access */ in snd_ac97_pcm_assign()
497 tmp &= pcm->r[0].slots; in snd_ac97_pcm_assign()
500 rpcm->r[0].rslots[j] = tmp; in snd_ac97_pcm_assign()
501 rpcm->r[0].codec[j] = bus->codec[j]; in snd_ac97_pcm_assign()
502 rpcm->r[0].rate_table[j] = rate_table[pcm->stream][j]; in snd_ac97_pcm_assign()
503 if (bus->no_vra) in snd_ac97_pcm_assign()
507 if (pcm->exclusive) in snd_ac97_pcm_assign()
508 avail_slots[pcm->stream][j] &= ~tmp; in snd_ac97_pcm_assign()
511 rpcm->r[0].slots |= tmp; in snd_ac97_pcm_assign()
512 rpcm->rates &= rates; in snd_ac97_pcm_assign()
514 /* for double rate, we check the first codec only */ in snd_ac97_pcm_assign()
515 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK && in snd_ac97_pcm_assign()
516 bus->codec[0] && (bus->codec[0]->flags & AC97_DOUBLE_RATE) && in snd_ac97_pcm_assign()
517 rate_table[pcm->stream][0] == 0) { in snd_ac97_pcm_assign()
520 if ((tmp & pcm->r[1].slots) == tmp) { in snd_ac97_pcm_assign()
521 rpcm->r[1].slots = tmp; in snd_ac97_pcm_assign()
522 rpcm->r[1].rslots[0] = tmp; in snd_ac97_pcm_assign()
523 rpcm->r[1].rate_table[0] = 0; in snd_ac97_pcm_assign()
524 rpcm->r[1].codec[0] = bus->codec[0]; in snd_ac97_pcm_assign()
525 if (pcm->exclusive) in snd_ac97_pcm_assign()
526 avail_slots[pcm->stream][0] &= ~tmp; in snd_ac97_pcm_assign()
527 if (bus->no_vra) in snd_ac97_pcm_assign()
531 rpcm->rates |= rates; in snd_ac97_pcm_assign()
534 if (rpcm->rates == ~0) in snd_ac97_pcm_assign()
535 rpcm->rates = 0; /* not used */ in snd_ac97_pcm_assign()
537 bus->pcms_count = pcms_count; in snd_ac97_pcm_assign()
538 bus->pcms = rpcms; in snd_ac97_pcm_assign()
545 * snd_ac97_pcm_open - opens the given AC97 pcm
547 * @rate: rate in Hz, if codec does not support VRA, this value must be 48000Hz
551 * It locks the specified slots and sets the given rate to AC97 registers.
555 int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate, in snd_ac97_pcm_open() argument
564 r = rate > 48000; in snd_ac97_pcm_open()
565 bus = pcm->bus; in snd_ac97_pcm_open()
568 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { in snd_ac97_pcm_open()
569 err = set_spdif_rate(bus->codec[cidx], rate); in snd_ac97_pcm_open()
574 spin_lock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_open()
580 if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { in snd_ac97_pcm_open()
581 spin_unlock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_open()
582 err = -EBUSY; in snd_ac97_pcm_open()
585 if (pcm->r[r].rslots[cidx] & (1 << i)) { in snd_ac97_pcm_open()
586 bus->used_slots[pcm->stream][cidx] |= (1 << i); in snd_ac97_pcm_open()
591 spin_unlock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_open()
592 dev_err(bus->card->dev, in snd_ac97_pcm_open()
595 err = -EAGAIN; in snd_ac97_pcm_open()
599 pcm->cur_dbl = r; in snd_ac97_pcm_open()
600 spin_unlock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_open()
605 if (pcm->r[r].rslots[cidx] & (1 << i)) { in snd_ac97_pcm_open()
608 dev_err(bus->card->dev, in snd_ac97_pcm_open()
612 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE))) in snd_ac97_pcm_open()
614 dev_dbg(bus->card->dev, in snd_ac97_pcm_open()
615 "setting ac97 reg 0x%x to rate %d\n", in snd_ac97_pcm_open()
616 reg, rate); in snd_ac97_pcm_open()
617 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate); in snd_ac97_pcm_open()
619 dev_err(bus->card->dev, in snd_ac97_pcm_open()
620 "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", in snd_ac97_pcm_open()
621 cidx, reg, rate, err); in snd_ac97_pcm_open()
623 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE)); in snd_ac97_pcm_open()
627 pcm->aslots = slots; in snd_ac97_pcm_open()
631 pcm->aslots = slots; in snd_ac97_pcm_open()
639 * snd_ac97_pcm_close - closes the given AC97 pcm
649 unsigned short slots = pcm->aslots; in snd_ac97_pcm_close()
653 int r = pcm->cur_dbl; in snd_ac97_pcm_close()
658 if (pcm->r[r].rslots[cidx] & (1 << i)) { in snd_ac97_pcm_close()
660 snd_ac97_update_power(pcm->r[r].codec[cidx], in snd_ac97_pcm_close()
667 bus = pcm->bus; in snd_ac97_pcm_close()
668 spin_lock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_close()
673 bus->used_slots[pcm->stream][cidx] &= ~(1 << i); in snd_ac97_pcm_close()
675 pcm->aslots = 0; in snd_ac97_pcm_close()
676 pcm->cur_dbl = 0; in snd_ac97_pcm_close()
677 spin_unlock_irq(&pcm->bus->bus_lock); in snd_ac97_pcm_close()
687 if (channels->min > 2) { in double_rate_hw_constraint_rate()
689 .min = 1, in double_rate_hw_constraint_rate()
692 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); in double_rate_hw_constraint_rate() local
693 return snd_interval_refine(rate, &single_rates); in double_rate_hw_constraint_rate()
701 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); in double_rate_hw_constraint_channels() local
702 if (rate->min > 48000) { in double_rate_hw_constraint_channels()
704 .min = 2, in double_rate_hw_constraint_channels()
714 * snd_ac97_pcm_double_rate_rules - set double rate constraints
728 SNDRV_PCM_HW_PARAM_CHANNELS, -1); in snd_ac97_pcm_double_rate_rules()
733 SNDRV_PCM_HW_PARAM_RATE, -1); in snd_ac97_pcm_double_rate_rules()