xref: /linux/sound/pci/oxygen/xonar_hdmi.c (revision 03d3ac21780be4d78f8d7679e428bb98fa9411ea)
165c3ac88SClemens Ladisch /*
2b532d6b8SClemens Ladisch  * helper functions for HDMI models (Xonar HDAV1.3/HDAV1.3 Slim)
365c3ac88SClemens Ladisch  *
465c3ac88SClemens Ladisch  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
565c3ac88SClemens Ladisch  *
665c3ac88SClemens Ladisch  *
765c3ac88SClemens Ladisch  *  This driver is free software; you can redistribute it and/or modify
865c3ac88SClemens Ladisch  *  it under the terms of the GNU General Public License, version 2.
965c3ac88SClemens Ladisch  *
1065c3ac88SClemens Ladisch  *  This driver is distributed in the hope that it will be useful,
1165c3ac88SClemens Ladisch  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1265c3ac88SClemens Ladisch  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1365c3ac88SClemens Ladisch  *  GNU General Public License for more details.
1465c3ac88SClemens Ladisch  *
1565c3ac88SClemens Ladisch  *  You should have received a copy of the GNU General Public License
1665c3ac88SClemens Ladisch  *  along with this driver; if not, see <http://www.gnu.org/licenses/>.
1765c3ac88SClemens Ladisch  */
1865c3ac88SClemens Ladisch 
1965c3ac88SClemens Ladisch #include <linux/pci.h>
2065c3ac88SClemens Ladisch #include <linux/delay.h>
2165c3ac88SClemens Ladisch #include <sound/asoundef.h>
2265c3ac88SClemens Ladisch #include <sound/control.h>
2365c3ac88SClemens Ladisch #include <sound/core.h>
2465c3ac88SClemens Ladisch #include <sound/pcm.h>
2565c3ac88SClemens Ladisch #include <sound/pcm_params.h>
2665c3ac88SClemens Ladisch #include <sound/tlv.h>
2765c3ac88SClemens Ladisch #include "xonar.h"
2865c3ac88SClemens Ladisch 
2965c3ac88SClemens Ladisch static void hdmi_write_command(struct oxygen *chip, u8 command,
3065c3ac88SClemens Ladisch 			       unsigned int count, const u8 *params)
3165c3ac88SClemens Ladisch {
3265c3ac88SClemens Ladisch 	unsigned int i;
3365c3ac88SClemens Ladisch 	u8 checksum;
3465c3ac88SClemens Ladisch 
3565c3ac88SClemens Ladisch 	oxygen_write_uart(chip, 0xfb);
3665c3ac88SClemens Ladisch 	oxygen_write_uart(chip, 0xef);
3765c3ac88SClemens Ladisch 	oxygen_write_uart(chip, command);
3865c3ac88SClemens Ladisch 	oxygen_write_uart(chip, count);
3965c3ac88SClemens Ladisch 	for (i = 0; i < count; ++i)
4065c3ac88SClemens Ladisch 		oxygen_write_uart(chip, params[i]);
4165c3ac88SClemens Ladisch 	checksum = 0xfb + 0xef + command + count;
4265c3ac88SClemens Ladisch 	for (i = 0; i < count; ++i)
4365c3ac88SClemens Ladisch 		checksum += params[i];
4465c3ac88SClemens Ladisch 	oxygen_write_uart(chip, checksum);
4565c3ac88SClemens Ladisch }
4665c3ac88SClemens Ladisch 
4765c3ac88SClemens Ladisch static void xonar_hdmi_init_commands(struct oxygen *chip,
4865c3ac88SClemens Ladisch 				     struct xonar_hdmi *hdmi)
4965c3ac88SClemens Ladisch {
5065c3ac88SClemens Ladisch 	u8 param;
5165c3ac88SClemens Ladisch 
5265c3ac88SClemens Ladisch 	oxygen_reset_uart(chip);
5365c3ac88SClemens Ladisch 	param = 0;
5465c3ac88SClemens Ladisch 	hdmi_write_command(chip, 0x61, 1, &param);
5565c3ac88SClemens Ladisch 	param = 1;
5665c3ac88SClemens Ladisch 	hdmi_write_command(chip, 0x74, 1, &param);
5765c3ac88SClemens Ladisch 	hdmi_write_command(chip, 0x54, 5, hdmi->params);
5865c3ac88SClemens Ladisch }
5965c3ac88SClemens Ladisch 
6065c3ac88SClemens Ladisch void xonar_hdmi_init(struct oxygen *chip, struct xonar_hdmi *hdmi)
6165c3ac88SClemens Ladisch {
6265c3ac88SClemens Ladisch 	hdmi->params[1] = IEC958_AES3_CON_FS_48000;
6365c3ac88SClemens Ladisch 	hdmi->params[4] = 1;
6465c3ac88SClemens Ladisch 	xonar_hdmi_init_commands(chip, hdmi);
6565c3ac88SClemens Ladisch }
6665c3ac88SClemens Ladisch 
6765c3ac88SClemens Ladisch void xonar_hdmi_cleanup(struct oxygen *chip)
6865c3ac88SClemens Ladisch {
6965c3ac88SClemens Ladisch 	u8 param = 0;
7065c3ac88SClemens Ladisch 
7165c3ac88SClemens Ladisch 	hdmi_write_command(chip, 0x74, 1, &param);
7265c3ac88SClemens Ladisch }
7365c3ac88SClemens Ladisch 
7465c3ac88SClemens Ladisch void xonar_hdmi_resume(struct oxygen *chip, struct xonar_hdmi *hdmi)
7565c3ac88SClemens Ladisch {
7665c3ac88SClemens Ladisch 	xonar_hdmi_init_commands(chip, hdmi);
7765c3ac88SClemens Ladisch }
7865c3ac88SClemens Ladisch 
7965c3ac88SClemens Ladisch void xonar_hdmi_pcm_hardware_filter(unsigned int channel,
8065c3ac88SClemens Ladisch 				    struct snd_pcm_hardware *hardware)
8165c3ac88SClemens Ladisch {
8265c3ac88SClemens Ladisch 	if (channel == PCM_MULTICH) {
8365c3ac88SClemens Ladisch 		hardware->rates = SNDRV_PCM_RATE_44100 |
8465c3ac88SClemens Ladisch 				  SNDRV_PCM_RATE_48000 |
8565c3ac88SClemens Ladisch 				  SNDRV_PCM_RATE_96000 |
8665c3ac88SClemens Ladisch 				  SNDRV_PCM_RATE_192000;
8765c3ac88SClemens Ladisch 		hardware->rate_min = 44100;
8865c3ac88SClemens Ladisch 	}
8965c3ac88SClemens Ladisch }
9065c3ac88SClemens Ladisch 
9165c3ac88SClemens Ladisch void xonar_set_hdmi_params(struct oxygen *chip, struct xonar_hdmi *hdmi,
9265c3ac88SClemens Ladisch 			   struct snd_pcm_hw_params *params)
9365c3ac88SClemens Ladisch {
9465c3ac88SClemens Ladisch 	hdmi->params[0] = 0; /* 1 = non-audio */
9565c3ac88SClemens Ladisch 	switch (params_rate(params)) {
9665c3ac88SClemens Ladisch 	case 44100:
9765c3ac88SClemens Ladisch 		hdmi->params[1] = IEC958_AES3_CON_FS_44100;
9865c3ac88SClemens Ladisch 		break;
9965c3ac88SClemens Ladisch 	case 48000:
10065c3ac88SClemens Ladisch 		hdmi->params[1] = IEC958_AES3_CON_FS_48000;
10165c3ac88SClemens Ladisch 		break;
10265c3ac88SClemens Ladisch 	default: /* 96000 */
10365c3ac88SClemens Ladisch 		hdmi->params[1] = IEC958_AES3_CON_FS_96000;
10465c3ac88SClemens Ladisch 		break;
10565c3ac88SClemens Ladisch 	case 192000:
10665c3ac88SClemens Ladisch 		hdmi->params[1] = IEC958_AES3_CON_FS_192000;
10765c3ac88SClemens Ladisch 		break;
10865c3ac88SClemens Ladisch 	}
10965c3ac88SClemens Ladisch 	hdmi->params[2] = params_channels(params) / 2 - 1;
11065c3ac88SClemens Ladisch 	if (params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
11165c3ac88SClemens Ladisch 		hdmi->params[3] = 0;
11265c3ac88SClemens Ladisch 	else
11365c3ac88SClemens Ladisch 		hdmi->params[3] = 0xc0;
11465c3ac88SClemens Ladisch 	hdmi->params[4] = 1; /* ? */
11565c3ac88SClemens Ladisch 	hdmi_write_command(chip, 0x54, 5, hdmi->params);
11665c3ac88SClemens Ladisch }
11765c3ac88SClemens Ladisch 
11865c3ac88SClemens Ladisch void xonar_hdmi_uart_input(struct oxygen *chip)
11965c3ac88SClemens Ladisch {
12065c3ac88SClemens Ladisch 	if (chip->uart_input_count >= 2 &&
12165c3ac88SClemens Ladisch 	    chip->uart_input[chip->uart_input_count - 2] == 'O' &&
12265c3ac88SClemens Ladisch 	    chip->uart_input[chip->uart_input_count - 1] == 'K') {
123*03d3ac21STakashi Iwai 		dev_dbg(chip->card->dev, "message from HDMI chip received:\n");
12465c3ac88SClemens Ladisch 		print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
12565c3ac88SClemens Ladisch 				     chip->uart_input, chip->uart_input_count);
12665c3ac88SClemens Ladisch 		chip->uart_input_count = 0;
12765c3ac88SClemens Ladisch 	}
12865c3ac88SClemens Ladisch }
129