xref: /linux/sound/pci/echoaudio/indigo_dsp.c (revision bc1d4e705f48f001f3a5480f04067c48bd00bcf0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 
4    Copyright Echo Digital Audio Corporation (c) 1998 - 2004
5    All rights reserved
6    www.echoaudio.com
7 
8    This file is part of Echo Digital Audio's generic driver library.
9    *************************************************************************
10 
11  Translation from C++ and adaptation for use in ALSA-Driver
12  were made by Giuliano Pochini <pochini@shiny.it>
13 
14 ****************************************************************************/
15 
16 
17 static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
18 			   int gain);
19 static int update_vmixer_level(struct echoaudio *chip);
20 
21 
init_hw(struct echoaudio * chip,u16 device_id,u16 subdevice_id)22 static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
23 {
24 	int err;
25 
26 	if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO))
27 		return -ENODEV;
28 
29 	err = init_dsp_comm_page(chip);
30 	if (err) {
31 		dev_err(chip->card->dev,
32 			"init_hw - could not initialize DSP comm page\n");
33 		return err;
34 	}
35 
36 	chip->device_id = device_id;
37 	chip->subdevice_id = subdevice_id;
38 	chip->bad_board = true;
39 	chip->dsp_code_to_load = FW_INDIGO_DSP;
40 	/* Since this card has no ASIC, mark it as loaded so everything
41 	   works OK */
42 	chip->asic_loaded = true;
43 	chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
44 
45 	err = load_firmware(chip);
46 	if (err < 0)
47 		return err;
48 	chip->bad_board = false;
49 
50 	return err;
51 }
52 
53 
54 
set_mixer_defaults(struct echoaudio * chip)55 static int set_mixer_defaults(struct echoaudio *chip)
56 {
57 	return init_line_levels(chip);
58 }
59 
60 
61 
detect_input_clocks(const struct echoaudio * chip)62 static u32 detect_input_clocks(const struct echoaudio *chip)
63 {
64 	return ECHO_CLOCK_BIT_INTERNAL;
65 }
66 
67 
68 
69 /* The Indigo has no ASIC. Just do nothing */
load_asic(struct echoaudio * chip)70 static int load_asic(struct echoaudio *chip)
71 {
72 	return 0;
73 }
74 
75 
76 
set_sample_rate(struct echoaudio * chip,u32 rate)77 static int set_sample_rate(struct echoaudio *chip, u32 rate)
78 {
79 	u32 control_reg;
80 
81 	switch (rate) {
82 	case 96000:
83 		control_reg = MIA_96000;
84 		break;
85 	case 88200:
86 		control_reg = MIA_88200;
87 		break;
88 	case 48000:
89 		control_reg = MIA_48000;
90 		break;
91 	case 44100:
92 		control_reg = MIA_44100;
93 		break;
94 	case 32000:
95 		control_reg = MIA_32000;
96 		break;
97 	default:
98 		dev_err(chip->card->dev,
99 			"set_sample_rate: %d invalid!\n", rate);
100 		return -EINVAL;
101 	}
102 
103 	/* Set the control register if it has changed */
104 	if (control_reg != le32_to_cpu(chip->comm_page->control_register)) {
105 		if (wait_handshake(chip))
106 			return -EIO;
107 
108 		chip->comm_page->sample_rate = cpu_to_le32(rate);	/* ignored by the DSP */
109 		chip->comm_page->control_register = cpu_to_le32(control_reg);
110 		chip->sample_rate = rate;
111 
112 		clear_handshake(chip);
113 		return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
114 	}
115 	return 0;
116 }
117 
118 
119 
120 /* This function routes the sound from a virtual channel to a real output */
set_vmixer_gain(struct echoaudio * chip,u16 output,u16 pipe,int gain)121 static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
122 			   int gain)
123 {
124 	int index;
125 
126 	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
127 		       output >= num_busses_out(chip)))
128 		return -EINVAL;
129 
130 	if (wait_handshake(chip))
131 		return -EIO;
132 
133 	chip->vmixer_gain[output][pipe] = gain;
134 	index = output * num_pipes_out(chip) + pipe;
135 	chip->comm_page->vmixer[index] = gain;
136 
137 	dev_dbg(chip->card->dev,
138 		"set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
139 	return 0;
140 }
141 
142 
143 
144 /* Tell the DSP to read and update virtual mixer levels in comm page. */
update_vmixer_level(struct echoaudio * chip)145 static int update_vmixer_level(struct echoaudio *chip)
146 {
147 	if (wait_handshake(chip))
148 		return -EIO;
149 	clear_handshake(chip);
150 	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
151 }
152 
153