jack1 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.

153 lines
4.0KB

  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. #include <jack/hardware.h>
  19. #include <jack/alsa_driver.h>
  20. #include <jack/ice1712.h>
  21. #include <jack/internal.h>
  22. static int
  23. ice1712_hw_monitor_toggle(jack_hardware_t *hw, int idx, int onoff)
  24. {
  25. ice1712_t *h = (ice1712_t *) hw->private;
  26. snd_ctl_elem_value_t *val;
  27. int err;
  28. snd_ctl_elem_value_alloca (&val);
  29. snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_MIXER);
  30. if (idx >= 8) {
  31. snd_ctl_elem_value_set_name (val, SPDIF_PLAYBACK_ROUTE_NAME);
  32. snd_ctl_elem_value_set_index (val, idx - 8);
  33. } else {
  34. snd_ctl_elem_value_set_name (val, ANALOG_PLAYBACK_ROUTE_NAME);
  35. snd_ctl_elem_value_set_index (val, idx);
  36. }
  37. if (onoff) {
  38. snd_ctl_elem_value_set_enumerated (val, 0, idx + 1);
  39. } else {
  40. snd_ctl_elem_value_set_enumerated (val, 0, 0);
  41. }
  42. if ((err = snd_ctl_elem_write (h->driver->ctl_handle, val)) != 0) {
  43. jack_error ("ALSA/ICE1712: (%d) cannot set input monitoring (%s)",
  44. idx,snd_strerror (err));
  45. return -1;
  46. }
  47. return 0;
  48. }
  49. static int
  50. ice1712_set_input_monitor_mask (jack_hardware_t *hw, unsigned long mask)
  51. {
  52. int idx;
  53. ice1712_t *h = (ice1712_t *) hw->private;
  54. for (idx = 0; idx < 10; idx++) {
  55. if (h->active_channels & (1<<idx)) {
  56. ice1712_hw_monitor_toggle (hw, idx, mask & (1<<idx) ? 1 : 0);
  57. }
  58. }
  59. hw->input_monitor_mask = mask;
  60. return 0;
  61. }
  62. static int
  63. ice1712_change_sample_clock (jack_hardware_t *hw, SampleClockMode mode)
  64. {
  65. return -1;
  66. }
  67. static void
  68. ice1712_release (jack_hardware_t *hw)
  69. {
  70. return;
  71. }
  72. jack_hardware_t *
  73. jack_alsa_ice1712_hw_new (alsa_driver_t *driver)
  74. {
  75. jack_hardware_t *hw;
  76. ice1712_t *h;
  77. snd_ctl_elem_value_t *val;
  78. int err;
  79. hw = (jack_hardware_t *) malloc (sizeof (jack_hardware_t));
  80. hw->capabilities = Cap_HardwareMonitoring;
  81. hw->input_monitor_mask = 0;
  82. hw->private = 0;
  83. hw->set_input_monitor_mask = ice1712_set_input_monitor_mask;
  84. hw->change_sample_clock = ice1712_change_sample_clock;
  85. hw->release = ice1712_release;
  86. h = (ice1712_t *) malloc (sizeof (ice1712_t));
  87. h->driver = driver;
  88. /* Get the EEPROM (adopted from envy24control) */
  89. h->eeprom = (ice1712_eeprom_t *) malloc (sizeof (ice1712_eeprom_t));
  90. snd_ctl_elem_value_alloca (&val);
  91. snd_ctl_elem_value_set_interface (val, SND_CTL_ELEM_IFACE_CARD);
  92. snd_ctl_elem_value_set_name (val, "ICE1712 EEPROM");
  93. if ((err = snd_ctl_elem_read (driver->ctl_handle, val)) < 0) {
  94. jack_error( "ALSA/ICE1712: Unable to read EEPROM contents (%s)\n", snd_strerror (err));
  95. /* Recover? */
  96. }
  97. memcpy(h->eeprom, snd_ctl_elem_value_get_bytes(val), 32);
  98. /* determine number of pro ADC's. We're asumming that there is at least one stereo pair.
  99. Should check this first, but how? */
  100. switch((h->eeprom->codec & 0xCU) >> 2) {
  101. case 0:
  102. h->active_channels = 0x3U;
  103. break;
  104. case 1:
  105. h->active_channels = 0xfU;
  106. break;
  107. case 2:
  108. h->active_channels = 0x3fU;
  109. break;
  110. case 3:
  111. h->active_channels = 0xffU;
  112. break;
  113. }
  114. /* check for SPDIF In's */
  115. if (h->eeprom->spdif & 0x1U) {
  116. h->active_channels |= 0x300U;
  117. }
  118. hw->private = h;
  119. return hw;
  120. }