static int rcar_du_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct drm_pending_vblank_event *event, uint32_t page_flip_flags) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct drm_device *dev = rcrtc->crtc.dev; unsigned long flags; spin_lock_irqsave(&dev->event_lock, flags); if (rcrtc->event != NULL) { spin_unlock_irqrestore(&dev->event_lock, flags); return -EBUSY; } spin_unlock_irqrestore(&dev->event_lock, flags); crtc->fb = fb; rcar_du_crtc_update_base(rcrtc); if (event) { event->pipe = rcrtc->index; drm_vblank_get(dev, rcrtc->index); spin_lock_irqsave(&dev->event_lock, flags); rcrtc->event = event; spin_unlock_irqrestore(&dev->event_lock, flags); } return 0; }
static void rcar_du_crtc_disable(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcar_du_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); rcar_du_plane_release(rcrtc->plane); }
static void rcar_du_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcar_du_crtc_update_planes(rcrtc); }
static void rcar_du_crtc_enable(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcar_du_crtc_get(rcrtc); rcar_du_crtc_start(rcrtc); }
static void rcar_du_crtc_disable(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcar_du_crtc_stop(rcrtc); rcar_du_crtc_put(rcrtc); rcrtc->outputs = 0; }
static void rcar_du_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcar_du_crtc_update_planes(rcrtc); if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) rcar_du_vsp_atomic_flush(rcrtc); }
static void rcar_du_crtc_mode_commit(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); /* We're done, restart the CRTC and set the DPMS mode to on. The * reference to the DU acquired at prepare() time will thus be released * by the DPMS handler (possibly called by the disable() handler). */ rcar_du_crtc_start(rcrtc); rcrtc->dpms = DRM_MODE_DPMS_ON; }
static int rcar_du_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, struct drm_framebuffer *old_fb) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); rcrtc->plane->src_x = x; rcrtc->plane->src_y = y; rcar_du_crtc_update_base(rcrtc); return 0; }
static void rcar_du_crtc_enable(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); if (rcrtc->enabled) return; rcar_du_crtc_get(rcrtc); rcar_du_crtc_start(rcrtc); rcrtc->enabled = true; }
int rcar_du_lvdsenc_enable(struct rcar_du_lvdsenc *lvds, struct drm_crtc *crtc, bool enable) { if (!enable) { rcar_du_lvdsenc_stop(lvds); return 0; } else if (crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); return rcar_du_lvdsenc_start(lvds, rcrtc); } else return -EINVAL; }
static void rcar_du_crtc_disable(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); if (!rcrtc->enabled) return; rcar_du_crtc_stop(rcrtc); rcar_du_crtc_put(rcrtc); rcrtc->enabled = false; rcrtc->outputs = 0; }
static void rcar_du_crtc_atomic_begin(struct drm_crtc *crtc) { struct drm_pending_vblank_event *event = crtc->state->event; struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct drm_device *dev = rcrtc->crtc.dev; unsigned long flags; if (event) { WARN_ON(drm_crtc_vblank_get(crtc) != 0); spin_lock_irqsave(&dev->event_lock, flags); rcrtc->event = event; spin_unlock_irqrestore(&dev->event_lock, flags); } }
void rcar_du_crtc_route_output(struct drm_crtc *crtc, enum rcar_du_output output) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct rcar_du_device *rcdu = rcrtc->group->dev; /* Store the route from the CRTC output to the DU output. The DU will be * configured when starting the CRTC. */ rcrtc->outputs |= BIT(output); /* Store RGB routing to DPAD0 for R8A7790. */ if (rcar_du_has(rcdu, RCAR_DU_FEATURE_DEFR8) && output == RCAR_DU_OUTPUT_DPAD0) rcdu->dpad0_source = rcrtc->index; }
static bool rcar_du_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct rcar_du_device *rcdu = rcrtc->group->dev; /* It is prohibition to set up the width of the multiple of 16 for the specification of H/W in R-Car series */ if ((mode) && (mode->hdisplay % 16)) { dev_err(rcdu->dev, "Error! width of the multiple of 16 is prohibition\n"); return false; } return true; }
static void rcar_du_crtc_dpms(struct drm_crtc *crtc, int mode) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); if (rcrtc->dpms == mode) return; if (mode == DRM_MODE_DPMS_ON) { rcar_du_crtc_get(rcrtc); rcar_du_crtc_start(rcrtc); } else { rcar_du_crtc_stop(rcrtc); rcar_du_crtc_put(rcrtc); } rcrtc->dpms = mode; }
static void rcar_du_crtc_mode_prepare(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); /* We need to access the hardware during mode set, acquire a reference * to the CRTC. */ rcar_du_crtc_get(rcrtc); /* Stop the CRTC and release the plane. Force the DPMS mode to off as a * result. */ rcar_du_crtc_stop(rcrtc); rcar_du_plane_release(rcrtc->plane); rcrtc->dpms = DRM_MODE_DPMS_OFF; }
static int rcar_du_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode, struct drm_display_mode *adjusted_mode, int x, int y, struct drm_framebuffer *old_fb) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct rcar_du_device *rcdu = rcrtc->group->dev; const struct rcar_du_format_info *format; int ret; format = rcar_du_format_info(crtc->fb->pixel_format); if (format == NULL) { dev_dbg(rcdu->dev, "mode_set: unsupported format %08x\n", crtc->fb->pixel_format); ret = -EINVAL; goto error; } ret = rcar_du_plane_reserve(rcrtc->plane, format); if (ret < 0) goto error; rcrtc->plane->format = format; rcrtc->plane->src_x = x; rcrtc->plane->src_y = y; rcrtc->plane->width = mode->hdisplay; rcrtc->plane->height = mode->vdisplay; rcar_du_plane_compute_base(rcrtc->plane, crtc->fb); rcrtc->outputs = 0; return 0; error: /* There's no rollback/abort operation to clean up in case of error. We * thus need to release the reference to the CRTC acquired in prepare() * here. */ rcar_du_crtc_put(rcrtc); return ret; }
static void rcar_du_crtc_atomic_begin(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) { struct drm_pending_vblank_event *event = crtc->state->event; struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct drm_device *dev = rcrtc->crtc.dev; unsigned long flags; if (event) { WARN_ON(drm_crtc_vblank_get(crtc) != 0); spin_lock_irqsave(&dev->event_lock, flags); rcrtc->event = event; spin_unlock_irqrestore(&dev->event_lock, flags); } if (rcar_du_has(rcrtc->group->dev, RCAR_DU_FEATURE_VSP1_SOURCE)) rcar_du_vsp_atomic_begin(rcrtc); }
void rcar_du_crtc_update_planes(struct drm_crtc *crtc) { struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc); struct rcar_du_plane *planes[RCAR_DU_NUM_HW_PLANES]; unsigned int num_planes = 0; unsigned int prio = 0; unsigned int i; u32 dptsr = 0; u32 dspr = 0; for (i = 0; i < ARRAY_SIZE(rcrtc->group->planes.planes); ++i) { struct rcar_du_plane *plane = &rcrtc->group->planes.planes[i]; unsigned int j; if (plane->crtc != &rcrtc->crtc || !plane->enabled) continue; /* Insert the plane in the sorted planes array. */ for (j = num_planes++; j > 0; --j) { if (planes[j-1]->zpos <= plane->zpos) break; planes[j] = planes[j-1]; } planes[j] = plane; prio += plane->format->planes * 4; } for (i = 0; i < num_planes; ++i) { struct rcar_du_plane *plane = planes[i]; unsigned int index = plane->hwindex; #ifdef CONFIG_DRM_RCAR_DESKTOP_TURN_OFF if (!plane->fb_plane) { prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); } #else prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); #endif if (plane->format->planes == 2) { index = (index + 1) % 8; #ifdef CONFIG_DRM_RCAR_DESKTOP_TURN_OFF if (!plane->fb_plane) { prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); } #else prio -= 4; dspr |= (index + 1) << prio; dptsr |= DPTSR_PnDK(index) | DPTSR_PnTS(index); #endif } } /* Select display timing and dot clock generator 1 for planes associated * with superposition controller 1. */ if (rcrtc->index % 2) { u32 value = rcar_du_group_read(rcrtc->group, DPTSR); /* The DPTSR register is updated when the display controller is * stopped. We thus need to restart the DU. Once again, sorry * for the flicker. One way to mitigate the issue would be to * pre-associate planes with CRTCs (either with a fixed 4/4 * split, or through a module parameter). Flicker would then * occur only if we need to break the pre-association. */ if (value != dptsr) { rcar_du_group_write(rcrtc->group, DPTSR, dptsr); rcar_du_group_restart(rcrtc->group); } } rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? DS2PR : DS1PR, dspr); }