2 * Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/mutex.h>
31 #include <sound/core.h>
32 #include <sound/pcm.h>
33 #include <sound/control.h>
34 #include <sound/ac97_codec.h>
35 #include <sound/asoundef.h>
37 #include "ac97_local.h"
43 static unsigned char rate_reg_tables
[2][4][9] = {
47 /* 3&4 front, 7&8 rear, 6&9 center/lfe */
48 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
49 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
51 AC97_PCM_LFE_DAC_RATE
, /* slot 6 */
52 AC97_PCM_SURR_DAC_RATE
, /* slot 7 */
53 AC97_PCM_SURR_DAC_RATE
, /* slot 8 */
54 AC97_PCM_LFE_DAC_RATE
, /* slot 9 */
59 /* 7&8 front, 6&9 rear, 10&11 center/lfe */
63 AC97_PCM_SURR_DAC_RATE
, /* slot 6 */
64 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
65 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
66 AC97_PCM_SURR_DAC_RATE
, /* slot 9 */
67 AC97_PCM_LFE_DAC_RATE
, /* slot 10 */
68 AC97_PCM_LFE_DAC_RATE
, /* slot 11 */
71 /* 6&9 front, 10&11 rear, 3&4 center/lfe */
72 AC97_PCM_LFE_DAC_RATE
, /* slot 3 */
73 AC97_PCM_LFE_DAC_RATE
, /* slot 4 */
75 AC97_PCM_FRONT_DAC_RATE
, /* slot 6 */
78 AC97_PCM_FRONT_DAC_RATE
, /* slot 9 */
79 AC97_PCM_SURR_DAC_RATE
, /* slot 10 */
80 AC97_PCM_SURR_DAC_RATE
, /* slot 11 */
83 /* 10&11 front, 3&4 rear, 7&8 center/lfe */
84 AC97_PCM_SURR_DAC_RATE
, /* slot 3 */
85 AC97_PCM_SURR_DAC_RATE
, /* slot 4 */
88 AC97_PCM_LFE_DAC_RATE
, /* slot 7 */
89 AC97_PCM_LFE_DAC_RATE
, /* slot 8 */
91 AC97_PCM_FRONT_DAC_RATE
, /* slot 10 */
92 AC97_PCM_FRONT_DAC_RATE
, /* slot 11 */
98 /* 3&4 front, 7&8 front (t+1) */
99 AC97_PCM_FRONT_DAC_RATE
, /* slot 3 */
100 AC97_PCM_FRONT_DAC_RATE
, /* slot 4 */
103 AC97_PCM_FRONT_DAC_RATE
, /* slot 7 */
104 AC97_PCM_FRONT_DAC_RATE
, /* slot 8 */
110 /* not specified in the specification */
145 /* FIXME: more various mappings for ADC? */
146 static unsigned char rate_cregs
[9] = {
147 AC97_PCM_LR_ADC_RATE
, /* 3 */
148 AC97_PCM_LR_ADC_RATE
, /* 4 */
150 AC97_PCM_MIC_ADC_RATE
, /* 6 */
158 static unsigned char get_slot_reg(struct ac97_pcm
*pcm
, unsigned short cidx
,
159 unsigned short slot
, int dbl
)
166 return AC97_SPDIF
; /* pseudo register */
167 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
168 return rate_reg_tables
[dbl
][pcm
->r
[dbl
].rate_table
[cidx
]][slot
- 3];
170 return rate_cregs
[slot
- 3];
173 static int set_spdif_rate(struct snd_ac97
*ac97
, unsigned short rate
)
175 unsigned short old
, bits
, reg
, mask
;
178 if (! (ac97
->ext_id
& AC97_EI_SPDIF
))
181 /* TODO: double rate support */
182 if (ac97
->flags
& AC97_CS_SPDIF
) {
184 case 48000: bits
= 0; break;
185 case 44100: bits
= 1 << AC97_SC_SPSR_SHIFT
; break;
186 default: /* invalid - disable output */
187 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
190 reg
= AC97_CSR_SPDIF
;
191 mask
= 1 << AC97_SC_SPSR_SHIFT
;
193 if (ac97
->id
== AC97_ID_CM9739
&& rate
!= 48000) {
194 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
198 case 44100: bits
= AC97_SC_SPSR_44K
; break;
199 case 48000: bits
= AC97_SC_SPSR_48K
; break;
200 case 32000: bits
= AC97_SC_SPSR_32K
; break;
201 default: /* invalid - disable output */
202 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
206 mask
= AC97_SC_SPSR_MASK
;
209 mutex_lock(&ac97
->reg_mutex
);
210 old
= snd_ac97_read(ac97
, reg
) & mask
;
212 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, 0);
213 snd_ac97_update_bits_nolock(ac97
, reg
, mask
, bits
);
214 /* update the internal spdif bits */
215 sbits
= ac97
->spdif_status
;
216 if (sbits
& IEC958_AES0_PROFESSIONAL
) {
217 sbits
&= ~IEC958_AES0_PRO_FS
;
219 case 44100: sbits
|= IEC958_AES0_PRO_FS_44100
; break;
220 case 48000: sbits
|= IEC958_AES0_PRO_FS_48000
; break;
221 case 32000: sbits
|= IEC958_AES0_PRO_FS_32000
; break;
224 sbits
&= ~(IEC958_AES3_CON_FS
<< 24);
226 case 44100: sbits
|= IEC958_AES3_CON_FS_44100
<<24; break;
227 case 48000: sbits
|= IEC958_AES3_CON_FS_48000
<<24; break;
228 case 32000: sbits
|= IEC958_AES3_CON_FS_32000
<<24; break;
231 ac97
->spdif_status
= sbits
;
233 snd_ac97_update_bits_nolock(ac97
, AC97_EXTENDED_STATUS
, AC97_EA_SPDIF
, AC97_EA_SPDIF
);
234 mutex_unlock(&ac97
->reg_mutex
);
239 * snd_ac97_set_rate - change the rate of the given input/output.
240 * @ac97: the ac97 instance
241 * @reg: the register to change
242 * @rate: the sample rate to set
244 * Changes the rate of the given input/output on the codec.
245 * If the codec doesn't support VAR, the rate must be 48000 (except
248 * The valid registers are AC97_PMC_MIC_ADC_RATE,
249 * AC97_PCM_FRONT_DAC_RATE, AC97_PCM_LR_ADC_RATE.
250 * AC97_PCM_SURR_DAC_RATE and AC97_PCM_LFE_DAC_RATE are accepted
251 * if the codec supports them.
252 * AC97_SPDIF is accepted as a pseudo register to modify the SPDIF
255 * Returns zero if successful, or a negative error code on failure.
257 int snd_ac97_set_rate(struct snd_ac97
*ac97
, int reg
, unsigned int rate
)
264 if (!(ac97
->flags
& AC97_DOUBLE_RATE
))
266 if (reg
!= AC97_PCM_FRONT_DAC_RATE
)
270 snd_ac97_update_power(ac97
, reg
, 1);
272 case AC97_PCM_MIC_ADC_RATE
:
273 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRM
) == 0) /* MIC VRA */
277 case AC97_PCM_FRONT_DAC_RATE
:
278 case AC97_PCM_LR_ADC_RATE
:
279 if ((ac97
->regs
[AC97_EXTENDED_STATUS
] & AC97_EA_VRA
) == 0) /* VRA */
280 if (rate
!= 48000 && rate
!= 96000)
283 case AC97_PCM_SURR_DAC_RATE
:
284 if (! (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
287 case AC97_PCM_LFE_DAC_RATE
:
288 if (! (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
293 return set_spdif_rate(ac97
, rate
);
299 tmp
= (rate
* ac97
->bus
->clock
) / 48000;
302 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
)
303 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
,
304 AC97_EA_DRA
, dbl
? AC97_EA_DRA
: 0);
305 snd_ac97_update(ac97
, reg
, tmp
& 0xffff);
306 snd_ac97_read(ac97
, reg
);
307 if ((ac97
->ext_id
& AC97_EI_DRA
) && reg
== AC97_PCM_FRONT_DAC_RATE
) {
308 /* Intel controllers require double rate data to be put in
311 snd_ac97_update_bits(ac97
, AC97_GENERAL_PURPOSE
,
313 dbl
? AC97_GP_DRSS_78
: 0);
314 snd_ac97_read(ac97
, AC97_GENERAL_PURPOSE
);
319 EXPORT_SYMBOL(snd_ac97_set_rate
);
321 static unsigned short get_pslots(struct snd_ac97
*ac97
, unsigned char *rate_table
, unsigned short *spdif_slots
)
323 if (!ac97_is_audio(ac97
))
325 if (ac97_is_rev22(ac97
) || ac97_can_amap(ac97
)) {
326 unsigned short slots
= 0;
327 if (ac97_is_rev22(ac97
)) {
328 /* Note: it's simply emulation of AMAP behaviour */
330 es
= ac97
->regs
[AC97_EXTENDED_ID
] &= ~AC97_EI_DACS_SLOT_MASK
;
331 switch (ac97
->addr
) {
333 case 2: es
|= (1<<AC97_EI_DACS_SLOT_SHIFT
); break;
334 case 3: es
|= (2<<AC97_EI_DACS_SLOT_SHIFT
); break;
336 snd_ac97_write_cache(ac97
, AC97_EXTENDED_ID
, es
);
338 switch (ac97
->addr
) {
340 slots
|= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
341 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
342 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
343 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
344 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
345 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
346 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
347 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
348 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
349 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
351 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
357 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
358 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
359 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
360 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
361 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
362 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
364 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
369 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
370 if (ac97
->ext_id
& AC97_EI_SPDIF
)
371 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
377 unsigned short slots
;
378 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
379 if (ac97
->scaps
& AC97_SCAP_SURROUND_DAC
)
380 slots
|= (1<<AC97_SLOT_PCM_SLEFT
)|(1<<AC97_SLOT_PCM_SRIGHT
);
381 if (ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
)
382 slots
|= (1<<AC97_SLOT_PCM_CENTER
)|(1<<AC97_SLOT_LFE
);
383 if (ac97
->ext_id
& AC97_EI_SPDIF
) {
384 if (!(ac97
->scaps
& AC97_SCAP_SURROUND_DAC
))
385 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT
)|(1<<AC97_SLOT_SPDIF_RIGHT
);
386 else if (!(ac97
->scaps
& AC97_SCAP_CENTER_LFE_DAC
))
387 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT1
)|(1<<AC97_SLOT_SPDIF_RIGHT1
);
389 *spdif_slots
= (1<<AC97_SLOT_SPDIF_LEFT2
)|(1<<AC97_SLOT_SPDIF_RIGHT2
);
396 static unsigned short get_cslots(struct snd_ac97
*ac97
)
398 unsigned short slots
;
400 if (!ac97_is_audio(ac97
))
402 slots
= (1<<AC97_SLOT_PCM_LEFT
)|(1<<AC97_SLOT_PCM_RIGHT
);
403 slots
|= (1<<AC97_SLOT_MIC
);
407 static unsigned int get_rates(struct ac97_pcm
*pcm
, unsigned int cidx
, unsigned short slots
, int dbl
)
410 unsigned int rates
= ~0;
413 for (i
= 3; i
< 12; i
++) {
414 if (!(slots
& (1 << i
)))
416 reg
= get_slot_reg(pcm
, cidx
, i
, dbl
);
418 case AC97_PCM_FRONT_DAC_RATE
: idx
= AC97_RATES_FRONT_DAC
; break;
419 case AC97_PCM_SURR_DAC_RATE
: idx
= AC97_RATES_SURR_DAC
; break;
420 case AC97_PCM_LFE_DAC_RATE
: idx
= AC97_RATES_LFE_DAC
; break;
421 case AC97_PCM_LR_ADC_RATE
: idx
= AC97_RATES_ADC
; break;
422 case AC97_PCM_MIC_ADC_RATE
: idx
= AC97_RATES_MIC_ADC
; break;
423 default: idx
= AC97_RATES_SPDIF
; break;
425 rates
&= pcm
->r
[dbl
].codec
[cidx
]->rates
[idx
];
428 rates
&= ~(SNDRV_PCM_RATE_64000
| SNDRV_PCM_RATE_88200
|
429 SNDRV_PCM_RATE_96000
);
434 * snd_ac97_pcm_assign - assign AC97 slots to given PCM streams
435 * @bus: the ac97 bus instance
436 * @pcms_count: count of PCMs to be assigned
437 * @pcms: PCMs to be assigned
439 * It assigns available AC97 slots for given PCMs. If none or only
440 * some slots are available, pcm->xxx.slots and pcm->xxx.rslots[] members
441 * are reduced and might be zero.
443 int snd_ac97_pcm_assign(struct snd_ac97_bus
*bus
,
444 unsigned short pcms_count
,
445 const struct ac97_pcm
*pcms
)
448 const struct ac97_pcm
*pcm
;
449 struct ac97_pcm
*rpcms
, *rpcm
;
450 unsigned short avail_slots
[2][4];
451 unsigned char rate_table
[2][4];
452 unsigned short tmp
, slots
;
453 unsigned short spdif_slots
[4];
455 struct snd_ac97
*codec
;
457 rpcms
= kcalloc(pcms_count
, sizeof(struct ac97_pcm
), GFP_KERNEL
);
460 memset(avail_slots
, 0, sizeof(avail_slots
));
461 memset(rate_table
, 0, sizeof(rate_table
));
462 memset(spdif_slots
, 0, sizeof(spdif_slots
));
463 for (i
= 0; i
< 4; i
++) {
464 codec
= bus
->codec
[i
];
467 avail_slots
[0][i
] = get_pslots(codec
, &rate_table
[0][i
], &spdif_slots
[i
]);
468 avail_slots
[1][i
] = get_cslots(codec
);
469 if (!(codec
->scaps
& AC97_SCAP_INDEP_SDIN
)) {
470 for (j
= 0; j
< i
; j
++) {
472 avail_slots
[1][i
] &= ~avail_slots
[1][j
];
476 /* first step - exclusive devices */
477 for (i
= 0; i
< pcms_count
; i
++) {
480 /* low-level driver thinks that it's more clever */
481 if (pcm
->copy_flag
) {
485 rpcm
->stream
= pcm
->stream
;
486 rpcm
->exclusive
= pcm
->exclusive
;
487 rpcm
->spdif
= pcm
->spdif
;
488 rpcm
->private_value
= pcm
->private_value
;
491 slots
= pcm
->r
[0].slots
;
492 for (j
= 0; j
< 4 && slots
; j
++) {
496 if (pcm
->spdif
&& pcm
->stream
== 0)
497 tmp
= spdif_slots
[j
];
499 tmp
= avail_slots
[pcm
->stream
][j
];
500 if (pcm
->exclusive
) {
501 /* exclusive access */
503 for (k
= 0; k
< i
; k
++) {
504 if (rpcm
->stream
== rpcms
[k
].stream
)
505 tmp
&= ~rpcms
[k
].r
[0].rslots
[j
];
508 /* non-exclusive access */
509 tmp
&= pcm
->r
[0].slots
;
512 rpcm
->r
[0].rslots
[j
] = tmp
;
513 rpcm
->r
[0].codec
[j
] = bus
->codec
[j
];
514 rpcm
->r
[0].rate_table
[j
] = rate_table
[pcm
->stream
][j
];
516 rates
= SNDRV_PCM_RATE_48000
;
518 rates
= get_rates(rpcm
, j
, tmp
, 0);
520 avail_slots
[pcm
->stream
][j
] &= ~tmp
;
523 rpcm
->r
[0].slots
|= tmp
;
524 rpcm
->rates
&= rates
;
526 /* for double rate, we check the first codec only */
527 if (pcm
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
528 bus
->codec
[0] && (bus
->codec
[0]->flags
& AC97_DOUBLE_RATE
) &&
529 rate_table
[pcm
->stream
][0] == 0) {
530 tmp
= (1<<AC97_SLOT_PCM_LEFT
) | (1<<AC97_SLOT_PCM_RIGHT
) |
531 (1<<AC97_SLOT_PCM_LEFT_0
) | (1<<AC97_SLOT_PCM_RIGHT_0
);
532 if ((tmp
& pcm
->r
[1].slots
) == tmp
) {
533 rpcm
->r
[1].slots
= tmp
;
534 rpcm
->r
[1].rslots
[0] = tmp
;
535 rpcm
->r
[1].rate_table
[0] = 0;
536 rpcm
->r
[1].codec
[0] = bus
->codec
[0];
538 avail_slots
[pcm
->stream
][0] &= ~tmp
;
540 rates
= SNDRV_PCM_RATE_96000
;
542 rates
= get_rates(rpcm
, 0, tmp
, 1);
543 rpcm
->rates
|= rates
;
546 if (rpcm
->rates
== ~0)
547 rpcm
->rates
= 0; /* not used */
549 bus
->pcms_count
= pcms_count
;
554 EXPORT_SYMBOL(snd_ac97_pcm_assign
);
557 * snd_ac97_pcm_open - opens the given AC97 pcm
558 * @pcm: the ac97 pcm instance
559 * @rate: rate in Hz, if codec does not support VRA, this value must be 48000Hz
560 * @cfg: output stream characteristics
561 * @slots: a subset of allocated slots (snd_ac97_pcm_assign) for this pcm
563 * It locks the specified slots and sets the given rate to AC97 registers.
565 int snd_ac97_pcm_open(struct ac97_pcm
*pcm
, unsigned int rate
,
566 enum ac97_pcm_cfg cfg
, unsigned short slots
)
568 struct snd_ac97_bus
*bus
;
569 int i
, cidx
, r
, ok_flag
;
570 unsigned int reg_ok
[4] = {0,0,0,0};
576 if (cfg
== AC97_PCM_CFG_SPDIF
) {
578 for (cidx
= 0; cidx
< 4; cidx
++)
579 if (bus
->codec
[cidx
] && (bus
->codec
[cidx
]->ext_id
& AC97_EI_SPDIF
)) {
580 err
= set_spdif_rate(bus
->codec
[cidx
], rate
);
585 spin_lock_irq(&pcm
->bus
->bus_lock
);
586 for (i
= 3; i
< 12; i
++) {
587 if (!(slots
& (1 << i
)))
590 for (cidx
= 0; cidx
< 4; cidx
++) {
591 if (bus
->used_slots
[pcm
->stream
][cidx
] & (1 << i
)) {
592 spin_unlock_irq(&pcm
->bus
->bus_lock
);
596 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
597 bus
->used_slots
[pcm
->stream
][cidx
] |= (1 << i
);
602 spin_unlock_irq(&pcm
->bus
->bus_lock
);
603 snd_printk(KERN_ERR
"cannot find configuration for AC97 slot %i\n", i
);
609 spin_unlock_irq(&pcm
->bus
->bus_lock
);
610 for (i
= 3; i
< 12; i
++) {
611 if (!(slots
& (1 << i
)))
613 for (cidx
= 0; cidx
< 4; cidx
++) {
614 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
615 reg
= get_slot_reg(pcm
, cidx
, i
, r
);
617 snd_printk(KERN_ERR
"invalid AC97 slot %i?\n", i
);
620 if (reg_ok
[cidx
] & (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
)))
622 //printk(KERN_DEBUG "setting ac97 reg 0x%x to rate %d\n", reg, rate);
623 err
= snd_ac97_set_rate(pcm
->r
[r
].codec
[cidx
], reg
, rate
);
625 snd_printk(KERN_ERR
"error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n", cidx
, reg
, rate
, err
);
627 reg_ok
[cidx
] |= (1 << (reg
- AC97_PCM_FRONT_DAC_RATE
));
636 snd_ac97_pcm_close(pcm
);
640 EXPORT_SYMBOL(snd_ac97_pcm_open
);
643 * snd_ac97_pcm_close - closes the given AC97 pcm
644 * @pcm: the ac97 pcm instance
646 * It frees the locked AC97 slots.
648 int snd_ac97_pcm_close(struct ac97_pcm
*pcm
)
650 struct snd_ac97_bus
*bus
;
651 unsigned short slots
= pcm
->aslots
;
654 #ifdef CONFIG_SND_AC97_POWER_SAVE
655 int r
= pcm
->cur_dbl
;
656 for (i
= 3; i
< 12; i
++) {
657 if (!(slots
& (1 << i
)))
659 for (cidx
= 0; cidx
< 4; cidx
++) {
660 if (pcm
->r
[r
].rslots
[cidx
] & (1 << i
)) {
661 int reg
= get_slot_reg(pcm
, cidx
, i
, r
);
662 snd_ac97_update_power(pcm
->r
[r
].codec
[cidx
],
670 spin_lock_irq(&pcm
->bus
->bus_lock
);
671 for (i
= 3; i
< 12; i
++) {
672 if (!(slots
& (1 << i
)))
674 for (cidx
= 0; cidx
< 4; cidx
++)
675 bus
->used_slots
[pcm
->stream
][cidx
] &= ~(1 << i
);
679 spin_unlock_irq(&pcm
->bus
->bus_lock
);
683 EXPORT_SYMBOL(snd_ac97_pcm_close
);
685 static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params
*params
,
686 struct snd_pcm_hw_rule
*rule
)
688 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
689 if (channels
->min
> 2) {
690 static const struct snd_interval single_rates
= {
694 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
695 return snd_interval_refine(rate
, &single_rates
);
700 static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params
*params
,
701 struct snd_pcm_hw_rule
*rule
)
703 struct snd_interval
*rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
704 if (rate
->min
> 48000) {
705 static const struct snd_interval double_rate_channels
= {
709 struct snd_interval
*channels
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
710 return snd_interval_refine(channels
, &double_rate_channels
);
716 * snd_ac97_pcm_double_rate_rules - set double rate constraints
717 * @runtime: the runtime of the ac97 front playback pcm
719 * Installs the hardware constraint rules to prevent using double rates and
720 * more than two channels at the same time.
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
);