1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2006-2011 Intel Corporation
6 * Eric Anholt <eric@anholt.net>
7 * Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
10 #include <linux/delay.h>
11 #include <linux/highmem.h>
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_fourcc.h>
15 #include <drm/drm_vblank.h>
17 #include "framebuffer.h"
19 #include "gma_display.h"
21 #include "psb_intel_drv.h"
22 #include "psb_intel_reg.h"
25 * Returns whether any output on the specified pipe is of the specified type
27 bool gma_pipe_has_type(struct drm_crtc *crtc, int type)
29 struct drm_device *dev = crtc->dev;
30 struct drm_connector_list_iter conn_iter;
31 struct drm_connector *connector;
33 drm_connector_list_iter_begin(dev, &conn_iter);
34 drm_for_each_connector_iter(connector, &conn_iter) {
35 if (connector->encoder && connector->encoder->crtc == crtc) {
36 struct gma_encoder *gma_encoder =
37 gma_attached_encoder(connector);
38 if (gma_encoder->type == type) {
39 drm_connector_list_iter_end(&conn_iter);
44 drm_connector_list_iter_end(&conn_iter);
49 void gma_wait_for_vblank(struct drm_device *dev)
51 /* Wait for 20ms, i.e. one cycle at 50hz. */
55 int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
56 struct drm_framebuffer *old_fb)
58 struct drm_device *dev = crtc->dev;
59 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
60 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
61 struct drm_framebuffer *fb = crtc->primary->fb;
62 struct psb_gem_object *pobj;
63 int pipe = gma_crtc->pipe;
64 const struct psb_offset *map = &dev_priv->regmap[pipe];
65 unsigned long start, offset;
69 if (!gma_power_begin(dev, true))
74 dev_err(dev->dev, "No FB bound\n");
75 goto gma_pipe_cleaner;
78 pobj = to_psb_gem_object(fb->obj[0]);
80 /* We are displaying this buffer, make sure it is actually loaded
82 ret = psb_gem_pin(pobj);
84 goto gma_pipe_set_base_exit;
86 offset = y * fb->pitches[0] + x * fb->format->cpp[0];
88 REG_WRITE(map->stride, fb->pitches[0]);
90 dspcntr = REG_READ(map->cntr);
91 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
93 switch (fb->format->cpp[0] * 8) {
95 dspcntr |= DISPPLANE_8BPP;
98 if (fb->format->depth == 15)
99 dspcntr |= DISPPLANE_15_16BPP;
101 dspcntr |= DISPPLANE_16BPP;
105 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
108 dev_err(dev->dev, "Unknown color depth\n");
110 goto gma_pipe_set_base_exit;
112 REG_WRITE(map->cntr, dspcntr);
115 "Writing base %08lX %08lX %d %d\n", start, offset, x, y);
117 /* FIXME: Investigate whether this really is the base for psb and why
118 the linear offset is named base for the other chips. map->surf
119 should be the base and map->linoff the offset for all chips */
121 REG_WRITE(map->base, offset + start);
124 REG_WRITE(map->base, offset);
126 REG_WRITE(map->surf, start);
131 /* If there was a previous display we can now unpin it */
133 psb_gem_unpin(to_psb_gem_object(old_fb->obj[0]));
135 gma_pipe_set_base_exit:
140 /* Loads the palette/gamma unit for the CRTC with the prepared values */
141 void gma_crtc_load_lut(struct drm_crtc *crtc)
143 struct drm_device *dev = crtc->dev;
144 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
145 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
146 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
147 int palreg = map->palette;
151 /* The clocks have to be on to load the palette. */
155 r = crtc->gamma_store;
156 g = r + crtc->gamma_size;
157 b = g + crtc->gamma_size;
159 if (gma_power_begin(dev, false)) {
160 for (i = 0; i < 256; i++) {
161 REG_WRITE(palreg + 4 * i,
162 (((*r++ >> 8) + gma_crtc->lut_adj[i]) << 16) |
163 (((*g++ >> 8) + gma_crtc->lut_adj[i]) << 8) |
164 ((*b++ >> 8) + gma_crtc->lut_adj[i]));
168 for (i = 0; i < 256; i++) {
169 /* FIXME: Why pipe[0] and not pipe[..._crtc->pipe]? */
170 dev_priv->regs.pipe[0].palette[i] =
171 (((*r++ >> 8) + gma_crtc->lut_adj[i]) << 16) |
172 (((*g++ >> 8) + gma_crtc->lut_adj[i]) << 8) |
173 ((*b++ >> 8) + gma_crtc->lut_adj[i]);
179 static int gma_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
181 struct drm_modeset_acquire_ctx *ctx)
183 gma_crtc_load_lut(crtc);
189 * Sets the power management mode of the pipe and plane.
191 * This code should probably grow support for turning the cursor off and back
192 * on appropriately at the same time as we're turning the pipe off/on.
194 void gma_crtc_dpms(struct drm_crtc *crtc, int mode)
196 struct drm_device *dev = crtc->dev;
197 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
198 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
199 int pipe = gma_crtc->pipe;
200 const struct psb_offset *map = &dev_priv->regmap[pipe];
203 /* XXX: When our outputs are all unaware of DPMS modes other than off
204 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
208 dev_priv->ops->disable_sr(dev);
211 case DRM_MODE_DPMS_ON:
212 case DRM_MODE_DPMS_STANDBY:
213 case DRM_MODE_DPMS_SUSPEND:
214 if (gma_crtc->active)
217 gma_crtc->active = true;
219 /* Enable the DPLL */
220 temp = REG_READ(map->dpll);
221 if ((temp & DPLL_VCO_ENABLE) == 0) {
222 REG_WRITE(map->dpll, temp);
224 /* Wait for the clocks to stabilize. */
226 REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
228 /* Wait for the clocks to stabilize. */
230 REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
232 /* Wait for the clocks to stabilize. */
236 /* Enable the plane */
237 temp = REG_READ(map->cntr);
238 if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
240 temp | DISPLAY_PLANE_ENABLE);
241 /* Flush the plane changes */
242 REG_WRITE(map->base, REG_READ(map->base));
247 /* Enable the pipe */
248 temp = REG_READ(map->conf);
249 if ((temp & PIPEACONF_ENABLE) == 0)
250 REG_WRITE(map->conf, temp | PIPEACONF_ENABLE);
252 temp = REG_READ(map->status);
254 temp |= PIPE_FIFO_UNDERRUN;
255 REG_WRITE(map->status, temp);
256 REG_READ(map->status);
258 gma_crtc_load_lut(crtc);
260 /* Give the overlay scaler a chance to enable
261 * if it's on this pipe */
262 /* psb_intel_crtc_dpms_video(crtc, true); TODO */
264 drm_crtc_vblank_on(crtc);
266 case DRM_MODE_DPMS_OFF:
267 if (!gma_crtc->active)
270 gma_crtc->active = false;
272 /* Give the overlay scaler a chance to disable
273 * if it's on this pipe */
274 /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
276 /* Disable the VGA plane that we never use */
277 REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
279 /* Turn off vblank interrupts */
280 drm_crtc_vblank_off(crtc);
282 /* Wait for vblank for the disable to take effect */
283 gma_wait_for_vblank(dev);
286 temp = REG_READ(map->cntr);
287 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
289 temp & ~DISPLAY_PLANE_ENABLE);
290 /* Flush the plane changes */
291 REG_WRITE(map->base, REG_READ(map->base));
296 temp = REG_READ(map->conf);
297 if ((temp & PIPEACONF_ENABLE) != 0) {
298 REG_WRITE(map->conf, temp & ~PIPEACONF_ENABLE);
302 /* Wait for vblank for the disable to take effect. */
303 gma_wait_for_vblank(dev);
308 temp = REG_READ(map->dpll);
309 if ((temp & DPLL_VCO_ENABLE) != 0) {
310 REG_WRITE(map->dpll, temp & ~DPLL_VCO_ENABLE);
314 /* Wait for the clocks to turn off. */
320 dev_priv->ops->update_wm(dev, crtc);
322 /* Set FIFO watermarks */
323 REG_WRITE(DSPARB, 0x3F3E);
326 static int gma_crtc_cursor_set(struct drm_crtc *crtc,
327 struct drm_file *file_priv, uint32_t handle,
328 uint32_t width, uint32_t height)
330 struct drm_device *dev = crtc->dev;
331 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
332 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
333 int pipe = gma_crtc->pipe;
334 uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
335 uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
338 struct psb_gem_object *pobj;
339 struct psb_gem_object *cursor_pobj = gma_crtc->cursor_pobj;
340 struct drm_gem_object *obj;
342 int ret = 0, i, cursor_pages;
344 /* If we didn't get a handle then turn the cursor off */
346 temp = CURSOR_MODE_DISABLE;
347 if (gma_power_begin(dev, false)) {
348 REG_WRITE(control, temp);
353 /* Unpin the old GEM object */
354 if (gma_crtc->cursor_obj) {
355 pobj = to_psb_gem_object(gma_crtc->cursor_obj);
357 drm_gem_object_put(gma_crtc->cursor_obj);
358 gma_crtc->cursor_obj = NULL;
363 /* Currently we only support 64x64 cursors */
364 if (width != 64 || height != 64) {
365 dev_dbg(dev->dev, "We currently only support 64x64 cursors\n");
369 obj = drm_gem_object_lookup(file_priv, handle);
375 if (obj->size < width * height * 4) {
376 dev_dbg(dev->dev, "Buffer is too small\n");
381 pobj = to_psb_gem_object(obj);
383 /* Pin the memory into the GTT */
384 ret = psb_gem_pin(pobj);
386 dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
390 if (dev_priv->ops->cursor_needs_phys) {
392 dev_err(dev->dev, "No hardware cursor mem available");
397 cursor_pages = obj->size / PAGE_SIZE;
398 if (cursor_pages > 4)
399 cursor_pages = 4; /* Prevent overflow */
401 /* Copy the cursor to cursor mem */
402 tmp_dst = dev_priv->vram_addr + cursor_pobj->offset;
403 for (i = 0; i < cursor_pages; i++) {
404 memcpy_from_page(tmp_dst, pobj->pages[i], 0, PAGE_SIZE);
405 tmp_dst += PAGE_SIZE;
408 addr = gma_crtc->cursor_addr;
411 gma_crtc->cursor_addr = addr;
415 /* set the pipe for the cursor */
416 temp |= (pipe << 28);
417 temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
419 if (gma_power_begin(dev, false)) {
420 REG_WRITE(control, temp);
421 REG_WRITE(base, addr);
425 /* unpin the old bo */
426 if (gma_crtc->cursor_obj) {
427 pobj = to_psb_gem_object(gma_crtc->cursor_obj);
429 drm_gem_object_put(gma_crtc->cursor_obj);
432 gma_crtc->cursor_obj = obj;
437 drm_gem_object_put(obj);
441 static int gma_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
443 struct drm_device *dev = crtc->dev;
444 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
445 int pipe = gma_crtc->pipe;
450 temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
454 temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
458 temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
459 temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
461 addr = gma_crtc->cursor_addr;
463 if (gma_power_begin(dev, false)) {
464 REG_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
465 REG_WRITE((pipe == 0) ? CURABASE : CURBBASE, addr);
471 void gma_crtc_prepare(struct drm_crtc *crtc)
473 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
474 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
477 void gma_crtc_commit(struct drm_crtc *crtc)
479 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
480 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
483 void gma_crtc_disable(struct drm_crtc *crtc)
485 struct psb_gem_object *pobj;
486 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
488 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
490 if (crtc->primary->fb) {
491 pobj = to_psb_gem_object(crtc->primary->fb->obj[0]);
496 void gma_crtc_destroy(struct drm_crtc *crtc)
498 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
500 if (gma_crtc->cursor_pobj)
501 drm_gem_object_put(&gma_crtc->cursor_pobj->base);
503 kfree(gma_crtc->crtc_state);
504 drm_crtc_cleanup(crtc);
508 int gma_crtc_page_flip(struct drm_crtc *crtc,
509 struct drm_framebuffer *fb,
510 struct drm_pending_vblank_event *event,
511 uint32_t page_flip_flags,
512 struct drm_modeset_acquire_ctx *ctx)
514 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
515 struct drm_framebuffer *current_fb = crtc->primary->fb;
516 struct drm_framebuffer *old_fb = crtc->primary->old_fb;
517 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
518 struct drm_device *dev = crtc->dev;
522 if (!crtc_funcs->mode_set_base)
525 /* Using mode_set_base requires the new fb to be set already. */
526 crtc->primary->fb = fb;
529 spin_lock_irqsave(&dev->event_lock, flags);
531 WARN_ON(drm_crtc_vblank_get(crtc) != 0);
533 gma_crtc->page_flip_event = event;
535 /* Call this locked if we want an event at vblank interrupt. */
536 ret = crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y, old_fb);
538 gma_crtc->page_flip_event = NULL;
539 drm_crtc_vblank_put(crtc);
542 spin_unlock_irqrestore(&dev->event_lock, flags);
544 ret = crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y, old_fb);
547 /* Restore previous fb in case of failure. */
549 crtc->primary->fb = current_fb;
554 int gma_crtc_set_config(struct drm_mode_set *set,
555 struct drm_modeset_acquire_ctx *ctx)
557 struct drm_device *dev = set->crtc->dev;
558 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
561 if (!dev_priv->rpm_enabled)
562 return drm_crtc_helper_set_config(set, ctx);
564 pm_runtime_forbid(dev->dev);
565 ret = drm_crtc_helper_set_config(set, ctx);
566 pm_runtime_allow(dev->dev);
571 const struct drm_crtc_funcs gma_crtc_funcs = {
572 .cursor_set = gma_crtc_cursor_set,
573 .cursor_move = gma_crtc_cursor_move,
574 .gamma_set = gma_crtc_gamma_set,
575 .set_config = gma_crtc_set_config,
576 .destroy = gma_crtc_destroy,
577 .page_flip = gma_crtc_page_flip,
578 .enable_vblank = gma_crtc_enable_vblank,
579 .disable_vblank = gma_crtc_disable_vblank,
580 .get_vblank_counter = gma_crtc_get_vblank_counter,
584 * Save HW states of given crtc
586 void gma_crtc_save(struct drm_crtc *crtc)
588 struct drm_device *dev = crtc->dev;
589 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
590 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
591 struct psb_intel_crtc_state *crtc_state = gma_crtc->crtc_state;
592 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
593 uint32_t palette_reg;
597 dev_err(dev->dev, "No CRTC state found\n");
601 crtc_state->saveDSPCNTR = REG_READ(map->cntr);
602 crtc_state->savePIPECONF = REG_READ(map->conf);
603 crtc_state->savePIPESRC = REG_READ(map->src);
604 crtc_state->saveFP0 = REG_READ(map->fp0);
605 crtc_state->saveFP1 = REG_READ(map->fp1);
606 crtc_state->saveDPLL = REG_READ(map->dpll);
607 crtc_state->saveHTOTAL = REG_READ(map->htotal);
608 crtc_state->saveHBLANK = REG_READ(map->hblank);
609 crtc_state->saveHSYNC = REG_READ(map->hsync);
610 crtc_state->saveVTOTAL = REG_READ(map->vtotal);
611 crtc_state->saveVBLANK = REG_READ(map->vblank);
612 crtc_state->saveVSYNC = REG_READ(map->vsync);
613 crtc_state->saveDSPSTRIDE = REG_READ(map->stride);
615 /* NOTE: DSPSIZE DSPPOS only for psb */
616 crtc_state->saveDSPSIZE = REG_READ(map->size);
617 crtc_state->saveDSPPOS = REG_READ(map->pos);
619 crtc_state->saveDSPBASE = REG_READ(map->base);
621 palette_reg = map->palette;
622 for (i = 0; i < 256; ++i)
623 crtc_state->savePalette[i] = REG_READ(palette_reg + (i << 2));
627 * Restore HW states of given crtc
629 void gma_crtc_restore(struct drm_crtc *crtc)
631 struct drm_device *dev = crtc->dev;
632 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
633 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
634 struct psb_intel_crtc_state *crtc_state = gma_crtc->crtc_state;
635 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
636 uint32_t palette_reg;
640 dev_err(dev->dev, "No crtc state\n");
644 if (crtc_state->saveDPLL & DPLL_VCO_ENABLE) {
646 crtc_state->saveDPLL & ~DPLL_VCO_ENABLE);
651 REG_WRITE(map->fp0, crtc_state->saveFP0);
654 REG_WRITE(map->fp1, crtc_state->saveFP1);
657 REG_WRITE(map->dpll, crtc_state->saveDPLL);
661 REG_WRITE(map->htotal, crtc_state->saveHTOTAL);
662 REG_WRITE(map->hblank, crtc_state->saveHBLANK);
663 REG_WRITE(map->hsync, crtc_state->saveHSYNC);
664 REG_WRITE(map->vtotal, crtc_state->saveVTOTAL);
665 REG_WRITE(map->vblank, crtc_state->saveVBLANK);
666 REG_WRITE(map->vsync, crtc_state->saveVSYNC);
667 REG_WRITE(map->stride, crtc_state->saveDSPSTRIDE);
669 REG_WRITE(map->size, crtc_state->saveDSPSIZE);
670 REG_WRITE(map->pos, crtc_state->saveDSPPOS);
672 REG_WRITE(map->src, crtc_state->savePIPESRC);
673 REG_WRITE(map->base, crtc_state->saveDSPBASE);
674 REG_WRITE(map->conf, crtc_state->savePIPECONF);
676 gma_wait_for_vblank(dev);
678 REG_WRITE(map->cntr, crtc_state->saveDSPCNTR);
679 REG_WRITE(map->base, crtc_state->saveDSPBASE);
681 gma_wait_for_vblank(dev);
683 palette_reg = map->palette;
684 for (i = 0; i < 256; ++i)
685 REG_WRITE(palette_reg + (i << 2), crtc_state->savePalette[i]);
688 void gma_encoder_prepare(struct drm_encoder *encoder)
690 const struct drm_encoder_helper_funcs *encoder_funcs =
691 encoder->helper_private;
692 /* lvds has its own version of prepare see psb_intel_lvds_prepare */
693 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
696 void gma_encoder_commit(struct drm_encoder *encoder)
698 const struct drm_encoder_helper_funcs *encoder_funcs =
699 encoder->helper_private;
700 /* lvds has its own version of commit see psb_intel_lvds_commit */
701 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
704 void gma_encoder_destroy(struct drm_encoder *encoder)
706 struct gma_encoder *intel_encoder = to_gma_encoder(encoder);
708 drm_encoder_cleanup(encoder);
709 kfree(intel_encoder);
712 /* Currently there is only a 1:1 mapping of encoders and connectors */
713 struct drm_encoder *gma_best_encoder(struct drm_connector *connector)
715 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
717 return &gma_encoder->base;
720 void gma_connector_attach_encoder(struct gma_connector *connector,
721 struct gma_encoder *encoder)
723 connector->encoder = encoder;
724 drm_connector_attach_encoder(&connector->base,
728 #define GMA_PLL_INVALID(s) { /* DRM_ERROR(s); */ return false; }
730 bool gma_pll_is_valid(struct drm_crtc *crtc,
731 const struct gma_limit_t *limit,
732 struct gma_clock_t *clock)
734 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
735 GMA_PLL_INVALID("p1 out of range");
736 if (clock->p < limit->p.min || limit->p.max < clock->p)
737 GMA_PLL_INVALID("p out of range");
738 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
739 GMA_PLL_INVALID("m2 out of range");
740 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
741 GMA_PLL_INVALID("m1 out of range");
742 /* On CDV m1 is always 0 */
743 if (clock->m1 <= clock->m2 && clock->m1 != 0)
744 GMA_PLL_INVALID("m1 <= m2 && m1 != 0");
745 if (clock->m < limit->m.min || limit->m.max < clock->m)
746 GMA_PLL_INVALID("m out of range");
747 if (clock->n < limit->n.min || limit->n.max < clock->n)
748 GMA_PLL_INVALID("n out of range");
749 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
750 GMA_PLL_INVALID("vco out of range");
751 /* XXX: We may need to be checking "Dot clock"
752 * depending on the multiplier, connector, etc.,
753 * rather than just a single range.
755 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
756 GMA_PLL_INVALID("dot out of range");
761 bool gma_find_best_pll(const struct gma_limit_t *limit,
762 struct drm_crtc *crtc, int target, int refclk,
763 struct gma_clock_t *best_clock)
765 struct drm_device *dev = crtc->dev;
766 const struct gma_clock_funcs *clock_funcs =
767 to_gma_crtc(crtc)->clock_funcs;
768 struct gma_clock_t clock;
771 if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
772 (REG_READ(LVDS) & LVDS_PORT_EN) != 0) {
774 * For LVDS, if the panel is on, just rely on its current
775 * settings for dual-channel. We haven't figured out how to
776 * reliably set up different single/dual channel state, if we
779 if ((REG_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
781 clock.p2 = limit->p2.p2_fast;
783 clock.p2 = limit->p2.p2_slow;
785 if (target < limit->p2.dot_limit)
786 clock.p2 = limit->p2.p2_slow;
788 clock.p2 = limit->p2.p2_fast;
791 memset(best_clock, 0, sizeof(*best_clock));
793 /* m1 is always 0 on CDV so the outmost loop will run just once */
794 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
795 for (clock.m2 = limit->m2.min;
796 (clock.m2 < clock.m1 || clock.m1 == 0) &&
797 clock.m2 <= limit->m2.max; clock.m2++) {
798 for (clock.n = limit->n.min;
799 clock.n <= limit->n.max; clock.n++) {
800 for (clock.p1 = limit->p1.min;
801 clock.p1 <= limit->p1.max;
805 clock_funcs->clock(refclk, &clock);
807 if (!clock_funcs->pll_is_valid(crtc,
811 this_err = abs(clock.dot - target);
812 if (this_err < err) {
821 return err != target;