]> Git Repo - linux.git/blob - drivers/gpu/drm/omapdrm/dss/display.c
Merge branch 'parisc-4.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux.git] / drivers / gpu / drm / omapdrm / dss / display.c
1 /*
2  * Copyright (C) 2009 Nokia Corporation
3  * Author: Tomi Valkeinen <[email protected]>
4  *
5  * Some code and ideas taken from drivers/video/omap/ driver
6  * by Imre Deak.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #define DSS_SUBSYS_NAME "DISPLAY"
22
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/jiffies.h>
26 #include <linux/platform_device.h>
27 #include <linux/of.h>
28
29 #include "omapdss.h"
30
31 void omapdss_default_get_timings(struct omap_dss_device *dssdev,
32                                  struct videomode *vm)
33 {
34         *vm = dssdev->panel.vm;
35 }
36 EXPORT_SYMBOL(omapdss_default_get_timings);
37
38 static LIST_HEAD(panel_list);
39 static DEFINE_MUTEX(panel_list_mutex);
40 static int disp_num_counter;
41
42 int omapdss_register_display(struct omap_dss_device *dssdev)
43 {
44         struct omap_dss_driver *drv = dssdev->driver;
45         struct list_head *cur;
46         int id;
47
48         /*
49          * Note: this presumes that all displays either have an DT alias, or
50          * none has.
51          */
52         id = of_alias_get_id(dssdev->dev->of_node, "display");
53         if (id < 0)
54                 id = disp_num_counter++;
55
56         snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
57
58         /* Use 'label' property for name, if it exists */
59         of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
60
61         if (dssdev->name == NULL)
62                 dssdev->name = dssdev->alias;
63
64         if (drv && drv->get_timings == NULL)
65                 drv->get_timings = omapdss_default_get_timings;
66
67         mutex_lock(&panel_list_mutex);
68         list_for_each(cur, &panel_list) {
69                 struct omap_dss_device *ldev = list_entry(cur,
70                                                          struct omap_dss_device,
71                                                          panel_list);
72                 if (strcmp(ldev->alias, dssdev->alias) > 0)
73                         break;
74         }
75         list_add_tail(&dssdev->panel_list, cur);
76         mutex_unlock(&panel_list_mutex);
77         return 0;
78 }
79 EXPORT_SYMBOL(omapdss_register_display);
80
81 void omapdss_unregister_display(struct omap_dss_device *dssdev)
82 {
83         mutex_lock(&panel_list_mutex);
84         list_del(&dssdev->panel_list);
85         mutex_unlock(&panel_list_mutex);
86 }
87 EXPORT_SYMBOL(omapdss_unregister_display);
88
89 bool omapdss_component_is_display(struct device_node *node)
90 {
91         struct omap_dss_device *dssdev;
92         bool found = false;
93
94         mutex_lock(&panel_list_mutex);
95         list_for_each_entry(dssdev, &panel_list, panel_list) {
96                 if (dssdev->dev->of_node == node) {
97                         found = true;
98                         goto out;
99                 }
100         }
101 out:
102         mutex_unlock(&panel_list_mutex);
103         return found;
104 }
105 EXPORT_SYMBOL(omapdss_component_is_display);
106
107 struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
108 {
109         if (!try_module_get(dssdev->owner))
110                 return NULL;
111
112         if (get_device(dssdev->dev) == NULL) {
113                 module_put(dssdev->owner);
114                 return NULL;
115         }
116
117         return dssdev;
118 }
119 EXPORT_SYMBOL(omap_dss_get_device);
120
121 void omap_dss_put_device(struct omap_dss_device *dssdev)
122 {
123         put_device(dssdev->dev);
124         module_put(dssdev->owner);
125 }
126 EXPORT_SYMBOL(omap_dss_put_device);
127
128 /*
129  * ref count of the found device is incremented.
130  * ref count of from-device is decremented.
131  */
132 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
133 {
134         struct list_head *l;
135         struct omap_dss_device *dssdev;
136
137         mutex_lock(&panel_list_mutex);
138
139         if (list_empty(&panel_list)) {
140                 dssdev = NULL;
141                 goto out;
142         }
143
144         if (from == NULL) {
145                 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
146                                 panel_list);
147                 omap_dss_get_device(dssdev);
148                 goto out;
149         }
150
151         omap_dss_put_device(from);
152
153         list_for_each(l, &panel_list) {
154                 dssdev = list_entry(l, struct omap_dss_device, panel_list);
155                 if (dssdev == from) {
156                         if (list_is_last(l, &panel_list)) {
157                                 dssdev = NULL;
158                                 goto out;
159                         }
160
161                         dssdev = list_entry(l->next, struct omap_dss_device,
162                                         panel_list);
163                         omap_dss_get_device(dssdev);
164                         goto out;
165                 }
166         }
167
168         WARN(1, "'from' dssdev not found\n");
169
170         dssdev = NULL;
171 out:
172         mutex_unlock(&panel_list_mutex);
173         return dssdev;
174 }
175 EXPORT_SYMBOL(omap_dss_get_next_device);
This page took 0.042952 seconds and 4 git commands to generate.