]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/gpu/drm/drm_panel.c
drm/gma500: add a missed gma_power_end in error path
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / drm_panel.c
CommitLineData
aead40ea
TR
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/err.h>
25#include <linux/module.h>
26
27#include <drm/drm_crtc.h>
28#include <drm/drm_panel.h>
29
30static DEFINE_MUTEX(panel_lock);
31static LIST_HEAD(panel_list);
32
83127f67
TR
33/**
34 * DOC: drm panel
35 *
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.
0aa5eb3a
DV
39 *
40 * For easy integration into drivers using the &drm_bridge infrastructure please
41 * take look at drm_panel_bridge_add() and devm_drm_panel_bridge_add().
83127f67
TR
42 */
43
44/**
45 * drm_panel_init - initialize a panel
46 * @panel: DRM panel
6dbe0c4b
LP
47 * @dev: parent device of the panel
48 * @funcs: panel operations
9a2654c0
LP
49 * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) corresponding to
50 * the panel interface
83127f67 51 *
6dbe0c4b
LP
52 * Initialize the panel structure for subsequent registration with
53 * drm_panel_add().
83127f67 54 */
6dbe0c4b 55void drm_panel_init(struct drm_panel *panel, struct device *dev,
9a2654c0 56 const struct drm_panel_funcs *funcs, int connector_type)
aead40ea
TR
57{
58 INIT_LIST_HEAD(&panel->list);
6dbe0c4b
LP
59 panel->dev = dev;
60 panel->funcs = funcs;
9a2654c0 61 panel->connector_type = connector_type;
aead40ea
TR
62}
63EXPORT_SYMBOL(drm_panel_init);
64
83127f67
TR
65/**
66 * drm_panel_add - add a panel to the global registry
67 * @panel: panel to add
68 *
69 * Add a panel to the global registry so that it can be looked up by display
70 * drivers.
71 *
72 * Return: 0 on success or a negative error code on failure.
73 */
aead40ea
TR
74int 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 return 0;
81}
82EXPORT_SYMBOL(drm_panel_add);
83
83127f67
TR
84/**
85 * drm_panel_remove - remove a panel from the global registry
86 * @panel: DRM panel
87 *
88 * Removes a panel from the global registry.
89 */
aead40ea
TR
90void drm_panel_remove(struct drm_panel *panel)
91{
92 mutex_lock(&panel_lock);
93 list_del_init(&panel->list);
94 mutex_unlock(&panel_lock);
95}
96EXPORT_SYMBOL(drm_panel_remove);
97
83127f67
TR
98/**
99 * drm_panel_attach - attach a panel to a connector
100 * @panel: DRM panel
101 * @connector: DRM connector
102 *
103 * After obtaining a pointer to a DRM panel a display driver calls this
104 * function to attach a panel to a connector.
105 *
106 * An error is returned if the panel is already attached to another connector.
107 *
38992c57
JS
108 * When unloading, the driver should detach from the panel by calling
109 * drm_panel_detach().
110 *
83127f67
TR
111 * Return: 0 on success or a negative error code on failure.
112 */
aead40ea
TR
113int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
114{
115 if (panel->connector)
116 return -EBUSY;
117
118 panel->connector = connector;
119 panel->drm = connector->dev;
120
121 return 0;
122}
123EXPORT_SYMBOL(drm_panel_attach);
124
83127f67
TR
125/**
126 * drm_panel_detach - detach a panel from a connector
127 * @panel: DRM panel
128 *
129 * Detaches a panel from the connector it is attached to. If a panel is not
130 * attached to any connector this is effectively a no-op.
131 *
38992c57
JS
132 * This function should not be called by the panel device itself. It
133 * is only for the drm device that called drm_panel_attach().
83127f67 134 */
e0d409ff 135void drm_panel_detach(struct drm_panel *panel)
aead40ea
TR
136{
137 panel->connector = NULL;
138 panel->drm = NULL;
aead40ea
TR
139}
140EXPORT_SYMBOL(drm_panel_detach);
141
7a833d30
SR
142/**
143 * drm_panel_prepare - power on a panel
144 * @panel: DRM panel
145 *
146 * Calling this function will enable power and deassert any reset signals to
147 * the panel. After this has completed it is possible to communicate with any
148 * integrated circuitry via a command bus.
149 *
150 * Return: 0 on success or a negative error code on failure.
151 */
152int drm_panel_prepare(struct drm_panel *panel)
153{
154 if (panel && panel->funcs && panel->funcs->prepare)
155 return panel->funcs->prepare(panel);
156
157 return panel ? -ENOSYS : -EINVAL;
158}
159EXPORT_SYMBOL(drm_panel_prepare);
160
161/**
162 * drm_panel_unprepare - power off a panel
163 * @panel: DRM panel
164 *
165 * Calling this function will completely power off a panel (assert the panel's
166 * reset, turn off power supplies, ...). After this function has completed, it
167 * is usually no longer possible to communicate with the panel until another
168 * call to drm_panel_prepare().
169 *
170 * Return: 0 on success or a negative error code on failure.
171 */
172int drm_panel_unprepare(struct drm_panel *panel)
173{
174 if (panel && panel->funcs && panel->funcs->unprepare)
175 return panel->funcs->unprepare(panel);
176
177 return panel ? -ENOSYS : -EINVAL;
178}
179EXPORT_SYMBOL(drm_panel_unprepare);
180
181/**
182 * drm_panel_enable - enable a panel
183 * @panel: DRM panel
184 *
185 * Calling this function will cause the panel display drivers to be turned on
186 * and the backlight to be enabled. Content will be visible on screen after
187 * this call completes.
188 *
189 * Return: 0 on success or a negative error code on failure.
190 */
191int drm_panel_enable(struct drm_panel *panel)
192{
193 if (panel && panel->funcs && panel->funcs->enable)
194 return panel->funcs->enable(panel);
195
196 return panel ? -ENOSYS : -EINVAL;
197}
198EXPORT_SYMBOL(drm_panel_enable);
199
200/**
201 * drm_panel_disable - disable a panel
202 * @panel: DRM panel
203 *
204 * This will typically turn off the panel's backlight or disable the display
205 * drivers. For smart panels it should still be possible to communicate with
206 * the integrated circuitry via any command bus after this call.
207 *
208 * Return: 0 on success or a negative error code on failure.
209 */
210int drm_panel_disable(struct drm_panel *panel)
211{
212 if (panel && panel->funcs && panel->funcs->disable)
213 return panel->funcs->disable(panel);
214
215 return panel ? -ENOSYS : -EINVAL;
216}
217EXPORT_SYMBOL(drm_panel_disable);
218
219/**
220 * drm_panel_get_modes - probe the available display modes of a panel
221 * @panel: DRM panel
222 *
223 * The modes probed from the panel are automatically added to the connector
224 * that the panel is attached to.
225 *
226 * Return: The number of modes available from the panel on success or a
227 * negative error code on failure.
228 */
229int drm_panel_get_modes(struct drm_panel *panel)
230{
231 if (panel && panel->funcs && panel->funcs->get_modes)
232 return panel->funcs->get_modes(panel);
233
234 return panel ? -ENOSYS : -EINVAL;
235}
236EXPORT_SYMBOL(drm_panel_get_modes);
237
aead40ea 238#ifdef CONFIG_OF
83127f67
TR
239/**
240 * of_drm_find_panel - look up a panel using a device tree node
241 * @np: device tree node of the panel
242 *
243 * Searches the set of registered panels for one that matches the given device
244 * tree node. If a matching panel is found, return a pointer to it.
245 *
246 * Return: A pointer to the panel registered for the specified device tree
5fa8e4a2 247 * node or an ERR_PTR() if no panel matching the device tree node can be found.
3eb3cd04 248 *
c59eb3cf 249 * Possible error codes returned by this function:
3eb3cd04 250 *
c59eb3cf
BB
251 * - EPROBE_DEFER: the panel device has not been probed yet, and the caller
252 * should retry later
253 * - ENODEV: the device is not available (status != "okay" or "ok")
83127f67 254 */
327bc443 255struct drm_panel *of_drm_find_panel(const struct device_node *np)
aead40ea
TR
256{
257 struct drm_panel *panel;
258
c59eb3cf
BB
259 if (!of_device_is_available(np))
260 return ERR_PTR(-ENODEV);
261
aead40ea
TR
262 mutex_lock(&panel_lock);
263
264 list_for_each_entry(panel, &panel_list, list) {
265 if (panel->dev->of_node == np) {
266 mutex_unlock(&panel_lock);
267 return panel;
268 }
269 }
270
271 mutex_unlock(&panel_lock);
5fa8e4a2 272 return ERR_PTR(-EPROBE_DEFER);
aead40ea
TR
273}
274EXPORT_SYMBOL(of_drm_find_panel);
275#endif
276
277MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
278MODULE_DESCRIPTION("DRM panel infrastructure");
279MODULE_LICENSE("GPL and additional rights");