1*55716d26SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2cc3f414cSSteffen Trumtrar /* 3cc3f414cSSteffen Trumtrar * generic videomode helper 4cc3f414cSSteffen Trumtrar * 5cc3f414cSSteffen Trumtrar * Copyright (c) 2012 Steffen Trumtrar <s.trumtrar@pengutronix.de>, Pengutronix 6cc3f414cSSteffen Trumtrar */ 7cc3f414cSSteffen Trumtrar #include <linux/errno.h> 8cc3f414cSSteffen Trumtrar #include <linux/export.h> 9cc3f414cSSteffen Trumtrar #include <linux/of.h> 10cc3f414cSSteffen Trumtrar #include <video/display_timing.h> 11cc3f414cSSteffen Trumtrar #include <video/of_display_timing.h> 12cc3f414cSSteffen Trumtrar #include <video/of_videomode.h> 13cc3f414cSSteffen Trumtrar #include <video/videomode.h> 14cc3f414cSSteffen Trumtrar 15cc3f414cSSteffen Trumtrar /** 16cc3f414cSSteffen Trumtrar * of_get_videomode - get the videomode #<index> from devicetree 17cc3f414cSSteffen Trumtrar * @np - devicenode with the display_timings 18cc3f414cSSteffen Trumtrar * @vm - set to return value 19cc3f414cSSteffen Trumtrar * @index - index into list of display_timings 20cc3f414cSSteffen Trumtrar * (Set this to OF_USE_NATIVE_MODE to use whatever mode is 21cc3f414cSSteffen Trumtrar * specified as native mode in the DT.) 22cc3f414cSSteffen Trumtrar * 23cc3f414cSSteffen Trumtrar * DESCRIPTION: 24cc3f414cSSteffen Trumtrar * Get a list of all display timings and put the one 25cc3f414cSSteffen Trumtrar * specified by index into *vm. This function should only be used, if 26cc3f414cSSteffen Trumtrar * only one videomode is to be retrieved. A driver that needs to work 27cc3f414cSSteffen Trumtrar * with multiple/all videomodes should work with 28cc3f414cSSteffen Trumtrar * of_get_display_timings instead. 29cc3f414cSSteffen Trumtrar **/ 30cc3f414cSSteffen Trumtrar int of_get_videomode(struct device_node *np, struct videomode *vm, 31cc3f414cSSteffen Trumtrar int index) 32cc3f414cSSteffen Trumtrar { 33cc3f414cSSteffen Trumtrar struct display_timings *disp; 34cc3f414cSSteffen Trumtrar int ret; 35cc3f414cSSteffen Trumtrar 36cc3f414cSSteffen Trumtrar disp = of_get_display_timings(np); 37cc3f414cSSteffen Trumtrar if (!disp) { 386d7e6533SRob Herring pr_err("%pOF: no timings specified\n", np); 39cc3f414cSSteffen Trumtrar return -EINVAL; 40cc3f414cSSteffen Trumtrar } 41cc3f414cSSteffen Trumtrar 42cc3f414cSSteffen Trumtrar if (index == OF_USE_NATIVE_MODE) 43cc3f414cSSteffen Trumtrar index = disp->native_mode; 44cc3f414cSSteffen Trumtrar 456cd2c7dbSTomi Valkeinen ret = videomode_from_timings(disp, vm, index); 46cc3f414cSSteffen Trumtrar 47cc3f414cSSteffen Trumtrar display_timings_release(disp); 48cc3f414cSSteffen Trumtrar 4937b617f9SChristian Engelmayer return ret; 50cc3f414cSSteffen Trumtrar } 51cc3f414cSSteffen Trumtrar EXPORT_SYMBOL_GPL(of_get_videomode); 52