1 /*
2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef __DRM_PANEL_H__
25 #define __DRM_PANEL_H__
26
27 #include <linux/err.h>
28 #include <linux/errno.h>
29 #include <linux/list.h>
30 #include <linux/notifier.h>
31
32 /* A hardware display blank change occurred */
33 #define DRM_PANEL_EVENT_BLANK 0x01
34 /* A hardware display blank early change occurred */
35 #define DRM_PANEL_EARLY_EVENT_BLANK 0x02
36
37 enum {
38 /* panel: power on */
39 DRM_PANEL_BLANK_UNBLANK,
40 /* panel: power off */
41 DRM_PANEL_BLANK_POWERDOWN,
42 };
43
44 struct drm_panel_notifier {
45 void *data;
46 };
47
48 struct device_node;
49 struct drm_connector;
50 struct drm_device;
51 struct drm_panel;
52 struct display_timing;
53
54 /**
55 * struct drm_panel_funcs - perform operations on a given panel
56 *
57 * The .prepare() function is typically called before the display controller
58 * starts to transmit video data. Panel drivers can use this to turn the panel
59 * on and wait for it to become ready. If additional configuration is required
60 * (via a control bus such as I2C, SPI or DSI for example) this is a good time
61 * to do that.
62 *
63 * After the display controller has started transmitting video data, it's safe
64 * to call the .enable() function. This will typically enable the backlight to
65 * make the image on screen visible. Some panels require a certain amount of
66 * time or frames before the image is displayed. This function is responsible
67 * for taking this into account before enabling the backlight to avoid visual
68 * glitches.
69 *
70 * Before stopping video transmission from the display controller it can be
71 * necessary to turn off the panel to avoid visual glitches. This is done in
72 * the .disable() function. Analogously to .enable() this typically involves
73 * turning off the backlight and waiting for some time to make sure no image
74 * is visible on the panel. It is then safe for the display controller to
75 * cease transmission of video data.
76 *
77 * To save power when no video data is transmitted, a driver can power down
78 * the panel. This is the job of the .unprepare() function.
79 */
80 struct drm_panel_funcs {
81 /**
82 * @prepare:
83 *
84 * Turn on panel and perform set up.
85 */
86 int (*prepare)(struct drm_panel *panel);
87
88 /**
89 * @enable:
90 *
91 * Enable panel (turn on back light, etc.).
92 */
93 int (*enable)(struct drm_panel *panel);
94
95 /**
96 * @disable:
97 *
98 * Disable panel (turn off back light, etc.).
99 */
100 int (*disable)(struct drm_panel *panel);
101
102 /**
103 * @unprepare:
104 *
105 * Turn off panel.
106 */
107 int (*unprepare)(struct drm_panel *panel);
108
109 /**
110 * @get_modes:
111 *
112 * Add modes to the connector that the panel is attached to and
113 * return the number of modes added.
114 */
115 int (*get_modes)(struct drm_panel *panel);
116
117 /**
118 * @get_timings:
119 *
120 * Copy display timings into the provided array and return
121 * the number of display timings available.
122 */
123 int (*get_timings)(struct drm_panel *panel, unsigned int num_timings,
124 struct display_timing *timings);
125 };
126
127 /**
128 * struct drm_panel - DRM panel object
129 */
130 struct drm_panel {
131 /**
132 * @drm:
133 *
134 * DRM device owning the panel.
135 */
136 struct drm_device *drm;
137
138 /**
139 * @connector:
140 *
141 * DRM connector that the panel is attached to.
142 */
143 struct drm_connector *connector;
144
145 /**
146 * @dev:
147 *
148 * Parent device of the panel.
149 */
150 struct device *dev;
151
152 /**
153 * @funcs:
154 *
155 * Operations that can be performed on the panel.
156 */
157 const struct drm_panel_funcs *funcs;
158
159 /**
160 * @list:
161 *
162 * Panel entry in registry.
163 */
164 struct list_head list;
165
166 /**
167 * @nh:
168 *
169 * panel notifier list head
170 */
171 struct blocking_notifier_head nh;
172 };
173
174 void drm_panel_init(struct drm_panel *panel);
175
176 int drm_panel_add(struct drm_panel *panel);
177 void drm_panel_remove(struct drm_panel *panel);
178
179 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector);
180 void drm_panel_detach(struct drm_panel *panel);
181
182 int drm_panel_notifier_register(struct drm_panel *panel,
183 struct notifier_block *nb);
184 int drm_panel_notifier_unregister(struct drm_panel *panel,
185 struct notifier_block *nb);
186 int drm_panel_notifier_call_chain(struct drm_panel *panel,
187 unsigned long val, void *v);
188
189 int drm_panel_prepare(struct drm_panel *panel);
190 int drm_panel_unprepare(struct drm_panel *panel);
191
192 int drm_panel_enable(struct drm_panel *panel);
193 int drm_panel_disable(struct drm_panel *panel);
194
195 int drm_panel_get_modes(struct drm_panel *panel);
196
197 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
198 struct drm_panel *of_drm_find_panel(const struct device_node *np);
199 #else
of_drm_find_panel(const struct device_node * np)200 static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
201 {
202 return ERR_PTR(-ENODEV);
203 }
204 #endif
205
206 #endif
207