xonar_hdmi.c 2.9 KB

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