xref: /dflybsd-src/sys/dev/drm/include/drm/drm_panel.h (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
12c9916cdSFrançois Tigeot /*
22c9916cdSFrançois Tigeot  * Copyright (C) 2013, NVIDIA Corporation.  All rights reserved.
32c9916cdSFrançois Tigeot  *
42c9916cdSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
52c9916cdSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
62c9916cdSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
72c9916cdSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sub license,
82c9916cdSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
92c9916cdSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
102c9916cdSFrançois Tigeot  *
112c9916cdSFrançois Tigeot  * The above copyright notice and this permission notice (including the
122c9916cdSFrançois Tigeot  * next paragraph) shall be included in all copies or substantial portions
132c9916cdSFrançois Tigeot  * of the Software.
142c9916cdSFrançois Tigeot  *
152c9916cdSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
162c9916cdSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
172c9916cdSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
182c9916cdSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
192c9916cdSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
202c9916cdSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
212c9916cdSFrançois Tigeot  * DEALINGS IN THE SOFTWARE.
222c9916cdSFrançois Tigeot  */
232c9916cdSFrançois Tigeot 
242c9916cdSFrançois Tigeot #ifndef __DRM_PANEL_H__
252c9916cdSFrançois Tigeot #define __DRM_PANEL_H__
262c9916cdSFrançois Tigeot 
27*3f2dd94aSFrançois Tigeot #include <linux/errno.h>
282c9916cdSFrançois Tigeot #include <linux/list.h>
292c9916cdSFrançois Tigeot 
30*3f2dd94aSFrançois Tigeot struct device_node;
312c9916cdSFrançois Tigeot struct drm_connector;
322c9916cdSFrançois Tigeot struct drm_device;
332c9916cdSFrançois Tigeot struct drm_panel;
34477eb7f9SFrançois Tigeot struct display_timing;
352c9916cdSFrançois Tigeot 
362c9916cdSFrançois Tigeot /**
372c9916cdSFrançois Tigeot  * struct drm_panel_funcs - perform operations on a given panel
382c9916cdSFrançois Tigeot  * @disable: disable panel (turn off back light, etc.)
392c9916cdSFrançois Tigeot  * @unprepare: turn off panel
402c9916cdSFrançois Tigeot  * @prepare: turn on panel and perform set up
412c9916cdSFrançois Tigeot  * @enable: enable panel (turn on back light, etc.)
422c9916cdSFrançois Tigeot  * @get_modes: add modes to the connector that the panel is attached to and
432c9916cdSFrançois Tigeot  * return the number of modes added
44477eb7f9SFrançois Tigeot  * @get_timings: copy display timings into the provided array and return
45477eb7f9SFrançois Tigeot  * the number of display timings available
462c9916cdSFrançois Tigeot  *
472c9916cdSFrançois Tigeot  * The .prepare() function is typically called before the display controller
482c9916cdSFrançois Tigeot  * starts to transmit video data. Panel drivers can use this to turn the panel
492c9916cdSFrançois Tigeot  * on and wait for it to become ready. If additional configuration is required
502c9916cdSFrançois Tigeot  * (via a control bus such as I2C, SPI or DSI for example) this is a good time
512c9916cdSFrançois Tigeot  * to do that.
522c9916cdSFrançois Tigeot  *
532c9916cdSFrançois Tigeot  * After the display controller has started transmitting video data, it's safe
542c9916cdSFrançois Tigeot  * to call the .enable() function. This will typically enable the backlight to
552c9916cdSFrançois Tigeot  * make the image on screen visible. Some panels require a certain amount of
562c9916cdSFrançois Tigeot  * time or frames before the image is displayed. This function is responsible
572c9916cdSFrançois Tigeot  * for taking this into account before enabling the backlight to avoid visual
582c9916cdSFrançois Tigeot  * glitches.
592c9916cdSFrançois Tigeot  *
602c9916cdSFrançois Tigeot  * Before stopping video transmission from the display controller it can be
612c9916cdSFrançois Tigeot  * necessary to turn off the panel to avoid visual glitches. This is done in
622c9916cdSFrançois Tigeot  * the .disable() function. Analogously to .enable() this typically involves
632c9916cdSFrançois Tigeot  * turning off the backlight and waiting for some time to make sure no image
642c9916cdSFrançois Tigeot  * is visible on the panel. It is then safe for the display controller to
652c9916cdSFrançois Tigeot  * cease transmission of video data.
662c9916cdSFrançois Tigeot  *
672c9916cdSFrançois Tigeot  * To save power when no video data is transmitted, a driver can power down
682c9916cdSFrançois Tigeot  * the panel. This is the job of the .unprepare() function.
692c9916cdSFrançois Tigeot  */
702c9916cdSFrançois Tigeot struct drm_panel_funcs {
712c9916cdSFrançois Tigeot 	int (*disable)(struct drm_panel *panel);
722c9916cdSFrançois Tigeot 	int (*unprepare)(struct drm_panel *panel);
732c9916cdSFrançois Tigeot 	int (*prepare)(struct drm_panel *panel);
742c9916cdSFrançois Tigeot 	int (*enable)(struct drm_panel *panel);
752c9916cdSFrançois Tigeot 	int (*get_modes)(struct drm_panel *panel);
76477eb7f9SFrançois Tigeot 	int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
77477eb7f9SFrançois Tigeot 			   struct display_timing *timings);
782c9916cdSFrançois Tigeot };
792c9916cdSFrançois Tigeot 
801dedbd3bSFrançois Tigeot /**
811dedbd3bSFrançois Tigeot  * struct drm_panel - DRM panel object
821dedbd3bSFrançois Tigeot  * @drm: DRM device owning the panel
831dedbd3bSFrançois Tigeot  * @connector: DRM connector that the panel is attached to
841dedbd3bSFrançois Tigeot  * @dev: parent device of the panel
851dedbd3bSFrançois Tigeot  * @funcs: operations that can be performed on the panel
861dedbd3bSFrançois Tigeot  * @list: panel entry in registry
871dedbd3bSFrançois Tigeot  */
882c9916cdSFrançois Tigeot struct drm_panel {
892c9916cdSFrançois Tigeot 	struct drm_device *drm;
902c9916cdSFrançois Tigeot 	struct drm_connector *connector;
912c9916cdSFrançois Tigeot 	struct device *dev;
922c9916cdSFrançois Tigeot 
932c9916cdSFrançois Tigeot 	const struct drm_panel_funcs *funcs;
942c9916cdSFrançois Tigeot 
952c9916cdSFrançois Tigeot 	struct list_head list;
962c9916cdSFrançois Tigeot };
972c9916cdSFrançois Tigeot 
981dedbd3bSFrançois Tigeot /**
991dedbd3bSFrançois Tigeot  * drm_disable_unprepare - power off a panel
1001dedbd3bSFrançois Tigeot  * @panel: DRM panel
1011dedbd3bSFrançois Tigeot  *
1021dedbd3bSFrançois Tigeot  * Calling this function will completely power off a panel (assert the panel's
1031dedbd3bSFrançois Tigeot  * reset, turn off power supplies, ...). After this function has completed, it
1041dedbd3bSFrançois Tigeot  * is usually no longer possible to communicate with the panel until another
1051dedbd3bSFrançois Tigeot  * call to drm_panel_prepare().
1061dedbd3bSFrançois Tigeot  *
1071dedbd3bSFrançois Tigeot  * Return: 0 on success or a negative error code on failure.
1081dedbd3bSFrançois Tigeot  */
drm_panel_unprepare(struct drm_panel * panel)1092c9916cdSFrançois Tigeot static inline int drm_panel_unprepare(struct drm_panel *panel)
1102c9916cdSFrançois Tigeot {
1112c9916cdSFrançois Tigeot 	if (panel && panel->funcs && panel->funcs->unprepare)
1122c9916cdSFrançois Tigeot 		return panel->funcs->unprepare(panel);
1132c9916cdSFrançois Tigeot 
1142c9916cdSFrançois Tigeot 	return panel ? -ENOSYS : -EINVAL;
1152c9916cdSFrançois Tigeot }
1162c9916cdSFrançois Tigeot 
1171dedbd3bSFrançois Tigeot /**
1181dedbd3bSFrançois Tigeot  * drm_panel_disable - disable a panel
1191dedbd3bSFrançois Tigeot  * @panel: DRM panel
1201dedbd3bSFrançois Tigeot  *
1211dedbd3bSFrançois Tigeot  * This will typically turn off the panel's backlight or disable the display
1221dedbd3bSFrançois Tigeot  * drivers. For smart panels it should still be possible to communicate with
1231dedbd3bSFrançois Tigeot  * the integrated circuitry via any command bus after this call.
1241dedbd3bSFrançois Tigeot  *
1251dedbd3bSFrançois Tigeot  * Return: 0 on success or a negative error code on failure.
1261dedbd3bSFrançois Tigeot  */
drm_panel_disable(struct drm_panel * panel)1272c9916cdSFrançois Tigeot static inline int drm_panel_disable(struct drm_panel *panel)
1282c9916cdSFrançois Tigeot {
1292c9916cdSFrançois Tigeot 	if (panel && panel->funcs && panel->funcs->disable)
1302c9916cdSFrançois Tigeot 		return panel->funcs->disable(panel);
1312c9916cdSFrançois Tigeot 
1322c9916cdSFrançois Tigeot 	return panel ? -ENOSYS : -EINVAL;
1332c9916cdSFrançois Tigeot }
1342c9916cdSFrançois Tigeot 
1351dedbd3bSFrançois Tigeot /**
1361dedbd3bSFrançois Tigeot  * drm_panel_prepare - power on a panel
1371dedbd3bSFrançois Tigeot  * @panel: DRM panel
1381dedbd3bSFrançois Tigeot  *
1391dedbd3bSFrançois Tigeot  * Calling this function will enable power and deassert any reset signals to
1401dedbd3bSFrançois Tigeot  * the panel. After this has completed it is possible to communicate with any
1411dedbd3bSFrançois Tigeot  * integrated circuitry via a command bus.
1421dedbd3bSFrançois Tigeot  *
1431dedbd3bSFrançois Tigeot  * Return: 0 on success or a negative error code on failure.
1441dedbd3bSFrançois Tigeot  */
drm_panel_prepare(struct drm_panel * panel)1452c9916cdSFrançois Tigeot static inline int drm_panel_prepare(struct drm_panel *panel)
1462c9916cdSFrançois Tigeot {
1472c9916cdSFrançois Tigeot 	if (panel && panel->funcs && panel->funcs->prepare)
1482c9916cdSFrançois Tigeot 		return panel->funcs->prepare(panel);
1492c9916cdSFrançois Tigeot 
1502c9916cdSFrançois Tigeot 	return panel ? -ENOSYS : -EINVAL;
1512c9916cdSFrançois Tigeot }
1522c9916cdSFrançois Tigeot 
1531dedbd3bSFrançois Tigeot /**
1541dedbd3bSFrançois Tigeot  * drm_panel_enable - enable a panel
1551dedbd3bSFrançois Tigeot  * @panel: DRM panel
1561dedbd3bSFrançois Tigeot  *
1571dedbd3bSFrançois Tigeot  * Calling this function will cause the panel display drivers to be turned on
1581dedbd3bSFrançois Tigeot  * and the backlight to be enabled. Content will be visible on screen after
1591dedbd3bSFrançois Tigeot  * this call completes.
1601dedbd3bSFrançois Tigeot  *
1611dedbd3bSFrançois Tigeot  * Return: 0 on success or a negative error code on failure.
1621dedbd3bSFrançois Tigeot  */
drm_panel_enable(struct drm_panel * panel)1632c9916cdSFrançois Tigeot static inline int drm_panel_enable(struct drm_panel *panel)
1642c9916cdSFrançois Tigeot {
1652c9916cdSFrançois Tigeot 	if (panel && panel->funcs && panel->funcs->enable)
1662c9916cdSFrançois Tigeot 		return panel->funcs->enable(panel);
1672c9916cdSFrançois Tigeot 
1682c9916cdSFrançois Tigeot 	return panel ? -ENOSYS : -EINVAL;
1692c9916cdSFrançois Tigeot }
1702c9916cdSFrançois Tigeot 
1711dedbd3bSFrançois Tigeot /**
1721dedbd3bSFrançois Tigeot  * drm_panel_get_modes - probe the available display modes of a panel
1731dedbd3bSFrançois Tigeot  * @panel: DRM panel
1741dedbd3bSFrançois Tigeot  *
1751dedbd3bSFrançois Tigeot  * The modes probed from the panel are automatically added to the connector
1761dedbd3bSFrançois Tigeot  * that the panel is attached to.
1771dedbd3bSFrançois Tigeot  *
1781dedbd3bSFrançois Tigeot  * Return: The number of modes available from the panel on success or a
1791dedbd3bSFrançois Tigeot  * negative error code on failure.
1801dedbd3bSFrançois Tigeot  */
drm_panel_get_modes(struct drm_panel * panel)1812c9916cdSFrançois Tigeot static inline int drm_panel_get_modes(struct drm_panel *panel)
1822c9916cdSFrançois Tigeot {
1832c9916cdSFrançois Tigeot 	if (panel && panel->funcs && panel->funcs->get_modes)
1842c9916cdSFrançois Tigeot 		return panel->funcs->get_modes(panel);
1852c9916cdSFrançois Tigeot 
1862c9916cdSFrançois Tigeot 	return panel ? -ENOSYS : -EINVAL;
1872c9916cdSFrançois Tigeot }
1882c9916cdSFrançois Tigeot 
1892c9916cdSFrançois Tigeot void drm_panel_init(struct drm_panel *panel);
1902c9916cdSFrançois Tigeot 
1912c9916cdSFrançois Tigeot int drm_panel_add(struct drm_panel *panel);
1922c9916cdSFrançois Tigeot void drm_panel_remove(struct drm_panel *panel);
1932c9916cdSFrançois Tigeot 
1942c9916cdSFrançois Tigeot int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector);
1952c9916cdSFrançois Tigeot int drm_panel_detach(struct drm_panel *panel);
1962c9916cdSFrançois Tigeot 
197*3f2dd94aSFrançois Tigeot #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
198*3f2dd94aSFrançois Tigeot struct drm_panel *of_drm_find_panel(const struct device_node *np);
1992c9916cdSFrançois Tigeot #else
of_drm_find_panel(const struct device_node * np)200*3f2dd94aSFrançois Tigeot static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
2012c9916cdSFrançois Tigeot {
2022c9916cdSFrançois Tigeot 	return NULL;
2032c9916cdSFrançois Tigeot }
2042c9916cdSFrançois Tigeot #endif
2052c9916cdSFrançois Tigeot 
2062c9916cdSFrançois Tigeot #endif
207