Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * helper functions for HDMI models (Xonar HDAV1.3/HDAV1.3 Slim)
0004  *
0005  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
0006  */
0007 
0008 #include <linux/pci.h>
0009 #include <linux/delay.h>
0010 #include <sound/asoundef.h>
0011 #include <sound/control.h>
0012 #include <sound/core.h>
0013 #include <sound/pcm.h>
0014 #include <sound/pcm_params.h>
0015 #include <sound/tlv.h>
0016 #include "xonar.h"
0017 
0018 static void hdmi_write_command(struct oxygen *chip, u8 command,
0019                    unsigned int count, const u8 *params)
0020 {
0021     unsigned int i;
0022     u8 checksum;
0023 
0024     oxygen_write_uart(chip, 0xfb);
0025     oxygen_write_uart(chip, 0xef);
0026     oxygen_write_uart(chip, command);
0027     oxygen_write_uart(chip, count);
0028     for (i = 0; i < count; ++i)
0029         oxygen_write_uart(chip, params[i]);
0030     checksum = 0xfb + 0xef + command + count;
0031     for (i = 0; i < count; ++i)
0032         checksum += params[i];
0033     oxygen_write_uart(chip, checksum);
0034 }
0035 
0036 static void xonar_hdmi_init_commands(struct oxygen *chip,
0037                      struct xonar_hdmi *hdmi)
0038 {
0039     u8 param;
0040 
0041     oxygen_reset_uart(chip);
0042     param = 0;
0043     hdmi_write_command(chip, 0x61, 1, &param);
0044     param = 1;
0045     hdmi_write_command(chip, 0x74, 1, &param);
0046     hdmi_write_command(chip, 0x54, 5, hdmi->params);
0047 }
0048 
0049 void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
0050 {
0051     hdmi->params[1] = IEC958_AES3_CON_FS_48000;
0052     hdmi->params[4] = 1;
0053     xonar_hdmi_init_commands(chip, hdmi);
0054 }
0055 
0056 void xonar_hdmi_cleanup(struct oxygen *chip)
0057 {
0058     u8 param = 0;
0059 
0060     hdmi_write_command(chip, 0x74, 1, &param);
0061 }
0062 
0063 void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
0064 {
0065     xonar_hdmi_init_commands(chip, hdmi);
0066 }
0067 
0068 void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
0069                     struct snd_pcm_hardware *hardware)
0070 {
0071     if (channel == PCM_MULTICH) {
0072         hardware->rates = SNDRV_PCM_RATE_44100 |
0073                   SNDRV_PCM_RATE_48000 |
0074                   SNDRV_PCM_RATE_96000 |
0075                   SNDRV_PCM_RATE_192000;
0076         hardware->rate_min = 44100;
0077     }
0078 }
0079 
0080 void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
0081                struct snd_pcm_hw_params *params)
0082 {
0083     hdmi->params[0] = 0; /* 1 = non-audio */
0084     switch (params_rate(params)) {
0085     case 44100:
0086         hdmi->params[1] = IEC958_AES3_CON_FS_44100;
0087         break;
0088     case 48000:
0089         hdmi->params[1] = IEC958_AES3_CON_FS_48000;
0090         break;
0091     default: /* 96000 */
0092         hdmi->params[1] = IEC958_AES3_CON_FS_96000;
0093         break;
0094     case 192000:
0095         hdmi->params[1] = IEC958_AES3_CON_FS_192000;
0096         break;
0097     }
0098     hdmi->params[2] = params_channels(params) / 2 - 1;
0099     if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
0100         hdmi->params[3] = 0;
0101     else
0102         hdmi->params[3] = 0xc0;
0103     hdmi->params[4] = 1; /* ? */
0104     hdmi_write_command(chip, 0x54, 5, hdmi->params);
0105 }
0106 
0107 void xonar_hdmi_uart_input(struct oxygen *chip)
0108 {
0109     if (chip->uart_input_count >= 2 &&
0110         chip->uart_input[chip->uart_input_count - 2] == 'O' &&
0111         chip->uart_input[chip->uart_input_count - 1] == 'K') {
0112         dev_dbg(chip->card->dev, "message from HDMI chip received:\n");
0113         print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
0114                      chip->uart_input, chip->uart_input_count);
0115         chip->uart_input_count = 0;
0116     }
0117 }