drm/panel: remove return value of function drm_panel_add
[linux-2.6-microblaze.git] / drivers / gpu / drm / drm_panel.c
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 #include <linux/backlight.h>
25 #include <linux/err.h>
26 #include <linux/module.h>
27
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_panel.h>
30 #include <drm/drm_print.h>
31
32 static DEFINE_MUTEX(panel_lock);
33 static LIST_HEAD(panel_list);
34
35 /**
36  * DOC: drm panel
37  *
38  * The DRM panel helpers allow drivers to register panel objects with a
39  * central registry and provide functions to retrieve those panels in display
40  * drivers.
41  *
42  * For easy integration into drivers using the &drm_bridge infrastructure please
43  * take look at drm_panel_bridge_add() and devm_drm_panel_bridge_add().
44  */
45
46 /**
47  * drm_panel_init - initialize a panel
48  * @panel: DRM panel
49  * @dev: parent device of the panel
50  * @funcs: panel operations
51  * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to
52  *      the panel interface
53  *
54  * Initialize the panel structure for subsequent registration with
55  * drm_panel_add().
56  */
57 void drm_panel_init(struct drm_panel *panel, struct device *dev,
58                     const struct drm_panel_funcs *funcs, int connector_type)
59 {
60         INIT_LIST_HEAD(&panel->list);
61         panel->dev = dev;
62         panel->funcs = funcs;
63         panel->connector_type = connector_type;
64 }
65 EXPORT_SYMBOL(drm_panel_init);
66
67 /**
68  * drm_panel_add - add a panel to the global registry
69  * @panel: panel to add
70  *
71  * Add a panel to the global registry so that it can be looked up by display
72  * drivers.
73  */
74 void drm_panel_add(struct drm_panel *panel)
75 {
76         mutex_lock(&panel_lock);
77         list_add_tail(&panel->list, &panel_list);
78         mutex_unlock(&panel_lock);
79 }
80 EXPORT_SYMBOL(drm_panel_add);
81
82 /**
83  * drm_panel_remove - remove a panel from the global registry
84  * @panel: DRM panel
85  *
86  * Removes a panel from the global registry.
87  */
88 void drm_panel_remove(struct drm_panel *panel)
89 {
90         mutex_lock(&panel_lock);
91         list_del_init(&panel->list);
92         mutex_unlock(&panel_lock);
93 }
94 EXPORT_SYMBOL(drm_panel_remove);
95
96 /**
97  * drm_panel_attach - attach a panel to a connector
98  * @panel: DRM panel
99  * @connector: DRM connector
100  *
101  * After obtaining a pointer to a DRM panel a display driver calls this
102  * function to attach a panel to a connector.
103  *
104  * An error is returned if the panel is already attached to another connector.
105  *
106  * When unloading, the driver should detach from the panel by calling
107  * drm_panel_detach().
108  *
109  * Return: 0 on success or a negative error code on failure.
110  */
111 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
112 {
113         return 0;
114 }
115 EXPORT_SYMBOL(drm_panel_attach);
116
117 /**
118  * drm_panel_detach - detach a panel from a connector
119  * @panel: DRM panel
120  *
121  * Detaches a panel from the connector it is attached to. If a panel is not
122  * attached to any connector this is effectively a no-op.
123  *
124  * This function should not be called by the panel device itself. It
125  * is only for the drm device that called drm_panel_attach().
126  */
127 void drm_panel_detach(struct drm_panel *panel)
128 {
129 }
130 EXPORT_SYMBOL(drm_panel_detach);
131
132 /**
133  * drm_panel_prepare - power on a panel
134  * @panel: DRM panel
135  *
136  * Calling this function will enable power and deassert any reset signals to
137  * the panel. After this has completed it is possible to communicate with any
138  * integrated circuitry via a command bus.
139  *
140  * Return: 0 on success or a negative error code on failure.
141  */
142 int drm_panel_prepare(struct drm_panel *panel)
143 {
144         if (!panel)
145                 return -EINVAL;
146
147         if (panel->funcs && panel->funcs->prepare)
148                 return panel->funcs->prepare(panel);
149
150         return 0;
151 }
152 EXPORT_SYMBOL(drm_panel_prepare);
153
154 /**
155  * drm_panel_unprepare - power off a panel
156  * @panel: DRM panel
157  *
158  * Calling this function will completely power off a panel (assert the panel's
159  * reset, turn off power supplies, ...). After this function has completed, it
160  * is usually no longer possible to communicate with the panel until another
161  * call to drm_panel_prepare().
162  *
163  * Return: 0 on success or a negative error code on failure.
164  */
165 int drm_panel_unprepare(struct drm_panel *panel)
166 {
167         if (!panel)
168                 return -EINVAL;
169
170         if (panel->funcs && panel->funcs->unprepare)
171                 return panel->funcs->unprepare(panel);
172
173         return 0;
174 }
175 EXPORT_SYMBOL(drm_panel_unprepare);
176
177 /**
178  * drm_panel_enable - enable a panel
179  * @panel: DRM panel
180  *
181  * Calling this function will cause the panel display drivers to be turned on
182  * and the backlight to be enabled. Content will be visible on screen after
183  * this call completes.
184  *
185  * Return: 0 on success or a negative error code on failure.
186  */
187 int drm_panel_enable(struct drm_panel *panel)
188 {
189         int ret;
190
191         if (!panel)
192                 return -EINVAL;
193
194         if (panel->funcs && panel->funcs->enable) {
195                 ret = panel->funcs->enable(panel);
196                 if (ret < 0)
197                         return ret;
198         }
199
200         ret = backlight_enable(panel->backlight);
201         if (ret < 0)
202                 DRM_DEV_INFO(panel->dev, "failed to enable backlight: %d\n",
203                              ret);
204
205         return 0;
206 }
207 EXPORT_SYMBOL(drm_panel_enable);
208
209 /**
210  * drm_panel_disable - disable a panel
211  * @panel: DRM panel
212  *
213  * This will typically turn off the panel's backlight or disable the display
214  * drivers. For smart panels it should still be possible to communicate with
215  * the integrated circuitry via any command bus after this call.
216  *
217  * Return: 0 on success or a negative error code on failure.
218  */
219 int drm_panel_disable(struct drm_panel *panel)
220 {
221         int ret;
222
223         if (!panel)
224                 return -EINVAL;
225
226         ret = backlight_disable(panel->backlight);
227         if (ret < 0)
228                 DRM_DEV_INFO(panel->dev, "failed to disable backlight: %d\n",
229                              ret);
230
231         if (panel->funcs && panel->funcs->disable)
232                 return panel->funcs->disable(panel);
233
234         return 0;
235 }
236 EXPORT_SYMBOL(drm_panel_disable);
237
238 /**
239  * drm_panel_get_modes - probe the available display modes of a panel
240  * @panel: DRM panel
241  * @connector: DRM connector
242  *
243  * The modes probed from the panel are automatically added to the connector
244  * that the panel is attached to.
245  *
246  * Return: The number of modes available from the panel on success or a
247  * negative error code on failure.
248  */
249 int drm_panel_get_modes(struct drm_panel *panel,
250                         struct drm_connector *connector)
251 {
252         if (!panel)
253                 return -EINVAL;
254
255         if (panel->funcs && panel->funcs->get_modes)
256                 return panel->funcs->get_modes(panel, connector);
257
258         return -EOPNOTSUPP;
259 }
260 EXPORT_SYMBOL(drm_panel_get_modes);
261
262 #ifdef CONFIG_OF
263 /**
264  * of_drm_find_panel - look up a panel using a device tree node
265  * @np: device tree node of the panel
266  *
267  * Searches the set of registered panels for one that matches the given device
268  * tree node. If a matching panel is found, return a pointer to it.
269  *
270  * Return: A pointer to the panel registered for the specified device tree
271  * node or an ERR_PTR() if no panel matching the device tree node can be found.
272  *
273  * Possible error codes returned by this function:
274  *
275  * - EPROBE_DEFER: the panel device has not been probed yet, and the caller
276  *   should retry later
277  * - ENODEV: the device is not available (status != "okay" or "ok")
278  */
279 struct drm_panel *of_drm_find_panel(const struct device_node *np)
280 {
281         struct drm_panel *panel;
282
283         if (!of_device_is_available(np))
284                 return ERR_PTR(-ENODEV);
285
286         mutex_lock(&panel_lock);
287
288         list_for_each_entry(panel, &panel_list, list) {
289                 if (panel->dev->of_node == np) {
290                         mutex_unlock(&panel_lock);
291                         return panel;
292                 }
293         }
294
295         mutex_unlock(&panel_lock);
296         return ERR_PTR(-EPROBE_DEFER);
297 }
298 EXPORT_SYMBOL(of_drm_find_panel);
299 #endif
300
301 #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
302 /**
303  * drm_panel_of_backlight - use backlight device node for backlight
304  * @panel: DRM panel
305  *
306  * Use this function to enable backlight handling if your panel
307  * uses device tree and has a backlight phandle.
308  *
309  * When the panel is enabled backlight will be enabled after a
310  * successful call to &drm_panel_funcs.enable()
311  *
312  * When the panel is disabled backlight will be disabled before the
313  * call to &drm_panel_funcs.disable().
314  *
315  * A typical implementation for a panel driver supporting device tree
316  * will call this function at probe time. Backlight will then be handled
317  * transparently without requiring any intervention from the driver.
318  * drm_panel_of_backlight() must be called after the call to drm_panel_init().
319  *
320  * Return: 0 on success or a negative error code on failure.
321  */
322 int drm_panel_of_backlight(struct drm_panel *panel)
323 {
324         struct backlight_device *backlight;
325
326         if (!panel || !panel->dev)
327                 return -EINVAL;
328
329         backlight = devm_of_find_backlight(panel->dev);
330
331         if (IS_ERR(backlight))
332                 return PTR_ERR(backlight);
333
334         panel->backlight = backlight;
335         return 0;
336 }
337 EXPORT_SYMBOL(drm_panel_of_backlight);
338 #endif
339
340 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
341 MODULE_DESCRIPTION("DRM panel infrastructure");
342 MODULE_LICENSE("GPL and additional rights");