CHROMIUM: drm/exynos: Remove panel_ops->commit
[cascardo/linux.git] / drivers / gpu / drm / exynos / exynos_dp_core.c
index f20d0c0..73d32c8 100644 (file)
@@ -10,6 +10,9 @@
  * option) any later version.
  */
 
+#include "drmP.h"
+#include "drm_crtc_helper.h"
+
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
@@ -27,6 +30,7 @@
 #include "exynos_drm_display.h"
 
 #include <plat/cpu.h>
+#include <plat/gpio-cfg.h>
 
 #include "exynos_dp_core.h"
 
@@ -51,6 +55,9 @@ static int exynos_dp_detect_hpd(struct exynos_dp_device *dp)
 {
        int timeout_loop = 0;
 
+       if (gpio_is_valid(dp->hpd_gpio))
+               return !gpio_get_value(dp->hpd_gpio);
+
        while (exynos_dp_get_plug_in_status(dp) != 0) {
                timeout_loop++;
                if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
@@ -497,6 +504,9 @@ static int exynos_dp_process_clock_recovery(struct exynos_dp_device *dp)
                return ret;
 
        lane_count = dp->link_train.lane_count;
+       if (lane_count == 0)
+               return 0;
+
        adjust_request = link_status + 4;
 
        if (exynos_dp_clock_recovery_ok(link_status, lane_count) == 0) {
@@ -815,7 +825,6 @@ static int exynos_dp_config_video(struct exynos_dp_device *dp)
 {
        int retval = 0;
        int timeout_loop = 0;
-       int done_count = 0;
 
        exynos_dp_config_video_slave_mode(dp);
 
@@ -828,14 +837,14 @@ static int exynos_dp_config_video(struct exynos_dp_device *dp)
 
        for (;;) {
                timeout_loop++;
-               if (exynos_dp_is_slave_video_stream_clock_on(dp) == 0)
+               if (!exynos_dp_is_slave_video_stream_clock_on(dp))
                        break;
                if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
-                       dev_err(dp->dev, "Timeout of video streamclk ok\n");
+                       dev_err(dp->dev, "Wait for stream clock timed out\n");
                        return -ETIMEDOUT;
                }
 
-               msleep(100);
+               usleep_range(1000, 5000);
        }
 
        /* Set to use the register calculated M/N video */
@@ -857,19 +866,15 @@ static int exynos_dp_config_video(struct exynos_dp_device *dp)
 
        for (;;) {
                timeout_loop++;
-               if (exynos_dp_is_video_stream_on(dp) == 0) {
-                       done_count++;
-                       if (done_count > 10)
-                               break;
-               } else if (done_count) {
-                       done_count = 0;
-               }
+               if (!exynos_dp_is_video_stream_on(dp))
+                       break;
+
                if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
-                       dev_err(dp->dev, "Timeout of video streamclk ok\n");
+                       dev_err(dp->dev, "Wait for video stream timed out\n");
                        return -ETIMEDOUT;
                }
 
-               msleep(100);
+               usleep_range(1000, 5000);
        }
 
        if (retval != 0)
@@ -911,12 +916,9 @@ static irqreturn_t exynos_dp_irq_handler(int irq, void *arg)
        irq_type = exynos_dp_get_irq_type(dp);
        switch (irq_type) {
        case DP_IRQ_TYPE_HP_CABLE_IN:
-               dev_dbg(dp->dev, "Received irq - cable in\n");
-               schedule_work(&dp->hotplug_work);
-               exynos_dp_clear_hotplug_interrupts(dp);
-               break;
        case DP_IRQ_TYPE_HP_CABLE_OUT:
-               dev_dbg(dp->dev, "Received irq - cable out\n");
+               dev_dbg(dp->dev, "Received irq - type=%d\n", irq_type);
+               schedule_work(&dp->hotplug_work);
                exynos_dp_clear_hotplug_interrupts(dp);
                break;
        case DP_IRQ_TYPE_HP_CHANGE:
@@ -938,15 +940,15 @@ static irqreturn_t exynos_dp_irq_handler(int irq, void *arg)
 static void exynos_dp_hotplug(struct work_struct *work)
 {
        struct exynos_dp_device *dp;
-       int ret;
 
        dp = container_of(work, struct exynos_dp_device, hotplug_work);
 
-       ret = exynos_dp_detect_hpd(dp);
-       if (ret) {
-               /* Cable has been disconnected, we're done */
-               return;
-       }
+       drm_helper_hpd_irq_event(dp->drm_dev);
+}
+
+static void exynos_dp_train_link(struct exynos_dp_device *dp)
+{
+       int ret;
 
        ret = exynos_dp_handle_edid(dp);
        if (ret) {
@@ -973,12 +975,15 @@ static void exynos_dp_hotplug(struct work_struct *work)
        exynos_dp_set_link_bandwidth(dp, dp->video_info->link_rate);
 
        exynos_dp_init_video(dp);
-       exynos_dp_config_video(dp);
 }
 
 static int exynos_dp_power_off(struct exynos_dp_device *dp)
 {
-       disable_irq(dp->irq);
+       if (!dp->enabled)
+               return 0;
+
+       dp->enabled = false;
+       exynos_dp_disable_hpd(dp);
 
        if (work_pending(&dp->hotplug_work))
                flush_work_sync(&dp->hotplug_work);
@@ -992,6 +997,9 @@ static int exynos_dp_power_off(struct exynos_dp_device *dp)
 
 static int exynos_dp_power_on(struct exynos_dp_device *dp)
 {
+       if (dp->enabled)
+               return 0;
+
        if (dp->phy_ops.phy_init)
                dp->phy_ops.phy_init();
 
@@ -999,12 +1007,22 @@ static int exynos_dp_power_on(struct exynos_dp_device *dp)
 
        exynos_dp_init_dp(dp);
 
-       enable_irq(dp->irq);
+       /*
+        * DP controller is reset and needs HPD interrupt to trigger
+        * re-configuration. If we don't have valid IRQ, this is never
+        * going to happen. Let's reconfigure it here in this case.
+        */
+       if (dp->irq < 0 && !exynos_dp_detect_hpd(dp))
+               schedule_work(&dp->hotplug_work);
+
+       exynos_dp_train_link(dp);
+       exynos_dp_config_video(dp);
 
+       dp->enabled = true;
        return 0;
 }
 
-static int exynos_dp_power(void *ctx, int mode)
+static int exynos_dp_dpms(void *ctx, int mode)
 {
        struct exynos_dp_device *dp = ctx;
 
@@ -1037,18 +1055,31 @@ static int exynos_dp_check_timing(void *ctx, void *timing)
 static bool exynos_dp_is_connected(void *ctx)
 {
        struct exynos_dp_device *dp = ctx;
-       int ret;
 
-       ret = exynos_dp_detect_hpd(dp);
-       return !ret;
+       if (dp->force_connected)
+               return true;
+       else
+               return !exynos_dp_detect_hpd(dp);
 }
 
 static int exynos_dp_subdrv_probe(void *ctx, struct drm_device *drm_dev)
 {
        struct exynos_dp_device *dp = ctx;
+       int ret;
 
        dp->drm_dev = drm_dev;
 
+       if (dp->irq >= 0) {
+               ret = request_irq(dp->irq, exynos_dp_irq_handler, dp->irq_flags,
+                               "exynos-dp", dp);
+               if (ret) {
+                       dev_err(dp->dev, "failed to request irq\n");
+                       return ret;
+               }
+       }
+
+       exynos_dp_dpms(dp, DRM_MODE_DPMS_ON);
+
        return 0;
 }
 
@@ -1056,7 +1087,7 @@ static struct exynos_panel_ops dp_panel_ops = {
        .subdrv_probe = exynos_dp_subdrv_probe,
        .is_connected = exynos_dp_is_connected,
        .check_timing = exynos_dp_check_timing,
-       .power = exynos_dp_power,
+       .dpms = exynos_dp_dpms,
 };
 
 static int __devinit exynos_dp_probe(struct platform_device *pdev)
@@ -1066,7 +1097,6 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
        struct exynos_dp_platdata *pdata;
 
        int ret = 0;
-       int irqflags;
 
        pdata = pdev->dev.platform_data;
        if (!pdata) {
@@ -1120,22 +1150,26 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
                ret = gpio_request_one(dp->hpd_gpio, GPIOF_IN, "dp_hpd");
                if (ret)
                        goto err_ioremap;
+#ifdef CONFIG_S5P_GPIO_INT
+               ret = s5p_register_gpio_interrupt(dp->hpd_gpio);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "cannot register/get GPIO irq\n");
+                       goto err_gpio;
+               }
+               s3c_gpio_cfgpin(dp->hpd_gpio, S3C_GPIO_SFN(0xf));
+#endif
                dp->irq = gpio_to_irq(dp->hpd_gpio);
-               irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
+               dp->irq_flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
        } else {
                dp->hpd_gpio = -ENODEV;
                dp->irq = platform_get_irq(pdev, 0);
-               irqflags = 0;
-       }
-
-       if (dp->irq < 0) {
-               dev_err(&pdev->dev, "failed to get irq\n");
-               ret = -ENODEV;
-               goto err_gpio;
+               dp->irq_flags = 0;
        }
 
+       dp->enabled = false;
        dp->training_type = pdata->training_type;
        dp->video_info = pdata->video_info;
+       dp->force_connected = pdata->force_connected;
        if (pdata->phy_init) {
                dp->phy_ops.phy_init = pdata->phy_init;
                dp->phy_ops.phy_init();
@@ -1145,15 +1179,6 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
 
        INIT_WORK(&dp->hotplug_work, exynos_dp_hotplug);
 
-       ret = request_irq(dp->irq, exynos_dp_irq_handler, irqflags,
-                       "exynos-dp", dp);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to request irq\n");
-               goto err_gpio;
-       }
-
-       disable_irq(dp->irq);
-
        platform_set_drvdata(pdev, dp);
 
        exynos_display_attach_panel(EXYNOS_DRM_DISPLAY_TYPE_FIMD, &dp_panel_ops,
@@ -1180,11 +1205,8 @@ static int __devexit exynos_dp_remove(struct platform_device *pdev)
 {
        struct exynos_dp_device *dp = platform_get_drvdata(pdev);
 
-       if (work_pending(&dp->hotplug_work))
-               flush_work_sync(&dp->hotplug_work);
-
-       if (dp->phy_ops.phy_exit)
-               dp->phy_ops.phy_exit();
+       /* power_off will take care of flushing the hotplug_work */
+       exynos_dp_dpms(dp, DRM_MODE_DPMS_OFF);
 
        if (gpio_is_valid(dp->hpd_gpio))
                gpio_free(dp->hpd_gpio);
@@ -1202,34 +1224,11 @@ static int __devexit exynos_dp_remove(struct platform_device *pdev)
        return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int exynos_dp_suspend(struct device *dev)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct exynos_dp_device *dp = platform_get_drvdata(pdev);
-
-       return exynos_dp_power(dp, DRM_MODE_DPMS_SUSPEND);
-}
-
-static int exynos_dp_resume(struct device *dev)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct exynos_dp_device *dp = platform_get_drvdata(pdev);
-
-       return exynos_dp_power(dp, DRM_MODE_DPMS_ON);
-}
-#endif
-
-static const struct dev_pm_ops dp_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(exynos_dp_suspend, exynos_dp_resume)
-};
-
 struct platform_driver dp_driver = {
        .probe          = exynos_dp_probe,
        .remove         = __devexit_p(exynos_dp_remove),
        .driver         = {
                .name   = "s5p-dp",
                .owner  = THIS_MODULE,
-               .pm     = &dp_pm_ops,
        },
 };