1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/delay.h>
27#include <linux/init.h>
28#include <linux/slab.h>
29#include <linux/mutex.h>
30#include <linux/export.h>
31
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_id.h"
38#include "ac97_local.h"
39
40
41
42
43
44static unsigned char rate_reg_tables[2][4][9] = {
45{
46
47 {
48
49 AC97_PCM_FRONT_DAC_RATE,
50 AC97_PCM_FRONT_DAC_RATE,
51 0xff,
52 AC97_PCM_LFE_DAC_RATE,
53 AC97_PCM_SURR_DAC_RATE,
54 AC97_PCM_SURR_DAC_RATE,
55 AC97_PCM_LFE_DAC_RATE,
56 0xff,
57 0xff,
58 },
59 {
60
61 0xff,
62 0xff,
63 0xff,
64 AC97_PCM_SURR_DAC_RATE,
65 AC97_PCM_FRONT_DAC_RATE,
66 AC97_PCM_FRONT_DAC_RATE,
67 AC97_PCM_SURR_DAC_RATE,
68 AC97_PCM_LFE_DAC_RATE,
69 AC97_PCM_LFE_DAC_RATE,
70 },
71 {
72
73 AC97_PCM_LFE_DAC_RATE,
74 AC97_PCM_LFE_DAC_RATE,
75 0xff,
76 AC97_PCM_FRONT_DAC_RATE,
77 0xff,
78 0xff,
79 AC97_PCM_FRONT_DAC_RATE,
80 AC97_PCM_SURR_DAC_RATE,
81 AC97_PCM_SURR_DAC_RATE,
82 },
83 {
84
85 AC97_PCM_SURR_DAC_RATE,
86 AC97_PCM_SURR_DAC_RATE,
87 0xff,
88 0xff,
89 AC97_PCM_LFE_DAC_RATE,
90 AC97_PCM_LFE_DAC_RATE,
91 0xff,
92 AC97_PCM_FRONT_DAC_RATE,
93 AC97_PCM_FRONT_DAC_RATE,
94 },
95},
96{
97
98 {
99
100 AC97_PCM_FRONT_DAC_RATE,
101 AC97_PCM_FRONT_DAC_RATE,
102 0xff,
103 0xff,
104 AC97_PCM_FRONT_DAC_RATE,
105 AC97_PCM_FRONT_DAC_RATE,
106 0xff,
107 0xff,
108 0xff,
109 },
110 {
111
112 0xff,
113 0xff,
114 0xff,
115 0xff,
116 0xff,
117 0xff,
118 0xff,
119 0xff,
120 0xff,
121 },
122 {
123 0xff,
124 0xff,
125 0xff,
126 0xff,
127 0xff,
128 0xff,
129 0xff,
130 0xff,
131 0xff,
132 },
133 {
134 0xff,
135 0xff,
136 0xff,
137 0xff,
138 0xff,
139 0xff,
140 0xff,
141 0xff,
142 0xff,
143 }
144}};
145
146
147static unsigned char rate_cregs[9] = {
148 AC97_PCM_LR_ADC_RATE,
149 AC97_PCM_LR_ADC_RATE,
150 0xff,
151 AC97_PCM_MIC_ADC_RATE,
152 0xff,
153 0xff,
154 0xff,
155 0xff,
156 0xff,
157};
158
159static unsigned char get_slot_reg(struct ac97_pcm *pcm, unsigned short cidx,
160 unsigned short slot, int dbl)
161{
162 if (slot < 3)
163 return 0xff;
164 if (slot > 11)
165 return 0xff;
166 if (pcm->spdif)
167 return AC97_SPDIF;
168 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK)
169 return rate_reg_tables[dbl][pcm->r[dbl].rate_table[cidx]][slot - 3];
170 else
171 return rate_cregs[slot - 3];
172}
173
174static int set_spdif_rate(struct snd_ac97 *ac97, unsigned short rate)
175{
176 unsigned short old, bits, reg, mask;
177 unsigned int sbits;
178
179 if (! (ac97->ext_id & AC97_EI_SPDIF))
180 return -ENODEV;
181
182
183 if (ac97->flags & AC97_CS_SPDIF) {
184 switch (rate) {
185 case 48000: bits = 0; break;
186 case 44100: bits = 1 << AC97_SC_SPSR_SHIFT; break;
187 default:
188 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
189 return -EINVAL;
190 }
191 reg = AC97_CSR_SPDIF;
192 mask = 1 << AC97_SC_SPSR_SHIFT;
193 } else {
194 if (ac97->id == AC97_ID_CM9739 && rate != 48000) {
195 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
196 return -EINVAL;
197 }
198 switch (rate) {
199 case 44100: bits = AC97_SC_SPSR_44K; break;
200 case 48000: bits = AC97_SC_SPSR_48K; break;
201 case 32000: bits = AC97_SC_SPSR_32K; break;
202 default:
203 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
204 return -EINVAL;
205 }
206 reg = AC97_SPDIF;
207 mask = AC97_SC_SPSR_MASK;
208 }
209
210 mutex_lock(&ac97->reg_mutex);
211 old = snd_ac97_read(ac97, reg) & mask;
212 if (old != bits) {
213 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
214 snd_ac97_update_bits_nolock(ac97, reg, mask, bits);
215
216 sbits = ac97->spdif_status;
217 if (sbits & IEC958_AES0_PROFESSIONAL) {
218 sbits &= ~IEC958_AES0_PRO_FS;
219 switch (rate) {
220 case 44100: sbits |= IEC958_AES0_PRO_FS_44100; break;
221 case 48000: sbits |= IEC958_AES0_PRO_FS_48000; break;
222 case 32000: sbits |= IEC958_AES0_PRO_FS_32000; break;
223 }
224 } else {
225 sbits &= ~(IEC958_AES3_CON_FS << 24);
226 switch (rate) {
227 case 44100: sbits |= IEC958_AES3_CON_FS_44100<<24; break;
228 case 48000: sbits |= IEC958_AES3_CON_FS_48000<<24; break;
229 case 32000: sbits |= IEC958_AES3_CON_FS_32000<<24; break;
230 }
231 }
232 ac97->spdif_status = sbits;
233 }
234 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF);
235 mutex_unlock(&ac97->reg_mutex);
236 return 0;
237}
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate)
259{
260 int dbl;
261 unsigned int tmp;
262
263 dbl = rate > 48000;
264 if (dbl) {
265 if (!(ac97->flags & AC97_DOUBLE_RATE))
266 return -EINVAL;
267 if (reg != AC97_PCM_FRONT_DAC_RATE)
268 return -EINVAL;
269 }
270
271 snd_ac97_update_power(ac97, reg, 1);
272 switch (reg) {
273 case AC97_PCM_MIC_ADC_RATE:
274 if ((ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_VRM) == 0)
275 if (rate != 48000)
276 return -EINVAL;
277 break;
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)
281 if (rate != 48000 && rate != 96000)
282 return -EINVAL;
283 break;
284 case AC97_PCM_SURR_DAC_RATE:
285 if (! (ac97->scaps & AC97_SCAP_SURROUND_DAC))
286 return -EINVAL;
287 break;
288 case AC97_PCM_LFE_DAC_RATE:
289 if (! (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC))
290 return -EINVAL;
291 break;
292 case AC97_SPDIF:
293
294 return set_spdif_rate(ac97, rate);
295 default:
296 return -EINVAL;
297 }
298 if (dbl)
299 rate /= 2;
300 tmp = (rate * ac97->bus->clock) / 48000;
301 if (tmp > 65535)
302 return -EINVAL;
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
310
311
312 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE,
313 AC97_GP_DRSS_MASK,
314 dbl ? AC97_GP_DRSS_78 : 0);
315 snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
316 }
317 return 0;
318}
319
320EXPORT_SYMBOL(snd_ac97_set_rate);
321
322static unsigned short get_pslots(struct snd_ac97 *ac97, unsigned char *rate_table, unsigned short *spdif_slots)
323{
324 if (!ac97_is_audio(ac97))
325 return 0;
326 if (ac97_is_rev22(ac97) || ac97_can_amap(ac97)) {
327 unsigned short slots = 0;
328 if (ac97_is_rev22(ac97)) {
329
330 u16 es;
331 es = ac97->regs[AC97_EXTENDED_ID] &= ~AC97_EI_DACS_SLOT_MASK;
332 switch (ac97->addr) {
333 case 1:
334 case 2: es |= (1<<AC97_EI_DACS_SLOT_SHIFT); break;
335 case 3: es |= (2<<AC97_EI_DACS_SLOT_SHIFT); break;
336 }
337 snd_ac97_write_cache(ac97, AC97_EXTENDED_ID, es);
338 }
339 switch (ac97->addr) {
340 case 0:
341 slots |= (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT);
342 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
343 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT);
344 if (ac97->scaps & AC97_SCAP_CENTER_LFE_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_LEFT)|(1<<AC97_SLOT_SPDIF_RIGHT);
349 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC))
350 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1);
351 else
352 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);
353 }
354 *rate_table = 0;
355 break;
356 case 1:
357 case 2:
358 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT);
359 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
360 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);
361 if (ac97->ext_id & AC97_EI_SPDIF) {
362 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC))
363 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1);
364 else
365 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);
366 }
367 *rate_table = 1;
368 break;
369 case 3:
370 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);
371 if (ac97->ext_id & AC97_EI_SPDIF)
372 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);
373 *rate_table = 2;
374 break;
375 }
376 return slots;
377 } else {
378 unsigned short slots;
379 slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT);
380 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
381 slots |= (1<<AC97_SLOT_PCM_SLEFT)|(1<<AC97_SLOT_PCM_SRIGHT);
382 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
383 slots |= (1<<AC97_SLOT_PCM_CENTER)|(1<<AC97_SLOT_LFE);
384 if (ac97->ext_id & AC97_EI_SPDIF) {
385 if (!(ac97->scaps & AC97_SCAP_SURROUND_DAC))
386 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT)|(1<<AC97_SLOT_SPDIF_RIGHT);
387 else if (!(ac97->scaps & AC97_SCAP_CENTER_LFE_DAC))
388 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT1)|(1<<AC97_SLOT_SPDIF_RIGHT1);
389 else
390 *spdif_slots = (1<<AC97_SLOT_SPDIF_LEFT2)|(1<<AC97_SLOT_SPDIF_RIGHT2);
391 }
392 *rate_table = 0;
393 return slots;
394 }
395}
396
397static unsigned short get_cslots(struct snd_ac97 *ac97)
398{
399 unsigned short slots;
400
401 if (!ac97_is_audio(ac97))
402 return 0;
403 slots = (1<<AC97_SLOT_PCM_LEFT)|(1<<AC97_SLOT_PCM_RIGHT);
404 slots |= (1<<AC97_SLOT_MIC);
405 return slots;
406}
407
408static unsigned int get_rates(struct ac97_pcm *pcm, unsigned int cidx, unsigned short slots, int dbl)
409{
410 int i, idx;
411 unsigned int rates = ~0;
412 unsigned char reg;
413
414 for (i = 3; i < 12; i++) {
415 if (!(slots & (1 << i)))
416 continue;
417 reg = get_slot_reg(pcm, cidx, i, dbl);
418 switch (reg) {
419 case AC97_PCM_FRONT_DAC_RATE: idx = AC97_RATES_FRONT_DAC; break;
420 case AC97_PCM_SURR_DAC_RATE: idx = AC97_RATES_SURR_DAC; break;
421 case AC97_PCM_LFE_DAC_RATE: idx = AC97_RATES_LFE_DAC; break;
422 case AC97_PCM_LR_ADC_RATE: idx = AC97_RATES_ADC; break;
423 case AC97_PCM_MIC_ADC_RATE: idx = AC97_RATES_MIC_ADC; break;
424 default: idx = AC97_RATES_SPDIF; break;
425 }
426 rates &= pcm->r[dbl].codec[cidx]->rates[idx];
427 }
428 if (!dbl)
429 rates &= ~(SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 |
430 SNDRV_PCM_RATE_96000);
431 return rates;
432}
433
434
435
436
437
438
439
440
441
442
443
444
445
446int snd_ac97_pcm_assign(struct snd_ac97_bus *bus,
447 unsigned short pcms_count,
448 const struct ac97_pcm *pcms)
449{
450 int i, j, k;
451 const struct ac97_pcm *pcm;
452 struct ac97_pcm *rpcms, *rpcm;
453 unsigned short avail_slots[2][4];
454 unsigned char rate_table[2][4];
455 unsigned short tmp, slots;
456 unsigned short spdif_slots[4];
457 unsigned int rates;
458 struct snd_ac97 *codec;
459
460 rpcms = kcalloc(pcms_count, sizeof(struct ac97_pcm), GFP_KERNEL);
461 if (rpcms == NULL)
462 return -ENOMEM;
463 memset(avail_slots, 0, sizeof(avail_slots));
464 memset(rate_table, 0, sizeof(rate_table));
465 memset(spdif_slots, 0, sizeof(spdif_slots));
466 for (i = 0; i < 4; i++) {
467 codec = bus->codec[i];
468 if (!codec)
469 continue;
470 avail_slots[0][i] = get_pslots(codec, &rate_table[0][i], &spdif_slots[i]);
471 avail_slots[1][i] = get_cslots(codec);
472 if (!(codec->scaps & AC97_SCAP_INDEP_SDIN)) {
473 for (j = 0; j < i; j++) {
474 if (bus->codec[j])
475 avail_slots[1][i] &= ~avail_slots[1][j];
476 }
477 }
478 }
479
480 for (i = 0; i < pcms_count; i++) {
481 pcm = &pcms[i];
482 rpcm = &rpcms[i];
483
484 if (pcm->copy_flag) {
485 *rpcm = *pcm;
486 continue;
487 }
488 rpcm->stream = pcm->stream;
489 rpcm->exclusive = pcm->exclusive;
490 rpcm->spdif = pcm->spdif;
491 rpcm->private_value = pcm->private_value;
492 rpcm->bus = bus;
493 rpcm->rates = ~0;
494 slots = pcm->r[0].slots;
495 for (j = 0; j < 4 && slots; j++) {
496 if (!bus->codec[j])
497 continue;
498 rates = ~0;
499 if (pcm->spdif && pcm->stream == 0)
500 tmp = spdif_slots[j];
501 else
502 tmp = avail_slots[pcm->stream][j];
503 if (pcm->exclusive) {
504
505 tmp &= slots;
506 for (k = 0; k < i; k++) {
507 if (rpcm->stream == rpcms[k].stream)
508 tmp &= ~rpcms[k].r[0].rslots[j];
509 }
510 } else {
511
512 tmp &= pcm->r[0].slots;
513 }
514 if (tmp) {
515 rpcm->r[0].rslots[j] = tmp;
516 rpcm->r[0].codec[j] = bus->codec[j];
517 rpcm->r[0].rate_table[j] = rate_table[pcm->stream][j];
518 if (bus->no_vra)
519 rates = SNDRV_PCM_RATE_48000;
520 else
521 rates = get_rates(rpcm, j, tmp, 0);
522 if (pcm->exclusive)
523 avail_slots[pcm->stream][j] &= ~tmp;
524 }
525 slots &= ~tmp;
526 rpcm->r[0].slots |= tmp;
527 rpcm->rates &= rates;
528 }
529
530 if (pcm->stream == SNDRV_PCM_STREAM_PLAYBACK &&
531 bus->codec[0] && (bus->codec[0]->flags & AC97_DOUBLE_RATE) &&
532 rate_table[pcm->stream][0] == 0) {
533 tmp = (1<<AC97_SLOT_PCM_LEFT) | (1<<AC97_SLOT_PCM_RIGHT) |
534 (1<<AC97_SLOT_PCM_LEFT_0) | (1<<AC97_SLOT_PCM_RIGHT_0);
535 if ((tmp & pcm->r[1].slots) == tmp) {
536 rpcm->r[1].slots = tmp;
537 rpcm->r[1].rslots[0] = tmp;
538 rpcm->r[1].rate_table[0] = 0;
539 rpcm->r[1].codec[0] = bus->codec[0];
540 if (pcm->exclusive)
541 avail_slots[pcm->stream][0] &= ~tmp;
542 if (bus->no_vra)
543 rates = SNDRV_PCM_RATE_96000;
544 else
545 rates = get_rates(rpcm, 0, tmp, 1);
546 rpcm->rates |= rates;
547 }
548 }
549 if (rpcm->rates == ~0)
550 rpcm->rates = 0;
551 }
552 bus->pcms_count = pcms_count;
553 bus->pcms = rpcms;
554 return 0;
555}
556
557EXPORT_SYMBOL(snd_ac97_pcm_assign);
558
559
560
561
562
563
564
565
566
567
568
569
570int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
571 enum ac97_pcm_cfg cfg, unsigned short slots)
572{
573 struct snd_ac97_bus *bus;
574 int i, cidx, r, ok_flag;
575 unsigned int reg_ok[4] = {0,0,0,0};
576 unsigned char reg;
577 int err = 0;
578
579 r = rate > 48000;
580 bus = pcm->bus;
581 if (cfg == AC97_PCM_CFG_SPDIF) {
582 for (cidx = 0; cidx < 4; cidx++)
583 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) {
584 err = set_spdif_rate(bus->codec[cidx], rate);
585 if (err < 0)
586 return err;
587 }
588 }
589 spin_lock_irq(&pcm->bus->bus_lock);
590 for (i = 3; i < 12; i++) {
591 if (!(slots & (1 << i)))
592 continue;
593 ok_flag = 0;
594 for (cidx = 0; cidx < 4; cidx++) {
595 if (bus->used_slots[pcm->stream][cidx] & (1 << i)) {
596 spin_unlock_irq(&pcm->bus->bus_lock);
597 err = -EBUSY;
598 goto error;
599 }
600 if (pcm->r[r].rslots[cidx] & (1 << i)) {
601 bus->used_slots[pcm->stream][cidx] |= (1 << i);
602 ok_flag++;
603 }
604 }
605 if (!ok_flag) {
606 spin_unlock_irq(&pcm->bus->bus_lock);
607 dev_err(bus->card->dev,
608 "cannot find configuration for AC97 slot %i\n",
609 i);
610 err = -EAGAIN;
611 goto error;
612 }
613 }
614 pcm->cur_dbl = r;
615 spin_unlock_irq(&pcm->bus->bus_lock);
616 for (i = 3; i < 12; i++) {
617 if (!(slots & (1 << i)))
618 continue;
619 for (cidx = 0; cidx < 4; cidx++) {
620 if (pcm->r[r].rslots[cidx] & (1 << i)) {
621 reg = get_slot_reg(pcm, cidx, i, r);
622 if (reg == 0xff) {
623 dev_err(bus->card->dev,
624 "invalid AC97 slot %i?\n", i);
625 continue;
626 }
627 if (reg_ok[cidx] & (1 << (reg - AC97_PCM_FRONT_DAC_RATE)))
628 continue;
629 dev_dbg(bus->card->dev,
630 "setting ac97 reg 0x%x to rate %d\n",
631 reg, rate);
632 err = snd_ac97_set_rate(pcm->r[r].codec[cidx], reg, rate);
633 if (err < 0)
634 dev_err(bus->card->dev,
635 "error in snd_ac97_set_rate: cidx=%d, reg=0x%x, rate=%d, err=%d\n",
636 cidx, reg, rate, err);
637 else
638 reg_ok[cidx] |= (1 << (reg - AC97_PCM_FRONT_DAC_RATE));
639 }
640 }
641 }
642 pcm->aslots = slots;
643 return 0;
644
645 error:
646 pcm->aslots = slots;
647 snd_ac97_pcm_close(pcm);
648 return err;
649}
650
651EXPORT_SYMBOL(snd_ac97_pcm_open);
652
653
654
655
656
657
658
659
660
661int snd_ac97_pcm_close(struct ac97_pcm *pcm)
662{
663 struct snd_ac97_bus *bus;
664 unsigned short slots = pcm->aslots;
665 int i, cidx;
666
667#ifdef CONFIG_SND_AC97_POWER_SAVE
668 int r = pcm->cur_dbl;
669 for (i = 3; i < 12; i++) {
670 if (!(slots & (1 << i)))
671 continue;
672 for (cidx = 0; cidx < 4; cidx++) {
673 if (pcm->r[r].rslots[cidx] & (1 << i)) {
674 int reg = get_slot_reg(pcm, cidx, i, r);
675 snd_ac97_update_power(pcm->r[r].codec[cidx],
676 reg, 0);
677 }
678 }
679 }
680#endif
681
682 bus = pcm->bus;
683 spin_lock_irq(&pcm->bus->bus_lock);
684 for (i = 3; i < 12; i++) {
685 if (!(slots & (1 << i)))
686 continue;
687 for (cidx = 0; cidx < 4; cidx++)
688 bus->used_slots[pcm->stream][cidx] &= ~(1 << i);
689 }
690 pcm->aslots = 0;
691 pcm->cur_dbl = 0;
692 spin_unlock_irq(&pcm->bus->bus_lock);
693 return 0;
694}
695
696EXPORT_SYMBOL(snd_ac97_pcm_close);
697
698static int double_rate_hw_constraint_rate(struct snd_pcm_hw_params *params,
699 struct snd_pcm_hw_rule *rule)
700{
701 struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
702 if (channels->min > 2) {
703 static const struct snd_interval single_rates = {
704 .min = 1,
705 .max = 48000,
706 };
707 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
708 return snd_interval_refine(rate, &single_rates);
709 }
710 return 0;
711}
712
713static int double_rate_hw_constraint_channels(struct snd_pcm_hw_params *params,
714 struct snd_pcm_hw_rule *rule)
715{
716 struct snd_interval *rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
717 if (rate->min > 48000) {
718 static const struct snd_interval double_rate_channels = {
719 .min = 2,
720 .max = 2,
721 };
722 struct snd_interval *channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
723 return snd_interval_refine(channels, &double_rate_channels);
724 }
725 return 0;
726}
727
728
729
730
731
732
733
734
735
736
737int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime)
738{
739 int err;
740
741 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
742 double_rate_hw_constraint_rate, NULL,
743 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
744 if (err < 0)
745 return err;
746 err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
747 double_rate_hw_constraint_channels, NULL,
748 SNDRV_PCM_HW_PARAM_RATE, -1);
749 return err;
750}
751
752EXPORT_SYMBOL(snd_ac97_pcm_double_rate_rules);
753