26 #include <linux/slab.h>
27 #include <linux/pci.h>
30 #include <linux/module.h>
45 #define DRIVER_NAME "pcxhr"
191 #define PCXHR_BOARD_HAS_AES1(x) (x->fw_file_set != 4)
193 #define PCXHR_BOARD_AESIN_NO_192K(x) ((x->capture_chips == 0) || \
194 (x->fw_file_set == 0) || \
195 (x->fw_file_set == 2))
197 static int pcxhr_pll_freq_register(
unsigned int freq,
unsigned int* pllreg,
198 unsigned int* realfreq)
202 if (freq < 6900 || freq > 110000)
204 reg = (28224000 * 2) / freq;
207 *pllreg = reg + 0x800;
208 else if (reg < 0x400)
209 *pllreg = reg & 0x1ff;
210 else if (reg < 0x800) {
211 *pllreg = ((reg >> 1) & 0x1ff) + 0x200;
214 *pllreg = ((reg >> 2) & 0x1ff) + 0x400;
218 *realfreq = (28224000 / (reg + 1));
223 #define PCXHR_FREQ_REG_MASK 0x1f
224 #define PCXHR_FREQ_QUARTZ_48000 0x00
225 #define PCXHR_FREQ_QUARTZ_24000 0x01
226 #define PCXHR_FREQ_QUARTZ_12000 0x09
227 #define PCXHR_FREQ_QUARTZ_32000 0x08
228 #define PCXHR_FREQ_QUARTZ_16000 0x04
229 #define PCXHR_FREQ_QUARTZ_8000 0x0c
230 #define PCXHR_FREQ_QUARTZ_44100 0x02
231 #define PCXHR_FREQ_QUARTZ_22050 0x0a
232 #define PCXHR_FREQ_QUARTZ_11025 0x06
233 #define PCXHR_FREQ_PLL 0x05
234 #define PCXHR_FREQ_QUARTZ_192000 0x10
235 #define PCXHR_FREQ_QUARTZ_96000 0x18
236 #define PCXHR_FREQ_QUARTZ_176400 0x14
237 #define PCXHR_FREQ_QUARTZ_88200 0x1c
238 #define PCXHR_FREQ_QUARTZ_128000 0x12
239 #define PCXHR_FREQ_QUARTZ_64000 0x1a
241 #define PCXHR_FREQ_WORD_CLOCK 0x0f
242 #define PCXHR_FREQ_SYNC_AES 0x0e
243 #define PCXHR_FREQ_AES_1 0x07
244 #define PCXHR_FREQ_AES_2 0x0b
245 #define PCXHR_FREQ_AES_3 0x03
246 #define PCXHR_FREQ_AES_4 0x0d
248 static int pcxhr_get_clock_reg(
struct pcxhr_mgr *mgr,
unsigned int rate,
249 unsigned int *
reg,
unsigned int *
freq)
251 unsigned int val, realfreq, pllreg;
277 err = pcxhr_pll_freq_register(rate, &pllreg, &realfreq);
283 rmh.
cmd[2] = pllreg >> 24;
288 "error CMD_ACCESS_IO_WRITE "
289 "for PLL register : %x!\n", err);
321 static int pcxhr_sub_set_clock(
struct pcxhr_mgr *mgr,
329 err = pcxhr_get_clock_reg(mgr, rate, &val, &realfreq);
336 else if (rate < 100000)
383 snd_printdd(
"pcxhr_sub_set_clock to %dHz (realfreq=%d)\n",
388 #define PCXHR_MODIFY_CLOCK_S_BIT 0x04
390 #define PCXHR_IRQ_TIMER_FREQ 92000
391 #define PCXHR_IRQ_TIMER_PERIOD 48
404 err = pcxhr_sub_set_clock(mgr, rate, &changed);
426 static int pcxhr_sub_get_external_clock(
struct pcxhr_mgr *mgr,
434 switch (clock_type) {
471 switch (rmh.stat[1] & 0x0f) {
497 return pcxhr_sub_get_external_clock(mgr, clock_type,
504 static int pcxhr_set_stream_state(
struct pcxhr_stream *stream)
509 int stream_mask,
start;
516 "CANNOT be stopped\n");
534 stream->
pipe->first_audio, 0, stream_mask);
547 #define HEADER_FMT_BASE_LIN 0xfed00000
548 #define HEADER_FMT_BASE_FLOAT 0xfad00000
549 #define HEADER_FMT_INTEL 0x00008000
550 #define HEADER_FMT_24BITS 0x00004000
551 #define HEADER_FMT_16BITS 0x00002000
552 #define HEADER_FMT_UPTO11 0x00000200
553 #define HEADER_FMT_UPTO32 0x00000100
554 #define HEADER_FMT_MONO 0x00000080
556 static int pcxhr_set_format(
struct pcxhr_stream *stream)
558 int err, is_capture, sample_rate, stream_num;
586 "error pcxhr_set_format() : unknown format\n");
591 sample_rate = chip->
mgr->sample_rate;
592 if (sample_rate <= 32000 && sample_rate !=0) {
593 if (sample_rate <= 11025)
601 is_capture = stream->
pipe->is_capture;
602 stream_num = is_capture ? 0 : stream->
substream->number;
623 rmh.
cmd[2] = (stream->
channels == 1) ? 0x01 : 0x03;
628 rmh.
cmd[rmh.
cmd_len++] = (header & 0xff) << 16;
635 static int pcxhr_update_r_buffer(
struct pcxhr_stream *stream)
637 int err, is_capture, stream_num;
643 stream_num = is_capture ? 0 : subs->
number;
646 "addr(%p) bytes(%zx) subs(%d)\n",
647 is_capture ?
'c' :
'p',
658 rmh.cmd[1] = subs->
runtime->dma_bytes * 8;
660 rmh.cmd[2] = subs->
runtime->dma_addr >> 24;
669 "ERROR CMD_UPDATE_R_BUFFERS err=%x;\n", err);
675 static int pcxhr_pipe_sample_count(
struct pcxhr_stream *stream,
683 1<<stream->
pipe->first_audio);
689 snd_printdd(
"PIPE_SAMPLE_COUNT = %lx\n", *sample_count);
694 static inline int pcxhr_stream_scheduled_get_pipe(
struct pcxhr_stream *stream,
698 *pipe = stream->
pipe;
704 static void pcxhr_trigger_tasklet(
unsigned long arg)
711 int capture_mask = 0;
712 int playback_mask = 0;
714 #ifdef CONFIG_SND_DEBUG_VERBOSE
724 if (pcxhr_stream_scheduled_get_pipe(&chip->
capture_stream[j], &pipe))
728 if (pcxhr_stream_scheduled_get_pipe(&chip->
playback_stream[j], &pipe)) {
736 if (capture_mask == 0 && playback_mask == 0) {
743 "playback_mask=%x capture_mask=%x\n",
744 playback_mask, capture_mask);
751 "error stop pipes (P%x C%x)\n",
752 playback_mask, capture_mask);
762 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe)) {
763 err = pcxhr_set_format(stream);
764 err = pcxhr_update_r_buffer(stream);
769 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe)) {
770 err = pcxhr_set_format(stream);
771 err = pcxhr_update_r_buffer(stream);
781 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe))
782 err = pcxhr_set_stream_state(stream);
786 if (pcxhr_stream_scheduled_get_pipe(stream, &pipe))
787 err = pcxhr_set_stream_state(stream);
796 "error start pipes (P%x C%x)\n",
797 playback_mask, capture_mask);
822 spin_unlock_irqrestore(&mgr->
lock, flags);
826 #ifdef CONFIG_SND_DEBUG_VERBOSE
828 snd_printdd(
"***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
829 (
long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
845 if (snd_pcm_stream_linked(subs)) {
850 stream = s->
runtime->private_data;
853 snd_pcm_trigger_done(s, subs);
855 tasklet_schedule(&chip->
mgr->trigger_taskq);
857 stream = subs->
runtime->private_data;
859 stream->
pipe->is_capture ?
'C' :
'P',
860 stream->
pipe->first_audio);
861 if (pcxhr_set_format(stream))
863 if (pcxhr_update_r_buffer(stream))
867 if (pcxhr_set_stream_state(stream))
875 stream = s->
runtime->private_data;
877 if (pcxhr_set_stream_state(stream))
879 snd_pcm_trigger_done(s, subs);
892 static int pcxhr_hardware_timer(
struct pcxhr_mgr *mgr,
int start)
919 snd_printdd(
"pcxhr_prepare : period_size(%lx) periods(%x) buffer_size(%lx)\n",
934 err = pcxhr_hardware_timer(mgr, 1);
1025 runtime->
hw = pcxhr_caps;
1028 snd_printdd(
"pcxhr_open playback chip%d subs%d\n",
1035 runtime->
hw.channels_max = 1;
1037 runtime->
hw.channels_min = 2;
1070 external_rate == 0) {
1075 runtime->
hw.rate_min = external_rate;
1076 runtime->
hw.rate_max = external_rate;
1114 pcxhr_hardware_timer(mgr, 0);
1128 unsigned long flags;
1141 spin_unlock_irqrestore(&chip->
mgr->lock, flags);
1150 .close = pcxhr_close,
1152 .prepare = pcxhr_prepare,
1153 .hw_params = pcxhr_hw_params,
1154 .hw_free = pcxhr_hw_free,
1155 .trigger = pcxhr_trigger,
1156 .pointer = pcxhr_stream_pointer,
1191 static int pcxhr_chip_free(
struct snd_pcxhr *chip)
1200 return pcxhr_chip_free(chip);
1212 .dev_free = pcxhr_chip_dev_free,
1225 if (idx < mgr->playback_chips)
1229 if (idx < mgr->capture_chips) {
1237 pcxhr_chip_free(chip);
1254 snd_iprintf(buffer,
"\n%s\n", mgr->
longname);
1262 snd_iprintf(buffer,
"module version %s\n",
1264 snd_iprintf(buffer,
"dsp version %d.%d.%d\n",
1265 ver_maj, ver_min, ver_build);
1267 snd_iprintf(buffer,
"analog io available\n");
1269 snd_iprintf(buffer,
"digital only board\n");
1274 int cur = rmh.stat[0];
1275 int ref = rmh.stat[1];
1279 ref = (ref * 48000) /
1285 cur = 100 - (100 *
cur) / ref;
1286 snd_iprintf(buffer,
"cpu load %d%%\n", cur);
1287 snd_iprintf(buffer,
"buffer pool %d/%d\n",
1288 rmh.stat[2], rmh.stat[3]);
1291 snd_iprintf(buffer,
"dma granularity : %d\n",
1293 snd_iprintf(buffer,
"dsp time errors : %d\n",
1295 snd_iprintf(buffer,
"dsp async pipe xrun errors : %d\n",
1297 snd_iprintf(buffer,
"dsp async stream xrun errors : %d\n",
1299 snd_iprintf(buffer,
"dsp async last other error : %x\n",
1309 if (rmh.stat_len > 8)
1311 for (i = 0; i < rmh.stat_len; i++)
1312 snd_iprintf(buffer,
"debug[%02d] = %06x\n",
1316 snd_iprintf(buffer,
"no firmware loaded\n");
1317 snd_iprintf(buffer,
"\n");
1324 static const char *textsHR22[3] = {
1325 "Internal",
"AES Sync",
"AES 1"
1327 static const char *textsPCXHR[7] = {
1328 "Internal",
"Word",
"AES Sync",
1329 "AES 1",
"AES 2",
"AES 3",
"AES 4"
1341 snd_iprintf(buffer,
"\n%s\n", mgr->
longname);
1342 snd_iprintf(buffer,
"Current Sample Clock\t: %s\n",
1344 snd_iprintf(buffer,
"Current Sample Rate\t= %d\n",
1349 for (i = 1; i <= max_clock; i++) {
1353 snd_iprintf(buffer,
"%s Clock\t\t= %d\n",
1354 texts[i], sample_rate);
1357 snd_iprintf(buffer,
"no firmware loaded\n");
1358 snd_iprintf(buffer,
"\n");
1371 snd_iprintf(buffer,
"GPI: 0x%x\n", value);
1373 snd_iprintf(buffer,
"GPO: 0x%x\n", value);
1375 snd_iprintf(buffer,
"no firmware loaded\n");
1376 snd_iprintf(buffer,
"\n");
1388 while (!snd_info_get_line(buffer, line,
sizeof(line))) {
1389 if (
sscanf(line,
"GPO: 0x%x", &value) != 1)
1396 #define TIME_CODE_VALID_MASK 0x00800000
1397 #define TIME_CODE_NEW_MASK 0x00400000
1398 #define TIME_CODE_BACK_MASK 0x00200000
1399 #define TIME_CODE_WAIT_MASK 0x00100000
1402 #define MANAGE_SIGNAL_TIME_CODE 0x01
1403 #define MANAGE_SIGNAL_MIDI 0x02
1412 unsigned int ltcHrs, ltcMin, ltcSec, ltcFrm;
1416 snd_iprintf(buffer,
"no firmware loaded\n");
1424 snd_iprintf(buffer,
"ltc not activated (%d)\n", err);
1437 snd_iprintf(buffer,
"ltc read error (err=%d)\n", err);
1440 ltcHrs = 10*((rmh.
stat[0] >> 8) & 0x3) + (rmh.
stat[0] & 0xf);
1441 ltcMin = 10*((rmh.
stat[1] >> 16) & 0x7) + ((rmh.
stat[1] >> 8) & 0xf);
1442 ltcSec = 10*(rmh.
stat[1] & 0x7) + ((rmh.
stat[2] >> 16) & 0xf);
1443 ltcFrm = 10*((rmh.
stat[2] >> 8) & 0x3) + (rmh.
stat[2] & 0xf);
1445 snd_iprintf(buffer,
"timecode: %02u:%02u:%02u-%02u\n",
1446 ltcHrs, ltcMin, ltcSec, ltcFrm);
1447 snd_iprintf(buffer,
"raw: 0x%04x%06x%06x\n", rmh.
stat[0] & 0x00ffff,
1448 rmh.
stat[1] & 0xffffff, rmh.
stat[2] & 0xffffff);
1452 snd_iprintf(buffer,
"warning: linear timecode not valid\n");
1460 if (! snd_card_proc_new(chip->
card,
"info", &entry))
1461 snd_info_set_text_ops(entry, chip, pcxhr_proc_info);
1462 if (! snd_card_proc_new(chip->
card,
"sync", &entry))
1463 snd_info_set_text_ops(entry, chip, pcxhr_proc_sync);
1465 if (chip->
mgr->is_hr_stereo &&
1466 !snd_card_proc_new(chip->
card,
"gpio", &entry)) {
1467 snd_info_set_text_ops(entry, chip, pcxhr_proc_gpio_read);
1468 entry->
c.
text.write = pcxhr_proc_gpo_write;
1471 if (!snd_card_proc_new(chip->
card,
"ltc", &entry))
1472 snd_info_set_text_ops(entry, chip, pcxhr_proc_ltc);
1479 static int pcxhr_free(
struct pcxhr_mgr *mgr)
1541 "32bit PCI busmaster DMA\n");
1584 for (i = 0; i < 3; i++)
1591 KBUILD_MODNAME, mgr)) {
1612 (
unsigned long) mgr);
1614 (
unsigned long) mgr);
1639 snprintf(tmpid,
sizeof(tmpid),
"%s-%d",
1640 id[dev] ?
id[dev] : card_name, i);
1653 if ((err = pcxhr_create(mgr, card, i)) < 0) {
1661 pcxhr_proc_init(mgr->
chip[i]);
1686 pci_set_drvdata(pci, mgr);
1693 pcxhr_free(pci_get_drvdata(pci));
1694 pci_set_drvdata(pci,
NULL);
1698 .name = KBUILD_MODNAME,
1699 .id_table = pcxhr_ids,
1700 .probe = pcxhr_probe,