Lines Matching refs:chip
35 static int restore_dsp_rettings(struct echoaudio *chip);
42 static int wait_handshake(struct echoaudio *chip) in wait_handshake() argument
50 if (chip->comm_page->handshake) { in wait_handshake()
56 dev_err(chip->card->dev, "wait_handshake(): Timeout waiting for DSP\n"); in wait_handshake()
66 static int send_vector(struct echoaudio *chip, u32 command) in send_vector() argument
74 if (!(get_dsp_register(chip, CHI32_VECTOR_REG) & in send_vector()
76 set_dsp_register(chip, CHI32_VECTOR_REG, command); in send_vector()
83 dev_err(chip->card->dev, "timeout on send_vector\n"); in send_vector()
91 static int write_dsp(struct echoaudio *chip, u32 data) in write_dsp() argument
96 status = get_dsp_register(chip, CHI32_STATUS_REG); in write_dsp()
98 set_dsp_register(chip, CHI32_DATA_REG, data); in write_dsp()
106 chip->bad_board = true; /* Set true until DSP re-loaded */ in write_dsp()
107 dev_dbg(chip->card->dev, "write_dsp: Set bad_board to true\n"); in write_dsp()
115 static int read_dsp(struct echoaudio *chip, u32 *data) in read_dsp() argument
120 status = get_dsp_register(chip, CHI32_STATUS_REG); in read_dsp()
122 *data = get_dsp_register(chip, CHI32_DATA_REG); in read_dsp()
129 chip->bad_board = true; /* Set true until DSP re-loaded */ in read_dsp()
130 dev_err(chip->card->dev, "read_dsp: Set bad_board to true\n"); in read_dsp()
145 static int read_sn(struct echoaudio *chip) in read_sn() argument
151 if (read_dsp(chip, &sn[i])) { in read_sn()
152 dev_err(chip->card->dev, in read_sn()
157 dev_dbg(chip->card->dev, in read_sn()
167 static inline int check_asic_status(struct echoaudio *chip) in check_asic_status() argument
169 chip->asic_loaded = true; in check_asic_status()
180 static int load_asic_generic(struct echoaudio *chip, u32 cmd, short asic) in load_asic_generic() argument
187 err = get_firmware(&fw, chip, asic); in load_asic_generic()
189 dev_warn(chip->card->dev, "Firmware not found !\n"); in load_asic_generic()
197 if (write_dsp(chip, cmd) < 0) in load_asic_generic()
201 if (write_dsp(chip, size) < 0) in load_asic_generic()
205 if (write_dsp(chip, code[i]) < 0) in load_asic_generic()
209 free_firmware(fw, chip); in load_asic_generic()
213 dev_err(chip->card->dev, "failed on write_dsp\n"); in load_asic_generic()
214 free_firmware(fw, chip); in load_asic_generic()
227 static int install_resident_loader(struct echoaudio *chip) in install_resident_loader() argument
237 if (chip->device_id != DEVICE_ID_56361) in install_resident_loader()
242 status = get_dsp_register(chip, CHI32_STATUS_REG); in install_resident_loader()
244 dev_dbg(chip->card->dev, in install_resident_loader()
250 i = get_firmware(&fw, chip, FW_361_LOADER); in install_resident_loader()
252 dev_warn(chip->card->dev, "Firmware not found !\n"); in install_resident_loader()
265 set_dsp_register(chip, CHI32_CONTROL_REG, in install_resident_loader()
266 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900); in install_resident_loader()
286 if (write_dsp(chip, words)) { in install_resident_loader()
287 dev_err(chip->card->dev, in install_resident_loader()
292 if (write_dsp(chip, address)) { in install_resident_loader()
293 dev_err(chip->card->dev, in install_resident_loader()
302 if (write_dsp(chip, data)) { in install_resident_loader()
303 dev_err(chip->card->dev, in install_resident_loader()
313 status = get_dsp_register(chip, CHI32_STATUS_REG); in install_resident_loader()
319 dev_err(chip->card->dev, "Resident loader failed to set HF5\n"); in install_resident_loader()
323 dev_dbg(chip->card->dev, "Resident loader successfully installed\n"); in install_resident_loader()
324 free_firmware(fw, chip); in install_resident_loader()
328 free_firmware(fw, chip); in install_resident_loader()
335 static int load_dsp(struct echoaudio *chip, u16 *code) in load_dsp() argument
340 if (chip->dsp_code == code) { in load_dsp()
341 dev_warn(chip->card->dev, "DSP is already loaded!\n"); in load_dsp()
344 chip->bad_board = true; /* Set true until DSP loaded */ in load_dsp()
345 chip->dsp_code = NULL; /* Current DSP code not loaded */ in load_dsp()
346 chip->asic_loaded = false; /* Loading the DSP code will reset the ASIC */ in load_dsp()
348 dev_dbg(chip->card->dev, "load_dsp: Set bad_board to true\n"); in load_dsp()
352 i = install_resident_loader(chip); in load_dsp()
358 if (send_vector(chip, DSP_VC_RESET) < 0) { in load_dsp()
359 dev_err(chip->card->dev, in load_dsp()
368 if (get_dsp_register(chip, CHI32_STATUS_REG) & in load_dsp()
375 dev_err(chip->card->dev, in load_dsp()
381 set_dsp_register(chip, CHI32_CONTROL_REG, in load_dsp()
382 get_dsp_register(chip, CHI32_CONTROL_REG) | 0x900); in load_dsp()
412 if (write_dsp(chip, words) < 0) { in load_dsp()
413 dev_err(chip->card->dev, in load_dsp()
417 if (write_dsp(chip, address) < 0) { in load_dsp()
418 dev_err(chip->card->dev, in load_dsp()
422 if (write_dsp(chip, mem_type) < 0) { in load_dsp()
423 dev_err(chip->card->dev, in load_dsp()
430 if (write_dsp(chip, data) < 0) { in load_dsp()
431 dev_err(chip->card->dev, in load_dsp()
438 if (write_dsp(chip, 0) < 0) { /* We're done!!! */ in load_dsp()
439 dev_err(chip->card->dev, in load_dsp()
447 if (get_dsp_register(chip, CHI32_STATUS_REG) & in load_dsp()
449 set_dsp_register(chip, CHI32_CONTROL_REG, in load_dsp()
450 get_dsp_register(chip, CHI32_CONTROL_REG) & ~0x1b00); in load_dsp()
452 if (write_dsp(chip, DSP_FNC_SET_COMMPAGE_ADDR) < 0) { in load_dsp()
453 dev_err(chip->card->dev, in load_dsp()
458 if (write_dsp(chip, chip->comm_page_phys) < 0) { in load_dsp()
459 dev_err(chip->card->dev, in load_dsp()
468 if (read_sn(chip) < 0) { in load_dsp()
469 dev_err(chip->card->dev, in load_dsp()
474 chip->dsp_code = code; /* Show which DSP code loaded */ in load_dsp()
475 chip->bad_board = false; /* DSP OK */ in load_dsp()
481 dev_err(chip->card->dev, in load_dsp()
489 static int load_firmware(struct echoaudio *chip) in load_firmware() argument
494 if (snd_BUG_ON(!chip->comm_page)) in load_firmware()
498 if (chip->dsp_code) { in load_firmware()
499 box_type = check_asic_status(chip); in load_firmware()
503 chip->dsp_code = NULL; in load_firmware()
506 err = get_firmware(&fw, chip, chip->dsp_code_to_load); in load_firmware()
509 err = load_dsp(chip, (u16 *)fw->data); in load_firmware()
510 free_firmware(fw, chip); in load_firmware()
514 box_type = load_asic(chip); in load_firmware()
531 static int set_nominal_level(struct echoaudio *chip, u16 index, char consumer) in set_nominal_level() argument
533 if (snd_BUG_ON(index >= num_busses_out(chip) + num_busses_in(chip))) in set_nominal_level()
537 if (wait_handshake(chip)) in set_nominal_level()
540 chip->nominal_level[index] = consumer; in set_nominal_level()
543 chip->comm_page->nominal_level_mask |= cpu_to_le32(1 << index); in set_nominal_level()
545 chip->comm_page->nominal_level_mask &= ~cpu_to_le32(1 << index); in set_nominal_level()
555 static int set_output_gain(struct echoaudio *chip, u16 channel, s8 gain) in set_output_gain() argument
557 if (snd_BUG_ON(channel >= num_busses_out(chip))) in set_output_gain()
560 if (wait_handshake(chip)) in set_output_gain()
564 chip->output_gain[channel] = gain; in set_output_gain()
565 chip->comm_page->line_out_level[channel] = gain; in set_output_gain()
573 static int set_monitor_gain(struct echoaudio *chip, u16 output, u16 input, in set_monitor_gain() argument
576 if (snd_BUG_ON(output >= num_busses_out(chip) || in set_monitor_gain()
577 input >= num_busses_in(chip))) in set_monitor_gain()
580 if (wait_handshake(chip)) in set_monitor_gain()
583 chip->monitor_gain[output][input] = gain; in set_monitor_gain()
584 chip->comm_page->monitors[monitor_index(chip, output, input)] = gain; in set_monitor_gain()
591 static int update_output_line_level(struct echoaudio *chip) in update_output_line_level() argument
593 if (wait_handshake(chip)) in update_output_line_level()
595 clear_handshake(chip); in update_output_line_level()
596 return send_vector(chip, DSP_VC_UPDATE_OUTVOL); in update_output_line_level()
602 static int update_input_line_level(struct echoaudio *chip) in update_input_line_level() argument
604 if (wait_handshake(chip)) in update_input_line_level()
606 clear_handshake(chip); in update_input_line_level()
607 return send_vector(chip, DSP_VC_UPDATE_INGAIN); in update_input_line_level()
614 static void set_meters_on(struct echoaudio *chip, char on) in set_meters_on() argument
616 if (on && !chip->meters_enabled) { in set_meters_on()
617 send_vector(chip, DSP_VC_METERS_ON); in set_meters_on()
618 chip->meters_enabled = 1; in set_meters_on()
619 } else if (!on && chip->meters_enabled) { in set_meters_on()
620 send_vector(chip, DSP_VC_METERS_OFF); in set_meters_on()
621 chip->meters_enabled = 0; in set_meters_on()
622 memset((s8 *)chip->comm_page->vu_meter, ECHOGAIN_MUTED, in set_meters_on()
624 memset((s8 *)chip->comm_page->peak_meter, ECHOGAIN_MUTED, in set_meters_on()
639 static void get_audio_meters(struct echoaudio *chip, long *meters) in get_audio_meters() argument
646 for (m = 0, n = 0, i = 0; i < num_busses_out(chip); i++, m++) { in get_audio_meters()
647 meters[n++] = chip->comm_page->vu_meter[m]; in get_audio_meters()
648 meters[n++] = chip->comm_page->peak_meter[m]; in get_audio_meters()
655 for (n = 32, i = 0; i < num_busses_in(chip); i++, m++) { in get_audio_meters()
656 meters[n++] = chip->comm_page->vu_meter[m]; in get_audio_meters()
657 meters[n++] = chip->comm_page->peak_meter[m]; in get_audio_meters()
660 for (n = 64, i = 0; i < num_pipes_out(chip); i++, m++) { in get_audio_meters()
661 meters[n++] = chip->comm_page->vu_meter[m]; in get_audio_meters()
662 meters[n++] = chip->comm_page->peak_meter[m]; in get_audio_meters()
669 static int restore_dsp_rettings(struct echoaudio *chip) in restore_dsp_rettings() argument
673 err = check_asic_status(chip); in restore_dsp_rettings()
678 chip->comm_page->gd_clock_state = GD_CLOCK_UNDEF; in restore_dsp_rettings()
679 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_UNDEF; in restore_dsp_rettings()
680 chip->comm_page->handshake = cpu_to_le32(0xffffffff); in restore_dsp_rettings()
683 for (i = 0; i < num_busses_out(chip); i++) { in restore_dsp_rettings()
684 err = set_output_gain(chip, i, chip->output_gain[i]); in restore_dsp_rettings()
690 for (i = 0; i < num_pipes_out(chip); i++) in restore_dsp_rettings()
691 for (o = 0; o < num_busses_out(chip); o++) { in restore_dsp_rettings()
692 err = set_vmixer_gain(chip, o, i, in restore_dsp_rettings()
693 chip->vmixer_gain[o][i]); in restore_dsp_rettings()
697 if (update_vmixer_level(chip) < 0) in restore_dsp_rettings()
702 for (o = 0; o < num_busses_out(chip); o++) in restore_dsp_rettings()
703 for (i = 0; i < num_busses_in(chip); i++) { in restore_dsp_rettings()
704 err = set_monitor_gain(chip, o, i, in restore_dsp_rettings()
705 chip->monitor_gain[o][i]); in restore_dsp_rettings()
712 for (i = 0; i < num_busses_in(chip); i++) { in restore_dsp_rettings()
713 err = set_input_gain(chip, i, chip->input_gain[i]); in restore_dsp_rettings()
719 err = update_output_line_level(chip); in restore_dsp_rettings()
723 err = update_input_line_level(chip); in restore_dsp_rettings()
727 err = set_sample_rate(chip, chip->sample_rate); in restore_dsp_rettings()
731 if (chip->meters_enabled) { in restore_dsp_rettings()
732 err = send_vector(chip, DSP_VC_METERS_ON); in restore_dsp_rettings()
738 if (set_digital_mode(chip, chip->digital_mode) < 0) in restore_dsp_rettings()
743 if (set_professional_spdif(chip, chip->professional_spdif) < 0) in restore_dsp_rettings()
748 if (set_phantom_power(chip, chip->phantom_power) < 0) in restore_dsp_rettings()
754 if (set_input_clock(chip, chip->input_clock) < 0) in restore_dsp_rettings()
759 if (set_output_clock(chip, chip->output_clock) < 0) in restore_dsp_rettings()
763 if (wait_handshake(chip) < 0) in restore_dsp_rettings()
765 clear_handshake(chip); in restore_dsp_rettings()
766 if (send_vector(chip, DSP_VC_UPDATE_FLAGS) < 0) in restore_dsp_rettings()
781 static void set_audio_format(struct echoaudio *chip, u16 pipe_index, in set_audio_format() argument
848 dev_dbg(chip->card->dev, in set_audio_format()
850 chip->comm_page->audio_format[pipe_index] = cpu_to_le16(dsp_format); in set_audio_format()
859 static int start_transport(struct echoaudio *chip, u32 channel_mask, in start_transport() argument
863 if (wait_handshake(chip)) in start_transport()
866 chip->comm_page->cmd_start |= cpu_to_le32(channel_mask); in start_transport()
868 if (chip->comm_page->cmd_start) { in start_transport()
869 clear_handshake(chip); in start_transport()
870 send_vector(chip, DSP_VC_START_TRANSFER); in start_transport()
871 if (wait_handshake(chip)) in start_transport()
874 chip->active_mask |= channel_mask; in start_transport()
875 chip->comm_page->cmd_start = 0; in start_transport()
879 dev_err(chip->card->dev, "start_transport: No pipes to start!\n"); in start_transport()
885 static int pause_transport(struct echoaudio *chip, u32 channel_mask) in pause_transport() argument
888 if (wait_handshake(chip)) in pause_transport()
891 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask); in pause_transport()
892 chip->comm_page->cmd_reset = 0; in pause_transport()
893 if (chip->comm_page->cmd_stop) { in pause_transport()
894 clear_handshake(chip); in pause_transport()
895 send_vector(chip, DSP_VC_STOP_TRANSFER); in pause_transport()
896 if (wait_handshake(chip)) in pause_transport()
899 chip->active_mask &= ~channel_mask; in pause_transport()
900 chip->comm_page->cmd_stop = 0; in pause_transport()
901 chip->comm_page->cmd_reset = 0; in pause_transport()
905 dev_dbg(chip->card->dev, "pause_transport: No pipes to stop!\n"); in pause_transport()
911 static int stop_transport(struct echoaudio *chip, u32 channel_mask) in stop_transport() argument
914 if (wait_handshake(chip)) in stop_transport()
917 chip->comm_page->cmd_stop |= cpu_to_le32(channel_mask); in stop_transport()
918 chip->comm_page->cmd_reset |= cpu_to_le32(channel_mask); in stop_transport()
919 if (chip->comm_page->cmd_reset) { in stop_transport()
920 clear_handshake(chip); in stop_transport()
921 send_vector(chip, DSP_VC_STOP_TRANSFER); in stop_transport()
922 if (wait_handshake(chip)) in stop_transport()
925 chip->active_mask &= ~channel_mask; in stop_transport()
926 chip->comm_page->cmd_stop = 0; in stop_transport()
927 chip->comm_page->cmd_reset = 0; in stop_transport()
931 dev_dbg(chip->card->dev, "stop_transport: No pipes to stop!\n"); in stop_transport()
937 static inline int is_pipe_allocated(struct echoaudio *chip, u16 pipe_index) in is_pipe_allocated() argument
939 return (chip->pipe_alloc_mask & (1 << pipe_index)); in is_pipe_allocated()
946 static int rest_in_peace(struct echoaudio *chip) in rest_in_peace() argument
950 stop_transport(chip, chip->active_mask); in rest_in_peace()
952 set_meters_on(chip, false); in rest_in_peace()
955 enable_midi_input(chip, false); in rest_in_peace()
959 if (chip->dsp_code) { in rest_in_peace()
961 chip->dsp_code = NULL; in rest_in_peace()
963 return send_vector(chip, DSP_VC_GO_COMATOSE); in rest_in_peace()
971 static int init_dsp_comm_page(struct echoaudio *chip) in init_dsp_comm_page() argument
975 dev_err(chip->card->dev, in init_dsp_comm_page()
981 chip->card_name = ECHOCARD_NAME; in init_dsp_comm_page()
982 chip->bad_board = true; /* Set true until DSP loaded */ in init_dsp_comm_page()
983 chip->dsp_code = NULL; /* Current DSP code not loaded */ in init_dsp_comm_page()
984 chip->asic_loaded = false; in init_dsp_comm_page()
985 memset(chip->comm_page, 0, sizeof(struct comm_page)); in init_dsp_comm_page()
988 chip->comm_page->comm_size = in init_dsp_comm_page()
990 chip->comm_page->handshake = cpu_to_le32(0xffffffff); in init_dsp_comm_page()
991 chip->comm_page->midi_out_free_count = in init_dsp_comm_page()
993 chip->comm_page->sample_rate = cpu_to_le32(44100); in init_dsp_comm_page()
996 memset(chip->comm_page->monitors, ECHOGAIN_MUTED, MONITOR_ARRAY_SIZE); in init_dsp_comm_page()
997 memset(chip->comm_page->vmixer, ECHOGAIN_MUTED, VMIXER_ARRAY_SIZE); in init_dsp_comm_page()
1008 static int init_line_levels(struct echoaudio *chip) in init_line_levels() argument
1010 memset(chip->output_gain, ECHOGAIN_MUTED, sizeof(chip->output_gain)); in init_line_levels()
1011 memset(chip->input_gain, ECHOGAIN_MUTED, sizeof(chip->input_gain)); in init_line_levels()
1012 memset(chip->monitor_gain, ECHOGAIN_MUTED, sizeof(chip->monitor_gain)); in init_line_levels()
1013 memset(chip->vmixer_gain, ECHOGAIN_MUTED, sizeof(chip->vmixer_gain)); in init_line_levels()
1014 chip->input_clock = ECHO_CLOCK_INTERNAL; in init_line_levels()
1015 chip->output_clock = ECHO_CLOCK_WORD; in init_line_levels()
1016 chip->sample_rate = 44100; in init_line_levels()
1017 return restore_dsp_rettings(chip); in init_line_levels()
1025 static int service_irq(struct echoaudio *chip) in service_irq() argument
1030 if (get_dsp_register(chip, CHI32_STATUS_REG) & CHI32_STATUS_IRQ) { in service_irq()
1034 if (chip->comm_page->midi_input[0]) /* The count is at index 0 */ in service_irq()
1035 st = midi_service_irq(chip); /* Returns how many midi bytes we received */ in service_irq()
1038 chip->comm_page->midi_input[0] = 0; in service_irq()
1039 send_vector(chip, DSP_VC_ACK_INT); in service_irq()
1054 static int allocate_pipes(struct echoaudio *chip, struct audiopipe *pipe, in allocate_pipes() argument
1060 dev_dbg(chip->card->dev, in allocate_pipes()
1063 if (chip->bad_board) in allocate_pipes()
1068 if (chip->pipe_alloc_mask & channel_mask) { in allocate_pipes()
1069 dev_err(chip->card->dev, in allocate_pipes()
1074 chip->comm_page->position[pipe_index] = 0; in allocate_pipes()
1075 chip->pipe_alloc_mask |= channel_mask; in allocate_pipes()
1077 chip->pipe_cyclic_mask |= channel_mask; in allocate_pipes()
1085 pipe->dma_counter = (__le32 *)&chip->comm_page->position[pipe_index]; in allocate_pipes()
1092 static int free_pipes(struct echoaudio *chip, struct audiopipe *pipe) in free_pipes() argument
1097 if (snd_BUG_ON(!is_pipe_allocated(chip, pipe->index))) in free_pipes()
1105 chip->pipe_alloc_mask &= ~channel_mask; in free_pipes()
1106 chip->pipe_cyclic_mask &= ~channel_mask; in free_pipes()
1116 static int sglist_init(struct echoaudio *chip, struct audiopipe *pipe) in sglist_init() argument
1120 chip->comm_page->sglist_addr[pipe->index].addr = in sglist_init()
1127 static int sglist_add_mapping(struct echoaudio *chip, struct audiopipe *pipe, in sglist_add_mapping() argument
1138 dev_err(chip->card->dev, "SGlist: too many fragments\n"); in sglist_add_mapping()
1146 static inline int sglist_add_irq(struct echoaudio *chip, struct audiopipe *pipe) in sglist_add_irq() argument
1148 return sglist_add_mapping(chip, pipe, 0, 0); in sglist_add_irq()
1153 static inline int sglist_wrap(struct echoaudio *chip, struct audiopipe *pipe) in sglist_wrap() argument
1155 return sglist_add_mapping(chip, pipe, pipe->sgpage.addr, 0); in sglist_wrap()