jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.1KB

  1. /*
  2. Copyright (C) 2002 Anthony Van Groningen
  3. Parts based on source code taken from the
  4. "Env24 chipset (ICE1712) control utility" that is
  5. Copyright (C) 2000 by Jaroslav Kysela <perex@suse.cz>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #if defined(HAVE_CONFIG_H)
  19. #include "config.h"
  20. #endif
  21. //#include <jack/hardware.h>
  22. #include "hardware.h"
  23. #include "alsa_driver.h"
  24. #include "ice1712.h"
  25. #include "JackError.h"
  26. static int
  27. ice1712_hw_monitor_toggle(jack_hardware_t *hw, int idx, int onoff)
  28. {
  29. ice1712_t *h = (ice1712_t *) hw->private_hw;
  30. snd_ctl_elem_value_t *val;
  31. int err;
  32. snd_ctl_elem_value_alloca (&val);
  33. snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_MIXER);
  34. if (idx >= 8) {
  35. snd_ctl_elem_value_set_name (val, SPDIF_PLAYBACK_ROUTE_NAME);
  36. snd_ctl_elem_value_set_index (val, idx - 8);
  37. } else {
  38. snd_ctl_elem_value_set_name (val, ANALOG_PLAYBACK_ROUTE_NAME);
  39. snd_ctl_elem_value_set_index (val, idx);
  40. }
  41. if (onoff) {
  42. snd_ctl_elem_value_set_enumerated (val, 0, idx + 1);
  43. } else {
  44. snd_ctl_elem_value_set_enumerated (val, 0, 0);
  45. }
  46. if ((err = snd_ctl_elem_write (h->driver->ctl_handle, val)) != 0) {
  47. jack_error ("ALSA/ICE1712: (%d) cannot set input monitoring (%s)",
  48. idx,snd_strerror (err));
  49. return -1;
  50. }
  51. return 0;
  52. }
  53. static int
  54. ice1712_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
  55. {
  56. int idx;
  57. ice1712_t *h = (ice1712_t *) hw->private_hw;
  58. for (idx = 0; idx < 10; idx++) {
  59. if (h->active_channels & (1<<idx)) {
  60. ice1712_hw_monitor_toggle (hw, idx, mask & (1<<idx) ? 1 : 0);
  61. }
  62. }
  63. hw->input_monitor_mask = mask;
  64. return 0;
  65. }
  66. static int
  67. ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
  68. {
  69. return -1;
  70. }
  71. static void
  72. ice1712_release (jack_hardware_t *hw)
  73. {
  74. ice1712_t *h = (ice1712_t *) hw->private_hw;
  75. if (h == 0)
  76. return;
  77. if (h->eeprom)
  78. free(h->eeprom);
  79. free(h);
  80. }
  81. jack_hardware_t *
  82. jack_alsa_ice1712_hw_new (alsa_driver_t *driver)
  83. {
  84. jack_hardware_t *hw;
  85. ice1712_t *h;
  86. snd_ctl_elem_value_t *val;
  87. int err;
  88. hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
  89. hw->capabilities = Cap_HardwareMonitoring;
  90. hw->input_monitor_mask = 0;
  91. hw->private_hw = 0;
  92. hw->set_input_monitor_mask = ice1712_set_input_monitor_mask;
  93. hw->change_sample_clock = ice1712_change_sample_clock;
  94. hw->release = ice1712_release;
  95. h = (ice1712_t *) malloc (sizeof (ice1712_t));
  96. h->driver = driver;
  97. /* Get the EEPROM (adopted from envy24control) */
  98. h->eeprom = (ice1712_eeprom_t *) malloc (sizeof (ice1712_eeprom_t));
  99. snd_ctl_elem_value_alloca (&val);
  100. snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_CARD);
  101. snd_ctl_elem_value_set_name (val, "ICE1712 EEPROM");
  102. if ((err = snd_ctl_elem_read (driver->ctl_handle, val)) < 0) {
  103. jack_error( "ALSA/ICE1712: Unable to read EEPROM contents (%s)\n", snd_strerror (err));
  104. /* Recover? */
  105. }
  106. memcpy(h->eeprom, snd_ctl_elem_value_get_bytes(val), 32);
  107. /* determine number of pro ADC's. We're asumming that there is at least one stereo pair.
  108. Should check this first, but how? */
  109. switch((h->eeprom->codec & 0xCU) >> 2) {
  110. case 0:
  111. h->active_channels = 0x3U;
  112. break;
  113. case 1:
  114. h->active_channels = 0xfU;
  115. break;
  116. case 2:
  117. h->active_channels = 0x3fU;
  118. break;
  119. case 3:
  120. h->active_channels = 0xffU;
  121. break;
  122. }
  123. /* check for SPDIF In's */
  124. if (h->eeprom->spdif & 0x1U) {
  125. h->active_channels |= 0x300U;
  126. }
  127. hw->private_hw = h;
  128. return hw;
  129. }