drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / drm_panel.c
blob3dfe3c886502d8b9abac5492075aded558f26b3e
1 /*
2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
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:
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.
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.
24 #include <linux/err.h>
25 #include <linux/module.h>
27 #include <drm/drm_crtc.h>
28 #include <drm/drm_panel.h>
30 static DEFINE_MUTEX(panel_lock);
31 static LIST_HEAD(panel_list);
33 /**
34 * DOC: drm panel
36 * The DRM panel helpers allow drivers to register panel objects with a
37 * central registry and provide functions to retrieve those panels in display
38 * drivers.
41 /**
42 * drm_panel_init - initialize a panel
43 * @panel: DRM panel
45 * Sets up internal fields of the panel so that it can subsequently be added
46 * to the registry.
48 void drm_panel_init(struct drm_panel *panel)
50 INIT_LIST_HEAD(&panel->list);
52 EXPORT_SYMBOL(drm_panel_init);
54 /**
55 * drm_panel_add - add a panel to the global registry
56 * @panel: panel to add
58 * Add a panel to the global registry so that it can be looked up by display
59 * drivers.
61 * Return: 0 on success or a negative error code on failure.
63 int drm_panel_add(struct drm_panel *panel)
65 mutex_lock(&panel_lock);
66 list_add_tail(&panel->list, &panel_list);
67 mutex_unlock(&panel_lock);
69 return 0;
71 EXPORT_SYMBOL(drm_panel_add);
73 /**
74 * drm_panel_remove - remove a panel from the global registry
75 * @panel: DRM panel
77 * Removes a panel from the global registry.
79 void drm_panel_remove(struct drm_panel *panel)
81 mutex_lock(&panel_lock);
82 list_del_init(&panel->list);
83 mutex_unlock(&panel_lock);
85 EXPORT_SYMBOL(drm_panel_remove);
87 /**
88 * drm_panel_attach - attach a panel to a connector
89 * @panel: DRM panel
90 * @connector: DRM connector
92 * After obtaining a pointer to a DRM panel a display driver calls this
93 * function to attach a panel to a connector.
95 * An error is returned if the panel is already attached to another connector.
97 * Return: 0 on success or a negative error code on failure.
99 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
101 if (panel->connector)
102 return -EBUSY;
104 panel->connector = connector;
105 panel->drm = connector->dev;
107 return 0;
109 EXPORT_SYMBOL(drm_panel_attach);
112 * drm_panel_detach - detach a panel from a connector
113 * @panel: DRM panel
115 * Detaches a panel from the connector it is attached to. If a panel is not
116 * attached to any connector this is effectively a no-op.
118 * Return: 0 on success or a negative error code on failure.
120 int drm_panel_detach(struct drm_panel *panel)
122 panel->connector = NULL;
123 panel->drm = NULL;
125 return 0;
127 EXPORT_SYMBOL(drm_panel_detach);
129 #ifdef CONFIG_OF
131 * of_drm_find_panel - look up a panel using a device tree node
132 * @np: device tree node of the panel
134 * Searches the set of registered panels for one that matches the given device
135 * tree node. If a matching panel is found, return a pointer to it.
137 * Return: A pointer to the panel registered for the specified device tree
138 * node or NULL if no panel matching the device tree node can be found.
140 struct drm_panel *of_drm_find_panel(struct device_node *np)
142 struct drm_panel *panel;
144 mutex_lock(&panel_lock);
146 list_for_each_entry(panel, &panel_list, list) {
147 if (panel->dev->of_node == np) {
148 mutex_unlock(&panel_lock);
149 return panel;
153 mutex_unlock(&panel_lock);
154 return NULL;
156 EXPORT_SYMBOL(of_drm_find_panel);
157 #endif
159 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
160 MODULE_DESCRIPTION("DRM panel infrastructure");
161 MODULE_LICENSE("GPL and additional rights");