1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2006-2011 Intel Corporation
10 #include <linux/delay.h>
11 #include <linux/highmem.h>
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_crtc_helper.h>
15 #include <drm/drm_fourcc.h>
16 #include <drm/drm_framebuffer.h>
17 #include <drm/drm_modeset_helper_vtables.h>
18 #include <drm/drm_vblank.h>
20 #include "framebuffer.h"
22 #include "gma_display.h"
24 #include "psb_intel_drv.h"
25 #include "psb_intel_reg.h"
28 * Returns whether any output on the specified pipe is of the specified type
30 bool gma_pipe_has_type(struct drm_crtc *crtc, int type)
32 struct drm_device *dev = crtc->dev;
33 struct drm_connector_list_iter conn_iter;
34 struct drm_connector *connector;
36 drm_connector_list_iter_begin(dev, &conn_iter);
37 drm_for_each_connector_iter(connector, &conn_iter) {
38 if (connector->encoder && connector->encoder->crtc == crtc) {
39 struct gma_encoder *gma_encoder =
40 gma_attached_encoder(connector);
41 if (gma_encoder->type == type) {
42 drm_connector_list_iter_end(&conn_iter);
47 drm_connector_list_iter_end(&conn_iter);
52 void gma_wait_for_vblank(struct drm_device *dev)
54 /* Wait for 20ms, i.e. one cycle at 50hz. */
58 int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
59 struct drm_framebuffer *old_fb)
61 struct drm_device *dev = crtc->dev;
62 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
63 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
64 struct drm_framebuffer *fb = crtc->primary->fb;
65 struct psb_gem_object *pobj;
66 int pipe = gma_crtc->pipe;
67 const struct psb_offset *map = &dev_priv->regmap[pipe];
68 unsigned long start, offset;
72 if (!gma_power_begin(dev, true))
77 dev_err(dev->dev, "No FB bound\n");
78 goto gma_pipe_cleaner;
81 pobj = to_psb_gem_object(fb->obj[0]);
83 /* We are displaying this buffer, make sure it is actually loaded
85 ret = psb_gem_pin(pobj);
87 goto gma_pipe_set_base_exit;
89 offset = y * fb->pitches[0] + x * fb->format->cpp[0];
91 REG_WRITE(map->stride, fb->pitches[0]);
93 dspcntr = REG_READ(map->cntr);
94 dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
96 switch (fb->format->cpp[0] * 8) {
98 dspcntr |= DISPPLANE_8BPP;
101 if (fb->format->depth == 15)
102 dspcntr |= DISPPLANE_15_16BPP;
104 dspcntr |= DISPPLANE_16BPP;
108 dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
111 dev_err(dev->dev, "Unknown color depth\n");
113 goto gma_pipe_set_base_exit;
115 REG_WRITE(map->cntr, dspcntr);
118 "Writing base %08lX %08lX %d %d\n", start, offset, x, y);
120 /* FIXME: Investigate whether this really is the base for psb and why
121 the linear offset is named base for the other chips. map->surf
122 should be the base and map->linoff the offset for all chips */
124 REG_WRITE(map->base, offset + start);
127 REG_WRITE(map->base, offset);
129 REG_WRITE(map->surf, start);
134 /* If there was a previous display we can now unpin it */
136 psb_gem_unpin(to_psb_gem_object(old_fb->obj[0]));
138 gma_pipe_set_base_exit:
143 /* Loads the palette/gamma unit for the CRTC with the prepared values */
144 void gma_crtc_load_lut(struct drm_crtc *crtc)
146 struct drm_device *dev = crtc->dev;
147 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
148 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
149 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
150 int palreg = map->palette;
154 /* The clocks have to be on to load the palette. */
158 r = crtc->gamma_store;
159 g = r + crtc->gamma_size;
160 b = g + crtc->gamma_size;
162 if (gma_power_begin(dev, false)) {
163 for (i = 0; i < 256; i++) {
164 REG_WRITE(palreg + 4 * i,
165 (((*r++ >> 8) + gma_crtc->lut_adj[i]) << 16) |
166 (((*g++ >> 8) + gma_crtc->lut_adj[i]) << 8) |
167 ((*b++ >> 8) + gma_crtc->lut_adj[i]));
171 for (i = 0; i < 256; i++) {
172 /* FIXME: Why pipe[0] and not pipe[..._crtc->pipe]? */
173 dev_priv->regs.pipe[0].palette[i] =
174 (((*r++ >> 8) + gma_crtc->lut_adj[i]) << 16) |
175 (((*g++ >> 8) + gma_crtc->lut_adj[i]) << 8) |
176 ((*b++ >> 8) + gma_crtc->lut_adj[i]);
182 static int gma_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
184 struct drm_modeset_acquire_ctx *ctx)
186 gma_crtc_load_lut(crtc);
192 * Sets the power management mode of the pipe and plane.
194 * This code should probably grow support for turning the cursor off and back
195 * on appropriately at the same time as we're turning the pipe off/on.
197 void gma_crtc_dpms(struct drm_crtc *crtc, int mode)
199 struct drm_device *dev = crtc->dev;
200 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
201 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
202 int pipe = gma_crtc->pipe;
203 const struct psb_offset *map = &dev_priv->regmap[pipe];
206 /* XXX: When our outputs are all unaware of DPMS modes other than off
207 * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
211 dev_priv->ops->disable_sr(dev);
214 case DRM_MODE_DPMS_ON:
215 case DRM_MODE_DPMS_STANDBY:
216 case DRM_MODE_DPMS_SUSPEND:
217 if (gma_crtc->active)
220 gma_crtc->active = true;
222 /* Enable the DPLL */
223 temp = REG_READ(map->dpll);
224 if ((temp & DPLL_VCO_ENABLE) == 0) {
225 REG_WRITE(map->dpll, temp);
227 /* Wait for the clocks to stabilize. */
229 REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
231 /* Wait for the clocks to stabilize. */
233 REG_WRITE(map->dpll, temp | DPLL_VCO_ENABLE);
235 /* Wait for the clocks to stabilize. */
239 /* Enable the plane */
240 temp = REG_READ(map->cntr);
241 if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
243 temp | DISPLAY_PLANE_ENABLE);
244 /* Flush the plane changes */
245 REG_WRITE(map->base, REG_READ(map->base));
250 /* Enable the pipe */
251 temp = REG_READ(map->conf);
252 if ((temp & PIPEACONF_ENABLE) == 0)
253 REG_WRITE(map->conf, temp | PIPEACONF_ENABLE);
255 temp = REG_READ(map->status);
257 temp |= PIPE_FIFO_UNDERRUN;
258 REG_WRITE(map->status, temp);
259 REG_READ(map->status);
261 gma_crtc_load_lut(crtc);
263 /* Give the overlay scaler a chance to enable
264 * if it's on this pipe */
265 /* psb_intel_crtc_dpms_video(crtc, true); TODO */
267 drm_crtc_vblank_on(crtc);
269 case DRM_MODE_DPMS_OFF:
270 if (!gma_crtc->active)
273 gma_crtc->active = false;
275 /* Give the overlay scaler a chance to disable
276 * if it's on this pipe */
277 /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */
279 /* Disable the VGA plane that we never use */
280 REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
282 /* Turn off vblank interrupts */
283 drm_crtc_vblank_off(crtc);
285 /* Wait for vblank for the disable to take effect */
286 gma_wait_for_vblank(dev);
289 temp = REG_READ(map->cntr);
290 if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
292 temp & ~DISPLAY_PLANE_ENABLE);
293 /* Flush the plane changes */
294 REG_WRITE(map->base, REG_READ(map->base));
299 temp = REG_READ(map->conf);
300 if ((temp & PIPEACONF_ENABLE) != 0) {
301 REG_WRITE(map->conf, temp & ~PIPEACONF_ENABLE);
305 /* Wait for vblank for the disable to take effect. */
306 gma_wait_for_vblank(dev);
311 temp = REG_READ(map->dpll);
312 if ((temp & DPLL_VCO_ENABLE) != 0) {
313 REG_WRITE(map->dpll, temp & ~DPLL_VCO_ENABLE);
317 /* Wait for the clocks to turn off. */
323 dev_priv->ops->update_wm(dev, crtc);
325 /* Set FIFO watermarks */
326 REG_WRITE(DSPARB, 0x3F3E);
329 static int gma_crtc_cursor_set(struct drm_crtc *crtc,
330 struct drm_file *file_priv, uint32_t handle,
331 uint32_t width, uint32_t height)
333 struct drm_device *dev = crtc->dev;
334 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
335 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
336 int pipe = gma_crtc->pipe;
337 uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
338 uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
341 struct psb_gem_object *pobj;
342 struct psb_gem_object *cursor_pobj = gma_crtc->cursor_pobj;
343 struct drm_gem_object *obj;
345 int ret = 0, i, cursor_pages;
347 /* If we didn't get a handle then turn the cursor off */
349 temp = CURSOR_MODE_DISABLE;
350 if (gma_power_begin(dev, false)) {
351 REG_WRITE(control, temp);
356 /* Unpin the old GEM object */
357 if (gma_crtc->cursor_obj) {
358 pobj = to_psb_gem_object(gma_crtc->cursor_obj);
360 drm_gem_object_put(gma_crtc->cursor_obj);
361 gma_crtc->cursor_obj = NULL;
366 /* Currently we only support 64x64 cursors */
367 if (width != 64 || height != 64) {
368 dev_dbg(dev->dev, "We currently only support 64x64 cursors\n");
372 obj = drm_gem_object_lookup(file_priv, handle);
378 if (obj->size < width * height * 4) {
379 dev_dbg(dev->dev, "Buffer is too small\n");
384 pobj = to_psb_gem_object(obj);
386 /* Pin the memory into the GTT */
387 ret = psb_gem_pin(pobj);
389 dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
393 if (dev_priv->ops->cursor_needs_phys) {
395 dev_err(dev->dev, "No hardware cursor mem available");
400 cursor_pages = obj->size / PAGE_SIZE;
401 if (cursor_pages > 4)
402 cursor_pages = 4; /* Prevent overflow */
404 /* Copy the cursor to cursor mem */
405 tmp_dst = dev_priv->vram_addr + cursor_pobj->offset;
406 for (i = 0; i < cursor_pages; i++) {
407 memcpy_from_page(tmp_dst, pobj->pages[i], 0, PAGE_SIZE);
408 tmp_dst += PAGE_SIZE;
411 addr = gma_crtc->cursor_addr;
414 gma_crtc->cursor_addr = addr;
418 /* set the pipe for the cursor */
419 temp |= (pipe << 28);
420 temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
422 if (gma_power_begin(dev, false)) {
423 REG_WRITE(control, temp);
424 REG_WRITE(base, addr);
428 /* unpin the old bo */
429 if (gma_crtc->cursor_obj) {
430 pobj = to_psb_gem_object(gma_crtc->cursor_obj);
432 drm_gem_object_put(gma_crtc->cursor_obj);
435 gma_crtc->cursor_obj = obj;
440 drm_gem_object_put(obj);
444 static int gma_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
446 struct drm_device *dev = crtc->dev;
447 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
448 int pipe = gma_crtc->pipe;
453 temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
457 temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
461 temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
462 temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
464 addr = gma_crtc->cursor_addr;
466 if (gma_power_begin(dev, false)) {
467 REG_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
468 REG_WRITE((pipe == 0) ? CURABASE : CURBBASE, addr);
474 void gma_crtc_prepare(struct drm_crtc *crtc)
476 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
477 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
480 void gma_crtc_commit(struct drm_crtc *crtc)
482 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
483 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
486 void gma_crtc_disable(struct drm_crtc *crtc)
488 struct psb_gem_object *pobj;
489 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
491 crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
493 if (crtc->primary->fb) {
494 pobj = to_psb_gem_object(crtc->primary->fb->obj[0]);
499 void gma_crtc_destroy(struct drm_crtc *crtc)
501 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
503 if (gma_crtc->cursor_pobj)
504 drm_gem_object_put(&gma_crtc->cursor_pobj->base);
506 kfree(gma_crtc->crtc_state);
507 drm_crtc_cleanup(crtc);
511 int gma_crtc_page_flip(struct drm_crtc *crtc,
512 struct drm_framebuffer *fb,
513 struct drm_pending_vblank_event *event,
514 uint32_t page_flip_flags,
515 struct drm_modeset_acquire_ctx *ctx)
517 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
518 struct drm_framebuffer *current_fb = crtc->primary->fb;
519 struct drm_framebuffer *old_fb = crtc->primary->old_fb;
520 const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
521 struct drm_device *dev = crtc->dev;
525 if (!crtc_funcs->mode_set_base)
528 /* Using mode_set_base requires the new fb to be set already. */
529 crtc->primary->fb = fb;
532 spin_lock_irqsave(&dev->event_lock, flags);
534 WARN_ON(drm_crtc_vblank_get(crtc) != 0);
536 gma_crtc->page_flip_event = event;
537 spin_unlock_irqrestore(&dev->event_lock, flags);
539 /* Call this locked if we want an event at vblank interrupt. */
540 ret = crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y, old_fb);
542 spin_lock_irqsave(&dev->event_lock, flags);
543 if (gma_crtc->page_flip_event) {
544 gma_crtc->page_flip_event = NULL;
545 drm_crtc_vblank_put(crtc);
547 spin_unlock_irqrestore(&dev->event_lock, flags);
550 ret = crtc_funcs->mode_set_base(crtc, crtc->x, crtc->y, old_fb);
553 /* Restore previous fb in case of failure. */
555 crtc->primary->fb = current_fb;
560 const struct drm_crtc_funcs gma_crtc_funcs = {
561 .cursor_set = gma_crtc_cursor_set,
562 .cursor_move = gma_crtc_cursor_move,
563 .gamma_set = gma_crtc_gamma_set,
564 .set_config = drm_crtc_helper_set_config,
565 .destroy = gma_crtc_destroy,
566 .page_flip = gma_crtc_page_flip,
567 .enable_vblank = gma_crtc_enable_vblank,
568 .disable_vblank = gma_crtc_disable_vblank,
569 .get_vblank_counter = gma_crtc_get_vblank_counter,
573 * Save HW states of given crtc
575 void gma_crtc_save(struct drm_crtc *crtc)
577 struct drm_device *dev = crtc->dev;
578 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
579 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
580 struct psb_intel_crtc_state *crtc_state = gma_crtc->crtc_state;
581 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
582 uint32_t palette_reg;
586 dev_err(dev->dev, "No CRTC state found\n");
590 crtc_state->saveDSPCNTR = REG_READ(map->cntr);
591 crtc_state->savePIPECONF = REG_READ(map->conf);
592 crtc_state->savePIPESRC = REG_READ(map->src);
593 crtc_state->saveFP0 = REG_READ(map->fp0);
594 crtc_state->saveFP1 = REG_READ(map->fp1);
595 crtc_state->saveDPLL = REG_READ(map->dpll);
596 crtc_state->saveHTOTAL = REG_READ(map->htotal);
597 crtc_state->saveHBLANK = REG_READ(map->hblank);
598 crtc_state->saveHSYNC = REG_READ(map->hsync);
599 crtc_state->saveVTOTAL = REG_READ(map->vtotal);
600 crtc_state->saveVBLANK = REG_READ(map->vblank);
601 crtc_state->saveVSYNC = REG_READ(map->vsync);
602 crtc_state->saveDSPSTRIDE = REG_READ(map->stride);
604 /* NOTE: DSPSIZE DSPPOS only for psb */
605 crtc_state->saveDSPSIZE = REG_READ(map->size);
606 crtc_state->saveDSPPOS = REG_READ(map->pos);
608 crtc_state->saveDSPBASE = REG_READ(map->base);
610 palette_reg = map->palette;
611 for (i = 0; i < 256; ++i)
612 crtc_state->savePalette[i] = REG_READ(palette_reg + (i << 2));
616 * Restore HW states of given crtc
618 void gma_crtc_restore(struct drm_crtc *crtc)
620 struct drm_device *dev = crtc->dev;
621 struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
622 struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
623 struct psb_intel_crtc_state *crtc_state = gma_crtc->crtc_state;
624 const struct psb_offset *map = &dev_priv->regmap[gma_crtc->pipe];
625 uint32_t palette_reg;
629 dev_err(dev->dev, "No crtc state\n");
633 if (crtc_state->saveDPLL & DPLL_VCO_ENABLE) {
635 crtc_state->saveDPLL & ~DPLL_VCO_ENABLE);
640 REG_WRITE(map->fp0, crtc_state->saveFP0);
643 REG_WRITE(map->fp1, crtc_state->saveFP1);
646 REG_WRITE(map->dpll, crtc_state->saveDPLL);
650 REG_WRITE(map->htotal, crtc_state->saveHTOTAL);
651 REG_WRITE(map->hblank, crtc_state->saveHBLANK);
652 REG_WRITE(map->hsync, crtc_state->saveHSYNC);
653 REG_WRITE(map->vtotal, crtc_state->saveVTOTAL);
654 REG_WRITE(map->vblank, crtc_state->saveVBLANK);
655 REG_WRITE(map->vsync, crtc_state->saveVSYNC);
656 REG_WRITE(map->stride, crtc_state->saveDSPSTRIDE);
658 REG_WRITE(map->size, crtc_state->saveDSPSIZE);
659 REG_WRITE(map->pos, crtc_state->saveDSPPOS);
661 REG_WRITE(map->src, crtc_state->savePIPESRC);
662 REG_WRITE(map->base, crtc_state->saveDSPBASE);
663 REG_WRITE(map->conf, crtc_state->savePIPECONF);
665 gma_wait_for_vblank(dev);
667 REG_WRITE(map->cntr, crtc_state->saveDSPCNTR);
668 REG_WRITE(map->base, crtc_state->saveDSPBASE);
670 gma_wait_for_vblank(dev);
672 palette_reg = map->palette;
673 for (i = 0; i < 256; ++i)
674 REG_WRITE(palette_reg + (i << 2), crtc_state->savePalette[i]);
677 void gma_encoder_prepare(struct drm_encoder *encoder)
679 const struct drm_encoder_helper_funcs *encoder_funcs =
680 encoder->helper_private;
681 /* lvds has its own version of prepare see psb_intel_lvds_prepare */
682 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
685 void gma_encoder_commit(struct drm_encoder *encoder)
687 const struct drm_encoder_helper_funcs *encoder_funcs =
688 encoder->helper_private;
689 /* lvds has its own version of commit see psb_intel_lvds_commit */
690 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
693 void gma_encoder_destroy(struct drm_encoder *encoder)
695 struct gma_encoder *intel_encoder = to_gma_encoder(encoder);
697 drm_encoder_cleanup(encoder);
698 kfree(intel_encoder);
701 /* Currently there is only a 1:1 mapping of encoders and connectors */
702 struct drm_encoder *gma_best_encoder(struct drm_connector *connector)
704 struct gma_encoder *gma_encoder = gma_attached_encoder(connector);
706 return &gma_encoder->base;
709 void gma_connector_attach_encoder(struct gma_connector *connector,
710 struct gma_encoder *encoder)
712 connector->encoder = encoder;
713 drm_connector_attach_encoder(&connector->base,
717 #define GMA_PLL_INVALID(s) { /* DRM_ERROR(s); */ return false; }
719 bool gma_pll_is_valid(struct drm_crtc *crtc,
720 const struct gma_limit_t *limit,
721 struct gma_clock_t *clock)
723 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
724 GMA_PLL_INVALID("p1 out of range");
725 if (clock->p < limit->p.min || limit->p.max < clock->p)
726 GMA_PLL_INVALID("p out of range");
727 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
728 GMA_PLL_INVALID("m2 out of range");
729 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
730 GMA_PLL_INVALID("m1 out of range");
731 /* On CDV m1 is always 0 */
732 if (clock->m1 <= clock->m2 && clock->m1 != 0)
733 GMA_PLL_INVALID("m1 <= m2 && m1 != 0");
734 if (clock->m < limit->m.min || limit->m.max < clock->m)
735 GMA_PLL_INVALID("m out of range");
736 if (clock->n < limit->n.min || limit->n.max < clock->n)
737 GMA_PLL_INVALID("n out of range");
738 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
739 GMA_PLL_INVALID("vco out of range");
740 /* XXX: We may need to be checking "Dot clock"
741 * depending on the multiplier, connector, etc.,
742 * rather than just a single range.
744 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
745 GMA_PLL_INVALID("dot out of range");
750 bool gma_find_best_pll(const struct gma_limit_t *limit,
751 struct drm_crtc *crtc, int target, int refclk,
752 struct gma_clock_t *best_clock)
754 struct drm_device *dev = crtc->dev;
755 const struct gma_clock_funcs *clock_funcs =
756 to_gma_crtc(crtc)->clock_funcs;
757 struct gma_clock_t clock;
760 if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
761 (REG_READ(LVDS) & LVDS_PORT_EN) != 0) {
763 * For LVDS, if the panel is on, just rely on its current
764 * settings for dual-channel. We haven't figured out how to
765 * reliably set up different single/dual channel state, if we
768 if ((REG_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
770 clock.p2 = limit->p2.p2_fast;
772 clock.p2 = limit->p2.p2_slow;
774 if (target < limit->p2.dot_limit)
775 clock.p2 = limit->p2.p2_slow;
777 clock.p2 = limit->p2.p2_fast;
780 memset(best_clock, 0, sizeof(*best_clock));
782 /* m1 is always 0 on CDV so the outmost loop will run just once */
783 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
784 for (clock.m2 = limit->m2.min;
785 (clock.m2 < clock.m1 || clock.m1 == 0) &&
786 clock.m2 <= limit->m2.max; clock.m2++) {
787 for (clock.n = limit->n.min;
788 clock.n <= limit->n.max; clock.n++) {
789 for (clock.p1 = limit->p1.min;
790 clock.p1 <= limit->p1.max;
794 clock_funcs->clock(refclk, &clock);
796 if (!clock_funcs->pll_is_valid(crtc,
800 this_err = abs(clock.dot - target);
801 if (this_err < err) {
810 return err != target;