Skip to content

Commit cb27b17

Browse files
6by9popcornmix
authored andcommitted
drm: Add a rotation parameter to connectors.
Some connectors, particularly writeback, can implement flip or transpose operations as writing back to memory. Add a connector rotation property to control this. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent fe4c5ef commit cb27b17

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

drivers/gpu/drm/drm_atomic_uapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,8 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
793793
state->privacy_screen_sw_state = val;
794794
} else if (property == connector->broadcast_rgb_property) {
795795
state->hdmi.broadcast_rgb = val;
796+
} else if (property == connector->rotation_property) {
797+
state->rotation = val;
796798
} else if (connector->funcs->atomic_set_property) {
797799
return connector->funcs->atomic_set_property(connector,
798800
state, property, val);
@@ -884,6 +886,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector,
884886
*val = state->privacy_screen_sw_state;
885887
} else if (property == connector->broadcast_rgb_property) {
886888
*val = state->hdmi.broadcast_rgb;
889+
} else if (property == connector->rotation_property) {
890+
*val = state->rotation;
887891
} else if (connector->funcs->atomic_get_property) {
888892
return connector->funcs->atomic_get_property(connector,
889893
state, property, val);

drivers/gpu/drm/drm_blend.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ int drm_plane_create_alpha_property(struct drm_plane *plane)
241241
}
242242
EXPORT_SYMBOL(drm_plane_create_alpha_property);
243243

244+
static const struct drm_prop_enum_list drm_rotate_props[] = {
245+
{ __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
246+
{ __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
247+
{ __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
248+
{ __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
249+
{ __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
250+
{ __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
251+
{ __builtin_ffs(DRM_MODE_TRANSPOSE) - 1, "transpose" },
252+
};
253+
244254
/**
245255
* drm_plane_create_rotation_property - create a new rotation property
246256
* @plane: drm plane
@@ -281,23 +291,15 @@ int drm_plane_create_rotation_property(struct drm_plane *plane,
281291
unsigned int rotation,
282292
unsigned int supported_rotations)
283293
{
284-
static const struct drm_prop_enum_list props[] = {
285-
{ __builtin_ffs(DRM_MODE_ROTATE_0) - 1, "rotate-0" },
286-
{ __builtin_ffs(DRM_MODE_ROTATE_90) - 1, "rotate-90" },
287-
{ __builtin_ffs(DRM_MODE_ROTATE_180) - 1, "rotate-180" },
288-
{ __builtin_ffs(DRM_MODE_ROTATE_270) - 1, "rotate-270" },
289-
{ __builtin_ffs(DRM_MODE_REFLECT_X) - 1, "reflect-x" },
290-
{ __builtin_ffs(DRM_MODE_REFLECT_Y) - 1, "reflect-y" },
291-
{ __builtin_ffs(DRM_MODE_TRANSPOSE) - 1, "transpose" },
292-
};
293294
struct drm_property *prop;
294295

295296
WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
296297
WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK));
297298
WARN_ON(rotation & ~supported_rotations);
298299

299300
prop = drm_property_create_bitmask(plane->dev, 0, "rotation",
300-
props, ARRAY_SIZE(props),
301+
drm_rotate_props,
302+
ARRAY_SIZE(drm_rotate_props),
301303
supported_rotations);
302304
if (!prop)
303305
return -ENOMEM;
@@ -313,6 +315,34 @@ int drm_plane_create_rotation_property(struct drm_plane *plane,
313315
}
314316
EXPORT_SYMBOL(drm_plane_create_rotation_property);
315317

318+
int drm_connector_create_rotation_property(struct drm_connector *conn,
319+
unsigned int rotation,
320+
unsigned int supported_rotations)
321+
{
322+
struct drm_property *prop;
323+
324+
WARN_ON((supported_rotations & DRM_MODE_ROTATE_MASK) == 0);
325+
WARN_ON(!is_power_of_2(rotation & DRM_MODE_ROTATE_MASK));
326+
WARN_ON(rotation & ~supported_rotations);
327+
328+
prop = drm_property_create_bitmask(conn->dev, 0, "rotation",
329+
drm_rotate_props,
330+
ARRAY_SIZE(drm_rotate_props),
331+
supported_rotations);
332+
if (!prop)
333+
return -ENOMEM;
334+
335+
drm_object_attach_property(&conn->base, prop, rotation);
336+
337+
if (conn->state)
338+
conn->state->rotation = rotation;
339+
340+
conn->rotation_property = prop;
341+
342+
return 0;
343+
}
344+
EXPORT_SYMBOL(drm_connector_create_rotation_property);
345+
316346
/**
317347
* drm_rotation_simplify() - Try to simplify the rotation
318348
* @rotation: Rotation to be simplified

include/drm/drm_blend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
struct drm_device;
3535
struct drm_atomic_state;
3636
struct drm_plane;
37+
struct drm_connector;
3738

3839
static inline bool drm_rotation_90_or_270(unsigned int rotation)
3940
{
@@ -58,4 +59,8 @@ int drm_atomic_normalize_zpos(struct drm_device *dev,
5859
struct drm_atomic_state *state);
5960
int drm_plane_create_blend_mode_property(struct drm_plane *plane,
6061
unsigned int supported_modes);
62+
63+
int drm_connector_create_rotation_property(struct drm_connector *conn,
64+
unsigned int rotation,
65+
unsigned int supported_rotations);
6166
#endif

include/drm/drm_connector.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,11 @@ struct drm_connector_state {
11491149
* @drm_atomic_helper_connector_hdmi_check().
11501150
*/
11511151
struct drm_connector_hdmi_state hdmi;
1152+
1153+
/**
1154+
* @rotation: Connector property to rotate the maximum output image.
1155+
*/
1156+
u32 rotation;
11521157
};
11531158

11541159
struct drm_connector_hdmi_audio_funcs {
@@ -2103,6 +2108,12 @@ struct drm_connector {
21032108
*/
21042109
struct drm_property *broadcast_rgb_property;
21052110

2111+
/**
2112+
* @rotation_property: Optional DRM property controlling rotation of the
2113+
* output.
2114+
*/
2115+
struct drm_property *rotation_property;
2116+
21062117
#define DRM_CONNECTOR_POLL_HPD (1 << 0)
21072118
#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
21082119
#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)

0 commit comments

Comments
 (0)