tegra: dc: Fix div by zero in frame time computation.
[linux-2.6.git] / drivers / video / tegra / dc / mode.c
index be90969..963ced6 100644 (file)
@@ -137,6 +137,17 @@ static bool check_ref_to_sync(struct tegra_dc_mode *mode)
        return true;
 }
 
+static s64 calc_frametime_ns(const struct tegra_dc_mode *m)
+{
+       long h_total, v_total;
+       h_total = m->h_active + m->h_front_porch + m->h_back_porch +
+               m->h_sync_width;
+       v_total = m->v_active + m->v_front_porch + m->v_back_porch +
+               m->v_sync_width;
+       return (!m->pclk) ? 0 : (s64)(div_s64(((s64)h_total * v_total *
+                                       1000000000ULL), m->pclk));
+}
+
 /* return in 1000ths of a Hertz */
 int tegra_dc_calc_refresh(const struct tegra_dc_mode *m)
 {
@@ -199,18 +210,21 @@ int tegra_dc_program_mode(struct tegra_dc *dc, struct tegra_dc_mode *mode)
 
        /* TODO: MIPI/CRT/HDMI clock cals */
 
-       val = DISP_DATA_FORMAT_DF1P1C;
-
-       if (dc->out->align == TEGRA_DC_ALIGN_MSB)
-               val |= DISP_DATA_ALIGNMENT_MSB;
-       else
-               val |= DISP_DATA_ALIGNMENT_LSB;
+       val = 0;
+       if (!(dc->out->type == TEGRA_DC_OUT_DSI ||
+               dc->out->type == TEGRA_DC_OUT_HDMI)) {
+               val = DISP_DATA_FORMAT_DF1P1C;
 
-       if (dc->out->order == TEGRA_DC_ORDER_RED_BLUE)
-               val |= DISP_DATA_ORDER_RED_BLUE;
-       else
-               val |= DISP_DATA_ORDER_BLUE_RED;
+               if (dc->out->align == TEGRA_DC_ALIGN_MSB)
+                       val |= DISP_DATA_ALIGNMENT_MSB;
+               else
+                       val |= DISP_DATA_ALIGNMENT_LSB;
 
+               if (dc->out->order == TEGRA_DC_ORDER_RED_BLUE)
+                       val |= DISP_DATA_ORDER_RED_BLUE;
+               else
+                       val |= DISP_DATA_ORDER_BLUE_RED;
+       }
        tegra_dc_writel(dc, val, DC_DISP_DISP_INTERFACE_CONTROL);
 
        rate = tegra_dc_clk_get_rate(dc);
@@ -265,6 +279,7 @@ int tegra_dc_set_mode(struct tegra_dc *dc, const struct tegra_dc_mode *mode)
                panel_sync_rate = dc->out->dsi->rated_refresh_rate * 1000;
 
        print_mode(dc, mode, __func__);
+       dc->frametime_ns = calc_frametime_ns(mode);
 
        return 0;
 }