OMAP: DSS2: Use MIPI DSI enums from include/video/mipi_display.h
[pandora-kernel.git] / drivers / video / omap2 / dss / dsi.c
index 1e2fd40..6735e0c 100644 (file)
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/debugfs.h>
+#include <linux/pm_runtime.h>
 
 #include <video/omapdss.h>
+#include <video/mipi_display.h>
 #include <plat/clock.h>
 
 #include "dss.h"
@@ -197,18 +199,6 @@ struct dsi_reg { u16 idx; };
         DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
         DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
 
-#define DSI_DT_DCS_SHORT_WRITE_0       0x05
-#define DSI_DT_DCS_SHORT_WRITE_1       0x15
-#define DSI_DT_DCS_READ                        0x06
-#define DSI_DT_SET_MAX_RET_PKG_SIZE    0x37
-#define DSI_DT_NULL_PACKET             0x09
-#define DSI_DT_DCS_LONG_WRITE          0x39
-
-#define DSI_DT_RX_ACK_WITH_ERR         0x02
-#define DSI_DT_RX_DCS_LONG_READ                0x1c
-#define DSI_DT_RX_SHORT_READ_1         0x21
-#define DSI_DT_RX_SHORT_READ_2         0x22
-
 typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
 
 #define DSI_MAX_NR_ISRS                2
@@ -267,9 +257,14 @@ struct dsi_isr_tables {
 struct dsi_data {
        struct platform_device *pdev;
        void __iomem    *base;
+
        int irq;
 
-       void (*dsi_mux_pads)(bool enable);
+       struct clk *dss_clk;
+       struct clk *sys_clk;
+
+       int (*enable_pads)(int dsi_id, unsigned lane_mask);
+       void (*disable_pads)(int dsi_id, unsigned lane_mask);
 
        struct dsi_clock_info current_cinfo;
 
@@ -363,14 +358,9 @@ struct platform_device *dsi_get_dsidev_from_id(int module)
        return dsi_pdev_map[module];
 }
 
-static int dsi_get_dsidev_id(struct platform_device *dsidev)
+static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
 {
-       /* TEMP: Pass 0 as the dsi module index till the time the dsi platform
-        * device names aren't changed to the form "omapdss_dsi.0",
-        * "omapdss_dsi.1" and so on */
-       BUG_ON(dsidev->id != -1);
-
-       return 0;
+       return dsidev->id;
 }
 
 static inline void dsi_write_reg(struct platform_device *dsidev,
@@ -389,15 +379,6 @@ static inline u32 dsi_read_reg(struct platform_device *dsidev,
        return __raw_readl(dsi->base + idx.idx);
 }
 
-
-void dsi_save_context(void)
-{
-}
-
-void dsi_restore_context(void)
-{
-}
-
 void dsi_bus_lock(struct omap_dss_device *dssdev)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -1048,13 +1029,27 @@ static u32 dsi_get_errors(struct platform_device *dsidev)
        return e;
 }
 
-/* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
-static inline void enable_clocks(bool enable)
+int dsi_runtime_get(struct platform_device *dsidev)
 {
-       if (enable)
-               dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
-       else
-               dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
+       int r;
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+
+       DSSDBG("dsi_runtime_get\n");
+
+       r = pm_runtime_get_sync(&dsi->pdev->dev);
+       WARN_ON(r < 0);
+       return r < 0 ? r : 0;
+}
+
+void dsi_runtime_put(struct platform_device *dsidev)
+{
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+       int r;
+
+       DSSDBG("dsi_runtime_put\n");
+
+       r = pm_runtime_put(&dsi->pdev->dev);
+       WARN_ON(r < 0);
 }
 
 /* source clock for DSI PLL. this could also be PCLKFREE */
@@ -1064,9 +1059,9 @@ static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
        if (enable)
-               dss_clk_enable(DSS_CLK_SYSCK);
+               clk_enable(dsi->sys_clk);
        else
-               dss_clk_disable(DSS_CLK_SYSCK);
+               clk_disable(dsi->sys_clk);
 
        if (enable && dsi->pll_locked) {
                if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
@@ -1159,10 +1154,11 @@ static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
 {
        unsigned long r;
        int dsi_module = dsi_get_dsidev_id(dsidev);
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
        if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
                /* DSI FCLK source is DSS_CLK_FCK */
-               r = dss_clk_get_rate(DSS_CLK_FCK);
+               r = clk_get_rate(dsi->dss_clk);
        } else {
                /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
                r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
@@ -1271,12 +1267,12 @@ static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
                return -EINVAL;
 
        if (cinfo->use_sys_clk) {
-               cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
+               cinfo->clkin = clk_get_rate(dsi->sys_clk);
                /* XXX it is unclear if highfreq should be used
                 * with DSS_SYS_CLK source also */
                cinfo->highfreq = 0;
        } else {
-               cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
+               cinfo->clkin = dispc_mgr_pclk_rate(dssdev->manager->id);
 
                if (cinfo->clkin < 32000000)
                        cinfo->highfreq = 0;
@@ -1320,7 +1316,7 @@ int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
        int match = 0;
        unsigned long dss_sys_clk, max_dss_fck;
 
-       dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
+       dss_sys_clk = clk_get_rate(dsi->sys_clk);
 
        max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
 
@@ -1610,7 +1606,6 @@ int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
                dsi->vdds_dsi_reg = vdds_dsi;
        }
 
-       enable_clocks(1);
        dsi_enable_pll_clock(dsidev, 1);
        /*
         * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
@@ -1662,7 +1657,6 @@ err1:
        }
 err0:
        dsi_disable_scp_clk(dsidev);
-       enable_clocks(0);
        dsi_enable_pll_clock(dsidev, 0);
        return r;
 }
@@ -1680,7 +1674,6 @@ void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
        }
 
        dsi_disable_scp_clk(dsidev);
-       enable_clocks(0);
        dsi_enable_pll_clock(dsidev, 0);
 
        DSSDBG("PLL uninit done\n");
@@ -1697,7 +1690,8 @@ static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
        dispc_clk_src = dss_get_dispc_clk_source();
        dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
 
-       enable_clocks(1);
+       if (dsi_runtime_get(dsidev))
+               return;
 
        seq_printf(s,   "- DSI%d PLL -\n", dsi_module + 1);
 
@@ -1740,7 +1734,7 @@ static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
 
        seq_printf(s,   "LP_CLK\t\t%lu\n", cinfo->lp_clk);
 
-       enable_clocks(0);
+       dsi_runtime_put(dsidev);
 }
 
 void dsi_dump_clocks(struct seq_file *s)
@@ -1882,7 +1876,8 @@ static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
 {
 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
 
-       dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
+       if (dsi_runtime_get(dsidev))
+               return;
        dsi_enable_scp_clk(dsidev);
 
        DUMPREG(DSI_REVISION);
@@ -1956,7 +1951,7 @@ static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
        DUMPREG(DSI_PLL_CONFIGURATION2);
 
        dsi_disable_scp_clk(dsidev);
-       dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
+       dsi_runtime_put(dsidev);
 #undef DUMPREG
 }
 
@@ -2350,6 +2345,24 @@ static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
        return 0;
 }
 
+static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
+{
+       unsigned lanes = 0;
+
+       if (dssdev->phy.dsi.clk_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
+       if (dssdev->phy.dsi.data1_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
+       if (dssdev->phy.dsi.data2_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
+       if (dssdev->phy.dsi.data3_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
+       if (dssdev->phy.dsi.data4_lane != 0)
+               lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
+
+       return lanes;
+}
+
 static int dsi_cio_init(struct omap_dss_device *dssdev)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -2360,8 +2373,9 @@ static int dsi_cio_init(struct omap_dss_device *dssdev)
 
        DSSDBGF();
 
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(true);
+       r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
+       if (r)
+               return r;
 
        dsi_enable_scp_clk(dsidev);
 
@@ -2457,41 +2471,18 @@ err_cio_pwr:
                dsi_cio_disable_lane_override(dsidev);
 err_scp_clk_dom:
        dsi_disable_scp_clk(dsidev);
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(false);
+       dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
        return r;
 }
 
-static void dsi_cio_uninit(struct platform_device *dsidev)
+static void dsi_cio_uninit(struct omap_dss_device *dssdev)
 {
+       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
        dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
        dsi_disable_scp_clk(dsidev);
-       if (dsi->dsi_mux_pads)
-               dsi->dsi_mux_pads(false);
-}
-
-static int _dsi_wait_reset(struct platform_device *dsidev)
-{
-       int t = 0;
-
-       while (REG_GET(dsidev, DSI_SYSSTATUS, 0, 0) == 0) {
-               if (++t > 5) {
-                       DSSERR("soft reset failed\n");
-                       return -ENODEV;
-               }
-               udelay(1);
-       }
-
-       return 0;
-}
-
-static int _dsi_reset(struct platform_device *dsidev)
-{
-       /* Soft reset */
-       REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 1, 1);
-       return _dsi_wait_reset(dsidev);
+       dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
 }
 
 static void dsi_config_tx_fifo(struct platform_device *dsidev,
@@ -2885,16 +2876,16 @@ static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
                val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
                DSSERR("\trawval %#08x\n", val);
                dt = FLD_GET(val, 5, 0);
-               if (dt == DSI_DT_RX_ACK_WITH_ERR) {
+               if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
                        u16 err = FLD_GET(val, 23, 8);
                        dsi_show_rx_ack_with_err(err);
-               } else if (dt == DSI_DT_RX_SHORT_READ_1) {
+               } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
                        DSSERR("\tDCS short response, 1 byte: %#x\n",
                                        FLD_GET(val, 23, 8));
-               } else if (dt == DSI_DT_RX_SHORT_READ_2) {
+               } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
                        DSSERR("\tDCS short response, 2 byte: %#x\n",
                                        FLD_GET(val, 23, 8));
-               } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
+               } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
                        DSSERR("\tDCS long response, len %d\n",
                                        FLD_GET(val, 23, 8));
                        dsi_vc_flush_long_data(dsidev, channel);
@@ -3099,7 +3090,7 @@ int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
        u8 nullpkg[] = {0, 0, 0, 0};
 
-       return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg,
+       return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, nullpkg,
                4, 0);
 }
 EXPORT_SYMBOL(dsi_vc_send_null);
@@ -3113,14 +3104,15 @@ int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
        BUG_ON(len == 0);
 
        if (len == 1) {
-               r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0,
-                               data[0], 0);
+               r = dsi_vc_send_short(dsidev, channel,
+                               MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
        } else if (len == 2) {
-               r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1,
+               r = dsi_vc_send_short(dsidev, channel,
+                               MIPI_DSI_DCS_SHORT_WRITE_PARAM,
                                data[0] | (data[1] << 8), 0);
        } else {
                /* 0x39 = DCS Long Write */
-               r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
+               r = dsi_vc_send_long(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
                                data, len, 0);
        }
 
@@ -3186,7 +3178,7 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
        if (dsi->debug_read)
                DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
 
-       r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0);
+       r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
        if (r)
                goto err;
 
@@ -3205,13 +3197,13 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
        if (dsi->debug_read)
                DSSDBG("\theader: %08x\n", val);
        dt = FLD_GET(val, 5, 0);
-       if (dt == DSI_DT_RX_ACK_WITH_ERR) {
+       if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
                u16 err = FLD_GET(val, 23, 8);
                dsi_show_rx_ack_with_err(err);
                r = -EIO;
                goto err;
 
-       } else if (dt == DSI_DT_RX_SHORT_READ_1) {
+       } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
                u8 data = FLD_GET(val, 15, 8);
                if (dsi->debug_read)
                        DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
@@ -3224,7 +3216,7 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                buf[0] = data;
 
                return 1;
-       } else if (dt == DSI_DT_RX_SHORT_READ_2) {
+       } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
                u16 data = FLD_GET(val, 23, 8);
                if (dsi->debug_read)
                        DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
@@ -3238,7 +3230,7 @@ int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
                buf[1] = (data >> 8) & 0xff;
 
                return 2;
-       } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
+       } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
                int w;
                int len = FLD_GET(val, 23, 8);
                if (dsi->debug_read)
@@ -3328,8 +3320,8 @@ int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
 
-       return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
-                       len, 0);
+       return dsi_vc_send_short(dsidev, channel,
+                       MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
 }
 EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
 
@@ -3646,161 +3638,6 @@ static void dsi_proto_timings(struct omap_dss_device *dssdev)
                        enter_hs_mode_lat, exit_hs_mode_lat);
 }
 
-
-#define DSI_DECL_VARS \
-       int __dsi_cb = 0; u32 __dsi_cv = 0;
-
-#define DSI_FLUSH(dsidev, ch) \
-       if (__dsi_cb > 0) { \
-               /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
-               dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
-               __dsi_cb = __dsi_cv = 0; \
-       }
-
-#define DSI_PUSH(dsidev, ch, data) \
-       do { \
-               __dsi_cv |= (data) << (__dsi_cb * 8); \
-               /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
-               if (++__dsi_cb > 3) \
-                       DSI_FLUSH(dsidev, ch); \
-       } while (0)
-
-static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
-                       int x, int y, int w, int h)
-{
-       /* Note: supports only 24bit colors in 32bit container */
-       struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
-       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
-       int first = 1;
-       int fifo_stalls = 0;
-       int max_dsi_packet_size;
-       int max_data_per_packet;
-       int max_pixels_per_packet;
-       int pixels_left;
-       int bytespp = dssdev->ctrl.pixel_size / 8;
-       int scr_width;
-       u32 __iomem *data;
-       int start_offset;
-       int horiz_inc;
-       int current_x;
-       struct omap_overlay *ovl;
-
-       debug_irq = 0;
-
-       DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
-                       x, y, w, h);
-
-       ovl = dssdev->manager->overlays[0];
-
-       if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
-               return -EINVAL;
-
-       if (dssdev->ctrl.pixel_size != 24)
-               return -EINVAL;
-
-       scr_width = ovl->info.screen_width;
-       data = ovl->info.vaddr;
-
-       start_offset = scr_width * y + x;
-       horiz_inc = scr_width - w;
-       current_x = x;
-
-       /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
-        * in fifo */
-
-       /* When using CPU, max long packet size is TX buffer size */
-       max_dsi_packet_size = dsi->vc[0].fifo_size * 32 * 4;
-
-       /* we seem to get better perf if we divide the tx fifo to half,
-          and while the other half is being sent, we fill the other half
-          max_dsi_packet_size /= 2; */
-
-       max_data_per_packet = max_dsi_packet_size - 4 - 1;
-
-       max_pixels_per_packet = max_data_per_packet / bytespp;
-
-       DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
-
-       pixels_left = w * h;
-
-       DSSDBG("total pixels %d\n", pixels_left);
-
-       data += start_offset;
-
-       while (pixels_left > 0) {
-               /* 0x2c = write_memory_start */
-               /* 0x3c = write_memory_continue */
-               u8 dcs_cmd = first ? 0x2c : 0x3c;
-               int pixels;
-               DSI_DECL_VARS;
-               first = 0;
-
-#if 1
-               /* using fifo not empty */
-               /* TX_FIFO_NOT_EMPTY */
-               while (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(0)), 5, 5)) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                               pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-                       udelay(1);
-               }
-#elif 1
-               /* using fifo emptiness */
-               while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
-                               max_dsi_packet_size) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                              pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-               }
-#else
-               while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS,
-                               7, 0) + 1) * 4 == 0) {
-                       fifo_stalls++;
-                       if (fifo_stalls > 0xfffff) {
-                               DSSERR("fifo stalls overflow, pixels left %d\n",
-                                              pixels_left);
-                               dsi_if_enable(dsidev, 0);
-                               return -EIO;
-                       }
-               }
-#endif
-               pixels = min(max_pixels_per_packet, pixels_left);
-
-               pixels_left -= pixels;
-
-               dsi_vc_write_long_header(dsidev, 0, DSI_DT_DCS_LONG_WRITE,
-                               1 + pixels * bytespp, 0);
-
-               DSI_PUSH(dsidev, 0, dcs_cmd);
-
-               while (pixels-- > 0) {
-                       u32 pix = __raw_readl(data++);
-
-                       DSI_PUSH(dsidev, 0, (pix >> 16) & 0xff);
-                       DSI_PUSH(dsidev, 0, (pix >> 8) & 0xff);
-                       DSI_PUSH(dsidev, 0, (pix >> 0) & 0xff);
-
-                       current_x++;
-                       if (current_x == x+w) {
-                               current_x = x;
-                               data += horiz_inc;
-                       }
-               }
-
-               DSI_FLUSH(dsidev, 0);
-       }
-
-       return 0;
-}
-
 static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
                u16 x, u16 y, u16 w, u16 h)
 {
@@ -3843,7 +3680,7 @@ static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
        l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
        dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
 
-       dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
+       dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
                packet_len, 0);
 
        if (dsi->te_enabled)
@@ -3968,11 +3805,9 @@ int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
 
        dsi_perf_mark_setup(dsidev);
 
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               dss_setup_partial_planes(dssdev, x, y, w, h,
-                               enlarge_update_area);
-               dispc_set_lcd_size(dssdev->manager->id, *w, *h);
-       }
+       dss_setup_partial_planes(dssdev, x, y, w, h,
+                       enlarge_update_area);
+       dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h);
 
        return 0;
 }
@@ -3994,27 +3829,16 @@ int omap_dsi_update(struct omap_dss_device *dssdev,
         * see rather obscure HW error happening, as DSS halts. */
        BUG_ON(x % 2 == 1);
 
-       if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
-               dsi->framedone_callback = callback;
-               dsi->framedone_data = data;
+       dsi->framedone_callback = callback;
+       dsi->framedone_data = data;
 
-               dsi->update_region.x = x;
-               dsi->update_region.y = y;
-               dsi->update_region.w = w;
-               dsi->update_region.h = h;
-               dsi->update_region.device = dssdev;
+       dsi->update_region.x = x;
+       dsi->update_region.y = y;
+       dsi->update_region.w = w;
+       dsi->update_region.h = h;
+       dsi->update_region.device = dssdev;
 
-               dsi_update_screen_dispc(dssdev, x, y, w, h);
-       } else {
-               int r;
-
-               r = dsi_update_screen_l4(dssdev, x, y, w, h);
-               if (r)
-                       return r;
-
-               dsi_perf_show(dsidev, "L4");
-               callback(0, data);
-       }
+       dsi_update_screen_dispc(dssdev, x, y, w, h);
 
        return 0;
 }
@@ -4037,14 +3861,15 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
                return r;
        }
 
-       dispc_set_lcd_display_type(dssdev->manager->id,
+       dispc_mgr_set_lcd_display_type(dssdev->manager->id,
                        OMAP_DSS_LCD_DISPLAY_TFT);
 
-       dispc_set_parallel_interface_mode(dssdev->manager->id,
+       dispc_mgr_set_parallel_interface_mode(dssdev->manager->id,
                        OMAP_DSS_PARALLELMODE_DSI);
-       dispc_enable_fifohandcheck(dssdev->manager->id, 1);
+       dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1);
 
-       dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
+       dispc_mgr_set_tft_data_lines(dssdev->manager->id,
+                       dssdev->ctrl.pixel_size);
 
        {
                struct omap_video_timings timings = {
@@ -4056,7 +3881,7 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
                        .vbp            = 0,
                };
 
-               dispc_set_lcd_timings(dssdev->manager->id, &timings);
+               dispc_mgr_set_lcd_timings(dssdev->manager->id, &timings);
        }
 
        return 0;
@@ -4118,7 +3943,7 @@ static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
                return r;
        }
 
-       r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
+       r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
        if (r) {
                DSSERR("Failed to set dispc clocks\n");
                return r;
@@ -4178,10 +4003,12 @@ static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
 
        return 0;
 err3:
-       dsi_cio_uninit(dsidev);
+       dsi_cio_uninit(dssdev);
 err2:
        dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
        dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
+       dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
+
 err1:
        dsi_pll_uninit(dsidev, true);
 err0:
@@ -4207,26 +4034,11 @@ static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
 
        dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
        dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
-       dsi_cio_uninit(dsidev);
+       dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
+       dsi_cio_uninit(dssdev);
        dsi_pll_uninit(dsidev, disconnect_lanes);
 }
 
-static int dsi_core_init(struct platform_device *dsidev)
-{
-       /* Autoidle */
-       REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 0, 0);
-
-       /* ENWAKEUP */
-       REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 2, 2);
-
-       /* SIDLEMODE smart-idle */
-       REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 2, 4, 3);
-
-       _dsi_initialize_irq(dsidev);
-
-       return 0;
-}
-
 int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
 {
        struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -4239,40 +4051,46 @@ int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
 
        mutex_lock(&dsi->lock);
 
+       if (dssdev->manager == NULL) {
+               DSSERR("failed to enable display: no manager\n");
+               r = -ENODEV;
+               goto err_start_dev;
+       }
+
        r = omap_dss_start_device(dssdev);
        if (r) {
                DSSERR("failed to start device\n");
-               goto err0;
+               goto err_start_dev;
        }
 
-       enable_clocks(1);
-       dsi_enable_pll_clock(dsidev, 1);
-
-       r = _dsi_reset(dsidev);
+       r = dsi_runtime_get(dsidev);
        if (r)
-               goto err1;
+               goto err_get_dsi;
 
-       dsi_core_init(dsidev);
+       dsi_enable_pll_clock(dsidev, 1);
+
+       _dsi_initialize_irq(dsidev);
 
        r = dsi_display_init_dispc(dssdev);
        if (r)
-               goto err1;
+               goto err_init_dispc;
 
        r = dsi_display_init_dsi(dssdev);
        if (r)
-               goto err2;
+               goto err_init_dsi;
 
        mutex_unlock(&dsi->lock);
 
        return 0;
 
-err2:
+err_init_dsi:
        dsi_display_uninit_dispc(dssdev);
-err1:
-       enable_clocks(0);
+err_init_dispc:
        dsi_enable_pll_clock(dsidev, 0);
+       dsi_runtime_put(dsidev);
+err_get_dsi:
        omap_dss_stop_device(dssdev);
-err0:
+err_start_dev:
        mutex_unlock(&dsi->lock);
        DSSDBG("dsi_display_enable FAILED\n");
        return r;
@@ -4300,7 +4118,7 @@ void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
 
        dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
 
-       enable_clocks(0);
+       dsi_runtime_put(dsidev);
        dsi_enable_pll_clock(dsidev, 0);
 
        omap_dss_stop_device(dssdev);
@@ -4450,8 +4268,44 @@ static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
        dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
 }
 
+static int dsi_get_clocks(struct platform_device *dsidev)
+{
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+       struct clk *clk;
+
+       clk = clk_get(&dsidev->dev, "fck");
+       if (IS_ERR(clk)) {
+               DSSERR("can't get fck\n");
+               return PTR_ERR(clk);
+       }
+
+       dsi->dss_clk = clk;
+
+       clk = clk_get(&dsidev->dev, "sys_clk");
+       if (IS_ERR(clk)) {
+               DSSERR("can't get sys_clk\n");
+               clk_put(dsi->dss_clk);
+               dsi->dss_clk = NULL;
+               return PTR_ERR(clk);
+       }
+
+       dsi->sys_clk = clk;
+
+       return 0;
+}
+
+static void dsi_put_clocks(struct platform_device *dsidev)
+{
+       struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
+
+       if (dsi->dss_clk)
+               clk_put(dsi->dss_clk);
+       if (dsi->sys_clk)
+               clk_put(dsi->sys_clk);
+}
+
 /* DSI1 HW IP initialisation */
-static int omap_dsi1hw_probe(struct platform_device *dsidev)
+static int omap_dsihw_probe(struct platform_device *dsidev)
 {
        struct omap_display_platform_data *dss_plat_data;
        struct omap_dss_board_info *board_info;
@@ -4463,7 +4317,7 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
        dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
        if (!dsi) {
                r = -ENOMEM;
-               goto err0;
+               goto err_alloc;
        }
 
        dsi->pdev = dsidev;
@@ -4472,7 +4326,8 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
 
        dss_plat_data = dsidev->dev.platform_data;
        board_info = dss_plat_data->board_data;
-       dsi->dsi_mux_pads = board_info->dsi_mux_pads;
+       dsi->enable_pads = board_info->dsi_enable_pads;
+       dsi->disable_pads = board_info->dsi_disable_pads;
 
        spin_lock_init(&dsi->irq_lock);
        spin_lock_init(&dsi->errors_lock);
@@ -4486,6 +4341,12 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
        mutex_init(&dsi->lock);
        sema_init(&dsi->bus_lock, 1);
 
+       r = dsi_get_clocks(dsidev);
+       if (r)
+               goto err_get_clk;
+
+       pm_runtime_enable(&dsidev->dev);
+
        INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
                        dsi_framedone_timeout_work_callback);
 
@@ -4498,26 +4359,26 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
        if (!dsi_mem) {
                DSSERR("can't get IORESOURCE_MEM DSI\n");
                r = -EINVAL;
-               goto err1;
+               goto err_ioremap;
        }
        dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
        if (!dsi->base) {
                DSSERR("can't ioremap DSI\n");
                r = -ENOMEM;
-               goto err1;
+               goto err_ioremap;
        }
        dsi->irq = platform_get_irq(dsi->pdev, 0);
        if (dsi->irq < 0) {
                DSSERR("platform_get_irq failed\n");
                r = -ENODEV;
-               goto err2;
+               goto err_get_irq;
        }
 
        r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
                dev_name(&dsidev->dev), dsi->pdev);
        if (r < 0) {
                DSSERR("request_irq failed\n");
-               goto err2;
+               goto err_get_irq;
        }
 
        /* DSI VCs initialization */
@@ -4529,7 +4390,9 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
 
        dsi_calc_clock_param_ranges(dsidev);
 
-       enable_clocks(1);
+       r = dsi_runtime_get(dsidev);
+       if (r)
+               goto err_get_dsi;
 
        rev = dsi_read_reg(dsidev, DSI_REVISION);
        dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
@@ -4537,23 +4400,32 @@ static int omap_dsi1hw_probe(struct platform_device *dsidev)
 
        dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
 
-       enable_clocks(0);
+       dsi_runtime_put(dsidev);
 
        return 0;
-err2:
+
+err_get_dsi:
+       free_irq(dsi->irq, dsi->pdev);
+err_get_irq:
        iounmap(dsi->base);
-err1:
+err_ioremap:
+       pm_runtime_disable(&dsidev->dev);
+err_get_clk:
        kfree(dsi);
-err0:
+err_alloc:
        return r;
 }
 
-static int omap_dsi1hw_remove(struct platform_device *dsidev)
+static int omap_dsihw_remove(struct platform_device *dsidev)
 {
        struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
 
        WARN_ON(dsi->scp_clk_refcount > 0);
 
+       pm_runtime_disable(&dsidev->dev);
+
+       dsi_put_clocks(dsidev);
+
        if (dsi->vdds_dsi_reg != NULL) {
                if (dsi->vdds_dsi_enabled) {
                        regulator_disable(dsi->vdds_dsi_reg);
@@ -4572,21 +4444,55 @@ static int omap_dsi1hw_remove(struct platform_device *dsidev)
        return 0;
 }
 
-static struct platform_driver omap_dsi1hw_driver = {
-       .probe          = omap_dsi1hw_probe,
-       .remove         = omap_dsi1hw_remove,
+static int dsi_runtime_suspend(struct device *dev)
+{
+       dispc_runtime_put();
+       dss_runtime_put();
+
+       return 0;
+}
+
+static int dsi_runtime_resume(struct device *dev)
+{
+       int r;
+
+       r = dss_runtime_get();
+       if (r)
+               goto err_get_dss;
+
+       r = dispc_runtime_get();
+       if (r)
+               goto err_get_dispc;
+
+       return 0;
+
+err_get_dispc:
+       dss_runtime_put();
+err_get_dss:
+       return r;
+}
+
+static const struct dev_pm_ops dsi_pm_ops = {
+       .runtime_suspend = dsi_runtime_suspend,
+       .runtime_resume = dsi_runtime_resume,
+};
+
+static struct platform_driver omap_dsihw_driver = {
+       .probe          = omap_dsihw_probe,
+       .remove         = omap_dsihw_remove,
        .driver         = {
-               .name   = "omapdss_dsi1",
+               .name   = "omapdss_dsi",
                .owner  = THIS_MODULE,
+               .pm     = &dsi_pm_ops,
        },
 };
 
 int dsi_init_platform_driver(void)
 {
-       return platform_driver_register(&omap_dsi1hw_driver);
+       return platform_driver_register(&omap_dsihw_driver);
 }
 
 void dsi_uninit_platform_driver(void)
 {
-       return platform_driver_unregister(&omap_dsi1hw_driver);
+       return platform_driver_unregister(&omap_dsihw_driver);
 }