Winmme driver compiles again.
[jack2.git] / linux / alsa / ice1712.c
blob968922100e511c21648aaee850ff80a0eb5900da
1 /*
2 Copyright (C) 2002 Anthony Van Groningen
4 Parts based on source code taken from the
5 "Env24 chipset (ICE1712) control utility" that is
7 Copyright (C) 2000 by Jaroslav Kysela <perex@suse.cz>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "hardware.h"
25 #include "alsa_driver.h"
26 #include "ice1712.h"
27 #include "JackError.h"
29 static int
30 ice1712_hw_monitor_toggle(jack_hardware_t *hw, int idx, int onoff)
32 ice1712_t *h = (ice1712_t *) hw->private_hw;
33 snd_ctl_elem_value_t *val;
34 int err;
36 snd_ctl_elem_value_alloca (&val);
37 snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_MIXER);
38 if (idx >= 8) {
39 snd_ctl_elem_value_set_name (val, SPDIF_PLAYBACK_ROUTE_NAME);
40 snd_ctl_elem_value_set_index (val, idx - 8);
41 } else {
42 snd_ctl_elem_value_set_name (val, ANALOG_PLAYBACK_ROUTE_NAME);
43 snd_ctl_elem_value_set_index (val, idx);
45 if (onoff) {
46 snd_ctl_elem_value_set_enumerated (val, 0, idx + 1);
47 } else {
48 snd_ctl_elem_value_set_enumerated (val, 0, 0);
50 if ((err = snd_ctl_elem_write (h->driver->ctl_handle, val)) != 0) {
51 jack_error ("ALSA/ICE1712: (%d) cannot set input monitoring (%s)",
52 idx,snd_strerror (err));
53 return -1;
56 return 0;
59 static int
60 ice1712_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
62 int idx;
63 ice1712_t *h = (ice1712_t *) hw->private_hw;
65 for (idx = 0; idx < 10; idx++) {
66 if (h->active_channels & (1<<idx)) {
67 ice1712_hw_monitor_toggle (hw, idx, mask & (1<<idx) ? 1 : 0);
70 hw->input_monitor_mask = mask;
72 return 0;
75 static int
76 ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
78 return -1;
81 static void
82 ice1712_release (jack_hardware_t *hw)
84 ice1712_t *h = (ice1712_t *) hw->private_hw;
86 if (h == 0)
87 return;
89 if (h->eeprom)
90 free(h->eeprom);
92 free(h);
96 jack_hardware_t *
97 jack_alsa_ice1712_hw_new (alsa_driver_t *driver)
99 jack_hardware_t *hw;
100 ice1712_t *h;
101 snd_ctl_elem_value_t *val;
102 int err;
104 hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
106 hw->capabilities = Cap_HardwareMonitoring;
107 hw->input_monitor_mask = 0;
108 hw->private_hw = 0;
110 hw->set_input_monitor_mask = ice1712_set_input_monitor_mask;
111 hw->change_sample_clock = ice1712_change_sample_clock;
112 hw->release = ice1712_release;
114 h = (ice1712_t *) malloc (sizeof (ice1712_t));
116 h->driver = driver;
118 /* Get the EEPROM (adopted from envy24control) */
119 h->eeprom = (ice1712_eeprom_t *) malloc (sizeof (ice1712_eeprom_t));
120 snd_ctl_elem_value_alloca (&val);
121 snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_CARD);
122 snd_ctl_elem_value_set_name (val, "ICE1712 EEPROM");
123 if ((err = snd_ctl_elem_read (driver->ctl_handle, val)) < 0) {
124 jack_error( "ALSA/ICE1712: Unable to read EEPROM contents (%s)\n", snd_strerror (err));
125 /* Recover? */
127 memcpy(h->eeprom, snd_ctl_elem_value_get_bytes(val), 32);
129 /* determine number of pro ADC's. We're asumming that there is at least one stereo pair.
130 Should check this first, but how? */
131 switch((h->eeprom->codec & 0xCU) >> 2) {
132 case 0:
133 h->active_channels = 0x3U;
134 break;
135 case 1:
136 h->active_channels = 0xfU;
137 break;
138 case 2:
139 h->active_channels = 0x3fU;
140 break;
141 case 3:
142 h->active_channels = 0xffU;
143 break;
145 /* check for SPDIF In's */
146 if (h->eeprom->spdif & 0x1U) {
147 h->active_channels |= 0x300U;
150 hw->private_hw = h;
152 return hw;