Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panel: Add helper for reading DT rotation

This adds a helper function for reading the rotation (panel
orientation) from the device tree.

Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Tested-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Derek Basehore <dbasehore@chromium.org>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200813215609.28643-2-digetx@gmail.com

authored by

Derek Basehore and committed by
Sam Ravnborg
5f3e7503 1c243751

+53
+43
drivers/gpu/drm/drm_panel.c
··· 260 260 return ERR_PTR(-EPROBE_DEFER); 261 261 } 262 262 EXPORT_SYMBOL(of_drm_find_panel); 263 + 264 + /** 265 + * of_drm_get_panel_orientation - look up the orientation of the panel through 266 + * the "rotation" binding from a device tree node 267 + * @np: device tree node of the panel 268 + * @orientation: orientation enum to be filled in 269 + * 270 + * Looks up the rotation of a panel in the device tree. The orientation of the 271 + * panel is expressed as a property name "rotation" in the device tree. The 272 + * rotation in the device tree is counter clockwise. 273 + * 274 + * Return: 0 when a valid rotation value (0, 90, 180, or 270) is read or the 275 + * rotation property doesn't exist. Return a negative error code on failure. 276 + */ 277 + int of_drm_get_panel_orientation(const struct device_node *np, 278 + enum drm_panel_orientation *orientation) 279 + { 280 + int rotation, ret; 281 + 282 + ret = of_property_read_u32(np, "rotation", &rotation); 283 + if (ret == -EINVAL) { 284 + /* Don't return an error if there's no rotation property. */ 285 + *orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 286 + return 0; 287 + } 288 + 289 + if (ret < 0) 290 + return ret; 291 + 292 + if (rotation == 0) 293 + *orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL; 294 + else if (rotation == 90) 295 + *orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP; 296 + else if (rotation == 180) 297 + *orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP; 298 + else if (rotation == 270) 299 + *orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP; 300 + else 301 + return -EINVAL; 302 + 303 + return 0; 304 + } 305 + EXPORT_SYMBOL(of_drm_get_panel_orientation); 263 306 #endif 264 307 265 308 #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
+10
include/drm/drm_panel.h
··· 35 35 struct drm_panel; 36 36 struct display_timing; 37 37 38 + enum drm_panel_orientation; 39 + 38 40 /** 39 41 * struct drm_panel_funcs - perform operations on a given panel 40 42 * ··· 190 188 191 189 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL) 192 190 struct drm_panel *of_drm_find_panel(const struct device_node *np); 191 + int of_drm_get_panel_orientation(const struct device_node *np, 192 + enum drm_panel_orientation *orientation); 193 193 #else 194 194 static inline struct drm_panel *of_drm_find_panel(const struct device_node *np) 195 195 { 196 196 return ERR_PTR(-ENODEV); 197 + } 198 + 199 + static inline int of_drm_get_panel_orientation(const struct device_node *np, 200 + enum drm_panel_orientation *orientation) 201 + { 202 + return -ENODEV; 197 203 } 198 204 #endif 199 205