2 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #define pr_fmt(fmt) "sde-hdmi:[%s] " fmt, __func__
21 #include <linux/list.h>
23 #include <linux/gpio.h>
24 #include <linux/of_irq.h>
25 #include <linux/of_platform.h>
26 #include <linux/irqdomain.h>
29 #include "sde_connector.h"
32 #include "sde_hdmi_regs.h"
35 static DEFINE_MUTEX(sde_hdmi_list_lock);
36 static LIST_HEAD(sde_hdmi_list);
38 /* HDMI SCDC register offsets */
39 #define HDMI_SCDC_UPDATE_0 0x10
40 #define HDMI_SCDC_UPDATE_1 0x11
41 #define HDMI_SCDC_TMDS_CONFIG 0x20
42 #define HDMI_SCDC_SCRAMBLER_STATUS 0x21
43 #define HDMI_SCDC_CONFIG_0 0x30
44 #define HDMI_SCDC_STATUS_FLAGS_0 0x40
45 #define HDMI_SCDC_STATUS_FLAGS_1 0x41
46 #define HDMI_SCDC_ERR_DET_0_L 0x50
47 #define HDMI_SCDC_ERR_DET_0_H 0x51
48 #define HDMI_SCDC_ERR_DET_1_L 0x52
49 #define HDMI_SCDC_ERR_DET_1_H 0x53
50 #define HDMI_SCDC_ERR_DET_2_L 0x54
51 #define HDMI_SCDC_ERR_DET_2_H 0x55
52 #define HDMI_SCDC_ERR_DET_CHECKSUM 0x56
54 #define HDMI_DISPLAY_MAX_WIDTH 4096
55 #define HDMI_DISPLAY_MAX_HEIGHT 2160
57 static const struct of_device_id sde_hdmi_dt_match[] = {
58 {.compatible = "qcom,hdmi-display"},
62 static ssize_t _sde_hdmi_debugfs_dump_info_read(struct file *file,
67 struct sde_hdmi *display = file->private_data;
77 buf = kzalloc(SZ_1K, GFP_KERNEL);
81 len += snprintf(buf, SZ_4K, "name = %s\n", display->name);
83 if (copy_to_user(buff, buf, len)) {
94 static ssize_t _sde_hdmi_debugfs_edid_modes_read(struct file *file,
99 struct sde_hdmi *display = file->private_data;
102 struct drm_connector *connector;
104 struct drm_display_mode *mode;
109 if (!display->ctrl.ctrl ||
110 !display->ctrl.ctrl->connector) {
111 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
119 connector = display->ctrl.ctrl->connector;
121 list_for_each_entry(mode, &connector->modes, head) {
125 /* Adding one more to store title */
128 buf = kzalloc((mode_count * sizeof(*mode)), GFP_KERNEL);
132 len += snprintf(buf + len, PAGE_SIZE - len,
133 "name refresh (Hz) hdisp hss hse htot vdisp");
135 len += snprintf(buf + len, PAGE_SIZE - len,
136 " vss vse vtot flags\n");
138 list_for_each_entry(mode, &connector->modes, head) {
139 len += snprintf(buf + len, SZ_4K - len,
140 "%s %d %d %d %d %d %d %d %d %d 0x%x\n",
141 mode->name, mode->vrefresh, mode->hdisplay,
142 mode->hsync_start, mode->hsync_end, mode->htotal,
143 mode->vdisplay, mode->vsync_start, mode->vsync_end,
144 mode->vtotal, mode->flags);
147 if (copy_to_user(buff, buf, len)) {
158 static ssize_t _sde_hdmi_debugfs_edid_vsdb_info_read(struct file *file,
163 struct sde_hdmi *display = file->private_data;
166 struct drm_connector *connector;
171 if (!display->ctrl.ctrl ||
172 !display->ctrl.ctrl->connector) {
173 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
178 SDE_HDMI_DEBUG("%s +", __func__);
182 connector = display->ctrl.ctrl->connector;
183 len += snprintf(buf + len, sizeof(buf) - len,
184 "max_tmds_clock = %d\n",
185 connector->max_tmds_clock);
186 len += snprintf(buf + len, sizeof(buf) - len,
187 "latency_present %d %d\n",
188 connector->latency_present[0],
189 connector->latency_present[1]);
190 len += snprintf(buf + len, sizeof(buf) - len,
191 "video_latency %d %d\n",
192 connector->video_latency[0],
193 connector->video_latency[1]);
194 len += snprintf(buf + len, sizeof(buf) - len,
195 "audio_latency %d %d\n",
196 connector->audio_latency[0],
197 connector->audio_latency[1]);
198 len += snprintf(buf + len, sizeof(buf) - len,
200 (int)connector->dvi_dual);
202 if (copy_to_user(buff, buf, len))
206 SDE_HDMI_DEBUG("%s - ", __func__);
210 static ssize_t _sde_hdmi_debugfs_edid_hdr_info_read(struct file *file,
215 struct sde_hdmi *display = file->private_data;
218 struct drm_connector *connector;
223 if (!display->ctrl.ctrl ||
224 !display->ctrl.ctrl->connector) {
225 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
230 SDE_HDMI_DEBUG("%s +", __func__);
234 connector = display->ctrl.ctrl->connector;
235 len += snprintf(buf, sizeof(buf), "hdr_eotf = %d\n"
236 "hdr_metadata_type_one %d\n"
237 "hdr_max_luminance %d\n"
238 "hdr_avg_luminance %d\n"
239 "hdr_min_luminance %d\n"
240 "hdr_supported %d\n",
242 connector->hdr_metadata_type_one,
243 connector->hdr_max_luminance,
244 connector->hdr_avg_luminance,
245 connector->hdr_min_luminance,
246 (int)connector->hdr_supported);
248 if (copy_to_user(buff, buf, len))
252 SDE_HDMI_DEBUG("%s - ", __func__);
256 static ssize_t _sde_hdmi_debugfs_edid_hfvsdb_info_read(struct file *file,
261 struct sde_hdmi *display = file->private_data;
264 struct drm_connector *connector;
269 if (!display->ctrl.ctrl ||
270 !display->ctrl.ctrl->connector) {
271 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
276 SDE_HDMI_DEBUG("%s +", __func__);
280 connector = display->ctrl.ctrl->connector;
281 len += snprintf(buf, PAGE_SIZE - len, "max_tmds_char = %d\n"
284 "supports_scramble %d\n"
286 connector->max_tmds_char,
287 (int)connector->scdc_present,
288 (int)connector->rr_capable,
289 (int)connector->supports_scramble,
290 connector->flags_3d);
292 if (copy_to_user(buff, buf, len))
299 static ssize_t _sde_hdmi_debugfs_edid_vcdb_info_read(struct file *file,
304 struct sde_hdmi *display = file->private_data;
307 struct drm_connector *connector;
312 if (!display->ctrl.ctrl ||
313 !display->ctrl.ctrl->connector) {
314 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
319 SDE_HDMI_DEBUG("%s +", __func__);
323 connector = display->ctrl.ctrl->connector;
324 len += snprintf(buf, PAGE_SIZE - len, "pt_scan_info = %d\n"
325 "it_scan_info = %d\n"
326 "ce_scan_info = %d\n",
327 (int)connector->pt_scan_info,
328 (int)connector->it_scan_info,
329 (int)connector->ce_scan_info);
331 if (copy_to_user(buff, buf, len))
335 SDE_HDMI_DEBUG("%s - ", __func__);
339 static ssize_t _sde_hdmi_edid_vendor_name_read(struct file *file,
344 struct sde_hdmi *display = file->private_data;
347 struct drm_connector *connector;
352 if (!display->ctrl.ctrl ||
353 !display->ctrl.ctrl->connector) {
354 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
359 SDE_HDMI_DEBUG("%s +", __func__);
363 connector = display->ctrl.ctrl->connector;
364 len += snprintf(buf, PAGE_SIZE - len, "Vendor ID is %s\n",
365 display->edid_ctrl->vendor_id);
367 if (copy_to_user(buff, buf, len))
371 SDE_HDMI_DEBUG("%s - ", __func__);
375 static ssize_t _sde_hdmi_src_hdcp14_support_read(struct file *file,
380 struct sde_hdmi *display = file->private_data;
387 if (!display->ctrl.ctrl) {
388 SDE_ERROR("hdmi is NULL\n");
392 SDE_HDMI_DEBUG("%s +", __func__);
396 if (display->hdcp14_present)
397 len += snprintf(buf, SZ_128 - len, "true\n");
399 len += snprintf(buf, SZ_128 - len, "false\n");
401 if (copy_to_user(buff, buf, len))
405 SDE_HDMI_DEBUG("%s - ", __func__);
409 static ssize_t _sde_hdmi_src_hdcp22_support_read(struct file *file,
414 struct sde_hdmi *display = file->private_data;
421 if (!display->ctrl.ctrl) {
422 SDE_ERROR("hdmi is NULL\n");
426 SDE_HDMI_DEBUG("%s +", __func__);
430 if (display->src_hdcp22_support)
431 len += snprintf(buf, SZ_128 - len, "true\n");
433 len += snprintf(buf, SZ_128 - len, "false\n");
435 if (copy_to_user(buff, buf, len))
439 SDE_HDMI_DEBUG("%s - ", __func__);
443 static ssize_t _sde_hdmi_sink_hdcp22_support_read(struct file *file,
448 struct sde_hdmi *display = file->private_data;
455 if (!display->ctrl.ctrl) {
456 SDE_ERROR("hdmi is NULL\n");
460 SDE_HDMI_DEBUG("%s +", __func__);
464 if (display->sink_hdcp22_support)
465 len += snprintf(buf, SZ_128 - len, "true\n");
467 len += snprintf(buf, SZ_128 - len, "false\n");
469 if (copy_to_user(buff, buf, len))
473 SDE_HDMI_DEBUG("%s - ", __func__);
477 static ssize_t _sde_hdmi_hdcp_state_read(struct file *file,
482 struct sde_hdmi *display = file->private_data;
489 SDE_HDMI_DEBUG("%s +", __func__);
493 len += snprintf(buf, SZ_128 - len, "HDCP state : %s\n",
494 sde_hdcp_state_name(display->hdcp_status));
496 if (copy_to_user(buff, buf, len))
500 SDE_HDMI_DEBUG("%s - ", __func__);
504 static const struct file_operations dump_info_fops = {
506 .read = _sde_hdmi_debugfs_dump_info_read,
509 static const struct file_operations edid_modes_fops = {
511 .read = _sde_hdmi_debugfs_edid_modes_read,
514 static const struct file_operations edid_vsdb_info_fops = {
516 .read = _sde_hdmi_debugfs_edid_vsdb_info_read,
519 static const struct file_operations edid_hdr_info_fops = {
521 .read = _sde_hdmi_debugfs_edid_hdr_info_read,
524 static const struct file_operations edid_hfvsdb_info_fops = {
526 .read = _sde_hdmi_debugfs_edid_hfvsdb_info_read,
529 static const struct file_operations edid_vcdb_info_fops = {
531 .read = _sde_hdmi_debugfs_edid_vcdb_info_read,
534 static const struct file_operations edid_vendor_name_fops = {
536 .read = _sde_hdmi_edid_vendor_name_read,
539 static const struct file_operations hdcp_src_14_support_fops = {
541 .read = _sde_hdmi_src_hdcp14_support_read,
544 static const struct file_operations hdcp_src_22_support_fops = {
546 .read = _sde_hdmi_src_hdcp22_support_read,
549 static const struct file_operations hdcp_sink_22_support_fops = {
551 .read = _sde_hdmi_sink_hdcp22_support_read,
554 static const struct file_operations sde_hdmi_hdcp_state_fops = {
556 .read = _sde_hdmi_hdcp_state_read,
559 static u64 _sde_hdmi_clip_valid_pclk(struct hdmi *hdmi, u64 pclk_in)
561 u32 pclk_delta, pclk;
562 u64 pclk_clip = pclk_in;
564 /* as per standard, 0.5% of deviation is allowed */
565 pclk = hdmi->pixclock;
566 pclk_delta = pclk * 5 / 1000;
568 if (pclk_in < (pclk - pclk_delta))
569 pclk_clip = pclk - pclk_delta;
570 else if (pclk_in > (pclk + pclk_delta))
571 pclk_clip = pclk + pclk_delta;
573 if (pclk_in != pclk_clip)
574 pr_warn("clip pclk from %lld to %lld\n", pclk_in, pclk_clip);
579 static void sde_hdmi_tx_hdcp_cb(void *ptr, enum sde_hdcp_states status)
581 struct sde_hdmi *hdmi_ctrl = (struct sde_hdmi *)ptr;
585 DEV_ERR("%s: invalid input\n", __func__);
589 hdmi = hdmi_ctrl->ctrl.ctrl;
590 hdmi_ctrl->hdcp_status = status;
591 queue_delayed_work(hdmi->workq, &hdmi_ctrl->hdcp_cb_work, HZ/4);
594 void sde_hdmi_hdcp_off(struct sde_hdmi *hdmi_ctrl)
598 SDE_ERROR("%s: invalid input\n", __func__);
602 if (hdmi_ctrl->hdcp_ops)
603 hdmi_ctrl->hdcp_ops->off(hdmi_ctrl->hdcp_data);
605 flush_delayed_work(&hdmi_ctrl->hdcp_cb_work);
607 hdmi_ctrl->hdcp_ops = NULL;
610 static void sde_hdmi_tx_hdcp_cb_work(struct work_struct *work)
612 struct sde_hdmi *hdmi_ctrl = NULL;
613 struct delayed_work *dw = to_delayed_work(work);
617 hdmi_ctrl = container_of(dw, struct sde_hdmi, hdcp_cb_work);
619 DEV_DBG("%s: invalid input\n", __func__);
623 hdmi = hdmi_ctrl->ctrl.ctrl;
625 switch (hdmi_ctrl->hdcp_status) {
626 case HDCP_STATE_AUTHENTICATED:
627 hdmi_ctrl->auth_state = true;
629 if (sde_hdmi_tx_is_panel_on(hdmi_ctrl) &&
630 sde_hdmi_tx_is_stream_shareable(hdmi_ctrl)) {
631 rc = sde_hdmi_config_avmute(hdmi, false);
634 if (hdmi_ctrl->hdcp1_use_sw_keys &&
635 hdmi_ctrl->hdcp14_present) {
636 if (!hdmi_ctrl->hdcp22_present)
640 case HDCP_STATE_AUTH_FAIL:
641 if (hdmi_ctrl->hdcp1_use_sw_keys && hdmi_ctrl->hdcp14_present) {
642 if (hdmi_ctrl->auth_state && !hdmi_ctrl->hdcp22_present)
643 hdcp1_set_enc(false);
646 hdmi_ctrl->auth_state = false;
648 if (sde_hdmi_tx_is_encryption_set(hdmi_ctrl) ||
649 !sde_hdmi_tx_is_stream_shareable(hdmi_ctrl))
650 rc = sde_hdmi_config_avmute(hdmi, true);
652 if (sde_hdmi_tx_is_panel_on(hdmi_ctrl)) {
653 pr_debug("%s: Reauthenticating\n", __func__);
654 if (hdmi_ctrl->hdcp_ops && hdmi_ctrl->hdcp_data) {
655 rc = hdmi_ctrl->hdcp_ops->reauthenticate(
656 hdmi_ctrl->hdcp_data);
658 pr_err("%s: HDCP reauth failed. rc=%d\n",
661 pr_err("%s: NULL HDCP Ops and Data\n",
664 pr_debug("%s: Not reauthenticating. Cable not conn\n",
669 case HDCP_STATE_AUTH_FAIL_NOREAUTH:
670 if (hdmi_ctrl->hdcp1_use_sw_keys && hdmi_ctrl->hdcp14_present) {
671 if (hdmi_ctrl->auth_state && !hdmi_ctrl->hdcp22_present)
672 hdcp1_set_enc(false);
675 hdmi_ctrl->auth_state = false;
678 case HDCP_STATE_AUTH_ENC_NONE:
679 hdmi_ctrl->enc_lvl = HDCP_STATE_AUTH_ENC_NONE;
680 if (sde_hdmi_tx_is_panel_on(hdmi_ctrl))
681 rc = sde_hdmi_config_avmute(hdmi, false);
683 case HDCP_STATE_AUTH_ENC_1X:
684 case HDCP_STATE_AUTH_ENC_2P2:
685 hdmi_ctrl->enc_lvl = hdmi_ctrl->hdcp_status;
687 if (sde_hdmi_tx_is_panel_on(hdmi_ctrl) &&
688 sde_hdmi_tx_is_stream_shareable(hdmi_ctrl)) {
689 rc = sde_hdmi_config_avmute(hdmi, false);
691 rc = sde_hdmi_config_avmute(hdmi, true);
701 * _sde_hdmi_update_pll_delta() - Update the HDMI pixel clock as per input ppm
703 * @ppm: ppm is parts per million multiplied by 1000.
704 * return: 0 on success, non-zero in case of failure.
706 * The input ppm will be clipped if it's more than or less than 5% of the TMDS
707 * clock rate defined by HDMI spec.
709 static int _sde_hdmi_update_pll_delta(struct sde_hdmi *display, s32 ppm)
711 struct hdmi *hdmi = display->ctrl.ctrl;
712 u64 cur_pclk, dst_pclk;
716 mutex_lock(&display->display_lock);
718 if (!hdmi->power_on || !display->connected) {
719 SDE_ERROR("HDMI display is not ready\n");
720 mutex_unlock(&display->display_lock);
724 if (!display->pll_update_enable) {
725 SDE_ERROR("PLL update function is not enabled\n");
726 mutex_unlock(&display->display_lock);
730 /* get current pclk */
731 cur_pclk = hdmi->actual_pixclock;
732 /* get desired pclk */
733 dst_pclk = cur_pclk * (1000000000 + ppm);
734 do_div(dst_pclk, 1000000000);
736 clip_pclk = _sde_hdmi_clip_valid_pclk(hdmi, dst_pclk);
739 if (clip_pclk != cur_pclk) {
740 SDE_DEBUG("PCLK changes from %llu to %llu when delta is %d\n",
741 cur_pclk, clip_pclk, ppm);
743 rc = clk_set_rate(hdmi->pwr_clks[0], clip_pclk);
745 SDE_ERROR("HDMI PLL update failed\n");
746 mutex_unlock(&display->display_lock);
750 hdmi->actual_pixclock = clip_pclk;
753 mutex_unlock(&display->display_lock);
758 static ssize_t _sde_hdmi_debugfs_pll_delta_write(struct file *file,
759 const char __user *user_buf, size_t count, loff_t *ppos)
761 struct sde_hdmi *display = file->private_data;
768 if (count >= sizeof(buf))
771 if (copy_from_user(buf, user_buf, count))
774 buf[count] = 0; /* end of string */
776 if (kstrtoint(buf, 0, &ppm))
780 _sde_hdmi_update_pll_delta(display, ppm);
785 static const struct file_operations pll_delta_fops = {
787 .write = _sde_hdmi_debugfs_pll_delta_write,
791 * _sde_hdmi_enable_pll_update() - Enable the HDMI PLL update function
793 * @enable: non-zero to enable PLL update function, 0 to disable.
794 * return: 0 on success, non-zero in case of failure.
797 static int _sde_hdmi_enable_pll_update(struct sde_hdmi *display, s32 enable)
799 struct hdmi *hdmi = display->ctrl.ctrl;
802 mutex_lock(&display->display_lock);
804 if (!hdmi->power_on || !display->connected) {
805 SDE_ERROR("HDMI display is not ready\n");
806 mutex_unlock(&display->display_lock);
810 if (!enable && hdmi->actual_pixclock != hdmi->pixclock) {
811 /* reset pixel clock when disable */
812 rc = clk_set_rate(hdmi->pwr_clks[0], hdmi->pixclock);
814 SDE_ERROR("reset clock rate failed\n");
815 mutex_unlock(&display->display_lock);
819 hdmi->actual_pixclock = hdmi->pixclock;
821 display->pll_update_enable = !!enable;
823 mutex_unlock(&display->display_lock);
825 SDE_DEBUG("HDMI PLL update: %s\n",
826 display->pll_update_enable ? "enable" : "disable");
831 static ssize_t _sde_hdmi_debugfs_pll_enable_read(struct file *file,
832 char __user *buff, size_t count, loff_t *ppos)
834 struct sde_hdmi *display = file->private_data;
844 buf = kzalloc(SZ_1K, GFP_KERNEL);
848 len += snprintf(buf, SZ_4K, "%s\n",
849 display->pll_update_enable ? "enable" : "disable");
851 if (copy_to_user(buff, buf, len)) {
862 static ssize_t _sde_hdmi_debugfs_pll_enable_write(struct file *file,
863 const char __user *user_buf, size_t count, loff_t *ppos)
865 struct sde_hdmi *display = file->private_data;
872 if (count >= sizeof(buf))
875 if (copy_from_user(buf, user_buf, count))
878 buf[count] = 0; /* end of string */
880 if (kstrtoint(buf, 0, &enable))
883 _sde_hdmi_enable_pll_update(display, enable);
888 static const struct file_operations pll_enable_fops = {
890 .read = _sde_hdmi_debugfs_pll_enable_read,
891 .write = _sde_hdmi_debugfs_pll_enable_write,
894 static int _sde_hdmi_debugfs_init(struct sde_hdmi *display)
897 struct dentry *dir, *dump_file, *edid_modes;
898 struct dentry *edid_vsdb_info, *edid_hdr_info, *edid_hfvsdb_info;
899 struct dentry *edid_vcdb_info, *edid_vendor_name;
900 struct dentry *src_hdcp14_support, *src_hdcp22_support;
901 struct dentry *sink_hdcp22_support, *hdmi_hdcp_state;
902 struct dentry *pll_delta_file, *pll_enable_file;
904 dir = debugfs_create_dir(display->name, NULL);
907 SDE_ERROR("[%s]debugfs create dir failed, rc = %d\n",
912 dump_file = debugfs_create_file("dump_info",
917 if (IS_ERR_OR_NULL(dump_file)) {
918 rc = PTR_ERR(dump_file);
919 SDE_ERROR("[%s]debugfs create dump_info file failed, rc=%d\n",
921 goto error_remove_dir;
924 pll_delta_file = debugfs_create_file("pll_delta",
929 if (IS_ERR_OR_NULL(pll_delta_file)) {
930 rc = PTR_ERR(pll_delta_file);
931 SDE_ERROR("[%s]debugfs create pll_delta file failed, rc=%d\n",
933 goto error_remove_dir;
936 pll_enable_file = debugfs_create_file("pll_enable",
941 if (IS_ERR_OR_NULL(pll_enable_file)) {
942 rc = PTR_ERR(pll_enable_file);
943 SDE_ERROR("[%s]debugfs create pll_enable file failed, rc=%d\n",
945 goto error_remove_dir;
948 edid_modes = debugfs_create_file("edid_modes",
954 if (IS_ERR_OR_NULL(edid_modes)) {
955 rc = PTR_ERR(edid_modes);
956 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
958 goto error_remove_dir;
961 edid_vsdb_info = debugfs_create_file("edid_vsdb_info",
965 &edid_vsdb_info_fops);
967 if (IS_ERR_OR_NULL(edid_vsdb_info)) {
968 rc = PTR_ERR(edid_vsdb_info);
969 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
971 goto error_remove_dir;
974 edid_hdr_info = debugfs_create_file("edid_hdr_info",
978 &edid_hdr_info_fops);
979 if (IS_ERR_OR_NULL(edid_hdr_info)) {
980 rc = PTR_ERR(edid_hdr_info);
981 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
983 goto error_remove_dir;
986 edid_hfvsdb_info = debugfs_create_file("edid_hfvsdb_info",
990 &edid_hfvsdb_info_fops);
992 if (IS_ERR_OR_NULL(edid_hfvsdb_info)) {
993 rc = PTR_ERR(edid_hfvsdb_info);
994 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
996 goto error_remove_dir;
999 edid_vcdb_info = debugfs_create_file("edid_vcdb_info",
1003 &edid_vcdb_info_fops);
1005 if (IS_ERR_OR_NULL(edid_vcdb_info)) {
1006 rc = PTR_ERR(edid_vcdb_info);
1007 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1009 goto error_remove_dir;
1012 edid_vendor_name = debugfs_create_file("edid_vendor_name",
1016 &edid_vendor_name_fops);
1018 if (IS_ERR_OR_NULL(edid_vendor_name)) {
1019 rc = PTR_ERR(edid_vendor_name);
1020 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1022 goto error_remove_dir;
1025 src_hdcp14_support = debugfs_create_file("src_hdcp14_support",
1029 &hdcp_src_14_support_fops);
1031 if (IS_ERR_OR_NULL(src_hdcp14_support)) {
1032 rc = PTR_ERR(src_hdcp14_support);
1033 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1035 goto error_remove_dir;
1038 src_hdcp22_support = debugfs_create_file("src_hdcp22_support",
1042 &hdcp_src_22_support_fops);
1044 if (IS_ERR_OR_NULL(src_hdcp22_support)) {
1045 rc = PTR_ERR(src_hdcp22_support);
1046 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1048 goto error_remove_dir;
1051 sink_hdcp22_support = debugfs_create_file("sink_hdcp22_support",
1055 &hdcp_sink_22_support_fops);
1057 if (IS_ERR_OR_NULL(sink_hdcp22_support)) {
1058 rc = PTR_ERR(sink_hdcp22_support);
1059 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1061 goto error_remove_dir;
1064 hdmi_hdcp_state = debugfs_create_file("hdmi_hdcp_state",
1068 &sde_hdmi_hdcp_state_fops);
1070 if (IS_ERR_OR_NULL(hdmi_hdcp_state)) {
1071 rc = PTR_ERR(hdmi_hdcp_state);
1072 SDE_ERROR("[%s]debugfs create file failed, rc=%d\n",
1074 goto error_remove_dir;
1077 display->root = dir;
1080 debugfs_remove(dir);
1085 static void _sde_hdmi_debugfs_deinit(struct sde_hdmi *display)
1087 debugfs_remove(display->root);
1090 static void _sde_hdmi_phy_reset(struct hdmi *hdmi)
1094 val = hdmi_read(hdmi, REG_HDMI_PHY_CTRL);
1096 if (val & HDMI_PHY_CTRL_SW_RESET_LOW)
1097 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1098 val & ~HDMI_PHY_CTRL_SW_RESET);
1100 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1101 val | HDMI_PHY_CTRL_SW_RESET);
1103 if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW)
1104 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1105 val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
1107 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1108 val | HDMI_PHY_CTRL_SW_RESET_PLL);
1110 if (val & HDMI_PHY_CTRL_SW_RESET_LOW)
1111 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1112 val | HDMI_PHY_CTRL_SW_RESET);
1114 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1115 val & ~HDMI_PHY_CTRL_SW_RESET);
1117 if (val & HDMI_PHY_CTRL_SW_RESET_PLL_LOW)
1118 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1119 val | HDMI_PHY_CTRL_SW_RESET_PLL);
1121 hdmi_write(hdmi, REG_HDMI_PHY_CTRL,
1122 val & ~HDMI_PHY_CTRL_SW_RESET_PLL);
1125 static int _sde_hdmi_gpio_config(struct hdmi *hdmi, bool on)
1127 const struct hdmi_platform_config *config = hdmi->config;
1131 if (config->ddc_clk_gpio != -1) {
1132 ret = gpio_request(config->ddc_clk_gpio,
1135 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1136 "HDMI_DDC_CLK", config->ddc_clk_gpio,
1138 goto error_ddc_clk_gpio;
1140 gpio_set_value_cansleep(config->ddc_clk_gpio, 1);
1143 if (config->ddc_data_gpio != -1) {
1144 ret = gpio_request(config->ddc_data_gpio,
1147 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1148 "HDMI_DDC_DATA", config->ddc_data_gpio,
1150 goto error_ddc_data_gpio;
1152 gpio_set_value_cansleep(config->ddc_data_gpio, 1);
1155 ret = gpio_request(config->hpd_gpio, "HDMI_HPD");
1157 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1158 "HDMI_HPD", config->hpd_gpio, ret);
1159 goto error_hpd_gpio;
1161 gpio_direction_output(config->hpd_gpio, 1);
1162 if (config->hpd5v_gpio != -1) {
1163 ret = gpio_request(config->hpd5v_gpio, "HDMI_HPD_5V");
1165 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1169 goto error_hpd5v_gpio;
1171 gpio_set_value_cansleep(config->hpd5v_gpio, 1);
1174 if (config->mux_en_gpio != -1) {
1175 ret = gpio_request(config->mux_en_gpio, "HDMI_MUX_EN");
1177 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1178 "HDMI_MUX_EN", config->mux_en_gpio,
1182 gpio_set_value_cansleep(config->mux_en_gpio, 1);
1185 if (config->mux_sel_gpio != -1) {
1186 ret = gpio_request(config->mux_sel_gpio,
1189 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1190 "HDMI_MUX_SEL", config->mux_sel_gpio,
1192 goto error_sel_gpio;
1194 gpio_set_value_cansleep(config->mux_sel_gpio, 0);
1197 if (config->mux_lpm_gpio != -1) {
1198 ret = gpio_request(config->mux_lpm_gpio,
1201 SDE_ERROR("'%s'(%d) gpio_request failed: %d\n",
1203 config->mux_lpm_gpio, ret);
1204 goto error_lpm_gpio;
1206 gpio_set_value_cansleep(config->mux_lpm_gpio, 1);
1208 SDE_DEBUG("gpio on");
1210 if (config->ddc_clk_gpio != -1)
1211 gpio_free(config->ddc_clk_gpio);
1213 if (config->ddc_data_gpio != -1)
1214 gpio_free(config->ddc_data_gpio);
1216 gpio_free(config->hpd_gpio);
1218 if (config->hpd5v_gpio != -1)
1219 gpio_free(config->hpd5v_gpio);
1221 if (config->mux_en_gpio != -1) {
1222 gpio_set_value_cansleep(config->mux_en_gpio, 0);
1223 gpio_free(config->mux_en_gpio);
1226 if (config->mux_sel_gpio != -1) {
1227 gpio_set_value_cansleep(config->mux_sel_gpio, 1);
1228 gpio_free(config->mux_sel_gpio);
1231 if (config->mux_lpm_gpio != -1) {
1232 gpio_set_value_cansleep(config->mux_lpm_gpio, 0);
1233 gpio_free(config->mux_lpm_gpio);
1235 SDE_DEBUG("gpio off");
1241 if (config->mux_sel_gpio != -1)
1242 gpio_free(config->mux_sel_gpio);
1244 if (config->mux_en_gpio != -1)
1245 gpio_free(config->mux_en_gpio);
1247 gpio_free(config->hpd5v_gpio);
1249 gpio_free(config->hpd_gpio);
1251 if (config->ddc_data_gpio != -1)
1252 gpio_free(config->ddc_data_gpio);
1253 error_ddc_data_gpio:
1254 if (config->ddc_clk_gpio != -1)
1255 gpio_free(config->ddc_clk_gpio);
1260 static int _sde_hdmi_hpd_enable(struct sde_hdmi *sde_hdmi)
1262 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
1263 const struct hdmi_platform_config *config = hdmi->config;
1264 struct device *dev = &hdmi->pdev->dev;
1267 unsigned long flags;
1268 struct drm_connector *connector;
1269 struct msm_drm_private *priv;
1270 struct sde_kms *sde_kms;
1272 connector = hdmi->connector;
1273 priv = connector->dev->dev_private;
1274 sde_kms = to_sde_kms(priv->kms);
1276 for (i = 0; i < config->hpd_reg_cnt; i++) {
1277 ret = regulator_enable(hdmi->hpd_regs[i]);
1279 SDE_ERROR("failed to enable hpd regulator: %s (%d)\n",
1280 config->hpd_reg_names[i], ret);
1285 ret = pinctrl_pm_select_default_state(dev);
1287 SDE_ERROR("pinctrl state chg failed: %d\n", ret);
1291 ret = _sde_hdmi_gpio_config(hdmi, true);
1293 SDE_ERROR("failed to configure GPIOs: %d\n", ret);
1297 for (i = 0; i < config->hpd_clk_cnt; i++) {
1298 if (config->hpd_freq && config->hpd_freq[i]) {
1299 ret = clk_set_rate(hdmi->hpd_clks[i],
1300 config->hpd_freq[i]);
1302 pr_warn("failed to set clk %s (%d)\n",
1303 config->hpd_clk_names[i], ret);
1306 ret = clk_prepare_enable(hdmi->hpd_clks[i]);
1308 SDE_ERROR("failed to enable hpd clk: %s (%d)\n",
1309 config->hpd_clk_names[i], ret);
1314 if (!sde_hdmi->cont_splash_enabled) {
1315 sde_hdmi_set_mode(hdmi, false);
1316 _sde_hdmi_phy_reset(hdmi);
1317 sde_hdmi_set_mode(hdmi, true);
1320 hdmi_write(hdmi, REG_HDMI_USEC_REFTIMER, 0x0001001b);
1322 /* set timeout to 4.1ms (max) for hardware debounce */
1323 spin_lock_irqsave(&hdmi->reg_lock, flags);
1324 hpd_ctrl = hdmi_read(hdmi, REG_HDMI_HPD_CTRL);
1325 hpd_ctrl |= HDMI_HPD_CTRL_TIMEOUT(0x1fff);
1327 hdmi_write(hdmi, REG_HDMI_HPD_CTRL,
1328 HDMI_HPD_CTRL_ENABLE | hpd_ctrl);
1330 /* enable HPD events: */
1331 hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL,
1332 HDMI_HPD_INT_CTRL_INT_CONNECT |
1333 HDMI_HPD_INT_CTRL_INT_EN);
1335 /* Toggle HPD circuit to trigger HPD sense */
1336 hdmi_write(hdmi, REG_HDMI_HPD_CTRL,
1337 ~HDMI_HPD_CTRL_ENABLE & hpd_ctrl);
1338 hdmi_write(hdmi, REG_HDMI_HPD_CTRL,
1339 HDMI_HPD_CTRL_ENABLE | hpd_ctrl);
1340 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
1342 if (!sde_hdmi->non_pluggable)
1343 hdmi->hpd_off = false;
1344 SDE_DEBUG("enabled hdmi hpd\n");
1351 int sde_hdmi_core_enable(struct sde_hdmi *sde_hdmi)
1353 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
1354 const struct hdmi_platform_config *config = hdmi->config;
1355 struct device *dev = &hdmi->pdev->dev;
1358 for (i = 0; i < config->hpd_reg_cnt; i++) {
1359 ret = regulator_enable(hdmi->hpd_regs[i]);
1361 SDE_ERROR("failed to enable hpd regulator: %s (%d)\n",
1362 config->hpd_reg_names[i], ret);
1363 goto err_regulator_enable;
1367 ret = pinctrl_pm_select_default_state(dev);
1369 SDE_ERROR("pinctrl state chg failed: %d\n", ret);
1370 goto err_pinctrl_state;
1373 ret = _sde_hdmi_gpio_config(hdmi, true);
1375 SDE_ERROR("failed to configure GPIOs: %d\n", ret);
1376 goto err_gpio_config;
1379 for (i = 0; i < config->hpd_clk_cnt; i++) {
1380 if (config->hpd_freq && config->hpd_freq[i]) {
1381 ret = clk_set_rate(hdmi->hpd_clks[i],
1382 config->hpd_freq[i]);
1384 pr_warn("failed to set clk %s (%d)\n",
1385 config->hpd_clk_names[i], ret);
1388 ret = clk_prepare_enable(hdmi->hpd_clks[i]);
1390 SDE_ERROR("failed to enable hpd clk: %s (%d)\n",
1391 config->hpd_clk_names[i], ret);
1392 goto err_clk_prepare_enable;
1395 sde_hdmi_set_mode(hdmi, true);
1398 err_clk_prepare_enable:
1399 for (i = 0; i < config->hpd_clk_cnt; i++)
1400 clk_disable_unprepare(hdmi->hpd_clks[i]);
1402 _sde_hdmi_gpio_config(hdmi, false);
1404 pinctrl_pm_select_sleep_state(dev);
1405 err_regulator_enable:
1406 for (i = 0; i < config->hpd_reg_cnt; i++)
1407 regulator_disable(hdmi->hpd_regs[i]);
1412 static void _sde_hdmi_hpd_disable(struct sde_hdmi *sde_hdmi)
1414 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
1415 const struct hdmi_platform_config *config = hdmi->config;
1416 struct device *dev = &hdmi->pdev->dev;
1418 unsigned long flags;
1420 if (!sde_hdmi->non_pluggable && hdmi->hpd_off) {
1421 pr_warn("hdmi display hpd was already disabled\n");
1425 spin_lock_irqsave(&hdmi->reg_lock, flags);
1426 /* Disable HPD interrupt */
1427 hdmi_write(hdmi, REG_HDMI_HPD_CTRL, 0);
1428 hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, 0);
1429 hdmi_write(hdmi, REG_HDMI_HPD_INT_STATUS, 0);
1430 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
1432 sde_hdmi_set_mode(hdmi, false);
1434 for (i = 0; i < config->hpd_clk_cnt; i++)
1435 clk_disable_unprepare(hdmi->hpd_clks[i]);
1437 ret = _sde_hdmi_gpio_config(hdmi, false);
1439 pr_warn("failed to unconfigure GPIOs: %d\n", ret);
1441 ret = pinctrl_pm_select_sleep_state(dev);
1443 pr_warn("pinctrl state chg failed: %d\n", ret);
1445 for (i = 0; i < config->hpd_reg_cnt; i++) {
1446 ret = regulator_disable(hdmi->hpd_regs[i]);
1448 pr_warn("failed to disable hpd regulator: %s (%d)\n",
1449 config->hpd_reg_names[i], ret);
1452 if (!sde_hdmi->non_pluggable)
1453 hdmi->hpd_off = true;
1454 SDE_DEBUG("disabled hdmi hpd\n");
1458 * _sde_hdmi_update_hpd_state() - Update the HDMI HPD clock state
1460 * @state: non-zero to disbale HPD clock, 0 to enable.
1461 * return: 0 on success, non-zero in case of failure.
1465 _sde_hdmi_update_hpd_state(struct sde_hdmi *hdmi_display, u64 state)
1467 struct hdmi *hdmi = hdmi_display->ctrl.ctrl;
1470 if (hdmi_display->non_pluggable)
1473 SDE_DEBUG("changing hdmi hpd state to %llu\n", state);
1475 if (state == SDE_MODE_HPD_ON) {
1477 pr_warn("hdmi display hpd was already enabled\n");
1478 rc = _sde_hdmi_hpd_enable(hdmi_display);
1480 _sde_hdmi_hpd_disable(hdmi_display);
1485 void sde_hdmi_core_disable(struct sde_hdmi *sde_hdmi)
1487 /* HPD contains all the core clock and pwr */
1488 _sde_hdmi_hpd_disable(sde_hdmi);
1491 static void _sde_hdmi_cec_update_phys_addr(struct sde_hdmi *display)
1493 struct edid *edid = display->edid_ctrl->edid;
1496 cec_notifier_set_phys_addr_from_edid(display->notifier, edid);
1498 cec_notifier_set_phys_addr(display->notifier,
1499 CEC_PHYS_ADDR_INVALID);
1503 static void _sde_hdmi_init_ddc(struct sde_hdmi *display, struct hdmi *hdmi)
1505 display->ddc_ctrl.io = &display->io[HDMI_TX_CORE_IO];
1506 init_completion(&display->ddc_ctrl.rx_status_done);
1509 static void _sde_hdmi_map_regs(struct sde_hdmi *display, struct hdmi *hdmi)
1511 display->io[HDMI_TX_CORE_IO].base = hdmi->mmio;
1512 display->io[HDMI_TX_CORE_IO].len = hdmi->mmio_len;
1513 display->io[HDMI_TX_QFPROM_IO].base = hdmi->qfprom_mmio;
1514 display->io[HDMI_TX_QFPROM_IO].len = hdmi->qfprom_mmio_len;
1515 display->io[HDMI_TX_HDCP_IO].base = hdmi->hdcp_mmio;
1516 display->io[HDMI_TX_HDCP_IO].len = hdmi->hdcp_mmio_len;
1519 static void _sde_hdmi_hotplug_work(struct work_struct *work)
1521 struct sde_hdmi *sde_hdmi =
1522 container_of(work, struct sde_hdmi, hpd_work);
1523 struct drm_connector *connector;
1524 struct hdmi *hdmi = NULL;
1527 if (!sde_hdmi || !sde_hdmi->ctrl.ctrl ||
1528 !sde_hdmi->ctrl.ctrl->connector ||
1529 !sde_hdmi->edid_ctrl) {
1530 SDE_ERROR("sde_hdmi=%p or hdmi or connector is NULL\n",
1534 hdmi = sde_hdmi->ctrl.ctrl;
1535 connector = sde_hdmi->ctrl.ctrl->connector;
1537 if (sde_hdmi->connected) {
1538 hdmi_ctrl = hdmi_read(hdmi, REG_HDMI_CTRL);
1539 hdmi_write(hdmi, REG_HDMI_CTRL, hdmi_ctrl | HDMI_CTRL_ENABLE);
1540 sde_get_edid(connector, hdmi->i2c,
1541 (void **)&sde_hdmi->edid_ctrl);
1542 hdmi_write(hdmi, REG_HDMI_CTRL, hdmi_ctrl);
1543 hdmi->hdmi_mode = sde_detect_hdmi_monitor(sde_hdmi->edid_ctrl);
1545 sde_free_edid((void **)&sde_hdmi->edid_ctrl);
1547 drm_helper_hpd_irq_event(connector->dev);
1548 _sde_hdmi_cec_update_phys_addr(sde_hdmi);
1551 static void _sde_hdmi_connector_irq(struct sde_hdmi *sde_hdmi)
1553 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
1554 uint32_t hpd_int_status, hpd_int_ctrl;
1557 hpd_int_status = hdmi_read(hdmi, REG_HDMI_HPD_INT_STATUS);
1558 hpd_int_ctrl = hdmi_read(hdmi, REG_HDMI_HPD_INT_CTRL);
1560 if ((hpd_int_ctrl & HDMI_HPD_INT_CTRL_INT_EN) &&
1561 (hpd_int_status & HDMI_HPD_INT_STATUS_INT)) {
1562 sde_hdmi->connected = !!(hpd_int_status &
1563 HDMI_HPD_INT_STATUS_CABLE_DETECTED);
1564 /* ack & disable (temporarily) HPD events: */
1565 hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL,
1566 HDMI_HPD_INT_CTRL_INT_ACK);
1568 SDE_HDMI_DEBUG("status=%04x, ctrl=%04x", hpd_int_status,
1571 /* detect disconnect if we are connected or visa versa: */
1572 hpd_int_ctrl = HDMI_HPD_INT_CTRL_INT_EN;
1573 if (!sde_hdmi->connected)
1574 hpd_int_ctrl |= HDMI_HPD_INT_CTRL_INT_CONNECT;
1575 hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, hpd_int_ctrl);
1577 queue_work(hdmi->workq, &sde_hdmi->hpd_work);
1581 static void _sde_hdmi_cec_irq(struct sde_hdmi *sde_hdmi)
1583 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
1584 u32 cec_intr = hdmi_read(hdmi, REG_HDMI_CEC_INT);
1586 /* Routing interrupt to external CEC drivers */
1588 generic_handle_irq(irq_find_mapping(
1589 sde_hdmi->irq_domain, 1));
1593 static irqreturn_t _sde_hdmi_irq(int irq, void *dev_id)
1595 struct sde_hdmi *display = dev_id;
1598 if (!display || !display->ctrl.ctrl) {
1599 SDE_ERROR("sde_hdmi=%pK or hdmi is NULL\n", display);
1603 hdmi = display->ctrl.ctrl;
1605 _sde_hdmi_connector_irq(display);
1607 /* Process Scrambling ISR */
1608 sde_hdmi_ddc_scrambling_isr((void *)display);
1611 sde_hdmi_ddc_hdcp2p2_isr((void *)display);
1614 hdmi_i2c_irq(hdmi->i2c);
1617 if (display->hdcp_ops && display->hdcp_data) {
1618 if (display->hdcp_ops->isr) {
1619 if (display->hdcp_ops->isr(
1620 display->hdcp_data))
1621 DEV_ERR("%s: hdcp_1x_isr failed\n",
1627 _sde_hdmi_cec_irq(display);
1632 static int _sde_hdmi_audio_info_setup(struct platform_device *pdev,
1633 struct msm_ext_disp_audio_setup_params *params)
1636 struct sde_hdmi *display = NULL;
1637 struct hdmi *hdmi = NULL;
1639 display = platform_get_drvdata(pdev);
1641 if (!display || !params) {
1642 SDE_ERROR("invalid param(s), display %pK, params %pK\n",
1647 hdmi = display->ctrl.ctrl;
1649 if (hdmi->hdmi_mode)
1650 rc = sde_hdmi_audio_on(hdmi, params);
1655 static int _sde_hdmi_get_audio_edid_blk(struct platform_device *pdev,
1656 struct msm_ext_disp_audio_edid_blk *blk)
1658 struct sde_hdmi *display = platform_get_drvdata(pdev);
1660 if (!display || !blk) {
1661 SDE_ERROR("invalid param(s), display %pK, blk %pK\n",
1666 blk->audio_data_blk = display->edid_ctrl->audio_data_block;
1667 blk->audio_data_blk_size = display->edid_ctrl->adb_size;
1669 blk->spk_alloc_data_blk = display->edid_ctrl->spkr_alloc_data_block;
1670 blk->spk_alloc_data_blk_size = display->edid_ctrl->sadb_size;
1675 static int _sde_hdmi_get_cable_status(struct platform_device *pdev, u32 vote)
1677 struct sde_hdmi *display = NULL;
1678 struct hdmi *hdmi = NULL;
1680 display = platform_get_drvdata(pdev);
1683 SDE_ERROR("invalid param(s), display %pK\n", display);
1687 hdmi = display->ctrl.ctrl;
1689 return hdmi->power_on && display->connected;
1692 static void _sde_hdmi_audio_codec_ready(struct platform_device *pdev)
1694 struct sde_hdmi *display = platform_get_drvdata(pdev);
1697 SDE_ERROR("invalid param(s), display %pK\n", display);
1701 mutex_lock(&display->display_lock);
1702 if (!display->codec_ready) {
1703 display->codec_ready = true;
1705 if (display->client_notify_pending)
1706 sde_hdmi_notify_clients(display, display->connected);
1708 mutex_unlock(&display->display_lock);
1711 static int _sde_hdmi_ext_disp_init(struct sde_hdmi *display)
1714 struct device_node *pd_np;
1715 const char *phandle = "qcom,msm_ext_disp";
1718 SDE_ERROR("Invalid params\n");
1722 display->ext_audio_data.type = EXT_DISPLAY_TYPE_HDMI;
1723 display->ext_audio_data.pdev = display->pdev;
1724 display->ext_audio_data.codec_ops.audio_info_setup =
1725 _sde_hdmi_audio_info_setup;
1726 display->ext_audio_data.codec_ops.get_audio_edid_blk =
1727 _sde_hdmi_get_audio_edid_blk;
1728 display->ext_audio_data.codec_ops.cable_status =
1729 _sde_hdmi_get_cable_status;
1730 display->ext_audio_data.codec_ops.codec_ready =
1731 _sde_hdmi_audio_codec_ready;
1733 if (!display->pdev->dev.of_node) {
1734 SDE_ERROR("[%s]cannot find sde_hdmi of_node\n", display->name);
1738 pd_np = of_parse_phandle(display->pdev->dev.of_node, phandle, 0);
1740 SDE_ERROR("[%s]cannot find %s device node\n",
1741 display->name, phandle);
1745 display->ext_pdev = of_find_device_by_node(pd_np);
1746 if (!display->ext_pdev) {
1747 SDE_ERROR("[%s]cannot find %s platform device\n",
1748 display->name, phandle);
1752 rc = msm_ext_disp_register_intf(display->ext_pdev,
1753 &display->ext_audio_data);
1755 SDE_ERROR("[%s]failed to register disp\n", display->name);
1760 void sde_hdmi_notify_clients(struct sde_hdmi *display, bool connected)
1762 int state = connected ?
1763 EXT_DISPLAY_CABLE_CONNECT : EXT_DISPLAY_CABLE_DISCONNECT;
1765 if (display && display->ext_audio_data.intf_ops.hpd) {
1766 struct hdmi *hdmi = display->ctrl.ctrl;
1767 u32 flags = MSM_EXT_DISP_HPD_ASYNC_VIDEO;
1769 if (hdmi->hdmi_mode)
1770 flags |= MSM_EXT_DISP_HPD_AUDIO;
1772 display->ext_audio_data.intf_ops.hpd(display->ext_pdev,
1773 display->ext_audio_data.type, state, flags);
1777 void sde_hdmi_set_mode(struct hdmi *hdmi, bool power_on)
1780 unsigned long flags;
1782 spin_lock_irqsave(&hdmi->reg_lock, flags);
1783 ctrl = hdmi_read(hdmi, REG_HDMI_CTRL);
1785 ctrl |= HDMI_CTRL_ENABLE;
1786 if (!hdmi->hdmi_mode) {
1787 ctrl |= HDMI_CTRL_HDMI;
1788 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
1789 ctrl &= ~HDMI_CTRL_HDMI;
1791 ctrl |= HDMI_CTRL_HDMI;
1794 ctrl &= ~HDMI_CTRL_HDMI;
1797 hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
1798 spin_unlock_irqrestore(&hdmi->reg_lock, flags);
1799 SDE_HDMI_DEBUG("HDMI Core: %s, HDMI_CTRL=0x%08x\n",
1800 power_on ? "Enable" : "Disable", ctrl);
1803 #define DDC_WRITE_MAX_BYTE_NUM 32
1805 int sde_hdmi_scdc_read(struct hdmi *hdmi, u32 data_type, u32 *val)
1808 u8 data_buf[2] = {0};
1809 u16 dev_addr, data_len;
1812 if (!hdmi || !hdmi->i2c || !val) {
1813 SDE_ERROR("Bad Parameters\n");
1817 if (data_type >= HDMI_TX_SCDC_MAX) {
1818 SDE_ERROR("Unsupported data type\n");
1824 switch (data_type) {
1825 case HDMI_TX_SCDC_SCRAMBLING_STATUS:
1827 offset = HDMI_SCDC_SCRAMBLER_STATUS;
1829 case HDMI_TX_SCDC_SCRAMBLING_ENABLE:
1830 case HDMI_TX_SCDC_TMDS_BIT_CLOCK_RATIO_UPDATE:
1832 offset = HDMI_SCDC_TMDS_CONFIG;
1834 case HDMI_TX_SCDC_CLOCK_DET_STATUS:
1835 case HDMI_TX_SCDC_CH0_LOCK_STATUS:
1836 case HDMI_TX_SCDC_CH1_LOCK_STATUS:
1837 case HDMI_TX_SCDC_CH2_LOCK_STATUS:
1839 offset = HDMI_SCDC_STATUS_FLAGS_0;
1841 case HDMI_TX_SCDC_CH0_ERROR_COUNT:
1843 offset = HDMI_SCDC_ERR_DET_0_L;
1845 case HDMI_TX_SCDC_CH1_ERROR_COUNT:
1847 offset = HDMI_SCDC_ERR_DET_1_L;
1849 case HDMI_TX_SCDC_CH2_ERROR_COUNT:
1851 offset = HDMI_SCDC_ERR_DET_2_L;
1853 case HDMI_TX_SCDC_READ_ENABLE:
1855 offset = HDMI_SCDC_CONFIG_0;
1861 rc = hdmi_ddc_read(hdmi, dev_addr, offset, data_buf,
1864 SDE_ERROR("DDC Read failed for %d\n", data_type);
1868 switch (data_type) {
1869 case HDMI_TX_SCDC_SCRAMBLING_STATUS:
1870 *val = (data_buf[0] & BIT(0)) ? 1 : 0;
1872 case HDMI_TX_SCDC_SCRAMBLING_ENABLE:
1873 *val = (data_buf[0] & BIT(0)) ? 1 : 0;
1875 case HDMI_TX_SCDC_TMDS_BIT_CLOCK_RATIO_UPDATE:
1876 *val = (data_buf[0] & BIT(1)) ? 1 : 0;
1878 case HDMI_TX_SCDC_CLOCK_DET_STATUS:
1879 *val = (data_buf[0] & BIT(0)) ? 1 : 0;
1881 case HDMI_TX_SCDC_CH0_LOCK_STATUS:
1882 *val = (data_buf[0] & BIT(1)) ? 1 : 0;
1884 case HDMI_TX_SCDC_CH1_LOCK_STATUS:
1885 *val = (data_buf[0] & BIT(2)) ? 1 : 0;
1887 case HDMI_TX_SCDC_CH2_LOCK_STATUS:
1888 *val = (data_buf[0] & BIT(3)) ? 1 : 0;
1890 case HDMI_TX_SCDC_CH0_ERROR_COUNT:
1891 case HDMI_TX_SCDC_CH1_ERROR_COUNT:
1892 case HDMI_TX_SCDC_CH2_ERROR_COUNT:
1893 if (data_buf[1] & BIT(7))
1894 *val = (data_buf[0] | ((data_buf[1] & 0x7F) << 8));
1898 case HDMI_TX_SCDC_READ_ENABLE:
1899 *val = (data_buf[0] & BIT(0)) ? 1 : 0;
1908 int sde_hdmi_scdc_write(struct hdmi *hdmi, u32 data_type, u32 val)
1911 u8 data_buf[2] = {0};
1913 u16 dev_addr, data_len;
1916 if (!hdmi || !hdmi->i2c) {
1917 SDE_ERROR("Bad Parameters\n");
1921 if (data_type >= HDMI_TX_SCDC_MAX) {
1922 SDE_ERROR("Unsupported data type\n");
1928 switch (data_type) {
1929 case HDMI_TX_SCDC_SCRAMBLING_ENABLE:
1930 case HDMI_TX_SCDC_TMDS_BIT_CLOCK_RATIO_UPDATE:
1933 offset = HDMI_SCDC_TMDS_CONFIG;
1934 rc = hdmi_ddc_read(hdmi, dev_addr, offset, &read_val,
1937 SDE_ERROR("scdc read failed\n");
1940 if (data_type == HDMI_TX_SCDC_SCRAMBLING_ENABLE) {
1941 data_buf[0] = ((((u8)(read_val & 0xFF)) & (~BIT(0))) |
1942 ((u8)(val & BIT(0))));
1944 data_buf[0] = ((((u8)(read_val & 0xFF)) & (~BIT(1))) |
1945 (((u8)(val & BIT(0))) << 1));
1948 case HDMI_TX_SCDC_READ_ENABLE:
1950 offset = HDMI_SCDC_CONFIG_0;
1951 data_buf[0] = (u8)(val & 0x1);
1954 SDE_ERROR("Cannot write to read only reg (%d)\n",
1959 rc = hdmi_ddc_write(hdmi, dev_addr, offset, data_buf,
1962 SDE_ERROR("DDC Read failed for %d\n", data_type);
1968 int sde_hdmi_get_info(struct msm_display_info *info,
1972 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
1973 struct hdmi *hdmi = hdmi_display->ctrl.ctrl;
1975 if (!display || !info) {
1976 SDE_ERROR("display=%p or info=%p is NULL\n", display, info);
1980 mutex_lock(&hdmi_display->display_lock);
1982 info->intf_type = DRM_MODE_CONNECTOR_HDMIA;
1983 info->num_of_h_tiles = 1;
1984 info->h_tile_instance[0] = 0;
1985 if (hdmi_display->non_pluggable) {
1986 info->capabilities = MSM_DISPLAY_CAP_VID_MODE;
1987 hdmi_display->connected = true;
1988 hdmi->hdmi_mode = true;
1990 info->capabilities = MSM_DISPLAY_CAP_HOT_PLUG |
1991 MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_VID_MODE;
1993 info->is_connected = hdmi_display->connected;
1994 info->max_width = HDMI_DISPLAY_MAX_WIDTH;
1995 info->max_height = HDMI_DISPLAY_MAX_HEIGHT;
1996 info->compression = MSM_DISPLAY_COMPRESS_NONE;
1998 mutex_unlock(&hdmi_display->display_lock);
2002 static void sde_hdmi_panel_set_hdr_infoframe(struct sde_hdmi *display,
2003 struct drm_msm_ext_panel_hdr_metadata *hdr_meta)
2005 u32 packet_payload = 0;
2006 u32 packet_header = 0;
2007 u32 packet_control = 0;
2008 u32 const type_code = 0x87;
2009 u32 const version = 0x01;
2010 u32 const length = 0x1a;
2011 u32 const descriptor_id = 0x00;
2013 struct drm_connector *connector;
2015 if (!display || !hdr_meta) {
2016 SDE_ERROR("invalid input\n");
2020 hdmi = display->ctrl.ctrl;
2021 connector = display->ctrl.ctrl->connector;
2023 if (!hdmi || !connector) {
2024 SDE_ERROR("invalid input\n");
2028 /* Setup Packet header and payload */
2029 packet_header = type_code | (version << 8) | (length << 16);
2030 hdmi_write(hdmi, HDMI_GENERIC0_HDR, packet_header);
2032 packet_payload = (hdr_meta->eotf << 8);
2033 if (connector->hdr_metadata_type_one) {
2034 packet_payload |= (descriptor_id << 16)
2035 | (HDMI_GET_LSB(hdr_meta->display_primaries_x[0])
2037 hdmi_write(hdmi, HDMI_GENERIC0_0, packet_payload);
2039 pr_debug("Metadata Type 1 not supported\n");
2040 hdmi_write(hdmi, HDMI_GENERIC0_0, packet_payload);
2041 goto enable_packet_control;
2045 (HDMI_GET_MSB(hdr_meta->display_primaries_x[0]))
2046 | (HDMI_GET_LSB(hdr_meta->display_primaries_y[0]) << 8)
2047 | (HDMI_GET_MSB(hdr_meta->display_primaries_y[0]) << 16)
2048 | (HDMI_GET_LSB(hdr_meta->display_primaries_x[1]) << 24);
2049 hdmi_write(hdmi, HDMI_GENERIC0_1, packet_payload);
2052 (HDMI_GET_MSB(hdr_meta->display_primaries_x[1]))
2053 | (HDMI_GET_LSB(hdr_meta->display_primaries_y[1]) << 8)
2054 | (HDMI_GET_MSB(hdr_meta->display_primaries_y[1]) << 16)
2055 | (HDMI_GET_LSB(hdr_meta->display_primaries_x[2]) << 24);
2056 hdmi_write(hdmi, HDMI_GENERIC0_2, packet_payload);
2059 (HDMI_GET_MSB(hdr_meta->display_primaries_x[2]))
2060 | (HDMI_GET_LSB(hdr_meta->display_primaries_y[2]) << 8)
2061 | (HDMI_GET_MSB(hdr_meta->display_primaries_y[2]) << 16)
2062 | (HDMI_GET_LSB(hdr_meta->white_point_x) << 24);
2063 hdmi_write(hdmi, HDMI_GENERIC0_3, packet_payload);
2066 (HDMI_GET_MSB(hdr_meta->white_point_x))
2067 | (HDMI_GET_LSB(hdr_meta->white_point_y) << 8)
2068 | (HDMI_GET_MSB(hdr_meta->white_point_y) << 16)
2069 | (HDMI_GET_LSB(hdr_meta->max_luminance) << 24);
2070 hdmi_write(hdmi, HDMI_GENERIC0_4, packet_payload);
2073 (HDMI_GET_MSB(hdr_meta->max_luminance))
2074 | (HDMI_GET_LSB(hdr_meta->min_luminance) << 8)
2075 | (HDMI_GET_MSB(hdr_meta->min_luminance) << 16)
2076 | (HDMI_GET_LSB(hdr_meta->max_content_light_level) << 24);
2077 hdmi_write(hdmi, HDMI_GENERIC0_5, packet_payload);
2080 (HDMI_GET_MSB(hdr_meta->max_content_light_level))
2081 | (HDMI_GET_LSB(hdr_meta->max_average_light_level) << 8)
2082 | (HDMI_GET_MSB(hdr_meta->max_average_light_level) << 16);
2083 hdmi_write(hdmi, HDMI_GENERIC0_6, packet_payload);
2085 enable_packet_control:
2087 * GENERIC0_LINE | GENERIC0_CONT | GENERIC0_SEND
2088 * Setup HDMI TX generic packet control
2089 * Enable this packet to transmit every frame
2090 * Enable HDMI TX engine to transmit Generic packet 1
2092 packet_control = hdmi_read(hdmi, HDMI_GEN_PKT_CTRL);
2093 packet_control |= BIT(0) | BIT(1) | BIT(2) | BIT(16);
2094 hdmi_write(hdmi, HDMI_GEN_PKT_CTRL, packet_control);
2097 static void sde_hdmi_update_colorimetry(struct sde_hdmi *display,
2101 struct drm_connector *connector;
2102 bool mode_is_yuv = false;
2103 struct drm_display_mode *mode;
2104 u32 mode_fmt_flags = 0;
2108 u8 avi_iframe[HDMI_AVI_INFOFRAME_BUFFER_SIZE] = {0};
2109 u8 *avi_frame = &avi_iframe[HDMI_INFOFRAME_HEADER_SIZE];
2110 struct hdmi_avi_infoframe info;
2113 SDE_ERROR("invalid input\n");
2117 hdmi = display->ctrl.ctrl;
2120 SDE_ERROR("invalid input\n");
2124 connector = display->ctrl.ctrl->connector;
2127 SDE_ERROR("invalid input\n");
2131 if (!connector->hdr_supported) {
2132 SDE_DEBUG("HDR is not supported\n");
2136 /* If sink doesn't support BT2020, just return */
2137 if (!(connector->color_enc_fmt & DRM_EDID_COLORIMETRY_BT2020_YCC) ||
2138 !(connector->color_enc_fmt & DRM_EDID_COLORIMETRY_BT2020_RGB)) {
2139 SDE_DEBUG("BT2020 colorimetry is not supported\n");
2143 /* If there is no change in colorimetry, just return */
2144 if (use_bt2020 && display->bt2020_colorimetry)
2146 else if (!use_bt2020 && !display->bt2020_colorimetry)
2149 mode = &display->mode;
2150 /* Cache the format flags before clearing */
2151 mode_fmt_flags = mode->flags;
2153 * Clear the RGB/YUV format flags before calling upstream API
2154 * as the API also compares the flags and then returns a mode
2156 mode->flags &= ~SDE_DRM_MODE_FLAG_FMT_MASK;
2157 drm_hdmi_avi_infoframe_from_display_mode(&info, mode);
2158 /* Restore the format flags */
2159 mode->flags = mode_fmt_flags;
2161 /* Mode should only support YUV and not both to set the flag */
2162 if ((mode->private_flags & MSM_MODE_FLAG_COLOR_FORMAT_YCBCR420)
2163 && !(mode->private_flags & MSM_MODE_FLAG_COLOR_FORMAT_RGB444)) {
2168 if (!display->bt2020_colorimetry && use_bt2020) {
2170 * 1. Update colorimetry to use extended
2171 * 2. Change extended to use BT2020
2172 * 3. Change colorspace based on mode
2173 * 4. Use limited as BT2020 is always limited
2175 info.colorimetry = SDE_HDMI_USE_EXTENDED_COLORIMETRY;
2176 info.extended_colorimetry = SDE_HDMI_BT2020_COLORIMETRY;
2178 info.colorspace = HDMI_COLORSPACE_YUV420;
2179 if (connector->yuv_qs)
2180 info.ycc_quantization_range =
2181 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
2182 } else if (display->bt2020_colorimetry && !use_bt2020) {
2184 * 1. Update colorimetry to non-extended
2185 * 2. Change colorspace based on mode
2186 * 3. Restore quantization to full if QS
2189 info.colorimetry = SDE_HDMI_DEFAULT_COLORIMETRY;
2191 info.colorspace = HDMI_COLORSPACE_YUV420;
2192 if (connector->yuv_qs)
2193 info.ycc_quantization_range =
2194 HDMI_YCC_QUANTIZATION_RANGE_FULL;
2197 hdmi_avi_infoframe_pack(&info, avi_iframe, sizeof(avi_iframe));
2198 checksum = avi_iframe[HDMI_INFOFRAME_HEADER_SIZE - 1];
2199 avi_info0 = checksum |
2200 LEFT_SHIFT_BYTE(avi_frame[0]) |
2201 LEFT_SHIFT_WORD(avi_frame[1]) |
2202 LEFT_SHIFT_24BITS(avi_frame[2]);
2204 avi_info1 = avi_frame[3] |
2205 LEFT_SHIFT_BYTE(avi_frame[4]) |
2206 LEFT_SHIFT_WORD(avi_frame[5]) |
2207 LEFT_SHIFT_24BITS(avi_frame[6]);
2209 hdmi_write(hdmi, REG_HDMI_AVI_INFO(0), avi_info0);
2210 hdmi_write(hdmi, REG_HDMI_AVI_INFO(1), avi_info1);
2211 display->bt2020_colorimetry = use_bt2020;
2214 static void sde_hdmi_clear_hdr_infoframe(struct sde_hdmi *display)
2217 struct drm_connector *connector;
2218 u32 packet_control = 0;
2221 SDE_ERROR("invalid input\n");
2225 hdmi = display->ctrl.ctrl;
2226 connector = display->ctrl.ctrl->connector;
2228 if (!hdmi || !connector) {
2229 SDE_ERROR("invalid input\n");
2233 packet_control = hdmi_read(hdmi, HDMI_GEN_PKT_CTRL);
2234 packet_control &= ~HDMI_GEN_PKT_CTRL_CLR_MASK;
2235 hdmi_write(hdmi, HDMI_GEN_PKT_CTRL, packet_control);
2238 int sde_hdmi_set_property(struct drm_connector *connector,
2239 struct drm_connector_state *state,
2246 if (!connector || !display) {
2247 SDE_ERROR("connector=%pK or display=%pK is NULL\n",
2248 connector, display);
2254 if (property_index == CONNECTOR_PROP_PLL_ENABLE)
2255 rc = _sde_hdmi_enable_pll_update(display, value);
2256 else if (property_index == CONNECTOR_PROP_PLL_DELTA)
2257 rc = _sde_hdmi_update_pll_delta(display, value);
2258 else if (property_index == CONNECTOR_PROP_HPD_OFF)
2259 rc = _sde_hdmi_update_hpd_state(display, value);
2264 int sde_hdmi_get_property(struct drm_connector *connector,
2265 struct drm_connector_state *state,
2270 struct sde_hdmi *hdmi_display = display;
2273 if (!connector || !hdmi_display) {
2274 SDE_ERROR("connector=%pK or display=%pK is NULL\n",
2275 connector, hdmi_display);
2279 mutex_lock(&hdmi_display->display_lock);
2280 if (property_index == CONNECTOR_PROP_PLL_ENABLE)
2281 *value = hdmi_display->pll_update_enable ? 1 : 0;
2282 if (property_index == CONNECTOR_PROP_HDCP_VERSION)
2283 *value = hdmi_display->sink_hdcp_ver;
2284 mutex_unlock(&hdmi_display->display_lock);
2289 u32 sde_hdmi_get_num_of_displays(void)
2292 struct sde_hdmi *display;
2294 mutex_lock(&sde_hdmi_list_lock);
2296 list_for_each_entry(display, &sde_hdmi_list, list)
2299 mutex_unlock(&sde_hdmi_list_lock);
2303 int sde_hdmi_get_displays(void **display_array, u32 max_display_count)
2305 struct sde_hdmi *display;
2310 if (!display_array || !max_display_count) {
2312 SDE_ERROR("invalid param\n");
2316 mutex_lock(&sde_hdmi_list_lock);
2317 list_for_each_entry(display, &sde_hdmi_list, list) {
2318 if (i >= max_display_count)
2320 display_array[i++] = display;
2322 mutex_unlock(&sde_hdmi_list_lock);
2327 int sde_hdmi_connector_pre_deinit(struct drm_connector *connector,
2330 struct sde_hdmi *sde_hdmi = (struct sde_hdmi *)display;
2332 if (!sde_hdmi || !sde_hdmi->ctrl.ctrl) {
2333 SDE_ERROR("sde_hdmi=%p or hdmi is NULL\n", sde_hdmi);
2337 _sde_hdmi_hpd_disable(sde_hdmi);
2342 static void _sde_hdmi_get_tx_version(struct sde_hdmi *sde_hdmi)
2344 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
2346 sde_hdmi->hdmi_tx_version = hdmi_read(hdmi, REG_HDMI_VERSION);
2347 sde_hdmi->hdmi_tx_major_version =
2348 SDE_GET_MAJOR_VER(sde_hdmi->hdmi_tx_version);
2350 switch (sde_hdmi->hdmi_tx_major_version) {
2351 case (HDMI_TX_VERSION_3):
2352 sde_hdmi->max_pclk_khz = HDMI_TX_3_MAX_PCLK_RATE;
2354 case (HDMI_TX_VERSION_4):
2355 sde_hdmi->max_pclk_khz = HDMI_TX_4_MAX_PCLK_RATE;
2358 sde_hdmi->max_pclk_khz = HDMI_DEFAULT_MAX_PCLK_RATE;
2361 SDE_DEBUG("sde_hdmi->hdmi_tx_version = 0x%x\n",
2362 sde_hdmi->hdmi_tx_version);
2363 SDE_DEBUG("sde_hdmi->hdmi_tx_major_version = 0x%x\n",
2364 sde_hdmi->hdmi_tx_major_version);
2365 SDE_DEBUG("sde_hdmi->max_pclk_khz = 0x%x\n",
2366 sde_hdmi->max_pclk_khz);
2369 static int sde_hdmi_tx_check_capability(struct sde_hdmi *sde_hdmi)
2371 u32 hdmi_disabled, hdcp_disabled, reg_val;
2373 struct hdmi *hdmi = sde_hdmi->ctrl.ctrl;
2375 /* check if hdmi and hdcp are disabled */
2376 if (sde_hdmi->hdmi_tx_major_version < HDMI_TX_VERSION_4) {
2377 hdcp_disabled = hdmi_qfprom_read(hdmi,
2378 QFPROM_RAW_FEAT_CONFIG_ROW0_LSB) & BIT(31);
2380 hdmi_disabled = hdmi_qfprom_read(hdmi,
2381 QFPROM_RAW_FEAT_CONFIG_ROW0_MSB) & BIT(0);
2383 reg_val = hdmi_qfprom_read(hdmi,
2384 QFPROM_RAW_FEAT_CONFIG_ROW0_LSB + QFPROM_RAW_VERSION_4);
2385 hdcp_disabled = reg_val & BIT(12);
2387 hdmi_disabled = reg_val & BIT(13);
2389 reg_val = hdmi_qfprom_read(hdmi, SEC_CTRL_HW_VERSION);
2391 SDE_DEBUG("SEC_CTRL_HW_VERSION reg_val = 0x%x\n", reg_val);
2393 * With HDCP enabled on capable hardware, check if HW
2394 * or SW keys should be used.
2396 if (!hdcp_disabled && (reg_val >= HDCP_SEL_MIN_SEC_VERSION)) {
2397 reg_val = hdmi_qfprom_read(hdmi,
2398 QFPROM_RAW_FEAT_CONFIG_ROW0_MSB +
2399 QFPROM_RAW_VERSION_4);
2401 if (!(reg_val & BIT(23)))
2402 sde_hdmi->hdcp1_use_sw_keys = true;
2406 if (sde_hdmi->hdmi_tx_major_version >= HDMI_TX_VERSION_4)
2407 sde_hdmi->dc_feature_supported = true;
2409 SDE_DEBUG("%s: Features <HDMI:%s, HDCP:%s, Deep Color:%s>\n", __func__,
2410 hdmi_disabled ? "OFF" : "ON",
2411 hdcp_disabled ? "OFF" : "ON",
2412 sde_hdmi->dc_feature_supported ? "ON" : "OFF");
2414 if (hdmi_disabled) {
2415 DEV_ERR("%s: HDMI disabled\n", __func__);
2420 sde_hdmi->hdcp14_present = !hdcp_disabled;
2424 } /* hdmi_tx_check_capability */
2426 static int _sde_hdmi_init_hdcp(struct sde_hdmi *hdmi_ctrl)
2428 struct sde_hdcp_init_data hdcp_init_data;
2434 SDE_ERROR("sde_hdmi is NULL\n");
2438 hdmi = hdmi_ctrl->ctrl.ctrl;
2439 hdcp_init_data.phy_addr = hdmi->mmio_phy_addr;
2440 hdcp_init_data.core_io = &hdmi_ctrl->io[HDMI_TX_CORE_IO];
2441 hdcp_init_data.qfprom_io = &hdmi_ctrl->io[HDMI_TX_QFPROM_IO];
2442 hdcp_init_data.hdcp_io = &hdmi_ctrl->io[HDMI_TX_HDCP_IO];
2443 hdcp_init_data.mutex = &hdmi_ctrl->hdcp_mutex;
2444 hdcp_init_data.workq = hdmi->workq;
2445 hdcp_init_data.notify_status = sde_hdmi_tx_hdcp_cb;
2446 hdcp_init_data.cb_data = (void *)hdmi_ctrl;
2447 hdcp_init_data.hdmi_tx_ver = hdmi_ctrl->hdmi_tx_major_version;
2448 hdcp_init_data.sec_access = true;
2449 hdcp_init_data.client_id = HDCP_CLIENT_HDMI;
2450 hdcp_init_data.ddc_ctrl = &hdmi_ctrl->ddc_ctrl;
2452 if (hdmi_ctrl->hdcp14_present) {
2453 hdcp_data = sde_hdcp_1x_init(&hdcp_init_data);
2455 if (IS_ERR_OR_NULL(hdcp_data)) {
2456 DEV_ERR("%s: hdcp 1.4 init failed\n", __func__);
2461 hdmi_ctrl->hdcp_feat_data[SDE_HDCP_1x] = hdcp_data;
2462 SDE_HDMI_DEBUG("%s: HDCP 1.4 initialized\n", __func__);
2466 hdcp_data = sde_hdmi_hdcp2p2_init(&hdcp_init_data);
2468 if (IS_ERR_OR_NULL(hdcp_data)) {
2469 DEV_ERR("%s: hdcp 2.2 init failed\n", __func__);
2473 hdmi_ctrl->hdcp_feat_data[SDE_HDCP_2P2] = hdcp_data;
2474 SDE_HDMI_DEBUG("%s: HDCP 2.2 initialized\n", __func__);
2481 int sde_hdmi_connector_post_init(struct drm_connector *connector,
2486 struct sde_hdmi *sde_hdmi = (struct sde_hdmi *)display;
2490 SDE_ERROR("sde_hdmi is NULL\n");
2494 hdmi = sde_hdmi->ctrl.ctrl;
2496 SDE_ERROR("hdmi is NULL\n");
2501 sde_kms_info_add_keystr(info,
2503 sde_hdmi->display_type);
2505 hdmi->connector = connector;
2506 INIT_WORK(&sde_hdmi->hpd_work, _sde_hdmi_hotplug_work);
2508 if (sde_hdmi->non_pluggable) {
2509 /* Disable HPD interrupt */
2510 hdmi_write(hdmi, REG_HDMI_HPD_CTRL, 0);
2511 hdmi_write(hdmi, REG_HDMI_HPD_INT_CTRL, 0);
2512 hdmi_write(hdmi, REG_HDMI_HPD_INT_STATUS, 0);
2514 /* Enable HPD detection if non_pluggable flag is not defined */
2515 rc = _sde_hdmi_hpd_enable(sde_hdmi);
2517 SDE_ERROR("failed to enable HPD: %d\n", rc);
2520 _sde_hdmi_get_tx_version(sde_hdmi);
2522 sde_hdmi_tx_check_capability(sde_hdmi);
2524 _sde_hdmi_init_hdcp(sde_hdmi);
2529 int sde_hdmi_start_hdcp(struct drm_connector *connector)
2532 struct sde_connector *c_conn = to_sde_connector(connector);
2533 struct sde_hdmi *display = (struct sde_hdmi *)c_conn->display;
2534 struct hdmi *hdmi = display->ctrl.ctrl;
2537 SDE_ERROR("%s: invalid input\n", __func__);
2541 if (!sde_hdmi_tx_is_hdcp_enabled(display))
2544 if (sde_hdmi_tx_is_encryption_set(display))
2545 sde_hdmi_config_avmute(hdmi, true);
2547 rc = display->hdcp_ops->authenticate(display->hdcp_data);
2549 SDE_ERROR("%s: hdcp auth failed. rc=%d\n", __func__, rc);
2554 enum drm_connector_status
2555 sde_hdmi_connector_detect(struct drm_connector *connector,
2559 enum drm_connector_status status = connector_status_unknown;
2560 struct msm_display_info info;
2563 if (!connector || !display) {
2564 SDE_ERROR("connector=%p or display=%p is NULL\n",
2565 connector, display);
2569 /* get display dsi_info */
2570 memset(&info, 0x0, sizeof(info));
2571 rc = sde_hdmi_get_info(&info, display);
2573 SDE_ERROR("failed to get display info, rc=%d\n", rc);
2574 return connector_status_disconnected;
2577 if (info.capabilities & MSM_DISPLAY_CAP_HOT_PLUG)
2578 status = (info.is_connected ? connector_status_connected :
2579 connector_status_disconnected);
2581 status = connector_status_connected;
2583 connector->display_info.width_mm = info.width_mm;
2584 connector->display_info.height_mm = info.height_mm;
2589 int sde_hdmi_pre_kickoff(struct drm_connector *connector,
2591 struct msm_display_kickoff_params *params)
2593 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
2594 struct drm_msm_ext_panel_hdr_ctrl *hdr_ctrl;
2595 struct drm_msm_ext_panel_hdr_metadata *hdr_meta;
2598 if (!connector || !display || !params ||
2599 !params->hdr_ctrl) {
2600 pr_err("Invalid params\n");
2604 hdr_ctrl = params->hdr_ctrl;
2605 hdr_meta = &hdr_ctrl->hdr_meta;
2608 SDE_ERROR("Invalid params\n");
2612 hdr_op = sde_hdmi_hdr_get_ops(hdmi_display->curr_hdr_state,
2613 hdr_ctrl->hdr_state);
2615 if (hdr_op == HDR_SEND_INFO) {
2616 if (connector->hdr_supported)
2617 sde_hdmi_panel_set_hdr_infoframe(display,
2618 &hdr_ctrl->hdr_meta);
2620 sde_hdmi_update_colorimetry(hdmi_display,
2623 sde_hdmi_update_colorimetry(hdmi_display,
2625 } else if (hdr_op == HDR_CLEAR_INFO)
2626 sde_hdmi_clear_hdr_infoframe(display);
2628 hdmi_display->curr_hdr_state = hdr_ctrl->hdr_state;
2633 bool sde_hdmi_mode_needs_full_range(void *display)
2635 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
2636 struct drm_display_mode *mode;
2637 u32 mode_fmt_flags = 0;
2640 if (!hdmi_display) {
2641 SDE_ERROR("invalid input\n");
2645 mode = &hdmi_display->mode;
2646 /* Cache the format flags before clearing */
2647 mode_fmt_flags = mode->flags;
2649 * Clear the RGB/YUV format flags before calling upstream API
2650 * as the API also compares the flags and then returns a mode
2652 mode->flags &= ~SDE_DRM_MODE_FLAG_FMT_MASK;
2653 cea_mode = drm_match_cea_mode(mode);
2654 /* Restore the format flags */
2655 mode->flags = mode_fmt_flags;
2657 if (cea_mode > SDE_HDMI_VIC_640x480)
2663 enum sde_csc_type sde_hdmi_get_csc_type(struct drm_connector *conn,
2666 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
2667 struct sde_connector_state *c_state;
2668 struct drm_msm_ext_panel_hdr_ctrl *hdr_ctrl;
2669 struct drm_msm_ext_panel_hdr_metadata *hdr_meta;
2671 if (!hdmi_display || !conn) {
2672 SDE_ERROR("invalid input\n");
2676 c_state = to_sde_connector_state(conn->state);
2679 SDE_ERROR("invalid input\n");
2683 hdr_ctrl = &c_state->hdr_ctrl;
2684 hdr_meta = &hdr_ctrl->hdr_meta;
2686 if ((hdr_ctrl->hdr_state == HDR_ENABLE)
2687 && (hdr_meta->eotf != 0))
2688 return SDE_CSC_RGB2YUV_2020L;
2689 else if (sde_hdmi_mode_needs_full_range(hdmi_display)
2691 return SDE_CSC_RGB2YUV_601FR;
2694 return SDE_CSC_RGB2YUV_601L;
2697 int sde_hdmi_connector_get_modes(struct drm_connector *connector, void *display)
2699 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
2700 struct drm_display_mode *mode, *m;
2703 if (!connector || !display) {
2704 SDE_ERROR("connector=%p or display=%p is NULL\n",
2705 connector, display);
2709 if (hdmi_display->non_pluggable) {
2710 list_for_each_entry(mode, &hdmi_display->mode_list, head) {
2711 m = drm_mode_duplicate(connector->dev, mode);
2713 SDE_ERROR("failed to add hdmi mode %dx%d\n",
2714 mode->hdisplay, mode->vdisplay);
2717 drm_mode_probed_add(connector, m);
2719 ret = hdmi_display->num_of_modes;
2721 /* pluggable case assumes EDID is read when HPD */
2722 ret = _sde_edid_update_modes(connector,
2723 hdmi_display->edid_ctrl);
2729 enum drm_mode_status sde_hdmi_mode_valid(struct drm_connector *connector,
2730 struct drm_display_mode *mode,
2733 struct sde_hdmi *hdmi_display = (struct sde_hdmi *)display;
2735 struct msm_drm_private *priv;
2736 struct msm_kms *kms;
2737 long actual, requested;
2739 if (!connector || !display || !mode) {
2740 SDE_ERROR("connector=%p or display=%p or mode=%p is NULL\n",
2741 connector, display, mode);
2745 hdmi = hdmi_display->ctrl.ctrl;
2746 priv = connector->dev->dev_private;
2748 requested = 1000 * mode->clock;
2749 actual = kms->funcs->round_pixclk(kms,
2750 requested, hdmi->encoder);
2752 SDE_HDMI_DEBUG("requested=%ld, actual=%ld", requested, actual);
2754 if (actual != requested)
2755 return MODE_CLOCK_RANGE;
2757 /* if no format flags are present remove the mode */
2758 if (!(mode->flags & SDE_DRM_MODE_FLAG_FMT_MASK)) {
2759 SDE_HDMI_DEBUG("removing following mode from list\n");
2760 drm_mode_debug_printmodeline(mode);
2767 int sde_hdmi_dev_init(struct sde_hdmi *display)
2770 SDE_ERROR("Invalid params\n");
2776 int sde_hdmi_dev_deinit(struct sde_hdmi *display)
2779 SDE_ERROR("Invalid params\n");
2782 if (display->hdcp_feat_data[SDE_HDCP_1x])
2783 sde_hdcp_1x_deinit(display->hdcp_feat_data[SDE_HDCP_1x]);
2785 if (display->hdcp_feat_data[SDE_HDCP_2P2])
2786 sde_hdmi_hdcp2p2_deinit(display->hdcp_feat_data[SDE_HDCP_2P2]);
2791 static int _sde_hdmi_cec_init(struct sde_hdmi *display)
2793 struct platform_device *pdev = display->pdev;
2795 display->notifier = cec_notifier_get(&pdev->dev);
2796 if (!display->notifier) {
2797 SDE_ERROR("CEC notifier get failed\n");
2804 static void _sde_hdmi_cec_deinit(struct sde_hdmi *display)
2806 cec_notifier_set_phys_addr(display->notifier, CEC_PHYS_ADDR_INVALID);
2807 cec_notifier_put(display->notifier);
2810 static int sde_hdmi_bind(struct device *dev, struct device *master, void *data)
2813 struct sde_hdmi_ctrl *display_ctrl = NULL;
2814 struct sde_hdmi *display = NULL;
2815 struct drm_device *drm = NULL;
2816 struct msm_drm_private *priv = NULL;
2817 struct platform_device *pdev = to_platform_device(dev);
2819 SDE_HDMI_DEBUG(" %s +\n", __func__);
2820 if (!dev || !pdev || !master) {
2821 pr_err("invalid param(s), dev %pK, pdev %pK, master %pK\n",
2826 drm = dev_get_drvdata(master);
2827 display = platform_get_drvdata(pdev);
2828 if (!drm || !display) {
2829 pr_err("invalid param(s), drm %pK, display %pK\n",
2834 priv = drm->dev_private;
2835 mutex_lock(&display->display_lock);
2837 rc = _sde_hdmi_debugfs_init(display);
2839 SDE_ERROR("[%s]Debugfs init failed, rc=%d\n",
2844 rc = _sde_hdmi_ext_disp_init(display);
2846 SDE_ERROR("[%s]Ext Disp init failed, rc=%d\n",
2851 rc = _sde_hdmi_cec_init(display);
2853 SDE_ERROR("[%s]CEC init failed, rc=%d\n",
2858 display->edid_ctrl = sde_edid_init();
2859 if (!display->edid_ctrl) {
2860 SDE_ERROR("[%s]sde edid init failed\n",
2866 display_ctrl = &display->ctrl;
2867 display_ctrl->ctrl = priv->hdmi;
2868 display->drm_dev = drm;
2870 _sde_hdmi_map_regs(display, priv->hdmi);
2871 _sde_hdmi_init_ddc(display, priv->hdmi);
2873 display->enc_lvl = HDCP_STATE_AUTH_ENC_NONE;
2875 INIT_DELAYED_WORK(&display->hdcp_cb_work,
2876 sde_hdmi_tx_hdcp_cb_work);
2877 mutex_init(&display->hdcp_mutex);
2878 mutex_unlock(&display->display_lock);
2882 (void)_sde_hdmi_cec_deinit(display);
2884 (void)_sde_hdmi_debugfs_deinit(display);
2886 mutex_unlock(&display->display_lock);
2891 static void sde_hdmi_unbind(struct device *dev, struct device *master,
2894 struct sde_hdmi *display = NULL;
2897 SDE_ERROR("invalid params\n");
2901 display = platform_get_drvdata(to_platform_device(dev));
2903 SDE_ERROR("Invalid display device\n");
2906 mutex_lock(&display->display_lock);
2907 (void)_sde_hdmi_debugfs_deinit(display);
2908 (void)sde_edid_deinit((void **)&display->edid_ctrl);
2909 (void)_sde_hdmi_cec_deinit(display);
2910 display->drm_dev = NULL;
2911 mutex_unlock(&display->display_lock);
2914 static const struct component_ops sde_hdmi_comp_ops = {
2915 .bind = sde_hdmi_bind,
2916 .unbind = sde_hdmi_unbind,
2919 static int _sde_hdmi_parse_dt_modes(struct device_node *np,
2920 struct list_head *head,
2924 struct drm_display_mode *mode;
2926 struct device_node *node = NULL;
2927 struct device_node *root_node = NULL;
2929 u32 h_front_porch, h_pulse_width, h_back_porch;
2930 u32 v_front_porch, v_pulse_width, v_back_porch;
2931 bool h_active_high, v_active_high;
2933 root_node = of_get_child_by_name(np, "qcom,customize-modes");
2935 root_node = of_parse_phandle(np, "qcom,customize-modes", 0);
2937 DRM_INFO("No entry present for qcom,customize-modes");
2941 for_each_child_of_node(root_node, node) {
2943 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
2945 SDE_ERROR("Out of memory\n");
2950 rc = of_property_read_string(node, "qcom,mode-name",
2953 SDE_ERROR("failed to read qcom,mode-name, rc=%d\n", rc);
2956 strlcpy(mode->name, name, DRM_DISPLAY_MODE_LEN);
2958 rc = of_property_read_u32(node, "qcom,mode-h-active",
2961 SDE_ERROR("failed to read h-active, rc=%d\n", rc);
2965 rc = of_property_read_u32(node, "qcom,mode-h-front-porch",
2968 SDE_ERROR("failed to read h-front-porch, rc=%d\n", rc);
2972 rc = of_property_read_u32(node, "qcom,mode-h-pulse-width",
2975 SDE_ERROR("failed to read h-pulse-width, rc=%d\n", rc);
2979 rc = of_property_read_u32(node, "qcom,mode-h-back-porch",
2982 SDE_ERROR("failed to read h-back-porch, rc=%d\n", rc);
2986 h_active_high = of_property_read_bool(node,
2987 "qcom,mode-h-active-high");
2989 rc = of_property_read_u32(node, "qcom,mode-v-active",
2992 SDE_ERROR("failed to read v-active, rc=%d\n", rc);
2996 rc = of_property_read_u32(node, "qcom,mode-v-front-porch",
2999 SDE_ERROR("failed to read v-front-porch, rc=%d\n", rc);
3003 rc = of_property_read_u32(node, "qcom,mode-v-pulse-width",
3006 SDE_ERROR("failed to read v-pulse-width, rc=%d\n", rc);
3010 rc = of_property_read_u32(node, "qcom,mode-v-back-porch",
3013 SDE_ERROR("failed to read v-back-porch, rc=%d\n", rc);
3017 v_active_high = of_property_read_bool(node,
3018 "qcom,mode-v-active-high");
3020 rc = of_property_read_u32(node, "qcom,mode-refresh-rate",
3023 SDE_ERROR("failed to read refresh-rate, rc=%d\n", rc);
3027 rc = of_property_read_u32(node, "qcom,mode-clock-in-khz",
3030 SDE_ERROR("failed to read clock, rc=%d\n", rc);
3034 mode->hsync_start = mode->hdisplay + h_front_porch;
3035 mode->hsync_end = mode->hsync_start + h_pulse_width;
3036 mode->htotal = mode->hsync_end + h_back_porch;
3037 mode->vsync_start = mode->vdisplay + v_front_porch;
3038 mode->vsync_end = mode->vsync_start + v_pulse_width;
3039 mode->vtotal = mode->vsync_end + v_back_porch;
3041 flags |= DRM_MODE_FLAG_PHSYNC;
3043 flags |= DRM_MODE_FLAG_NHSYNC;
3045 flags |= DRM_MODE_FLAG_PVSYNC;
3047 flags |= DRM_MODE_FLAG_NVSYNC;
3049 flags |= DRM_MODE_FLAG_SUPPORTS_RGB;
3050 mode->flags = flags;
3054 list_add_tail(&mode->head, head);
3057 SDE_DEBUG("mode[%d] h[%d,%d,%d,%d] v[%d,%d,%d,%d] %d %xH %d\n",
3058 mode_count - 1, mode->hdisplay, mode->hsync_start,
3059 mode->hsync_end, mode->htotal, mode->vdisplay,
3060 mode->vsync_start, mode->vsync_end, mode->vtotal,
3061 mode->vrefresh, mode->flags, mode->clock);
3070 *num_of_modes = mode_count;
3076 static int _sde_hdmi_parse_dt(struct device_node *node,
3077 struct sde_hdmi *display)
3081 struct hdmi *hdmi = display->ctrl.ctrl;
3083 display->name = of_get_property(node, "label", NULL);
3085 display->display_type = of_get_property(node,
3086 "qcom,display-type", NULL);
3087 if (!display->display_type)
3088 display->display_type = "unknown";
3090 display->non_pluggable = of_property_read_bool(node,
3091 "qcom,non-pluggable");
3093 display->skip_ddc = of_property_read_bool(node,
3095 if (!display->non_pluggable)
3096 hdmi_i2c_destroy(hdmi->i2c);
3098 rc = _sde_hdmi_parse_dt_modes(node, &display->mode_list,
3099 &display->num_of_modes);
3101 SDE_ERROR("parse_dt_modes failed rc=%d\n", rc);
3106 static int _sde_hdmi_dev_probe(struct platform_device *pdev)
3109 struct sde_hdmi *display;
3115 if (!pdev || !pdev->dev.of_node) {
3116 SDE_ERROR("pdev not found\n");
3120 display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
3124 INIT_LIST_HEAD(&display->mode_list);
3125 rc = _sde_hdmi_parse_dt(pdev->dev.of_node, display);
3127 SDE_ERROR("parse dt failed, rc=%d\n", rc);
3129 mutex_init(&display->display_lock);
3130 display->pdev = pdev;
3131 platform_set_drvdata(pdev, display);
3132 mutex_lock(&sde_hdmi_list_lock);
3133 list_add(&display->list, &sde_hdmi_list);
3134 mutex_unlock(&sde_hdmi_list_lock);
3135 if (!sde_hdmi_dev_init(display)) {
3136 ret = component_add(&pdev->dev, &sde_hdmi_comp_ops);
3138 pr_err("component add failed\n");
3146 devm_kfree(&pdev->dev, display);
3150 static int _sde_hdmi_dev_remove(struct platform_device *pdev)
3152 struct sde_hdmi *display;
3153 struct sde_hdmi *pos, *tmp;
3154 struct drm_display_mode *mode, *n;
3157 SDE_ERROR("Invalid device\n");
3161 display = platform_get_drvdata(pdev);
3163 mutex_lock(&sde_hdmi_list_lock);
3164 list_for_each_entry_safe(pos, tmp, &sde_hdmi_list, list) {
3165 if (pos == display) {
3166 list_del(&display->list);
3170 mutex_unlock(&sde_hdmi_list_lock);
3172 list_for_each_entry_safe(mode, n, &display->mode_list, head) {
3173 list_del(&mode->head);
3177 platform_set_drvdata(pdev, NULL);
3178 devm_kfree(&pdev->dev, display);
3182 static struct platform_driver sde_hdmi_driver = {
3183 .probe = _sde_hdmi_dev_probe,
3184 .remove = _sde_hdmi_dev_remove,
3187 .of_match_table = sde_hdmi_dt_match,
3191 static int sde_hdmi_irqdomain_map(struct irq_domain *domain,
3192 unsigned int irq, irq_hw_number_t hwirq)
3194 struct sde_hdmi *display;
3197 if (!domain || !domain->host_data) {
3198 pr_err("invalid parameters domain\n");
3201 display = domain->host_data;
3203 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_level_irq);
3204 rc = irq_set_chip_data(irq, display);
3209 static const struct irq_domain_ops sde_hdmi_irqdomain_ops = {
3210 .map = sde_hdmi_irqdomain_map,
3211 .xlate = irq_domain_xlate_onecell,
3214 int sde_hdmi_drm_init(struct sde_hdmi *display, struct drm_encoder *enc)
3217 struct msm_drm_private *priv = NULL;
3219 struct platform_device *pdev;
3222 if (!display || !display->drm_dev || !enc) {
3223 SDE_ERROR("display=%p or enc=%p or drm_dev is NULL\n",
3228 mutex_lock(&display->display_lock);
3229 priv = display->drm_dev->dev_private;
3230 hdmi = display->ctrl.ctrl;
3232 if (!priv || !hdmi) {
3233 SDE_ERROR("priv=%p or hdmi=%p is NULL\n",
3235 mutex_unlock(&display->display_lock);
3240 hdmi->dev = display->drm_dev;
3241 hdmi->encoder = enc;
3243 hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
3245 hdmi->bridge = sde_hdmi_bridge_init(hdmi, display);
3246 if (IS_ERR(hdmi->bridge)) {
3247 rc = PTR_ERR(hdmi->bridge);
3248 SDE_ERROR("failed to create HDMI bridge: %d\n", rc);
3249 hdmi->bridge = NULL;
3252 hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
3253 if (hdmi->irq < 0) {
3255 SDE_ERROR("failed to get irq: %d\n", rc);
3259 rc = devm_request_irq(&pdev->dev, hdmi->irq,
3260 _sde_hdmi_irq, IRQF_TRIGGER_HIGH,
3261 "sde_hdmi_isr", display);
3263 SDE_ERROR("failed to request IRQ%u: %d\n",
3268 display->irq_domain = irq_domain_add_linear(pdev->dev.of_node, 8,
3269 &sde_hdmi_irqdomain_ops, display);
3270 if (!display->irq_domain) {
3271 SDE_ERROR("failed to create IRQ domain\n");
3275 enc->bridge = hdmi->bridge;
3276 priv->bridges[priv->num_bridges++] = hdmi->bridge;
3279 * After initialising HDMI bridge, we need to check
3280 * whether the early display is enabled for HDMI.
3281 * If yes, we need to increase refcount of hdmi power
3282 * clocks. This can skip the clock disabling operation in
3283 * clock_late_init when finding clk.count == 1.
3285 if (display->cont_splash_enabled) {
3286 sde_hdmi_bridge_power_on(hdmi->bridge);
3287 hdmi->power_on = true;
3290 mutex_unlock(&display->display_lock);
3294 /* bridge is normally destroyed by drm: */
3296 hdmi_bridge_destroy(hdmi->bridge);
3297 hdmi->bridge = NULL;
3299 mutex_unlock(&display->display_lock);
3303 int sde_hdmi_drm_deinit(struct sde_hdmi *display)
3308 SDE_ERROR("Invalid params\n");
3312 if (display->irq_domain)
3313 irq_domain_remove(display->irq_domain);
3318 static int __init sde_hdmi_register(void)
3323 rc = platform_driver_register(&sde_hdmi_driver);
3327 static void __exit sde_hdmi_unregister(void)
3329 platform_driver_unregister(&sde_hdmi_driver);
3332 module_init(sde_hdmi_register);
3333 module_exit(sde_hdmi_unregister);