1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 * Universal interface for Audio Codec '97
6 * For more details look to AC '97 component specification revision 2.2
7 * by Intel Corporation (http://developer.intel.com) and to datasheets
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
15 #include <linux/export.h>
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/control.h>
20 #include <sound/ac97_codec.h>
21 #include <sound/asoundef.h>
23 #include "ac97_local.h"
29 static const unsigned char rate_reg_tables
[2][4][9] = {
33 /* 3&4 front, 7&8 rear, 6&9 center/lfe */
34 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
35 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
37 AC97_PCM_LFE_DAC_RATE
, /* slot 6 */
38 AC97_PCM_SURR_DAC_RATE
, /* slot 7 */
39 AC97_PCM_SURR_DAC_RATE
, /* slot 8 */
40 AC97_PCM_LFE_DAC_RATE
, /* slot 9 */
45 /* 7&8 front, 6&9 rear, 10&11 center/lfe */
49 AC97_PCM_SURR_DAC_RATE
, /* slot 6 */
50 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
51 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
52 AC97_PCM_SURR_DAC_RATE
, /* slot 9 */
53 AC97_PCM_LFE_DAC_RATE
, /* slot 10 */
54 AC97_PCM_LFE_DAC_RATE
, /* slot 11 */
57 /* 6&9 front, 10&11 rear, 3&4 center/lfe */
58 AC97_PCM_LFE_DAC_RATE
, /* slot 3 */
59 AC97_PCM_LFE_DAC_RATE
, /* slot 4 */
61 AC97_PCM_FRONT_DAC_RATE
, /* slot 6 */
64 AC97_PCM_FRONT_DAC_RATE
, /* slot 9 */
65 AC97_PCM_SURR_DAC_RATE
, /* slot 10 */
66 AC97_PCM_SURR_DAC_RATE
, /* slot 11 */
69 /* 10&11 front, 3&4 rear, 7&8 center/lfe */
70 AC97_PCM_SURR_DAC_RATE
, /* slot 3 */
71 AC97_PCM_SURR_DAC_RATE
, /* slot 4 */
74 AC97_PCM_LFE_DAC_RATE
, /* slot 7 */
75 AC97_PCM_LFE_DAC_RATE
, /* slot 8 */
77 AC97_PCM_FRONT_DAC_RATE
, /* slot 10 */
78 AC97_PCM_FRONT_DAC_RATE
, /* slot 11 */
84 /* 3&4 front, 7&8 front (t+1) */
85 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
86 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
89 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
90 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
96 /* not specified in the specification */
131 /* FIXME: more various mappings for ADC? */
132 static const unsigned char rate_cregs
[9] = {
133 AC97_PCM_LR_ADC_RATE
, /* 3 */
134 AC97_PCM_LR_ADC_RATE
, /* 4 */
136 AC97_PCM_MIC_ADC_RATE
, /* 6 */
144 static unsigned char get_slot_reg(struct ac97_pcm
*pcm
, unsigned short cidx
,
145 unsigned short slot
, int dbl
)
152 return AC97_SPDIF
; /* pseudo register */
153 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
154 return rate_reg_tables
[dbl
][pcm
->r
[dbl
].rate_table
[cidx
]][slot
- 3];
156 return rate_cregs
[slot
- 3];
159 static int set_spdif_rate(struct snd_ac97
*ac97
, unsigned short rate
)
161 unsigned short old
, bits
, reg
, mask
;
164 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
167 /* TODO: double rate support */
168 if (ac97
->flags
& AC97_CS_SPDIF
) {
170 case 48000: bits
= 0; break;
171 case 44100: bits
= 1 << AC97_SC_SPSR_SHIFT
; break;
172 default: /* invalid - disable output */
173 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
176 reg
= AC97_CSR_SPDIF
;
177 mask
= 1 << AC97_SC_SPSR_SHIFT
;
179 if (ac97
->id
== AC97_ID_CM9739
&& rate
!= 48000) {
180 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
184 case 44100: bits
= AC97_SC_SPSR_44K
; break;
185 case 48000: bits
= AC97_SC_SPSR_48K
; break;
186 case 32000: bits
= AC97_SC_SPSR_32K
; break;
187 default: /* invalid - disable output */
188 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
192 mask
= AC97_SC_SPSR_MASK
;
195 mutex_lock(&ac97
->reg_mutex
);
196 old
= snd_ac97_read(ac97
, reg
) & mask
;
198 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
199 snd_ac97_update_bits_nolock(ac97
, reg
, mask
, bits
);
200 /* update the internal spdif bits */
201 sbits
= ac97
->spdif_status
;
202 if (sbits
& IEC958_AES0_PROFESSIONAL
) {
203 sbits
&= ~IEC958_AES0_PRO_FS
;
205 case 44100: sbits
|= IEC958_AES0_PRO_FS_44100
; break;
206 case 48000: sbits
|= IEC958_AES0_PRO_FS_48000
; break;
207 case 32000: sbits
|= IEC958_AES0_PRO_FS_32000
; break;
210 sbits
&= ~(IEC958_AES3_CON_FS
<< 24);
212 case 44100: sbits
|= IEC958_AES3_CON_FS_44100
<<24; break;
213 case 48000: sbits
|= IEC958_AES3_CON_FS_48000
<<24; break;
214 case 32000: sbits
|= IEC958_AES3_CON_FS_32000
<<24; break;
217 ac97
->spdif_status
= sbits
;
219 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, AC97_EA_SPDIF
);
220 mutex_unlock(&ac97
->reg_mutex
);
225 * snd_ac97_set_rate - change the rate of the given input/output.
226 * @ac97: the ac97 instance
227 * @reg: the register to change
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
234 * The valid registers are AC97_PMC_MIC_ADC_RATE,
235 * AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE.
236 * AC97_PCM_SURR_DAC_RATE and AC97_PCM_LFE_DAC_RATE are accepted
237 * if the codec supports them.
238 * AC97_SPDIF is accepted as a pseudo register to modify the SPDIF
241 * Return: Zero if successful, or a negative error code on failure.
243 int snd_ac97_set_rate(struct snd_ac97
*ac97
, int reg
, unsigned int rate
)
250 if (!(ac97
->flags
& AC97_DOUBLE_RATE
))
252 if (reg
!= AC97_PCM_FRONT_DAC_RATE
)
256 snd_ac97_update_power(ac97
, reg
, 1);
258 case AC97_PCM_MIC_ADC_RATE
:
259 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRM
) == 0) /* MIC VRA */
263 case AC97_PCM_FRONT_DAC_RATE
:
264 case AC97_PCM_LR_ADC_RATE
:
265 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRA
) == 0) /* VRA */
266 if (rate
!= 48000 && rate
!= 96000)
269 case AC97_PCM_SURR_DAC_RATE
:
270 if (! (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
273 case AC97_PCM_LFE_DAC_RATE
:
274 if (! (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
279 return set_spdif_rate(ac97
, rate
);
285 tmp
= (rate
* ac97
->bus
->clock
) / 48000;
288 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
)
289 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
,
290 AC97_EA_DRA
, dbl
? AC97_EA_DRA
: 0);
291 snd_ac97_update(ac97
, reg
, tmp
& 0xffff);
292 snd_ac97_read(ac97
, reg
);
293 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
) {
294 /* Intel controllers require double rate data to be put in
297 snd_ac97_update_bits(ac97
, AC97_GENERAL_PURPOSE
,
299 dbl
? AC97_GP_DRSS_78
: 0);
300 snd_ac97_read(ac97
, AC97_GENERAL_PURPOSE
);
305 EXPORT_SYMBOL(snd_ac97_set_rate
);
307 static unsigned short get_pslots(struct snd_ac97
*ac97
, unsigned char *rate_table
, unsigned short *spdif_slots
)
309 if (!ac97_is_audio(ac97
))
311 if (ac97_is_rev22(ac97
) || ac97_can_amap(ac97
)) {
312 unsigned short slots
= 0;
313 if (ac97_is_rev22(ac97
)) {
314 /* Note: it's simply emulation of AMAP behaviour */
316 es
= ac97
->regs
[AC97_EXTENDED_ID
] &= ~AC97_EI_DACS_SLOT_MASK
;
317 switch (ac97
->addr
) {
319 case 2: es
|= (1<<AC97_EI_DACS_SLOT_SHIFT
); break;
320 case 3: es
|= (2<<AC97_EI_DACS_SLOT_SHIFT
); break;
322 snd_ac97_write_cache(ac97
, AC97_EXTENDED_ID
, es
);
324 switch (ac97
->addr
) {
326 slots
|= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
327 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
328 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
329 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
330 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
331 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
332 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
333 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
334 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
335 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
337 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
343 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
344 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
345 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
346 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
347 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
348 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
350 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
355 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
356 if (ac97
->ext_id
& AC97_EI_SPDIF
)
357 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
363 unsigned short slots
;
364 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
365 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
366 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
367 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
368 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
369 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
370 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
371 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
372 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
373 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
375 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
382 static unsigned short get_cslots(struct snd_ac97
*ac97
)
384 unsigned short slots
;
386 if (!ac97_is_audio(ac97
))
388 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
389 slots
|= (1<<AC97_SLOT_MIC
);
393 static unsigned int get_rates(struct ac97_pcm
*pcm
, unsigned int cidx
, unsigned short slots
, int dbl
)
396 unsigned int rates
= ~0;
399 for (i
= 3; i
< 12; i
++) {
400 if (!(slots
& (1 << i
)))
402 reg
= get_slot_reg(pcm
, cidx
, i
, dbl
);
404 case AC97_PCM_FRONT_DAC_RATE
: idx
= AC97_RATES_FRONT_DAC
; break;
405 case AC97_PCM_SURR_DAC_RATE
: idx
= AC97_RATES_SURR_DAC
; break;
406 case AC97_PCM_LFE_DAC_RATE
: idx
= AC97_RATES_LFE_DAC
; break;
407 case AC97_PCM_LR_ADC_RATE
: idx
= AC97_RATES_ADC
; break;
408 case AC97_PCM_MIC_ADC_RATE
: idx
= AC97_RATES_MIC_ADC
; break;
409 default: idx
= AC97_RATES_SPDIF
; break;
411 rates
&= pcm
->r
[dbl
].codec
[cidx
]->rates
[idx
];
414 rates
&= ~(SNDRV_PCM_RATE_64000
| SNDRV_PCM_RATE_88200
|
415 SNDRV_PCM_RATE_96000
);
420 * snd_ac97_pcm_assign - assign AC97 slots to given PCM streams
421 * @bus: the ac97 bus instance
422 * @pcms_count: count of PCMs to be assigned
423 * @pcms: PCMs to be assigned
425 * It assigns available AC97 slots for given PCMs. If none or only
426 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
427 * are reduced and might be zero.
429 * Return: Zero if successful, or a negative error code on failure.
431 int snd_ac97_pcm_assign(struct snd_ac97_bus
*bus
,
432 unsigned short pcms_count
,
433 const struct ac97_pcm
*pcms
)
436 const struct ac97_pcm
*pcm
;
437 struct ac97_pcm
*rpcms
, *rpcm
;
438 unsigned short avail_slots
[2][4];
439 unsigned char rate_table
[2][4];
440 unsigned short tmp
, slots
;
441 unsigned short spdif_slots
[4];
443 struct snd_ac97
*codec
;
445 rpcms
= kcalloc(pcms_count
, sizeof(struct ac97_pcm
), GFP_KERNEL
);
448 memset(avail_slots
, 0, sizeof(avail_slots
));
449 memset(rate_table
, 0, sizeof(rate_table
));
450 memset(spdif_slots
, 0, sizeof(spdif_slots
));
451 for (i
= 0; i
< 4; i
++) {
452 codec
= bus
->codec
[i
];
455 avail_slots
[0][i
] = get_pslots(codec
, &rate_table
[0][i
], &spdif_slots
[i
]);
456 avail_slots
[1][i
] = get_cslots(codec
);
457 if (!(codec
->scaps
& AC97_SCAP_INDEP_SDIN
)) {
458 for (j
= 0; j
< i
; j
++) {
460 avail_slots
[1][i
] &= ~avail_slots
[1][j
];
464 /* first step - exclusive devices */
465 for (i
= 0; i
< pcms_count
; i
++) {
468 /* low-level driver thinks that it's more clever */
469 if (pcm
->copy_flag
) {
473 rpcm
->stream
= pcm
->stream
;
474 rpcm
->exclusive
= pcm
->exclusive
;
475 rpcm
->spdif
= pcm
->spdif
;
476 rpcm
->private_value
= pcm
->private_value
;
479 slots
= pcm
->r
[0].slots
;
480 for (j
= 0; j
< 4 && slots
; j
++) {
484 if (pcm
->spdif
&& pcm
->stream
== 0)
485 tmp
= spdif_slots
[j
];
487 tmp
= avail_slots
[pcm
->stream
][j
];
488 if (pcm
->exclusive
) {
489 /* exclusive access */
491 for (k
= 0; k
< i
; k
++) {
492 if (rpcm
->stream
== rpcms
[k
].stream
)
493 tmp
&= ~rpcms
[k
].r
[0].rslots
[j
];
496 /* non-exclusive access */
497 tmp
&= pcm
->r
[0].slots
;
500 rpcm
->r
[0].rslots
[j
] = tmp
;
501 rpcm
->r
[0].codec
[j
] = bus
->codec
[j
];
502 rpcm
->r
[0].rate_table
[j
] = rate_table
[pcm
->stream
][j
];
504 rates
= SNDRV_PCM_RATE_48000
;
506 rates
= get_rates(rpcm
, j
, tmp
, 0);
508 avail_slots
[pcm
->stream
][j
] &= ~tmp
;
511 rpcm
->r
[0].slots
|= tmp
;
512 rpcm
->rates
&= rates
;
514 /* for double rate, we check the first codec only */
515 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
516 bus
->codec
[0] && (bus
->codec
[0]->flags
& AC97_DOUBLE_RATE
) &&
517 rate_table
[pcm
->stream
][0] == 0) {
518 tmp
= (1<<AC97_SLOT_PCM_LEFT
) | (1<<AC97_SLOT_PCM_RIGHT
) |
519 (1<<AC97_SLOT_PCM_LEFT_0
) | (1<<AC97_SLOT_PCM_RIGHT_0
);
520 if ((tmp
& pcm
->r
[1].slots
) == tmp
) {
521 rpcm
->r
[1].slots
= tmp
;
522 rpcm
->r
[1].rslots
[0] = tmp
;
523 rpcm
->r
[1].rate_table
[0] = 0;
524 rpcm
->r
[1].codec
[0] = bus
->codec
[0];
526 avail_slots
[pcm
->stream
][0] &= ~tmp
;
528 rates
= SNDRV_PCM_RATE_96000
;
530 rates
= get_rates(rpcm
, 0, tmp
, 1);
531 rpcm
->rates
|= rates
;
534 if (rpcm
->rates
== ~0)
535 rpcm
->rates
= 0; /* not used */
537 bus
->pcms_count
= pcms_count
;
542 EXPORT_SYMBOL(snd_ac97_pcm_assign
);
545 * snd_ac97_pcm_open - opens the given AC97 pcm
546 * @pcm: the ac97 pcm instance
547 * @rate: rate in Hz, if codec does not support VRA, this value must be 48000Hz
548 * @cfg: output stream characteristics
549 * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm
551 * It locks the specified slots and sets the given rate to AC97 registers.
553 * Return: Zero if successful, or a negative error code on failure.
555 int snd_ac97_pcm_open(struct ac97_pcm
*pcm
, unsigned int rate
,
556 enum ac97_pcm_cfg cfg
, unsigned short slots
)
558 struct snd_ac97_bus
*bus
;
559 int i
, cidx
, r
, ok_flag
;
560 unsigned int reg_ok
[4] = {0,0,0,0};
566 if (cfg
== AC97_PCM_CFG_SPDIF
) {
567 for (cidx
= 0; cidx
< 4; cidx
++)
568 if (bus
->codec
[cidx
] && (bus
->codec
[cidx
]->ext_id
& AC97_EI_SPDIF
)) {
569 err
= set_spdif_rate(bus
->codec
[cidx
], rate
);
574 spin_lock_irq(&pcm
->bus
->bus_lock
);
575 for (i
= 3; i
< 12; i
++) {
576 if (!(slots
& (1 << i
)))
579 for (cidx
= 0; cidx
< 4; cidx
++) {
580 if (bus
->used_slots
[pcm
->stream
][cidx
] & (1 << i
)) {
581 spin_unlock_irq(&pcm
->bus
->bus_lock
);
585 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
586 bus
->used_slots
[pcm
->stream
][cidx
] |= (1 << i
);
591 spin_unlock_irq(&pcm
->bus
->bus_lock
);
592 dev_err(bus
->card
->dev
,
593 "cannot find configuration for AC97 slot %i\n",
600 spin_unlock_irq(&pcm
->bus
->bus_lock
);
601 for (i
= 3; i
< 12; i
++) {
602 if (!(slots
& (1 << i
)))
604 for (cidx
= 0; cidx
< 4; cidx
++) {
605 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
606 reg
= get_slot_reg(pcm
, cidx
, i
, r
);
608 dev_err(bus
->card
->dev
,
609 "invalid AC97 slot %i?\n", i
);
612 if (reg_ok
[cidx
] & (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
)))
614 dev_dbg(bus
->card
->dev
,
615 "setting ac97 reg 0x%x to rate %d\n",
617 err
= snd_ac97_set_rate(pcm
->r
[r
].codec
[cidx
], reg
, rate
);
619 dev_err(bus
->card
->dev
,
620 "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n",
621 cidx
, reg
, rate
, err
);
623 reg_ok
[cidx
] |= (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
));
632 snd_ac97_pcm_close(pcm
);
636 EXPORT_SYMBOL(snd_ac97_pcm_open
);
639 * snd_ac97_pcm_close - closes the given AC97 pcm
640 * @pcm: the ac97 pcm instance
642 * It frees the locked AC97 slots.
646 int snd_ac97_pcm_close(struct ac97_pcm
*pcm
)
648 struct snd_ac97_bus
*bus
;
649 unsigned short slots
= pcm
->aslots
;
652 #ifdef CONFIG_SND_AC97_POWER_SAVE
653 int r
= pcm
->cur_dbl
;
654 for (i
= 3; i
< 12; i
++) {
655 if (!(slots
& (1 << i
)))
657 for (cidx
= 0; cidx
< 4; cidx
++) {
658 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
659 int reg
= get_slot_reg(pcm
, cidx
, i
, r
);
660 snd_ac97_update_power(pcm
->r
[r
].codec
[cidx
],
668 spin_lock_irq(&pcm
->bus
->bus_lock
);
669 for (i
= 3; i
< 12; i
++) {
670 if (!(slots
& (1 << i
)))
672 for (cidx
= 0; cidx
< 4; cidx
++)
673 bus
->used_slots
[pcm
->stream
][cidx
] &= ~(1 << i
);
677 spin_unlock_irq(&pcm
->bus
->bus_lock
);
681 EXPORT_SYMBOL(snd_ac97_pcm_close
);
683 static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params
*params
,
684 struct snd_pcm_hw_rule
*rule
)
686 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
687 if (channels
->min
> 2) {
688 static const struct snd_interval single_rates
= {
692 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
693 return snd_interval_refine(rate
, &single_rates
);
698 static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params
*params
,
699 struct snd_pcm_hw_rule
*rule
)
701 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
702 if (rate
->min
> 48000) {
703 static const struct snd_interval double_rate_channels
= {
707 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
708 return snd_interval_refine(channels
, &double_rate_channels
);
714 * snd_ac97_pcm_double_rate_rules - set double rate constraints
715 * @runtime: the runtime of the ac97 front playback pcm
717 * Installs the hardware constraint rules to prevent using double rates and
718 * more than two channels at the same time.
720 * Return: Zero if successful, or a negative error code on failure.
722 int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime
*runtime
)
726 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
727 double_rate_hw_constraint_rate
, NULL
,
728 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
731 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
732 double_rate_hw_constraint_channels
, NULL
,
733 SNDRV_PCM_HW_PARAM_RATE
, -1);
737 EXPORT_SYMBOL(snd_ac97_pcm_double_rate_rules
);