2019-05-21 01:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-11-18 11:47:52 +08:00
|
|
|
/*
|
|
|
|
* Generic routines and proc interface for ELD(EDID Like Data) information
|
|
|
|
*
|
|
|
|
* Copyright(c) 2008 Intel Corporation.
|
2013-10-25 02:10:36 +08:00
|
|
|
* Copyright (c) 2013 Anssi Hannula <anssi.hannula@iki.fi>
|
2008-11-18 11:47:52 +08:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Wu Fengguang <wfg@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-11-18 11:47:52 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <asm/unaligned.h>
|
2016-03-04 22:29:51 +08:00
|
|
|
#include <sound/hda_chmap.h>
|
2018-08-23 04:24:57 +08:00
|
|
|
#include <sound/hda_codec.h>
|
2008-11-18 11:47:52 +08:00
|
|
|
#include "hda_local.h"
|
|
|
|
|
|
|
|
enum eld_versions {
|
|
|
|
ELD_VER_CEA_861D = 2,
|
|
|
|
ELD_VER_PARTIAL = 31,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cea_edid_versions {
|
|
|
|
CEA_EDID_VER_NONE = 0,
|
|
|
|
CEA_EDID_VER_CEA861 = 1,
|
|
|
|
CEA_EDID_VER_CEA861A = 2,
|
|
|
|
CEA_EDID_VER_CEA861BCD = 3,
|
|
|
|
CEA_EDID_VER_RESERVED = 4,
|
|
|
|
};
|
|
|
|
|
2015-08-17 21:06:52 +08:00
|
|
|
static const char * const eld_connection_type_names[4] = {
|
2008-11-18 11:47:52 +08:00
|
|
|
"HDMI",
|
2008-11-22 09:40:56 +08:00
|
|
|
"DisplayPort",
|
2008-11-18 11:47:52 +08:00
|
|
|
"2-reserved",
|
|
|
|
"3-reserved"
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cea_audio_coding_types {
|
|
|
|
AUDIO_CODING_TYPE_REF_STREAM_HEADER = 0,
|
|
|
|
AUDIO_CODING_TYPE_LPCM = 1,
|
|
|
|
AUDIO_CODING_TYPE_AC3 = 2,
|
|
|
|
AUDIO_CODING_TYPE_MPEG1 = 3,
|
|
|
|
AUDIO_CODING_TYPE_MP3 = 4,
|
|
|
|
AUDIO_CODING_TYPE_MPEG2 = 5,
|
|
|
|
AUDIO_CODING_TYPE_AACLC = 6,
|
|
|
|
AUDIO_CODING_TYPE_DTS = 7,
|
|
|
|
AUDIO_CODING_TYPE_ATRAC = 8,
|
|
|
|
AUDIO_CODING_TYPE_SACD = 9,
|
|
|
|
AUDIO_CODING_TYPE_EAC3 = 10,
|
|
|
|
AUDIO_CODING_TYPE_DTS_HD = 11,
|
|
|
|
AUDIO_CODING_TYPE_MLP = 12,
|
|
|
|
AUDIO_CODING_TYPE_DST = 13,
|
|
|
|
AUDIO_CODING_TYPE_WMAPRO = 14,
|
|
|
|
AUDIO_CODING_TYPE_REF_CXT = 15,
|
|
|
|
/* also include valid xtypes below */
|
|
|
|
AUDIO_CODING_TYPE_HE_AAC = 15,
|
|
|
|
AUDIO_CODING_TYPE_HE_AAC2 = 16,
|
|
|
|
AUDIO_CODING_TYPE_MPEG_SURROUND = 17,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cea_audio_coding_xtypes {
|
|
|
|
AUDIO_CODING_XTYPE_HE_REF_CT = 0,
|
|
|
|
AUDIO_CODING_XTYPE_HE_AAC = 1,
|
|
|
|
AUDIO_CODING_XTYPE_HE_AAC2 = 2,
|
|
|
|
AUDIO_CODING_XTYPE_MPEG_SURROUND = 3,
|
|
|
|
AUDIO_CODING_XTYPE_FIRST_RESERVED = 4,
|
|
|
|
};
|
|
|
|
|
2015-08-17 21:06:52 +08:00
|
|
|
static const char * const cea_audio_coding_type_names[] = {
|
2008-11-18 11:47:52 +08:00
|
|
|
/* 0 */ "undefined",
|
|
|
|
/* 1 */ "LPCM",
|
|
|
|
/* 2 */ "AC-3",
|
|
|
|
/* 3 */ "MPEG1",
|
|
|
|
/* 4 */ "MP3",
|
|
|
|
/* 5 */ "MPEG2",
|
|
|
|
/* 6 */ "AAC-LC",
|
|
|
|
/* 7 */ "DTS",
|
|
|
|
/* 8 */ "ATRAC",
|
2008-11-19 15:14:01 +08:00
|
|
|
/* 9 */ "DSD (One Bit Audio)",
|
2008-11-18 11:47:52 +08:00
|
|
|
/* 10 */ "E-AC-3/DD+ (Dolby Digital Plus)",
|
|
|
|
/* 11 */ "DTS-HD",
|
|
|
|
/* 12 */ "MLP (Dolby TrueHD)",
|
|
|
|
/* 13 */ "DST",
|
|
|
|
/* 14 */ "WMAPro",
|
|
|
|
/* 15 */ "HE-AAC",
|
|
|
|
/* 16 */ "HE-AACv2",
|
|
|
|
/* 17 */ "MPEG Surround",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following two lists are shared between
|
|
|
|
* - HDMI audio InfoFrame (source to sink)
|
2008-11-19 15:13:59 +08:00
|
|
|
* - CEA E-EDID Extension (sink to source)
|
2008-11-18 11:47:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SS1:SS0 index => sample size
|
|
|
|
*/
|
2020-01-05 22:47:24 +08:00
|
|
|
static const int cea_sample_sizes[4] = {
|
2008-11-18 11:47:52 +08:00
|
|
|
0, /* 0: Refer to Stream Header */
|
|
|
|
AC_SUPPCM_BITS_16, /* 1: 16 bits */
|
|
|
|
AC_SUPPCM_BITS_20, /* 2: 20 bits */
|
|
|
|
AC_SUPPCM_BITS_24, /* 3: 24 bits */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SF2:SF1:SF0 index => sampling frequency
|
|
|
|
*/
|
2020-01-05 22:47:24 +08:00
|
|
|
static const int cea_sampling_frequencies[8] = {
|
2008-11-18 11:47:52 +08:00
|
|
|
0, /* 0: Refer to Stream Header */
|
|
|
|
SNDRV_PCM_RATE_32000, /* 1: 32000Hz */
|
|
|
|
SNDRV_PCM_RATE_44100, /* 2: 44100Hz */
|
|
|
|
SNDRV_PCM_RATE_48000, /* 3: 48000Hz */
|
|
|
|
SNDRV_PCM_RATE_88200, /* 4: 88200Hz */
|
|
|
|
SNDRV_PCM_RATE_96000, /* 5: 96000Hz */
|
|
|
|
SNDRV_PCM_RATE_176400, /* 6: 176400Hz */
|
|
|
|
SNDRV_PCM_RATE_192000, /* 7: 192000Hz */
|
|
|
|
};
|
|
|
|
|
2011-08-20 15:14:45 +08:00
|
|
|
static unsigned int hdmi_get_eld_data(struct hda_codec *codec, hda_nid_t nid,
|
2008-11-18 11:47:52 +08:00
|
|
|
int byte_index)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
val = snd_hda_codec_read(codec, nid, 0,
|
|
|
|
AC_VERB_GET_HDMI_ELDD, byte_index);
|
|
|
|
#ifdef BE_PARANOID
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI: ELD data byte %d: 0x%x\n", byte_index, val);
|
2008-11-18 11:47:52 +08:00
|
|
|
#endif
|
2011-08-20 15:14:45 +08:00
|
|
|
return val;
|
2008-11-18 11:47:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GRAB_BITS(buf, byte, lowbit, bits) \
|
|
|
|
({ \
|
|
|
|
BUILD_BUG_ON(lowbit > 7); \
|
|
|
|
BUILD_BUG_ON(bits > 8); \
|
|
|
|
BUILD_BUG_ON(bits <= 0); \
|
|
|
|
\
|
|
|
|
(buf[byte] >> (lowbit)) & ((1 << (bits)) - 1); \
|
|
|
|
})
|
|
|
|
|
2014-06-07 00:04:34 +08:00
|
|
|
static void hdmi_update_short_audio_desc(struct hda_codec *codec,
|
|
|
|
struct cea_sad *a,
|
2008-11-18 11:47:52 +08:00
|
|
|
const unsigned char *buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = GRAB_BITS(buf, 1, 0, 7);
|
|
|
|
a->rates = 0;
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
if (val & (1 << i))
|
|
|
|
a->rates |= cea_sampling_frequencies[i + 1];
|
|
|
|
|
|
|
|
a->channels = GRAB_BITS(buf, 0, 0, 3);
|
|
|
|
a->channels++;
|
|
|
|
|
2010-12-08 03:19:23 +08:00
|
|
|
a->sample_bits = 0;
|
|
|
|
a->max_bitrate = 0;
|
|
|
|
|
2008-11-18 11:47:52 +08:00
|
|
|
a->format = GRAB_BITS(buf, 0, 3, 4);
|
|
|
|
switch (a->format) {
|
|
|
|
case AUDIO_CODING_TYPE_REF_STREAM_HEADER:
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec, "HDMI: audio coding type 0 not expected\n");
|
2008-11-18 11:47:52 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_LPCM:
|
|
|
|
val = GRAB_BITS(buf, 2, 0, 3);
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
if (val & (1 << i))
|
|
|
|
a->sample_bits |= cea_sample_sizes[i + 1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_AC3:
|
|
|
|
case AUDIO_CODING_TYPE_MPEG1:
|
|
|
|
case AUDIO_CODING_TYPE_MP3:
|
|
|
|
case AUDIO_CODING_TYPE_MPEG2:
|
|
|
|
case AUDIO_CODING_TYPE_AACLC:
|
|
|
|
case AUDIO_CODING_TYPE_DTS:
|
|
|
|
case AUDIO_CODING_TYPE_ATRAC:
|
|
|
|
a->max_bitrate = GRAB_BITS(buf, 2, 0, 8);
|
|
|
|
a->max_bitrate *= 8000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_SACD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_EAC3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_DTS_HD:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_MLP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_DST:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_WMAPRO:
|
|
|
|
a->profile = GRAB_BITS(buf, 2, 0, 3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIO_CODING_TYPE_REF_CXT:
|
|
|
|
a->format = GRAB_BITS(buf, 2, 3, 5);
|
|
|
|
if (a->format == AUDIO_CODING_XTYPE_HE_REF_CT ||
|
|
|
|
a->format >= AUDIO_CODING_XTYPE_FIRST_RESERVED) {
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec,
|
|
|
|
"HDMI: audio coding xtype %d not expected\n",
|
|
|
|
a->format);
|
2008-11-18 11:47:52 +08:00
|
|
|
a->format = 0;
|
|
|
|
} else
|
|
|
|
a->format += AUDIO_CODING_TYPE_HE_AAC -
|
|
|
|
AUDIO_CODING_XTYPE_HE_AAC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Be careful, ELD buf could be totally rubbish!
|
|
|
|
*/
|
2014-06-07 00:04:34 +08:00
|
|
|
int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
|
2013-02-19 23:11:24 +08:00
|
|
|
const unsigned char *buf, int size)
|
2008-11-18 11:47:52 +08:00
|
|
|
{
|
|
|
|
int mnl;
|
|
|
|
int i;
|
|
|
|
|
2015-11-13 19:51:49 +08:00
|
|
|
memset(e, 0, sizeof(*e));
|
2008-11-18 11:47:52 +08:00
|
|
|
e->eld_ver = GRAB_BITS(buf, 0, 3, 5);
|
|
|
|
if (e->eld_ver != ELD_VER_CEA_861D &&
|
|
|
|
e->eld_ver != ELD_VER_PARTIAL) {
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec, "HDMI: Unknown ELD version %d\n", e->eld_ver);
|
2008-11-18 11:47:52 +08:00
|
|
|
goto out_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
e->baseline_len = GRAB_BITS(buf, 2, 0, 8);
|
|
|
|
mnl = GRAB_BITS(buf, 4, 0, 5);
|
|
|
|
e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3);
|
|
|
|
|
|
|
|
e->support_hdcp = GRAB_BITS(buf, 5, 0, 1);
|
|
|
|
e->support_ai = GRAB_BITS(buf, 5, 1, 1);
|
|
|
|
e->conn_type = GRAB_BITS(buf, 5, 2, 2);
|
|
|
|
e->sad_count = GRAB_BITS(buf, 5, 4, 4);
|
|
|
|
|
|
|
|
e->aud_synch_delay = GRAB_BITS(buf, 6, 0, 8) * 2;
|
|
|
|
e->spk_alloc = GRAB_BITS(buf, 7, 0, 7);
|
|
|
|
|
|
|
|
e->port_id = get_unaligned_le64(buf + 8);
|
|
|
|
|
|
|
|
/* not specified, but the spec's tendency is little endian */
|
|
|
|
e->manufacture_id = get_unaligned_le16(buf + 16);
|
|
|
|
e->product_id = get_unaligned_le16(buf + 18);
|
|
|
|
|
|
|
|
if (mnl > ELD_MAX_MNL) {
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec, "HDMI: MNL is reserved value %d\n", mnl);
|
2008-11-18 11:47:52 +08:00
|
|
|
goto out_fail;
|
|
|
|
} else if (ELD_FIXED_BYTES + mnl > size) {
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec, "HDMI: out of range MNL %d\n", mnl);
|
2008-11-18 11:47:52 +08:00
|
|
|
goto out_fail;
|
|
|
|
} else
|
ALSA: Convert strlcpy to strscpy when return value is unused
strlcpy is deprecated. see: Documentation/process/deprecated.rst
Change the calls that do not use the strlcpy return value to the
preferred strscpy.
Done with cocci script:
@@
expression e1, e2, e3;
@@
- strlcpy(
+ strscpy(
e1, e2, e3);
This cocci script leaves the instances where the return value is
used unchanged.
After this patch, sound/ has 3 uses of strlcpy() that need to be
manually inspected for conversion and changed one day.
$ git grep -w strlcpy sound/
sound/usb/card.c: len = strlcpy(card->longname, s, sizeof(card->longname));
sound/usb/mixer.c: return strlcpy(buf, p->name, buflen);
sound/usb/mixer.c: return strlcpy(buf, p->names[index], buflen);
Miscellenea:
o Remove trailing whitespace in conversion of sound/core/hwdep.c
Link: https://lore.kernel.org/lkml/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/22b393d1790bb268769d0bab7bacf0866dcb0c14.camel@perches.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-01-05 01:17:34 +08:00
|
|
|
strscpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1);
|
2008-11-18 11:47:52 +08:00
|
|
|
|
|
|
|
for (i = 0; i < e->sad_count; i++) {
|
|
|
|
if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) {
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_info(codec, "HDMI: out of range SAD %d\n", i);
|
2008-11-18 11:47:52 +08:00
|
|
|
goto out_fail;
|
|
|
|
}
|
2014-06-07 00:04:34 +08:00
|
|
|
hdmi_update_short_audio_desc(codec, e->sad + i,
|
2008-11-18 11:47:52 +08:00
|
|
|
buf + ELD_FIXED_BYTES + mnl + 3 * i);
|
|
|
|
}
|
|
|
|
|
2011-11-16 16:29:48 +08:00
|
|
|
/*
|
|
|
|
* HDMI sink's ELD info cannot always be retrieved for now, e.g.
|
|
|
|
* in console or for audio devices. Assume the highest speakers
|
|
|
|
* configuration, to _not_ prohibit multi-channel audio playback.
|
|
|
|
*/
|
|
|
|
if (!e->spk_alloc)
|
|
|
|
e->spk_alloc = 0xffff;
|
|
|
|
|
2008-11-18 11:47:52 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_fail:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid)
|
|
|
|
{
|
|
|
|
return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE,
|
|
|
|
AC_DIPSIZE_ELD_BUF);
|
|
|
|
}
|
|
|
|
|
2013-02-19 23:11:24 +08:00
|
|
|
int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
|
|
|
|
unsigned char *buf, int *eld_size)
|
2008-11-18 11:47:52 +08:00
|
|
|
{
|
|
|
|
int i;
|
2013-03-28 17:20:22 +08:00
|
|
|
int ret = 0;
|
2008-11-18 11:47:52 +08:00
|
|
|
int size;
|
|
|
|
|
2011-10-01 05:35:41 +08:00
|
|
|
/*
|
|
|
|
* ELD size is initialized to zero in caller function. If no errors and
|
2013-02-19 23:11:24 +08:00
|
|
|
* ELD is valid, actual eld_size is assigned.
|
2011-10-01 05:35:41 +08:00
|
|
|
*/
|
|
|
|
|
2008-11-18 11:47:52 +08:00
|
|
|
size = snd_hdmi_get_eld_size(codec, nid);
|
|
|
|
if (size == 0) {
|
|
|
|
/* wfg: workaround for ASUS P5E-VM HDMI board */
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI: ELD buf size is 0, force 128\n");
|
2008-11-18 11:47:52 +08:00
|
|
|
size = 128;
|
|
|
|
}
|
2011-10-01 05:35:41 +08:00
|
|
|
if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI: invalid ELD buf size %d\n", size);
|
2008-11-18 11:47:52 +08:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2011-10-01 05:35:41 +08:00
|
|
|
/* set ELD buffer */
|
2011-08-20 15:14:45 +08:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
unsigned int val = hdmi_get_eld_data(codec, nid, i);
|
2011-11-22 16:46:23 +08:00
|
|
|
/*
|
|
|
|
* Graphics driver might be writing to ELD buffer right now.
|
|
|
|
* Just abort. The caller will repoll after a while.
|
|
|
|
*/
|
2011-08-20 15:14:45 +08:00
|
|
|
if (!(val & AC_ELDD_ELD_VALID)) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI: invalid ELD data byte %d\n", i);
|
2011-11-22 16:46:23 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
val &= AC_ELDD_ELD_DATA;
|
|
|
|
/*
|
|
|
|
* The first byte cannot be zero. This can happen on some DVI
|
|
|
|
* connections. Some Intel chips may also need some 250ms delay
|
|
|
|
* to return non-zero ELD data, even when the graphics driver
|
|
|
|
* correctly writes ELD content before setting ELD_valid bit.
|
|
|
|
*/
|
|
|
|
if (!val && !i) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_dbg(codec, "HDMI: 0 ELD data\n");
|
2011-11-22 16:46:23 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto error;
|
|
|
|
}
|
2011-08-20 15:14:45 +08:00
|
|
|
buf[i] = val;
|
|
|
|
}
|
2008-11-18 11:47:52 +08:00
|
|
|
|
2013-02-19 23:11:24 +08:00
|
|
|
*eld_size = size;
|
2011-08-20 15:14:45 +08:00
|
|
|
error:
|
2008-11-18 11:47:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-29 22:06:01 +08:00
|
|
|
/*
|
2011-10-06 04:14:20 +08:00
|
|
|
* SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with
|
|
|
|
* hdmi-specific routine.
|
|
|
|
*/
|
|
|
|
static void hdmi_print_pcm_rates(int pcm, char *buf, int buflen)
|
|
|
|
{
|
2020-01-05 22:47:24 +08:00
|
|
|
static const unsigned int alsa_rates[] = {
|
2012-03-13 23:43:02 +08:00
|
|
|
5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
|
|
|
|
88200, 96000, 176400, 192000, 384000
|
2011-10-06 04:14:20 +08:00
|
|
|
};
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < ARRAY_SIZE(alsa_rates); i++)
|
|
|
|
if (pcm & (1 << i))
|
2020-02-18 17:14:09 +08:00
|
|
|
j += scnprintf(buf + j, buflen - j, " %d",
|
2011-10-06 04:14:20 +08:00
|
|
|
alsa_rates[i]);
|
|
|
|
|
|
|
|
buf[j] = '\0'; /* necessary when j == 0 */
|
|
|
|
}
|
|
|
|
|
2011-10-06 14:16:29 +08:00
|
|
|
#define SND_PRINT_RATES_ADVISED_BUFSIZE 80
|
|
|
|
|
2014-06-07 00:04:34 +08:00
|
|
|
static void hdmi_show_short_audio_desc(struct hda_codec *codec,
|
|
|
|
struct cea_sad *a)
|
2008-11-18 11:47:52 +08:00
|
|
|
{
|
|
|
|
char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
|
2008-11-19 15:14:03 +08:00
|
|
|
char buf2[8 + SND_PRINT_BITS_ADVISED_BUFSIZE] = ", bits =";
|
2008-11-18 11:47:52 +08:00
|
|
|
|
2008-11-19 15:14:03 +08:00
|
|
|
if (!a->format)
|
|
|
|
return;
|
2008-11-18 11:47:52 +08:00
|
|
|
|
2011-10-06 04:14:20 +08:00
|
|
|
hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
|
2008-11-18 11:47:52 +08:00
|
|
|
|
|
|
|
if (a->format == AUDIO_CODING_TYPE_LPCM)
|
2011-01-26 02:44:26 +08:00
|
|
|
snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8);
|
2008-11-19 15:14:03 +08:00
|
|
|
else if (a->max_bitrate)
|
|
|
|
snprintf(buf2, sizeof(buf2),
|
|
|
|
", max bitrate = %d", a->max_bitrate);
|
|
|
|
else
|
|
|
|
buf2[0] = '\0';
|
|
|
|
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_dbg(codec,
|
|
|
|
"HDMI: supports coding type %s: channels = %d, rates =%s%s\n",
|
|
|
|
cea_audio_coding_type_names[a->format],
|
|
|
|
a->channels, buf, buf2);
|
2008-11-18 11:47:52 +08:00
|
|
|
}
|
|
|
|
|
2014-06-07 00:04:34 +08:00
|
|
|
void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e)
|
2008-11-18 11:47:52 +08:00
|
|
|
{
|
|
|
|
int i;
|
2008-11-19 15:14:03 +08:00
|
|
|
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_dbg(codec, "HDMI: detected monitor %s at connection type %s\n",
|
2008-11-19 15:14:03 +08:00
|
|
|
e->monitor_name,
|
|
|
|
eld_connection_type_names[e->conn_type]);
|
|
|
|
|
|
|
|
if (e->spk_alloc) {
|
|
|
|
char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
|
2016-03-04 22:29:52 +08:00
|
|
|
snd_hdac_print_channel_allocation(e->spk_alloc, buf, sizeof(buf));
|
2014-06-07 00:04:34 +08:00
|
|
|
codec_dbg(codec, "HDMI: available speakers:%s\n", buf);
|
2008-11-19 15:14:03 +08:00
|
|
|
}
|
2008-11-18 11:47:52 +08:00
|
|
|
|
|
|
|
for (i = 0; i < e->sad_count; i++)
|
2014-06-07 00:04:34 +08:00
|
|
|
hdmi_show_short_audio_desc(codec, e->sad + i);
|
2008-11-18 11:47:52 +08:00
|
|
|
}
|
2008-11-18 11:47:53 +08:00
|
|
|
|
2015-05-27 19:45:45 +08:00
|
|
|
#ifdef CONFIG_SND_PROC_FS
|
2008-11-18 11:47:53 +08:00
|
|
|
|
|
|
|
static void hdmi_print_sad_info(int i, struct cea_sad *a,
|
|
|
|
struct snd_info_buffer *buffer)
|
|
|
|
{
|
2008-11-19 15:14:02 +08:00
|
|
|
char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
|
2008-11-18 11:47:53 +08:00
|
|
|
|
|
|
|
snd_iprintf(buffer, "sad%d_coding_type\t[0x%x] %s\n",
|
|
|
|
i, a->format, cea_audio_coding_type_names[a->format]);
|
|
|
|
snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels);
|
|
|
|
|
2011-10-06 04:14:20 +08:00
|
|
|
hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
|
2008-11-19 15:14:01 +08:00
|
|
|
snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf);
|
2008-11-18 11:47:53 +08:00
|
|
|
|
2008-11-19 15:14:02 +08:00
|
|
|
if (a->format == AUDIO_CODING_TYPE_LPCM) {
|
|
|
|
snd_print_pcm_bits(a->sample_bits, buf, sizeof(buf));
|
|
|
|
snd_iprintf(buffer, "sad%d_bits\t\t[0x%x]%s\n",
|
|
|
|
i, a->sample_bits, buf);
|
|
|
|
}
|
2008-11-18 11:47:53 +08:00
|
|
|
|
|
|
|
if (a->max_bitrate)
|
|
|
|
snd_iprintf(buffer, "sad%d_max_bitrate\t%d\n",
|
|
|
|
i, a->max_bitrate);
|
|
|
|
|
|
|
|
if (a->profile)
|
|
|
|
snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile);
|
|
|
|
}
|
|
|
|
|
2013-10-18 00:21:12 +08:00
|
|
|
void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
|
2022-09-21 17:33:49 +08:00
|
|
|
struct snd_info_buffer *buffer,
|
|
|
|
hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
|
2008-11-18 11:47:53 +08:00
|
|
|
{
|
2013-02-19 23:11:24 +08:00
|
|
|
struct parsed_hdmi_eld *e = &eld->info;
|
2008-11-19 08:56:16 +08:00
|
|
|
char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
|
2008-11-18 11:47:53 +08:00
|
|
|
int i;
|
2015-08-17 21:06:52 +08:00
|
|
|
static const char * const eld_version_names[32] = {
|
2008-11-22 09:40:57 +08:00
|
|
|
"reserved",
|
|
|
|
"reserved",
|
|
|
|
"CEA-861D or below",
|
|
|
|
[3 ... 30] = "reserved",
|
|
|
|
[31] = "partial"
|
|
|
|
};
|
2015-08-17 21:06:52 +08:00
|
|
|
static const char * const cea_edid_version_names[8] = {
|
2008-11-22 09:40:57 +08:00
|
|
|
"no CEA EDID Timing Extension block present",
|
|
|
|
"CEA-861",
|
|
|
|
"CEA-861-A",
|
|
|
|
"CEA-861-B, C or D",
|
|
|
|
[4 ... 7] = "reserved"
|
|
|
|
};
|
2008-11-18 11:47:53 +08:00
|
|
|
|
2013-02-19 23:11:24 +08:00
|
|
|
snd_iprintf(buffer, "monitor_present\t\t%d\n", eld->monitor_present);
|
|
|
|
snd_iprintf(buffer, "eld_valid\t\t%d\n", eld->eld_valid);
|
2022-09-21 17:33:49 +08:00
|
|
|
snd_iprintf(buffer, "codec_pin_nid\t\t0x%x\n", pin_nid);
|
|
|
|
snd_iprintf(buffer, "codec_dev_id\t\t0x%x\n", dev_id);
|
|
|
|
snd_iprintf(buffer, "codec_cvt_nid\t\t0x%x\n", cvt_nid);
|
2013-10-18 00:21:12 +08:00
|
|
|
if (!eld->eld_valid)
|
ALSA: HDA: Unify HDMI hotplug handling.
This change unifies the initial handling of a pin's state with the code to
update a pin's state after a hotplug (unsolicited response) event. The
initial probing, and all updates, are now routed through hdmi_present_sense.
The stored PD and ELDV status is now always derived from GetPinSense verb
execution, and not from the data in the unsolicited response. This means:
a) The WAR for NVIDIA codec's UR.PD values ("old_pin_detect") can be
removed, since this only affected the no-longer-used unsolicited
response payload.
b) In turn, this means that most NVIDIA codecs can simply use
patch_generic_hdmi instead of having a custom variant just to set
old_pin_detect.
c) When PD && ELDV becomes true, no extra verbs are executed, because the
GetPinSense that was previously executed by snd_hdmi_get_eld (really,
hdmi_eld_valid) has simply moved into hdmi_present_sense.
d) When PD && ELDV becomes false, there is a single extra GetPinSense verb
executed for codecs where old_pin_detect wasn't set, i.e. some NVIDIA,
and all ATI/AMD and Intel codecs. I doubt this will be a performance
issue.
The new unified code in hdmi_present_sense also ensures that eld->eld_valid
is not set unless eld->monitor_present is also set. This protects against
potential invalid combinations of PD and ELDV received from HW, and
transitively from a graphics driver.
Also, print the derived PD/ELDV bits from hdmi_present_sense so the kernel
log always displays the actual state stored, which will differ from the
values in the unsolicited response for NVIDIA HW where old_pin_detect was
previously set.
Finally, a couple of small tweaks originally by Takashi:
* Clear the ELD content to zero before reading it, so that if it's not
read (i.e. when !(PD && ELDV)) it's in a known state.
* Don't show ELD fields in /proc ELD files when the ELD isn't valid.
The only possibility I can see for regression here is a codec where the
GetPinSense verb returns incorrect data. However, we're already exposed
to that, since that data is used (a) from hdmi_add_pin to set up the
initial pin state, and (b) within snd_hda_input_jack_report to query
a pin's presence value. As such, I don't believe any HW has bugs here.
Includes-changes-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-05-25 07:11:17 +08:00
|
|
|
return;
|
2008-11-21 12:34:05 +08:00
|
|
|
snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name);
|
2008-11-18 11:47:53 +08:00
|
|
|
snd_iprintf(buffer, "connection_type\t\t%s\n",
|
|
|
|
eld_connection_type_names[e->conn_type]);
|
|
|
|
snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver,
|
2013-02-19 23:11:24 +08:00
|
|
|
eld_version_names[e->eld_ver]);
|
2008-11-18 11:47:53 +08:00
|
|
|
snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver,
|
|
|
|
cea_edid_version_names[e->cea_edid_ver]);
|
|
|
|
snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id);
|
|
|
|
snd_iprintf(buffer, "product_id\t\t0x%x\n", e->product_id);
|
|
|
|
snd_iprintf(buffer, "port_id\t\t\t0x%llx\n", (long long)e->port_id);
|
|
|
|
snd_iprintf(buffer, "support_hdcp\t\t%d\n", e->support_hdcp);
|
|
|
|
snd_iprintf(buffer, "support_ai\t\t%d\n", e->support_ai);
|
|
|
|
snd_iprintf(buffer, "audio_sync_delay\t%d\n", e->aud_synch_delay);
|
|
|
|
|
2016-03-04 22:29:52 +08:00
|
|
|
snd_hdac_print_channel_allocation(e->spk_alloc, buf, sizeof(buf));
|
2008-11-19 15:14:01 +08:00
|
|
|
snd_iprintf(buffer, "speakers\t\t[0x%x]%s\n", e->spk_alloc, buf);
|
2008-11-18 11:47:53 +08:00
|
|
|
|
|
|
|
snd_iprintf(buffer, "sad_count\t\t%d\n", e->sad_count);
|
|
|
|
|
|
|
|
for (i = 0; i < e->sad_count; i++)
|
|
|
|
hdmi_print_sad_info(i, e->sad + i, buffer);
|
|
|
|
}
|
|
|
|
|
2013-10-18 00:21:12 +08:00
|
|
|
void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
|
|
|
|
struct snd_info_buffer *buffer)
|
2008-11-21 11:41:50 +08:00
|
|
|
{
|
2013-02-19 23:11:24 +08:00
|
|
|
struct parsed_hdmi_eld *e = &eld->info;
|
2008-11-21 11:41:50 +08:00
|
|
|
char line[64];
|
|
|
|
char name[64];
|
|
|
|
char *sname;
|
|
|
|
long long val;
|
2009-07-29 20:35:20 +08:00
|
|
|
unsigned int n;
|
2008-11-21 11:41:50 +08:00
|
|
|
|
|
|
|
while (!snd_info_get_line(buffer, line, sizeof(line))) {
|
|
|
|
if (sscanf(line, "%s %llx", name, &val) != 2)
|
|
|
|
continue;
|
2008-11-22 09:40:54 +08:00
|
|
|
/*
|
|
|
|
* We don't allow modification to these fields:
|
|
|
|
* monitor_name manufacture_id product_id
|
|
|
|
* eld_version edid_version
|
|
|
|
*/
|
2009-11-18 12:38:01 +08:00
|
|
|
if (!strcmp(name, "monitor_present"))
|
2013-02-19 23:11:24 +08:00
|
|
|
eld->monitor_present = val;
|
2009-11-18 12:38:01 +08:00
|
|
|
else if (!strcmp(name, "eld_valid"))
|
2013-02-19 23:11:24 +08:00
|
|
|
eld->eld_valid = val;
|
2009-11-18 12:38:01 +08:00
|
|
|
else if (!strcmp(name, "connection_type"))
|
2008-11-21 11:41:50 +08:00
|
|
|
e->conn_type = val;
|
|
|
|
else if (!strcmp(name, "port_id"))
|
|
|
|
e->port_id = val;
|
|
|
|
else if (!strcmp(name, "support_hdcp"))
|
|
|
|
e->support_hdcp = val;
|
|
|
|
else if (!strcmp(name, "support_ai"))
|
|
|
|
e->support_ai = val;
|
|
|
|
else if (!strcmp(name, "audio_sync_delay"))
|
|
|
|
e->aud_synch_delay = val;
|
|
|
|
else if (!strcmp(name, "speakers"))
|
|
|
|
e->spk_alloc = val;
|
|
|
|
else if (!strcmp(name, "sad_count"))
|
|
|
|
e->sad_count = val;
|
|
|
|
else if (!strncmp(name, "sad", 3)) {
|
|
|
|
sname = name + 4;
|
|
|
|
n = name[3] - '0';
|
|
|
|
if (name[4] >= '0' && name[4] <= '9') {
|
|
|
|
sname++;
|
|
|
|
n = 10 * n + name[4] - '0';
|
|
|
|
}
|
2009-07-29 20:35:20 +08:00
|
|
|
if (n >= ELD_MAX_SAD)
|
2008-11-21 11:41:50 +08:00
|
|
|
continue;
|
|
|
|
if (!strcmp(sname, "_coding_type"))
|
|
|
|
e->sad[n].format = val;
|
|
|
|
else if (!strcmp(sname, "_channels"))
|
|
|
|
e->sad[n].channels = val;
|
|
|
|
else if (!strcmp(sname, "_rates"))
|
|
|
|
e->sad[n].rates = val;
|
|
|
|
else if (!strcmp(sname, "_bits"))
|
|
|
|
e->sad[n].sample_bits = val;
|
|
|
|
else if (!strcmp(sname, "_max_bitrate"))
|
|
|
|
e->sad[n].max_bitrate = val;
|
2008-11-22 09:40:54 +08:00
|
|
|
else if (!strcmp(sname, "_profile"))
|
|
|
|
e->sad[n].profile = val;
|
2008-11-21 11:41:50 +08:00
|
|
|
if (n >= e->sad_count)
|
|
|
|
e->sad_count = n + 1;
|
|
|
|
}
|
|
|
|
}
|
2008-11-21 16:11:50 +08:00
|
|
|
}
|
2015-05-27 19:45:45 +08:00
|
|
|
#endif /* CONFIG_SND_PROC_FS */
|
2010-08-19 14:11:53 +08:00
|
|
|
|
2010-08-13 14:45:23 +08:00
|
|
|
/* update PCM info based on ELD */
|
2013-02-19 23:11:24 +08:00
|
|
|
void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
|
2011-06-02 01:14:20 +08:00
|
|
|
struct hda_pcm_stream *hinfo)
|
2010-08-13 14:45:23 +08:00
|
|
|
{
|
2011-06-02 01:14:20 +08:00
|
|
|
u32 rates;
|
|
|
|
u64 formats;
|
|
|
|
unsigned int maxbps;
|
|
|
|
unsigned int channels_max;
|
2010-08-13 14:45:23 +08:00
|
|
|
int i;
|
|
|
|
|
2010-12-08 02:56:19 +08:00
|
|
|
/* assume basic audio support (the basic audio flag is not in ELD;
|
|
|
|
* however, all audio capable sinks are required to support basic
|
|
|
|
* audio) */
|
2011-06-02 01:14:20 +08:00
|
|
|
rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
|
|
|
|
SNDRV_PCM_RATE_48000;
|
|
|
|
formats = SNDRV_PCM_FMTBIT_S16_LE;
|
|
|
|
maxbps = 16;
|
|
|
|
channels_max = 2;
|
2013-02-19 23:11:24 +08:00
|
|
|
for (i = 0; i < e->sad_count; i++) {
|
|
|
|
struct cea_sad *a = &e->sad[i];
|
2011-06-02 01:14:20 +08:00
|
|
|
rates |= a->rates;
|
|
|
|
if (a->channels > channels_max)
|
|
|
|
channels_max = a->channels;
|
2010-08-13 14:45:23 +08:00
|
|
|
if (a->format == AUDIO_CODING_TYPE_LPCM) {
|
|
|
|
if (a->sample_bits & AC_SUPPCM_BITS_20) {
|
2011-06-02 01:14:20 +08:00
|
|
|
formats |= SNDRV_PCM_FMTBIT_S32_LE;
|
|
|
|
if (maxbps < 20)
|
|
|
|
maxbps = 20;
|
2010-08-13 14:45:23 +08:00
|
|
|
}
|
|
|
|
if (a->sample_bits & AC_SUPPCM_BITS_24) {
|
2011-06-02 01:14:20 +08:00
|
|
|
formats |= SNDRV_PCM_FMTBIT_S32_LE;
|
|
|
|
if (maxbps < 24)
|
|
|
|
maxbps = 24;
|
2010-08-13 14:45:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restrict the parameters by the values the codec provides */
|
2011-06-02 01:14:20 +08:00
|
|
|
hinfo->rates &= rates;
|
|
|
|
hinfo->formats &= formats;
|
|
|
|
hinfo->maxbps = min(hinfo->maxbps, maxbps);
|
|
|
|
hinfo->channels_max = min(hinfo->channels_max, channels_max);
|
2010-08-13 14:45:23 +08:00
|
|
|
}
|
2013-10-25 02:10:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* ATI/AMD specific stuff (ELD emulation) */
|
|
|
|
|
|
|
|
#define ATI_VERB_SET_AUDIO_DESCRIPTOR 0x776
|
|
|
|
#define ATI_VERB_SET_SINK_INFO_INDEX 0x780
|
|
|
|
#define ATI_VERB_GET_SPEAKER_ALLOCATION 0xf70
|
|
|
|
#define ATI_VERB_GET_AUDIO_DESCRIPTOR 0xf76
|
|
|
|
#define ATI_VERB_GET_AUDIO_VIDEO_DELAY 0xf7b
|
|
|
|
#define ATI_VERB_GET_SINK_INFO_INDEX 0xf80
|
|
|
|
#define ATI_VERB_GET_SINK_INFO_DATA 0xf81
|
|
|
|
|
|
|
|
#define ATI_SPKALLOC_SPKALLOC 0x007f
|
|
|
|
#define ATI_SPKALLOC_TYPE_HDMI 0x0100
|
|
|
|
#define ATI_SPKALLOC_TYPE_DISPLAYPORT 0x0200
|
|
|
|
|
|
|
|
/* first three bytes are just standard SAD */
|
|
|
|
#define ATI_AUDIODESC_CHANNELS 0x00000007
|
|
|
|
#define ATI_AUDIODESC_RATES 0x0000ff00
|
|
|
|
#define ATI_AUDIODESC_LPCM_STEREO_RATES 0xff000000
|
|
|
|
|
|
|
|
/* in standard HDMI VSDB format */
|
|
|
|
#define ATI_DELAY_VIDEO_LATENCY 0x000000ff
|
|
|
|
#define ATI_DELAY_AUDIO_LATENCY 0x0000ff00
|
|
|
|
|
|
|
|
enum ati_sink_info_idx {
|
|
|
|
ATI_INFO_IDX_MANUFACTURER_ID = 0,
|
|
|
|
ATI_INFO_IDX_PRODUCT_ID = 1,
|
|
|
|
ATI_INFO_IDX_SINK_DESC_LEN = 2,
|
|
|
|
ATI_INFO_IDX_PORT_ID_LOW = 3,
|
|
|
|
ATI_INFO_IDX_PORT_ID_HIGH = 4,
|
|
|
|
ATI_INFO_IDX_SINK_DESC_FIRST = 5,
|
|
|
|
ATI_INFO_IDX_SINK_DESC_LAST = 22, /* max len 18 bytes */
|
|
|
|
};
|
|
|
|
|
|
|
|
int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
|
|
|
|
unsigned char *buf, int *eld_size, bool rev3_or_later)
|
|
|
|
{
|
|
|
|
int spkalloc, ati_sad, aud_synch;
|
|
|
|
int sink_desc_len = 0;
|
|
|
|
int pos, i;
|
|
|
|
|
|
|
|
/* ATI/AMD does not have ELD, emulate it */
|
|
|
|
|
|
|
|
spkalloc = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SPEAKER_ALLOCATION, 0);
|
|
|
|
|
2013-11-11 02:56:10 +08:00
|
|
|
if (spkalloc <= 0) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI ATI/AMD: no speaker allocation for ELD\n");
|
2013-10-25 02:10:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, ELD_FIXED_BYTES + ELD_MAX_MNL + ELD_MAX_SAD * 3);
|
|
|
|
|
|
|
|
/* version */
|
|
|
|
buf[0] = ELD_VER_CEA_861D << 3;
|
|
|
|
|
|
|
|
/* speaker allocation from EDID */
|
|
|
|
buf[7] = spkalloc & ATI_SPKALLOC_SPKALLOC;
|
|
|
|
|
|
|
|
/* is DisplayPort? */
|
|
|
|
if (spkalloc & ATI_SPKALLOC_TYPE_DISPLAYPORT)
|
|
|
|
buf[5] |= 0x04;
|
|
|
|
|
|
|
|
pos = ELD_FIXED_BYTES;
|
|
|
|
|
|
|
|
if (rev3_or_later) {
|
|
|
|
int sink_info;
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_LOW);
|
|
|
|
sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
put_unaligned_le32(sink_info, buf + 8);
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PORT_ID_HIGH);
|
|
|
|
sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
put_unaligned_le32(sink_info, buf + 12);
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_MANUFACTURER_ID);
|
|
|
|
sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
put_unaligned_le16(sink_info, buf + 16);
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_PRODUCT_ID);
|
|
|
|
sink_info = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
put_unaligned_le16(sink_info, buf + 18);
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_LEN);
|
|
|
|
sink_desc_len = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
|
|
|
|
if (sink_desc_len > ELD_MAX_MNL) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI ATI/AMD: Truncating HDMI sink description with length %d\n",
|
2013-10-25 02:10:36 +08:00
|
|
|
sink_desc_len);
|
|
|
|
sink_desc_len = ELD_MAX_MNL;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[4] |= sink_desc_len;
|
|
|
|
|
|
|
|
for (i = 0; i < sink_desc_len; i++) {
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_SINK_INFO_INDEX, ATI_INFO_IDX_SINK_DESC_FIRST + i);
|
|
|
|
buf[pos++] = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_SINK_INFO_DATA, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = AUDIO_CODING_TYPE_LPCM; i <= AUDIO_CODING_TYPE_WMAPRO; i++) {
|
|
|
|
if (i == AUDIO_CODING_TYPE_SACD || i == AUDIO_CODING_TYPE_DST)
|
|
|
|
continue; /* not handled by ATI/AMD */
|
|
|
|
|
|
|
|
snd_hda_codec_write(codec, nid, 0, ATI_VERB_SET_AUDIO_DESCRIPTOR, i << 3);
|
|
|
|
ati_sad = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_DESCRIPTOR, 0);
|
|
|
|
|
2013-11-11 02:56:10 +08:00
|
|
|
if (ati_sad <= 0)
|
|
|
|
continue;
|
|
|
|
|
2013-10-25 02:10:36 +08:00
|
|
|
if (ati_sad & ATI_AUDIODESC_RATES) {
|
|
|
|
/* format is supported, copy SAD as-is */
|
|
|
|
buf[pos++] = (ati_sad & 0x0000ff) >> 0;
|
|
|
|
buf[pos++] = (ati_sad & 0x00ff00) >> 8;
|
|
|
|
buf[pos++] = (ati_sad & 0xff0000) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == AUDIO_CODING_TYPE_LPCM
|
|
|
|
&& (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES)
|
|
|
|
&& (ati_sad & ATI_AUDIODESC_LPCM_STEREO_RATES) >> 16 != (ati_sad & ATI_AUDIODESC_RATES)) {
|
|
|
|
/* for PCM there is a separate stereo rate mask */
|
|
|
|
buf[pos++] = ((ati_sad & 0x000000ff) & ~ATI_AUDIODESC_CHANNELS) | 0x1;
|
|
|
|
/* rates from the extra byte */
|
|
|
|
buf[pos++] = (ati_sad & 0xff000000) >> 24;
|
|
|
|
buf[pos++] = (ati_sad & 0x00ff0000) >> 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos == ELD_FIXED_BYTES + sink_desc_len) {
|
2014-02-25 19:21:03 +08:00
|
|
|
codec_info(codec, "HDMI ATI/AMD: no audio descriptors for ELD\n");
|
2013-10-25 02:10:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-11-11 02:56:11 +08:00
|
|
|
/*
|
|
|
|
* HDMI VSDB latency format:
|
|
|
|
* separately for both audio and video:
|
|
|
|
* 0 field not valid or unknown latency
|
|
|
|
* [1..251] msecs = (x-1)*2 (max 500ms with x = 251 = 0xfb)
|
|
|
|
* 255 audio/video not supported
|
|
|
|
*
|
|
|
|
* HDA latency format:
|
|
|
|
* single value indicating video latency relative to audio:
|
|
|
|
* 0 unknown or 0ms
|
|
|
|
* [1..250] msecs = x*2 (max 500ms with x = 250 = 0xfa)
|
|
|
|
* [251..255] reserved
|
|
|
|
*/
|
2013-10-25 02:10:36 +08:00
|
|
|
aud_synch = snd_hda_codec_read(codec, nid, 0, ATI_VERB_GET_AUDIO_VIDEO_DELAY, 0);
|
|
|
|
if ((aud_synch & ATI_DELAY_VIDEO_LATENCY) && (aud_synch & ATI_DELAY_AUDIO_LATENCY)) {
|
2013-11-11 02:56:11 +08:00
|
|
|
int video_latency_hdmi = (aud_synch & ATI_DELAY_VIDEO_LATENCY);
|
|
|
|
int audio_latency_hdmi = (aud_synch & ATI_DELAY_AUDIO_LATENCY) >> 8;
|
2013-10-25 02:10:36 +08:00
|
|
|
|
2013-11-11 02:56:11 +08:00
|
|
|
if (video_latency_hdmi <= 0xfb && audio_latency_hdmi <= 0xfb &&
|
|
|
|
video_latency_hdmi > audio_latency_hdmi)
|
|
|
|
buf[6] = video_latency_hdmi - audio_latency_hdmi;
|
|
|
|
/* else unknown/invalid or 0ms or video ahead of audio, so use zero */
|
2013-10-25 02:10:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SAD count */
|
|
|
|
buf[5] |= ((pos - ELD_FIXED_BYTES - sink_desc_len) / 3) << 4;
|
|
|
|
|
2013-11-11 04:57:42 +08:00
|
|
|
/* Baseline ELD block length is 4-byte aligned */
|
|
|
|
pos = round_up(pos, 4);
|
|
|
|
|
|
|
|
/* Baseline ELD length (4-byte header is not counted in) */
|
|
|
|
buf[2] = (pos - 4) / 4;
|
|
|
|
|
2013-10-25 02:10:36 +08:00
|
|
|
*eld_size = pos;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|