xref: /linux/sound/pci/echoaudio/indigo_express_dsp.c (revision bc1d4e705f48f001f3a5480f04067c48bd00bcf0)
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /************************************************************************
3 
4 This file is part of Echo Digital Audio's generic driver library.
5 Copyright Echo Digital Audio Corporation (c) 1998 - 2005
6 All rights reserved
7 www.echoaudio.com
8 
9  Translation from C++ and adaptation for use in ALSA-Driver
10  were made by Giuliano Pochini <pochini@shiny.it>
11 
12 *************************************************************************/
13 
set_sample_rate(struct echoaudio * chip,u32 rate)14 static int set_sample_rate(struct echoaudio *chip, u32 rate)
15 {
16 	u32 clock, control_reg, old_control_reg;
17 
18 	if (wait_handshake(chip))
19 		return -EIO;
20 
21 	old_control_reg = le32_to_cpu(chip->comm_page->control_register);
22 	control_reg = old_control_reg & ~INDIGO_EXPRESS_CLOCK_MASK;
23 
24 	switch (rate) {
25 	case 32000:
26 		clock = INDIGO_EXPRESS_32000;
27 		break;
28 	case 44100:
29 		clock = INDIGO_EXPRESS_44100;
30 		break;
31 	case 48000:
32 		clock = INDIGO_EXPRESS_48000;
33 		break;
34 	case 64000:
35 		clock = INDIGO_EXPRESS_32000|INDIGO_EXPRESS_DOUBLE_SPEED;
36 		break;
37 	case 88200:
38 		clock = INDIGO_EXPRESS_44100|INDIGO_EXPRESS_DOUBLE_SPEED;
39 		break;
40 	case 96000:
41 		clock = INDIGO_EXPRESS_48000|INDIGO_EXPRESS_DOUBLE_SPEED;
42 		break;
43 	default:
44 		return -EINVAL;
45 	}
46 
47 	control_reg |= clock;
48 	if (control_reg != old_control_reg) {
49 		dev_dbg(chip->card->dev,
50 			"set_sample_rate: %d clock %d\n", rate, clock);
51 		chip->comm_page->control_register = cpu_to_le32(control_reg);
52 		chip->sample_rate = rate;
53 		clear_handshake(chip);
54 		return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
55 	}
56 	return 0;
57 }
58 
59 
60 
61 /* 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)62 static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
63 			   int gain)
64 {
65 	int index;
66 
67 	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
68 		       output >= num_busses_out(chip)))
69 		return -EINVAL;
70 
71 	if (wait_handshake(chip))
72 		return -EIO;
73 
74 	chip->vmixer_gain[output][pipe] = gain;
75 	index = output * num_pipes_out(chip) + pipe;
76 	chip->comm_page->vmixer[index] = gain;
77 
78 	dev_dbg(chip->card->dev,
79 		"set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
80 	return 0;
81 }
82 
83 
84 
85 /* Tell the DSP to read and update virtual mixer levels in comm page. */
update_vmixer_level(struct echoaudio * chip)86 static int update_vmixer_level(struct echoaudio *chip)
87 {
88 	if (wait_handshake(chip))
89 		return -EIO;
90 	clear_handshake(chip);
91 	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
92 }
93 
94 
95 
detect_input_clocks(const struct echoaudio * chip)96 static u32 detect_input_clocks(const struct echoaudio *chip)
97 {
98 	return ECHO_CLOCK_BIT_INTERNAL;
99 }
100 
101 
102 
103 /* The IndigoIO has no ASIC. Just do nothing */
load_asic(struct echoaudio * chip)104 static int load_asic(struct echoaudio *chip)
105 {
106 	return 0;
107 }
108