drm/exynos: Debounce gpio hotplug interrupts
[cascardo/linux.git] / drivers / gpu / drm / exynos / exynos_hdmi.c
index 8492ab4..153edeb 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/delay.h>
-#include <linux/pm_runtime.h>
 #include <linux/clk.h>
 #include <linux/regulator/consumer.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_i2c.h>
 #include <linux/of_gpio.h>
 #include <plat/gpio-cfg.h>
 
 #include <drm/exynos_drm.h>
 
 #include "exynos_drm_drv.h"
-#include "exynos_drm_hdmi.h"
+#include "exynos_drm_display.h"
 
 #include "exynos_hdmi.h"
 
-#define MAX_WIDTH              1920
-#define MAX_HEIGHT             1080
 #define get_hdmi_context(dev)  platform_get_drvdata(to_platform_device(dev))
 
+#define HOTPLUG_DEBOUNCE_MS            1100
+
 struct hdmi_resources {
        struct clk                      *hdmi;
        struct clk                      *sclk_hdmi;
@@ -134,19 +135,18 @@ struct hdmi_context {
        unsigned int                    default_win;
        unsigned int                    default_bpp;
        bool                            hpd_handle;
-       bool                            enabled;
        bool                            has_hdmi_sink;
        bool                            has_hdmi_audio;
        bool                            is_soc_exynos5;
        bool                            is_hdmi_powered_on;
+       bool                            video_enabled;
 
        struct resource                 *regs_res;
        void __iomem                    *regs;
        unsigned int                    external_irq;
        unsigned int                    internal_irq;
        unsigned int                    curr_irq;
-       struct workqueue_struct         *wq;
-       struct work_struct              hotplug_work;
+       struct timer_list               hotplug_timer;
 
        struct i2c_client               *ddc_port;
        struct i2c_client               *hdmiphy_port;
@@ -155,7 +155,6 @@ struct hdmi_context {
        int cur_conf;
 
        struct hdmi_resources           res;
-       void                            *parent_ctx;
 };
 
 /* HDMI Version 1.3 */
@@ -437,6 +436,15 @@ struct hdmiphy_config {
 };
 
 static const struct hdmiphy_config phy_configs[] = {
+       {
+               .pixel_clock = 25200000,
+               .conf = {
+                       0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
+                       0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
        {
                .pixel_clock = 27000000,
                .conf = {
@@ -455,6 +463,33 @@ static const struct hdmiphy_config phy_configs[] = {
                        0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
                },
        },
+       {
+               .pixel_clock = 36000000,
+               .conf = {
+                       0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
+                       0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
+       {
+               .pixel_clock = 40000000,
+               .conf = {
+                       0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
+                       0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
+       {
+               .pixel_clock = 65000000,
+               .conf = {
+                       0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
+                       0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
        {
                .pixel_clock = 74176000,
                .conf = {
@@ -473,6 +508,42 @@ static const struct hdmiphy_config phy_configs[] = {
                        0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
                },
        },
+       {
+               .pixel_clock = 83500000,
+               .conf = {
+                       0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
+                       0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
+       {
+               .pixel_clock = 106500000,
+               .conf = {
+                       0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
+                       0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
+       {
+               .pixel_clock = 108000000,
+               .conf = {
+                       0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
+                       0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
+       {
+               .pixel_clock = 146250000,
+               .conf = {
+                       0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
+                       0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
+                       0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
+                       0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
+               },
+       },
        {
                .pixel_clock = 148500000,
                .conf = {
@@ -792,10 +863,10 @@ static int hdmi_v13_conf_index(struct drm_display_mode *mode)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(hdmi_v13_confs); ++i)
-               if (hdmi_v13_confs[i].width == mode->hdisplay &&
-                               hdmi_v13_confs[i].height == mode->vdisplay &&
-                               hdmi_v13_confs[i].vrefresh == mode->vrefresh &&
-                               hdmi_v13_confs[i].interlace ==
+               if (hdmi_v13_confs[i].width == mode->crtc_hdisplay &&
+                       hdmi_v13_confs[i].height == mode->crtc_vdisplay &&
+                       hdmi_v13_confs[i].vrefresh == mode->vrefresh &&
+                       hdmi_v13_confs[i].interlace ==
                                ((mode->flags & DRM_MODE_FLAG_INTERLACE) ?
                                 true : false))
                        return i;
@@ -819,34 +890,30 @@ static bool hdmi_is_connected(void *ctx)
        return true;
 }
 
-static int hdmi_get_edid(void *ctx, struct drm_connector *connector,
-                               u8 *edid, int len)
+static struct edid *hdmi_get_edid(void *ctx, struct drm_connector *connector)
 {
-       struct edid *raw_edid;
        struct hdmi_context *hdata = ctx;
+       struct edid *edid;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", DRM_BASE_ID(connector),
+                       drm_get_connector_name(connector));
 
        if (!hdata->ddc_port)
-               return -ENODEV;
+               return ERR_PTR(-ENODEV);
+
+       edid = drm_get_edid(connector, hdata->ddc_port->adapter);
+       if (!edid)
+               return ERR_PTR(-ENODEV);
 
-       raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
-       if (raw_edid) {
-       /* TODO : Need to call this in exynos_drm_connector.c, do a drm_get_edid
+       /*
+        * TODO : Need to call this in exynos_drm_connector.c, do a drm_get_edid
         * to get the edid and then call drm_detect_hdmi_monitor.
         */
-               hdata->has_hdmi_sink = drm_detect_hdmi_monitor(raw_edid);
-               hdata->has_hdmi_audio = drm_detect_monitor_audio(raw_edid);
-               memcpy(edid, raw_edid, min((1 + raw_edid->extensions)
-                                       * EDID_LENGTH, len));
-               DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
-                       (hdata->has_hdmi_sink ? "hdmi monitor" : "dvi monitor"),
-                       raw_edid->width_cm, raw_edid->height_cm);
-       } else {
-               return -ENODEV;
-       }
+       hdata->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
+       hdata->has_hdmi_audio = drm_detect_monitor_audio(edid);
+       DRM_DEBUG_KMS("%s monitor\n", hdata->has_hdmi_sink ? "hdmi" : "dvi");
 
-       return 0;
+       return edid;
 }
 
 static int hdmi_v13_check_timing(struct fb_videomode *check_timing)
@@ -887,12 +954,11 @@ static int find_hdmiphy_conf(int pixel_clock)
 static int hdmi_v14_check_timing(struct fb_videomode *mode)
 {
        int ret;
+       enum exynos_mixer_mode_type mode_type;
 
-       /*
-        * No support for interlaced since there's no clear way to convert the
-        * timing values in drm_display_mode to exynos register values.
-        */
-       if (mode->vmode == FB_VMODE_INTERLACED)
+       /* Make sure the mixer can generate this mode */
+       mode_type = exynos_mixer_get_mode_type(mode->xres, mode->yres);
+       if (mode_type == EXYNOS_MIXER_MODE_INVALID)
                return -EINVAL;
 
        ret = find_hdmiphy_conf(mode->pixclock);
@@ -920,7 +986,9 @@ void hdmi_reg_infoframe(struct hdmi_context *hdata,
        u32 aspect_ratio;
        u32 mod;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       /* TODO: stringify HDMI_PACKET_TYPE */
+       DRM_DEBUG_KMS("type: %d ver: %d len: %d\n", infoframe->type,
+                       infoframe->ver, infoframe->len);
        mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
        if (!hdata->has_hdmi_sink) {
                hdmi_reg_writeb(hdata, HDMI_VSI_CON,
@@ -977,8 +1045,6 @@ static int hdmi_check_timing(void *ctx, void *timing)
        struct hdmi_context *hdata = ctx;
        struct fb_videomode *check_timing = timing;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
-
        DRM_DEBUG_KMS("[%d]x[%d] [%d]Hz [%x]\n", check_timing->xres,
                        check_timing->yres, check_timing->refresh,
                        check_timing->vmode);
@@ -1171,6 +1237,33 @@ static void hdmi_conf_reset(struct hdmi_context *hdata)
        hdata->hpd_handle = true;
 }
 
+static void hdmi_enable_video(struct hdmi_context *hdata)
+{
+       if (hdata->is_v13)
+               return;
+
+       hdata->video_enabled = true;
+       hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
+}
+
+static void hdmi_disable_video(struct hdmi_context *hdata)
+{
+       if (hdata->is_v13)
+               return;
+
+       /* Set the blue screen color to black */
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_R_0, 0);
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_R_1, 0);
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_G_0, 0);
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_G_1, 0);
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_B_0, 0);
+       hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_B_1, 0);
+
+       /* Enable the "blue screen", which effectively disconnects the mixer */
+       hdata->video_enabled = false;
+       hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_BLUE_SCR_EN);
+}
+
 static void hdmi_conf_init(struct hdmi_context *hdata)
 {
        struct hdmi_infoframe infoframe;
@@ -1187,8 +1280,11 @@ static void hdmi_conf_init(struct hdmi_context *hdata)
        /* choose HDMI mode */
        hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
                HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
-       /* disable bluescreen */
-       hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
+
+       if (hdata->video_enabled)
+               hdmi_enable_video(hdata);
+       else
+               hdmi_disable_video(hdata);
 
        if (!hdata->has_hdmi_sink) {
                /* choose DVI mode */
@@ -1532,6 +1628,8 @@ static void hdmiphy_conf_apply(struct hdmi_context *hdata)
        int ret;
        int i;
 
+       DRM_DEBUG_KMS("\n");
+
        if (!hdata->hdmiphy_port) {
                DRM_ERROR("hdmiphy is not attached\n");
                return;
@@ -1577,7 +1675,7 @@ static void hdmiphy_conf_apply(struct hdmi_context *hdata)
 
 static void hdmi_conf_apply(struct hdmi_context *hdata)
 {
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       DRM_DEBUG_KMS("\n");
 
        hdmiphy_conf_reset(hdata);
        hdmiphy_conf_apply(hdata);
@@ -1600,6 +1698,8 @@ static void hdmi_mode_copy(struct drm_display_mode *dst,
 {
        struct drm_mode_object base;
 
+       DRM_DEBUG_KMS("[MODE:%d:%s]\n", DRM_BASE_ID(src), src->name);
+
        /* following information should be preserved,
         * required for releasing the drm_display_mode node,
         * duplicated to recieve adjustment info. */
@@ -1617,37 +1717,43 @@ static void hdmi_mode_fixup(void *ctx, struct drm_connector *connector,
                                struct drm_display_mode *mode,
                                struct drm_display_mode *adjusted_mode)
 {
-       struct drm_display_mode *m;
+       struct drm_display_mode *t, *con_mode;
        struct hdmi_context *hdata = ctx;
        int index;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       DRM_DEBUG_KMS("[CONNECTOR:%d:%s] [MODE:%d:%s]\n",
+                       DRM_BASE_ID(connector),
+                       drm_get_connector_name(connector),
+                       DRM_BASE_ID(mode), mode->name);
 
-       drm_mode_set_crtcinfo(adjusted_mode, 0);
-
-       if (hdata->is_v13)
-               index = hdmi_v13_conf_index(adjusted_mode);
-       else
-               index = find_hdmiphy_conf(adjusted_mode->clock * 1000);
-
-       /* just return if user desired mode exists. */
-       if (index >= 0)
-               return;
+       /*
+        * Match the incoming mode to a mode in the connector list and copy it
+        * over. This is important since this might be an adjusted mode from the
+        * mixer and those have differing crtc_* values.
+        */
+       list_for_each_entry_safe(con_mode, t, &connector->modes, head) {
+               if (mode->hdisplay == con_mode->hdisplay &&
+                   mode->vdisplay == con_mode->vdisplay &&
+                   mode->clock == con_mode->clock) {
+                       hdmi_mode_copy(adjusted_mode, con_mode);
+                       return;
+               }
+       }
 
        /*
-        * otherwise, find the most suitable mode among modes and change it
-        * to adjusted_mode.
+        * We didn't find a mode which matched the desired resolution, so just
+        * find something with the same clock.
         */
-       list_for_each_entry(m, &connector->modes, head) {
+       list_for_each_entry_safe(con_mode, t, &connector->modes, head) {
                if (hdata->is_v13)
-                       index = hdmi_v13_conf_index(m);
+                       index = hdmi_v13_conf_index(con_mode);
                else
-                       index = find_hdmiphy_conf(m->clock * 1000);
+                       index = find_hdmiphy_conf(con_mode->clock * 1000);
 
                if (index >= 0) {
                        DRM_INFO("desired mode doesn't exist so\n");
                        DRM_INFO("use the most suitable mode among modes.\n");
-                       hdmi_mode_copy(adjusted_mode, m);
+                       hdmi_mode_copy(adjusted_mode, con_mode);
                        break;
                }
        }
@@ -1667,47 +1773,91 @@ static void hdmi_v14_mode_set(struct hdmi_context *hdata,
        struct hdmi_core_regs *core = &hdata->mode_conf.core;
        struct hdmi_tg_regs *tg = &hdata->mode_conf.tg;
 
+       DRM_DEBUG_KMS("[MODE:%d:%s]\n", DRM_BASE_ID(m), m->name);
+
        hdata->mode_conf.vic = drm_match_cea_mode(m);
 
        hdata->mode_conf.pixel_clock = m->clock * 1000;
-       hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
-       hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
-       hdmi_set_reg(core->v_line, 2, m->vtotal);
-       hdmi_set_reg(core->h_line, 2, m->htotal);
+       hdmi_set_reg(core->h_blank, 2, m->crtc_htotal - m->crtc_hdisplay);
+       hdmi_set_reg(core->v_line, 2, m->crtc_vtotal);
+       hdmi_set_reg(core->h_line, 2, m->crtc_htotal);
        hdmi_set_reg(core->hsync_pol, 1,
                        (m->flags & DRM_MODE_FLAG_NHSYNC)  ? 1 : 0);
        hdmi_set_reg(core->vsync_pol, 1,
                        (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
        hdmi_set_reg(core->int_pro_mode, 1,
-                       (m->flags >> DRM_MODE_FLAG_INTERLACE) & 0x01);
-       /* Quirk requirement for exynos 5 HDMI IP design,
+                       (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
+
+       /*
+        * Quirk requirement for exynos 5 HDMI IP design,
         * 2 pixels less than the actual calculation for hsync_start
         * and end.
         */
-       hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
-       hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
-       hdmi_set_reg(core->v_sync_line_bef_2, 2, m->vsync_end - m->vdisplay);
-       hdmi_set_reg(core->v_sync_line_bef_1, 2, m->vsync_start - m->vdisplay);
+
+       /* Following values & calculations differ for different type of modes */
+       if (m->flags & DRM_MODE_FLAG_INTERLACE) {
+               /* Interlaced Mode */
+               hdmi_set_reg(core->v_sync_line_bef_2, 2,
+                       (m->crtc_vsync_end - m->crtc_vdisplay) / 2);
+               hdmi_set_reg(core->v_sync_line_bef_1, 2,
+                       (m->crtc_vsync_start - m->crtc_vdisplay) / 2);
+               hdmi_set_reg(core->v2_blank, 2, m->crtc_vtotal / 2);
+               hdmi_set_reg(core->v1_blank, 2,
+                               (m->crtc_vtotal - m->crtc_vdisplay) / 2);
+               hdmi_set_reg(core->v_blank_f0, 2,
+                       (m->crtc_vtotal +
+                       ((m->crtc_vsync_end - m->crtc_vsync_start) * 4) + 5)
+                       / 2);
+               hdmi_set_reg(core->v_blank_f1, 2, m->crtc_vtotal);
+               hdmi_set_reg(core->v_sync_line_aft_2, 2,
+                       (m->crtc_vtotal / 2) + 7);
+               hdmi_set_reg(core->v_sync_line_aft_1, 2,
+                       (m->crtc_vtotal / 2) + 2);
+               hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
+                       (m->crtc_htotal / 2) +
+                       (m->crtc_hsync_start - m->crtc_hdisplay));
+               hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
+                       (m->crtc_htotal / 2) +
+                       (m->crtc_hsync_start - m->crtc_hdisplay));
+               hdmi_set_reg(tg->vact_st, 2,
+                       (m->crtc_vtotal - m->crtc_vdisplay) / 2);
+               hdmi_set_reg(tg->vact_sz, 2, m->crtc_vdisplay / 2);
+               hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
+               hdmi_set_reg(tg->vact_st3, 2, 0x0);
+               hdmi_set_reg(tg->vact_st4, 2, 0x0);
+       } else {
+               /* Progressive Mode */
+               hdmi_set_reg(core->v_sync_line_bef_2, 2,
+                       m->crtc_vsync_end - m->crtc_vdisplay);
+               hdmi_set_reg(core->v_sync_line_bef_1, 2,
+                       m->crtc_vsync_start - m->crtc_vdisplay);
+               hdmi_set_reg(core->v2_blank, 2, m->crtc_vtotal);
+               hdmi_set_reg(core->v1_blank, 2,
+                       m->crtc_vtotal - m->crtc_vdisplay);
+               hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
+               hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
+               hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
+               hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
+               hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
+               hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
+               hdmi_set_reg(tg->vact_st, 2, m->crtc_vtotal - m->crtc_vdisplay);
+               hdmi_set_reg(tg->vact_sz, 2, m->crtc_vdisplay);
+               hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
+               hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
+               hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
+       }
+
+       /* Following values & calculations are same irrespective of mode type */
+       hdmi_set_reg(core->h_sync_start, 2,
+               m->crtc_hsync_start - m->crtc_hdisplay - 2);
+       hdmi_set_reg(core->h_sync_end, 2,
+               m->crtc_hsync_end - m->crtc_hdisplay - 2);
        hdmi_set_reg(core->vact_space_1, 2, 0xffff);
        hdmi_set_reg(core->vact_space_2, 2, 0xffff);
        hdmi_set_reg(core->vact_space_3, 2, 0xffff);
        hdmi_set_reg(core->vact_space_4, 2, 0xffff);
        hdmi_set_reg(core->vact_space_5, 2, 0xffff);
        hdmi_set_reg(core->vact_space_6, 2, 0xffff);
-
-       /*
-        * The following values can be different when using interlaced mode.
-        * Unfortunately the datasheet doesn't describe them. This is why we
-        * reject interlaced modes. Once this is fixed, we can remove that
-        * restriction.
-        */
-       hdmi_set_reg(core->v2_blank, 2, m->vtotal);
-       hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
-       hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
-       hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
-       hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
-       hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
-       hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
        hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
        hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
        hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
@@ -1723,30 +1873,35 @@ static void hdmi_v14_mode_set(struct hdmi_context *hdata,
 
        /* Timing generator registers */
        hdmi_set_reg(tg->cmd, 1, 0x0);
-       hdmi_set_reg(tg->h_fsz, 2, m->htotal);
-       hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
-       hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
-       hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
+       hdmi_set_reg(tg->h_fsz, 2, m->crtc_htotal);
+       hdmi_set_reg(tg->hact_st, 2, m->crtc_htotal - m->crtc_hdisplay);
+       hdmi_set_reg(tg->hact_sz, 2, m->crtc_hdisplay);
+       hdmi_set_reg(tg->v_fsz, 2, m->crtc_vtotal);
        hdmi_set_reg(tg->vsync, 2, 0x1);
        hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
-       hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
-       hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
        hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
-       hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
-       hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
-       hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
        hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
        hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
        hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
        hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
        hdmi_set_reg(tg->tg_3d, 1, 0x0);
+
+       /* Workaround 4 implementation for 1440x900 resolution support */
+       if (hdata->is_soc_exynos5) {
+               if (m->crtc_hdisplay == 1440 && m->crtc_vdisplay == 900 &&
+                   m->clock == 106500) {
+                       hdmi_set_reg(tg->hact_st, 2,
+                               m->crtc_htotal - m->crtc_hdisplay - 0xe0);
+                       hdmi_set_reg(tg->hact_sz, 2, m->crtc_hdisplay + 0xe0);
+               }
+       }
 }
 
-static void hdmi_mode_set(void *ctx, void *mode)
+static void hdmi_mode_set(void *ctx, struct drm_display_mode *mode)
 {
        struct hdmi_context *hdata = ctx;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       DRM_DEBUG_KMS("[MODE:%d:%s]\n", DRM_BASE_ID(mode), mode->name);
 
        if (hdata->is_v13)
                hdata->cur_conf = hdmi_v13_conf_index(mode);
@@ -1754,36 +1909,161 @@ static void hdmi_mode_set(void *ctx, void *mode)
                hdmi_v14_mode_set(hdata, mode);
 }
 
-static void hdmi_commit(void *ctx)
+static int hdmiphy_update_bits(struct i2c_client *client, u8 *reg_cache,
+                              u8 reg, u8 mask, u8 val)
 {
-       struct hdmi_context *hdata = ctx;
+       int ret;
+       u8 buffer[2];
+
+       buffer[0] = reg;
+       buffer[1] = (reg_cache[reg] & ~mask) | (val & mask);
+       reg_cache[reg] = buffer[1];
+
+       ret = i2c_master_send(client, buffer, 2);
+       if (ret != 2)
+               return -EIO;
+
+       return 0;
+}
+
+static int hdmiphy_s_power(struct i2c_client *client, bool on)
+{
+       u8 reg_cache[32] = { 0 };
+       u8 buffer[2];
+       int ret;
+
+       DRM_DEBUG_KMS("%s\n", on ? "on" : "off");
+
+       /* Cache all 32 registers to make the code below faster */
+       buffer[0] = 0x0;
+       ret = i2c_master_send(client, buffer, 1);
+       if (ret != 1) {
+               ret = -EIO;
+               goto exit;
+       }
+       ret = i2c_master_recv(client, reg_cache, 32);
+       if (ret != 32) {
+               ret = -EIO;
+               goto exit;
+       }
+
+       /* Go to/from configuration from/to operation mode */
+       ret = hdmiphy_update_bits(client, reg_cache, 0x1f, 0xff,
+                                 on ? 0x80 : 0x00);
+       if (ret)
+               goto exit;
+
+       /*
+        * Turn off undocumented "oscpad" if !on; it turns on again in
+        * hdmiphy_conf_apply()
+        */
+       if (!on)
+               ret = hdmiphy_update_bits(client, reg_cache, 0x0b, 0xc0, 0x00);
+               if (ret)
+                       goto exit;
+
+       /* Disable powerdown if on; enable if !on */
+       ret = hdmiphy_update_bits(client, reg_cache, 0x1d, 0x80,
+                                 on ? 0 : ~0);
+       if (ret)
+               goto exit;
+       ret = hdmiphy_update_bits(client, reg_cache, 0x1d, 0x77,
+                                 on ? 0 : ~0);
+       if (ret)
+               goto exit;
+
+       /*
+        * Turn off bit 3 of reg 4 if !on; it turns on again in
+        * hdmiphy_conf_apply().  It's unclear what this bit does.
+        */
+       if (!on)
+               ret = hdmiphy_update_bits(client, reg_cache, 0x04, BIT(3), 0);
+               if (ret)
+                       goto exit;
+
+exit:
+       /* Don't expect any errors so just do a single warn */
+       WARN_ON(ret);
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
-       if (!hdata->is_hdmi_powered_on)
+       return ret;
+}
+
+static void hdmi_resource_poweron(struct hdmi_context *hdata)
+{
+       struct hdmi_resources *res = &hdata->res;
+
+       hdata->is_hdmi_powered_on = true;
+       hdmi_cfg_hpd(hdata, false);
+
+       /* irq change by TV power status */
+       if (hdata->curr_irq == hdata->internal_irq)
                return;
 
+       disable_irq(hdata->curr_irq);
+
+       hdata->curr_irq = hdata->internal_irq;
+
+       enable_irq(hdata->curr_irq);
+
+       /* turn HDMI power on */
+       regulator_bulk_enable(res->regul_count, res->regul_bulk);
+
+       /* power-on hdmi clocks */
+       clk_enable(res->hdmiphy);
+
+       hdmiphy_s_power(hdata->hdmiphy_port, 1);
+       hdmiphy_conf_reset(hdata);
+       hdmi_conf_reset(hdata);
+       hdmi_conf_init(hdata);
+       if (!hdata->is_soc_exynos5)
+               hdmi_audio_init(hdata);
        hdmi_conf_apply(hdata);
-       hdata->enabled = true;
 }
 
-static int hdmi_power_on(void *ctx, int mode)
+static void hdmi_resource_poweroff(struct hdmi_context *hdata)
+{
+       struct hdmi_resources *res = &hdata->res;
+
+       hdmi_cfg_hpd(hdata, true);
+
+       if (hdata->curr_irq == hdata->external_irq)
+               return;
+
+       disable_irq(hdata->curr_irq);
+       hdata->curr_irq = hdata->external_irq;
+
+       enable_irq(hdata->curr_irq);
+       hdata->is_hdmi_powered_on = false;
+
+       hdmiphy_s_power(hdata->hdmiphy_port, 0);
+       hdmiphy_conf_reset(hdata);
+
+       /* power-off hdmi clocks */
+       clk_disable(res->hdmiphy);
+
+       /* turn HDMI power off */
+       regulator_bulk_disable(res->regul_count, res->regul_bulk);
+}
+
+static int hdmi_dpms(void *ctx, int mode)
 {
        struct hdmi_context *hdata = ctx;
 
+       DRM_DEBUG_KMS("[DPMS:%s]\n", drm_get_dpms_name(mode));
+
        switch (mode) {
        case DRM_MODE_DPMS_ON:
-               if (!hdata->is_hdmi_powered_on) {
-                       pm_runtime_get_sync(hdata->dev);
-                       hdmi_commit(ctx);
-               }
+               if (!hdata->is_hdmi_powered_on)
+                       hdmi_resource_poweron(hdata);
+               hdmi_enable_video(hdata);
                break;
        case DRM_MODE_DPMS_STANDBY:
-               break;
-       case DRM_MODE_DPMS_SUSPEND:
+               hdmi_disable_video(hdata);
                break;
        case DRM_MODE_DPMS_OFF:
+       case DRM_MODE_DPMS_SUSPEND:
                if (hdata->is_hdmi_powered_on)
-                       pm_runtime_put_sync(hdata->dev);
+                       hdmi_resource_poweroff(hdata);
                break;
        default:
                DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
@@ -1793,37 +2073,45 @@ static int hdmi_power_on(void *ctx, int mode)
        return 0;
 }
 
-static struct exynos_hdmi_ops hdmi_ops = {
+static int hdmi_subdrv_probe(void *ctx, struct drm_device *drm_dev)
+{
+       struct hdmi_context *hdata = ctx;
+
+       DRM_DEBUG_KMS("[DEV:%s]\n", drm_dev->devname);
+
+       hdata->drm_dev = drm_dev;
+
+       return 0;
+}
+
+static struct exynos_panel_ops hdmi_ops = {
        /* display */
+       .subdrv_probe   = hdmi_subdrv_probe,
        .is_connected   = hdmi_is_connected,
        .get_edid       = hdmi_get_edid,
        .check_timing   = hdmi_check_timing,
-       .power_on       = hdmi_power_on,
+       .dpms           = hdmi_dpms,
 
        /* manager */
        .mode_fixup     = hdmi_mode_fixup,
        .mode_set       = hdmi_mode_set,
-       .commit         = hdmi_commit,
 };
 
 /*
  * Handle hotplug events outside the interrupt handler proper.
  */
-static void hdmi_hotplug_func(struct work_struct *work)
+static void hdmi_hotplug_timer_func(unsigned long data)
 {
-       struct hdmi_context *hdata =
-               container_of(work, struct hdmi_context, hotplug_work);
-       struct exynos_drm_hdmi_context *ctx =
-               (struct exynos_drm_hdmi_context *)hdata->parent_ctx;
+       struct hdmi_context *hdata = (struct hdmi_context *)data;
 
-       drm_helper_hpd_irq_event(ctx->drm_dev);
+       drm_helper_hpd_irq_event(hdata->drm_dev);
 }
 
 static irqreturn_t hdmi_irq_handler(int irq, void *arg)
 {
-       struct exynos_drm_hdmi_context *ctx = arg;
-       struct hdmi_context *hdata = ctx->ctx;
-       u32 intc_flag;
+       struct hdmi_context *hdata = arg;
+       u32 intc_flag, time_ms = HOTPLUG_DEBOUNCE_MS;
+
        if (hdata->is_hdmi_powered_on) {
                intc_flag = hdmi_reg_read(hdata, HDMI_INTC_FLAG);
                /* clearing flags for HPD plug/unplug */
@@ -1839,10 +2127,17 @@ static irqreturn_t hdmi_irq_handler(int irq, void *arg)
                        hdmi_reg_writemask(hdata, HDMI_INTC_FLAG, ~0,
                                HDMI_INTC_FLAG_HPD_PLUG);
                }
+
+               /*
+                * No need to debounce if we're powered on, the hardware
+                * has already done it for us.
+                */
+               time_ms = 0;
        }
 
-       if (ctx->drm_dev && hdata->hpd_handle)
-               queue_work(hdata->wq, &hdata->hotplug_work);
+       if (hdata->drm_dev && hdata->hpd_handle)
+               mod_timer(&hdata->hotplug_timer,
+                               jiffies + msecs_to_jiffies(time_ms));
 
        return IRQ_HANDLED;
 }
@@ -1947,151 +2242,66 @@ static int hdmi_resources_cleanup(struct hdmi_context *hdata)
        return 0;
 }
 
-static void hdmi_resource_poweron(struct hdmi_context *hdata)
-{
-       struct hdmi_resources *res = &hdata->res;
-
-       hdata->is_hdmi_powered_on = true;
-       hdmi_cfg_hpd(hdata, false);
-
-       /* irq change by TV power status */
-       if (hdata->curr_irq == hdata->internal_irq)
-               return;
-
-       disable_irq(hdata->curr_irq);
-
-       hdata->curr_irq = hdata->internal_irq;
-
-       enable_irq(hdata->curr_irq);
-
-       /* turn HDMI power on */
-       regulator_bulk_enable(res->regul_count, res->regul_bulk);
-
-       /* power-on hdmi clocks */
-       clk_enable(res->hdmiphy);
-
-       hdmiphy_conf_reset(hdata);
-       hdmi_conf_reset(hdata);
-       hdmi_conf_init(hdata);
-       if (!hdata->is_soc_exynos5)
-               hdmi_audio_init(hdata);
-}
+struct platform_device *hdmi_audio_device;
 
-static void hdmi_resource_poweroff(struct hdmi_context *hdata)
+int hdmi_register_audio_device(struct platform_device *pdev)
 {
-       struct hdmi_resources *res = &hdata->res;
-
-       hdmi_cfg_hpd(hdata, true);
-
-       if (hdata->curr_irq == hdata->external_irq)
-               return;
-
-       disable_irq(hdata->curr_irq);
-       hdata->curr_irq = hdata->external_irq;
-
-       enable_irq(hdata->curr_irq);
-       hdata->is_hdmi_powered_on = false;
-
-       hdmiphy_conf_reset(hdata);
-
-       /* power-off hdmi clocks */
-       clk_disable(res->hdmiphy);
-
-       /* turn HDMI power off */
-       regulator_bulk_disable(res->regul_count, res->regul_bulk);
-}
+       struct hdmi_context *hdata = platform_get_drvdata(pdev);
+       struct platform_device *audio_dev;
+       int ret;
 
-#ifdef CONFIG_PM_SLEEP
-static int hdmi_suspend(struct device *dev)
-{
-       struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
-       struct hdmi_context *hdata = ctx->ctx;
+       DRM_DEBUG_KMS("[PDEV:%s]\n", pdev->name);
 
-       DRM_DEBUG_KMS("[hdmi] sleep suspend - start\n");
-       if (pm_runtime_suspended(dev)) {
-               DRM_DEBUG_KMS("[hdmi] sleep suspend - already suspended\n");
-               return 0;
+       audio_dev = platform_device_alloc("exynos-hdmi-audio", -1);
+       if (!audio_dev) {
+               DRM_ERROR("hdmi audio device allocation failed.\n");
+               ret = -ENOMEM;
+               goto err;
        }
 
-       hdmi_resource_poweroff(hdata);
-       DRM_DEBUG_KMS("[hdmi] sleep suspend - end\n");
-
-       return 0;
-}
-static int hdmi_resume(struct device *dev)
-{
-       struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
-       struct hdmi_context *hdata = ctx->ctx;
-
-       DRM_DEBUG_KMS("[hdmi] sleep resume - start\n");
-
-       if (!pm_runtime_suspended(dev)) {
-               hdmi_resource_poweron(hdata);
-               hdmi_commit(hdata);
-               DRM_DEBUG_KMS("[hdmi] sleep resuming\n");
+       ret = platform_device_add_resources(audio_dev, pdev->resource,
+                       pdev->num_resources);
+       if (ret) {
+               ret = -ENOMEM;
+               goto err_device;
        }
-       DRM_DEBUG_KMS("[hdmi] sleep resume - end\n");
-       return 0;
-}
-#endif
-#ifdef CONFIG_PM_RUNTIME
-static int hdmi_runtime_suspend(struct device *dev)
-{
-       struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
-       struct hdmi_context *hdata = ctx->ctx;
-
-       DRM_DEBUG_KMS("[hdmi] runtime suspend - start\n");
-       hdmi_resource_poweroff(hdata);
-       DRM_DEBUG_KMS("[hdmi] runtime suspend - end\n");
 
-       return 0;
-}
+       audio_dev->dev.of_node = of_get_next_child(pdev->dev.of_node, NULL);
+       audio_dev->dev.platform_data = (void *)hdata->hpd_gpio;
 
-static int hdmi_runtime_resume(struct device *dev)
-{
-       struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
-       struct hdmi_context *hdata = ctx->ctx;
-
-       DRM_DEBUG_KMS("[hdmi] runtime resume - start\n");
-
-       hdmi_resource_poweron(hdata);
+       ret = platform_device_add(audio_dev);
+       if (ret) {
+               DRM_ERROR("hdmi audio device add failed.\n");
+               goto err_device;
+       }
 
-       DRM_DEBUG_KMS("[hdmi] runtime resume - end\n");
+       hdmi_audio_device = audio_dev;
        return 0;
-}
-#endif
-static const struct dev_pm_ops hdmi_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
-       SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
-};
 
-static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
+err_device:
+       platform_device_put(audio_dev);
 
-void hdmi_attach_ddc_client(struct i2c_client *ddc)
-{
-       if (ddc)
-               hdmi_ddc = ddc;
+err:
+       return ret;
 }
 
-void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
+void hdmi_unregister_audio_device(void)
 {
-       if (hdmiphy)
-               hdmi_hdmiphy = hdmiphy;
+       DRM_DEBUG_KMS("\n");
+       platform_device_unregister(hdmi_audio_device);
 }
 
-struct platform_device *hdmi_audio_device;
-
 static int __devinit hdmi_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       struct exynos_drm_hdmi_context *drm_hdmi_ctx;
        struct hdmi_context *hdata;
        struct exynos_drm_hdmi_pdata *pdata;
        struct resource *res;
+       struct device_node *ddc_node, *phy_node;
        int ret;
        enum of_gpio_flags flags;
 
-       DRM_DEBUG_KMS("[%d]\n", __LINE__);
+       DRM_DEBUG_KMS("[PDEV:%s]\n", pdev->name);
 
        pdata = pdev->dev.platform_data;
        if (!pdata) {
@@ -2099,23 +2309,13 @@ static int __devinit hdmi_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       drm_hdmi_ctx = kzalloc(sizeof(*drm_hdmi_ctx), GFP_KERNEL);
-       if (!drm_hdmi_ctx) {
-               DRM_ERROR("failed to allocate common hdmi context.\n");
-               return -ENOMEM;
-       }
-
        hdata = kzalloc(sizeof(struct hdmi_context), GFP_KERNEL);
        if (!hdata) {
                DRM_ERROR("out of memory\n");
-               kfree(drm_hdmi_ctx);
                return -ENOMEM;
        }
 
-       drm_hdmi_ctx->ctx = (void *)hdata;
-       hdata->parent_ctx = (void *)drm_hdmi_ctx;
-
-       platform_set_drvdata(pdev, drm_hdmi_ctx);
+       platform_set_drvdata(pdev, hdata);
 
        hdata->is_v13 = pdata->is_v13;
        hdata->default_win = pdata->default_win;
@@ -2153,48 +2353,33 @@ static int __devinit hdmi_probe(struct platform_device *pdev)
                goto err_req_region;
        }
 
-       if (of_device_is_compatible(dev->of_node,
-               "samsung,exynos5-hdmi")) {
-
-               hdmi_audio_device =
-                       platform_device_alloc("exynos-hdmi-audio", -1);
-
-               if (!hdmi_audio_device) {
-                       ret = -ENOMEM;
-                       goto err_iomap;
-               }
-
-               ret = platform_device_add_resources(hdmi_audio_device, res, 1);
-               if (ret) {
-                       ret = -ENOMEM;
-                       goto err_iomap;
-               }
-
-               hdmi_audio_device->dev.of_node =
-                       of_get_next_child(dev->of_node, NULL);
-
-               ret = platform_device_add(hdmi_audio_device);
-               if (ret)
-                       platform_device_put(hdmi_audio_device);
-       }
-
        /* DDC i2c driver */
-       if (i2c_add_driver(&ddc_driver)) {
-               DRM_ERROR("failed to register ddc i2c driver\n");
-               ret = -ENOENT;
+       ddc_node = of_find_node_by_name(NULL, "exynos_ddc");
+       if (!ddc_node) {
+               DRM_ERROR("Failed to find ddc node in device tree\n");
+               ret = -ENODEV;
+               goto err_iomap;
+       }
+       hdata->ddc_port = of_find_i2c_device_by_node(ddc_node);
+       if (!hdata->ddc_port) {
+               DRM_ERROR("Failed to get ddc i2c client by node\n");
+               ret = -ENODEV;
                goto err_iomap;
        }
-
-       hdata->ddc_port = hdmi_ddc;
 
        /* hdmiphy i2c driver */
-       if (i2c_add_driver(&hdmiphy_driver)) {
-               DRM_ERROR("failed to register hdmiphy i2c driver\n");
-               ret = -ENOENT;
+       phy_node = of_find_node_by_name(NULL, "exynos_hdmiphy");
+       if (!phy_node) {
+               DRM_ERROR("Failed to find hdmiphy node in device tree\n");
+               ret = -ENODEV;
+               goto err_ddc;
+       }
+       hdata->hdmiphy_port = of_find_i2c_device_by_node(phy_node);
+       if (!hdata->hdmiphy_port) {
+               DRM_ERROR("Failed to get hdmi phy i2c client from node\n");
+               ret = -ENODEV;
                goto err_ddc;
        }
-
-       hdata->hdmiphy_port = hdmi_hdmiphy;
 
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (res == NULL) {
@@ -2216,54 +2401,55 @@ static int __devinit hdmi_probe(struct platform_device *pdev)
 
        hdata->external_irq = gpio_to_irq(hdata->hpd_gpio);
 
-       /* create workqueue and hotplug work */
-       hdata->wq = alloc_workqueue("exynos-drm-hdmi",
-                       WQ_UNBOUND | WQ_NON_REENTRANT, 1);
-       if (hdata->wq == NULL) {
-               DRM_ERROR("Failed to create workqueue.\n");
-               ret = -ENOMEM;
-               goto err_hdmiphy;
-       }
-       INIT_WORK(&hdata->hotplug_work, hdmi_hotplug_func);
-
        ret = request_irq(hdata->internal_irq, hdmi_irq_handler,
-                       0, "int_hdmi", hdata->parent_ctx);
+                       IRQF_SHARED, "int_hdmi", hdata);
        if (ret) {
-               DRM_ERROR("request interrupt failed.\n");
-               goto err_workqueue;
+               DRM_ERROR("request int interrupt failed.\n");
+               goto err_hdmiphy;
        }
        disable_irq(hdata->internal_irq);
 
        ret = request_irq(hdata->external_irq, hdmi_irq_handler,
-               IRQ_TYPE_EDGE_BOTH, "ext_hdmi", hdata->parent_ctx);
+               IRQ_TYPE_EDGE_BOTH | IRQF_SHARED, "ext_hdmi",
+               hdata);
        if (ret) {
-               DRM_ERROR("request interrupt failed.\n");
-               goto err_workqueue;
+               DRM_ERROR("request ext interrupt failed.\n");
+               goto err_int_irq;
        }
        disable_irq(hdata->external_irq);
 
-       /* Attach HDMI Driver to common hdmi. */
-       exynos_hdmi_drv_attach(drm_hdmi_ctx);
+       setup_timer(&hdata->hotplug_timer, hdmi_hotplug_timer_func,
+                       (unsigned long)hdata);
+
+       if (of_device_is_compatible(dev->of_node,
+               "samsung,exynos5-hdmi")) {
+               ret = hdmi_register_audio_device(pdev);
+               if (ret) {
+                       DRM_ERROR("hdmi-audio device registering failed.\n");
+                       goto err_ext_irq;
+               }
+       }
 
-       /* register specific callbacks to common hdmi. */
-       exynos_hdmi_ops_register(&hdmi_ops);
        hdmi_resource_poweron(hdata);
-       pm_runtime_enable(dev);
 
        if (!hdmi_is_connected(hdata)) {
                hdmi_resource_poweroff(hdata);
                DRM_DEBUG_KMS("gpio state is low. powering off!\n");
-       } else {
-               pm_runtime_get_sync(dev);
        }
+
+       exynos_display_attach_panel(EXYNOS_DRM_DISPLAY_TYPE_MIXER, &hdmi_ops,
+                       hdata);
+
        return 0;
 
-err_workqueue:
-       destroy_workqueue(hdata->wq);
+err_ext_irq:
+       free_irq(hdata->external_irq, hdata);
+err_int_irq:
+       free_irq(hdata->internal_irq, hdata);
 err_hdmiphy:
-       i2c_del_driver(&hdmiphy_driver);
+       put_device(&hdata->hdmiphy_port->dev);
 err_ddc:
-       i2c_del_driver(&ddc_driver);
+       put_device(&hdata->ddc_port->dev);
 err_iomap:
        iounmap(hdata->regs);
 err_req_region:
@@ -2273,26 +2459,25 @@ err_resource:
        hdmi_resources_cleanup(hdata);
 err_data:
        kfree(hdata);
-       kfree(drm_hdmi_ctx);
        return ret;
 }
 
 static int __devexit hdmi_remove(struct platform_device *pdev)
 {
-       struct exynos_drm_hdmi_context *ctx = platform_get_drvdata(pdev);
-       struct hdmi_context *hdata = ctx->ctx;
+       struct hdmi_context *hdata = platform_get_drvdata(pdev);
        struct hdmi_resources *res = &hdata->res;
 
-       DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
+       DRM_DEBUG_KMS("[PDEV:%s]\n", pdev->name);
 
        hdmi_resource_poweroff(hdata);
 
+       hdmi_unregister_audio_device();
+
        disable_irq(hdata->curr_irq);
        free_irq(hdata->internal_irq, hdata);
        free_irq(hdata->external_irq, hdata);
 
-       cancel_work_sync(&hdata->hotplug_work);
-       destroy_workqueue(hdata->wq);
+       del_timer(&hdata->hotplug_timer);
 
        clk_disable(res->hdmi);
        clk_disable(res->sclk_hdmi);
@@ -2303,10 +2488,8 @@ static int __devexit hdmi_remove(struct platform_device *pdev)
        release_mem_region(hdata->regs_res->start,
                        resource_size(hdata->regs_res));
 
-       /* hdmiphy i2c driver */
-       i2c_del_driver(&hdmiphy_driver);
-       /* DDC i2c driver */
-       i2c_del_driver(&ddc_driver);
+       put_device(&hdata->hdmiphy_port->dev);
+       put_device(&hdata->ddc_port->dev);
 
        kfree(hdata);
 
@@ -2323,6 +2506,5 @@ struct platform_driver hdmi_driver = {
                .name   = "exynos4-hdmi",
 #endif
                .owner  = THIS_MODULE,
-               .pm = &hdmi_pm_ops,
        },
 };