xref: /linux/drivers/gpu/drm/drm_panel.c (revision 99676aed1fec109d62822e21a06760eb098dc5f4)
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/export.h>
27 #include <linux/module.h>
28 #include <linux/of.h>
29 
30 #include <drm/drm_crtc.h>
31 #include <drm/drm_panel.h>
32 #include <drm/drm_print.h>
33 
34 static DEFINE_MUTEX(panel_lock);
35 static LIST_HEAD(panel_list);
36 
37 /**
38  * DOC: drm panel
39  *
40  * The DRM panel helpers allow drivers to register panel objects with a
41  * central registry and provide functions to retrieve those panels in display
42  * drivers.
43  *
44  * For easy integration into drivers using the &drm_bridge infrastructure please
45  * take look at drm_panel_bridge_add() and devm_drm_panel_bridge_add().
46  */
47 
48 /**
49  * drm_panel_init - initialize a panel
50  * @panel: DRM panel
51  * @dev: parent device of the panel
52  * @funcs: panel operations
53  * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to
54  *	the panel interface (must NOT be DRM_MODE_CONNECTOR_Unknown)
55  *
56  * Initialize the panel structure for subsequent registration with
57  * drm_panel_add().
58  */
59 static void drm_panel_init(struct drm_panel *panel, struct device *dev,
60 			   const struct drm_panel_funcs *funcs,
61 			   int connector_type)
62 {
63 	if (connector_type == DRM_MODE_CONNECTOR_Unknown)
64 		DRM_WARN("%s: %s: a valid connector type is required!\n", __func__, dev_name(dev));
65 
66 	INIT_LIST_HEAD(&panel->list);
67 	INIT_LIST_HEAD(&panel->followers);
68 	mutex_init(&panel->follower_lock);
69 	panel->dev = dev;
70 	panel->funcs = funcs;
71 	panel->connector_type = connector_type;
72 }
73 
74 /**
75  * drm_panel_add - add a panel to the global registry
76  * @panel: panel to add
77  *
78  * Add a panel to the global registry so that it can be looked
79  * up by display drivers. The panel to be added must have been
80  * allocated by devm_drm_panel_alloc().
81  */
82 void drm_panel_add(struct drm_panel *panel)
83 {
84 	mutex_lock(&panel_lock);
85 	list_add_tail(&panel->list, &panel_list);
86 	mutex_unlock(&panel_lock);
87 }
88 EXPORT_SYMBOL(drm_panel_add);
89 
90 /**
91  * drm_panel_remove - remove a panel from the global registry
92  * @panel: DRM panel
93  *
94  * Removes a panel from the global registry.
95  */
96 void drm_panel_remove(struct drm_panel *panel)
97 {
98 	mutex_lock(&panel_lock);
99 	list_del_init(&panel->list);
100 	mutex_unlock(&panel_lock);
101 }
102 EXPORT_SYMBOL(drm_panel_remove);
103 
104 static void drm_panel_add_release(void *data)
105 {
106 	drm_panel_remove(data);
107 }
108 
109 /**
110  * devm_drm_panel_add - add a panel to the global registry using devres
111  * @panel: panel to add
112  *
113  * Add a panel to the global registry so that it can be looked
114  * up by display drivers. The panel to be added must have been
115  * allocated by devm_drm_panel_alloc(). Unlike drm_panel_add() with this
116  * function there is no need to call drm_panel_remove(), it will be called
117  * automatically.
118  */
119 int devm_drm_panel_add(struct device *dev, struct drm_panel *panel)
120 {
121 	drm_panel_add(panel);
122 
123 	return devm_add_action_or_reset(dev, drm_panel_add_release, panel);
124 }
125 EXPORT_SYMBOL(devm_drm_panel_add);
126 
127 /**
128  * drm_panel_prepare - power on a panel
129  * @panel: DRM panel
130  *
131  * Calling this function will enable power and deassert any reset signals to
132  * the panel. After this has completed it is possible to communicate with any
133  * integrated circuitry via a command bus. This function cannot fail (as it is
134  * called from the pre_enable call chain). There will always be a call to
135  * drm_panel_disable() afterwards.
136  */
137 void drm_panel_prepare(struct drm_panel *panel)
138 {
139 	struct drm_panel_follower *follower;
140 	int ret;
141 
142 	if (!panel)
143 		return;
144 
145 	if (panel->prepared) {
146 		dev_warn(panel->dev, "Skipping prepare of already prepared panel\n");
147 		return;
148 	}
149 
150 	mutex_lock(&panel->follower_lock);
151 
152 	if (panel->funcs && panel->funcs->prepare) {
153 		ret = panel->funcs->prepare(panel);
154 		if (ret < 0)
155 			goto exit;
156 	}
157 	panel->prepared = true;
158 
159 	list_for_each_entry(follower, &panel->followers, list) {
160 		if (!follower->funcs->panel_prepared)
161 			continue;
162 
163 		ret = follower->funcs->panel_prepared(follower);
164 		if (ret < 0)
165 			dev_info(panel->dev, "%ps failed: %d\n",
166 				 follower->funcs->panel_prepared, ret);
167 	}
168 
169 exit:
170 	mutex_unlock(&panel->follower_lock);
171 }
172 EXPORT_SYMBOL(drm_panel_prepare);
173 
174 /**
175  * drm_panel_unprepare - power off a panel
176  * @panel: DRM panel
177  *
178  * Calling this function will completely power off a panel (assert the panel's
179  * reset, turn off power supplies, ...). After this function has completed, it
180  * is usually no longer possible to communicate with the panel until another
181  * call to drm_panel_prepare().
182  */
183 void drm_panel_unprepare(struct drm_panel *panel)
184 {
185 	struct drm_panel_follower *follower;
186 	int ret;
187 
188 	if (!panel)
189 		return;
190 
191 	/*
192 	 * If you are seeing the warning below it likely means one of two things:
193 	 * - Your panel driver incorrectly calls drm_panel_unprepare() in its
194 	 *   shutdown routine. You should delete this.
195 	 * - You are using panel-edp or panel-simple and your DRM modeset
196 	 *   driver's shutdown() callback happened after the panel's shutdown().
197 	 *   In this case the warning is harmless though ideally you should
198 	 *   figure out how to reverse the order of the shutdown() callbacks.
199 	 */
200 	if (!panel->prepared) {
201 		dev_warn(panel->dev, "Skipping unprepare of already unprepared panel\n");
202 		return;
203 	}
204 
205 	mutex_lock(&panel->follower_lock);
206 
207 	list_for_each_entry(follower, &panel->followers, list) {
208 		if (!follower->funcs->panel_unpreparing)
209 			continue;
210 
211 		ret = follower->funcs->panel_unpreparing(follower);
212 		if (ret < 0)
213 			dev_info(panel->dev, "%ps failed: %d\n",
214 				 follower->funcs->panel_unpreparing, ret);
215 	}
216 
217 	if (panel->funcs && panel->funcs->unprepare) {
218 		ret = panel->funcs->unprepare(panel);
219 		if (ret < 0)
220 			goto exit;
221 	}
222 	panel->prepared = false;
223 
224 exit:
225 	mutex_unlock(&panel->follower_lock);
226 }
227 EXPORT_SYMBOL(drm_panel_unprepare);
228 
229 /**
230  * drm_panel_enable - enable a panel
231  * @panel: DRM panel
232  *
233  * Calling this function will cause the panel display drivers to be turned on
234  * and the backlight to be enabled. Content will be visible on screen after
235  * this call completes. This function cannot fail (as it is called from the
236  * enable call chain). There will always be a call to drm_panel_disable()
237  * afterwards.
238  */
239 void drm_panel_enable(struct drm_panel *panel)
240 {
241 	struct drm_panel_follower *follower;
242 	int ret;
243 
244 	if (!panel)
245 		return;
246 
247 	if (panel->enabled) {
248 		dev_warn(panel->dev, "Skipping enable of already enabled panel\n");
249 		return;
250 	}
251 
252 	mutex_lock(&panel->follower_lock);
253 
254 	if (panel->funcs && panel->funcs->enable) {
255 		ret = panel->funcs->enable(panel);
256 		if (ret < 0)
257 			goto exit;
258 	}
259 	panel->enabled = true;
260 
261 	ret = backlight_enable(panel->backlight);
262 	if (ret < 0)
263 		DRM_DEV_INFO(panel->dev, "failed to enable backlight: %d\n",
264 			     ret);
265 
266 	list_for_each_entry(follower, &panel->followers, list) {
267 		if (!follower->funcs->panel_enabled)
268 			continue;
269 
270 		ret = follower->funcs->panel_enabled(follower);
271 		if (ret < 0)
272 			dev_info(panel->dev, "%ps failed: %d\n",
273 				 follower->funcs->panel_enabled, ret);
274 	}
275 
276 exit:
277 	mutex_unlock(&panel->follower_lock);
278 }
279 EXPORT_SYMBOL(drm_panel_enable);
280 
281 /**
282  * drm_panel_disable - disable a panel
283  * @panel: DRM panel
284  *
285  * This will typically turn off the panel's backlight or disable the display
286  * drivers. For smart panels it should still be possible to communicate with
287  * the integrated circuitry via any command bus after this call.
288  */
289 void drm_panel_disable(struct drm_panel *panel)
290 {
291 	struct drm_panel_follower *follower;
292 	int ret;
293 
294 	if (!panel)
295 		return;
296 
297 	/*
298 	 * If you are seeing the warning below it likely means one of two things:
299 	 * - Your panel driver incorrectly calls drm_panel_disable() in its
300 	 *   shutdown routine. You should delete this.
301 	 * - You are using panel-edp or panel-simple and your DRM modeset
302 	 *   driver's shutdown() callback happened after the panel's shutdown().
303 	 *   In this case the warning is harmless though ideally you should
304 	 *   figure out how to reverse the order of the shutdown() callbacks.
305 	 */
306 	if (!panel->enabled) {
307 		dev_warn(panel->dev, "Skipping disable of already disabled panel\n");
308 		return;
309 	}
310 
311 	mutex_lock(&panel->follower_lock);
312 
313 	list_for_each_entry(follower, &panel->followers, list) {
314 		if (!follower->funcs->panel_disabling)
315 			continue;
316 
317 		ret = follower->funcs->panel_disabling(follower);
318 		if (ret < 0)
319 			dev_info(panel->dev, "%ps failed: %d\n",
320 				 follower->funcs->panel_disabling, ret);
321 	}
322 
323 	ret = backlight_disable(panel->backlight);
324 	if (ret < 0)
325 		DRM_DEV_INFO(panel->dev, "failed to disable backlight: %d\n",
326 			     ret);
327 
328 	if (panel->funcs && panel->funcs->disable) {
329 		ret = panel->funcs->disable(panel);
330 		if (ret < 0)
331 			goto exit;
332 	}
333 	panel->enabled = false;
334 
335 exit:
336 	mutex_unlock(&panel->follower_lock);
337 }
338 EXPORT_SYMBOL(drm_panel_disable);
339 
340 /**
341  * drm_panel_get_modes - probe the available display modes of a panel
342  * @panel: DRM panel
343  * @connector: DRM connector
344  *
345  * The modes probed from the panel are automatically added to the connector
346  * that the panel is attached to.
347  *
348  * Return: The number of modes available from the panel on success, or 0 on
349  * failure (no modes).
350  */
351 int drm_panel_get_modes(struct drm_panel *panel,
352 			struct drm_connector *connector)
353 {
354 	if (!panel)
355 		return 0;
356 
357 	if (panel->funcs && panel->funcs->get_modes) {
358 		int num;
359 
360 		num = panel->funcs->get_modes(panel, connector);
361 		if (num > 0)
362 			return num;
363 	}
364 
365 	return 0;
366 }
367 EXPORT_SYMBOL(drm_panel_get_modes);
368 
369 static void __drm_panel_free(struct kref *kref)
370 {
371 	struct drm_panel *panel = container_of(kref, struct drm_panel, refcount);
372 
373 	kfree(panel->container);
374 }
375 
376 /**
377  * drm_panel_get - Acquire a panel reference
378  * @panel: DRM panel
379  *
380  * This function increments the panel's refcount.
381  * Returns:
382  * Pointer to @panel
383  */
384 struct drm_panel *drm_panel_get(struct drm_panel *panel)
385 {
386 	if (!panel)
387 		return panel;
388 
389 	kref_get(&panel->refcount);
390 
391 	return panel;
392 }
393 EXPORT_SYMBOL(drm_panel_get);
394 
395 /**
396  * drm_panel_put - Release a panel reference
397  * @panel: DRM panel
398  *
399  * This function decrements the panel's reference count and frees the
400  * object if the reference count drops to zero.
401  */
402 void drm_panel_put(struct drm_panel *panel)
403 {
404 	if (panel)
405 		kref_put(&panel->refcount, __drm_panel_free);
406 }
407 EXPORT_SYMBOL(drm_panel_put);
408 
409 /**
410  * drm_panel_put_void - wrapper to drm_panel_put() taking a void pointer
411  *
412  * @data: pointer to @struct drm_panel, cast to a void pointer
413  *
414  * Wrapper of drm_panel_put() to be used when a function taking a void
415  * pointer is needed, for example as a devm action.
416  */
417 static void drm_panel_put_void(void *data)
418 {
419 	struct drm_panel *panel = (struct drm_panel *)data;
420 
421 	drm_panel_put(panel);
422 }
423 
424 void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offset,
425 			     const struct drm_panel_funcs *funcs,
426 			     int connector_type)
427 {
428 	void *container;
429 	struct drm_panel *panel;
430 	int err;
431 
432 	if (!funcs) {
433 		dev_warn(dev, "Missing funcs pointer\n");
434 		return ERR_PTR(-EINVAL);
435 	}
436 
437 	container = kzalloc(size, GFP_KERNEL);
438 	if (!container)
439 		return ERR_PTR(-ENOMEM);
440 
441 	panel = container + offset;
442 	panel->container = container;
443 	panel->funcs = funcs;
444 	kref_init(&panel->refcount);
445 
446 	err = devm_add_action_or_reset(dev, drm_panel_put_void, panel);
447 	if (err)
448 		return ERR_PTR(err);
449 
450 	drm_panel_init(panel, dev, funcs, connector_type);
451 
452 	return container;
453 }
454 EXPORT_SYMBOL(__devm_drm_panel_alloc);
455 
456 #ifdef CONFIG_OF
457 /**
458  * of_drm_find_panel - look up a panel using a device tree node
459  * @np: device tree node of the panel
460  *
461  * Searches the set of registered panels for one that matches the given device
462  * tree node. If a matching panel is found, return a pointer to it.
463  *
464  * Return: A pointer to the panel registered for the specified device tree
465  * node or an ERR_PTR() if no panel matching the device tree node can be found.
466  *
467  * Possible error codes returned by this function:
468  *
469  * - EPROBE_DEFER: the panel device has not been probed yet, and the caller
470  *   should retry later
471  * - ENODEV: the device is not available (status != "okay" or "ok")
472  */
473 struct drm_panel *of_drm_find_panel(const struct device_node *np)
474 {
475 	struct drm_panel *panel;
476 
477 	if (!of_device_is_available(np))
478 		return ERR_PTR(-ENODEV);
479 
480 	mutex_lock(&panel_lock);
481 
482 	list_for_each_entry(panel, &panel_list, list) {
483 		if (panel->dev->of_node == np) {
484 			mutex_unlock(&panel_lock);
485 			return panel;
486 		}
487 	}
488 
489 	mutex_unlock(&panel_lock);
490 	return ERR_PTR(-EPROBE_DEFER);
491 }
492 EXPORT_SYMBOL(of_drm_find_panel);
493 
494 /**
495  * of_drm_get_panel_orientation - look up the orientation of the panel through
496  * the "rotation" binding from a device tree node
497  * @np: device tree node of the panel
498  * @orientation: orientation enum to be filled in
499  *
500  * Looks up the rotation of a panel in the device tree. The orientation of the
501  * panel is expressed as a property name "rotation" in the device tree. The
502  * rotation in the device tree is counter clockwise.
503  *
504  * Return: 0 when a valid rotation value (0, 90, 180, or 270) is read or the
505  * rotation property doesn't exist. Return a negative error code on failure.
506  */
507 int of_drm_get_panel_orientation(const struct device_node *np,
508 				 enum drm_panel_orientation *orientation)
509 {
510 	int rotation, ret;
511 
512 	ret = of_property_read_u32(np, "rotation", &rotation);
513 	if (ret == -EINVAL) {
514 		/* Don't return an error if there's no rotation property. */
515 		*orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
516 		return 0;
517 	}
518 
519 	if (ret < 0)
520 		return ret;
521 
522 	if (rotation == 0)
523 		*orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL;
524 	else if (rotation == 90)
525 		*orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP;
526 	else if (rotation == 180)
527 		*orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
528 	else if (rotation == 270)
529 		*orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP;
530 	else
531 		return -EINVAL;
532 
533 	return 0;
534 }
535 EXPORT_SYMBOL(of_drm_get_panel_orientation);
536 #endif
537 
538 /* Find panel by fwnode. This should be identical to of_drm_find_panel(). */
539 static struct drm_panel *find_panel_by_fwnode(const struct fwnode_handle *fwnode)
540 {
541 	struct drm_panel *panel;
542 
543 	if (!fwnode_device_is_available(fwnode))
544 		return ERR_PTR(-ENODEV);
545 
546 	mutex_lock(&panel_lock);
547 
548 	list_for_each_entry(panel, &panel_list, list) {
549 		if (dev_fwnode(panel->dev) == fwnode) {
550 			mutex_unlock(&panel_lock);
551 			return panel;
552 		}
553 	}
554 
555 	mutex_unlock(&panel_lock);
556 
557 	return ERR_PTR(-EPROBE_DEFER);
558 }
559 
560 /* Find panel by follower device */
561 static struct drm_panel *find_panel_by_dev(struct device *follower_dev)
562 {
563 	struct fwnode_handle *fwnode;
564 	struct drm_panel *panel;
565 
566 	fwnode = fwnode_find_reference(dev_fwnode(follower_dev), "panel", 0);
567 	if (IS_ERR(fwnode))
568 		return ERR_PTR(-ENODEV);
569 
570 	panel = find_panel_by_fwnode(fwnode);
571 	fwnode_handle_put(fwnode);
572 
573 	return panel;
574 }
575 
576 /**
577  * drm_is_panel_follower() - Check if the device is a panel follower
578  * @dev: The 'struct device' to check
579  *
580  * This checks to see if a device needs to be power sequenced together with
581  * a panel using the panel follower API.
582  *
583  * The "panel" property of the follower points to the panel to be followed.
584  *
585  * Return: true if we should be power sequenced with a panel; false otherwise.
586  */
587 bool drm_is_panel_follower(struct device *dev)
588 {
589 	/*
590 	 * The "panel" property is actually a phandle, but for simplicity we
591 	 * don't bother trying to parse it here. We just need to know if the
592 	 * property is there.
593 	 */
594 	return device_property_present(dev, "panel");
595 }
596 EXPORT_SYMBOL(drm_is_panel_follower);
597 
598 /**
599  * drm_panel_add_follower() - Register something to follow panel state.
600  * @follower_dev: The 'struct device' for the follower.
601  * @follower:     The panel follower descriptor for the follower.
602  *
603  * A panel follower is called right after preparing/enabling the panel and right
604  * before unpreparing/disabling the panel. It's primary intention is to power on
605  * an associated touchscreen, though it could be used for any similar devices.
606  * Multiple devices are allowed the follow the same panel.
607  *
608  * If a follower is added to a panel that's already been prepared/enabled, the
609  * follower's prepared/enabled callback is called right away.
610  *
611  * The "panel" property of the follower points to the panel to be followed.
612  *
613  * Return: 0 or an error code. Note that -ENODEV means that we detected that
614  *         follower_dev is not actually following a panel. The caller may
615  *         choose to ignore this return value if following a panel is optional.
616  */
617 int drm_panel_add_follower(struct device *follower_dev,
618 			   struct drm_panel_follower *follower)
619 {
620 	struct drm_panel *panel;
621 	int ret;
622 
623 	panel = find_panel_by_dev(follower_dev);
624 	if (IS_ERR(panel))
625 		return PTR_ERR(panel);
626 
627 	get_device(panel->dev);
628 	follower->panel = panel;
629 
630 	mutex_lock(&panel->follower_lock);
631 
632 	list_add_tail(&follower->list, &panel->followers);
633 	if (panel->prepared && follower->funcs->panel_prepared) {
634 		ret = follower->funcs->panel_prepared(follower);
635 		if (ret < 0)
636 			dev_info(panel->dev, "%ps failed: %d\n",
637 				 follower->funcs->panel_prepared, ret);
638 	}
639 	if (panel->enabled && follower->funcs->panel_enabled) {
640 		ret = follower->funcs->panel_enabled(follower);
641 		if (ret < 0)
642 			dev_info(panel->dev, "%ps failed: %d\n",
643 				 follower->funcs->panel_enabled, ret);
644 	}
645 
646 	mutex_unlock(&panel->follower_lock);
647 
648 	return 0;
649 }
650 EXPORT_SYMBOL(drm_panel_add_follower);
651 
652 /**
653  * drm_panel_remove_follower() - Reverse drm_panel_add_follower().
654  * @follower:     The panel follower descriptor for the follower.
655  *
656  * Undo drm_panel_add_follower(). This includes calling the follower's
657  * unpreparing/disabling function if we're removed from a panel that's currently
658  * prepared/enabled.
659  *
660  * Return: 0 or an error code.
661  */
662 void drm_panel_remove_follower(struct drm_panel_follower *follower)
663 {
664 	struct drm_panel *panel = follower->panel;
665 	int ret;
666 
667 	mutex_lock(&panel->follower_lock);
668 
669 	if (panel->enabled && follower->funcs->panel_disabling) {
670 		ret = follower->funcs->panel_disabling(follower);
671 		if (ret < 0)
672 			dev_info(panel->dev, "%ps failed: %d\n",
673 				 follower->funcs->panel_disabling, ret);
674 	}
675 	if (panel->prepared && follower->funcs->panel_unpreparing) {
676 		ret = follower->funcs->panel_unpreparing(follower);
677 		if (ret < 0)
678 			dev_info(panel->dev, "%ps failed: %d\n",
679 				 follower->funcs->panel_unpreparing, ret);
680 	}
681 	list_del_init(&follower->list);
682 
683 	mutex_unlock(&panel->follower_lock);
684 
685 	put_device(panel->dev);
686 }
687 EXPORT_SYMBOL(drm_panel_remove_follower);
688 
689 static void drm_panel_remove_follower_void(void *follower)
690 {
691 	drm_panel_remove_follower(follower);
692 }
693 
694 /**
695  * devm_drm_panel_add_follower() - devm version of drm_panel_add_follower()
696  * @follower_dev: The 'struct device' for the follower.
697  * @follower:     The panel follower descriptor for the follower.
698  *
699  * Handles calling drm_panel_remove_follower() using devm on the follower_dev.
700  *
701  * Return: 0 or an error code.
702  */
703 int devm_drm_panel_add_follower(struct device *follower_dev,
704 				struct drm_panel_follower *follower)
705 {
706 	int ret;
707 
708 	ret = drm_panel_add_follower(follower_dev, follower);
709 	if (ret)
710 		return ret;
711 
712 	return devm_add_action_or_reset(follower_dev,
713 					drm_panel_remove_follower_void, follower);
714 }
715 EXPORT_SYMBOL(devm_drm_panel_add_follower);
716 
717 #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
718 /**
719  * drm_panel_of_backlight - use backlight device node for backlight
720  * @panel: DRM panel
721  *
722  * Use this function to enable backlight handling if your panel
723  * uses device tree and has a backlight phandle.
724  *
725  * When the panel is enabled backlight will be enabled after a
726  * successful call to &drm_panel_funcs.enable()
727  *
728  * When the panel is disabled backlight will be disabled before the
729  * call to &drm_panel_funcs.disable().
730  *
731  * A typical implementation for a panel driver supporting device tree
732  * will call this function at probe time. Backlight will then be handled
733  * transparently without requiring any intervention from the driver.
734  *
735  * Return: 0 on success or a negative error code on failure.
736  */
737 int drm_panel_of_backlight(struct drm_panel *panel)
738 {
739 	struct backlight_device *backlight;
740 
741 	if (!panel || !panel->dev)
742 		return -EINVAL;
743 
744 	backlight = devm_of_find_backlight(panel->dev);
745 
746 	if (IS_ERR(backlight))
747 		return PTR_ERR(backlight);
748 
749 	panel->backlight = backlight;
750 	return 0;
751 }
752 EXPORT_SYMBOL(drm_panel_of_backlight);
753 #endif
754 
755 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
756 MODULE_DESCRIPTION("DRM panel infrastructure");
757 MODULE_LICENSE("GPL and additional rights");
758