]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/gma500/mrst_crtc.c
staging: gma500: Add moorestown lvds driver code
[karo-tx-linux.git] / drivers / staging / gma500 / mrst_crtc.c
1 /*
2  * Copyright © 2009 Intel Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17
18 #include <linux/i2c.h>
19 #include <linux/pm_runtime.h>
20
21 #include <drm/drmP.h>
22 #include "psb_fb.h"
23 #include "psb_drv.h"
24 #include "psb_intel_drv.h"
25 #include "psb_intel_reg.h"
26 #include "psb_intel_display.h"
27 #include "psb_powermgmt.h"
28
29 struct psb_intel_range_t {
30         int min, max;
31 };
32
33 struct mrst_limit_t {
34         struct psb_intel_range_t dot, m, p1;
35 };
36
37 struct mrst_clock_t {
38         /* derived values */
39         int dot;
40         int m;
41         int p1;
42 };
43
44 #define MRST_LIMIT_LVDS_100L        0
45 #define MRST_LIMIT_LVDS_83          1
46 #define MRST_LIMIT_LVDS_100         2
47
48 #define MRST_DOT_MIN              19750
49 #define MRST_DOT_MAX              120000
50 #define MRST_M_MIN_100L             20
51 #define MRST_M_MIN_100              10
52 #define MRST_M_MIN_83               12
53 #define MRST_M_MAX_100L             34
54 #define MRST_M_MAX_100              17
55 #define MRST_M_MAX_83               20
56 #define MRST_P1_MIN                 2
57 #define MRST_P1_MAX_0               7
58 #define MRST_P1_MAX_1               8
59
60 static const struct mrst_limit_t mrst_limits[] = {
61         {                       /* MRST_LIMIT_LVDS_100L */
62          .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
63          .m = {.min = MRST_M_MIN_100L, .max = MRST_M_MAX_100L},
64          .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
65          },
66         {                       /* MRST_LIMIT_LVDS_83L */
67          .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
68          .m = {.min = MRST_M_MIN_83, .max = MRST_M_MAX_83},
69          .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_0},
70          },
71         {                       /* MRST_LIMIT_LVDS_100 */
72          .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX},
73          .m = {.min = MRST_M_MIN_100, .max = MRST_M_MAX_100},
74          .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1},
75          },
76 };
77
78 #define MRST_M_MIN          10
79 static const u32 mrst_m_converts[] = {
80         0x2B, 0x15, 0x2A, 0x35, 0x1A, 0x0D, 0x26, 0x33, 0x19, 0x2C,
81         0x36, 0x3B, 0x1D, 0x2E, 0x37, 0x1B, 0x2D, 0x16, 0x0B, 0x25,
82         0x12, 0x09, 0x24, 0x32, 0x39, 0x1c,
83 };
84
85 static const struct mrst_limit_t *mrst_limit(struct drm_crtc *crtc)
86 {
87         const struct mrst_limit_t *limit = NULL;
88         struct drm_device *dev = crtc->dev;
89         DRM_DRIVER_PRIVATE_T *dev_priv = dev->dev_private;
90
91         if (psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)
92             || psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)) {
93                 switch (dev_priv->core_freq) {
94                 case 100:
95                         limit = &mrst_limits[MRST_LIMIT_LVDS_100L];
96                         break;
97                 case 166:
98                         limit = &mrst_limits[MRST_LIMIT_LVDS_83];
99                         break;
100                 case 200:
101                         limit = &mrst_limits[MRST_LIMIT_LVDS_100];
102                         break;
103                 }
104         } else {
105                 limit = NULL;
106                 PSB_DEBUG_ENTRY("mrst_limit Wrong display type.\n");
107         }
108
109         return limit;
110 }
111
112 /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
113 static void mrst_clock(int refclk, struct mrst_clock_t *clock)
114 {
115         clock->dot = (refclk * clock->m) / (14 * clock->p1);
116 }
117
118 void mrstPrintPll(char *prefix, struct mrst_clock_t *clock)
119 {
120         PSB_DEBUG_ENTRY("%s: dotclock = %d,  m = %d, p1 = %d.\n",
121              prefix, clock->dot, clock->m, clock->p1);
122 }
123
124 /**
125  * Returns a set of divisors for the desired target clock with the given refclk,
126  * or FALSE.  Divisor values are the actual divisors for
127  */
128 static bool
129 mrstFindBestPLL(struct drm_crtc *crtc, int target, int refclk,
130                 struct mrst_clock_t *best_clock)
131 {
132         struct mrst_clock_t clock;
133         const struct mrst_limit_t *limit = mrst_limit(crtc);
134         int err = target;
135
136         memset(best_clock, 0, sizeof(*best_clock));
137
138         for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) {
139                 for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max;
140                      clock.p1++) {
141                         int this_err;
142
143                         mrst_clock(refclk, &clock);
144
145                         this_err = abs(clock.dot - target);
146                         if (this_err < err) {
147                                 *best_clock = clock;
148                                 err = this_err;
149                         }
150                 }
151         }
152         DRM_DEBUG("mrstFindBestPLL err = %d.\n", err);
153
154         return err != target;
155 }
156
157 /**
158  * Sets the power management mode of the pipe and plane.
159  *
160  * This code should probably grow support for turning the cursor off and back
161  * on appropriately at the same time as we're turning the pipe off/on.
162  */
163 static void mrst_crtc_dpms(struct drm_crtc *crtc, int mode)
164 {
165         struct drm_device *dev = crtc->dev;
166         struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
167         int pipe = psb_intel_crtc->pipe;
168         int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B;
169         int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
170         int dspbase_reg = (pipe == 0) ? MRST_DSPABASE : DSPBBASE;
171         int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
172         u32 temp;
173         bool enabled;
174
175         PSB_DEBUG_ENTRY("mode = %d, pipe = %d\n", mode, pipe);
176
177         if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND,
178                                        OSPM_UHB_FORCE_POWER_ON))
179                 return;
180
181         /* XXX: When our outputs are all unaware of DPMS modes other than off
182          * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
183          */
184         switch (mode) {
185         case DRM_MODE_DPMS_ON:
186         case DRM_MODE_DPMS_STANDBY:
187         case DRM_MODE_DPMS_SUSPEND:
188                 /* Enable the DPLL */
189                 temp = REG_READ(dpll_reg);
190                 if ((temp & DPLL_VCO_ENABLE) == 0) {
191                         REG_WRITE(dpll_reg, temp);
192                         REG_READ(dpll_reg);
193                         /* Wait for the clocks to stabilize. */
194                         udelay(150);
195                         REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
196                         REG_READ(dpll_reg);
197                         /* Wait for the clocks to stabilize. */
198                         udelay(150);
199                         REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
200                         REG_READ(dpll_reg);
201                         /* Wait for the clocks to stabilize. */
202                         udelay(150);
203                 }
204                 /* Enable the pipe */
205                 temp = REG_READ(pipeconf_reg);
206                 if ((temp & PIPEACONF_ENABLE) == 0)
207                         REG_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
208                 /* Enable the plane */
209                 temp = REG_READ(dspcntr_reg);
210                 if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
211                         REG_WRITE(dspcntr_reg,
212                                   temp | DISPLAY_PLANE_ENABLE);
213                         /* Flush the plane changes */
214                         REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
215                 }
216
217                 psb_intel_crtc_load_lut(crtc);
218
219                 /* Give the overlay scaler a chance to enable
220                    if it's on this pipe */
221                 /* psb_intel_crtc_dpms_video(crtc, true); TODO */
222                 break;
223         case DRM_MODE_DPMS_OFF:
224                 /* Give the overlay scaler a chance to disable
225                  * if it's on this pipe */
226                 /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
227
228                 /* Disable the VGA plane that we never use */
229                 REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
230                 /* Disable display plane */
231                 temp = REG_READ(dspcntr_reg);
232                 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
233                         REG_WRITE(dspcntr_reg,
234                                   temp & ~DISPLAY_PLANE_ENABLE);
235                         /* Flush the plane changes */
236                         REG_WRITE(dspbase_reg, REG_READ(dspbase_reg));
237                         REG_READ(dspbase_reg);
238                 }
239
240                 /* Next, disable display pipes */
241                 temp = REG_READ(pipeconf_reg);
242                 if ((temp & PIPEACONF_ENABLE) != 0) {
243                         REG_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
244                         REG_READ(pipeconf_reg);
245                 }
246                 /* Wait for for the pipe disable to take effect. */
247                 psb_intel_wait_for_vblank(dev);
248
249                 temp = REG_READ(dpll_reg);
250                 if ((temp & DPLL_VCO_ENABLE) != 0) {
251                         REG_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
252                         REG_READ(dpll_reg);
253                 }
254
255                 /* Wait for the clocks to turn off. */
256                 udelay(150);
257                 break;
258         }
259
260         enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
261
262         /*Set FIFO Watermarks*/
263         REG_WRITE(DSPARB, 0x3FFF);
264         REG_WRITE(DSPFW1, 0x3F88080A);
265         REG_WRITE(DSPFW2, 0x0b060808);
266         REG_WRITE(DSPFW3, 0x0);
267         REG_WRITE(DSPFW4, 0x08030404);
268         REG_WRITE(DSPFW5, 0x04040404);
269         REG_WRITE(DSPFW6, 0x78);
270         REG_WRITE(0x70400, REG_READ(0x70400) | 0x4000);
271         /* Must write Bit 14 of the Chicken Bit Register */
272
273         ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND);
274 }
275
276 /**
277  * Return the pipe currently connected to the panel fitter,
278  * or -1 if the panel fitter is not present or not in use
279  */
280 static int mrst_panel_fitter_pipe(struct drm_device *dev)
281 {
282         u32 pfit_control;
283
284         pfit_control = REG_READ(PFIT_CONTROL);
285
286         /* See if the panel fitter is in use */
287         if ((pfit_control & PFIT_ENABLE) == 0)
288                 return -1;
289         return (pfit_control >> 29) & 3;
290 }
291
292 static int mrst_crtc_mode_set(struct drm_crtc *crtc,
293                               struct drm_display_mode *mode,
294                               struct drm_display_mode *adjusted_mode,
295                               int x, int y,
296                               struct drm_framebuffer *old_fb)
297 {
298         struct drm_device *dev = crtc->dev;
299         struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
300         DRM_DRIVER_PRIVATE_T *dev_priv = dev->dev_private;
301         int pipe = psb_intel_crtc->pipe;
302         int fp_reg = (pipe == 0) ? MRST_FPA0 : FPB0;
303         int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B;
304         int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
305         int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
306         int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
307         int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
308         int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
309         int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
310         int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
311         int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
312         int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
313         int refclk = 0;
314         struct mrst_clock_t clock;
315         u32 dpll = 0, fp = 0, dspcntr, pipeconf;
316         bool ok, is_sdvo = false;
317         bool is_crt = false, is_lvds = false, is_tv = false;
318         bool is_mipi = false;
319         struct drm_mode_config *mode_config = &dev->mode_config;
320         struct psb_intel_output *psb_intel_output = NULL;
321         uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN;
322         struct drm_encoder *encoder;
323
324         PSB_DEBUG_ENTRY("pipe = 0x%x\n", pipe);
325
326         if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND,
327                                         OSPM_UHB_FORCE_POWER_ON))
328                 return 0;
329
330         memcpy(&psb_intel_crtc->saved_mode,
331                 mode,
332                 sizeof(struct drm_display_mode));
333         memcpy(&psb_intel_crtc->saved_adjusted_mode,
334                 adjusted_mode,
335                 sizeof(struct drm_display_mode));
336
337         list_for_each_entry(encoder, &mode_config->encoder_list, head) {
338
339                 if (encoder->crtc != crtc)
340                         continue;
341
342                 psb_intel_output = enc_to_psb_intel_output(encoder);
343                 switch (psb_intel_output->type) {
344                 case INTEL_OUTPUT_LVDS:
345                         is_lvds = true;
346                         break;
347                 case INTEL_OUTPUT_SDVO:
348                         is_sdvo = true;
349                         break;
350                 case INTEL_OUTPUT_TVOUT:
351                         is_tv = true;
352                         break;
353                 case INTEL_OUTPUT_ANALOG:
354                         is_crt = true;
355                         break;
356                 case INTEL_OUTPUT_MIPI:
357                         is_mipi = true;
358                         break;
359                 }
360         }
361
362         /* Disable the VGA plane that we never use */
363         REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
364
365         /* Disable the panel fitter if it was on our pipe */
366         if (mrst_panel_fitter_pipe(dev) == pipe)
367                 REG_WRITE(PFIT_CONTROL, 0);
368
369         REG_WRITE(pipesrc_reg,
370                   ((mode->crtc_hdisplay - 1) << 16) |
371                   (mode->crtc_vdisplay - 1));
372
373         if (psb_intel_output)
374                 drm_connector_property_get_value(&psb_intel_output->base,
375                         dev->mode_config.scaling_mode_property, &scalingType);
376
377         if (scalingType == DRM_MODE_SCALE_NO_SCALE) {
378                 /* Moorestown doesn't have register support for centering so
379                  * we need to mess with the h/vblank and h/vsync start and
380                  * ends to get centering */
381                 int offsetX = 0, offsetY = 0;
382
383                 offsetX = (adjusted_mode->crtc_hdisplay -
384                            mode->crtc_hdisplay) / 2;
385                 offsetY = (adjusted_mode->crtc_vdisplay -
386                            mode->crtc_vdisplay) / 2;
387
388                 REG_WRITE(htot_reg, (mode->crtc_hdisplay - 1) |
389                         ((adjusted_mode->crtc_htotal - 1) << 16));
390                 REG_WRITE(vtot_reg, (mode->crtc_vdisplay - 1) |
391                         ((adjusted_mode->crtc_vtotal - 1) << 16));
392                 REG_WRITE(hblank_reg,
393                         (adjusted_mode->crtc_hblank_start - offsetX - 1) |
394                         ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16));
395                 REG_WRITE(hsync_reg,
396                         (adjusted_mode->crtc_hsync_start - offsetX - 1) |
397                         ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16));
398                 REG_WRITE(vblank_reg,
399                         (adjusted_mode->crtc_vblank_start - offsetY - 1) |
400                         ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16));
401                 REG_WRITE(vsync_reg,
402                         (adjusted_mode->crtc_vsync_start - offsetY - 1) |
403                         ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16));
404         } else {
405                 REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
406                         ((adjusted_mode->crtc_htotal - 1) << 16));
407                 REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
408                         ((adjusted_mode->crtc_vtotal - 1) << 16));
409                 REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
410                         ((adjusted_mode->crtc_hblank_end - 1) << 16));
411                 REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
412                         ((adjusted_mode->crtc_hsync_end - 1) << 16));
413                 REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
414                         ((adjusted_mode->crtc_vblank_end - 1) << 16));
415                 REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
416                         ((adjusted_mode->crtc_vsync_end - 1) << 16));
417         }
418
419         /* Flush the plane changes */
420         {
421                 struct drm_crtc_helper_funcs *crtc_funcs =
422                     crtc->helper_private;
423                 crtc_funcs->mode_set_base(crtc, x, y, old_fb);
424         }
425
426         /* setup pipeconf */
427         pipeconf = REG_READ(pipeconf_reg);
428
429         /* Set up the display plane register */
430         dspcntr = REG_READ(dspcntr_reg);
431         dspcntr |= DISPPLANE_GAMMA_ENABLE;
432
433         if (pipe == 0)
434                 dspcntr |= DISPPLANE_SEL_PIPE_A;
435         else
436                 dspcntr |= DISPPLANE_SEL_PIPE_B;
437
438         dev_priv->dspcntr = dspcntr |= DISPLAY_PLANE_ENABLE;
439         dev_priv->pipeconf = pipeconf |= PIPEACONF_ENABLE;
440
441         if (is_mipi)
442                 goto mrst_crtc_mode_set_exit;
443
444         refclk = dev_priv->core_freq * 1000;
445
446         dpll = 0;               /*BIT16 = 0 for 100MHz reference */
447
448         ok = mrstFindBestPLL(crtc, adjusted_mode->clock, refclk, &clock);
449
450         if (!ok) {
451                 PSB_DEBUG_ENTRY(
452                         "mrstFindBestPLL fail in mrst_crtc_mode_set.\n");
453         } else {
454                 PSB_DEBUG_ENTRY("mrst_crtc_mode_set pixel clock = %d,"
455                          "m = %x, p1 = %x.\n", clock.dot, clock.m,
456                          clock.p1);
457         }
458
459         fp = mrst_m_converts[(clock.m - MRST_M_MIN)] << 8;
460
461         dpll |= DPLL_VGA_MODE_DIS;
462
463
464         dpll |= DPLL_VCO_ENABLE;
465
466         if (is_lvds)
467                 dpll |= DPLLA_MODE_LVDS;
468         else
469                 dpll |= DPLLB_MODE_DAC_SERIAL;
470
471         if (is_sdvo) {
472                 int sdvo_pixel_multiply =
473                     adjusted_mode->clock / mode->clock;
474
475                 dpll |= DPLL_DVO_HIGH_SPEED;
476                 dpll |=
477                     (sdvo_pixel_multiply -
478                      1) << SDVO_MULTIPLIER_SHIFT_HIRES;
479         }
480
481
482         /* compute bitmask from p1 value */
483         dpll |= (1 << (clock.p1 - 2)) << 17;
484
485         dpll |= DPLL_VCO_ENABLE;
486
487         mrstPrintPll("chosen", &clock);
488
489         if (dpll & DPLL_VCO_ENABLE) {
490                 REG_WRITE(fp_reg, fp);
491                 REG_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
492                 REG_READ(dpll_reg);
493                 /* Check the DPLLA lock bit PIPEACONF[29] */
494                 udelay(150);
495         }
496
497         REG_WRITE(fp_reg, fp);
498         REG_WRITE(dpll_reg, dpll);
499         REG_READ(dpll_reg);
500         /* Wait for the clocks to stabilize. */
501         udelay(150);
502
503         /* write it again -- the BIOS does, after all */
504         REG_WRITE(dpll_reg, dpll);
505         REG_READ(dpll_reg);
506         /* Wait for the clocks to stabilize. */
507         udelay(150);
508
509         REG_WRITE(pipeconf_reg, pipeconf);
510         REG_READ(pipeconf_reg);
511         psb_intel_wait_for_vblank(dev);
512
513         REG_WRITE(dspcntr_reg, dspcntr);
514         psb_intel_wait_for_vblank(dev);
515
516 mrst_crtc_mode_set_exit:
517         ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND);
518         return 0;
519 }
520
521 static bool mrst_crtc_mode_fixup(struct drm_crtc *crtc,
522                                   struct drm_display_mode *mode,
523                                   struct drm_display_mode *adjusted_mode)
524 {
525         return true;
526 }
527
528 int mrst_pipe_set_base(struct drm_crtc *crtc,
529                             int x, int y, struct drm_framebuffer *old_fb)
530 {
531         struct drm_device *dev = crtc->dev;
532         /* struct drm_i915_master_private *master_priv; */
533         struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc);
534         struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb);
535         struct psb_intel_mode_device *mode_dev = psb_intel_crtc->mode_dev;
536         int pipe = psb_intel_crtc->pipe;
537         unsigned long Start, Offset;
538         /* FIXME: check if we need this surely MRST is pipe 0 only */
539         int dspbase = (pipe == 0 ? DSPALINOFF : DSPBBASE);
540         int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
541         int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
542         int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
543         u32 dspcntr;
544         int ret = 0;
545
546         PSB_DEBUG_ENTRY("\n");
547
548         /* no fb bound */
549         if (!crtc->fb) {
550                 DRM_DEBUG("No FB bound\n");
551                 return 0;
552         }
553
554         if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND,
555                                        OSPM_UHB_FORCE_POWER_ON))
556                 return 0;
557
558         Start = mode_dev->bo_offset(dev, psbfb);
559         Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
560
561         REG_WRITE(dspstride, crtc->fb->pitch);
562
563         dspcntr = REG_READ(dspcntr_reg);
564         dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
565
566         switch (crtc->fb->bits_per_pixel) {
567         case 8:
568                 dspcntr |= DISPPLANE_8BPP;
569                 break;
570         case 16:
571                 if (crtc->fb->depth == 15)
572                         dspcntr |= DISPPLANE_15_16BPP;
573                 else
574                         dspcntr |= DISPPLANE_16BPP;
575                 break;
576         case 24:
577         case 32:
578                 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
579                 break;
580         default:
581                 DRM_ERROR("Unknown color depth\n");
582                 ret = -EINVAL;
583                 goto pipe_set_base_exit;
584         }
585         REG_WRITE(dspcntr_reg, dspcntr);
586
587         DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
588         if (0 /* FIXMEAC - check what PSB needs */) {
589                 REG_WRITE(dspbase, Offset);
590                 REG_READ(dspbase);
591                 REG_WRITE(dspsurf, Start);
592                 REG_READ(dspsurf);
593         } else {
594                 REG_WRITE(dspbase, Start + Offset);
595                 REG_READ(dspbase);
596         }
597
598 pipe_set_base_exit:
599         ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND);
600         return ret;
601 }
602
603 static void mrst_crtc_prepare(struct drm_crtc *crtc)
604 {
605         struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
606         crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
607 }
608
609 static void mrst_crtc_commit(struct drm_crtc *crtc)
610 {
611         struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
612         crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
613 }
614
615 const struct drm_crtc_helper_funcs mrst_helper_funcs = {
616         .dpms = mrst_crtc_dpms,
617         .mode_fixup = mrst_crtc_mode_fixup,
618         .mode_set = mrst_crtc_mode_set,
619         .mode_set_base = mrst_pipe_set_base,
620         .prepare = mrst_crtc_prepare,
621         .commit = mrst_crtc_commit,
622 };
623