@@ -382,9 +382,20 @@ int drm_fb_helper_debug_leave(struct fb_info *info)
}
EXPORT_SYMBOL(drm_fb_helper_debug_leave);
-/* Check if the plane can hw rotate to match panel orientation */
-static bool drm_fb_helper_panel_rotation(struct drm_mode_set *modeset,
- unsigned int *rotation)
+/**
+ * drm_client_panel_rotation() - Check panel orientation
+ * @modeset: DRM modeset
+ * @rotation: Returned rotation value
+ *
+ * This function checks if the primary plane in @modeset can hw rotate to match
+ * the panel orientation on its connector.
+ *
+ * Note: Currently only 0 and 180 degrees are supported.
+ *
+ * Return:
+ * True if the plane can do the rotation, false otherwise.
+ */
+bool drm_client_panel_rotation(struct drm_mode_set *modeset, unsigned int *rotation)
{
struct drm_connector *connector = modeset->connectors[0];
struct drm_plane *plane = modeset->crtc->primary;
@@ -425,9 +436,9 @@ static bool drm_fb_helper_panel_rotation(struct drm_mode_set *modeset,
return true;
}
-static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool active)
+static int drm_client_modesets_commit_atomic(struct drm_device *dev, struct drm_mode_set *modesets,
+ bool active)
{
- struct drm_device *dev = fb_helper->dev;
struct drm_plane_state *plane_state;
struct drm_plane *plane;
struct drm_atomic_state *state;
@@ -463,11 +474,11 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
goto out_state;
}
- drm_client_for_each_modeset(mode_set, fb_helper->modesets) {
+ drm_client_for_each_modeset(mode_set, modesets) {
struct drm_plane *primary = mode_set->crtc->primary;
unsigned int rotation;
- if (drm_fb_helper_panel_rotation(mode_set, &rotation)) {
+ if (drm_client_panel_rotation(mode_set, &rotation)) {
/* Cannot fail as we've already gotten the plane state above */
plane_state = drm_atomic_get_new_plane_state(state, primary);
plane_state->rotation = rotation;
@@ -509,14 +520,13 @@ static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper, bool activ
goto retry;
}
-static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper)
+static int drm_client_modesets_commit_legacy(struct drm_device *dev, struct drm_mode_set *modesets)
{
- struct drm_device *dev = fb_helper->dev;
struct drm_mode_set *mode_set;
struct drm_plane *plane;
int ret = 0;
- drm_modeset_lock_all(fb_helper->dev);
+ drm_modeset_lock_all(dev);
drm_for_each_plane(plane, dev) {
if (plane->type != DRM_PLANE_TYPE_PRIMARY)
drm_plane_force_disable(plane);
@@ -527,7 +537,7 @@ static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper)
DRM_MODE_ROTATE_0);
}
- drm_client_for_each_modeset(mode_set, fb_helper->modesets) {
+ drm_client_for_each_modeset(mode_set, modesets) {
struct drm_crtc *crtc = mode_set->crtc;
if (crtc->funcs->cursor_set2) {
@@ -545,19 +555,25 @@ static int restore_fbdev_mode_legacy(struct drm_fb_helper *fb_helper)
goto out;
}
out:
- drm_modeset_unlock_all(fb_helper->dev);
+ drm_modeset_unlock_all(dev);
return ret;
}
-static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
+/**
+ * drm_client_modesets_commit() - Commit CRTC configuration
+ * @dev: DRM device
+ * @modesets: Modeset array
+ *
+ * Returns:
+ * Zero on success or negative error code on failure.
+ */
+int drm_client_modesets_commit(struct drm_device *dev, struct drm_mode_set *modesets)
{
- struct drm_device *dev = fb_helper->dev;
-
if (drm_drv_uses_atomic_modeset(dev))
- return restore_fbdev_mode_atomic(fb_helper, true);
+ return drm_client_modesets_commit_atomic(dev, modesets, true);
else
- return restore_fbdev_mode_legacy(fb_helper);
+ return drm_client_modesets_commit_legacy(dev, modesets);
}
/**
@@ -583,7 +599,7 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
return 0;
mutex_lock(&fb_helper->lock);
- ret = restore_fbdev_mode(fb_helper);
+ ret = drm_client_modesets_commit(fb_helper->dev, fb_helper->modesets);
do_delayed = fb_helper->delayed_hotplug;
if (do_delayed)
@@ -645,7 +661,7 @@ static bool drm_fb_helper_force_kernel_mode(void)
continue;
mutex_lock(&helper->lock);
- ret = restore_fbdev_mode(helper);
+ ret = drm_client_modesets_commit(dev, helper->modesets);
if (ret)
error = true;
mutex_unlock(&helper->lock);
@@ -677,15 +693,15 @@ static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
#endif
-static void dpms_legacy(struct drm_fb_helper *fb_helper, int dpms_mode)
+static void drm_client_modesets_dpms_legacy(struct drm_device *dev, struct drm_mode_set *modesets,
+ int dpms_mode)
{
- struct drm_device *dev = fb_helper->dev;
struct drm_connector *connector;
struct drm_mode_set *modeset;
int j;
drm_modeset_lock_all(dev);
- drm_client_for_each_modeset(modeset, fb_helper->modesets) {
+ drm_client_for_each_modeset(modeset, modesets) {
if (!modeset->crtc->enabled)
continue;
@@ -699,6 +715,22 @@ static void dpms_legacy(struct drm_fb_helper *fb_helper, int dpms_mode)
drm_modeset_unlock_all(dev);
}
+/**
+ * drm_client_modesets_dpms() - Set DPMS mode
+ * @dev: DRM device
+ * @modesets: Modeset array
+ * @mode: DPMS mode
+ *
+ * Note: For atomic drivers @mode is reduced to on/off.
+ */
+void drm_client_modesets_dpms(struct drm_device *dev, struct drm_mode_set *modesets, int mode)
+{
+ if (drm_drv_uses_atomic_modeset(dev))
+ drm_client_modesets_commit_atomic(dev, modesets, mode == DRM_MODE_DPMS_ON);
+ else
+ drm_client_modesets_dpms_legacy(dev, modesets, mode);
+}
+
static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
{
struct drm_fb_helper *fb_helper = info->par;
@@ -707,15 +739,8 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
* For each CRTC in this fb, turn the connectors on/off.
*/
mutex_lock(&fb_helper->lock);
- if (!drm_fb_helper_is_bound(fb_helper)) {
- mutex_unlock(&fb_helper->lock);
- return;
- }
-
- if (drm_drv_uses_atomic_modeset(fb_helper->dev))
- restore_fbdev_mode_atomic(fb_helper, dpms_mode == DRM_MODE_DPMS_ON);
- else
- dpms_legacy(fb_helper, dpms_mode);
+ if (drm_fb_helper_is_bound(fb_helper))
+ drm_client_modesets_dpms(fb_helper->dev, fb_helper->modesets, dpms_mode);
mutex_unlock(&fb_helper->lock);
}
@@ -1770,7 +1795,7 @@ static int pan_display_atomic(struct fb_var_screeninfo *var,
pan_set(fb_helper, var->xoffset, var->yoffset);
- ret = restore_fbdev_mode_atomic(fb_helper, true);
+ ret = drm_client_modesets_commit(fb_helper->dev, fb_helper->modesets);
if (!ret) {
info->var.xoffset = var->xoffset;
info->var.yoffset = var->yoffset;
@@ -1987,7 +2012,7 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
/* First time: disable all crtc's.. */
if (!fb_helper->deferred_setup && !READ_ONCE(fb_helper->dev->master))
- restore_fbdev_mode(fb_helper);
+ drm_client_modesets_commit(fb_helper->dev, fb_helper->modesets);
return -EAGAIN;
}
@@ -2754,7 +2779,7 @@ static void drm_setup_crtcs_fb(struct drm_fb_helper *fb_helper)
modeset->fb = fb_helper->fb;
- if (drm_fb_helper_panel_rotation(modeset, &rotation))
+ if (drm_client_panel_rotation(modeset, &rotation))
/* Rotating in hardware, fbcon should not rotate */
sw_rotations |= DRM_MODE_ROTATE_0;
else
This makes the necessary changes so the commit code can be moved out to drm_client as-is in the next patch. It's split up to ease review. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> --- drivers/gpu/drm/drm_fb_helper.c | 93 +++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 34 deletions(-)