2 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
4 * This source file is released under GPL v2 license (no other versions).
5 * See the COPYING file included in the main directory of this source
6 * distribution for the license terms and conditions.
11 * This file contains the implementation of the device resource management
21 #include "cthardware.h"
26 #include <linux/delay.h>
27 #include <sound/pcm.h>
28 #include <sound/control.h>
29 #include <sound/asoundef.h>
31 #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */
33 #define MAX_MULTI_CHN 8
35 #define IEC958_DEFAULT_CON ((IEC958_AES0_NONAUDIO \
36 | IEC958_AES0_CON_NOT_COPYRIGHT) \
37 | ((IEC958_AES1_CON_MIXER \
38 | IEC958_AES1_CON_ORIGINAL) << 8) \
40 | ((IEC958_AES3_CON_FS_48000) << 24))
42 static struct snd_pci_quirk __devinitdata subsys_20k1_list
[] = {
43 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0022, "SB055x", CTSB055X
),
44 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x002f, "SB055x", CTSB055X
),
45 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0029, "SB073x", CTSB073X
),
46 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0031, "SB073x", CTSB073X
),
47 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE
, 0xf000, 0x6000,
52 static struct snd_pci_quirk __devinitdata subsys_20k2_list
[] = {
53 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB0760
,
55 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08801
,
57 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08802
,
59 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08803
,
61 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE
, 0xf000,
62 PCI_SUBDEVICE_ID_CREATIVE_HENDRIX
, "HENDRIX",
67 static const char *ct_subsys_name
[NUM_CTCARDS
] = {
69 [CTSB055X
] = "SB055x",
70 [CTSB073X
] = "SB073x",
72 [CT20K1_UNKNOWN
] = "Unknown",
74 [CTSB0760
] = "SB076x",
75 [CTHENDRIX
] = "Hendrix",
76 [CTSB0880
] = "SB0880",
77 [CT20K2_UNKNOWN
] = "Unknown",
81 int (*create
)(struct ct_atc
*atc
,
82 enum CTALSADEVS device
, const char *device_name
);
83 int (*destroy
)(void *alsa_dev
);
84 const char *public_name
;
85 } alsa_dev_funcs
[NUM_CTALSADEVS
] = {
86 [FRONT
] = { .create
= ct_alsa_pcm_create
,
88 .public_name
= "Front/WaveIn"},
89 [SURROUND
] = { .create
= ct_alsa_pcm_create
,
91 .public_name
= "Surround"},
92 [CLFE
] = { .create
= ct_alsa_pcm_create
,
94 .public_name
= "Center/LFE"},
95 [SIDE
] = { .create
= ct_alsa_pcm_create
,
97 .public_name
= "Side"},
98 [IEC958
] = { .create
= ct_alsa_pcm_create
,
100 .public_name
= "IEC958 Non-audio"},
102 [MIXER
] = { .create
= ct_alsa_mix_create
,
104 .public_name
= "Mixer"}
107 typedef int (*create_t
)(void *, void **);
108 typedef int (*destroy_t
)(void *);
111 int (*create
)(void *hw
, void **rmgr
);
112 int (*destroy
)(void *mgr
);
113 } rsc_mgr_funcs
[NUM_RSCTYP
] = {
114 [SRC
] = { .create
= (create_t
)src_mgr_create
,
115 .destroy
= (destroy_t
)src_mgr_destroy
},
116 [SRCIMP
] = { .create
= (create_t
)srcimp_mgr_create
,
117 .destroy
= (destroy_t
)srcimp_mgr_destroy
},
118 [AMIXER
] = { .create
= (create_t
)amixer_mgr_create
,
119 .destroy
= (destroy_t
)amixer_mgr_destroy
},
120 [SUM
] = { .create
= (create_t
)sum_mgr_create
,
121 .destroy
= (destroy_t
)sum_mgr_destroy
},
122 [DAIO
] = { .create
= (create_t
)daio_mgr_create
,
123 .destroy
= (destroy_t
)daio_mgr_destroy
}
127 atc_pcm_release_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
);
130 * Only mono and interleaved modes are supported now.
131 * Always allocates a contiguous channel block.
134 static int ct_map_audio_buffer(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
136 struct snd_pcm_runtime
*runtime
;
139 if (NULL
== apcm
->substream
)
142 runtime
= apcm
->substream
->runtime
;
145 apcm
->vm_block
= vm
->map(vm
, apcm
->substream
, runtime
->dma_bytes
);
147 if (NULL
== apcm
->vm_block
)
153 static void ct_unmap_audio_buffer(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
157 if (NULL
== apcm
->vm_block
)
162 vm
->unmap(vm
, apcm
->vm_block
);
164 apcm
->vm_block
= NULL
;
167 static unsigned long atc_get_ptp_phys(struct ct_atc
*atc
, int index
)
171 unsigned long phys_addr
;
174 kvirt_addr
= vm
->get_ptp_virt(vm
, index
);
175 if (kvirt_addr
== NULL
)
178 phys_addr
= virt_to_phys(kvirt_addr
);
183 static unsigned int convert_format(snd_pcm_format_t snd_format
)
185 switch (snd_format
) {
186 case SNDRV_PCM_FORMAT_U8
:
188 case SNDRV_PCM_FORMAT_S16_LE
:
190 case SNDRV_PCM_FORMAT_S24_3LE
:
192 case SNDRV_PCM_FORMAT_S32_LE
:
194 case SNDRV_PCM_FORMAT_FLOAT_LE
:
197 printk(KERN_ERR
"ctxfi: not recognized snd format is %d \n",
204 atc_get_pitch(unsigned int input_rate
, unsigned int output_rate
)
209 /* get pitch and convert to fixed-point 8.24 format. */
210 pitch
= (input_rate
/ output_rate
) << 24;
211 input_rate
%= output_rate
;
214 for (b
= 31; ((b
>= 0) && !(input_rate
>> b
)); )
218 input_rate
<<= (31 - b
);
219 input_rate
/= output_rate
;
232 static int select_rom(unsigned int pitch
)
234 if ((pitch
> 0x00428f5c) && (pitch
< 0x01b851ec)) {
235 /* 0.26 <= pitch <= 1.72 */
237 } else if ((0x01d66666 == pitch
) || (0x01d66667 == pitch
)) {
238 /* pitch == 1.8375 */
240 } else if (0x02000000 == pitch
) {
243 } else if ((pitch
>= 0x0) && (pitch
<= 0x08000000)) {
244 /* 0 <= pitch <= 8 */
251 static int atc_pcm_playback_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
253 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
254 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
255 struct src_desc desc
= {0};
256 struct amixer_desc mix_dsc
= {0};
258 struct amixer
*amixer
;
260 int n_amixer
= apcm
->substream
->runtime
->channels
, i
= 0;
261 int device
= apcm
->substream
->pcm
->device
;
264 /* first release old resources */
265 atc_pcm_release_resources(atc
, apcm
);
267 /* Get SRC resource */
268 desc
.multi
= apcm
->substream
->runtime
->channels
;
271 err
= src_mgr
->get_src(src_mgr
, &desc
, (struct src
**)&apcm
->src
);
275 pitch
= atc_get_pitch(apcm
->substream
->runtime
->rate
,
276 (atc
->rsr
* atc
->msr
));
278 src
->ops
->set_pitch(src
, pitch
);
279 src
->ops
->set_rom(src
, select_rom(pitch
));
280 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
281 src
->ops
->set_pm(src
, (src
->ops
->next_interleave(src
) != NULL
));
283 /* Get AMIXER resource */
284 n_amixer
= (n_amixer
< 2) ? 2 : n_amixer
;
285 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
286 if (NULL
== apcm
->amixers
) {
290 mix_dsc
.msr
= atc
->msr
;
291 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
292 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
293 (struct amixer
**)&apcm
->amixers
[i
]);
300 /* Set up device virtual mem map */
301 err
= ct_map_audio_buffer(atc
, apcm
);
305 /* Connect resources */
307 for (i
= 0; i
< n_amixer
; i
++) {
308 amixer
= apcm
->amixers
[i
];
309 mutex_lock(&atc
->atc_mutex
);
310 amixer
->ops
->setup(amixer
, &src
->rsc
,
311 INIT_VOL
, atc
->pcm
[i
+device
*2]);
312 mutex_unlock(&atc
->atc_mutex
);
313 src
= src
->ops
->next_interleave(src
);
318 ct_timer_prepare(apcm
->timer
);
323 atc_pcm_release_resources(atc
, apcm
);
328 atc_pcm_release_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
330 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
331 struct srcimp_mgr
*srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
332 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
333 struct sum_mgr
*sum_mgr
= atc
->rsc_mgrs
[SUM
];
334 struct srcimp
*srcimp
;
337 if (NULL
!= apcm
->srcimps
) {
338 for (i
= 0; i
< apcm
->n_srcimp
; i
++) {
339 srcimp
= apcm
->srcimps
[i
];
340 srcimp
->ops
->unmap(srcimp
);
341 srcimp_mgr
->put_srcimp(srcimp_mgr
, srcimp
);
342 apcm
->srcimps
[i
] = NULL
;
344 kfree(apcm
->srcimps
);
345 apcm
->srcimps
= NULL
;
348 if (NULL
!= apcm
->srccs
) {
349 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
350 src_mgr
->put_src(src_mgr
, apcm
->srccs
[i
]);
351 apcm
->srccs
[i
] = NULL
;
357 if (NULL
!= apcm
->amixers
) {
358 for (i
= 0; i
< apcm
->n_amixer
; i
++) {
359 amixer_mgr
->put_amixer(amixer_mgr
, apcm
->amixers
[i
]);
360 apcm
->amixers
[i
] = NULL
;
362 kfree(apcm
->amixers
);
363 apcm
->amixers
= NULL
;
366 if (NULL
!= apcm
->mono
) {
367 sum_mgr
->put_sum(sum_mgr
, apcm
->mono
);
371 if (NULL
!= apcm
->src
) {
372 src_mgr
->put_src(src_mgr
, apcm
->src
);
376 if (NULL
!= apcm
->vm_block
) {
377 /* Undo device virtual mem map */
378 ct_unmap_audio_buffer(atc
, apcm
);
379 apcm
->vm_block
= NULL
;
385 static int atc_pcm_playback_start(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
387 unsigned int max_cisz
;
388 struct src
*src
= apcm
->src
;
394 max_cisz
= src
->multi
* src
->rsc
.msr
;
395 max_cisz
= 0x80 * (max_cisz
< 8 ? max_cisz
: 8);
397 src
->ops
->set_sa(src
, apcm
->vm_block
->addr
);
398 src
->ops
->set_la(src
, apcm
->vm_block
->addr
+ apcm
->vm_block
->size
);
399 src
->ops
->set_ca(src
, apcm
->vm_block
->addr
+ max_cisz
);
400 src
->ops
->set_cisz(src
, max_cisz
);
402 src
->ops
->set_bm(src
, 1);
403 src
->ops
->set_state(src
, SRC_STATE_INIT
);
404 src
->ops
->commit_write(src
);
406 ct_timer_start(apcm
->timer
);
410 static int atc_pcm_stop(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
415 ct_timer_stop(apcm
->timer
);
418 src
->ops
->set_bm(src
, 0);
419 src
->ops
->set_state(src
, SRC_STATE_OFF
);
420 src
->ops
->commit_write(src
);
422 if (NULL
!= apcm
->srccs
) {
423 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
424 src
= apcm
->srccs
[i
];
425 src
->ops
->set_bm(src
, 0);
426 src
->ops
->set_state(src
, SRC_STATE_OFF
);
427 src
->ops
->commit_write(src
);
437 atc_pcm_playback_position(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
439 struct src
*src
= apcm
->src
;
445 position
= src
->ops
->get_ca(src
);
447 size
= apcm
->vm_block
->size
;
448 max_cisz
= src
->multi
* src
->rsc
.msr
;
449 max_cisz
= 128 * (max_cisz
< 8 ? max_cisz
: 8);
451 return (position
+ size
- max_cisz
- apcm
->vm_block
->addr
) % size
;
454 struct src_node_conf_t
{
457 unsigned int mix_msr
:8;
458 unsigned int imp_msr
:8;
462 static void setup_src_node_conf(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
,
463 struct src_node_conf_t
*conf
, int *n_srcc
)
467 /* get pitch and convert to fixed-point 8.24 format. */
468 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
469 apcm
->substream
->runtime
->rate
);
473 *n_srcc
= apcm
->substream
->runtime
->channels
;
474 conf
[0].pitch
= pitch
;
475 conf
[0].mix_msr
= conf
[0].imp_msr
= conf
[0].msr
= 1;
477 } else if (2 == atc
->msr
) {
478 if (0x8000000 < pitch
) {
479 /* Need two-stage SRCs, SRCIMPs and
480 * AMIXERs for converting format */
481 conf
[0].pitch
= (atc
->msr
<< 24);
482 conf
[0].msr
= conf
[0].mix_msr
= 1;
483 conf
[0].imp_msr
= atc
->msr
;
485 conf
[1].pitch
= atc_get_pitch(atc
->rsr
,
486 apcm
->substream
->runtime
->rate
);
487 conf
[1].msr
= conf
[1].mix_msr
= conf
[1].imp_msr
= 1;
489 *n_srcc
= apcm
->substream
->runtime
->channels
* 2;
490 } else if (0x1000000 < pitch
) {
491 /* Need one-stage SRCs, SRCIMPs and
492 * AMIXERs for converting format */
493 conf
[0].pitch
= pitch
;
494 conf
[0].msr
= conf
[0].mix_msr
495 = conf
[0].imp_msr
= atc
->msr
;
497 *n_srcc
= apcm
->substream
->runtime
->channels
;
503 atc_pcm_capture_get_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
505 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
506 struct srcimp_mgr
*srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
507 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
508 struct sum_mgr
*sum_mgr
= atc
->rsc_mgrs
[SUM
];
509 struct src_desc src_dsc
= {0};
511 struct srcimp_desc srcimp_dsc
= {0};
512 struct srcimp
*srcimp
;
513 struct amixer_desc mix_dsc
= {0};
514 struct sum_desc sum_dsc
= {0};
517 int n_srcimp
, n_amixer
, n_srcc
, n_sum
;
518 struct src_node_conf_t src_node_conf
[2] = {{0} };
520 /* first release old resources */
521 atc_pcm_release_resources(atc
, apcm
);
523 /* The numbers of converting SRCs and SRCIMPs should be determined
526 multi
= apcm
->substream
->runtime
->channels
;
528 /* get pitch and convert to fixed-point 8.24 format. */
529 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
530 apcm
->substream
->runtime
->rate
);
532 setup_src_node_conf(atc
, apcm
, src_node_conf
, &n_srcc
);
533 n_sum
= (1 == multi
) ? 1 : 0;
534 n_amixer
= n_sum
* 2 + n_srcc
;
536 if ((multi
> 1) && (0x8000000 >= pitch
)) {
537 /* Need extra AMIXERs and SRCIMPs for special treatment
538 * of interleaved recording of conjugate channels */
539 n_amixer
+= multi
* atc
->msr
;
540 n_srcimp
+= multi
* atc
->msr
;
546 apcm
->srccs
= kzalloc(sizeof(void *)*n_srcc
, GFP_KERNEL
);
547 if (NULL
== apcm
->srccs
)
551 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
552 if (NULL
== apcm
->amixers
) {
557 apcm
->srcimps
= kzalloc(sizeof(void *)*n_srcimp
, GFP_KERNEL
);
558 if (NULL
== apcm
->srcimps
) {
563 /* Allocate SRCs for sample rate conversion if needed */
565 src_dsc
.mode
= ARCRW
;
566 for (i
= 0, apcm
->n_srcc
= 0; i
< n_srcc
; i
++) {
567 src_dsc
.msr
= src_node_conf
[i
/multi
].msr
;
568 err
= src_mgr
->get_src(src_mgr
, &src_dsc
,
569 (struct src
**)&apcm
->srccs
[i
]);
573 src
= apcm
->srccs
[i
];
574 pitch
= src_node_conf
[i
/multi
].pitch
;
575 src
->ops
->set_pitch(src
, pitch
);
576 src
->ops
->set_rom(src
, select_rom(pitch
));
577 src
->ops
->set_vo(src
, src_node_conf
[i
/multi
].vo
);
582 /* Allocate AMIXERs for routing SRCs of conversion if needed */
583 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
585 mix_dsc
.msr
= atc
->msr
;
586 else if (i
< (n_sum
*2+n_srcc
))
587 mix_dsc
.msr
= src_node_conf
[(i
-n_sum
*2)/multi
].mix_msr
;
591 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
592 (struct amixer
**)&apcm
->amixers
[i
]);
599 /* Allocate a SUM resource to mix all input channels together */
600 sum_dsc
.msr
= atc
->msr
;
601 err
= sum_mgr
->get_sum(sum_mgr
, &sum_dsc
, (struct sum
**)&apcm
->mono
);
605 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
606 apcm
->substream
->runtime
->rate
);
607 /* Allocate SRCIMP resources */
608 for (i
= 0, apcm
->n_srcimp
= 0; i
< n_srcimp
; i
++) {
610 srcimp_dsc
.msr
= src_node_conf
[i
/multi
].imp_msr
;
612 srcimp_dsc
.msr
= (pitch
<= 0x8000000) ? atc
->msr
: 1;
616 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
, &srcimp
);
620 apcm
->srcimps
[i
] = srcimp
;
624 /* Allocate a SRC for writing data to host memory */
625 src_dsc
.multi
= apcm
->substream
->runtime
->channels
;
627 src_dsc
.mode
= MEMWR
;
628 err
= src_mgr
->get_src(src_mgr
, &src_dsc
, (struct src
**)&apcm
->src
);
633 src
->ops
->set_pitch(src
, pitch
);
635 /* Set up device virtual mem map */
636 err
= ct_map_audio_buffer(atc
, apcm
);
643 atc_pcm_release_resources(atc
, apcm
);
647 static int atc_pcm_capture_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
650 struct amixer
*amixer
;
651 struct srcimp
*srcimp
;
652 struct ct_mixer
*mixer
= atc
->mixer
;
654 struct rsc
*out_ports
[8] = {NULL
};
655 int err
, i
, j
, n_sum
, multi
;
657 int mix_base
= 0, imp_base
= 0;
659 atc_pcm_release_resources(atc
, apcm
);
661 /* Get needed resources. */
662 err
= atc_pcm_capture_get_resources(atc
, apcm
);
666 /* Connect resources */
667 mixer
->get_output_ports(mixer
, MIX_PCMO_FRONT
,
668 &out_ports
[0], &out_ports
[1]);
670 multi
= apcm
->substream
->runtime
->channels
;
673 for (i
= 0; i
< 2; i
++) {
674 amixer
= apcm
->amixers
[i
];
675 amixer
->ops
->setup(amixer
, out_ports
[i
],
676 MONO_SUM_SCALE
, mono
);
678 out_ports
[0] = &mono
->rsc
;
680 mix_base
= n_sum
* 2;
683 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
684 src
= apcm
->srccs
[i
];
685 srcimp
= apcm
->srcimps
[imp_base
+i
];
686 amixer
= apcm
->amixers
[mix_base
+i
];
687 srcimp
->ops
->map(srcimp
, src
, out_ports
[i
%multi
]);
688 amixer
->ops
->setup(amixer
, &src
->rsc
, INIT_VOL
, NULL
);
689 out_ports
[i
%multi
] = &amixer
->rsc
;
692 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
693 apcm
->substream
->runtime
->rate
);
695 if ((multi
> 1) && (pitch
<= 0x8000000)) {
696 /* Special connection for interleaved
697 * recording with conjugate channels */
698 for (i
= 0; i
< multi
; i
++) {
699 out_ports
[i
]->ops
->master(out_ports
[i
]);
700 for (j
= 0; j
< atc
->msr
; j
++) {
701 amixer
= apcm
->amixers
[apcm
->n_srcc
+j
*multi
+i
];
702 amixer
->ops
->set_input(amixer
, out_ports
[i
]);
703 amixer
->ops
->set_scale(amixer
, INIT_VOL
);
704 amixer
->ops
->set_sum(amixer
, NULL
);
705 amixer
->ops
->commit_raw_write(amixer
);
706 out_ports
[i
]->ops
->next_conj(out_ports
[i
]);
708 srcimp
= apcm
->srcimps
[apcm
->n_srcc
+j
*multi
+i
];
709 srcimp
->ops
->map(srcimp
, apcm
->src
,
714 for (i
= 0; i
< multi
; i
++) {
715 srcimp
= apcm
->srcimps
[apcm
->n_srcc
+i
];
716 srcimp
->ops
->map(srcimp
, apcm
->src
, out_ports
[i
]);
720 ct_timer_prepare(apcm
->timer
);
725 static int atc_pcm_capture_start(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
728 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
735 multi
= apcm
->substream
->runtime
->channels
;
736 /* Set up converting SRCs */
737 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
738 src
= apcm
->srccs
[i
];
739 src
->ops
->set_pm(src
, ((i
%multi
) != (multi
-1)));
740 src_mgr
->src_disable(src_mgr
, src
);
743 /* Set up recording SRC */
745 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
746 src
->ops
->set_sa(src
, apcm
->vm_block
->addr
);
747 src
->ops
->set_la(src
, apcm
->vm_block
->addr
+ apcm
->vm_block
->size
);
748 src
->ops
->set_ca(src
, apcm
->vm_block
->addr
);
749 src_mgr
->src_disable(src_mgr
, src
);
751 /* Disable relevant SRCs firstly */
752 src_mgr
->commit_write(src_mgr
);
754 /* Enable SRCs respectively */
755 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
756 src
= apcm
->srccs
[i
];
757 src
->ops
->set_state(src
, SRC_STATE_RUN
);
758 src
->ops
->commit_write(src
);
759 src_mgr
->src_enable_s(src_mgr
, src
);
762 src
->ops
->set_bm(src
, 1);
763 src
->ops
->set_state(src
, SRC_STATE_RUN
);
764 src
->ops
->commit_write(src
);
765 src_mgr
->src_enable_s(src_mgr
, src
);
767 /* Enable relevant SRCs synchronously */
768 src_mgr
->commit_write(src_mgr
);
770 ct_timer_start(apcm
->timer
);
775 atc_pcm_capture_position(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
777 struct src
*src
= apcm
->src
;
781 return src
->ops
->get_ca(src
) - apcm
->vm_block
->addr
;
784 static int spdif_passthru_playback_get_resources(struct ct_atc
*atc
,
785 struct ct_atc_pcm
*apcm
)
787 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
788 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
789 struct src_desc desc
= {0};
790 struct amixer_desc mix_dsc
= {0};
793 int n_amixer
= apcm
->substream
->runtime
->channels
, i
;
794 unsigned int pitch
, rsr
= atc
->pll_rate
;
796 /* first release old resources */
797 atc_pcm_release_resources(atc
, apcm
);
799 /* Get SRC resource */
800 desc
.multi
= apcm
->substream
->runtime
->channels
;
802 while (apcm
->substream
->runtime
->rate
> (rsr
* desc
.msr
))
806 err
= src_mgr
->get_src(src_mgr
, &desc
, (struct src
**)&apcm
->src
);
810 pitch
= atc_get_pitch(apcm
->substream
->runtime
->rate
, (rsr
* desc
.msr
));
812 src
->ops
->set_pitch(src
, pitch
);
813 src
->ops
->set_rom(src
, select_rom(pitch
));
814 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
815 src
->ops
->set_pm(src
, (src
->ops
->next_interleave(src
) != NULL
));
816 src
->ops
->set_bp(src
, 1);
818 /* Get AMIXER resource */
819 n_amixer
= (n_amixer
< 2) ? 2 : n_amixer
;
820 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
821 if (NULL
== apcm
->amixers
) {
825 mix_dsc
.msr
= desc
.msr
;
826 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
827 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
828 (struct amixer
**)&apcm
->amixers
[i
]);
835 /* Set up device virtual mem map */
836 err
= ct_map_audio_buffer(atc
, apcm
);
843 atc_pcm_release_resources(atc
, apcm
);
847 static int atc_pll_init(struct ct_atc
*atc
, int rate
)
849 struct hw
*hw
= atc
->hw
;
851 err
= hw
->pll_init(hw
, rate
);
852 atc
->pll_rate
= err
? 0 : rate
;
857 spdif_passthru_playback_setup(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
859 struct dao
*dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
860 unsigned int rate
= apcm
->substream
->runtime
->rate
;
863 unsigned char iec958_con_fs
;
867 iec958_con_fs
= IEC958_AES3_CON_FS_48000
;
870 iec958_con_fs
= IEC958_AES3_CON_FS_44100
;
873 iec958_con_fs
= IEC958_AES3_CON_FS_32000
;
879 mutex_lock(&atc
->atc_mutex
);
880 dao
->ops
->get_spos(dao
, &status
);
881 if (((status
>> 24) & IEC958_AES3_CON_FS
) != iec958_con_fs
) {
882 status
&= ((~IEC958_AES3_CON_FS
) << 24);
883 status
|= (iec958_con_fs
<< 24);
884 dao
->ops
->set_spos(dao
, status
);
885 dao
->ops
->commit_write(dao
);
887 if ((rate
!= atc
->pll_rate
) && (32000 != rate
))
888 err
= atc_pll_init(atc
, rate
);
889 mutex_unlock(&atc
->atc_mutex
);
895 spdif_passthru_playback_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
898 struct amixer
*amixer
;
903 atc_pcm_release_resources(atc
, apcm
);
905 /* Configure SPDIFOO and PLL to passthrough mode;
906 * determine pll_rate. */
907 err
= spdif_passthru_playback_setup(atc
, apcm
);
911 /* Get needed resources. */
912 err
= spdif_passthru_playback_get_resources(atc
, apcm
);
916 /* Connect resources */
918 for (i
= 0; i
< apcm
->n_amixer
; i
++) {
919 amixer
= apcm
->amixers
[i
];
920 amixer
->ops
->setup(amixer
, &src
->rsc
, INIT_VOL
, NULL
);
921 src
= src
->ops
->next_interleave(src
);
925 /* Connect to SPDIFOO */
926 mutex_lock(&atc
->atc_mutex
);
927 dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
928 amixer
= apcm
->amixers
[0];
929 dao
->ops
->set_left_input(dao
, &amixer
->rsc
);
930 amixer
= apcm
->amixers
[1];
931 dao
->ops
->set_right_input(dao
, &amixer
->rsc
);
932 mutex_unlock(&atc
->atc_mutex
);
934 ct_timer_prepare(apcm
->timer
);
939 static int atc_select_line_in(struct ct_atc
*atc
)
941 struct hw
*hw
= atc
->hw
;
942 struct ct_mixer
*mixer
= atc
->mixer
;
945 if (hw
->is_adc_source_selected(hw
, ADC_LINEIN
))
948 mixer
->set_input_left(mixer
, MIX_MIC_IN
, NULL
);
949 mixer
->set_input_right(mixer
, MIX_MIC_IN
, NULL
);
951 hw
->select_adc_source(hw
, ADC_LINEIN
);
954 mixer
->set_input_left(mixer
, MIX_LINE_IN
, &src
->rsc
);
956 mixer
->set_input_right(mixer
, MIX_LINE_IN
, &src
->rsc
);
961 static int atc_select_mic_in(struct ct_atc
*atc
)
963 struct hw
*hw
= atc
->hw
;
964 struct ct_mixer
*mixer
= atc
->mixer
;
967 if (hw
->is_adc_source_selected(hw
, ADC_MICIN
))
970 mixer
->set_input_left(mixer
, MIX_LINE_IN
, NULL
);
971 mixer
->set_input_right(mixer
, MIX_LINE_IN
, NULL
);
973 hw
->select_adc_source(hw
, ADC_MICIN
);
976 mixer
->set_input_left(mixer
, MIX_MIC_IN
, &src
->rsc
);
978 mixer
->set_input_right(mixer
, MIX_MIC_IN
, &src
->rsc
);
983 static int atc_have_digit_io_switch(struct ct_atc
*atc
)
985 struct hw
*hw
= atc
->hw
;
987 return hw
->have_digit_io_switch(hw
);
990 static int atc_select_digit_io(struct ct_atc
*atc
)
992 struct hw
*hw
= atc
->hw
;
994 if (hw
->is_adc_source_selected(hw
, ADC_NONE
))
997 hw
->select_adc_source(hw
, ADC_NONE
);
1002 static int atc_daio_unmute(struct ct_atc
*atc
, unsigned char state
, int type
)
1004 struct daio_mgr
*daio_mgr
= atc
->rsc_mgrs
[DAIO
];
1007 daio_mgr
->daio_enable(daio_mgr
, atc
->daios
[type
]);
1009 daio_mgr
->daio_disable(daio_mgr
, atc
->daios
[type
]);
1011 daio_mgr
->commit_write(daio_mgr
);
1017 atc_dao_get_status(struct ct_atc
*atc
, unsigned int *status
, int type
)
1019 struct dao
*dao
= container_of(atc
->daios
[type
], struct dao
, daio
);
1020 return dao
->ops
->get_spos(dao
, status
);
1024 atc_dao_set_status(struct ct_atc
*atc
, unsigned int status
, int type
)
1026 struct dao
*dao
= container_of(atc
->daios
[type
], struct dao
, daio
);
1028 dao
->ops
->set_spos(dao
, status
);
1029 dao
->ops
->commit_write(dao
);
1033 static int atc_line_front_unmute(struct ct_atc
*atc
, unsigned char state
)
1035 return atc_daio_unmute(atc
, state
, LINEO1
);
1038 static int atc_line_surround_unmute(struct ct_atc
*atc
, unsigned char state
)
1040 return atc_daio_unmute(atc
, state
, LINEO4
);
1043 static int atc_line_clfe_unmute(struct ct_atc
*atc
, unsigned char state
)
1045 return atc_daio_unmute(atc
, state
, LINEO3
);
1048 static int atc_line_rear_unmute(struct ct_atc
*atc
, unsigned char state
)
1050 return atc_daio_unmute(atc
, state
, LINEO2
);
1053 static int atc_line_in_unmute(struct ct_atc
*atc
, unsigned char state
)
1055 return atc_daio_unmute(atc
, state
, LINEIM
);
1058 static int atc_spdif_out_unmute(struct ct_atc
*atc
, unsigned char state
)
1060 return atc_daio_unmute(atc
, state
, SPDIFOO
);
1063 static int atc_spdif_in_unmute(struct ct_atc
*atc
, unsigned char state
)
1065 return atc_daio_unmute(atc
, state
, SPDIFIO
);
1068 static int atc_spdif_out_get_status(struct ct_atc
*atc
, unsigned int *status
)
1070 return atc_dao_get_status(atc
, status
, SPDIFOO
);
1073 static int atc_spdif_out_set_status(struct ct_atc
*atc
, unsigned int status
)
1075 return atc_dao_set_status(atc
, status
, SPDIFOO
);
1078 static int atc_spdif_out_passthru(struct ct_atc
*atc
, unsigned char state
)
1080 struct dao_desc da_dsc
= {0};
1083 struct ct_mixer
*mixer
= atc
->mixer
;
1084 struct rsc
*rscs
[2] = {NULL
};
1085 unsigned int spos
= 0;
1087 mutex_lock(&atc
->atc_mutex
);
1088 dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
1089 da_dsc
.msr
= state
? 1 : atc
->msr
;
1090 da_dsc
.passthru
= state
? 1 : 0;
1091 err
= dao
->ops
->reinit(dao
, &da_dsc
);
1093 spos
= IEC958_DEFAULT_CON
;
1095 mixer
->get_output_ports(mixer
, MIX_SPDIF_OUT
,
1096 &rscs
[0], &rscs
[1]);
1097 dao
->ops
->set_left_input(dao
, rscs
[0]);
1098 dao
->ops
->set_right_input(dao
, rscs
[1]);
1099 /* Restore PLL to atc->rsr if needed. */
1100 if (atc
->pll_rate
!= atc
->rsr
)
1101 err
= atc_pll_init(atc
, atc
->rsr
);
1103 dao
->ops
->set_spos(dao
, spos
);
1104 dao
->ops
->commit_write(dao
);
1105 mutex_unlock(&atc
->atc_mutex
);
1110 static int atc_release_resources(struct ct_atc
*atc
)
1113 struct daio_mgr
*daio_mgr
= NULL
;
1114 struct dao
*dao
= NULL
;
1115 struct dai
*dai
= NULL
;
1116 struct daio
*daio
= NULL
;
1117 struct sum_mgr
*sum_mgr
= NULL
;
1118 struct src_mgr
*src_mgr
= NULL
;
1119 struct srcimp_mgr
*srcimp_mgr
= NULL
;
1120 struct srcimp
*srcimp
= NULL
;
1121 struct ct_mixer
*mixer
= NULL
;
1123 /* disconnect internal mixer objects */
1124 if (NULL
!= atc
->mixer
) {
1126 mixer
->set_input_left(mixer
, MIX_LINE_IN
, NULL
);
1127 mixer
->set_input_right(mixer
, MIX_LINE_IN
, NULL
);
1128 mixer
->set_input_left(mixer
, MIX_MIC_IN
, NULL
);
1129 mixer
->set_input_right(mixer
, MIX_MIC_IN
, NULL
);
1130 mixer
->set_input_left(mixer
, MIX_SPDIF_IN
, NULL
);
1131 mixer
->set_input_right(mixer
, MIX_SPDIF_IN
, NULL
);
1134 if (NULL
!= atc
->daios
) {
1135 daio_mgr
= (struct daio_mgr
*)atc
->rsc_mgrs
[DAIO
];
1136 for (i
= 0; i
< atc
->n_daio
; i
++) {
1137 daio
= atc
->daios
[i
];
1138 if (daio
->type
< LINEIM
) {
1139 dao
= container_of(daio
, struct dao
, daio
);
1140 dao
->ops
->clear_left_input(dao
);
1141 dao
->ops
->clear_right_input(dao
);
1143 dai
= container_of(daio
, struct dai
, daio
);
1144 /* some thing to do for dai ... */
1146 daio_mgr
->put_daio(daio_mgr
, daio
);
1152 if (NULL
!= atc
->pcm
) {
1153 sum_mgr
= atc
->rsc_mgrs
[SUM
];
1154 for (i
= 0; i
< atc
->n_pcm
; i
++)
1155 sum_mgr
->put_sum(sum_mgr
, atc
->pcm
[i
]);
1161 if (NULL
!= atc
->srcs
) {
1162 src_mgr
= atc
->rsc_mgrs
[SRC
];
1163 for (i
= 0; i
< atc
->n_src
; i
++)
1164 src_mgr
->put_src(src_mgr
, atc
->srcs
[i
]);
1170 if (NULL
!= atc
->srcimps
) {
1171 srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
1172 for (i
= 0; i
< atc
->n_srcimp
; i
++) {
1173 srcimp
= atc
->srcimps
[i
];
1174 srcimp
->ops
->unmap(srcimp
);
1175 srcimp_mgr
->put_srcimp(srcimp_mgr
, atc
->srcimps
[i
]);
1177 kfree(atc
->srcimps
);
1178 atc
->srcimps
= NULL
;
1184 static int ct_atc_destroy(struct ct_atc
*atc
)
1192 ct_timer_free(atc
->timer
);
1196 atc_release_resources(atc
);
1198 /* Destroy internal mixer objects */
1199 if (NULL
!= atc
->mixer
)
1200 ct_mixer_destroy(atc
->mixer
);
1202 for (i
= 0; i
< NUM_RSCTYP
; i
++) {
1203 if ((NULL
!= rsc_mgr_funcs
[i
].destroy
) &&
1204 (NULL
!= atc
->rsc_mgrs
[i
]))
1205 rsc_mgr_funcs
[i
].destroy(atc
->rsc_mgrs
[i
]);
1209 if (NULL
!= atc
->hw
)
1210 destroy_hw_obj((struct hw
*)atc
->hw
);
1212 /* Destroy device virtual memory manager object */
1213 if (NULL
!= atc
->vm
) {
1214 ct_vm_destroy(atc
->vm
);
1223 static int atc_dev_free(struct snd_device
*dev
)
1225 struct ct_atc
*atc
= dev
->device_data
;
1226 return ct_atc_destroy(atc
);
1229 static int __devinit
atc_identify_card(struct ct_atc
*atc
)
1231 const struct snd_pci_quirk
*p
;
1232 const struct snd_pci_quirk
*list
;
1234 switch (atc
->chip_type
) {
1236 atc
->chip_name
= "20K1";
1237 list
= subsys_20k1_list
;
1240 atc
->chip_name
= "20K2";
1241 list
= subsys_20k2_list
;
1246 p
= snd_pci_quirk_lookup(atc
->pci
, list
);
1249 printk(KERN_ERR
"ctxfi: "
1250 "Device %04x:%04x is black-listed\n",
1251 atc
->pci
->subsystem_vendor
,
1252 atc
->pci
->subsystem_device
);
1255 atc
->model
= p
->value
;
1257 if (atc
->chip_type
== ATC20K1
)
1258 atc
->model
= CT20K1_UNKNOWN
;
1260 atc
->model
= CT20K2_UNKNOWN
;
1262 atc
->model_name
= ct_subsys_name
[atc
->model
];
1263 snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n",
1264 atc
->chip_name
, atc
->model_name
,
1265 atc
->pci
->subsystem_vendor
,
1266 atc
->pci
->subsystem_device
);
1270 int __devinit
ct_atc_create_alsa_devs(struct ct_atc
*atc
)
1275 alsa_dev_funcs
[MIXER
].public_name
= atc
->chip_name
;
1277 for (i
= 0; i
< NUM_CTALSADEVS
; i
++) {
1278 if (NULL
== alsa_dev_funcs
[i
].create
)
1281 err
= alsa_dev_funcs
[i
].create(atc
, i
,
1282 alsa_dev_funcs
[i
].public_name
);
1284 printk(KERN_ERR
"ctxfi: "
1285 "Creating alsa device %d failed!\n", i
);
1293 static int __devinit
atc_create_hw_devs(struct ct_atc
*atc
)
1296 struct card_conf info
= {0};
1299 err
= create_hw_obj(atc
->pci
, atc
->chip_type
, atc
->model
, &hw
);
1301 printk(KERN_ERR
"Failed to create hw obj!!!\n");
1306 /* Initialize card hardware. */
1307 info
.rsr
= atc
->rsr
;
1308 info
.msr
= atc
->msr
;
1309 info
.vm_pgt_phys
= atc_get_ptp_phys(atc
, 0);
1310 err
= hw
->card_init(hw
, &info
);
1314 for (i
= 0; i
< NUM_RSCTYP
; i
++) {
1315 if (NULL
== rsc_mgr_funcs
[i
].create
)
1318 err
= rsc_mgr_funcs
[i
].create(atc
->hw
, &atc
->rsc_mgrs
[i
]);
1320 printk(KERN_ERR
"ctxfi: "
1321 "Failed to create rsc_mgr %d!!!\n", i
);
1329 static int atc_get_resources(struct ct_atc
*atc
)
1331 struct daio_desc da_desc
= {0};
1332 struct daio_mgr
*daio_mgr
;
1333 struct src_desc src_dsc
= {0};
1334 struct src_mgr
*src_mgr
;
1335 struct srcimp_desc srcimp_dsc
= {0};
1336 struct srcimp_mgr
*srcimp_mgr
;
1337 struct sum_desc sum_dsc
= {0};
1338 struct sum_mgr
*sum_mgr
;
1341 atc
->daios
= kzalloc(sizeof(void *)*(DAIONUM
), GFP_KERNEL
);
1342 if (NULL
== atc
->daios
)
1345 atc
->srcs
= kzalloc(sizeof(void *)*(2*2), GFP_KERNEL
);
1346 if (NULL
== atc
->srcs
)
1349 atc
->srcimps
= kzalloc(sizeof(void *)*(2*2), GFP_KERNEL
);
1350 if (NULL
== atc
->srcimps
)
1353 atc
->pcm
= kzalloc(sizeof(void *)*(2*4), GFP_KERNEL
);
1354 if (NULL
== atc
->pcm
)
1357 daio_mgr
= (struct daio_mgr
*)atc
->rsc_mgrs
[DAIO
];
1358 da_desc
.msr
= atc
->msr
;
1359 for (i
= 0, atc
->n_daio
= 0; i
< DAIONUM
-1; i
++) {
1361 err
= daio_mgr
->get_daio(daio_mgr
, &da_desc
,
1362 (struct daio
**)&atc
->daios
[i
]);
1364 printk(KERN_ERR
"ctxfi: Failed to get DAIO "
1365 "resource %d!!!\n", i
);
1370 if (atc
->model
== CTSB073X
)
1371 da_desc
.type
= SPDIFI1
;
1373 da_desc
.type
= SPDIFIO
;
1374 err
= daio_mgr
->get_daio(daio_mgr
, &da_desc
,
1375 (struct daio
**)&atc
->daios
[i
]);
1377 printk(KERN_ERR
"ctxfi: Failed to get S/PDIF-in resource!!!\n");
1382 src_mgr
= atc
->rsc_mgrs
[SRC
];
1384 src_dsc
.msr
= atc
->msr
;
1385 src_dsc
.mode
= ARCRW
;
1386 for (i
= 0, atc
->n_src
= 0; i
< (2*2); i
++) {
1387 err
= src_mgr
->get_src(src_mgr
, &src_dsc
,
1388 (struct src
**)&atc
->srcs
[i
]);
1395 srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
1396 srcimp_dsc
.msr
= 8; /* SRCIMPs for S/PDIFIn SRT */
1397 for (i
= 0, atc
->n_srcimp
= 0; i
< (2*1); i
++) {
1398 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
,
1399 (struct srcimp
**)&atc
->srcimps
[i
]);
1405 srcimp_dsc
.msr
= 8; /* SRCIMPs for LINE/MICIn SRT */
1406 for (i
= 0; i
< (2*1); i
++) {
1407 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
,
1408 (struct srcimp
**)&atc
->srcimps
[2*1+i
]);
1415 sum_mgr
= atc
->rsc_mgrs
[SUM
];
1416 sum_dsc
.msr
= atc
->msr
;
1417 for (i
= 0, atc
->n_pcm
= 0; i
< (2*4); i
++) {
1418 err
= sum_mgr
->get_sum(sum_mgr
, &sum_dsc
,
1419 (struct sum
**)&atc
->pcm
[i
]);
1430 atc_connect_dai(struct src_mgr
*src_mgr
, struct dai
*dai
,
1431 struct src
**srcs
, struct srcimp
**srcimps
)
1433 struct rsc
*rscs
[2] = {NULL
};
1435 struct srcimp
*srcimp
;
1438 rscs
[0] = &dai
->daio
.rscl
;
1439 rscs
[1] = &dai
->daio
.rscr
;
1440 for (i
= 0; i
< 2; i
++) {
1442 srcimp
= srcimps
[i
];
1443 srcimp
->ops
->map(srcimp
, src
, rscs
[i
]);
1444 src_mgr
->src_disable(src_mgr
, src
);
1447 src_mgr
->commit_write(src_mgr
); /* Actually disable SRCs */
1450 src
->ops
->set_pm(src
, 1);
1451 for (i
= 0; i
< 2; i
++) {
1453 src
->ops
->set_state(src
, SRC_STATE_RUN
);
1454 src
->ops
->commit_write(src
);
1455 src_mgr
->src_enable_s(src_mgr
, src
);
1458 dai
->ops
->set_srt_srcl(dai
, &(srcs
[0]->rsc
));
1459 dai
->ops
->set_srt_srcr(dai
, &(srcs
[1]->rsc
));
1461 dai
->ops
->set_enb_src(dai
, 1);
1462 dai
->ops
->set_enb_srt(dai
, 1);
1463 dai
->ops
->commit_write(dai
);
1465 src_mgr
->commit_write(src_mgr
); /* Synchronously enable SRCs */
1468 static void atc_connect_resources(struct ct_atc
*atc
)
1474 struct ct_mixer
*mixer
;
1475 struct rsc
*rscs
[2] = {NULL
};
1480 for (i
= MIX_WAVE_FRONT
, j
= LINEO1
; i
<= MIX_SPDIF_OUT
; i
++, j
++) {
1481 mixer
->get_output_ports(mixer
, i
, &rscs
[0], &rscs
[1]);
1482 dao
= container_of(atc
->daios
[j
], struct dao
, daio
);
1483 dao
->ops
->set_left_input(dao
, rscs
[0]);
1484 dao
->ops
->set_right_input(dao
, rscs
[1]);
1487 dai
= container_of(atc
->daios
[LINEIM
], struct dai
, daio
);
1488 atc_connect_dai(atc
->rsc_mgrs
[SRC
], dai
,
1489 (struct src
**)&atc
->srcs
[2],
1490 (struct srcimp
**)&atc
->srcimps
[2]);
1492 mixer
->set_input_left(mixer
, MIX_LINE_IN
, &src
->rsc
);
1494 mixer
->set_input_right(mixer
, MIX_LINE_IN
, &src
->rsc
);
1496 dai
= container_of(atc
->daios
[SPDIFIO
], struct dai
, daio
);
1497 atc_connect_dai(atc
->rsc_mgrs
[SRC
], dai
,
1498 (struct src
**)&atc
->srcs
[0],
1499 (struct srcimp
**)&atc
->srcimps
[0]);
1502 mixer
->set_input_left(mixer
, MIX_SPDIF_IN
, &src
->rsc
);
1504 mixer
->set_input_right(mixer
, MIX_SPDIF_IN
, &src
->rsc
);
1506 for (i
= MIX_PCMI_FRONT
, j
= 0; i
<= MIX_PCMI_SURROUND
; i
++, j
+= 2) {
1508 mixer
->set_input_left(mixer
, i
, &sum
->rsc
);
1509 sum
= atc
->pcm
[j
+1];
1510 mixer
->set_input_right(mixer
, i
, &sum
->rsc
);
1515 static int atc_suspend(struct ct_atc
*atc
, pm_message_t state
)
1518 struct hw
*hw
= atc
->hw
;
1520 snd_power_change_state(atc
->card
, SNDRV_CTL_POWER_D3hot
);
1522 for (i
= FRONT
; i
< NUM_PCMS
; i
++) {
1526 snd_pcm_suspend_all(atc
->pcms
[i
]);
1529 atc_release_resources(atc
);
1531 hw
->suspend(hw
, state
);
1536 static int atc_hw_resume(struct ct_atc
*atc
)
1538 struct hw
*hw
= atc
->hw
;
1539 struct card_conf info
= {0};
1541 /* Re-initialize card hardware. */
1542 info
.rsr
= atc
->rsr
;
1543 info
.msr
= atc
->msr
;
1544 info
.vm_pgt_phys
= atc_get_ptp_phys(atc
, 0);
1545 return hw
->resume(hw
, &info
);
1548 static int atc_resources_resume(struct ct_atc
*atc
)
1550 struct ct_mixer
*mixer
;
1554 err
= atc_get_resources(atc
);
1556 atc_release_resources(atc
);
1560 /* Build topology */
1561 atc_connect_resources(atc
);
1564 mixer
->resume(mixer
);
1569 static int atc_resume(struct ct_atc
*atc
)
1573 /* Do hardware resume. */
1574 err
= atc_hw_resume(atc
);
1576 printk(KERN_ERR
"ctxfi: pci_enable_device failed, "
1577 "disabling device\n");
1578 snd_card_disconnect(atc
->card
);
1582 err
= atc_resources_resume(atc
);
1586 snd_power_change_state(atc
->card
, SNDRV_CTL_POWER_D0
);
1592 static struct ct_atc atc_preset __devinitdata
= {
1593 .map_audio_buffer
= ct_map_audio_buffer
,
1594 .unmap_audio_buffer
= ct_unmap_audio_buffer
,
1595 .pcm_playback_prepare
= atc_pcm_playback_prepare
,
1596 .pcm_release_resources
= atc_pcm_release_resources
,
1597 .pcm_playback_start
= atc_pcm_playback_start
,
1598 .pcm_playback_stop
= atc_pcm_stop
,
1599 .pcm_playback_position
= atc_pcm_playback_position
,
1600 .pcm_capture_prepare
= atc_pcm_capture_prepare
,
1601 .pcm_capture_start
= atc_pcm_capture_start
,
1602 .pcm_capture_stop
= atc_pcm_stop
,
1603 .pcm_capture_position
= atc_pcm_capture_position
,
1604 .spdif_passthru_playback_prepare
= spdif_passthru_playback_prepare
,
1605 .get_ptp_phys
= atc_get_ptp_phys
,
1606 .select_line_in
= atc_select_line_in
,
1607 .select_mic_in
= atc_select_mic_in
,
1608 .select_digit_io
= atc_select_digit_io
,
1609 .line_front_unmute
= atc_line_front_unmute
,
1610 .line_surround_unmute
= atc_line_surround_unmute
,
1611 .line_clfe_unmute
= atc_line_clfe_unmute
,
1612 .line_rear_unmute
= atc_line_rear_unmute
,
1613 .line_in_unmute
= atc_line_in_unmute
,
1614 .spdif_out_unmute
= atc_spdif_out_unmute
,
1615 .spdif_in_unmute
= atc_spdif_in_unmute
,
1616 .spdif_out_get_status
= atc_spdif_out_get_status
,
1617 .spdif_out_set_status
= atc_spdif_out_set_status
,
1618 .spdif_out_passthru
= atc_spdif_out_passthru
,
1619 .have_digit_io_switch
= atc_have_digit_io_switch
,
1621 .suspend
= atc_suspend
,
1622 .resume
= atc_resume
,
1627 * ct_atc_create - create and initialize a hardware manager
1628 * @card: corresponding alsa card object
1629 * @pci: corresponding kernel pci device object
1630 * @ratc: return created object address in it
1632 * Creates and initializes a hardware manager.
1634 * Creates kmallocated ct_atc structure. Initializes hardware.
1635 * Returns 0 if suceeds, or negative error code if fails.
1638 int __devinit
ct_atc_create(struct snd_card
*card
, struct pci_dev
*pci
,
1639 unsigned int rsr
, unsigned int msr
,
1640 int chip_type
, struct ct_atc
**ratc
)
1643 static struct snd_device_ops ops
= {
1644 .dev_free
= atc_dev_free
,
1650 atc
= kzalloc(sizeof(*atc
), GFP_KERNEL
);
1654 /* Set operations */
1661 atc
->chip_type
= chip_type
;
1663 mutex_init(&atc
->atc_mutex
);
1665 /* Find card model */
1666 err
= atc_identify_card(atc
);
1668 printk(KERN_ERR
"ctatc: Card not recognised\n");
1672 /* Set up device virtual memory management object */
1673 err
= ct_vm_create(&atc
->vm
);
1677 /* Create all atc hw devices */
1678 err
= atc_create_hw_devs(atc
);
1682 err
= ct_mixer_create(atc
, (struct ct_mixer
**)&atc
->mixer
);
1684 printk(KERN_ERR
"ctxfi: Failed to create mixer obj!!!\n");
1689 err
= atc_get_resources(atc
);
1693 /* Build topology */
1694 atc_connect_resources(atc
);
1696 atc
->timer
= ct_timer_new(atc
);
1700 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, atc
, &ops
);
1704 snd_card_set_dev(card
, &pci
->dev
);
1710 ct_atc_destroy(atc
);
1711 printk(KERN_ERR
"ctxfi: Something wrong!!!\n");