drm/i915: Update to Linux 4.7.10
[dragonfly.git] / sys / dev / drm / drm_panel.c
blobc6523f0ba45999a2d640cd8377a70e119ea6526e
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/drmP.h>
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_panel.h>
31 static DEFINE_MUTEX(panel_lock);
32 static LINUX_LIST_HEAD(panel_list);
34 /**
35 * DOC: drm panel
37 * The DRM panel helpers allow drivers to register panel objects with a
38 * central registry and provide functions to retrieve those panels in display
39 * drivers.
42 /**
43 * drm_panel_init - initialize a panel
44 * @panel: DRM panel
46 * Sets up internal fields of the panel so that it can subsequently be added
47 * to the registry.
49 void drm_panel_init(struct drm_panel *panel)
51 INIT_LIST_HEAD(&panel->list);
53 EXPORT_SYMBOL(drm_panel_init);
55 /**
56 * drm_panel_add - add a panel to the global registry
57 * @panel: panel to add
59 * Add a panel to the global registry so that it can be looked up by display
60 * drivers.
62 * Return: 0 on success or a negative error code on failure.
64 int drm_panel_add(struct drm_panel *panel)
66 mutex_lock(&panel_lock);
67 list_add_tail(&panel->list, &panel_list);
68 mutex_unlock(&panel_lock);
70 return 0;
72 EXPORT_SYMBOL(drm_panel_add);
74 /**
75 * drm_panel_remove - remove a panel from the global registry
76 * @panel: DRM panel
78 * Removes a panel from the global registry.
80 void drm_panel_remove(struct drm_panel *panel)
82 mutex_lock(&panel_lock);
83 list_del_init(&panel->list);
84 mutex_unlock(&panel_lock);
86 EXPORT_SYMBOL(drm_panel_remove);
88 /**
89 * drm_panel_attach - attach a panel to a connector
90 * @panel: DRM panel
91 * @connector: DRM connector
93 * After obtaining a pointer to a DRM panel a display driver calls this
94 * function to attach a panel to a connector.
96 * An error is returned if the panel is already attached to another connector.
98 * Return: 0 on success or a negative error code on failure.
100 int drm_panel_attach(struct drm_panel *panel, struct drm_connector *connector)
102 if (panel->connector)
103 return -EBUSY;
105 panel->connector = connector;
106 panel->drm = connector->dev;
108 return 0;
110 EXPORT_SYMBOL(drm_panel_attach);
113 * drm_panel_detach - detach a panel from a connector
114 * @panel: DRM panel
116 * Detaches a panel from the connector it is attached to. If a panel is not
117 * attached to any connector this is effectively a no-op.
119 * Return: 0 on success or a negative error code on failure.
121 int drm_panel_detach(struct drm_panel *panel)
123 panel->connector = NULL;
124 panel->drm = NULL;
126 return 0;
128 EXPORT_SYMBOL(drm_panel_detach);
130 #ifdef CONFIG_OF
132 * of_drm_find_panel - look up a panel using a device tree node
133 * @np: device tree node of the panel
135 * Searches the set of registered panels for one that matches the given device
136 * tree node. If a matching panel is found, return a pointer to it.
138 * Return: A pointer to the panel registered for the specified device tree
139 * node or NULL if no panel matching the device tree node can be found.
141 struct drm_panel *of_drm_find_panel(struct device_node *np)
143 struct drm_panel *panel;
145 mutex_lock(&panel_lock);
147 list_for_each_entry(panel, &panel_list, list) {
148 if (panel->dev->of_node == np) {
149 mutex_unlock(&panel_lock);
150 return panel;
154 mutex_unlock(&panel_lock);
155 return NULL;
157 EXPORT_SYMBOL(of_drm_find_panel);
158 #endif
160 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
161 MODULE_DESCRIPTION("DRM panel infrastructure");