26 #include <linux/pci.h>
28 #include <linux/module.h>
30 #include <linux/slab.h>
43 #define CARD_NAME "miXart"
72 static int mixart_set_pipe_state(
struct mixart_mgr *mgr,
94 system_msg_uid = 0x12345678;
100 request.data = &system_msg_uid;
101 request.size =
sizeof(system_msg_uid);
111 memset(&group_state, 0,
sizeof(group_state));
112 group_state.pipe_count = 1;
113 group_state.pipe_uid[0] = pipe->
group_uid;
122 request.size =
sizeof(group_state);
125 if (err < 0 || group_state_resp.txx_status != 0) {
126 snd_printk(
KERN_ERR "error MSG_STREAM_ST***_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status);
133 group_state.pipe_count = 0;
136 if (err < 0 || group_state_resp.txx_status != 0) {
137 snd_printk(
KERN_ERR "error MSG_STREAM_START_STREAM_GRP_PACKET err=%x stat=%x !\n", err, group_state_resp.txx_status);
149 if (err < 0 || stat != 0) {
150 snd_printk(
KERN_ERR "error MSG_SYSTEM_SEND_SYNCHRO_CMD err=%x stat=%x !\n", err, stat);
163 static int mixart_set_clock(
struct mixart_mgr *mgr,
181 snd_printk(
KERN_ERR "error mixart_set_clock(%d) called with wrong pipe->status !\n", rate);
186 memset(&clock_properties, 0,
sizeof(clock_properties));
189 clock_properties.frequency =
rate;
190 clock_properties.nb_callers = 1;
191 clock_properties.uid_caller[0] = pipe->
group_uid;
197 request.data = &clock_properties;
198 request.size =
sizeof(clock_properties);
201 if (err < 0 || clock_prop_resp.status != 0 || clock_prop_resp.clock_mode !=
CM_STANDALONE) {
202 snd_printk(
KERN_ERR "error MSG_CLOCK_SET_PROPERTIES err=%x stat=%x mod=%x !\n", err, clock_prop_resp.status, clock_prop_resp.clock_mode);
262 request.
data = &
buf->sgroup_req;
263 request.
size =
sizeof(
buf->sgroup_req);
268 buf->sgroup_req.channel_count = 2;
269 buf->sgroup_req.latency = 256;
278 buf->sgroup_req.stream_info[
i].size_max_byte_frame = 1024;
279 buf->sgroup_req.stream_info[
i].size_max_sample_frame = 256;
286 buf->sgroup_req.flow_entry[
i] =
j;
304 if((err < 0) || (
buf->sgroup_resp.status != 0)) {
305 snd_printk(
KERN_ERR "error MSG_STREAM_ADD_**PUT_GROUP err=%x stat=%x !\n", err,
buf->sgroup_resp.status);
344 err = mixart_set_clock( mgr, pipe, 0);
350 err = mixart_set_pipe_state(mgr, pipe, 0);
362 if ((err < 0) || (delete_resp.
status != 0)) {
374 static int mixart_set_stream_state(
struct mixart_stream *stream,
int start)
383 memset(&stream_state_req, 0,
sizeof(stream_state_req));
384 stream_state_req.stream_count = 1;
385 stream_state_req.stream_info.stream_desc.uid_pipe = stream->
pipe->group_uid;
386 stream_state_req.stream_info.stream_desc.stream_idx = stream->
substream->number;
394 request.data = &stream_state_req;
395 request.size =
sizeof(stream_state_req);
420 if( mixart_set_stream_state(stream, 1) )
429 if( mixart_set_stream_state(stream, 0) )
454 static int mixart_sync_nonblock_events(
struct mixart_mgr *mgr)
479 mixart_sync_nonblock_events(chip->
mgr);
483 if(chip->
mgr->ref_count_rate == 1)
487 if(stream->
pipe->references == 1) {
488 if( mixart_set_clock(chip->
mgr, stream->
pipe, subs->
runtime->rate) )
506 memset(&stream_param, 0,
sizeof(stream_param));
509 stream_param.number_of_channel = stream->
channels;
511 stream_param.sampling_freq = chip->mgr->sample_rate;
512 if(stream_param.sampling_freq == 0)
513 stream_param.sampling_freq = 44100;
518 stream_param.sample_size = 8;
522 stream_param.sample_size = 16;
526 stream_param.sample_size = 16;
530 stream_param.sample_size = 24;
534 stream_param.sample_size = 24;
538 stream_param.sample_size = 32;
542 stream_param.sample_size = 32;
549 snd_printdd(
"set SNDRV_PCM_FORMAT sample_type(%d) sample_size(%d) freq(%d) channels(%d)\n",
550 stream_param.sample_type, stream_param.sample_size, stream_param.sampling_freq, stream->
channels);
557 stream_param.pipe_count = 1;
558 stream_param.stream_count = 1;
559 stream_param.stream_desc[0].uid_pipe = stream->
pipe->group_uid;
560 stream_param.stream_desc[0].stream_idx = stream->
substream->number;
565 request.size =
sizeof(stream_param);
568 if((err < 0) ||
resp.error_code) {
609 err = mixart_set_format(stream, format);
630 snd_printdd(
"snd_mixart_hw_params(pcm %d) : dma_addr(%x) dma_bytes(%x) subs-number(%d)\n", i,
644 mixart_sync_nonblock_events(chip->
mgr);
667 .buffer_bytes_max = (32*1024),
671 .periods_max = (32*1024/256),
688 .buffer_bytes_max = (32*1024),
692 .periods_max = (32*1024/256),
709 if ( pcm == chip->
pcm ) {
711 runtime->
hw = snd_mixart_analog_caps;
715 runtime->
hw = snd_mixart_digital_caps;
738 err = mixart_set_pipe_state(chip->
mgr, pipe, 1);
784 if ( pcm == chip->
pcm ) {
786 runtime->
hw = snd_mixart_analog_caps;
790 runtime->
hw = snd_mixart_digital_caps;
793 runtime->
hw.channels_min = 2;
816 err = mixart_set_pipe_state(chip->
mgr, pipe, 1);
890 static struct snd_pcm_ops snd_mixart_playback_ops = {
891 .open = snd_mixart_playback_open,
892 .close = snd_mixart_close,
894 .prepare = snd_mixart_prepare,
895 .hw_params = snd_mixart_hw_params,
896 .hw_free = snd_mixart_hw_free,
897 .trigger = snd_mixart_trigger,
898 .pointer = snd_mixart_stream_pointer,
901 static struct snd_pcm_ops snd_mixart_capture_ops = {
902 .open = snd_mixart_capture_open,
903 .close = snd_mixart_close,
905 .prepare = snd_mixart_prepare,
906 .hw_params = snd_mixart_hw_params,
907 .hw_free = snd_mixart_hw_free,
908 .trigger = snd_mixart_trigger,
909 .pointer = snd_mixart_stream_pointer,
918 for (stream = 0; stream < 2; stream++) {
920 for (subs = pcm->
streams[stream].substream; subs; subs = subs->
next, idx++)
922 subs->dma_device.id = subs->
pcm->device << 16 |
933 static int snd_mixart_pcm_analog(
struct snd_mixart *chip)
955 preallocate_buffers(chip, pcm);
964 static int snd_mixart_pcm_digital(
struct snd_mixart *chip)
986 preallocate_buffers(chip, pcm);
992 static int snd_mixart_chip_free(
struct snd_mixart *chip)
1001 return snd_mixart_chip_free(chip);
1012 .dev_free = snd_mixart_chip_dev_free,
1026 snd_mixart_chip_free(chip);
1040 err = snd_mixart_pcm_analog(chip);
1046 err = snd_mixart_pcm_digital(chip);
1057 static int snd_mixart_free(
struct mixart_mgr *mgr)
1080 for (i = 0; i < 2; i++) {
1081 if (mgr->
mem[i].virt)
1110 void *file_private_data,
1126 void *file_private_data,
1127 struct file *file,
char __user *buf,
1128 size_t count, loff_t pos)
1139 .read = snd_mixart_BA0_read,
1143 .read = snd_mixart_BA1_read,
1153 snd_iprintf(buffer,
"Digigram miXart (alsa card %d)\n\n", chip->
chip_idx);
1157 snd_iprintf(buffer,
"- hardware -\n");
1158 switch (chip->
mgr->board_type ) {
1162 default: snd_iprintf(buffer,
"\tUNKNOWN!\n\n");
break;
1165 snd_iprintf(buffer,
"- system load -\n");
1176 snd_iprintf(buffer,
"\tstreaming : %d\n", streaming);
1177 snd_iprintf(buffer,
"\tmailbox : %d\n", mailbox);
1178 snd_iprintf(buffer,
"\tinterrups handling : %d\n\n", interr);
1188 if (! snd_card_proc_new(chip->
card,
"board_info", &entry)) {
1190 entry->
c.
text.read = snd_mixart_proc_read;
1193 if (! snd_card_proc_new(chip->
card,
"mixart_BA0", &entry)) {
1196 entry->
c.
ops = &snd_mixart_proc_ops_BA0;
1199 if (! snd_card_proc_new(chip->
card,
"mixart_BA1", &entry)) {
1202 entry->
c.
ops = &snd_mixart_proc_ops_BA1;
1259 for (i = 0; i < 2; i++) {
1262 if (!mgr->
mem[i].virt) {
1265 snd_mixart_free(mgr);
1271 KBUILD_MODNAME, mgr)) {
1273 snd_mixart_free(mgr);
1310 snprintf(tmpid,
sizeof(tmpid),
"%s-%d",
id[dev] ?
id[dev] :
"MIXART", i);
1315 snd_mixart_free(mgr);
1323 if ((err = snd_mixart_create(mgr, card, i)) < 0) {
1325 snd_mixart_free(mgr);
1331 snd_mixart_proc_init(mgr->
chip[i]);
1335 snd_mixart_free(mgr);
1348 snd_mixart_free(mgr);
1359 snd_mixart_free(mgr);
1368 snd_mixart_free(mgr);
1372 pci_set_drvdata(pci, mgr);
1379 snd_mixart_free(pci_get_drvdata(pci));
1380 pci_set_drvdata(pci,
NULL);
1384 .name = KBUILD_MODNAME,
1385 .id_table = snd_mixart_ids,
1386 .probe = snd_mixart_probe,