@@ -293,6 +293,7 @@ static int rcar_du_crtc_mode_set(struct drm_crtc *crtc,
struct rcar_du_device *rcdu = crtc->dev->dev_private;
struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
const struct rcar_du_format_info *format;
+ int ret;
format = rcar_du_format_info(crtc->fb->pixel_format);
if (format == NULL) {
@@ -301,6 +302,10 @@ static int rcar_du_crtc_mode_set(struct drm_crtc *crtc,
return -EINVAL;
}
+ ret = rcar_du_plane_reserve(rcrtc->plane, format);
+ if (ret < 0)
+ return ret;
+
rcrtc->plane->format = format;
rcrtc->plane->pitch = crtc->fb->pitches[0];
@@ -311,7 +316,7 @@ static int rcar_du_crtc_mode_set(struct drm_crtc *crtc,
rcar_du_plane_compute_base(rcrtc->plane, crtc->fb);
- return rcar_du_plane_reserve(rcrtc->plane);
+ return 0;
}
static void rcar_du_crtc_mode_commit(struct drm_crtc *crtc)
@@ -38,7 +38,8 @@ static void rcar_du_plane_write(struct rcar_du_device *rcdu,
rcar_du_write(rcdu, index * PLANE_OFF + reg, data);
}
-int rcar_du_plane_reserve(struct rcar_du_plane *plane)
+int rcar_du_plane_reserve(struct rcar_du_plane *plane,
+ const struct rcar_du_format_info *format)
{
struct rcar_du_device *rcdu = plane->dev;
unsigned int i;
@@ -50,7 +51,7 @@ int rcar_du_plane_reserve(struct rcar_du_plane *plane)
if (!(rcdu->planes.free & (1 << i)))
continue;
- if (plane->format->planes == 1 ||
+ if (format->planes == 1 ||
rcdu->planes.free & (1 << ((i + 1) % 8)))
break;
}
@@ -59,7 +60,7 @@ int rcar_du_plane_reserve(struct rcar_du_plane *plane)
goto done;
rcdu->planes.free &= ~(1 << i);
- if (plane->format->planes == 2)
+ if (format->planes == 2)
rcdu->planes.free &= ~(1 << ((i + 1) % 8));
plane->hwindex = i;
@@ -263,6 +264,16 @@ rcar_du_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
nplanes = rplane->format ? rplane->format->planes : 0;
+ /* Reallocate hardware planes if the number of required planes has
+ * changed.
+ */
+ if (format->planes != nplanes) {
+ rcar_du_plane_release(rplane);
+ ret = rcar_du_plane_reserve(rplane, format);
+ if (ret < 0)
+ return ret;
+ }
+
rplane->crtc = crtc;
rplane->format = format;
rplane->pitch = fb->pitches[0];
@@ -274,16 +285,6 @@ rcar_du_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
rplane->width = crtc_w;
rplane->height = crtc_h;
- /* Reallocate hardware planes if the number of required planes has
- * changed.
- */
- if (format->planes != nplanes) {
- rcar_du_plane_release(rplane);
- ret = rcar_du_plane_reserve(rplane);
- if (ret < 0)
- return ret;
- }
-
rcar_du_plane_compute_base(rplane, fb);
rcar_du_plane_setup(rplane);
@@ -19,6 +19,7 @@
struct drm_framebuffer;
struct rcar_du_device;
+struct rcar_du_format_info;
struct rcar_du_plane {
struct drm_plane plane;
@@ -53,7 +54,8 @@ void rcar_du_plane_setup(struct rcar_du_plane *plane);
void rcar_du_plane_update_base(struct rcar_du_plane *plane);
void rcar_du_plane_compute_base(struct rcar_du_plane *plane,
struct drm_framebuffer *fb);
-int rcar_du_plane_reserve(struct rcar_du_plane *plane);
+int rcar_du_plane_reserve(struct rcar_du_plane *plane,
+ const struct rcar_du_format_info *format);
void rcar_du_plane_release(struct rcar_du_plane *plane);
#endif /* __RCAR_DU_PLANE_H__ */