2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Universal interface for Audio Codec '97
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com) and to datasheets
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <sound/driver.h>
27 #include <linux/delay.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/mutex.h>
32 #include <sound/core.h>
33 #include <sound/pcm.h>
34 #include <sound/control.h>
35 #include <sound/ac97_codec.h>
36 #include <sound/asoundef.h>
37 #include "ac97_patch.h"
39 #include "ac97_local.h"
45 static unsigned char rate_reg_tables
[2][4][9] = {
49 /* 3&4 front, 7&8 rear, 6&9 center/lfe */
50 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
51 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
53 AC97_PCM_LFE_DAC_RATE
, /* slot 6 */
54 AC97_PCM_SURR_DAC_RATE
, /* slot 7 */
55 AC97_PCM_SURR_DAC_RATE
, /* slot 8 */
56 AC97_PCM_LFE_DAC_RATE
, /* slot 9 */
61 /* 7&8 front, 6&9 rear, 10&11 center/lfe */
65 AC97_PCM_SURR_DAC_RATE
, /* slot 6 */
66 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
67 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
68 AC97_PCM_SURR_DAC_RATE
, /* slot 9 */
69 AC97_PCM_LFE_DAC_RATE
, /* slot 10 */
70 AC97_PCM_LFE_DAC_RATE
, /* slot 11 */
73 /* 6&9 front, 10&11 rear, 3&4 center/lfe */
74 AC97_PCM_LFE_DAC_RATE
, /* slot 3 */
75 AC97_PCM_LFE_DAC_RATE
, /* slot 4 */
77 AC97_PCM_FRONT_DAC_RATE
, /* slot 6 */
80 AC97_PCM_FRONT_DAC_RATE
, /* slot 9 */
81 AC97_PCM_SURR_DAC_RATE
, /* slot 10 */
82 AC97_PCM_SURR_DAC_RATE
, /* slot 11 */
85 /* 10&11 front, 3&4 rear, 7&8 center/lfe */
86 AC97_PCM_SURR_DAC_RATE
, /* slot 3 */
87 AC97_PCM_SURR_DAC_RATE
, /* slot 4 */
90 AC97_PCM_LFE_DAC_RATE
, /* slot 7 */
91 AC97_PCM_LFE_DAC_RATE
, /* slot 8 */
93 AC97_PCM_FRONT_DAC_RATE
, /* slot 10 */
94 AC97_PCM_FRONT_DAC_RATE
, /* slot 11 */
100 /* 3&4 front, 7&8 front (t+1) */
101 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
102 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
105 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
106 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
112 /* not specified in the specification */
147 /* FIXME: more various mappings for ADC? */
148 static unsigned char rate_cregs
[9] = {
149 AC97_PCM_LR_ADC_RATE
, /* 3 */
150 AC97_PCM_LR_ADC_RATE
, /* 4 */
152 AC97_PCM_MIC_ADC_RATE
, /* 6 */
160 static unsigned char get_slot_reg(struct ac97_pcm
*pcm
, unsigned short cidx
,
161 unsigned short slot
, int dbl
)
168 return AC97_SPDIF
; /* pseudo register */
169 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
170 return rate_reg_tables
[dbl
][pcm
->r
[dbl
].rate_table
[cidx
]][slot
- 3];
172 return rate_cregs
[slot
- 3];
175 static int set_spdif_rate(struct snd_ac97
*ac97
, unsigned short rate
)
177 unsigned short old
, bits
, reg
, mask
;
180 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
183 /* TODO: double rate support */
184 if (ac97
->flags
& AC97_CS_SPDIF
) {
186 case 48000: bits
= 0; break;
187 case 44100: bits
= 1 << AC97_SC_SPSR_SHIFT
; break;
188 default: /* invalid - disable output */
189 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
192 reg
= AC97_CSR_SPDIF
;
193 mask
= 1 << AC97_SC_SPSR_SHIFT
;
195 if (ac97
->id
== AC97_ID_CM9739
&& rate
!= 48000) {
196 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
200 case 44100: bits
= AC97_SC_SPSR_44K
; break;
201 case 48000: bits
= AC97_SC_SPSR_48K
; break;
202 case 32000: bits
= AC97_SC_SPSR_32K
; break;
203 default: /* invalid - disable output */
204 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
208 mask
= AC97_SC_SPSR_MASK
;
211 mutex_lock(&ac97
->reg_mutex
);
212 old
= snd_ac97_read(ac97
, reg
) & mask
;
214 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
215 snd_ac97_update_bits_nolock(ac97
, reg
, mask
, bits
);
216 /* update the internal spdif bits */
217 sbits
= ac97
->spdif_status
;
218 if (sbits
& IEC958_AES0_PROFESSIONAL
) {
219 sbits
&= ~IEC958_AES0_PRO_FS
;
221 case 44100: sbits
|= IEC958_AES0_PRO_FS_44100
; break;
222 case 48000: sbits
|= IEC958_AES0_PRO_FS_48000
; break;
223 case 32000: sbits
|= IEC958_AES0_PRO_FS_32000
; break;
226 sbits
&= ~(IEC958_AES3_CON_FS
<< 24);
228 case 44100: sbits
|= IEC958_AES3_CON_FS_44100
<<24; break;
229 case 48000: sbits
|= IEC958_AES3_CON_FS_48000
<<24; break;
230 case 32000: sbits
|= IEC958_AES3_CON_FS_32000
<<24; break;
233 ac97
->spdif_status
= sbits
;
235 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, AC97_EA_SPDIF
);
236 mutex_unlock(&ac97
->reg_mutex
);
241 * snd_ac97_set_rate - change the rate of the given input/output.
242 * @ac97: the ac97 instance
243 * @reg: the register to change
244 * @rate: the sample rate to set
246 * Changes the rate of the given input/output on the codec.
247 * If the codec doesn't support VAR, the rate must be 48000 (except
250 * The valid registers are AC97_PMC_MIC_ADC_RATE,
251 * AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE.
252 * AC97_PCM_SURR_DAC_RATE and AC97_PCM_LFE_DAC_RATE are accepted
253 * if the codec supports them.
254 * AC97_SPDIF is accepted as a pseudo register to modify the SPDIF
257 * Returns zero if successful, or a negative error code on failure.
259 int snd_ac97_set_rate(struct snd_ac97
*ac97
, int reg
, unsigned int rate
)
266 if (!(ac97
->flags
& AC97_DOUBLE_RATE
))
268 if (reg
!= AC97_PCM_FRONT_DAC_RATE
)
273 case AC97_PCM_MIC_ADC_RATE
:
274 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRM
) == 0) /* MIC VRA */
278 case AC97_PCM_FRONT_DAC_RATE
:
279 case AC97_PCM_LR_ADC_RATE
:
280 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRA
) == 0) /* VRA */
281 if (rate
!= 48000 && rate
!= 96000)
284 case AC97_PCM_SURR_DAC_RATE
:
285 if (! (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
288 case AC97_PCM_LFE_DAC_RATE
:
289 if (! (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
294 return set_spdif_rate(ac97
, rate
);
300 tmp
= (rate
* ac97
->bus
->clock
) / 48000;
303 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
)
304 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
,
305 AC97_EA_DRA
, dbl
? AC97_EA_DRA
: 0);
306 snd_ac97_update(ac97
, reg
, tmp
& 0xffff);
307 snd_ac97_read(ac97
, reg
);
308 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
) {
309 /* Intel controllers require double rate data to be put in
312 snd_ac97_update_bits(ac97
, AC97_GENERAL_PURPOSE
,
314 dbl
? AC97_GP_DRSS_78
: 0);
315 snd_ac97_read(ac97
, AC97_GENERAL_PURPOSE
);
320 static unsigned short get_pslots(struct snd_ac97
*ac97
, unsigned char *rate_table
, unsigned short *spdif_slots
)
322 if (!ac97_is_audio(ac97
))
324 if (ac97_is_rev22(ac97
) || ac97_can_amap(ac97
)) {
325 unsigned short slots
= 0;
326 if (ac97_is_rev22(ac97
)) {
327 /* Note: it's simply emulation of AMAP behaviour */
329 es
= ac97
->regs
[AC97_EXTENDED_ID
] &= ~AC97_EI_DACS_SLOT_MASK
;
330 switch (ac97
->addr
) {
332 case 2: es
|= (1<<AC97_EI_DACS_SLOT_SHIFT
); break;
333 case 3: es
|= (2<<AC97_EI_DACS_SLOT_SHIFT
); break;
335 snd_ac97_write_cache(ac97
, AC97_EXTENDED_ID
, es
);
337 switch (ac97
->addr
) {
339 slots
|= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
340 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
341 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
342 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
343 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
344 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
345 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
346 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
347 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_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
);
356 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
357 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
358 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
359 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
360 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
361 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
363 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
368 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
369 if (ac97
->ext_id
& AC97_EI_SPDIF
)
370 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
376 unsigned short slots
;
377 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
378 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
379 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
380 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
381 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
382 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
383 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
384 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
385 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
386 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
388 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
395 static unsigned short get_cslots(struct snd_ac97
*ac97
)
397 unsigned short slots
;
399 if (!ac97_is_audio(ac97
))
401 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
402 slots
|= (1<<AC97_SLOT_MIC
);
406 static unsigned int get_rates(struct ac97_pcm
*pcm
, unsigned int cidx
, unsigned short slots
, int dbl
)
409 unsigned int rates
= ~0;
412 for (i
= 3; i
< 12; i
++) {
413 if (!(slots
& (1 << i
)))
415 reg
= get_slot_reg(pcm
, cidx
, i
, dbl
);
417 case AC97_PCM_FRONT_DAC_RATE
: idx
= AC97_RATES_FRONT_DAC
; break;
418 case AC97_PCM_SURR_DAC_RATE
: idx
= AC97_RATES_SURR_DAC
; break;
419 case AC97_PCM_LFE_DAC_RATE
: idx
= AC97_RATES_LFE_DAC
; break;
420 case AC97_PCM_LR_ADC_RATE
: idx
= AC97_RATES_ADC
; break;
421 case AC97_PCM_MIC_ADC_RATE
: idx
= AC97_RATES_MIC_ADC
; break;
422 default: idx
= AC97_RATES_SPDIF
; break;
424 rates
&= pcm
->r
[dbl
].codec
[cidx
]->rates
[idx
];
427 rates
&= ~(SNDRV_PCM_RATE_64000
| SNDRV_PCM_RATE_88200
|
428 SNDRV_PCM_RATE_96000
);
433 * snd_ac97_pcm_assign - assign AC97 slots to given PCM streams
434 * @bus: the ac97 bus instance
435 * @pcms_count: count of PCMs to be assigned
436 * @pcms: PCMs to be assigned
438 * It assigns available AC97 slots for given PCMs. If none or only
439 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
440 * are reduced and might be zero.
442 int snd_ac97_pcm_assign(struct snd_ac97_bus
*bus
,
443 unsigned short pcms_count
,
444 const struct ac97_pcm
*pcms
)
447 const struct ac97_pcm
*pcm
;
448 struct ac97_pcm
*rpcms
, *rpcm
;
449 unsigned short avail_slots
[2][4];
450 unsigned char rate_table
[2][4];
451 unsigned short tmp
, slots
;
452 unsigned short spdif_slots
[4];
454 struct snd_ac97
*codec
;
456 rpcms
= kcalloc(pcms_count
, sizeof(struct ac97_pcm
), GFP_KERNEL
);
459 memset(avail_slots
, 0, sizeof(avail_slots
));
460 memset(rate_table
, 0, sizeof(rate_table
));
461 memset(spdif_slots
, 0, sizeof(spdif_slots
));
462 for (i
= 0; i
< 4; i
++) {
463 codec
= bus
->codec
[i
];
466 avail_slots
[0][i
] = get_pslots(codec
, &rate_table
[0][i
], &spdif_slots
[i
]);
467 avail_slots
[1][i
] = get_cslots(codec
);
468 if (!(codec
->scaps
& AC97_SCAP_INDEP_SDIN
)) {
469 for (j
= 0; j
< i
; j
++) {
471 avail_slots
[1][i
] &= ~avail_slots
[1][j
];
475 /* first step - exclusive devices */
476 for (i
= 0; i
< pcms_count
; i
++) {
479 /* low-level driver thinks that it's more clever */
480 if (pcm
->copy_flag
) {
484 rpcm
->stream
= pcm
->stream
;
485 rpcm
->exclusive
= pcm
->exclusive
;
486 rpcm
->spdif
= pcm
->spdif
;
487 rpcm
->private_value
= pcm
->private_value
;
490 slots
= pcm
->r
[0].slots
;
491 for (j
= 0; j
< 4 && slots
; j
++) {
495 if (pcm
->spdif
&& pcm
->stream
== 0)
496 tmp
= spdif_slots
[j
];
498 tmp
= avail_slots
[pcm
->stream
][j
];
499 if (pcm
->exclusive
) {
500 /* exclusive access */
502 for (k
= 0; k
< i
; k
++) {
503 if (rpcm
->stream
== rpcms
[k
].stream
)
504 tmp
&= ~rpcms
[k
].r
[0].rslots
[j
];
507 /* non-exclusive access */
508 tmp
&= pcm
->r
[0].slots
;
511 rpcm
->r
[0].rslots
[j
] = tmp
;
512 rpcm
->r
[0].codec
[j
] = bus
->codec
[j
];
513 rpcm
->r
[0].rate_table
[j
] = rate_table
[pcm
->stream
][j
];
515 rates
= SNDRV_PCM_RATE_48000
;
517 rates
= get_rates(rpcm
, j
, tmp
, 0);
519 avail_slots
[pcm
->stream
][j
] &= ~tmp
;
522 rpcm
->r
[0].slots
|= tmp
;
523 rpcm
->rates
&= rates
;
525 /* for double rate, we check the first codec only */
526 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
527 bus
->codec
[0] && (bus
->codec
[0]->flags
& AC97_DOUBLE_RATE
) &&
528 rate_table
[pcm
->stream
][0] == 0) {
529 tmp
= (1<<AC97_SLOT_PCM_LEFT
) | (1<<AC97_SLOT_PCM_RIGHT
) |
530 (1<<AC97_SLOT_PCM_LEFT_0
) | (1<<AC97_SLOT_PCM_RIGHT_0
);
531 if ((tmp
& pcm
->r
[1].slots
) == tmp
) {
532 rpcm
->r
[1].slots
= tmp
;
533 rpcm
->r
[1].rslots
[0] = tmp
;
534 rpcm
->r
[1].rate_table
[0] = 0;
535 rpcm
->r
[1].codec
[0] = bus
->codec
[0];
537 avail_slots
[pcm
->stream
][0] &= ~tmp
;
539 rates
= SNDRV_PCM_RATE_96000
;
541 rates
= get_rates(rpcm
, 0, tmp
, 1);
542 rpcm
->rates
|= rates
;
545 if (rpcm
->rates
== ~0)
546 rpcm
->rates
= 0; /* not used */
548 bus
->pcms_count
= pcms_count
;
554 * snd_ac97_pcm_open - opens the given AC97 pcm
555 * @pcm: the ac97 pcm instance
556 * @rate: rate in Hz, if codec does not support VRA, this value must be 48000Hz
557 * @cfg: output stream characteristics
558 * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm
560 * It locks the specified slots and sets the given rate to AC97 registers.
562 int snd_ac97_pcm_open(struct ac97_pcm
*pcm
, unsigned int rate
,
563 enum ac97_pcm_cfg cfg
, unsigned short slots
)
565 struct snd_ac97_bus
*bus
;
566 int i
, cidx
, r
, ok_flag
;
567 unsigned int reg_ok
[4] = {0,0,0,0};
573 if (cfg
== AC97_PCM_CFG_SPDIF
) {
575 for (cidx
= 0; cidx
< 4; cidx
++)
576 if (bus
->codec
[cidx
] && (bus
->codec
[cidx
]->ext_id
& AC97_EI_SPDIF
)) {
577 err
= set_spdif_rate(bus
->codec
[cidx
], rate
);
582 spin_lock_irq(&pcm
->bus
->bus_lock
);
583 for (i
= 3; i
< 12; i
++) {
584 if (!(slots
& (1 << i
)))
587 for (cidx
= 0; cidx
< 4; cidx
++) {
588 if (bus
->used_slots
[pcm
->stream
][cidx
] & (1 << i
)) {
589 spin_unlock_irq(&pcm
->bus
->bus_lock
);
593 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
594 bus
->used_slots
[pcm
->stream
][cidx
] |= (1 << i
);
599 spin_unlock_irq(&pcm
->bus
->bus_lock
);
600 snd_printk(KERN_ERR
"cannot find configuration for AC97 slot %i\n", i
);
605 spin_unlock_irq(&pcm
->bus
->bus_lock
);
606 for (i
= 3; i
< 12; i
++) {
607 if (!(slots
& (1 << i
)))
609 for (cidx
= 0; cidx
< 4; cidx
++) {
610 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
611 reg
= get_slot_reg(pcm
, cidx
, i
, r
);
613 snd_printk(KERN_ERR
"invalid AC97 slot %i?\n", i
);
616 if (reg_ok
[cidx
] & (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
)))
618 //printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate);
619 err
= snd_ac97_set_rate(pcm
->r
[r
].codec
[cidx
], reg
, rate
);
621 snd_printk(KERN_ERR
"error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx
, reg
, rate
, err
);
623 reg_ok
[cidx
] |= (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
));
632 snd_ac97_pcm_close(pcm
);
637 * snd_ac97_pcm_close - closes the given AC97 pcm
638 * @pcm: the ac97 pcm instance
640 * It frees the locked AC97 slots.
642 int snd_ac97_pcm_close(struct ac97_pcm
*pcm
)
644 struct snd_ac97_bus
*bus
;
645 unsigned short slots
= pcm
->aslots
;
649 spin_lock_irq(&pcm
->bus
->bus_lock
);
650 for (i
= 3; i
< 12; i
++) {
651 if (!(slots
& (1 << i
)))
653 for (cidx
= 0; cidx
< 4; cidx
++)
654 bus
->used_slots
[pcm
->stream
][cidx
] &= ~(1 << i
);
657 spin_unlock_irq(&pcm
->bus
->bus_lock
);
661 static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params
*params
,
662 struct snd_pcm_hw_rule
*rule
)
664 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
665 if (channels
->min
> 2) {
666 static const struct snd_interval single_rates
= {
670 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
671 return snd_interval_refine(rate
, &single_rates
);
676 static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params
*params
,
677 struct snd_pcm_hw_rule
*rule
)
679 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
680 if (rate
->min
> 48000) {
681 static const struct snd_interval double_rate_channels
= {
685 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
686 return snd_interval_refine(channels
, &double_rate_channels
);
692 * snd_ac97_pcm_double_rate_rules - set double rate constraints
693 * @runtime: the runtime of the ac97 front playback pcm
695 * Installs the hardware constraint rules to prevent using double rates and
696 * more than two channels at the same time.
698 int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime
*runtime
)
702 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
703 double_rate_hw_constraint_rate
, NULL
,
704 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
707 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
708 double_rate_hw_constraint_channels
, NULL
,
709 SNDRV_PCM_HW_PARAM_RATE
, -1);