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 <linux/slab.h>
28 #include <sound/pcm.h>
29 #include <sound/control.h>
30 #include <sound/asoundef.h>
32 #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */
34 #define MAX_MULTI_CHN 8
36 #define IEC958_DEFAULT_CON ((IEC958_AES0_NONAUDIO \
37 | IEC958_AES0_CON_NOT_COPYRIGHT) \
38 | ((IEC958_AES1_CON_MIXER \
39 | IEC958_AES1_CON_ORIGINAL) << 8) \
41 | ((IEC958_AES3_CON_FS_48000) << 24))
43 static struct snd_pci_quirk __devinitdata subsys_20k1_list
[] = {
44 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0022, "SB055x", CTSB055X
),
45 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x002f, "SB055x", CTSB055X
),
46 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0029, "SB073x", CTSB073X
),
47 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, 0x0031, "SB073x", CTSB073X
),
48 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE
, 0xf000, 0x6000,
53 static struct snd_pci_quirk __devinitdata subsys_20k2_list
[] = {
54 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB0760
,
56 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08801
,
58 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08802
,
60 SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE
, PCI_SUBDEVICE_ID_CREATIVE_SB08803
,
62 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE
, 0xf000,
63 PCI_SUBDEVICE_ID_CREATIVE_HENDRIX
, "HENDRIX",
68 static const char *ct_subsys_name
[NUM_CTCARDS
] = {
70 [CTSB055X
] = "SB055x",
71 [CTSB073X
] = "SB073x",
73 [CT20K1_UNKNOWN
] = "Unknown",
75 [CTSB0760
] = "SB076x",
76 [CTHENDRIX
] = "Hendrix",
77 [CTSB0880
] = "SB0880",
78 [CT20K2_UNKNOWN
] = "Unknown",
82 int (*create
)(struct ct_atc
*atc
,
83 enum CTALSADEVS device
, const char *device_name
);
84 int (*destroy
)(void *alsa_dev
);
85 const char *public_name
;
86 } alsa_dev_funcs
[NUM_CTALSADEVS
] = {
87 [FRONT
] = { .create
= ct_alsa_pcm_create
,
89 .public_name
= "Front/WaveIn"},
90 [SURROUND
] = { .create
= ct_alsa_pcm_create
,
92 .public_name
= "Surround"},
93 [CLFE
] = { .create
= ct_alsa_pcm_create
,
95 .public_name
= "Center/LFE"},
96 [SIDE
] = { .create
= ct_alsa_pcm_create
,
98 .public_name
= "Side"},
99 [IEC958
] = { .create
= ct_alsa_pcm_create
,
101 .public_name
= "IEC958 Non-audio"},
103 [MIXER
] = { .create
= ct_alsa_mix_create
,
105 .public_name
= "Mixer"}
108 typedef int (*create_t
)(void *, void **);
109 typedef int (*destroy_t
)(void *);
112 int (*create
)(void *hw
, void **rmgr
);
113 int (*destroy
)(void *mgr
);
114 } rsc_mgr_funcs
[NUM_RSCTYP
] = {
115 [SRC
] = { .create
= (create_t
)src_mgr_create
,
116 .destroy
= (destroy_t
)src_mgr_destroy
},
117 [SRCIMP
] = { .create
= (create_t
)srcimp_mgr_create
,
118 .destroy
= (destroy_t
)srcimp_mgr_destroy
},
119 [AMIXER
] = { .create
= (create_t
)amixer_mgr_create
,
120 .destroy
= (destroy_t
)amixer_mgr_destroy
},
121 [SUM
] = { .create
= (create_t
)sum_mgr_create
,
122 .destroy
= (destroy_t
)sum_mgr_destroy
},
123 [DAIO
] = { .create
= (create_t
)daio_mgr_create
,
124 .destroy
= (destroy_t
)daio_mgr_destroy
}
128 atc_pcm_release_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
);
131 * Only mono and interleaved modes are supported now.
132 * Always allocates a contiguous channel block.
135 static int ct_map_audio_buffer(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
137 struct snd_pcm_runtime
*runtime
;
140 if (!apcm
->substream
)
143 runtime
= apcm
->substream
->runtime
;
146 apcm
->vm_block
= vm
->map(vm
, apcm
->substream
, runtime
->dma_bytes
);
154 static void ct_unmap_audio_buffer(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
163 vm
->unmap(vm
, apcm
->vm_block
);
165 apcm
->vm_block
= NULL
;
168 static unsigned long atc_get_ptp_phys(struct ct_atc
*atc
, int index
)
170 return atc
->vm
->get_ptp_phys(atc
->vm
, index
);
173 static unsigned int convert_format(snd_pcm_format_t snd_format
)
175 switch (snd_format
) {
176 case SNDRV_PCM_FORMAT_U8
:
178 case SNDRV_PCM_FORMAT_S16_LE
:
180 case SNDRV_PCM_FORMAT_S24_3LE
:
182 case SNDRV_PCM_FORMAT_S32_LE
:
184 case SNDRV_PCM_FORMAT_FLOAT_LE
:
187 printk(KERN_ERR
"ctxfi: not recognized snd format is %d \n",
194 atc_get_pitch(unsigned int input_rate
, unsigned int output_rate
)
199 /* get pitch and convert to fixed-point 8.24 format. */
200 pitch
= (input_rate
/ output_rate
) << 24;
201 input_rate
%= output_rate
;
204 for (b
= 31; ((b
>= 0) && !(input_rate
>> b
)); )
208 input_rate
<<= (31 - b
);
209 input_rate
/= output_rate
;
222 static int select_rom(unsigned int pitch
)
224 if (pitch
> 0x00428f5c && pitch
< 0x01b851ec) {
225 /* 0.26 <= pitch <= 1.72 */
227 } else if (pitch
== 0x01d66666 || pitch
== 0x01d66667) {
228 /* pitch == 1.8375 */
230 } else if (pitch
== 0x02000000) {
233 } else if (pitch
<= 0x08000000) {
234 /* 0 <= pitch <= 8 */
241 static int atc_pcm_playback_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
243 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
244 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
245 struct src_desc desc
= {0};
246 struct amixer_desc mix_dsc
= {0};
248 struct amixer
*amixer
;
250 int n_amixer
= apcm
->substream
->runtime
->channels
, i
= 0;
251 int device
= apcm
->substream
->pcm
->device
;
254 /* first release old resources */
255 atc_pcm_release_resources(atc
, apcm
);
257 /* Get SRC resource */
258 desc
.multi
= apcm
->substream
->runtime
->channels
;
261 err
= src_mgr
->get_src(src_mgr
, &desc
, (struct src
**)&apcm
->src
);
265 pitch
= atc_get_pitch(apcm
->substream
->runtime
->rate
,
266 (atc
->rsr
* atc
->msr
));
268 src
->ops
->set_pitch(src
, pitch
);
269 src
->ops
->set_rom(src
, select_rom(pitch
));
270 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
271 src
->ops
->set_pm(src
, (src
->ops
->next_interleave(src
) != NULL
));
273 /* Get AMIXER resource */
274 n_amixer
= (n_amixer
< 2) ? 2 : n_amixer
;
275 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
276 if (!apcm
->amixers
) {
280 mix_dsc
.msr
= atc
->msr
;
281 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
282 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
283 (struct amixer
**)&apcm
->amixers
[i
]);
290 /* Set up device virtual mem map */
291 err
= ct_map_audio_buffer(atc
, apcm
);
295 /* Connect resources */
297 for (i
= 0; i
< n_amixer
; i
++) {
298 amixer
= apcm
->amixers
[i
];
299 mutex_lock(&atc
->atc_mutex
);
300 amixer
->ops
->setup(amixer
, &src
->rsc
,
301 INIT_VOL
, atc
->pcm
[i
+device
*2]);
302 mutex_unlock(&atc
->atc_mutex
);
303 src
= src
->ops
->next_interleave(src
);
308 ct_timer_prepare(apcm
->timer
);
313 atc_pcm_release_resources(atc
, apcm
);
318 atc_pcm_release_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
320 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
321 struct srcimp_mgr
*srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
322 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
323 struct sum_mgr
*sum_mgr
= atc
->rsc_mgrs
[SUM
];
324 struct srcimp
*srcimp
;
328 for (i
= 0; i
< apcm
->n_srcimp
; i
++) {
329 srcimp
= apcm
->srcimps
[i
];
330 srcimp
->ops
->unmap(srcimp
);
331 srcimp_mgr
->put_srcimp(srcimp_mgr
, srcimp
);
332 apcm
->srcimps
[i
] = NULL
;
334 kfree(apcm
->srcimps
);
335 apcm
->srcimps
= NULL
;
339 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
340 src_mgr
->put_src(src_mgr
, apcm
->srccs
[i
]);
341 apcm
->srccs
[i
] = NULL
;
348 for (i
= 0; i
< apcm
->n_amixer
; i
++) {
349 amixer_mgr
->put_amixer(amixer_mgr
, apcm
->amixers
[i
]);
350 apcm
->amixers
[i
] = NULL
;
352 kfree(apcm
->amixers
);
353 apcm
->amixers
= NULL
;
357 sum_mgr
->put_sum(sum_mgr
, apcm
->mono
);
362 src_mgr
->put_src(src_mgr
, apcm
->src
);
366 if (apcm
->vm_block
) {
367 /* Undo device virtual mem map */
368 ct_unmap_audio_buffer(atc
, apcm
);
369 apcm
->vm_block
= NULL
;
375 static int atc_pcm_playback_start(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
377 unsigned int max_cisz
;
378 struct src
*src
= apcm
->src
;
384 max_cisz
= src
->multi
* src
->rsc
.msr
;
385 max_cisz
= 0x80 * (max_cisz
< 8 ? max_cisz
: 8);
387 src
->ops
->set_sa(src
, apcm
->vm_block
->addr
);
388 src
->ops
->set_la(src
, apcm
->vm_block
->addr
+ apcm
->vm_block
->size
);
389 src
->ops
->set_ca(src
, apcm
->vm_block
->addr
+ max_cisz
);
390 src
->ops
->set_cisz(src
, max_cisz
);
392 src
->ops
->set_bm(src
, 1);
393 src
->ops
->set_state(src
, SRC_STATE_INIT
);
394 src
->ops
->commit_write(src
);
396 ct_timer_start(apcm
->timer
);
400 static int atc_pcm_stop(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
405 ct_timer_stop(apcm
->timer
);
408 src
->ops
->set_bm(src
, 0);
409 src
->ops
->set_state(src
, SRC_STATE_OFF
);
410 src
->ops
->commit_write(src
);
413 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
414 src
= apcm
->srccs
[i
];
415 src
->ops
->set_bm(src
, 0);
416 src
->ops
->set_state(src
, SRC_STATE_OFF
);
417 src
->ops
->commit_write(src
);
427 atc_pcm_playback_position(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
429 struct src
*src
= apcm
->src
;
435 position
= src
->ops
->get_ca(src
);
437 size
= apcm
->vm_block
->size
;
438 max_cisz
= src
->multi
* src
->rsc
.msr
;
439 max_cisz
= 128 * (max_cisz
< 8 ? max_cisz
: 8);
441 return (position
+ size
- max_cisz
- apcm
->vm_block
->addr
) % size
;
444 struct src_node_conf_t
{
447 unsigned int mix_msr
:8;
448 unsigned int imp_msr
:8;
452 static void setup_src_node_conf(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
,
453 struct src_node_conf_t
*conf
, int *n_srcc
)
457 /* get pitch and convert to fixed-point 8.24 format. */
458 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
459 apcm
->substream
->runtime
->rate
);
463 *n_srcc
= apcm
->substream
->runtime
->channels
;
464 conf
[0].pitch
= pitch
;
465 conf
[0].mix_msr
= conf
[0].imp_msr
= conf
[0].msr
= 1;
467 } else if (2 == atc
->msr
) {
468 if (0x8000000 < pitch
) {
469 /* Need two-stage SRCs, SRCIMPs and
470 * AMIXERs for converting format */
471 conf
[0].pitch
= (atc
->msr
<< 24);
472 conf
[0].msr
= conf
[0].mix_msr
= 1;
473 conf
[0].imp_msr
= atc
->msr
;
475 conf
[1].pitch
= atc_get_pitch(atc
->rsr
,
476 apcm
->substream
->runtime
->rate
);
477 conf
[1].msr
= conf
[1].mix_msr
= conf
[1].imp_msr
= 1;
479 *n_srcc
= apcm
->substream
->runtime
->channels
* 2;
480 } else if (0x1000000 < pitch
) {
481 /* Need one-stage SRCs, SRCIMPs and
482 * AMIXERs for converting format */
483 conf
[0].pitch
= pitch
;
484 conf
[0].msr
= conf
[0].mix_msr
485 = conf
[0].imp_msr
= atc
->msr
;
487 *n_srcc
= apcm
->substream
->runtime
->channels
;
493 atc_pcm_capture_get_resources(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
495 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
496 struct srcimp_mgr
*srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
497 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
498 struct sum_mgr
*sum_mgr
= atc
->rsc_mgrs
[SUM
];
499 struct src_desc src_dsc
= {0};
501 struct srcimp_desc srcimp_dsc
= {0};
502 struct srcimp
*srcimp
;
503 struct amixer_desc mix_dsc
= {0};
504 struct sum_desc sum_dsc
= {0};
507 int n_srcimp
, n_amixer
, n_srcc
, n_sum
;
508 struct src_node_conf_t src_node_conf
[2] = {{0} };
510 /* first release old resources */
511 atc_pcm_release_resources(atc
, apcm
);
513 /* The numbers of converting SRCs and SRCIMPs should be determined
516 multi
= apcm
->substream
->runtime
->channels
;
518 /* get pitch and convert to fixed-point 8.24 format. */
519 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
520 apcm
->substream
->runtime
->rate
);
522 setup_src_node_conf(atc
, apcm
, src_node_conf
, &n_srcc
);
523 n_sum
= (1 == multi
) ? 1 : 0;
524 n_amixer
= n_sum
* 2 + n_srcc
;
526 if ((multi
> 1) && (0x8000000 >= pitch
)) {
527 /* Need extra AMIXERs and SRCIMPs for special treatment
528 * of interleaved recording of conjugate channels */
529 n_amixer
+= multi
* atc
->msr
;
530 n_srcimp
+= multi
* atc
->msr
;
536 apcm
->srccs
= kzalloc(sizeof(void *)*n_srcc
, GFP_KERNEL
);
541 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
542 if (!apcm
->amixers
) {
547 apcm
->srcimps
= kzalloc(sizeof(void *)*n_srcimp
, GFP_KERNEL
);
548 if (!apcm
->srcimps
) {
553 /* Allocate SRCs for sample rate conversion if needed */
555 src_dsc
.mode
= ARCRW
;
556 for (i
= 0, apcm
->n_srcc
= 0; i
< n_srcc
; i
++) {
557 src_dsc
.msr
= src_node_conf
[i
/multi
].msr
;
558 err
= src_mgr
->get_src(src_mgr
, &src_dsc
,
559 (struct src
**)&apcm
->srccs
[i
]);
563 src
= apcm
->srccs
[i
];
564 pitch
= src_node_conf
[i
/multi
].pitch
;
565 src
->ops
->set_pitch(src
, pitch
);
566 src
->ops
->set_rom(src
, select_rom(pitch
));
567 src
->ops
->set_vo(src
, src_node_conf
[i
/multi
].vo
);
572 /* Allocate AMIXERs for routing SRCs of conversion if needed */
573 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
575 mix_dsc
.msr
= atc
->msr
;
576 else if (i
< (n_sum
*2+n_srcc
))
577 mix_dsc
.msr
= src_node_conf
[(i
-n_sum
*2)/multi
].mix_msr
;
581 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
582 (struct amixer
**)&apcm
->amixers
[i
]);
589 /* Allocate a SUM resource to mix all input channels together */
590 sum_dsc
.msr
= atc
->msr
;
591 err
= sum_mgr
->get_sum(sum_mgr
, &sum_dsc
, (struct sum
**)&apcm
->mono
);
595 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
596 apcm
->substream
->runtime
->rate
);
597 /* Allocate SRCIMP resources */
598 for (i
= 0, apcm
->n_srcimp
= 0; i
< n_srcimp
; i
++) {
600 srcimp_dsc
.msr
= src_node_conf
[i
/multi
].imp_msr
;
602 srcimp_dsc
.msr
= (pitch
<= 0x8000000) ? atc
->msr
: 1;
606 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
, &srcimp
);
610 apcm
->srcimps
[i
] = srcimp
;
614 /* Allocate a SRC for writing data to host memory */
615 src_dsc
.multi
= apcm
->substream
->runtime
->channels
;
617 src_dsc
.mode
= MEMWR
;
618 err
= src_mgr
->get_src(src_mgr
, &src_dsc
, (struct src
**)&apcm
->src
);
623 src
->ops
->set_pitch(src
, pitch
);
625 /* Set up device virtual mem map */
626 err
= ct_map_audio_buffer(atc
, apcm
);
633 atc_pcm_release_resources(atc
, apcm
);
637 static int atc_pcm_capture_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
640 struct amixer
*amixer
;
641 struct srcimp
*srcimp
;
642 struct ct_mixer
*mixer
= atc
->mixer
;
644 struct rsc
*out_ports
[8] = {NULL
};
645 int err
, i
, j
, n_sum
, multi
;
647 int mix_base
= 0, imp_base
= 0;
649 atc_pcm_release_resources(atc
, apcm
);
651 /* Get needed resources. */
652 err
= atc_pcm_capture_get_resources(atc
, apcm
);
656 /* Connect resources */
657 mixer
->get_output_ports(mixer
, MIX_PCMO_FRONT
,
658 &out_ports
[0], &out_ports
[1]);
660 multi
= apcm
->substream
->runtime
->channels
;
663 for (i
= 0; i
< 2; i
++) {
664 amixer
= apcm
->amixers
[i
];
665 amixer
->ops
->setup(amixer
, out_ports
[i
],
666 MONO_SUM_SCALE
, mono
);
668 out_ports
[0] = &mono
->rsc
;
670 mix_base
= n_sum
* 2;
673 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
674 src
= apcm
->srccs
[i
];
675 srcimp
= apcm
->srcimps
[imp_base
+i
];
676 amixer
= apcm
->amixers
[mix_base
+i
];
677 srcimp
->ops
->map(srcimp
, src
, out_ports
[i
%multi
]);
678 amixer
->ops
->setup(amixer
, &src
->rsc
, INIT_VOL
, NULL
);
679 out_ports
[i
%multi
] = &amixer
->rsc
;
682 pitch
= atc_get_pitch((atc
->rsr
* atc
->msr
),
683 apcm
->substream
->runtime
->rate
);
685 if ((multi
> 1) && (pitch
<= 0x8000000)) {
686 /* Special connection for interleaved
687 * recording with conjugate channels */
688 for (i
= 0; i
< multi
; i
++) {
689 out_ports
[i
]->ops
->master(out_ports
[i
]);
690 for (j
= 0; j
< atc
->msr
; j
++) {
691 amixer
= apcm
->amixers
[apcm
->n_srcc
+j
*multi
+i
];
692 amixer
->ops
->set_input(amixer
, out_ports
[i
]);
693 amixer
->ops
->set_scale(amixer
, INIT_VOL
);
694 amixer
->ops
->set_sum(amixer
, NULL
);
695 amixer
->ops
->commit_raw_write(amixer
);
696 out_ports
[i
]->ops
->next_conj(out_ports
[i
]);
698 srcimp
= apcm
->srcimps
[apcm
->n_srcc
+j
*multi
+i
];
699 srcimp
->ops
->map(srcimp
, apcm
->src
,
704 for (i
= 0; i
< multi
; i
++) {
705 srcimp
= apcm
->srcimps
[apcm
->n_srcc
+i
];
706 srcimp
->ops
->map(srcimp
, apcm
->src
, out_ports
[i
]);
710 ct_timer_prepare(apcm
->timer
);
715 static int atc_pcm_capture_start(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
718 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
725 multi
= apcm
->substream
->runtime
->channels
;
726 /* Set up converting SRCs */
727 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
728 src
= apcm
->srccs
[i
];
729 src
->ops
->set_pm(src
, ((i
%multi
) != (multi
-1)));
730 src_mgr
->src_disable(src_mgr
, src
);
733 /* Set up recording SRC */
735 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
736 src
->ops
->set_sa(src
, apcm
->vm_block
->addr
);
737 src
->ops
->set_la(src
, apcm
->vm_block
->addr
+ apcm
->vm_block
->size
);
738 src
->ops
->set_ca(src
, apcm
->vm_block
->addr
);
739 src_mgr
->src_disable(src_mgr
, src
);
741 /* Disable relevant SRCs firstly */
742 src_mgr
->commit_write(src_mgr
);
744 /* Enable SRCs respectively */
745 for (i
= 0; i
< apcm
->n_srcc
; i
++) {
746 src
= apcm
->srccs
[i
];
747 src
->ops
->set_state(src
, SRC_STATE_RUN
);
748 src
->ops
->commit_write(src
);
749 src_mgr
->src_enable_s(src_mgr
, src
);
752 src
->ops
->set_bm(src
, 1);
753 src
->ops
->set_state(src
, SRC_STATE_RUN
);
754 src
->ops
->commit_write(src
);
755 src_mgr
->src_enable_s(src_mgr
, src
);
757 /* Enable relevant SRCs synchronously */
758 src_mgr
->commit_write(src_mgr
);
760 ct_timer_start(apcm
->timer
);
765 atc_pcm_capture_position(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
767 struct src
*src
= apcm
->src
;
771 return src
->ops
->get_ca(src
) - apcm
->vm_block
->addr
;
774 static int spdif_passthru_playback_get_resources(struct ct_atc
*atc
,
775 struct ct_atc_pcm
*apcm
)
777 struct src_mgr
*src_mgr
= atc
->rsc_mgrs
[SRC
];
778 struct amixer_mgr
*amixer_mgr
= atc
->rsc_mgrs
[AMIXER
];
779 struct src_desc desc
= {0};
780 struct amixer_desc mix_dsc
= {0};
783 int n_amixer
= apcm
->substream
->runtime
->channels
, i
;
784 unsigned int pitch
, rsr
= atc
->pll_rate
;
786 /* first release old resources */
787 atc_pcm_release_resources(atc
, apcm
);
789 /* Get SRC resource */
790 desc
.multi
= apcm
->substream
->runtime
->channels
;
792 while (apcm
->substream
->runtime
->rate
> (rsr
* desc
.msr
))
796 err
= src_mgr
->get_src(src_mgr
, &desc
, (struct src
**)&apcm
->src
);
800 pitch
= atc_get_pitch(apcm
->substream
->runtime
->rate
, (rsr
* desc
.msr
));
802 src
->ops
->set_pitch(src
, pitch
);
803 src
->ops
->set_rom(src
, select_rom(pitch
));
804 src
->ops
->set_sf(src
, convert_format(apcm
->substream
->runtime
->format
));
805 src
->ops
->set_pm(src
, (src
->ops
->next_interleave(src
) != NULL
));
806 src
->ops
->set_bp(src
, 1);
808 /* Get AMIXER resource */
809 n_amixer
= (n_amixer
< 2) ? 2 : n_amixer
;
810 apcm
->amixers
= kzalloc(sizeof(void *)*n_amixer
, GFP_KERNEL
);
811 if (!apcm
->amixers
) {
815 mix_dsc
.msr
= desc
.msr
;
816 for (i
= 0, apcm
->n_amixer
= 0; i
< n_amixer
; i
++) {
817 err
= amixer_mgr
->get_amixer(amixer_mgr
, &mix_dsc
,
818 (struct amixer
**)&apcm
->amixers
[i
]);
825 /* Set up device virtual mem map */
826 err
= ct_map_audio_buffer(atc
, apcm
);
833 atc_pcm_release_resources(atc
, apcm
);
837 static int atc_pll_init(struct ct_atc
*atc
, int rate
)
839 struct hw
*hw
= atc
->hw
;
841 err
= hw
->pll_init(hw
, rate
);
842 atc
->pll_rate
= err
? 0 : rate
;
847 spdif_passthru_playback_setup(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
849 struct dao
*dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
850 unsigned int rate
= apcm
->substream
->runtime
->rate
;
853 unsigned char iec958_con_fs
;
857 iec958_con_fs
= IEC958_AES3_CON_FS_48000
;
860 iec958_con_fs
= IEC958_AES3_CON_FS_44100
;
863 iec958_con_fs
= IEC958_AES3_CON_FS_32000
;
869 mutex_lock(&atc
->atc_mutex
);
870 dao
->ops
->get_spos(dao
, &status
);
871 if (((status
>> 24) & IEC958_AES3_CON_FS
) != iec958_con_fs
) {
872 status
&= ~(IEC958_AES3_CON_FS
<< 24);
873 status
|= (iec958_con_fs
<< 24);
874 dao
->ops
->set_spos(dao
, status
);
875 dao
->ops
->commit_write(dao
);
877 if ((rate
!= atc
->pll_rate
) && (32000 != rate
))
878 err
= atc_pll_init(atc
, rate
);
879 mutex_unlock(&atc
->atc_mutex
);
885 spdif_passthru_playback_prepare(struct ct_atc
*atc
, struct ct_atc_pcm
*apcm
)
888 struct amixer
*amixer
;
893 atc_pcm_release_resources(atc
, apcm
);
895 /* Configure SPDIFOO and PLL to passthrough mode;
896 * determine pll_rate. */
897 err
= spdif_passthru_playback_setup(atc
, apcm
);
901 /* Get needed resources. */
902 err
= spdif_passthru_playback_get_resources(atc
, apcm
);
906 /* Connect resources */
908 for (i
= 0; i
< apcm
->n_amixer
; i
++) {
909 amixer
= apcm
->amixers
[i
];
910 amixer
->ops
->setup(amixer
, &src
->rsc
, INIT_VOL
, NULL
);
911 src
= src
->ops
->next_interleave(src
);
915 /* Connect to SPDIFOO */
916 mutex_lock(&atc
->atc_mutex
);
917 dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
918 amixer
= apcm
->amixers
[0];
919 dao
->ops
->set_left_input(dao
, &amixer
->rsc
);
920 amixer
= apcm
->amixers
[1];
921 dao
->ops
->set_right_input(dao
, &amixer
->rsc
);
922 mutex_unlock(&atc
->atc_mutex
);
924 ct_timer_prepare(apcm
->timer
);
929 static int atc_select_line_in(struct ct_atc
*atc
)
931 struct hw
*hw
= atc
->hw
;
932 struct ct_mixer
*mixer
= atc
->mixer
;
935 if (hw
->is_adc_source_selected(hw
, ADC_LINEIN
))
938 mixer
->set_input_left(mixer
, MIX_MIC_IN
, NULL
);
939 mixer
->set_input_right(mixer
, MIX_MIC_IN
, NULL
);
941 hw
->select_adc_source(hw
, ADC_LINEIN
);
944 mixer
->set_input_left(mixer
, MIX_LINE_IN
, &src
->rsc
);
946 mixer
->set_input_right(mixer
, MIX_LINE_IN
, &src
->rsc
);
951 static int atc_select_mic_in(struct ct_atc
*atc
)
953 struct hw
*hw
= atc
->hw
;
954 struct ct_mixer
*mixer
= atc
->mixer
;
957 if (hw
->is_adc_source_selected(hw
, ADC_MICIN
))
960 mixer
->set_input_left(mixer
, MIX_LINE_IN
, NULL
);
961 mixer
->set_input_right(mixer
, MIX_LINE_IN
, NULL
);
963 hw
->select_adc_source(hw
, ADC_MICIN
);
966 mixer
->set_input_left(mixer
, MIX_MIC_IN
, &src
->rsc
);
968 mixer
->set_input_right(mixer
, MIX_MIC_IN
, &src
->rsc
);
973 static int atc_have_digit_io_switch(struct ct_atc
*atc
)
975 struct hw
*hw
= atc
->hw
;
977 return hw
->have_digit_io_switch(hw
);
980 static int atc_select_digit_io(struct ct_atc
*atc
)
982 struct hw
*hw
= atc
->hw
;
984 if (hw
->is_adc_source_selected(hw
, ADC_NONE
))
987 hw
->select_adc_source(hw
, ADC_NONE
);
992 static int atc_daio_unmute(struct ct_atc
*atc
, unsigned char state
, int type
)
994 struct daio_mgr
*daio_mgr
= atc
->rsc_mgrs
[DAIO
];
997 daio_mgr
->daio_enable(daio_mgr
, atc
->daios
[type
]);
999 daio_mgr
->daio_disable(daio_mgr
, atc
->daios
[type
]);
1001 daio_mgr
->commit_write(daio_mgr
);
1007 atc_dao_get_status(struct ct_atc
*atc
, unsigned int *status
, int type
)
1009 struct dao
*dao
= container_of(atc
->daios
[type
], struct dao
, daio
);
1010 return dao
->ops
->get_spos(dao
, status
);
1014 atc_dao_set_status(struct ct_atc
*atc
, unsigned int status
, int type
)
1016 struct dao
*dao
= container_of(atc
->daios
[type
], struct dao
, daio
);
1018 dao
->ops
->set_spos(dao
, status
);
1019 dao
->ops
->commit_write(dao
);
1023 static int atc_line_front_unmute(struct ct_atc
*atc
, unsigned char state
)
1025 return atc_daio_unmute(atc
, state
, LINEO1
);
1028 static int atc_line_surround_unmute(struct ct_atc
*atc
, unsigned char state
)
1030 return atc_daio_unmute(atc
, state
, LINEO2
);
1033 static int atc_line_clfe_unmute(struct ct_atc
*atc
, unsigned char state
)
1035 return atc_daio_unmute(atc
, state
, LINEO3
);
1038 static int atc_line_rear_unmute(struct ct_atc
*atc
, unsigned char state
)
1040 return atc_daio_unmute(atc
, state
, LINEO4
);
1043 static int atc_line_in_unmute(struct ct_atc
*atc
, unsigned char state
)
1045 return atc_daio_unmute(atc
, state
, LINEIM
);
1048 static int atc_spdif_out_unmute(struct ct_atc
*atc
, unsigned char state
)
1050 return atc_daio_unmute(atc
, state
, SPDIFOO
);
1053 static int atc_spdif_in_unmute(struct ct_atc
*atc
, unsigned char state
)
1055 return atc_daio_unmute(atc
, state
, SPDIFIO
);
1058 static int atc_spdif_out_get_status(struct ct_atc
*atc
, unsigned int *status
)
1060 return atc_dao_get_status(atc
, status
, SPDIFOO
);
1063 static int atc_spdif_out_set_status(struct ct_atc
*atc
, unsigned int status
)
1065 return atc_dao_set_status(atc
, status
, SPDIFOO
);
1068 static int atc_spdif_out_passthru(struct ct_atc
*atc
, unsigned char state
)
1070 struct dao_desc da_dsc
= {0};
1073 struct ct_mixer
*mixer
= atc
->mixer
;
1074 struct rsc
*rscs
[2] = {NULL
};
1075 unsigned int spos
= 0;
1077 mutex_lock(&atc
->atc_mutex
);
1078 dao
= container_of(atc
->daios
[SPDIFOO
], struct dao
, daio
);
1079 da_dsc
.msr
= state
? 1 : atc
->msr
;
1080 da_dsc
.passthru
= state
? 1 : 0;
1081 err
= dao
->ops
->reinit(dao
, &da_dsc
);
1083 spos
= IEC958_DEFAULT_CON
;
1085 mixer
->get_output_ports(mixer
, MIX_SPDIF_OUT
,
1086 &rscs
[0], &rscs
[1]);
1087 dao
->ops
->set_left_input(dao
, rscs
[0]);
1088 dao
->ops
->set_right_input(dao
, rscs
[1]);
1089 /* Restore PLL to atc->rsr if needed. */
1090 if (atc
->pll_rate
!= atc
->rsr
)
1091 err
= atc_pll_init(atc
, atc
->rsr
);
1093 dao
->ops
->set_spos(dao
, spos
);
1094 dao
->ops
->commit_write(dao
);
1095 mutex_unlock(&atc
->atc_mutex
);
1100 static int atc_release_resources(struct ct_atc
*atc
)
1103 struct daio_mgr
*daio_mgr
= NULL
;
1104 struct dao
*dao
= NULL
;
1105 struct dai
*dai
= NULL
;
1106 struct daio
*daio
= NULL
;
1107 struct sum_mgr
*sum_mgr
= NULL
;
1108 struct src_mgr
*src_mgr
= NULL
;
1109 struct srcimp_mgr
*srcimp_mgr
= NULL
;
1110 struct srcimp
*srcimp
= NULL
;
1111 struct ct_mixer
*mixer
= NULL
;
1113 /* disconnect internal mixer objects */
1116 mixer
->set_input_left(mixer
, MIX_LINE_IN
, NULL
);
1117 mixer
->set_input_right(mixer
, MIX_LINE_IN
, NULL
);
1118 mixer
->set_input_left(mixer
, MIX_MIC_IN
, NULL
);
1119 mixer
->set_input_right(mixer
, MIX_MIC_IN
, NULL
);
1120 mixer
->set_input_left(mixer
, MIX_SPDIF_IN
, NULL
);
1121 mixer
->set_input_right(mixer
, MIX_SPDIF_IN
, NULL
);
1125 daio_mgr
= (struct daio_mgr
*)atc
->rsc_mgrs
[DAIO
];
1126 for (i
= 0; i
< atc
->n_daio
; i
++) {
1127 daio
= atc
->daios
[i
];
1128 if (daio
->type
< LINEIM
) {
1129 dao
= container_of(daio
, struct dao
, daio
);
1130 dao
->ops
->clear_left_input(dao
);
1131 dao
->ops
->clear_right_input(dao
);
1133 dai
= container_of(daio
, struct dai
, daio
);
1134 /* some thing to do for dai ... */
1136 daio_mgr
->put_daio(daio_mgr
, daio
);
1143 sum_mgr
= atc
->rsc_mgrs
[SUM
];
1144 for (i
= 0; i
< atc
->n_pcm
; i
++)
1145 sum_mgr
->put_sum(sum_mgr
, atc
->pcm
[i
]);
1152 src_mgr
= atc
->rsc_mgrs
[SRC
];
1153 for (i
= 0; i
< atc
->n_src
; i
++)
1154 src_mgr
->put_src(src_mgr
, atc
->srcs
[i
]);
1161 srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
1162 for (i
= 0; i
< atc
->n_srcimp
; i
++) {
1163 srcimp
= atc
->srcimps
[i
];
1164 srcimp
->ops
->unmap(srcimp
);
1165 srcimp_mgr
->put_srcimp(srcimp_mgr
, atc
->srcimps
[i
]);
1167 kfree(atc
->srcimps
);
1168 atc
->srcimps
= NULL
;
1174 static int ct_atc_destroy(struct ct_atc
*atc
)
1182 ct_timer_free(atc
->timer
);
1186 atc_release_resources(atc
);
1188 /* Destroy internal mixer objects */
1190 ct_mixer_destroy(atc
->mixer
);
1192 for (i
= 0; i
< NUM_RSCTYP
; i
++) {
1193 if (rsc_mgr_funcs
[i
].destroy
&& atc
->rsc_mgrs
[i
])
1194 rsc_mgr_funcs
[i
].destroy(atc
->rsc_mgrs
[i
]);
1199 destroy_hw_obj((struct hw
*)atc
->hw
);
1201 /* Destroy device virtual memory manager object */
1203 ct_vm_destroy(atc
->vm
);
1212 static int atc_dev_free(struct snd_device
*dev
)
1214 struct ct_atc
*atc
= dev
->device_data
;
1215 return ct_atc_destroy(atc
);
1218 static int __devinit
atc_identify_card(struct ct_atc
*atc
, unsigned int ssid
)
1220 const struct snd_pci_quirk
*p
;
1221 const struct snd_pci_quirk
*list
;
1222 u16 vendor_id
, device_id
;
1224 switch (atc
->chip_type
) {
1226 atc
->chip_name
= "20K1";
1227 list
= subsys_20k1_list
;
1230 atc
->chip_name
= "20K2";
1231 list
= subsys_20k2_list
;
1237 vendor_id
= ssid
>> 16;
1238 device_id
= ssid
& 0xffff;
1240 vendor_id
= atc
->pci
->subsystem_vendor
;
1241 device_id
= atc
->pci
->subsystem_device
;
1243 p
= snd_pci_quirk_lookup_id(vendor_id
, device_id
, list
);
1246 printk(KERN_ERR
"ctxfi: "
1247 "Device %04x:%04x is black-listed\n",
1248 vendor_id
, device_id
);
1251 atc
->model
= p
->value
;
1253 if (atc
->chip_type
== ATC20K1
)
1254 atc
->model
= CT20K1_UNKNOWN
;
1256 atc
->model
= CT20K2_UNKNOWN
;
1258 atc
->model_name
= ct_subsys_name
[atc
->model
];
1259 snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n",
1260 atc
->chip_name
, atc
->model_name
,
1261 vendor_id
, device_id
);
1265 int __devinit
ct_atc_create_alsa_devs(struct ct_atc
*atc
)
1270 alsa_dev_funcs
[MIXER
].public_name
= atc
->chip_name
;
1272 for (i
= 0; i
< NUM_CTALSADEVS
; i
++) {
1273 if (!alsa_dev_funcs
[i
].create
)
1276 err
= alsa_dev_funcs
[i
].create(atc
, i
,
1277 alsa_dev_funcs
[i
].public_name
);
1279 printk(KERN_ERR
"ctxfi: "
1280 "Creating alsa device %d failed!\n", i
);
1288 static int __devinit
atc_create_hw_devs(struct ct_atc
*atc
)
1291 struct card_conf info
= {0};
1294 err
= create_hw_obj(atc
->pci
, atc
->chip_type
, atc
->model
, &hw
);
1296 printk(KERN_ERR
"Failed to create hw obj!!!\n");
1301 /* Initialize card hardware. */
1302 info
.rsr
= atc
->rsr
;
1303 info
.msr
= atc
->msr
;
1304 info
.vm_pgt_phys
= atc_get_ptp_phys(atc
, 0);
1305 err
= hw
->card_init(hw
, &info
);
1309 for (i
= 0; i
< NUM_RSCTYP
; i
++) {
1310 if (!rsc_mgr_funcs
[i
].create
)
1313 err
= rsc_mgr_funcs
[i
].create(atc
->hw
, &atc
->rsc_mgrs
[i
]);
1315 printk(KERN_ERR
"ctxfi: "
1316 "Failed to create rsc_mgr %d!!!\n", i
);
1324 static int atc_get_resources(struct ct_atc
*atc
)
1326 struct daio_desc da_desc
= {0};
1327 struct daio_mgr
*daio_mgr
;
1328 struct src_desc src_dsc
= {0};
1329 struct src_mgr
*src_mgr
;
1330 struct srcimp_desc srcimp_dsc
= {0};
1331 struct srcimp_mgr
*srcimp_mgr
;
1332 struct sum_desc sum_dsc
= {0};
1333 struct sum_mgr
*sum_mgr
;
1336 atc
->daios
= kzalloc(sizeof(void *)*(DAIONUM
), GFP_KERNEL
);
1340 atc
->srcs
= kzalloc(sizeof(void *)*(2*2), GFP_KERNEL
);
1344 atc
->srcimps
= kzalloc(sizeof(void *)*(2*2), GFP_KERNEL
);
1348 atc
->pcm
= kzalloc(sizeof(void *)*(2*4), GFP_KERNEL
);
1352 daio_mgr
= (struct daio_mgr
*)atc
->rsc_mgrs
[DAIO
];
1353 da_desc
.msr
= atc
->msr
;
1354 for (i
= 0, atc
->n_daio
= 0; i
< DAIONUM
-1; i
++) {
1356 err
= daio_mgr
->get_daio(daio_mgr
, &da_desc
,
1357 (struct daio
**)&atc
->daios
[i
]);
1359 printk(KERN_ERR
"ctxfi: Failed to get DAIO "
1360 "resource %d!!!\n", i
);
1365 if (atc
->model
== CTSB073X
)
1366 da_desc
.type
= SPDIFI1
;
1368 da_desc
.type
= SPDIFIO
;
1369 err
= daio_mgr
->get_daio(daio_mgr
, &da_desc
,
1370 (struct daio
**)&atc
->daios
[i
]);
1372 printk(KERN_ERR
"ctxfi: Failed to get S/PDIF-in resource!!!\n");
1377 src_mgr
= atc
->rsc_mgrs
[SRC
];
1379 src_dsc
.msr
= atc
->msr
;
1380 src_dsc
.mode
= ARCRW
;
1381 for (i
= 0, atc
->n_src
= 0; i
< (2*2); i
++) {
1382 err
= src_mgr
->get_src(src_mgr
, &src_dsc
,
1383 (struct src
**)&atc
->srcs
[i
]);
1390 srcimp_mgr
= atc
->rsc_mgrs
[SRCIMP
];
1391 srcimp_dsc
.msr
= 8; /* SRCIMPs for S/PDIFIn SRT */
1392 for (i
= 0, atc
->n_srcimp
= 0; i
< (2*1); i
++) {
1393 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
,
1394 (struct srcimp
**)&atc
->srcimps
[i
]);
1400 srcimp_dsc
.msr
= 8; /* SRCIMPs for LINE/MICIn SRT */
1401 for (i
= 0; i
< (2*1); i
++) {
1402 err
= srcimp_mgr
->get_srcimp(srcimp_mgr
, &srcimp_dsc
,
1403 (struct srcimp
**)&atc
->srcimps
[2*1+i
]);
1410 sum_mgr
= atc
->rsc_mgrs
[SUM
];
1411 sum_dsc
.msr
= atc
->msr
;
1412 for (i
= 0, atc
->n_pcm
= 0; i
< (2*4); i
++) {
1413 err
= sum_mgr
->get_sum(sum_mgr
, &sum_dsc
,
1414 (struct sum
**)&atc
->pcm
[i
]);
1425 atc_connect_dai(struct src_mgr
*src_mgr
, struct dai
*dai
,
1426 struct src
**srcs
, struct srcimp
**srcimps
)
1428 struct rsc
*rscs
[2] = {NULL
};
1430 struct srcimp
*srcimp
;
1433 rscs
[0] = &dai
->daio
.rscl
;
1434 rscs
[1] = &dai
->daio
.rscr
;
1435 for (i
= 0; i
< 2; i
++) {
1437 srcimp
= srcimps
[i
];
1438 srcimp
->ops
->map(srcimp
, src
, rscs
[i
]);
1439 src_mgr
->src_disable(src_mgr
, src
);
1442 src_mgr
->commit_write(src_mgr
); /* Actually disable SRCs */
1445 src
->ops
->set_pm(src
, 1);
1446 for (i
= 0; i
< 2; i
++) {
1448 src
->ops
->set_state(src
, SRC_STATE_RUN
);
1449 src
->ops
->commit_write(src
);
1450 src_mgr
->src_enable_s(src_mgr
, src
);
1453 dai
->ops
->set_srt_srcl(dai
, &(srcs
[0]->rsc
));
1454 dai
->ops
->set_srt_srcr(dai
, &(srcs
[1]->rsc
));
1456 dai
->ops
->set_enb_src(dai
, 1);
1457 dai
->ops
->set_enb_srt(dai
, 1);
1458 dai
->ops
->commit_write(dai
);
1460 src_mgr
->commit_write(src_mgr
); /* Synchronously enable SRCs */
1463 static void atc_connect_resources(struct ct_atc
*atc
)
1469 struct ct_mixer
*mixer
;
1470 struct rsc
*rscs
[2] = {NULL
};
1475 for (i
= MIX_WAVE_FRONT
, j
= LINEO1
; i
<= MIX_SPDIF_OUT
; i
++, j
++) {
1476 mixer
->get_output_ports(mixer
, i
, &rscs
[0], &rscs
[1]);
1477 dao
= container_of(atc
->daios
[j
], struct dao
, daio
);
1478 dao
->ops
->set_left_input(dao
, rscs
[0]);
1479 dao
->ops
->set_right_input(dao
, rscs
[1]);
1482 dai
= container_of(atc
->daios
[LINEIM
], struct dai
, daio
);
1483 atc_connect_dai(atc
->rsc_mgrs
[SRC
], dai
,
1484 (struct src
**)&atc
->srcs
[2],
1485 (struct srcimp
**)&atc
->srcimps
[2]);
1487 mixer
->set_input_left(mixer
, MIX_LINE_IN
, &src
->rsc
);
1489 mixer
->set_input_right(mixer
, MIX_LINE_IN
, &src
->rsc
);
1491 dai
= container_of(atc
->daios
[SPDIFIO
], struct dai
, daio
);
1492 atc_connect_dai(atc
->rsc_mgrs
[SRC
], dai
,
1493 (struct src
**)&atc
->srcs
[0],
1494 (struct srcimp
**)&atc
->srcimps
[0]);
1497 mixer
->set_input_left(mixer
, MIX_SPDIF_IN
, &src
->rsc
);
1499 mixer
->set_input_right(mixer
, MIX_SPDIF_IN
, &src
->rsc
);
1501 for (i
= MIX_PCMI_FRONT
, j
= 0; i
<= MIX_PCMI_SURROUND
; i
++, j
+= 2) {
1503 mixer
->set_input_left(mixer
, i
, &sum
->rsc
);
1504 sum
= atc
->pcm
[j
+1];
1505 mixer
->set_input_right(mixer
, i
, &sum
->rsc
);
1510 static int atc_suspend(struct ct_atc
*atc
, pm_message_t state
)
1513 struct hw
*hw
= atc
->hw
;
1515 snd_power_change_state(atc
->card
, SNDRV_CTL_POWER_D3hot
);
1517 for (i
= FRONT
; i
< NUM_PCMS
; i
++) {
1521 snd_pcm_suspend_all(atc
->pcms
[i
]);
1524 atc_release_resources(atc
);
1526 hw
->suspend(hw
, state
);
1531 static int atc_hw_resume(struct ct_atc
*atc
)
1533 struct hw
*hw
= atc
->hw
;
1534 struct card_conf info
= {0};
1536 /* Re-initialize card hardware. */
1537 info
.rsr
= atc
->rsr
;
1538 info
.msr
= atc
->msr
;
1539 info
.vm_pgt_phys
= atc_get_ptp_phys(atc
, 0);
1540 return hw
->resume(hw
, &info
);
1543 static int atc_resources_resume(struct ct_atc
*atc
)
1545 struct ct_mixer
*mixer
;
1549 err
= atc_get_resources(atc
);
1551 atc_release_resources(atc
);
1555 /* Build topology */
1556 atc_connect_resources(atc
);
1559 mixer
->resume(mixer
);
1564 static int atc_resume(struct ct_atc
*atc
)
1568 /* Do hardware resume. */
1569 err
= atc_hw_resume(atc
);
1571 printk(KERN_ERR
"ctxfi: pci_enable_device failed, "
1572 "disabling device\n");
1573 snd_card_disconnect(atc
->card
);
1577 err
= atc_resources_resume(atc
);
1581 snd_power_change_state(atc
->card
, SNDRV_CTL_POWER_D0
);
1587 static struct ct_atc atc_preset __devinitdata
= {
1588 .map_audio_buffer
= ct_map_audio_buffer
,
1589 .unmap_audio_buffer
= ct_unmap_audio_buffer
,
1590 .pcm_playback_prepare
= atc_pcm_playback_prepare
,
1591 .pcm_release_resources
= atc_pcm_release_resources
,
1592 .pcm_playback_start
= atc_pcm_playback_start
,
1593 .pcm_playback_stop
= atc_pcm_stop
,
1594 .pcm_playback_position
= atc_pcm_playback_position
,
1595 .pcm_capture_prepare
= atc_pcm_capture_prepare
,
1596 .pcm_capture_start
= atc_pcm_capture_start
,
1597 .pcm_capture_stop
= atc_pcm_stop
,
1598 .pcm_capture_position
= atc_pcm_capture_position
,
1599 .spdif_passthru_playback_prepare
= spdif_passthru_playback_prepare
,
1600 .get_ptp_phys
= atc_get_ptp_phys
,
1601 .select_line_in
= atc_select_line_in
,
1602 .select_mic_in
= atc_select_mic_in
,
1603 .select_digit_io
= atc_select_digit_io
,
1604 .line_front_unmute
= atc_line_front_unmute
,
1605 .line_surround_unmute
= atc_line_surround_unmute
,
1606 .line_clfe_unmute
= atc_line_clfe_unmute
,
1607 .line_rear_unmute
= atc_line_rear_unmute
,
1608 .line_in_unmute
= atc_line_in_unmute
,
1609 .spdif_out_unmute
= atc_spdif_out_unmute
,
1610 .spdif_in_unmute
= atc_spdif_in_unmute
,
1611 .spdif_out_get_status
= atc_spdif_out_get_status
,
1612 .spdif_out_set_status
= atc_spdif_out_set_status
,
1613 .spdif_out_passthru
= atc_spdif_out_passthru
,
1614 .have_digit_io_switch
= atc_have_digit_io_switch
,
1616 .suspend
= atc_suspend
,
1617 .resume
= atc_resume
,
1622 * ct_atc_create - create and initialize a hardware manager
1623 * @card: corresponding alsa card object
1624 * @pci: corresponding kernel pci device object
1625 * @ratc: return created object address in it
1627 * Creates and initializes a hardware manager.
1629 * Creates kmallocated ct_atc structure. Initializes hardware.
1630 * Returns 0 if succeeds, or negative error code if fails.
1633 int __devinit
ct_atc_create(struct snd_card
*card
, struct pci_dev
*pci
,
1634 unsigned int rsr
, unsigned int msr
,
1635 int chip_type
, unsigned int ssid
,
1636 struct ct_atc
**ratc
)
1639 static struct snd_device_ops ops
= {
1640 .dev_free
= atc_dev_free
,
1646 atc
= kzalloc(sizeof(*atc
), GFP_KERNEL
);
1650 /* Set operations */
1657 atc
->chip_type
= chip_type
;
1659 mutex_init(&atc
->atc_mutex
);
1661 /* Find card model */
1662 err
= atc_identify_card(atc
, ssid
);
1664 printk(KERN_ERR
"ctatc: Card not recognised\n");
1668 /* Set up device virtual memory management object */
1669 err
= ct_vm_create(&atc
->vm
, pci
);
1673 /* Create all atc hw devices */
1674 err
= atc_create_hw_devs(atc
);
1678 err
= ct_mixer_create(atc
, (struct ct_mixer
**)&atc
->mixer
);
1680 printk(KERN_ERR
"ctxfi: Failed to create mixer obj!!!\n");
1685 err
= atc_get_resources(atc
);
1689 /* Build topology */
1690 atc_connect_resources(atc
);
1692 atc
->timer
= ct_timer_new(atc
);
1696 err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, atc
, &ops
);
1700 snd_card_set_dev(card
, &pci
->dev
);
1706 ct_atc_destroy(atc
);
1707 printk(KERN_ERR
"ctxfi: Something wrong!!!\n");