25 #include <linux/slab.h>
27 #include <asm/unaligned.h>
44 static char *cea_speaker_allocation_names[] = {
58 static char *eld_connection_type_names[4] = {
96 static char *cea_audio_coding_type_names[] = {
106 "DSD (One Bit Audio)",
107 "E-AC-3/DD+ (Dolby Digital Plus)",
109 "MLP (Dolby TrueHD)",
126 static int cea_sample_sizes[4] = {
136 static int cea_sampling_frequencies[8] = {
160 #define GRAB_BITS(buf, byte, lowbit, bits) \
162 BUILD_BUG_ON(lowbit > 7); \
163 BUILD_BUG_ON(bits > 8); \
164 BUILD_BUG_ON(bits <= 0); \
166 (buf[byte] >> (lowbit)) & ((1 << (bits)) - 1); \
169 static void hdmi_update_short_audio_desc(
struct cea_sad *
a,
170 const unsigned char *
buf)
177 for (i = 0; i < 7; i++)
179 a->
rates |= cea_sampling_frequencies[i + 1];
191 "HDMI: audio coding type 0 not expected\n");
196 for (i = 0; i < 3; i++)
236 "HDMI: audio coding xtype %d not expected\n",
249 static int hdmi_update_eld(
struct hdmi_eld *
e,
250 const unsigned char *
buf,
int size)
296 hdmi_update_short_audio_desc(e->
sad + i,
348 for (i = 0; i <
size; i++) {
349 unsigned int val = hdmi_get_eld_data(codec, nid, i);
356 "HDMI: invalid ELD data byte %d\n", i);
375 ret = hdmi_update_eld(eld, buf, size);
385 static void hdmi_print_pcm_rates(
int pcm,
char *buf,
int buflen)
387 static unsigned int alsa_rates[] = {
388 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
389 88200, 96000, 176400, 192000, 384000
393 for (i = 0, j = 0; i <
ARRAY_SIZE(alsa_rates); i++)
395 j +=
snprintf(buf + j, buflen - j,
" %d",
401 #define SND_PRINT_RATES_ADVISED_BUFSIZE 80
403 static void hdmi_show_short_audio_desc(
struct cea_sad *
a)
411 hdmi_print_pcm_rates(a->
rates, buf,
sizeof(buf));
422 " channels = %d, rates =%s%s\n",
423 cea_audio_coding_type_names[a->
format],
433 for (i = 0, j = 0; i <
ARRAY_SIZE(cea_speaker_allocation_names); i++) {
434 if (spk_alloc & (1 << i))
435 j +=
snprintf(buf + j, buflen - j,
" %s",
436 cea_speaker_allocation_names[i]);
447 eld_connection_type_names[e->
conn_type]);
456 hdmi_show_short_audio_desc(e->
sad + i);
459 #ifdef CONFIG_PROC_FS
461 static void hdmi_print_sad_info(
int i,
struct cea_sad *
a,
466 snd_iprintf(buffer,
"sad%d_coding_type\t[0x%x] %s\n",
468 snd_iprintf(buffer,
"sad%d_channels\t\t%d\n", i, a->
channels);
470 hdmi_print_pcm_rates(a->
rates, buf,
sizeof(buf));
471 snd_iprintf(buffer,
"sad%d_rates\t\t[0x%x]%s\n", i, a->
rates, buf);
475 snd_iprintf(buffer,
"sad%d_bits\t\t[0x%x]%s\n",
480 snd_iprintf(buffer,
"sad%d_max_bitrate\t%d\n",
484 snd_iprintf(buffer,
"sad%d_profile\t\t%d\n", i, a->
profile);
493 static char *eld_versoin_names[32] = {
497 [3 ... 30] =
"reserved",
500 static char *cea_edid_version_names[8] = {
501 "no CEA EDID Timing Extension block present",
505 [4 ... 7] =
"reserved"
509 snd_iprintf(buffer,
"eld_valid\t\t%d\n", e->
eld_valid);
512 snd_iprintf(buffer,
"monitor_name\t\t%s\n", e->
monitor_name);
513 snd_iprintf(buffer,
"connection_type\t\t%s\n",
514 eld_connection_type_names[e->
conn_type]);
515 snd_iprintf(buffer,
"eld_version\t\t[0x%x] %s\n", e->
eld_ver,
516 eld_versoin_names[e->
eld_ver]);
517 snd_iprintf(buffer,
"edid_version\t\t[0x%x] %s\n", e->
cea_edid_ver,
519 snd_iprintf(buffer,
"manufacture_id\t\t0x%x\n", e->
manufacture_id);
520 snd_iprintf(buffer,
"product_id\t\t0x%x\n", e->
product_id);
521 snd_iprintf(buffer,
"port_id\t\t\t0x%llx\n", (
long long)e->
port_id);
522 snd_iprintf(buffer,
"support_hdcp\t\t%d\n", e->
support_hdcp);
523 snd_iprintf(buffer,
"support_ai\t\t%d\n", e->
support_ai);
527 snd_iprintf(buffer,
"speakers\t\t[0x%x]%s\n", e->
spk_alloc, buf);
529 snd_iprintf(buffer,
"sad_count\t\t%d\n", e->
sad_count);
532 hdmi_print_sad_info(i, e->
sad + i, buffer);
545 while (!snd_info_get_line(buffer, line,
sizeof(line))) {
546 if (
sscanf(line,
"%s %llx", name, &val) != 2)
553 if (!
strcmp(name,
"monitor_present"))
555 else if (!
strcmp(name,
"eld_valid"))
557 else if (!
strcmp(name,
"connection_type"))
559 else if (!
strcmp(name,
"port_id"))
561 else if (!
strcmp(name,
"support_hdcp"))
563 else if (!
strcmp(name,
"support_ai"))
565 else if (!
strcmp(name,
"audio_sync_delay"))
567 else if (!
strcmp(name,
"speakers"))
569 else if (!
strcmp(name,
"sad_count"))
571 else if (!
strncmp(name,
"sad", 3)) {
574 if (name[4] >=
'0' && name[4] <=
'9') {
576 n = 10 * n + name[4] -
'0';
580 if (!
strcmp(sname,
"_coding_type"))
582 else if (!
strcmp(sname,
"_channels"))
584 else if (!
strcmp(sname,
"_rates"))
586 else if (!
strcmp(sname,
"_bits"))
588 else if (!
strcmp(sname,
"_max_bitrate"))
590 else if (!
strcmp(sname,
"_profile"))
606 snprintf(name,
sizeof(name),
"eld#%d.%d", codec->
addr, index);
607 err = snd_card_proc_new(codec->
bus->card, name, &entry);
611 snd_info_set_text_ops(entry, eld, hdmi_print_eld_info);
612 entry->
c.
text.write = hdmi_write_eld_info;
614 eld->proc_entry =
entry;
621 if (!codec->
bus->shutdown && eld->proc_entry) {
623 eld->proc_entry =
NULL;
636 unsigned int channels_max;