xonar_lib.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * helper functions for Asus Xonar cards
  3. *
  4. * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
  5. *
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License, version 2.
  9. *
  10. * This driver 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. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this driver; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/delay.h>
  19. #include <sound/core.h>
  20. #include <sound/control.h>
  21. #include <sound/pcm.h>
  22. #include <sound/pcm_params.h>
  23. #include "xonar.h"
  24. #define GPIO_CS53x1_M_MASK 0x000c
  25. #define GPIO_CS53x1_M_SINGLE 0x0000
  26. #define GPIO_CS53x1_M_DOUBLE 0x0004
  27. #define GPIO_CS53x1_M_QUAD 0x0008
  28. void xonar_enable_output(struct oxygen *chip)
  29. {
  30. struct xonar_generic *data = chip->model_data;
  31. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
  32. msleep(data->anti_pop_delay);
  33. oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
  34. }
  35. void xonar_disable_output(struct oxygen *chip)
  36. {
  37. struct xonar_generic *data = chip->model_data;
  38. oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
  39. }
  40. static void xonar_ext_power_gpio_changed(struct oxygen *chip)
  41. {
  42. struct xonar_generic *data = chip->model_data;
  43. u8 has_power;
  44. has_power = !!(oxygen_read8(chip, data->ext_power_reg)
  45. & data->ext_power_bit);
  46. if (has_power != data->has_power) {
  47. data->has_power = has_power;
  48. if (has_power) {
  49. dev_notice(chip->card->dev, "power restored\n");
  50. } else {
  51. dev_crit(chip->card->dev,
  52. "Hey! Don't unplug the power cable!\n");
  53. /* TODO: stop PCMs */
  54. }
  55. }
  56. }
  57. void xonar_init_ext_power(struct oxygen *chip)
  58. {
  59. struct xonar_generic *data = chip->model_data;
  60. oxygen_set_bits8(chip, data->ext_power_int_reg,
  61. data->ext_power_bit);
  62. chip->interrupt_mask |= OXYGEN_INT_GPIO;
  63. chip->model.gpio_changed = xonar_ext_power_gpio_changed;
  64. data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
  65. & data->ext_power_bit);
  66. }
  67. void xonar_init_cs53x1(struct oxygen *chip)
  68. {
  69. oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
  70. oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
  71. GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
  72. }
  73. void xonar_set_cs53x1_params(struct oxygen *chip,
  74. struct snd_pcm_hw_params *params)
  75. {
  76. unsigned int value;
  77. if (params_rate(params) <= 54000)
  78. value = GPIO_CS53x1_M_SINGLE;
  79. else if (params_rate(params) <= 108000)
  80. value = GPIO_CS53x1_M_DOUBLE;
  81. else
  82. value = GPIO_CS53x1_M_QUAD;
  83. oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
  84. value, GPIO_CS53x1_M_MASK);
  85. }
  86. int xonar_gpio_bit_switch_get(struct snd_kcontrol *ctl,
  87. struct snd_ctl_elem_value *value)
  88. {
  89. struct oxygen *chip = ctl->private_data;
  90. u16 bit = ctl->private_value;
  91. bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
  92. value->value.integer.value[0] =
  93. !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit) ^ invert;
  94. return 0;
  95. }
  96. int xonar_gpio_bit_switch_put(struct snd_kcontrol *ctl,
  97. struct snd_ctl_elem_value *value)
  98. {
  99. struct oxygen *chip = ctl->private_data;
  100. u16 bit = ctl->private_value;
  101. bool invert = ctl->private_value & XONAR_GPIO_BIT_INVERT;
  102. u16 old_bits, new_bits;
  103. int changed;
  104. spin_lock_irq(&chip->reg_lock);
  105. old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
  106. if (!!value->value.integer.value[0] ^ invert)
  107. new_bits = old_bits | bit;
  108. else
  109. new_bits = old_bits & ~bit;
  110. changed = new_bits != old_bits;
  111. if (changed)
  112. oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
  113. spin_unlock_irq(&chip->reg_lock);
  114. return changed;
  115. }