Lines Matching +full:hdmi +full:- +full:connector
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/hdmi.h>
21 #include <sound/hdmi-codec.h>
33 #include "hdmi.h"
66 struct regulator *hdmi; member
112 static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi, in tegra_hdmi_readl() argument
115 u32 value = readl(hdmi->regs + (offset << 2)); in tegra_hdmi_readl()
117 trace_hdmi_readl(hdmi->dev, offset, value); in tegra_hdmi_readl()
122 static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value, in tegra_hdmi_writel() argument
125 trace_hdmi_writel(hdmi->dev, offset, value); in tegra_hdmi_writel()
126 writel(value, hdmi->regs + (offset << 2)); in tegra_hdmi_writel()
372 static void tegra_hdmi_audio_lock(struct tegra_hdmi *hdmi) in tegra_hdmi_audio_lock() argument
374 mutex_lock(&hdmi->audio_lock); in tegra_hdmi_audio_lock()
375 disable_irq(hdmi->irq); in tegra_hdmi_audio_lock()
378 static void tegra_hdmi_audio_unlock(struct tegra_hdmi *hdmi) in tegra_hdmi_audio_unlock() argument
380 enable_irq(hdmi->irq); in tegra_hdmi_audio_unlock()
381 mutex_unlock(&hdmi->audio_lock); in tegra_hdmi_audio_unlock()
392 int64_t min_err = (uint64_t)-1 >> 1; in tegra_hdmi_get_audio_config()
393 unsigned int min_delta = -1; in tegra_hdmi_get_audio_config()
397 config->n = -1; in tegra_hdmi_get_audio_config()
417 delta = abs(n - ideal_n); in tegra_hdmi_get_audio_config()
420 err = abs((int64_t)cts_f - cts); in tegra_hdmi_get_audio_config()
422 config->n = n; in tegra_hdmi_get_audio_config()
423 config->cts = cts >> 16; in tegra_hdmi_get_audio_config()
424 config->aval = aval_f >> 16; in tegra_hdmi_get_audio_config()
430 return config->n != -1 ? 0 : -EINVAL; in tegra_hdmi_get_audio_config()
433 static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio_fs_tables() argument
454 value = AUDIO_FS_LOW(eight_half - delta) | in tegra_hdmi_setup_audio_fs_tables()
456 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i)); in tegra_hdmi_setup_audio_fs_tables()
460 static void tegra_hdmi_write_aval(struct tegra_hdmi *hdmi, u32 value) in tegra_hdmi_write_aval() argument
477 if (regs[i].sample_rate == hdmi->format.sample_rate) { in tegra_hdmi_write_aval()
478 tegra_hdmi_writel(hdmi, value, regs[i].offset); in tegra_hdmi_write_aval()
484 static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio() argument
490 switch (hdmi->audio_source) { in tegra_hdmi_setup_audio()
492 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
495 return -EINVAL; in tegra_hdmi_setup_audio()
500 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
507 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
517 * audio input source for HDMI. The source select field has moved to in tegra_hdmi_setup_audio()
521 if (hdmi->config->has_hda) { in tegra_hdmi_setup_audio()
532 if (hdmi->format.channels == 2) in tegra_hdmi_setup_audio()
539 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0); in tegra_hdmi_setup_audio()
549 if (!hdmi->config->has_hda) in tegra_hdmi_setup_audio()
552 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0); in tegra_hdmi_setup_audio()
555 * Advertise support for High Bit-Rate on Tegra114 and later. in tegra_hdmi_setup_audio()
557 if (hdmi->config->has_hbr) { in tegra_hdmi_setup_audio()
558 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); in tegra_hdmi_setup_audio()
560 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); in tegra_hdmi_setup_audio()
563 err = tegra_hdmi_get_audio_config(hdmi->format.sample_rate, in tegra_hdmi_setup_audio()
564 hdmi->pixel_clock, &config); in tegra_hdmi_setup_audio()
566 dev_err(hdmi->dev, in tegra_hdmi_setup_audio()
568 hdmi->format.sample_rate, hdmi->pixel_clock); in tegra_hdmi_setup_audio()
572 dev_dbg(hdmi->dev, "audio: pixclk=%u, n=%u, cts=%u, aval=%u\n", in tegra_hdmi_setup_audio()
573 hdmi->pixel_clock, config.n, config.cts, config.aval); in tegra_hdmi_setup_audio()
575 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL); in tegra_hdmi_setup_audio()
578 AUDIO_N_VALUE(config.n - 1); in tegra_hdmi_setup_audio()
579 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
581 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config.n) | ACR_ENABLE, in tegra_hdmi_setup_audio()
584 tegra_hdmi_writel(hdmi, ACR_SUBPACK_CTS(config.cts), in tegra_hdmi_setup_audio()
588 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE); in tegra_hdmi_setup_audio()
590 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
592 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
594 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
595 tegra_hdmi_write_aval(hdmi, config.aval); in tegra_hdmi_setup_audio()
597 tegra_hdmi_setup_audio_fs_tables(hdmi); in tegra_hdmi_setup_audio()
602 static void tegra_hdmi_disable_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_audio() argument
606 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_audio()
608 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_audio()
611 static void tegra_hdmi_enable_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_audio() argument
615 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_audio()
617 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_audio()
620 static void tegra_hdmi_write_eld(struct tegra_hdmi *hdmi) in tegra_hdmi_write_eld() argument
622 size_t length = drm_eld_size(hdmi->output.connector.eld), i; in tegra_hdmi_write_eld()
626 tegra_hdmi_writel(hdmi, i << 8 | hdmi->output.connector.eld[i], in tegra_hdmi_write_eld()
636 tegra_hdmi_writel(hdmi, i << 8 | 0, in tegra_hdmi_write_eld()
640 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); in tegra_hdmi_write_eld()
648 for (i = size; i > 0; i--) in tegra_hdmi_subpack()
649 value = (value << 8) | ptr[i - 1]; in tegra_hdmi_subpack()
654 static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data, in tegra_hdmi_write_infopack() argument
676 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n", in tegra_hdmi_write_infopack()
684 tegra_hdmi_writel(hdmi, value, offset); in tegra_hdmi_write_infopack()
689 * - subpack_low: bytes 0 - 3 in tegra_hdmi_write_infopack()
690 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) in tegra_hdmi_write_infopack()
693 size_t rem = size - i, num = min_t(size_t, rem, 4); in tegra_hdmi_write_infopack()
696 tegra_hdmi_writel(hdmi, value, offset++); in tegra_hdmi_write_infopack()
698 num = min_t(size_t, rem - num, 3); in tegra_hdmi_write_infopack()
701 tegra_hdmi_writel(hdmi, value, offset++); in tegra_hdmi_write_infopack()
705 static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi, in tegra_hdmi_setup_avi_infoframe() argument
713 &hdmi->output.connector, mode); in tegra_hdmi_setup_avi_infoframe()
715 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err); in tegra_hdmi_setup_avi_infoframe()
721 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err); in tegra_hdmi_setup_avi_infoframe()
725 tegra_hdmi_write_infopack(hdmi, buffer, err); in tegra_hdmi_setup_avi_infoframe()
728 static void tegra_hdmi_disable_avi_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_avi_infoframe() argument
732 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_disable_avi_infoframe()
734 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_disable_avi_infoframe()
737 static void tegra_hdmi_enable_avi_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_avi_infoframe() argument
741 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_enable_avi_infoframe()
743 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_enable_avi_infoframe()
746 static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio_infoframe() argument
754 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n", in tegra_hdmi_setup_audio_infoframe()
759 frame.channels = hdmi->format.channels; in tegra_hdmi_setup_audio_infoframe()
763 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n", in tegra_hdmi_setup_audio_infoframe()
774 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err)); in tegra_hdmi_setup_audio_infoframe()
777 static void tegra_hdmi_disable_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_audio_infoframe() argument
781 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_disable_audio_infoframe()
783 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_disable_audio_infoframe()
786 static void tegra_hdmi_enable_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_audio_infoframe() argument
790 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_enable_audio_infoframe()
792 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_enable_audio_infoframe()
795 static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_stereo_infoframe() argument
806 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n", in tegra_hdmi_setup_stereo_infoframe()
811 tegra_hdmi_write_infopack(hdmi, buffer, err); in tegra_hdmi_setup_stereo_infoframe()
814 static void tegra_hdmi_disable_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_stereo_infoframe() argument
818 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_stereo_infoframe()
820 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_stereo_infoframe()
823 static void tegra_hdmi_enable_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_stereo_infoframe() argument
827 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_stereo_infoframe()
829 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_stereo_infoframe()
832 static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi, in tegra_hdmi_setup_tmds() argument
837 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_setup_tmds()
838 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1); in tegra_hdmi_setup_tmds()
839 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT); in tegra_hdmi_setup_tmds()
841 tegra_hdmi_writel(hdmi, tmds->drive_current, in tegra_hdmi_setup_tmds()
844 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset); in tegra_hdmi_setup_tmds()
845 value |= hdmi->config->fuse_override_value; in tegra_hdmi_setup_tmds()
846 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset); in tegra_hdmi_setup_tmds()
848 if (hdmi->config->has_sor_io_peak_current) in tegra_hdmi_setup_tmds()
849 tegra_hdmi_writel(hdmi, tmds->peak_current, in tegra_hdmi_setup_tmds()
853 static int tegra_hdmi_reconfigure_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_reconfigure_audio() argument
857 err = tegra_hdmi_setup_audio(hdmi); in tegra_hdmi_reconfigure_audio()
859 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
860 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_reconfigure_audio()
862 tegra_hdmi_setup_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
863 tegra_hdmi_enable_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
864 tegra_hdmi_enable_audio(hdmi); in tegra_hdmi_reconfigure_audio()
872 return output->connector.display_info.is_hdmi; in tegra_output_is_hdmi()
876 tegra_hdmi_connector_detect(struct drm_connector *connector, bool force) in tegra_hdmi_connector_detect() argument
878 struct tegra_output *output = connector_to_output(connector); in tegra_hdmi_connector_detect()
879 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_connector_detect() local
882 status = tegra_output_connector_detect(connector, force); in tegra_hdmi_connector_detect()
886 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); in tegra_hdmi_connector_detect()
1061 struct drm_info_node *node = s->private; in tegra_hdmi_show_regs()
1062 struct tegra_hdmi *hdmi = node->info_ent->data; in tegra_hdmi_show_regs() local
1063 struct drm_crtc *crtc = hdmi->output.encoder.crtc; in tegra_hdmi_show_regs()
1064 struct drm_device *drm = node->minor->dev; in tegra_hdmi_show_regs()
1070 if (!crtc || !crtc->state->active) { in tegra_hdmi_show_regs()
1071 err = -EBUSY; in tegra_hdmi_show_regs()
1078 seq_printf(s, "%-56s %#05x %08x\n", tegra_hdmi_regs[i].name, in tegra_hdmi_show_regs()
1079 offset, tegra_hdmi_readl(hdmi, offset)); in tegra_hdmi_show_regs()
1091 static int tegra_hdmi_late_register(struct drm_connector *connector) in tegra_hdmi_late_register() argument
1093 struct tegra_output *output = connector_to_output(connector); in tegra_hdmi_late_register()
1095 struct drm_minor *minor = connector->dev->primary; in tegra_hdmi_late_register()
1096 struct dentry *root = connector->debugfs_entry; in tegra_hdmi_late_register()
1097 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_late_register() local
1099 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), in tegra_hdmi_late_register()
1101 if (!hdmi->debugfs_files) in tegra_hdmi_late_register()
1102 return -ENOMEM; in tegra_hdmi_late_register()
1105 hdmi->debugfs_files[i].data = hdmi; in tegra_hdmi_late_register()
1107 drm_debugfs_create_files(hdmi->debugfs_files, count, root, minor); in tegra_hdmi_late_register()
1112 static void tegra_hdmi_early_unregister(struct drm_connector *connector) in tegra_hdmi_early_unregister() argument
1114 struct tegra_output *output = connector_to_output(connector); in tegra_hdmi_early_unregister()
1115 struct drm_minor *minor = connector->dev->primary; in tegra_hdmi_early_unregister()
1117 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_early_unregister() local
1119 drm_debugfs_remove_files(hdmi->debugfs_files, count, minor); in tegra_hdmi_early_unregister()
1120 kfree(hdmi->debugfs_files); in tegra_hdmi_early_unregister()
1121 hdmi->debugfs_files = NULL; in tegra_hdmi_early_unregister()
1136 tegra_hdmi_connector_mode_valid(struct drm_connector *connector, in tegra_hdmi_connector_mode_valid() argument
1139 struct tegra_output *output = connector_to_output(connector); in tegra_hdmi_connector_mode_valid()
1140 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_connector_mode_valid() local
1141 unsigned long pclk = mode->clock * 1000; in tegra_hdmi_connector_mode_valid()
1146 parent = clk_get_parent(hdmi->clk_parent); in tegra_hdmi_connector_mode_valid()
1164 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_hdmi_encoder_disable()
1165 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_disable() local
1169 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_encoder_disable()
1183 if (!hdmi->dvi) { in tegra_hdmi_encoder_disable()
1184 if (hdmi->stereo) in tegra_hdmi_encoder_disable()
1185 tegra_hdmi_disable_stereo_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1187 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1188 tegra_hdmi_disable_avi_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1189 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_encoder_disable()
1192 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_ENABLE); in tegra_hdmi_encoder_disable()
1193 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_MASK); in tegra_hdmi_encoder_disable()
1195 hdmi->pixel_clock = 0; in tegra_hdmi_encoder_disable()
1197 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_encoder_disable()
1199 err = host1x_client_suspend(&hdmi->client); in tegra_hdmi_encoder_disable()
1201 dev_err(hdmi->dev, "failed to suspend: %d\n", err); in tegra_hdmi_encoder_disable()
1206 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in tegra_hdmi_encoder_enable()
1209 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_hdmi_encoder_enable()
1210 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_enable() local
1216 err = host1x_client_resume(&hdmi->client); in tegra_hdmi_encoder_enable()
1218 dev_err(hdmi->dev, "failed to resume: %d\n", err); in tegra_hdmi_encoder_enable()
1222 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_encoder_enable()
1227 * HDMI driver. in tegra_hdmi_encoder_enable()
1229 tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_ENABLE); in tegra_hdmi_encoder_enable()
1230 tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_MASK); in tegra_hdmi_encoder_enable()
1232 hdmi->pixel_clock = mode->clock * 1000; in tegra_hdmi_encoder_enable()
1233 h_sync_width = mode->hsync_end - mode->hsync_start; in tegra_hdmi_encoder_enable()
1234 h_back_porch = mode->htotal - mode->hsync_end; in tegra_hdmi_encoder_enable()
1235 h_front_porch = mode->hsync_start - mode->hdisplay; in tegra_hdmi_encoder_enable()
1237 err = dev_pm_opp_set_rate(hdmi->dev, hdmi->pixel_clock); in tegra_hdmi_encoder_enable()
1239 dev_err(hdmi->dev, "failed to set HDMI clock frequency: %d\n", in tegra_hdmi_encoder_enable()
1243 DRM_DEBUG_KMS("HDMI clock rate: %lu Hz\n", clk_get_rate(hdmi->clk)); in tegra_hdmi_encoder_enable()
1246 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1248 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1252 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1254 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1262 pulse_start = 1 + h_sync_width + h_back_porch - 10; in tegra_hdmi_encoder_enable()
1275 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW); in tegra_hdmi_encoder_enable()
1277 if (dc->pipe) in tegra_hdmi_encoder_enable()
1282 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) || in tegra_hdmi_encoder_enable()
1283 (mode->vdisplay == 576))) in tegra_hdmi_encoder_enable()
1284 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1288 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1292 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4; in tegra_hdmi_encoder_enable()
1294 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK); in tegra_hdmi_encoder_enable()
1296 hdmi->dvi = !tegra_output_is_hdmi(output); in tegra_hdmi_encoder_enable()
1297 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1302 if (hdmi->format.sample_rate > 0) { in tegra_hdmi_encoder_enable()
1303 err = tegra_hdmi_setup_audio(hdmi); in tegra_hdmi_encoder_enable()
1305 hdmi->dvi = true; in tegra_hdmi_encoder_enable()
1309 if (hdmi->config->has_hda) in tegra_hdmi_encoder_enable()
1310 tegra_hdmi_write_eld(hdmi); in tegra_hdmi_encoder_enable()
1315 h_front_porch - rekey - 18) / 32); in tegra_hdmi_encoder_enable()
1317 if (!hdmi->dvi) in tegra_hdmi_encoder_enable()
1320 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL); in tegra_hdmi_encoder_enable()
1322 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1323 tegra_hdmi_setup_avi_infoframe(hdmi, mode); in tegra_hdmi_encoder_enable()
1324 tegra_hdmi_setup_audio_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1326 if (hdmi->stereo) in tegra_hdmi_encoder_enable()
1327 tegra_hdmi_setup_stereo_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1331 for (i = 0; i < hdmi->config->num_tmds; i++) { in tegra_hdmi_encoder_enable()
1332 if (hdmi->pixel_clock <= hdmi->config->tmds[i].pclk) { in tegra_hdmi_encoder_enable()
1333 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]); in tegra_hdmi_encoder_enable()
1338 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1352 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0)); in tegra_hdmi_encoder_enable()
1353 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8)); in tegra_hdmi_encoder_enable()
1355 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM); in tegra_hdmi_encoder_enable()
1362 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM); in tegra_hdmi_encoder_enable()
1365 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1371 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1379 BUG_ON(--retries < 0); in tegra_hdmi_encoder_enable()
1380 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR); in tegra_hdmi_encoder_enable()
1390 if (mode->flags & DRM_MODE_FLAG_PHSYNC) in tegra_hdmi_encoder_enable()
1393 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in tegra_hdmi_encoder_enable()
1396 if (mode->flags & DRM_MODE_FLAG_PVSYNC) in tegra_hdmi_encoder_enable()
1399 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in tegra_hdmi_encoder_enable()
1402 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2); in tegra_hdmi_encoder_enable()
1405 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1); in tegra_hdmi_encoder_enable()
1407 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1408 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1409 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED, in tegra_hdmi_encoder_enable()
1411 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1419 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1420 tegra_hdmi_enable_avi_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1421 tegra_hdmi_enable_audio_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1422 tegra_hdmi_enable_audio(hdmi); in tegra_hdmi_encoder_enable()
1424 if (hdmi->stereo) in tegra_hdmi_encoder_enable()
1425 tegra_hdmi_enable_stereo_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1430 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_encoder_enable()
1439 struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); in tegra_hdmi_encoder_atomic_check()
1440 unsigned long pclk = crtc_state->mode.clock * 1000; in tegra_hdmi_encoder_atomic_check()
1441 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_atomic_check() local
1444 err = tegra_dc_state_setup_clock(dc, crtc_state, hdmi->clk_parent, in tegra_hdmi_encoder_atomic_check()
1447 dev_err(output->dev, "failed to setup CRTC state: %d\n", err); in tegra_hdmi_encoder_atomic_check()
1464 struct tegra_hdmi *hdmi = data; in tegra_hdmi_hw_params() local
1467 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_hw_params()
1469 hdmi->format.sample_rate = hparms->sample_rate; in tegra_hdmi_hw_params()
1470 hdmi->format.channels = hparms->channels; in tegra_hdmi_hw_params()
1472 if (hdmi->pixel_clock && !hdmi->dvi) in tegra_hdmi_hw_params()
1473 ret = tegra_hdmi_reconfigure_audio(hdmi); in tegra_hdmi_hw_params()
1475 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_hw_params()
1482 struct tegra_hdmi *hdmi = data; in tegra_hdmi_audio_startup() local
1485 ret = host1x_client_resume(&hdmi->client); in tegra_hdmi_audio_startup()
1487 dev_err(hdmi->dev, "failed to resume: %d\n", ret); in tegra_hdmi_audio_startup()
1494 struct tegra_hdmi *hdmi = data; in tegra_hdmi_audio_shutdown() local
1497 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_audio_shutdown()
1499 hdmi->format.sample_rate = 0; in tegra_hdmi_audio_shutdown()
1500 hdmi->format.channels = 0; in tegra_hdmi_audio_shutdown()
1502 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_audio_shutdown()
1504 ret = host1x_client_suspend(&hdmi->client); in tegra_hdmi_audio_shutdown()
1506 dev_err(hdmi->dev, "failed to suspend: %d\n", ret); in tegra_hdmi_audio_shutdown()
1515 static int tegra_hdmi_codec_register(struct tegra_hdmi *hdmi) in tegra_hdmi_codec_register() argument
1519 if (hdmi->config->has_hda) in tegra_hdmi_codec_register()
1523 codec_data.data = hdmi; in tegra_hdmi_codec_register()
1526 hdmi->audio_pdev = platform_device_register_data(hdmi->dev, in tegra_hdmi_codec_register()
1531 if (IS_ERR(hdmi->audio_pdev)) in tegra_hdmi_codec_register()
1532 return PTR_ERR(hdmi->audio_pdev); in tegra_hdmi_codec_register()
1534 hdmi->format.channels = 2; in tegra_hdmi_codec_register()
1539 static void tegra_hdmi_codec_unregister(struct tegra_hdmi *hdmi) in tegra_hdmi_codec_unregister() argument
1541 if (hdmi->audio_pdev) in tegra_hdmi_codec_unregister()
1542 platform_device_unregister(hdmi->audio_pdev); in tegra_hdmi_codec_unregister()
1547 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_init() local
1548 struct drm_device *drm = dev_get_drvdata(client->host); in tegra_hdmi_init()
1549 struct drm_connector *connector; in tegra_hdmi_init() local
1552 hdmi->output.dev = client->dev; in tegra_hdmi_init()
1554 drm_simple_encoder_init(drm, &hdmi->output.encoder, in tegra_hdmi_init()
1556 drm_encoder_helper_add(&hdmi->output.encoder, in tegra_hdmi_init()
1559 if (hdmi->output.bridge) { in tegra_hdmi_init()
1560 err = drm_bridge_attach(&hdmi->output.encoder, hdmi->output.bridge, in tegra_hdmi_init()
1563 dev_err(client->dev, "failed to attach bridge: %d\n", in tegra_hdmi_init()
1568 connector = drm_bridge_connector_init(drm, &hdmi->output.encoder); in tegra_hdmi_init()
1569 if (IS_ERR(connector)) { in tegra_hdmi_init()
1570 dev_err(client->dev, in tegra_hdmi_init()
1571 "failed to initialize bridge connector: %pe\n", in tegra_hdmi_init()
1572 connector); in tegra_hdmi_init()
1573 return PTR_ERR(connector); in tegra_hdmi_init()
1576 drm_connector_attach_encoder(connector, &hdmi->output.encoder); in tegra_hdmi_init()
1578 drm_connector_init_with_ddc(drm, &hdmi->output.connector, in tegra_hdmi_init()
1581 hdmi->output.ddc); in tegra_hdmi_init()
1582 drm_connector_helper_add(&hdmi->output.connector, in tegra_hdmi_init()
1584 hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF; in tegra_hdmi_init()
1586 drm_connector_attach_encoder(&hdmi->output.connector, in tegra_hdmi_init()
1587 &hdmi->output.encoder); in tegra_hdmi_init()
1588 drm_connector_register(&hdmi->output.connector); in tegra_hdmi_init()
1591 err = tegra_output_init(drm, &hdmi->output); in tegra_hdmi_init()
1593 dev_err(client->dev, "failed to initialize output: %d\n", err); in tegra_hdmi_init()
1597 hdmi->output.encoder.possible_crtcs = 0x3; in tegra_hdmi_init()
1599 err = regulator_enable(hdmi->hdmi); in tegra_hdmi_init()
1601 dev_err(client->dev, "failed to enable HDMI regulator: %d\n", in tegra_hdmi_init()
1606 err = regulator_enable(hdmi->pll); in tegra_hdmi_init()
1608 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err); in tegra_hdmi_init()
1612 err = regulator_enable(hdmi->vdd); in tegra_hdmi_init()
1614 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err); in tegra_hdmi_init()
1618 err = tegra_hdmi_codec_register(hdmi); in tegra_hdmi_init()
1620 dev_err(hdmi->dev, "failed to register audio codec: %d\n", err); in tegra_hdmi_init()
1627 regulator_disable(hdmi->vdd); in tegra_hdmi_init()
1629 regulator_disable(hdmi->pll); in tegra_hdmi_init()
1631 regulator_disable(hdmi->hdmi); in tegra_hdmi_init()
1633 tegra_output_exit(&hdmi->output); in tegra_hdmi_init()
1640 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_exit() local
1642 tegra_hdmi_codec_unregister(hdmi); in tegra_hdmi_exit()
1644 tegra_output_exit(&hdmi->output); in tegra_hdmi_exit()
1646 regulator_disable(hdmi->vdd); in tegra_hdmi_exit()
1647 regulator_disable(hdmi->pll); in tegra_hdmi_exit()
1648 regulator_disable(hdmi->hdmi); in tegra_hdmi_exit()
1655 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_runtime_suspend() local
1656 struct device *dev = client->dev; in tegra_hdmi_runtime_suspend()
1659 err = reset_control_assert(hdmi->rst); in tegra_hdmi_runtime_suspend()
1667 clk_disable_unprepare(hdmi->clk); in tegra_hdmi_runtime_suspend()
1675 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_runtime_resume() local
1676 struct device *dev = client->dev; in tegra_hdmi_runtime_resume()
1685 err = clk_prepare_enable(hdmi->clk); in tegra_hdmi_runtime_resume()
1693 err = reset_control_deassert(hdmi->rst); in tegra_hdmi_runtime_resume()
1702 clk_disable_unprepare(hdmi->clk); in tegra_hdmi_runtime_resume()
1756 { .compatible = "nvidia,tegra124-hdmi", .data = &tegra124_hdmi_config },
1757 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
1758 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1759 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1766 struct tegra_hdmi *hdmi = data; in tegra_hdmi_irq() local
1769 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_INT_STATUS); in tegra_hdmi_irq()
1770 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_INT_STATUS); in tegra_hdmi_irq()
1776 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_HDA_CODEC_SCRATCH0); in tegra_hdmi_irq()
1781 tegra_hda_parse_format(format, &hdmi->format); in tegra_hdmi_irq()
1782 tegra_hdmi_reconfigure_audio(hdmi); in tegra_hdmi_irq()
1784 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_irq()
1785 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_irq()
1794 struct tegra_hdmi *hdmi; in tegra_hdmi_probe() local
1797 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); in tegra_hdmi_probe()
1798 if (!hdmi) in tegra_hdmi_probe()
1799 return -ENOMEM; in tegra_hdmi_probe()
1801 hdmi->config = of_device_get_match_data(&pdev->dev); in tegra_hdmi_probe()
1802 hdmi->dev = &pdev->dev; in tegra_hdmi_probe()
1804 hdmi->audio_source = AUTO; in tegra_hdmi_probe()
1805 hdmi->stereo = false; in tegra_hdmi_probe()
1806 hdmi->dvi = false; in tegra_hdmi_probe()
1808 mutex_init(&hdmi->audio_lock); in tegra_hdmi_probe()
1810 hdmi->clk = devm_clk_get(&pdev->dev, NULL); in tegra_hdmi_probe()
1811 if (IS_ERR(hdmi->clk)) { in tegra_hdmi_probe()
1812 dev_err(&pdev->dev, "failed to get clock\n"); in tegra_hdmi_probe()
1813 return PTR_ERR(hdmi->clk); in tegra_hdmi_probe()
1816 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi"); in tegra_hdmi_probe()
1817 if (IS_ERR(hdmi->rst)) { in tegra_hdmi_probe()
1818 dev_err(&pdev->dev, "failed to get reset\n"); in tegra_hdmi_probe()
1819 return PTR_ERR(hdmi->rst); in tegra_hdmi_probe()
1822 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent"); in tegra_hdmi_probe()
1823 if (IS_ERR(hdmi->clk_parent)) in tegra_hdmi_probe()
1824 return PTR_ERR(hdmi->clk_parent); in tegra_hdmi_probe()
1826 err = clk_set_parent(hdmi->clk, hdmi->clk_parent); in tegra_hdmi_probe()
1828 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err); in tegra_hdmi_probe()
1832 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi"); in tegra_hdmi_probe()
1833 err = PTR_ERR_OR_ZERO(hdmi->hdmi); in tegra_hdmi_probe()
1835 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1836 "failed to get HDMI regulator\n"); in tegra_hdmi_probe()
1838 hdmi->pll = devm_regulator_get(&pdev->dev, "pll"); in tegra_hdmi_probe()
1839 err = PTR_ERR_OR_ZERO(hdmi->pll); in tegra_hdmi_probe()
1841 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1844 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd"); in tegra_hdmi_probe()
1845 err = PTR_ERR_OR_ZERO(hdmi->vdd); in tegra_hdmi_probe()
1847 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1850 hdmi->output.dev = &pdev->dev; in tegra_hdmi_probe()
1852 err = tegra_output_probe(&hdmi->output); in tegra_hdmi_probe()
1856 hdmi->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_hdmi_probe()
1857 if (IS_ERR(hdmi->regs)) { in tegra_hdmi_probe()
1858 err = PTR_ERR(hdmi->regs); in tegra_hdmi_probe()
1866 hdmi->irq = err; in tegra_hdmi_probe()
1868 err = devm_request_irq(hdmi->dev, hdmi->irq, tegra_hdmi_irq, 0, in tegra_hdmi_probe()
1869 dev_name(hdmi->dev), hdmi); in tegra_hdmi_probe()
1871 dev_err(&pdev->dev, "failed to request IRQ#%u: %d\n", in tegra_hdmi_probe()
1872 hdmi->irq, err); in tegra_hdmi_probe()
1876 platform_set_drvdata(pdev, hdmi); in tegra_hdmi_probe()
1878 err = devm_pm_runtime_enable(&pdev->dev); in tegra_hdmi_probe()
1882 err = devm_tegra_core_dev_init_opp_table_common(&pdev->dev); in tegra_hdmi_probe()
1886 INIT_LIST_HEAD(&hdmi->client.list); in tegra_hdmi_probe()
1887 hdmi->client.ops = &hdmi_client_ops; in tegra_hdmi_probe()
1888 hdmi->client.dev = &pdev->dev; in tegra_hdmi_probe()
1890 err = host1x_client_register(&hdmi->client); in tegra_hdmi_probe()
1892 dev_err(&pdev->dev, "failed to register host1x client: %d\n", in tegra_hdmi_probe()
1900 tegra_output_remove(&hdmi->output); in tegra_hdmi_probe()
1906 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev); in tegra_hdmi_remove() local
1908 host1x_client_unregister(&hdmi->client); in tegra_hdmi_remove()
1910 tegra_output_remove(&hdmi->output); in tegra_hdmi_remove()
1915 .name = "tegra-hdmi",