27 #include <linux/module.h>
28 #include <linux/pci.h>
36 static const unsigned long dsp_port_offsets[] = {
72 return base_address + dsp_port_offsets[
port]*4;
88 for (i = 0; i != len; ++
i)
95 void __iomem *address = lx_dsp_register(chip, port);
99 static void lx_dsp_reg_writebuf(
struct lx6464es *chip,
int port,
102 u32 __iomem *address = lx_dsp_register(chip, port);
106 for (i = 0; i != len; ++
i)
111 static const unsigned long plx_port_offsets[] = {
129 return base_address + plx_port_offsets[
port];
134 void __iomem *address = lx_plx_register(chip, port);
140 void __iomem *address = lx_plx_register(chip, port);
203 #ifdef CONFIG_SND_DEBUG
204 #define CMD_NAME(a) a
206 #define CMD_NAME(a) NULL
209 #define Reg_CSM_MR 0x00000002
210 #define Reg_CSM_MC 0x00000001
240 , 1 , 2 ,
CMD_NAME(
"GET_SYS_CFG") },
242 , 1 , 0 ,
CMD_NAME(
"SET_GRANULARITY") },
244 , 1 , 0 ,
CMD_NAME(
"SET_TIMER_IRQ") },
250 , 0 , 0 ,
CMD_NAME(
"ALLOCATE_PIPE") },
252 , 0 , 0 ,
CMD_NAME(
"RELEASE_PIPE") },
258 , 1 , 1 ,
CMD_NAME(
"GET_PIPE_SPL_COUNT") },
260 , 1 , 0 ,
CMD_NAME(
"TOGGLE_PIPE_STATE") },
266 , 1 , 2 ,
CMD_NAME(
"GET_STREAM_SPL_COUNT") },
268 , 0 , 1 ,
CMD_NAME(
"UPDATE_BUFFER") },
272 , 1 , 1 ,
CMD_NAME(
"CANCEL_BUFFER") },
276 , 1 , 0 ,
CMD_NAME(
"SET_STREAM_STATE") },
290 #ifdef CONFIG_SND_DEBUG
299 #define LXRMH "lx6464es rmh: "
300 static void lx_message_dump(
struct lx_rmh *rmh)
315 static inline void lx_message_dump(
struct lx_rmh *rmh)
322 #define XILINX_TIMEOUT_MS 40
323 #define XILINX_POLL_NO_SLEEP 100
324 #define XILINX_POLL_ITERATIONS 150
327 static int lx_message_send_atomic(
struct lx6464es *chip,
struct lx_rmh *rmh)
350 goto polling_successful;
381 lx_message_dump(rmh);
396 ret = lx_message_send_atomic(chip, &chip->
rmh);
398 *rdsp_version = chip->
rmh.stat[1];
399 spin_unlock_irqrestore(&chip->
msg_lock, flags);
414 ret = lx_message_send_atomic(chip, &chip->
rmh);
429 spin_unlock_irqrestore(&chip->
msg_lock, flags);
463 chip->
rmh.cmd[0] |= gran;
465 ret = lx_message_send_atomic(chip, &chip->
rmh);
466 spin_unlock_irqrestore(&chip->
msg_lock, flags);
478 chip->
rmh.stat_len = 9;
480 ret = lx_message_send_atomic(chip, &chip->
rmh);
485 spin_unlock_irqrestore(&chip->
msg_lock, flags);
489 #define CSES_TIMEOUT 100
490 #define CSES_CE 0x0001
491 #define CSES_BROADCAST 0x0002
492 #define CSES_UPDATE_LDSV 0x0004
521 #define PIPE_INFO_TO_CMD(capture, pipe) \
522 ((u32)((u32)(pipe) | ((capture) ? ID_IS_CAPTURE : 0L)) << ID_OFFSET)
538 chip->
rmh.cmd[0] |= pipe_cmd;
541 err = lx_message_send_atomic(chip, &chip->
rmh);
542 spin_unlock_irqrestore(&chip->
msg_lock, flags);
560 chip->
rmh.cmd[0] |= pipe_cmd;
562 err = lx_message_send_atomic(chip, &chip->
rmh);
563 spin_unlock_irqrestore(&chip->
msg_lock, flags);
569 u32 *r_needed,
u32 *r_freed,
u32 *size_array)
576 #ifdef CONFIG_SND_DEBUG
587 chip->
rmh.cmd[0] |= pipe_cmd;
589 err = lx_message_send_atomic(chip, &chip->
rmh);
608 *r_needed, *r_freed);
610 for (i = 0; i != chip->
rmh.stat_len; ++
i)
618 spin_unlock_irqrestore(&chip->
msg_lock, flags);
633 chip->
rmh.cmd[0] |= pipe_cmd;
635 err = lx_message_send_atomic(chip, &chip->
rmh);
637 spin_unlock_irqrestore(&chip->
msg_lock, flags);
641 static int lx_pipe_toggle_state(
struct lx6464es *chip,
u32 pipe,
int is_capture)
651 chip->
rmh.cmd[0] |= pipe_cmd;
653 err = lx_message_send_atomic(chip, &chip->
rmh);
655 spin_unlock_irqrestore(&chip->
msg_lock, flags);
668 err = lx_pipe_toggle_state(chip, pipe, is_capture);
681 err = lx_pipe_toggle_state(chip, pipe, is_capture);
698 chip->
rmh.cmd[0] |= pipe_cmd;
699 chip->
rmh.stat_len = 2;
701 err = lx_message_send_atomic(chip, &chip->
rmh);
705 "lx6464es: could not query pipe's sample count\n");
712 spin_unlock_irqrestore(&chip->
msg_lock, flags);
726 chip->
rmh.cmd[0] |= pipe_cmd;
728 err = lx_message_send_atomic(chip, &chip->
rmh);
735 spin_unlock_irqrestore(&chip->
msg_lock, flags);
746 for (i = 0; i != 50; ++
i) {
753 if (current_state == state)
764 return lx_pipe_wait_for_state(chip, pipe, is_capture,
PSTATE_RUN);
769 return lx_pipe_wait_for_state(chip, pipe, is_capture,
PSTATE_IDLE);
784 chip->
rmh.cmd[0] |= pipe_cmd;
787 err = lx_message_send_atomic(chip, &chip->
rmh);
788 spin_unlock_irqrestore(&chip->
msg_lock, flags);
794 u32 pipe,
int is_capture)
810 chip->
rmh.cmd[0] |= pipe_cmd;
820 chip->
rmh.cmd[0] |= channels-1;
822 err = lx_message_send_atomic(chip, &chip->
rmh);
823 spin_unlock_irqrestore(&chip->
msg_lock, flags);
839 chip->
rmh.cmd[0] |= pipe_cmd;
841 err = lx_message_send_atomic(chip, &chip->
rmh);
845 spin_unlock_irqrestore(&chip->
msg_lock, flags);
860 chip->
rmh.cmd[0] |= pipe_cmd;
862 err = lx_message_send_atomic(chip, &chip->
rmh);
868 spin_unlock_irqrestore(&chip->
msg_lock, flags);
874 u32 buffer_size,
u32 buf_address_lo,
u32 buf_address_hi,
885 chip->
rmh.cmd[0] |= pipe_cmd;
891 chip->
rmh.cmd[2] = buf_address_lo;
893 if (buf_address_hi) {
894 chip->
rmh.cmd_len = 4;
895 chip->
rmh.cmd[3] = buf_address_hi;
899 err = lx_message_send_atomic(chip, &chip->
rmh);
902 *r_buffer_index = chip->
rmh.stat[0];
907 snd_printk(
LXP "lx_buffer_give EB_RBUFFERS_TABLE_OVERFLOW\n");
916 spin_unlock_irqrestore(&chip->
msg_lock, flags);
931 chip->
rmh.cmd[0] |= pipe_cmd;
935 err = lx_message_send_atomic(chip, &chip->
rmh);
940 spin_unlock_irqrestore(&chip->
msg_lock, flags);
955 chip->
rmh.cmd[0] |= pipe_cmd;
956 chip->
rmh.cmd[0] |= buffer_index;
958 err = lx_message_send_atomic(chip, &chip->
rmh);
960 spin_unlock_irqrestore(&chip->
msg_lock, flags);
976 u64 mute_mask = unmute ? 0 : 0xFFFFFFFFFFFFFFFFLLU;
983 chip->
rmh.cmd[1] = (
u32)(mute_mask >> (
u64)32);
984 chip->
rmh.cmd[2] = (
u32)(mute_mask & (
u64)0xFFFFFFFF);
989 err = lx_message_send_atomic(chip, &chip->
rmh);
991 spin_unlock_irqrestore(&chip->
msg_lock, flags);
995 static u32 peak_map[] = {
1018 unsigned long flags;
1022 for (i = 0; i <
channels; i += 4) {
1028 err = lx_message_send_atomic(chip, &chip->
rmh);
1031 s0 = peak_map[chip->
rmh.stat[0] & 0x0F];
1032 s1 = peak_map[(chip->
rmh.stat[0] >> 4) & 0xf];
1033 s2 = peak_map[(chip->
rmh.stat[0] >> 8) & 0xf];
1034 s3 = peak_map[(chip->
rmh.stat[0] >> 12) & 0xf];
1036 s0 = s1 = s2 = s3 = 0;
1046 spin_unlock_irqrestore(&chip->
msg_lock, flags);
1051 #define PCX_IRQ_NONE 0
1052 #define IRQCS_ACTIVE_PCIDB 0x00002000L
1053 #define IRQCS_ENABLE_PCIIRQ 0x00000100L
1054 #define IRQCS_ENABLE_PCIDB 0x00000200L
1056 static u32 lx_interrupt_test_ack(
struct lx6464es *chip)
1076 static int lx_interrupt_ack(
struct lx6464es *chip,
u32 *r_irqsrc,
1077 int *r_async_pending,
int *r_async_escmd)
1080 u32 irqsrc = lx_interrupt_test_ack(chip);
1091 irq_async &= ~MASK_SYS_STATUS_ESA;
1097 *r_async_pending = 1;
1103 static int lx_interrupt_handle_async_events(
struct lx6464es *chip,
u32 irqsrc,
1104 int *r_freq_changed,
1105 u64 *r_notified_in_pipe_mask,
1106 u64 *r_notified_out_pipe_mask)
1139 if (eb_pending_in) {
1140 *r_notified_in_pipe_mask = ((
u64)stat[3] << 32)
1143 *r_notified_in_pipe_mask);
1145 if (eb_pending_out) {
1146 *r_notified_out_pipe_mask = ((
u64)stat[1] << 32)
1149 *r_notified_out_pipe_mask);
1152 orun_mask = ((
u64)stat[7] << 32) + stat[8];
1153 urun_mask = ((
u64)stat[5] << 32) + stat[6];
1160 static int lx_interrupt_request_new_buffer(
struct lx6464es *chip,
1164 const unsigned int is_capture = lx_stream->
is_capture;
1166 unsigned long flags;
1170 const u32 period_size = substream->
runtime->period_size;
1173 const u32 next_pos = ((pos+1) == substream->
runtime->periods) ?
1179 u32 buffer_index = 0;
1184 snd_printdd(
"->lx_interrupt_request_new_buffer\n");
1188 err =
lx_buffer_ask(chip, 0, is_capture, &needed, &freed, size_array);
1189 snd_printdd(
LXP "interrupt: needed %d, freed %d\n", needed, freed);
1191 unpack_pointer(buf, &buf_lo, &buf_hi);
1192 err =
lx_buffer_give(chip, 0, is_capture, period_bytes, buf_lo, buf_hi,
1194 snd_printdd(
LXP "interrupt: gave buffer index %x on %p (%d bytes)\n",
1195 buffer_index, (
void *)buf, period_bytes);
1198 spin_unlock_irqrestore(&chip->
lock, flags);
1211 err = lx_interrupt_request_new_buffer(chip, lx_stream);
1214 "cannot request new buffer for playback\n");
1226 err = lx_interrupt_request_new_buffer(chip, lx_stream);
1229 "cannot request new buffer for capture\n");
1236 static int lx_interrupt_handle_audio_transfer(
struct lx6464es *chip,
1237 u64 notified_in_pipe_mask,
1238 u64 notified_out_pipe_mask)
1242 if (notified_in_pipe_mask) {
1247 if (notified_out_pipe_mask) {
1259 int async_pending, async_escmd;
1262 spin_lock(&chip->
lock);
1264 snd_printdd(
"**************************************************\n");
1266 if (!lx_interrupt_ack(chip, &irqsrc, &async_pending, &async_escmd)) {
1267 spin_unlock(&chip->
lock);
1289 if (async_pending) {
1290 u64 notified_in_pipe_mask = 0;
1291 u64 notified_out_pipe_mask = 0;
1296 err = lx_interrupt_handle_async_events(chip, irqsrc,
1298 ¬ified_in_pipe_mask,
1299 ¬ified_out_pipe_mask);
1302 "error handling async events\n");
1304 err = lx_interrupt_handle_audio_transfer(chip,
1305 notified_in_pipe_mask,
1306 notified_out_pipe_mask
1310 "error during audio transfer\n");
1321 snd_printdd(
"lx6464es: interrupt requests escmd handling\n");
1326 spin_unlock(&chip->
lock);
1350 lx_irq_set(chip, 1);
1356 lx_irq_set(chip, 0);