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_IO))
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_IO_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 IndigoIO 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 if (wait_handshake(chip))
80 return -EIO;
81
82 chip->sample_rate = rate;
83 chip->comm_page->sample_rate = cpu_to_le32(rate);
84 clear_handshake(chip);
85 return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
86 }
87
88
89
90 /* 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)91 static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
92 int gain)
93 {
94 int index;
95
96 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
97 output >= num_busses_out(chip)))
98 return -EINVAL;
99
100 if (wait_handshake(chip))
101 return -EIO;
102
103 chip->vmixer_gain[output][pipe] = gain;
104 index = output * num_pipes_out(chip) + pipe;
105 chip->comm_page->vmixer[index] = gain;
106
107 dev_dbg(chip->card->dev,
108 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
109 return 0;
110 }
111
112
113
114 /* Tell the DSP to read and update virtual mixer levels in comm page. */
update_vmixer_level(struct echoaudio * chip)115 static int update_vmixer_level(struct echoaudio *chip)
116 {
117 if (wait_handshake(chip))
118 return -EIO;
119 clear_handshake(chip);
120 return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
121 }
122
123