Lines Matching +full:tegra124 +full:- +full:hdmi

1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/hdmi.h>
21 #include <sound/hdmi-codec.h>
35 #include "hdmi.h"
68 struct regulator *hdmi; member
114 static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi, in tegra_hdmi_readl() argument
117 u32 value = readl(hdmi->regs + (offset << 2)); in tegra_hdmi_readl()
119 trace_hdmi_readl(hdmi->dev, offset, value); in tegra_hdmi_readl()
124 static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value, in tegra_hdmi_writel() argument
127 trace_hdmi_writel(hdmi->dev, offset, value); in tegra_hdmi_writel()
128 writel(value, hdmi->regs + (offset << 2)); in tegra_hdmi_writel()
374 static void tegra_hdmi_audio_lock(struct tegra_hdmi *hdmi) in tegra_hdmi_audio_lock() argument
376 mutex_lock(&hdmi->audio_lock); in tegra_hdmi_audio_lock()
377 disable_irq(hdmi->irq); in tegra_hdmi_audio_lock()
380 static void tegra_hdmi_audio_unlock(struct tegra_hdmi *hdmi) in tegra_hdmi_audio_unlock() argument
382 enable_irq(hdmi->irq); in tegra_hdmi_audio_unlock()
383 mutex_unlock(&hdmi->audio_lock); in tegra_hdmi_audio_unlock()
394 int64_t min_err = (uint64_t)-1 >> 1; in tegra_hdmi_get_audio_config()
395 unsigned int min_delta = -1; in tegra_hdmi_get_audio_config()
399 config->n = -1; in tegra_hdmi_get_audio_config()
419 delta = abs(n - ideal_n); in tegra_hdmi_get_audio_config()
422 err = abs((int64_t)cts_f - cts); in tegra_hdmi_get_audio_config()
424 config->n = n; in tegra_hdmi_get_audio_config()
425 config->cts = cts >> 16; in tegra_hdmi_get_audio_config()
426 config->aval = aval_f >> 16; in tegra_hdmi_get_audio_config()
432 return config->n != -1 ? 0 : -EINVAL; in tegra_hdmi_get_audio_config()
435 static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio_fs_tables() argument
456 value = AUDIO_FS_LOW(eight_half - delta) | in tegra_hdmi_setup_audio_fs_tables()
458 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i)); in tegra_hdmi_setup_audio_fs_tables()
462 static void tegra_hdmi_write_aval(struct tegra_hdmi *hdmi, u32 value) in tegra_hdmi_write_aval() argument
479 if (regs[i].sample_rate == hdmi->format.sample_rate) { in tegra_hdmi_write_aval()
480 tegra_hdmi_writel(hdmi, value, regs[i].offset); in tegra_hdmi_write_aval()
486 static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio() argument
492 switch (hdmi->audio_source) { in tegra_hdmi_setup_audio()
494 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
497 return -EINVAL; in tegra_hdmi_setup_audio()
502 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
509 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
519 * audio input source for HDMI. The source select field has moved to in tegra_hdmi_setup_audio()
523 if (hdmi->config->has_hda) { in tegra_hdmi_setup_audio()
534 if (hdmi->format.channels == 2) in tegra_hdmi_setup_audio()
541 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0); in tegra_hdmi_setup_audio()
551 if (!hdmi->config->has_hda) in tegra_hdmi_setup_audio()
554 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0); in tegra_hdmi_setup_audio()
557 * Advertise support for High Bit-Rate on Tegra114 and later. in tegra_hdmi_setup_audio()
559 if (hdmi->config->has_hbr) { in tegra_hdmi_setup_audio()
560 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); in tegra_hdmi_setup_audio()
562 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_SPARE0); in tegra_hdmi_setup_audio()
565 err = tegra_hdmi_get_audio_config(hdmi->format.sample_rate, in tegra_hdmi_setup_audio()
566 hdmi->pixel_clock, &config); in tegra_hdmi_setup_audio()
568 dev_err(hdmi->dev, in tegra_hdmi_setup_audio()
570 hdmi->format.sample_rate, hdmi->pixel_clock); in tegra_hdmi_setup_audio()
574 dev_dbg(hdmi->dev, "audio: pixclk=%u, n=%u, cts=%u, aval=%u\n", in tegra_hdmi_setup_audio()
575 hdmi->pixel_clock, config.n, config.cts, config.aval); in tegra_hdmi_setup_audio()
577 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL); in tegra_hdmi_setup_audio()
580 AUDIO_N_VALUE(config.n - 1); in tegra_hdmi_setup_audio()
581 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
583 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config.n) | ACR_ENABLE, in tegra_hdmi_setup_audio()
586 tegra_hdmi_writel(hdmi, ACR_SUBPACK_CTS(config.cts), in tegra_hdmi_setup_audio()
590 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE); in tegra_hdmi_setup_audio()
592 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
594 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N); in tegra_hdmi_setup_audio()
596 if (hdmi->config->has_hda) in tegra_hdmi_setup_audio()
597 tegra_hdmi_write_aval(hdmi, config.aval); in tegra_hdmi_setup_audio()
599 tegra_hdmi_setup_audio_fs_tables(hdmi); in tegra_hdmi_setup_audio()
604 static void tegra_hdmi_disable_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_audio() argument
608 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_audio()
610 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_audio()
613 static void tegra_hdmi_enable_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_audio() argument
617 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_audio()
619 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_audio()
622 static void tegra_hdmi_write_eld(struct tegra_hdmi *hdmi) in tegra_hdmi_write_eld() argument
624 size_t length = drm_eld_size(hdmi->output.connector.eld), i; in tegra_hdmi_write_eld()
628 tegra_hdmi_writel(hdmi, i << 8 | hdmi->output.connector.eld[i], in tegra_hdmi_write_eld()
638 tegra_hdmi_writel(hdmi, i << 8 | 0, in tegra_hdmi_write_eld()
642 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); in tegra_hdmi_write_eld()
650 for (i = size; i > 0; i--) in tegra_hdmi_subpack()
651 value = (value << 8) | ptr[i - 1]; in tegra_hdmi_subpack()
656 static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data, in tegra_hdmi_write_infopack() argument
678 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n", in tegra_hdmi_write_infopack()
686 tegra_hdmi_writel(hdmi, value, offset); in tegra_hdmi_write_infopack()
691 * - subpack_low: bytes 0 - 3 in tegra_hdmi_write_infopack()
692 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00) in tegra_hdmi_write_infopack()
695 size_t rem = size - i, num = min_t(size_t, rem, 4); in tegra_hdmi_write_infopack()
698 tegra_hdmi_writel(hdmi, value, offset++); in tegra_hdmi_write_infopack()
700 num = min_t(size_t, rem - num, 3); in tegra_hdmi_write_infopack()
703 tegra_hdmi_writel(hdmi, value, offset++); in tegra_hdmi_write_infopack()
707 static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi, in tegra_hdmi_setup_avi_infoframe() argument
715 &hdmi->output.connector, mode); in tegra_hdmi_setup_avi_infoframe()
717 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err); in tegra_hdmi_setup_avi_infoframe()
723 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err); in tegra_hdmi_setup_avi_infoframe()
727 tegra_hdmi_write_infopack(hdmi, buffer, err); in tegra_hdmi_setup_avi_infoframe()
730 static void tegra_hdmi_disable_avi_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_avi_infoframe() argument
734 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_disable_avi_infoframe()
736 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_disable_avi_infoframe()
739 static void tegra_hdmi_enable_avi_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_avi_infoframe() argument
743 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_enable_avi_infoframe()
745 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL); in tegra_hdmi_enable_avi_infoframe()
748 static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_audio_infoframe() argument
756 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n", in tegra_hdmi_setup_audio_infoframe()
761 frame.channels = hdmi->format.channels; in tegra_hdmi_setup_audio_infoframe()
765 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n", in tegra_hdmi_setup_audio_infoframe()
776 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err)); in tegra_hdmi_setup_audio_infoframe()
779 static void tegra_hdmi_disable_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_audio_infoframe() argument
783 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_disable_audio_infoframe()
785 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_disable_audio_infoframe()
788 static void tegra_hdmi_enable_audio_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_audio_infoframe() argument
792 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_enable_audio_infoframe()
794 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL); in tegra_hdmi_enable_audio_infoframe()
797 static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_setup_stereo_infoframe() argument
808 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n", in tegra_hdmi_setup_stereo_infoframe()
813 tegra_hdmi_write_infopack(hdmi, buffer, err); in tegra_hdmi_setup_stereo_infoframe()
816 static void tegra_hdmi_disable_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_disable_stereo_infoframe() argument
820 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_stereo_infoframe()
822 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_disable_stereo_infoframe()
825 static void tegra_hdmi_enable_stereo_infoframe(struct tegra_hdmi *hdmi) in tegra_hdmi_enable_stereo_infoframe() argument
829 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_stereo_infoframe()
831 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL); in tegra_hdmi_enable_stereo_infoframe()
834 static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi, in tegra_hdmi_setup_tmds() argument
839 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_setup_tmds()
840 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1); in tegra_hdmi_setup_tmds()
841 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT); in tegra_hdmi_setup_tmds()
843 tegra_hdmi_writel(hdmi, tmds->drive_current, in tegra_hdmi_setup_tmds()
846 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset); in tegra_hdmi_setup_tmds()
847 value |= hdmi->config->fuse_override_value; in tegra_hdmi_setup_tmds()
848 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset); in tegra_hdmi_setup_tmds()
850 if (hdmi->config->has_sor_io_peak_current) in tegra_hdmi_setup_tmds()
851 tegra_hdmi_writel(hdmi, tmds->peak_current, in tegra_hdmi_setup_tmds()
855 static int tegra_hdmi_reconfigure_audio(struct tegra_hdmi *hdmi) in tegra_hdmi_reconfigure_audio() argument
859 err = tegra_hdmi_setup_audio(hdmi); in tegra_hdmi_reconfigure_audio()
861 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
862 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_reconfigure_audio()
864 tegra_hdmi_setup_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
865 tegra_hdmi_enable_audio_infoframe(hdmi); in tegra_hdmi_reconfigure_audio()
866 tegra_hdmi_enable_audio(hdmi); in tegra_hdmi_reconfigure_audio()
874 return output->connector.display_info.is_hdmi; in tegra_output_is_hdmi()
881 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_connector_detect() local
888 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE); in tegra_hdmi_connector_detect()
1063 struct drm_info_node *node = s->private; in tegra_hdmi_show_regs()
1064 struct tegra_hdmi *hdmi = node->info_ent->data; in tegra_hdmi_show_regs() local
1065 struct drm_crtc *crtc = hdmi->output.encoder.crtc; in tegra_hdmi_show_regs()
1066 struct drm_device *drm = node->minor->dev; in tegra_hdmi_show_regs()
1072 if (!crtc || !crtc->state->active) { in tegra_hdmi_show_regs()
1073 err = -EBUSY; in tegra_hdmi_show_regs()
1080 seq_printf(s, "%-56s %#05x %08x\n", tegra_hdmi_regs[i].name, in tegra_hdmi_show_regs()
1081 offset, tegra_hdmi_readl(hdmi, offset)); in tegra_hdmi_show_regs()
1097 struct drm_minor *minor = connector->dev->primary; in tegra_hdmi_late_register()
1098 struct dentry *root = connector->debugfs_entry; in tegra_hdmi_late_register()
1099 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_late_register() local
1101 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), in tegra_hdmi_late_register()
1103 if (!hdmi->debugfs_files) in tegra_hdmi_late_register()
1104 return -ENOMEM; in tegra_hdmi_late_register()
1107 hdmi->debugfs_files[i].data = hdmi; in tegra_hdmi_late_register()
1109 drm_debugfs_create_files(hdmi->debugfs_files, count, root, minor); in tegra_hdmi_late_register()
1117 struct drm_minor *minor = connector->dev->primary; in tegra_hdmi_early_unregister()
1119 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_early_unregister() local
1121 drm_debugfs_remove_files(hdmi->debugfs_files, count, in tegra_hdmi_early_unregister()
1122 connector->debugfs_entry, minor); in tegra_hdmi_early_unregister()
1123 kfree(hdmi->debugfs_files); in tegra_hdmi_early_unregister()
1124 hdmi->debugfs_files = NULL; in tegra_hdmi_early_unregister()
1143 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_connector_mode_valid() local
1144 unsigned long pclk = mode->clock * 1000; in tegra_hdmi_connector_mode_valid()
1149 parent = clk_get_parent(hdmi->clk_parent); in tegra_hdmi_connector_mode_valid()
1167 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_hdmi_encoder_disable()
1168 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_disable() local
1172 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_encoder_disable()
1186 if (!hdmi->dvi) { in tegra_hdmi_encoder_disable()
1187 if (hdmi->stereo) in tegra_hdmi_encoder_disable()
1188 tegra_hdmi_disable_stereo_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1190 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1191 tegra_hdmi_disable_avi_infoframe(hdmi); in tegra_hdmi_encoder_disable()
1192 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_encoder_disable()
1195 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_ENABLE); in tegra_hdmi_encoder_disable()
1196 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_INT_MASK); in tegra_hdmi_encoder_disable()
1198 hdmi->pixel_clock = 0; in tegra_hdmi_encoder_disable()
1200 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_encoder_disable()
1202 err = host1x_client_suspend(&hdmi->client); in tegra_hdmi_encoder_disable()
1204 dev_err(hdmi->dev, "failed to suspend: %d\n", err); in tegra_hdmi_encoder_disable()
1209 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in tegra_hdmi_encoder_enable()
1212 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_hdmi_encoder_enable()
1213 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_enable() local
1219 err = host1x_client_resume(&hdmi->client); in tegra_hdmi_encoder_enable()
1221 dev_err(hdmi->dev, "failed to resume: %d\n", err); in tegra_hdmi_encoder_enable()
1225 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_encoder_enable()
1230 * HDMI driver. in tegra_hdmi_encoder_enable()
1232 tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_ENABLE); in tegra_hdmi_encoder_enable()
1233 tegra_hdmi_writel(hdmi, INT_CODEC_SCRATCH0, HDMI_NV_PDISP_INT_MASK); in tegra_hdmi_encoder_enable()
1235 hdmi->pixel_clock = mode->clock * 1000; in tegra_hdmi_encoder_enable()
1236 h_sync_width = mode->hsync_end - mode->hsync_start; in tegra_hdmi_encoder_enable()
1237 h_back_porch = mode->htotal - mode->hsync_end; in tegra_hdmi_encoder_enable()
1238 h_front_porch = mode->hsync_start - mode->hdisplay; in tegra_hdmi_encoder_enable()
1240 err = dev_pm_opp_set_rate(hdmi->dev, hdmi->pixel_clock); in tegra_hdmi_encoder_enable()
1242 dev_err(hdmi->dev, "failed to set HDMI clock frequency: %d\n", in tegra_hdmi_encoder_enable()
1246 DRM_DEBUG_KMS("HDMI clock rate: %lu Hz\n", clk_get_rate(hdmi->clk)); in tegra_hdmi_encoder_enable()
1249 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1251 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1255 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1257 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0); in tegra_hdmi_encoder_enable()
1265 pulse_start = 1 + h_sync_width + h_back_porch - 10; in tegra_hdmi_encoder_enable()
1278 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW); in tegra_hdmi_encoder_enable()
1280 if (dc->pipe) in tegra_hdmi_encoder_enable()
1285 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) || in tegra_hdmi_encoder_enable()
1286 (mode->vdisplay == 576))) in tegra_hdmi_encoder_enable()
1287 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1291 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1295 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4; in tegra_hdmi_encoder_enable()
1297 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK); in tegra_hdmi_encoder_enable()
1299 hdmi->dvi = !tegra_output_is_hdmi(output); in tegra_hdmi_encoder_enable()
1300 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1305 if (hdmi->format.sample_rate > 0) { in tegra_hdmi_encoder_enable()
1306 err = tegra_hdmi_setup_audio(hdmi); in tegra_hdmi_encoder_enable()
1308 hdmi->dvi = true; in tegra_hdmi_encoder_enable()
1312 if (hdmi->config->has_hda) in tegra_hdmi_encoder_enable()
1313 tegra_hdmi_write_eld(hdmi); in tegra_hdmi_encoder_enable()
1318 h_front_porch - rekey - 18) / 32); in tegra_hdmi_encoder_enable()
1320 if (!hdmi->dvi) in tegra_hdmi_encoder_enable()
1323 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL); in tegra_hdmi_encoder_enable()
1325 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1326 tegra_hdmi_setup_avi_infoframe(hdmi, mode); in tegra_hdmi_encoder_enable()
1327 tegra_hdmi_setup_audio_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1329 if (hdmi->stereo) in tegra_hdmi_encoder_enable()
1330 tegra_hdmi_setup_stereo_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1334 for (i = 0; i < hdmi->config->num_tmds; i++) { in tegra_hdmi_encoder_enable()
1335 if (hdmi->pixel_clock <= hdmi->config->tmds[i].pclk) { in tegra_hdmi_encoder_enable()
1336 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]); in tegra_hdmi_encoder_enable()
1341 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1355 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0)); in tegra_hdmi_encoder_enable()
1356 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8)); in tegra_hdmi_encoder_enable()
1358 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM); in tegra_hdmi_encoder_enable()
1365 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM); in tegra_hdmi_encoder_enable()
1368 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1374 tegra_hdmi_writel(hdmi, in tegra_hdmi_encoder_enable()
1382 BUG_ON(--retries < 0); in tegra_hdmi_encoder_enable()
1383 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR); in tegra_hdmi_encoder_enable()
1393 if (mode->flags & DRM_MODE_FLAG_PHSYNC) in tegra_hdmi_encoder_enable()
1396 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in tegra_hdmi_encoder_enable()
1399 if (mode->flags & DRM_MODE_FLAG_PVSYNC) in tegra_hdmi_encoder_enable()
1402 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in tegra_hdmi_encoder_enable()
1405 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2); in tegra_hdmi_encoder_enable()
1408 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1); in tegra_hdmi_encoder_enable()
1410 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1411 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1412 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED, in tegra_hdmi_encoder_enable()
1414 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0); in tegra_hdmi_encoder_enable()
1422 if (!hdmi->dvi) { in tegra_hdmi_encoder_enable()
1423 tegra_hdmi_enable_avi_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1424 tegra_hdmi_enable_audio_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1425 tegra_hdmi_enable_audio(hdmi); in tegra_hdmi_encoder_enable()
1427 if (hdmi->stereo) in tegra_hdmi_encoder_enable()
1428 tegra_hdmi_enable_stereo_infoframe(hdmi); in tegra_hdmi_encoder_enable()
1433 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_encoder_enable()
1442 struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); in tegra_hdmi_encoder_atomic_check()
1443 unsigned long pclk = crtc_state->mode.clock * 1000; in tegra_hdmi_encoder_atomic_check()
1444 struct tegra_hdmi *hdmi = to_hdmi(output); in tegra_hdmi_encoder_atomic_check() local
1447 err = tegra_dc_state_setup_clock(dc, crtc_state, hdmi->clk_parent, in tegra_hdmi_encoder_atomic_check()
1450 dev_err(output->dev, "failed to setup CRTC state: %d\n", err); in tegra_hdmi_encoder_atomic_check()
1467 struct tegra_hdmi *hdmi = data; in tegra_hdmi_hw_params() local
1470 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_hw_params()
1472 hdmi->format.sample_rate = hparms->sample_rate; in tegra_hdmi_hw_params()
1473 hdmi->format.channels = hparms->channels; in tegra_hdmi_hw_params()
1475 if (hdmi->pixel_clock && !hdmi->dvi) in tegra_hdmi_hw_params()
1476 ret = tegra_hdmi_reconfigure_audio(hdmi); in tegra_hdmi_hw_params()
1478 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_hw_params()
1485 struct tegra_hdmi *hdmi = data; in tegra_hdmi_audio_startup() local
1488 ret = host1x_client_resume(&hdmi->client); in tegra_hdmi_audio_startup()
1490 dev_err(hdmi->dev, "failed to resume: %d\n", ret); in tegra_hdmi_audio_startup()
1497 struct tegra_hdmi *hdmi = data; in tegra_hdmi_audio_shutdown() local
1500 tegra_hdmi_audio_lock(hdmi); in tegra_hdmi_audio_shutdown()
1502 hdmi->format.sample_rate = 0; in tegra_hdmi_audio_shutdown()
1503 hdmi->format.channels = 0; in tegra_hdmi_audio_shutdown()
1505 tegra_hdmi_audio_unlock(hdmi); in tegra_hdmi_audio_shutdown()
1507 ret = host1x_client_suspend(&hdmi->client); in tegra_hdmi_audio_shutdown()
1509 dev_err(hdmi->dev, "failed to suspend: %d\n", ret); in tegra_hdmi_audio_shutdown()
1518 static int tegra_hdmi_codec_register(struct tegra_hdmi *hdmi) in tegra_hdmi_codec_register() argument
1522 if (hdmi->config->has_hda) in tegra_hdmi_codec_register()
1526 codec_data.data = hdmi; in tegra_hdmi_codec_register()
1529 hdmi->audio_pdev = platform_device_register_data(hdmi->dev, in tegra_hdmi_codec_register()
1534 if (IS_ERR(hdmi->audio_pdev)) in tegra_hdmi_codec_register()
1535 return PTR_ERR(hdmi->audio_pdev); in tegra_hdmi_codec_register()
1537 hdmi->format.channels = 2; in tegra_hdmi_codec_register()
1542 static void tegra_hdmi_codec_unregister(struct tegra_hdmi *hdmi) in tegra_hdmi_codec_unregister() argument
1544 if (hdmi->audio_pdev) in tegra_hdmi_codec_unregister()
1545 platform_device_unregister(hdmi->audio_pdev); in tegra_hdmi_codec_unregister()
1550 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_init() local
1551 struct drm_device *drm = dev_get_drvdata(client->host); in tegra_hdmi_init()
1555 hdmi->output.dev = client->dev; in tegra_hdmi_init()
1557 drm_simple_encoder_init(drm, &hdmi->output.encoder, in tegra_hdmi_init()
1559 drm_encoder_helper_add(&hdmi->output.encoder, in tegra_hdmi_init()
1562 if (hdmi->output.bridge) { in tegra_hdmi_init()
1563 err = drm_bridge_attach(&hdmi->output.encoder, hdmi->output.bridge, in tegra_hdmi_init()
1566 dev_err(client->dev, "failed to attach bridge: %d\n", in tegra_hdmi_init()
1571 connector = drm_bridge_connector_init(drm, &hdmi->output.encoder); in tegra_hdmi_init()
1573 dev_err(client->dev, in tegra_hdmi_init()
1579 drm_connector_attach_encoder(connector, &hdmi->output.encoder); in tegra_hdmi_init()
1581 drm_connector_init_with_ddc(drm, &hdmi->output.connector, in tegra_hdmi_init()
1584 hdmi->output.ddc); in tegra_hdmi_init()
1585 drm_connector_helper_add(&hdmi->output.connector, in tegra_hdmi_init()
1587 hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF; in tegra_hdmi_init()
1589 drm_connector_attach_encoder(&hdmi->output.connector, in tegra_hdmi_init()
1590 &hdmi->output.encoder); in tegra_hdmi_init()
1591 drm_connector_register(&hdmi->output.connector); in tegra_hdmi_init()
1594 err = tegra_output_init(drm, &hdmi->output); in tegra_hdmi_init()
1596 dev_err(client->dev, "failed to initialize output: %d\n", err); in tegra_hdmi_init()
1600 hdmi->output.encoder.possible_crtcs = 0x3; in tegra_hdmi_init()
1602 err = regulator_enable(hdmi->hdmi); in tegra_hdmi_init()
1604 dev_err(client->dev, "failed to enable HDMI regulator: %d\n", in tegra_hdmi_init()
1609 err = regulator_enable(hdmi->pll); in tegra_hdmi_init()
1611 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err); in tegra_hdmi_init()
1615 err = regulator_enable(hdmi->vdd); in tegra_hdmi_init()
1617 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err); in tegra_hdmi_init()
1621 err = tegra_hdmi_codec_register(hdmi); in tegra_hdmi_init()
1623 dev_err(hdmi->dev, "failed to register audio codec: %d\n", err); in tegra_hdmi_init()
1630 regulator_disable(hdmi->vdd); in tegra_hdmi_init()
1632 regulator_disable(hdmi->pll); in tegra_hdmi_init()
1634 regulator_disable(hdmi->hdmi); in tegra_hdmi_init()
1636 tegra_output_exit(&hdmi->output); in tegra_hdmi_init()
1643 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_exit() local
1645 tegra_hdmi_codec_unregister(hdmi); in tegra_hdmi_exit()
1647 tegra_output_exit(&hdmi->output); in tegra_hdmi_exit()
1649 regulator_disable(hdmi->vdd); in tegra_hdmi_exit()
1650 regulator_disable(hdmi->pll); in tegra_hdmi_exit()
1651 regulator_disable(hdmi->hdmi); in tegra_hdmi_exit()
1658 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_runtime_suspend() local
1659 struct device *dev = client->dev; in tegra_hdmi_runtime_suspend()
1662 err = reset_control_assert(hdmi->rst); in tegra_hdmi_runtime_suspend()
1670 clk_disable_unprepare(hdmi->clk); in tegra_hdmi_runtime_suspend()
1678 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client); in tegra_hdmi_runtime_resume() local
1679 struct device *dev = client->dev; in tegra_hdmi_runtime_resume()
1688 err = clk_prepare_enable(hdmi->clk); in tegra_hdmi_runtime_resume()
1696 err = reset_control_deassert(hdmi->rst); in tegra_hdmi_runtime_resume()
1705 clk_disable_unprepare(hdmi->clk); in tegra_hdmi_runtime_resume()
1759 { .compatible = "nvidia,tegra124-hdmi", .data = &tegra124_hdmi_config },
1760 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
1761 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1762 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1769 struct tegra_hdmi *hdmi = data; in tegra_hdmi_irq() local
1772 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_INT_STATUS); in tegra_hdmi_irq()
1773 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_INT_STATUS); in tegra_hdmi_irq()
1779 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_AUDIO_HDA_CODEC_SCRATCH0); in tegra_hdmi_irq()
1784 tegra_hda_parse_format(format, &hdmi->format); in tegra_hdmi_irq()
1785 tegra_hdmi_reconfigure_audio(hdmi); in tegra_hdmi_irq()
1787 tegra_hdmi_disable_audio_infoframe(hdmi); in tegra_hdmi_irq()
1788 tegra_hdmi_disable_audio(hdmi); in tegra_hdmi_irq()
1797 struct tegra_hdmi *hdmi; in tegra_hdmi_probe() local
1800 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); in tegra_hdmi_probe()
1801 if (!hdmi) in tegra_hdmi_probe()
1802 return -ENOMEM; in tegra_hdmi_probe()
1804 hdmi->config = of_device_get_match_data(&pdev->dev); in tegra_hdmi_probe()
1805 hdmi->dev = &pdev->dev; in tegra_hdmi_probe()
1807 hdmi->audio_source = AUTO; in tegra_hdmi_probe()
1808 hdmi->stereo = false; in tegra_hdmi_probe()
1809 hdmi->dvi = false; in tegra_hdmi_probe()
1811 mutex_init(&hdmi->audio_lock); in tegra_hdmi_probe()
1813 hdmi->clk = devm_clk_get(&pdev->dev, NULL); in tegra_hdmi_probe()
1814 if (IS_ERR(hdmi->clk)) { in tegra_hdmi_probe()
1815 dev_err(&pdev->dev, "failed to get clock\n"); in tegra_hdmi_probe()
1816 return PTR_ERR(hdmi->clk); in tegra_hdmi_probe()
1819 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi"); in tegra_hdmi_probe()
1820 if (IS_ERR(hdmi->rst)) { in tegra_hdmi_probe()
1821 dev_err(&pdev->dev, "failed to get reset\n"); in tegra_hdmi_probe()
1822 return PTR_ERR(hdmi->rst); in tegra_hdmi_probe()
1825 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent"); in tegra_hdmi_probe()
1826 if (IS_ERR(hdmi->clk_parent)) in tegra_hdmi_probe()
1827 return PTR_ERR(hdmi->clk_parent); in tegra_hdmi_probe()
1829 err = clk_set_parent(hdmi->clk, hdmi->clk_parent); in tegra_hdmi_probe()
1831 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err); in tegra_hdmi_probe()
1835 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi"); in tegra_hdmi_probe()
1836 err = PTR_ERR_OR_ZERO(hdmi->hdmi); in tegra_hdmi_probe()
1838 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1839 "failed to get HDMI regulator\n"); in tegra_hdmi_probe()
1841 hdmi->pll = devm_regulator_get(&pdev->dev, "pll"); in tegra_hdmi_probe()
1842 err = PTR_ERR_OR_ZERO(hdmi->pll); in tegra_hdmi_probe()
1844 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1847 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd"); in tegra_hdmi_probe()
1848 err = PTR_ERR_OR_ZERO(hdmi->vdd); in tegra_hdmi_probe()
1850 return dev_err_probe(&pdev->dev, err, in tegra_hdmi_probe()
1853 hdmi->output.dev = &pdev->dev; in tegra_hdmi_probe()
1855 err = tegra_output_probe(&hdmi->output); in tegra_hdmi_probe()
1859 hdmi->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_hdmi_probe()
1860 if (IS_ERR(hdmi->regs)) { in tegra_hdmi_probe()
1861 err = PTR_ERR(hdmi->regs); in tegra_hdmi_probe()
1869 hdmi->irq = err; in tegra_hdmi_probe()
1871 err = devm_request_irq(hdmi->dev, hdmi->irq, tegra_hdmi_irq, 0, in tegra_hdmi_probe()
1872 dev_name(hdmi->dev), hdmi); in tegra_hdmi_probe()
1874 dev_err(&pdev->dev, "failed to request IRQ#%u: %d\n", in tegra_hdmi_probe()
1875 hdmi->irq, err); in tegra_hdmi_probe()
1879 platform_set_drvdata(pdev, hdmi); in tegra_hdmi_probe()
1881 err = devm_pm_runtime_enable(&pdev->dev); in tegra_hdmi_probe()
1885 err = devm_tegra_core_dev_init_opp_table_common(&pdev->dev); in tegra_hdmi_probe()
1889 INIT_LIST_HEAD(&hdmi->client.list); in tegra_hdmi_probe()
1890 hdmi->client.ops = &hdmi_client_ops; in tegra_hdmi_probe()
1891 hdmi->client.dev = &pdev->dev; in tegra_hdmi_probe()
1893 err = host1x_client_register(&hdmi->client); in tegra_hdmi_probe()
1895 dev_err(&pdev->dev, "failed to register host1x client: %d\n", in tegra_hdmi_probe()
1903 tegra_output_remove(&hdmi->output); in tegra_hdmi_probe()
1909 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev); in tegra_hdmi_remove() local
1911 host1x_client_unregister(&hdmi->client); in tegra_hdmi_remove()
1913 tegra_output_remove(&hdmi->output); in tegra_hdmi_remove()
1918 .name = "tegra-hdmi",