35 #define PCXHR_PLX_OFFSET_MIN 0x40
36 #define PCXHR_PLX_MBOX0 0x40
37 #define PCXHR_PLX_MBOX1 0x44
38 #define PCXHR_PLX_MBOX2 0x48
39 #define PCXHR_PLX_MBOX3 0x4C
40 #define PCXHR_PLX_MBOX4 0x50
41 #define PCXHR_PLX_MBOX5 0x54
42 #define PCXHR_PLX_MBOX6 0x58
43 #define PCXHR_PLX_MBOX7 0x5C
44 #define PCXHR_PLX_L2PCIDB 0x64
45 #define PCXHR_PLX_IRQCS 0x68
46 #define PCXHR_PLX_CHIPSC 0x6C
49 #define PCXHR_DSP_ICR 0x00
50 #define PCXHR_DSP_CVR 0x04
51 #define PCXHR_DSP_ISR 0x08
52 #define PCXHR_DSP_IVR 0x0C
53 #define PCXHR_DSP_RXH 0x14
54 #define PCXHR_DSP_TXH 0x14
55 #define PCXHR_DSP_RXM 0x18
56 #define PCXHR_DSP_TXM 0x18
57 #define PCXHR_DSP_RXL 0x1C
58 #define PCXHR_DSP_TXL 0x1C
59 #define PCXHR_DSP_RESET 0x20
60 #define PCXHR_DSP_OFFSET_MAX 0x20
66 #if (PCXHR_DSP_OFFSET_MAX > PCXHR_PLX_OFFSET_MIN)
67 #undef PCXHR_REG_TO_PORT(x)
69 #define PCXHR_REG_TO_PORT(x) ((x)>PCXHR_DSP_OFFSET_MAX ? PCXHR_PLX : PCXHR_DSP)
71 #define PCXHR_INPB(mgr,x) inb((mgr)->port[PCXHR_REG_TO_PORT(x)] + (x))
72 #define PCXHR_INPL(mgr,x) inl((mgr)->port[PCXHR_REG_TO_PORT(x)] + (x))
73 #define PCXHR_OUTPB(mgr,x,data) outb((data), (mgr)->port[PCXHR_REG_TO_PORT(x)] + (x))
74 #define PCXHR_OUTPL(mgr,x,data) outl((data), (mgr)->port[PCXHR_REG_TO_PORT(x)] + (x))
78 #define PCXHR_MBOX0_HF5 (1 << 0)
79 #define PCXHR_MBOX0_HF4 (1 << 1)
80 #define PCXHR_MBOX0_BOOT_HERE (1 << 23)
82 #define PCXHR_IRQCS_ENABLE_PCIIRQ (1 << 8)
83 #define PCXHR_IRQCS_ENABLE_PCIDB (1 << 9)
84 #define PCXHR_IRQCS_ACTIVE_PCIDB (1 << 13)
86 #define PCXHR_CHIPSC_INIT_VALUE 0x100D767E
87 #define PCXHR_CHIPSC_RESET_XILINX (1 << 16)
88 #define PCXHR_CHIPSC_GPI_USERI (1 << 17)
89 #define PCXHR_CHIPSC_DATA_CLK (1 << 24)
90 #define PCXHR_CHIPSC_DATA_IN (1 << 26)
93 #define PCXHR_ICR_HI08_RREQ 0x01
94 #define PCXHR_ICR_HI08_TREQ 0x02
95 #define PCXHR_ICR_HI08_HDRQ 0x04
96 #define PCXHR_ICR_HI08_HF0 0x08
97 #define PCXHR_ICR_HI08_HF1 0x10
98 #define PCXHR_ICR_HI08_HLEND 0x20
99 #define PCXHR_ICR_HI08_INIT 0x80
101 #define PCXHR_CVR_HI08_HC 0x80
103 #define PCXHR_ISR_HI08_RXDF 0x01
104 #define PCXHR_ISR_HI08_TXDE 0x02
105 #define PCXHR_ISR_HI08_TRDY 0x04
106 #define PCXHR_ISR_HI08_ERR 0x08
107 #define PCXHR_ISR_HI08_CHK 0x10
108 #define PCXHR_ISR_HI08_HREQ 0x80
112 #define PCXHR_WAIT_DEFAULT 2
113 #define PCXHR_WAIT_IT 25
114 #define PCXHR_WAIT_IT_EXTRA 65
125 static int pcxhr_check_reg_bit(
struct pcxhr_mgr *mgr,
unsigned int reg,
130 unsigned long end_time =
jiffies + (time *
HZ + 999) / 1000;
133 if ((*read & mask) == bit) {
143 "pcxhr_check_reg_bit: timeout, reg=%x, mask=0x%x, val=%x\n",
149 #define PCXHR_TIMEOUT_DSP 200
152 #define PCXHR_MASK_EXTRA_INFO 0x0000FE
153 #define PCXHR_MASK_IT_HF0 0x000100
154 #define PCXHR_MASK_IT_HF1 0x000200
155 #define PCXHR_MASK_IT_NO_HF0_HF1 0x000400
156 #define PCXHR_MASK_IT_MANAGE_HF5 0x000800
157 #define PCXHR_MASK_IT_WAIT 0x010000
158 #define PCXHR_MASK_IT_WAIT_EXTRA 0x020000
160 #define PCXHR_IT_SEND_BYTE_XILINX (0x0000003C | PCXHR_MASK_IT_HF0)
161 #define PCXHR_IT_TEST_XILINX (0x0000003C | PCXHR_MASK_IT_HF1 | \
162 PCXHR_MASK_IT_MANAGE_HF5)
163 #define PCXHR_IT_DOWNLOAD_BOOT (0x0000000C | PCXHR_MASK_IT_HF1 | \
164 PCXHR_MASK_IT_MANAGE_HF5 | \
166 #define PCXHR_IT_RESET_BOARD_FUNC (0x0000000C | PCXHR_MASK_IT_HF0 | \
167 PCXHR_MASK_IT_MANAGE_HF5 | \
168 PCXHR_MASK_IT_WAIT_EXTRA)
169 #define PCXHR_IT_DOWNLOAD_DSP (0x0000000C | \
170 PCXHR_MASK_IT_MANAGE_HF5 | \
172 #define PCXHR_IT_DEBUG (0x0000005A | PCXHR_MASK_IT_NO_HF0_HF1)
173 #define PCXHR_IT_RESET_SEMAPHORE (0x0000005C | PCXHR_MASK_IT_NO_HF0_HF1)
174 #define PCXHR_IT_MESSAGE (0x00000074 | PCXHR_MASK_IT_NO_HF0_HF1)
175 #define PCXHR_IT_RESET_CHK (0x00000076 | PCXHR_MASK_IT_NO_HF0_HF1)
176 #define PCXHR_IT_UPDATE_RBUFFER (0x00000078 | PCXHR_MASK_IT_NO_HF0_HF1)
178 static int pcxhr_send_it_dsp(
struct pcxhr_mgr *mgr,
179 unsigned int itdsp,
int atomic)
222 if (itdsp & PCXHR_MASK_IT_MANAGE_HF5) {
231 "pcxhr_send_it_dsp : TIMEOUT HF5\n");
259 pcxhr_enable_irq(mgr, 0);
274 pcxhr_enable_irq(mgr, 1);
287 const unsigned char *
image;
305 image = xilinx->
data;
306 for (i = 0; i < xilinx->
size; i++, image++) {
337 const unsigned char *
data;
347 for (i = 0; i < dsp->
size; i += 3) {
348 data = dsp->
data +
i;
351 len = (
unsigned int)((data[0]<<16) +
354 if (len && (dsp->
size != (len + 2) * 3))
364 "dsp loading error at position %d\n", i);
404 err = pcxhr_download_dsp(mgr, eeprom);
418 unsigned int physaddr = mgr->
hostport.addr;
433 err = pcxhr_download_dsp(mgr, boot);
454 err = pcxhr_download_dsp(mgr, dsp);
511 #ifdef CONFIG_SND_DEBUG_VERBOSE
512 static char* cmd_names[] = {
557 for (i = 0; i < rmh->
stat_len; i++) {
565 "ISR:RXDF=1 (ISR = %x; i=%d )\n",
578 rmh->
stat_len = (data & 0x0000ff) + 1;
592 #ifdef CONFIG_SND_DEBUG_VERBOSE
596 if (i < max_stat_len)
642 #ifdef CONFIG_SND_DEBUG_VERBOSE
645 data, cmd_names[rmh->
cmd_idx]);
669 for (i=1; i < rmh->
cmd_len; i++) {
672 #ifdef CONFIG_SND_DEBUG_VERBOSE
712 err = pcxhr_read_rmh_status(mgr, rmh);
739 unsigned int param1,
unsigned int param2,
744 rmh->
cmd[0] |= 0x800;
749 rmh->
cmd[0] |= param2;
753 rmh->
cmd[1] = param3;
769 err = pcxhr_send_msg_nolock(mgr, rmh);
770 spin_unlock_irqrestore(&mgr->
msg_lock, flags);
774 static inline int pcxhr_pipes_running(
struct pcxhr_mgr *mgr)
782 start_mask &= 0xffffff;
783 snd_printdd(
"CMD_PIPE_STATE MBOX2=0x%06x\n", start_mask);
787 #define PCXHR_PIPE_STATE_CAPTURE_OFFSET 12
788 #define MAX_WAIT_FOR_DSP 20
790 static int pcxhr_prepair_pipe_start(
struct pcxhr_mgr *mgr,
791 int audio_mask,
int *
retry)
799 if (audio_mask & 1) {
814 "(CMD_CAN_START_PIPE) err=%x!\n",
821 if (rmh.
stat[0] == 0)
822 *retry |= (1<<
audio);
830 static int pcxhr_stop_pipes(
struct pcxhr_mgr *mgr,
int audio_mask)
837 if (audio_mask & 1) {
852 "(CMD_STOP_PIPE) err=%x!\n", err);
862 static int pcxhr_toggle_pipes(
struct pcxhr_mgr *mgr,
int audio_mask)
869 if (audio_mask & 1) {
881 "(CMD_CONF_PIPE) err=%x!\n", err);
893 "error pipe start (CMD_SEND_IRQA) err=%x!\n",
903 int capture_mask,
int start)
908 #ifdef CONFIG_SND_DEBUG_VERBOSE
912 audio_mask = (playback_mask |
915 state = pcxhr_pipes_running(mgr);
916 snd_printdd(
"pcxhr_set_pipe_state %s (mask %x current %x)\n",
917 start ?
"START" :
"STOP", audio_mask, state);
920 audio_mask &= ~state;
923 err = pcxhr_prepair_pipe_start(mgr, state, &state);
936 err = pcxhr_toggle_pipes(mgr, audio_mask);
942 state = pcxhr_pipes_running(mgr);
944 if ((state & audio_mask) == (start ? audio_mask : 0))
953 err = pcxhr_stop_pipes(mgr, audio_mask);
957 #ifdef CONFIG_SND_DEBUG_VERBOSE
959 snd_printdd(
"***SET PIPE STATE*** TIME = %ld (err = %x)\n",
974 snd_printdd(
"IO_NUM_REG_CONT mask %x already is set to %x\n",
978 spin_unlock_irqrestore(&mgr->
msg_lock, flags);
986 err = pcxhr_send_msg_nolock(mgr, &rmh);
993 spin_unlock_irqrestore(&mgr->
msg_lock, flags);
997 #define PCXHR_IRQ_TIMER 0x000300
998 #define PCXHR_IRQ_FREQ_CHANGE 0x000800
999 #define PCXHR_IRQ_TIME_CODE 0x001000
1000 #define PCXHR_IRQ_NOTIFY 0x002000
1001 #define PCXHR_IRQ_ASYNC 0x008000
1002 #define PCXHR_IRQ_MASK 0x00bb00
1003 #define PCXHR_FATAL_DSP_ERR 0xff0000
1011 static int pcxhr_handle_async_err(
struct pcxhr_mgr *mgr,
u32 err,
1015 #ifdef CONFIG_SND_DEBUG_VERBOSE
1016 static char* err_src_name[] = {
1025 err = ((err >> 12) & 0xfff);
1028 snd_printdd(
"CMD_ASYNC : Error %s %s Pipe %d err=%x\n",
1029 err_src_name[err_src],
1030 is_capture ?
"Record" :
"Play", pipe, err);
1033 else if (err == 0xe10)
1049 snd_printdd(
"TASKLET : PCXHR_IRQ_FREQ_CHANGE event occurred\n");
1051 snd_printdd(
"TASKLET : PCXHR_IRQ_TIME_CODE event occurred\n");
1053 snd_printdd(
"TASKLET : PCXHR_IRQ_NOTIFY event occurred\n");
1059 err, prmh->
stat[0]);
1062 snd_printdd(
"TASKLET : PCXHR_IRQ_ASYNC event occurred\n");
1079 int is_capture = prmh->
stat[
i] & 0x400000;
1082 if (prmh->
stat[i] & 0x800000) {
1084 is_capture ?
"Record" :
"Play",
1090 pcxhr_handle_async_err(mgr, err2,
1094 for (j = 0; j < nb_stream; j++) {
1095 err2 = prmh->
stat[
i] ?
1098 pcxhr_handle_async_err(mgr, err2,
1104 for (j = 0; j < nb_audio; j++) {
1105 err2 = prmh->
stat[
i] ?
1108 pcxhr_handle_async_err(mgr, err2,
1118 static u_int64_t pcxhr_stream_read_position(
struct pcxhr_mgr *mgr,
1121 u_int64_t hw_sample_count;
1123 int err, stream_mask;
1125 stream_mask = stream->
pipe->is_capture ? 1 : 1<<stream->
substream->number;
1130 stream->
pipe->first_audio, 0, stream_mask);
1137 hw_sample_count = ((u_int64_t)rmh.
stat[0]) << 24;
1138 hw_sample_count += (u_int64_t)rmh.
stat[1];
1140 snd_printdd(
"stream %c%d : abs samples real(%llu) timer(%llu)\n",
1141 stream->
pipe->is_capture ?
'C' :
'P',
1146 return hw_sample_count;
1149 static void pcxhr_update_timer_pos(
struct pcxhr_mgr *mgr,
1155 u_int64_t new_sample_count;
1157 int hardware_read = 0;
1160 if (samples_to_add < 0) {
1171 pcxhr_stream_read_position(mgr, stream);
1183 if (!hardware_read) {
1193 if (new_elapse_pos > new_sample_count)
1207 "ERROR new_sample_count too small ??? %ld\n",
1208 (
long unsigned int)new_sample_count);
1212 spin_unlock(&mgr->
lock);
1214 spin_lock(&mgr->
lock);
1226 spin_lock(&mgr->
lock);
1230 spin_unlock(&mgr->
lock);
1247 if ((dsp_time_diff < 0) &&
1251 snd_printdd(
"WARNING DSP timestamp old(%d) new(%d)",
1253 if (tmp_diff > 0 && tmp_diff <= (2*mgr->
granularity)) {
1255 "diff=%d\n", tmp_diff);
1256 dsp_time_diff = tmp_diff;
1262 #ifdef CONFIG_SND_DEBUG_VERBOSE
1263 if (dsp_time_diff == 0)
1267 snd_printdd(
"ERROR DSP TIME TOO BIG old(%d) add(%d)\n",
1282 reg &= ~PCXHR_IRQ_TIMER;
1284 chip = mgr->
chip[
i];
1286 pcxhr_update_timer_pos(mgr,
1291 chip = mgr->
chip[
i];
1293 pcxhr_update_timer_pos(mgr,
1310 #ifdef CONFIG_SND_DEBUG_VERBOSE
1314 spin_unlock(&mgr->
lock);