blob: bc3716895fc862cf7feadc5f2f38b49579ef673a [file] [log] [blame]
Giuliano Pochinidd7b2542006-06-28 13:53:41 +02001/****************************************************************************
2
3 Copyright Echo Digital Audio Corporation (c) 1998 - 2004
4 All rights reserved
5 www.echoaudio.com
6
7 This file is part of Echo Digital Audio's generic driver library.
8
9 Echo Digital Audio's generic driver library is free software;
10 you can redistribute it and/or modify it under the terms of
11 the GNU General Public License as published by the Free Software
12 Foundation.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 MA 02111-1307, USA.
23
24 *************************************************************************
25
26 Translation from C++ and adaptation for use in ALSA-Driver
27 were made by Giuliano Pochini <pochini@shiny.it>
28
29****************************************************************************/
30
31static int load_asic(struct echoaudio *chip);
32static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode);
33static int set_digital_mode(struct echoaudio *chip, u8 mode);
34static int check_asic_status(struct echoaudio *chip);
35static int set_sample_rate(struct echoaudio *chip, u32 rate);
36static int set_input_clock(struct echoaudio *chip, u16 clock);
37static int set_professional_spdif(struct echoaudio *chip, char prof);
38static int set_phantom_power(struct echoaudio *chip, char on);
39static int write_control_reg(struct echoaudio *chip, u32 ctl, u32 frq,
40 char force);
41
Adrian Bunk579c84a2007-01-23 19:22:26 +010042#include <linux/interrupt.h>
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020043
44static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
45{
46 int err;
47
48 local_irq_enable();
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +053049 dev_dbg(chip->card->dev, "init_hw() - Echo3G\n");
Takashi Iwaida3cec32008-08-08 17:12:14 +020050 if (snd_BUG_ON((subdevice_id & 0xfff0) != ECHO3G))
51 return -ENODEV;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020052
53 if ((err = init_dsp_comm_page(chip))) {
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +053054 dev_err(chip->card->dev,
55 "init_hw - could not initialize DSP comm page\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020056 return err;
57 }
58
59 chip->comm_page->e3g_frq_register =
Harvey Harrisone930e992009-02-11 14:49:30 -080060 cpu_to_le32((E3G_MAGIC_NUMBER / 48000) - 2);
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020061 chip->device_id = device_id;
62 chip->subdevice_id = subdevice_id;
63 chip->bad_board = TRUE;
64 chip->has_midi = TRUE;
Giuliano Pochini19b50062010-02-14 18:15:34 +010065 chip->dsp_code_to_load = FW_ECHO3G_DSP;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020066
67 /* Load the DSP code and the ASIC on the PCI card and get
68 what type of external box is attached */
69 err = load_firmware(chip);
70
71 if (err < 0) {
72 return err;
73 } else if (err == E3G_GINA3G_BOX_TYPE) {
74 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL |
75 ECHO_CLOCK_BIT_SPDIF |
76 ECHO_CLOCK_BIT_ADAT;
77 chip->card_name = "Gina3G";
78 chip->px_digital_out = chip->bx_digital_out = 6;
79 chip->px_analog_in = chip->bx_analog_in = 14;
80 chip->px_digital_in = chip->bx_digital_in = 16;
81 chip->px_num = chip->bx_num = 24;
82 chip->has_phantom_power = TRUE;
83 chip->hasnt_input_nominal_level = TRUE;
84 } else if (err == E3G_LAYLA3G_BOX_TYPE) {
85 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL |
86 ECHO_CLOCK_BIT_SPDIF |
87 ECHO_CLOCK_BIT_ADAT |
88 ECHO_CLOCK_BIT_WORD;
89 chip->card_name = "Layla3G";
90 chip->px_digital_out = chip->bx_digital_out = 8;
91 chip->px_analog_in = chip->bx_analog_in = 16;
92 chip->px_digital_in = chip->bx_digital_in = 24;
93 chip->px_num = chip->bx_num = 32;
94 } else {
95 return -ENODEV;
96 }
97
98 chip->digital_modes = ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
99 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
100 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200101
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +0530102 dev_dbg(chip->card->dev, "init_hw done\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200103 return err;
104}
105
106
107
Giuliano Pochiniad3499f2010-02-14 18:15:59 +0100108static int set_mixer_defaults(struct echoaudio *chip)
109{
110 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
111 chip->professional_spdif = FALSE;
112 chip->non_audio_spdif = FALSE;
113 chip->bad_board = FALSE;
114 chip->phantom_power = FALSE;
115 return init_line_levels(chip);
116}
117
118
119
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200120static int set_phantom_power(struct echoaudio *chip, char on)
121{
122 u32 control_reg = le32_to_cpu(chip->comm_page->control_register);
123
124 if (on)
125 control_reg |= E3G_PHANTOM_POWER;
126 else
127 control_reg &= ~E3G_PHANTOM_POWER;
128
129 chip->phantom_power = on;
130 return write_control_reg(chip, control_reg,
131 le32_to_cpu(chip->comm_page->e3g_frq_register),
132 0);
133}