xonar_hdmi.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * helper functions for HDMI models (Xonar HDAV1.3/HDAV1.3 Slim)
  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/pci.h>
  19. #include <linux/delay.h>
  20. #include <sound/asoundef.h>
  21. #include <sound/control.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/tlv.h>
  26. #include "xonar.h"
  27. static void hdmi_write_command(struct oxygen *chip, u8 command,
  28. unsigned int count, const u8 *params)
  29. {
  30. unsigned int i;
  31. u8 checksum;
  32. oxygen_write_uart(chip, 0xfb);
  33. oxygen_write_uart(chip, 0xef);
  34. oxygen_write_uart(chip, command);
  35. oxygen_write_uart(chip, count);
  36. for (i = 0; i < count; ++i)
  37. oxygen_write_uart(chip, params[i]);
  38. checksum = 0xfb + 0xef + command + count;
  39. for (i = 0; i < count; ++i)
  40. checksum += params[i];
  41. oxygen_write_uart(chip, checksum);
  42. }
  43. static void xonar_hdmi_init_commands(struct oxygen *chip,
  44. struct xonar_hdmi *hdmi)
  45. {
  46. u8 param;
  47. oxygen_reset_uart(chip);
  48. param = 0;
  49. hdmi_write_command(chip, 0x61, 1, &param);
  50. param = 1;
  51. hdmi_write_command(chip, 0x74, 1, &param);
  52. hdmi_write_command(chip, 0x54, 5, hdmi->params);
  53. }
  54. void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
  55. {
  56. hdmi->params[1] = IEC958_AES3_CON_FS_48000;
  57. hdmi->params[4] = 1;
  58. xonar_hdmi_init_commands(chip, hdmi);
  59. }
  60. void xonar_hdmi_cleanup(struct oxygen *chip)
  61. {
  62. u8 param = 0;
  63. hdmi_write_command(chip, 0x74, 1, &param);
  64. }
  65. void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
  66. {
  67. xonar_hdmi_init_commands(chip, hdmi);
  68. }
  69. void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
  70. struct snd_pcm_hardware *hardware)
  71. {
  72. if (channel == PCM_MULTICH) {
  73. hardware->rates = SNDRV_PCM_RATE_44100 |
  74. SNDRV_PCM_RATE_48000 |
  75. SNDRV_PCM_RATE_96000 |
  76. SNDRV_PCM_RATE_192000;
  77. hardware->rate_min = 44100;
  78. }
  79. }
  80. void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
  81. struct snd_pcm_hw_params *params)
  82. {
  83. hdmi->params[0] = 0; /* 1 = non-audio */
  84. switch (params_rate(params)) {
  85. case 44100:
  86. hdmi->params[1] = IEC958_AES3_CON_FS_44100;
  87. break;
  88. case 48000:
  89. hdmi->params[1] = IEC958_AES3_CON_FS_48000;
  90. break;
  91. default: /* 96000 */
  92. hdmi->params[1] = IEC958_AES3_CON_FS_96000;
  93. break;
  94. case 192000:
  95. hdmi->params[1] = IEC958_AES3_CON_FS_192000;
  96. break;
  97. }
  98. hdmi->params[2] = params_channels(params) / 2 - 1;
  99. if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
  100. hdmi->params[3] = 0;
  101. else
  102. hdmi->params[3] = 0xc0;
  103. hdmi->params[4] = 1; /* ? */
  104. hdmi_write_command(chip, 0x54, 5, hdmi->params);
  105. }
  106. void xonar_hdmi_uart_input(struct oxygen *chip)
  107. {
  108. if (chip->uart_input_count >= 2 &&
  109. chip->uart_input[chip->uart_input_count - 2] == 'O' &&
  110. chip->uart_input[chip->uart_input_count - 1] == 'K') {
  111. printk(KERN_DEBUG "message from HDMI chip received:\n");
  112. print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
  113. chip->uart_input, chip->uart_input_count);
  114. chip->uart_input_count = 0;
  115. }
  116. }