drivers/gpu/drm/mediatek/mtk_hdmi_common.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/mediatek/mtk_hdmi_common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/mediatek/mtk_hdmi_common.c- Extension
.c- Size
- 12924 bytes
- Lines
- 459
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
drm/drm_modes.hlinux/device.hlinux/hdmi.hlinux/i2c.hlinux/math.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/mfd/syscon.hsound/hdmi-codec.hmtk_hdmi_common.h
Detected Declarations
struct hdmi_acr_nfunction hdmi_recommended_nfunction hdmi_mode_clock_to_hzfunction hdmi_expected_ctsfunction mtk_hdmi_get_nctsfunction mtk_hdmi_audio_paramsfunction mtk_hdmi_audio_get_eldfunction mtk_hdmi_audio_set_plugged_cbfunction mtk_hdmi_get_all_clkfunction mtk_hdmi_bridge_mode_fixupfunction mtk_hdmi_bridge_mode_setfunction mtk_hdmi_put_devicefunction mtk_hdmi_get_cec_devfunction mtk_hdmi_dt_parse_pdatafunction mtk_hdmi_unregister_audio_driverfunction mtk_hdmi_register_audio_driver
Annotated Snippet
struct hdmi_acr_n {
unsigned int clock;
unsigned int n[3];
};
/* Recommended N values from HDMI specification, tables 7-1 to 7-3 */
static const struct hdmi_acr_n hdmi_rec_n_table[] = {
/* Clock, N: 32kHz 44.1kHz 48kHz */
{ 25175, { 4576, 7007, 6864 } },
{ 74176, { 11648, 17836, 11648 } },
{ 148352, { 11648, 8918, 5824 } },
{ 296703, { 5824, 4459, 5824 } },
{ 297000, { 3072, 4704, 5120 } },
{ 0, { 4096, 6272, 6144 } }, /* all other TMDS clocks */
};
/**
* hdmi_recommended_n() - Return N value recommended by HDMI specification
* @freq: audio sample rate in Hz
* @clock: rounded TMDS clock in kHz
*/
static unsigned int hdmi_recommended_n(unsigned int freq, unsigned int clock)
{
const struct hdmi_acr_n *recommended;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) {
if (clock == hdmi_rec_n_table[i].clock)
break;
}
recommended = hdmi_rec_n_table + i;
switch (freq) {
case 32000:
return recommended->n[0];
case 44100:
return recommended->n[1];
case 48000:
return recommended->n[2];
case 88200:
return recommended->n[1] * 2;
case 96000:
return recommended->n[2] * 2;
case 176400:
return recommended->n[1] * 4;
case 192000:
return recommended->n[2] * 4;
default:
return (128 * freq) / 1000;
}
}
static unsigned int hdmi_mode_clock_to_hz(unsigned int clock)
{
switch (clock) {
case 25175:
return 25174825; /* 25.2/1.001 MHz */
case 74176:
return 74175824; /* 74.25/1.001 MHz */
case 148352:
return 148351648; /* 148.5/1.001 MHz */
case 296703:
return 296703297; /* 297/1.001 MHz */
default:
return clock * 1000;
}
}
static unsigned int hdmi_expected_cts(unsigned int audio_sample_rate,
unsigned int tmds_clock, unsigned int n)
{
return DIV_ROUND_CLOSEST_ULL((u64)hdmi_mode_clock_to_hz(tmds_clock) * n,
128 * audio_sample_rate);
}
void mtk_hdmi_get_ncts(unsigned int sample_rate, unsigned int clock,
unsigned int *n, unsigned int *cts)
{
*n = hdmi_recommended_n(sample_rate, clock);
*cts = hdmi_expected_cts(sample_rate, clock, *n);
}
EXPORT_SYMBOL_NS_GPL(mtk_hdmi_get_ncts, "DRM_MTK_HDMI");
int mtk_hdmi_audio_params(struct mtk_hdmi *hdmi,
struct hdmi_codec_daifmt *daifmt,
struct hdmi_codec_params *params)
{
struct hdmi_audio_param aud_params = { 0 };
unsigned int chan = params->cea.channels;
Annotation
- Immediate include surface: `drm/drm_modes.h`, `linux/device.h`, `linux/hdmi.h`, `linux/i2c.h`, `linux/math.h`, `linux/of.h`, `linux/of_platform.h`, `linux/platform_device.h`.
- Detected declarations: `struct hdmi_acr_n`, `function hdmi_recommended_n`, `function hdmi_mode_clock_to_hz`, `function hdmi_expected_cts`, `function mtk_hdmi_get_ncts`, `function mtk_hdmi_audio_params`, `function mtk_hdmi_audio_get_eld`, `function mtk_hdmi_audio_set_plugged_cb`, `function mtk_hdmi_get_all_clk`, `function mtk_hdmi_bridge_mode_fixup`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.