1 // SPDX-License-Identifier: GPL-2.0-only
3 * helper functions for HDMI models (Xonar HDAV1.3/HDAV1.3 Slim)
9 #include <linux/delay.h>
10 #include <sound/asoundef.h>
11 #include <sound/control.h>
12 #include <sound/core.h>
13 #include <sound/pcm.h>
14 #include <sound/pcm_params.h>
15 #include <sound/tlv.h>
18 static void hdmi_write_command(struct oxygen *chip, u8 command,
19 unsigned int count, const u8 *params)
24 oxygen_write_uart(chip, 0xfb);
25 oxygen_write_uart(chip, 0xef);
26 oxygen_write_uart(chip, command);
27 oxygen_write_uart(chip, count);
28 for (i = 0; i < count; ++i)
29 oxygen_write_uart(chip, params[i]);
30 checksum = 0xfb + 0xef + command + count;
31 for (i = 0; i < count; ++i)
32 checksum += params[i];
33 oxygen_write_uart(chip, checksum);
36 static void xonar_hdmi_init_commands(struct oxygen *chip,
37 struct xonar_hdmi *hdmi)
41 oxygen_reset_uart(chip);
43 hdmi_write_command(chip, 0x61, 1, ¶m);
45 hdmi_write_command(chip, 0x74, 1, ¶m);
46 hdmi_write_command(chip, 0x54, 5, hdmi->params);
49 void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
51 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
53 xonar_hdmi_init_commands(chip, hdmi);
56 void xonar_hdmi_cleanup(struct oxygen *chip)
60 hdmi_write_command(chip, 0x74, 1, ¶m);
63 void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
65 xonar_hdmi_init_commands(chip, hdmi);
68 void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
69 struct snd_pcm_hardware *hardware)
71 if (channel == PCM_MULTICH) {
72 hardware->rates = SNDRV_PCM_RATE_44100 |
73 SNDRV_PCM_RATE_48000 |
74 SNDRV_PCM_RATE_96000 |
75 SNDRV_PCM_RATE_192000;
76 hardware->rate_min = 44100;
80 void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
81 struct snd_pcm_hw_params *params)
83 hdmi->params[0] = 0; /* 1 = non-audio */
84 switch (params_rate(params)) {
86 hdmi->params[1] = IEC958_AES3_CON_FS_44100;
89 hdmi->params[1] = IEC958_AES3_CON_FS_48000;
92 hdmi->params[1] = IEC958_AES3_CON_FS_96000;
95 hdmi->params[1] = IEC958_AES3_CON_FS_192000;
98 hdmi->params[2] = params_channels(params) / 2 - 1;
99 if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
102 hdmi->params[3] = 0xc0;
103 hdmi->params[4] = 1; /* ? */
104 hdmi_write_command(chip, 0x54, 5, hdmi->params);
107 void xonar_hdmi_uart_input(struct oxygen *chip)
109 if (chip->uart_input_count >= 2 &&
110 chip->uart_input[chip->uart_input_count - 2] == 'O' &&
111 chip->uart_input[chip->uart_input_count - 1] == 'K') {
112 dev_dbg(chip->card->dev, "message from HDMI chip received:\n");
113 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
114 chip->uart_input, chip->uart_input_count);
115 chip->uart_input_count = 0;