xref: /netbsd-src/sys/external/bsd/drm2/dist/include/drm/drm_panel.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1*41ec0267Sriastradh /*	$NetBSD: drm_panel.h,v 1.4 2021/12/18 23:45:46 riastradh Exp $	*/
2efa246c0Sriastradh 
39d20d926Sriastradh /*
49d20d926Sriastradh  * Copyright (C) 2013, NVIDIA Corporation.  All rights reserved.
59d20d926Sriastradh  *
69d20d926Sriastradh  * Permission is hereby granted, free of charge, to any person obtaining a
79d20d926Sriastradh  * copy of this software and associated documentation files (the "Software"),
89d20d926Sriastradh  * to deal in the Software without restriction, including without limitation
99d20d926Sriastradh  * the rights to use, copy, modify, merge, publish, distribute, sub license,
109d20d926Sriastradh  * and/or sell copies of the Software, and to permit persons to whom the
119d20d926Sriastradh  * Software is furnished to do so, subject to the following conditions:
129d20d926Sriastradh  *
139d20d926Sriastradh  * The above copyright notice and this permission notice (including the
149d20d926Sriastradh  * next paragraph) shall be included in all copies or substantial portions
159d20d926Sriastradh  * of the Software.
169d20d926Sriastradh  *
179d20d926Sriastradh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
189d20d926Sriastradh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
199d20d926Sriastradh  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
209d20d926Sriastradh  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
219d20d926Sriastradh  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229d20d926Sriastradh  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
239d20d926Sriastradh  * DEALINGS IN THE SOFTWARE.
249d20d926Sriastradh  */
259d20d926Sriastradh 
269d20d926Sriastradh #ifndef __DRM_PANEL_H__
279d20d926Sriastradh #define __DRM_PANEL_H__
289d20d926Sriastradh 
29*41ec0267Sriastradh #include <linux/err.h>
30*41ec0267Sriastradh #include <linux/errno.h>
319d20d926Sriastradh #include <linux/list.h>
329d20d926Sriastradh 
33*41ec0267Sriastradh struct backlight_device;
34*41ec0267Sriastradh struct device_node;
359d20d926Sriastradh struct drm_connector;
369d20d926Sriastradh struct drm_device;
379d20d926Sriastradh struct drm_panel;
38efa246c0Sriastradh struct display_timing;
399d20d926Sriastradh 
40efa246c0Sriastradh /**
41efa246c0Sriastradh  * struct drm_panel_funcs - perform operations on a given panel
42efa246c0Sriastradh  *
43efa246c0Sriastradh  * The .prepare() function is typically called before the display controller
44efa246c0Sriastradh  * starts to transmit video data. Panel drivers can use this to turn the panel
45efa246c0Sriastradh  * on and wait for it to become ready. If additional configuration is required
46efa246c0Sriastradh  * (via a control bus such as I2C, SPI or DSI for example) this is a good time
47efa246c0Sriastradh  * to do that.
48efa246c0Sriastradh  *
49efa246c0Sriastradh  * After the display controller has started transmitting video data, it's safe
50efa246c0Sriastradh  * to call the .enable() function. This will typically enable the backlight to
51efa246c0Sriastradh  * make the image on screen visible. Some panels require a certain amount of
52efa246c0Sriastradh  * time or frames before the image is displayed. This function is responsible
53efa246c0Sriastradh  * for taking this into account before enabling the backlight to avoid visual
54efa246c0Sriastradh  * glitches.
55efa246c0Sriastradh  *
56efa246c0Sriastradh  * Before stopping video transmission from the display controller it can be
57efa246c0Sriastradh  * necessary to turn off the panel to avoid visual glitches. This is done in
58efa246c0Sriastradh  * the .disable() function. Analogously to .enable() this typically involves
59efa246c0Sriastradh  * turning off the backlight and waiting for some time to make sure no image
60efa246c0Sriastradh  * is visible on the panel. It is then safe for the display controller to
61efa246c0Sriastradh  * cease transmission of video data.
62efa246c0Sriastradh  *
63efa246c0Sriastradh  * To save power when no video data is transmitted, a driver can power down
64efa246c0Sriastradh  * the panel. This is the job of the .unprepare() function.
65*41ec0267Sriastradh  *
66*41ec0267Sriastradh  * Backlight can be handled automatically if configured using
67*41ec0267Sriastradh  * drm_panel_of_backlight(). Then the driver does not need to implement the
68*41ec0267Sriastradh  * functionality to enable/disable backlight.
69efa246c0Sriastradh  */
709d20d926Sriastradh struct drm_panel_funcs {
71*41ec0267Sriastradh 	/**
72*41ec0267Sriastradh 	 * @prepare:
73*41ec0267Sriastradh 	 *
74*41ec0267Sriastradh 	 * Turn on panel and perform set up.
75*41ec0267Sriastradh 	 *
76*41ec0267Sriastradh 	 * This function is optional.
77*41ec0267Sriastradh 	 */
78efa246c0Sriastradh 	int (*prepare)(struct drm_panel *panel);
79*41ec0267Sriastradh 
80*41ec0267Sriastradh 	/**
81*41ec0267Sriastradh 	 * @enable:
82*41ec0267Sriastradh 	 *
83*41ec0267Sriastradh 	 * Enable panel (turn on back light, etc.).
84*41ec0267Sriastradh 	 *
85*41ec0267Sriastradh 	 * This function is optional.
86*41ec0267Sriastradh 	 */
879d20d926Sriastradh 	int (*enable)(struct drm_panel *panel);
88*41ec0267Sriastradh 
89*41ec0267Sriastradh 	/**
90*41ec0267Sriastradh 	 * @disable:
91*41ec0267Sriastradh 	 *
92*41ec0267Sriastradh 	 * Disable panel (turn off back light, etc.).
93*41ec0267Sriastradh 	 *
94*41ec0267Sriastradh 	 * This function is optional.
95*41ec0267Sriastradh 	 */
96*41ec0267Sriastradh 	int (*disable)(struct drm_panel *panel);
97*41ec0267Sriastradh 
98*41ec0267Sriastradh 	/**
99*41ec0267Sriastradh 	 * @unprepare:
100*41ec0267Sriastradh 	 *
101*41ec0267Sriastradh 	 * Turn off panel.
102*41ec0267Sriastradh 	 *
103*41ec0267Sriastradh 	 * This function is optional.
104*41ec0267Sriastradh 	 */
105*41ec0267Sriastradh 	int (*unprepare)(struct drm_panel *panel);
106*41ec0267Sriastradh 
107*41ec0267Sriastradh 	/**
108*41ec0267Sriastradh 	 * @get_modes:
109*41ec0267Sriastradh 	 *
110*41ec0267Sriastradh 	 * Add modes to the connector that the panel is attached to
111*41ec0267Sriastradh 	 * and returns the number of modes added.
112*41ec0267Sriastradh 	 *
113*41ec0267Sriastradh 	 * This function is mandatory.
114*41ec0267Sriastradh 	 */
115*41ec0267Sriastradh 	int (*get_modes)(struct drm_panel *panel,
116*41ec0267Sriastradh 			 struct drm_connector *connector);
117*41ec0267Sriastradh 
118*41ec0267Sriastradh 	/**
119*41ec0267Sriastradh 	 * @get_timings:
120*41ec0267Sriastradh 	 *
121*41ec0267Sriastradh 	 * Copy display timings into the provided array and return
122*41ec0267Sriastradh 	 * the number of display timings available.
123*41ec0267Sriastradh 	 *
124*41ec0267Sriastradh 	 * This function is optional.
125*41ec0267Sriastradh 	 */
126efa246c0Sriastradh 	int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
127efa246c0Sriastradh 			   struct display_timing *timings);
1289d20d926Sriastradh };
1299d20d926Sriastradh 
130*41ec0267Sriastradh /**
131*41ec0267Sriastradh  * struct drm_panel - DRM panel object
132*41ec0267Sriastradh  */
1339d20d926Sriastradh struct drm_panel {
134*41ec0267Sriastradh 	/**
135*41ec0267Sriastradh 	 * @dev:
136*41ec0267Sriastradh 	 *
137*41ec0267Sriastradh 	 * Parent device of the panel.
138*41ec0267Sriastradh 	 */
1399d20d926Sriastradh 	struct device *dev;
1409d20d926Sriastradh 
141*41ec0267Sriastradh 	/**
142*41ec0267Sriastradh 	 * @backlight:
143*41ec0267Sriastradh 	 *
144*41ec0267Sriastradh 	 * Backlight device, used to turn on backlight after the call
145*41ec0267Sriastradh 	 * to enable(), and to turn off backlight before the call to
146*41ec0267Sriastradh 	 * disable().
147*41ec0267Sriastradh 	 * backlight is set by drm_panel_of_backlight() and drivers
148*41ec0267Sriastradh 	 * shall not assign it.
149*41ec0267Sriastradh 	 */
150*41ec0267Sriastradh 	struct backlight_device *backlight;
151*41ec0267Sriastradh 
152*41ec0267Sriastradh 	/**
153*41ec0267Sriastradh 	 * @funcs:
154*41ec0267Sriastradh 	 *
155*41ec0267Sriastradh 	 * Operations that can be performed on the panel.
156*41ec0267Sriastradh 	 */
1579d20d926Sriastradh 	const struct drm_panel_funcs *funcs;
1589d20d926Sriastradh 
159*41ec0267Sriastradh 	/**
160*41ec0267Sriastradh 	 * @connector_type:
161*41ec0267Sriastradh 	 *
162*41ec0267Sriastradh 	 * Type of the panel as a DRM_MODE_CONNECTOR_* value. This is used to
163*41ec0267Sriastradh 	 * initialise the drm_connector corresponding to the panel with the
164*41ec0267Sriastradh 	 * correct connector type.
165*41ec0267Sriastradh 	 */
166*41ec0267Sriastradh 	int connector_type;
167*41ec0267Sriastradh 
168*41ec0267Sriastradh 	/**
169*41ec0267Sriastradh 	 * @list:
170*41ec0267Sriastradh 	 *
171*41ec0267Sriastradh 	 * Panel entry in registry.
172*41ec0267Sriastradh 	 */
1739d20d926Sriastradh 	struct list_head list;
1749d20d926Sriastradh };
1759d20d926Sriastradh 
176453c4aa9Sjmcneill #ifdef __NetBSD__
177453c4aa9Sjmcneill void drm_panel_init_lock(void);
178453c4aa9Sjmcneill void drm_panel_fini_lock(void);
179453c4aa9Sjmcneill #endif
180453c4aa9Sjmcneill 
181*41ec0267Sriastradh void drm_panel_init(struct drm_panel *panel, struct device *dev,
182*41ec0267Sriastradh 		    const struct drm_panel_funcs *funcs,
183*41ec0267Sriastradh 		    int connector_type);
1849d20d926Sriastradh 
1859d20d926Sriastradh int drm_panel_add(struct drm_panel *panel);
1869d20d926Sriastradh void drm_panel_remove(struct drm_panel *panel);
1879d20d926Sriastradh 
1889d20d926Sriastradh int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector);
189*41ec0267Sriastradh void drm_panel_detach(struct drm_panel *panel);
1909d20d926Sriastradh 
191*41ec0267Sriastradh int drm_panel_prepare(struct drm_panel *panel);
192*41ec0267Sriastradh int drm_panel_unprepare(struct drm_panel *panel);
193*41ec0267Sriastradh 
194*41ec0267Sriastradh int drm_panel_enable(struct drm_panel *panel);
195*41ec0267Sriastradh int drm_panel_disable(struct drm_panel *panel);
196*41ec0267Sriastradh 
197*41ec0267Sriastradh int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
198*41ec0267Sriastradh 
199*41ec0267Sriastradh #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
200*41ec0267Sriastradh struct drm_panel *of_drm_find_panel(const struct device_node *np);
2019d20d926Sriastradh #else
of_drm_find_panel(const struct device_node * np)202*41ec0267Sriastradh static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
2039d20d926Sriastradh {
204*41ec0267Sriastradh 	return ERR_PTR(-ENODEV);
205*41ec0267Sriastradh }
206*41ec0267Sriastradh #endif
207*41ec0267Sriastradh 
208*41ec0267Sriastradh #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
209*41ec0267Sriastradh int drm_panel_of_backlight(struct drm_panel *panel);
210*41ec0267Sriastradh #else
drm_panel_of_backlight(struct drm_panel * panel)211*41ec0267Sriastradh static inline int drm_panel_of_backlight(struct drm_panel *panel)
212*41ec0267Sriastradh {
213*41ec0267Sriastradh 	return 0;
2149d20d926Sriastradh }
2159d20d926Sriastradh #endif
2169d20d926Sriastradh 
2179d20d926Sriastradh #endif
218