]> Pileus Git - ~andy/linux/blob - drivers/video/omap2/dss/manager.c
OMAPDSS: alloc dssdevs dynamically
[~andy/linux] / drivers / video / omap2 / dss / manager.c
1 /*
2  * linux/drivers/video/omap2/dss/manager.c
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6  *
7  * Some code and ideas taken from drivers/video/omap/ driver
8  * by Imre Deak.
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License version 2 as published by
12  * the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17  * more details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #define DSS_SUBSYS_NAME "MANAGER"
24
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/jiffies.h>
30
31 #include <video/omapdss.h>
32
33 #include "dss.h"
34 #include "dss_features.h"
35
36 static int num_managers;
37 static struct omap_overlay_manager *managers;
38
39 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
40 {
41         unsigned long timeout = msecs_to_jiffies(500);
42         u32 irq;
43         int r;
44
45         r = dispc_runtime_get();
46         if (r)
47                 return r;
48
49         if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC)
50                 irq = DISPC_IRQ_EVSYNC_ODD;
51         else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI)
52                 irq = DISPC_IRQ_EVSYNC_EVEN;
53         else
54                 irq = dispc_mgr_get_vsync_irq(mgr->id);
55
56         r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
57
58         dispc_runtime_put();
59
60         return r;
61 }
62
63 int dss_init_overlay_managers(struct platform_device *pdev)
64 {
65         int i, r;
66
67         num_managers = dss_feat_get_num_mgrs();
68
69         managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
70                         GFP_KERNEL);
71
72         BUG_ON(managers == NULL);
73
74         for (i = 0; i < num_managers; ++i) {
75                 struct omap_overlay_manager *mgr = &managers[i];
76
77                 switch (i) {
78                 case 0:
79                         mgr->name = "lcd";
80                         mgr->id = OMAP_DSS_CHANNEL_LCD;
81                         break;
82                 case 1:
83                         mgr->name = "tv";
84                         mgr->id = OMAP_DSS_CHANNEL_DIGIT;
85                         break;
86                 case 2:
87                         mgr->name = "lcd2";
88                         mgr->id = OMAP_DSS_CHANNEL_LCD2;
89                         break;
90                 case 3:
91                         mgr->name = "lcd3";
92                         mgr->id = OMAP_DSS_CHANNEL_LCD3;
93                         break;
94                 }
95
96                 mgr->set_device = &dss_mgr_set_device;
97                 mgr->unset_device = &dss_mgr_unset_device;
98                 mgr->apply = &omap_dss_mgr_apply;
99                 mgr->set_manager_info = &dss_mgr_set_info;
100                 mgr->get_manager_info = &dss_mgr_get_info;
101                 mgr->wait_for_go = &dss_mgr_wait_for_go;
102                 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
103
104                 mgr->caps = 0;
105                 mgr->supported_displays =
106                         dss_feat_get_supported_displays(mgr->id);
107
108                 INIT_LIST_HEAD(&mgr->overlays);
109
110                 r = dss_manager_kobj_init(mgr, pdev);
111                 if (r)
112                         DSSERR("failed to create sysfs file\n");
113         }
114
115         return 0;
116 }
117
118 void dss_uninit_overlay_managers(struct platform_device *pdev)
119 {
120         int i;
121
122         for (i = 0; i < num_managers; ++i) {
123                 struct omap_overlay_manager *mgr = &managers[i];
124                 dss_manager_kobj_uninit(mgr);
125         }
126
127         kfree(managers);
128         managers = NULL;
129         num_managers = 0;
130 }
131
132 int omap_dss_get_num_overlay_managers(void)
133 {
134         return num_managers;
135 }
136 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
137
138 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
139 {
140         if (num >= num_managers)
141                 return NULL;
142
143         return &managers[num];
144 }
145 EXPORT_SYMBOL(omap_dss_get_overlay_manager);
146
147 int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
148                 const struct omap_overlay_manager_info *info)
149 {
150         if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
151                 /*
152                  * OMAP3 supports only graphics source transparency color key
153                  * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
154                  * Alpha Mode.
155                  */
156                 if (info->partial_alpha_enabled && info->trans_enabled
157                         && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
158                         DSSERR("check_manager: illegal transparency key\n");
159                         return -EINVAL;
160                 }
161         }
162
163         return 0;
164 }
165
166 static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
167                 struct omap_overlay_info **overlay_infos)
168 {
169         struct omap_overlay *ovl1, *ovl2;
170         struct omap_overlay_info *info1, *info2;
171
172         list_for_each_entry(ovl1, &mgr->overlays, list) {
173                 info1 = overlay_infos[ovl1->id];
174
175                 if (info1 == NULL)
176                         continue;
177
178                 list_for_each_entry(ovl2, &mgr->overlays, list) {
179                         if (ovl1 == ovl2)
180                                 continue;
181
182                         info2 = overlay_infos[ovl2->id];
183
184                         if (info2 == NULL)
185                                 continue;
186
187                         if (info1->zorder == info2->zorder) {
188                                 DSSERR("overlays %d and %d have the same "
189                                                 "zorder %d\n",
190                                         ovl1->id, ovl2->id, info1->zorder);
191                                 return -EINVAL;
192                         }
193                 }
194         }
195
196         return 0;
197 }
198
199 int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
200                 const struct omap_video_timings *timings)
201 {
202         if (!dispc_mgr_timings_ok(mgr->id, timings)) {
203                 DSSERR("check_manager: invalid timings\n");
204                 return -EINVAL;
205         }
206
207         return 0;
208 }
209
210 static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
211                 const struct dss_lcd_mgr_config *config)
212 {
213         struct dispc_clock_info cinfo = config->clock_info;
214         int dl = config->video_port_width;
215         bool stallmode = config->stallmode;
216         bool fifohandcheck = config->fifohandcheck;
217
218         if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
219                 return -EINVAL;
220
221         if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
222                 return -EINVAL;
223
224         if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
225                 return -EINVAL;
226
227         /* fifohandcheck should be used only with stallmode */
228         if (stallmode == false && fifohandcheck == true)
229                 return -EINVAL;
230
231         /*
232          * io pad mode can be only checked by using dssdev connected to the
233          * manager. Ignore checking these for now, add checks when manager
234          * is capable of holding information related to the connected interface
235          */
236
237         return 0;
238 }
239
240 int dss_mgr_check(struct omap_overlay_manager *mgr,
241                 struct omap_overlay_manager_info *info,
242                 const struct omap_video_timings *mgr_timings,
243                 const struct dss_lcd_mgr_config *lcd_config,
244                 struct omap_overlay_info **overlay_infos)
245 {
246         struct omap_overlay *ovl;
247         int r;
248
249         if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
250                 r = dss_mgr_check_zorder(mgr, overlay_infos);
251                 if (r)
252                         return r;
253         }
254
255         r = dss_mgr_check_timings(mgr, mgr_timings);
256         if (r)
257                 return r;
258
259         r = dss_mgr_check_lcd_config(mgr, lcd_config);
260         if (r)
261                 return r;
262
263         list_for_each_entry(ovl, &mgr->overlays, list) {
264                 struct omap_overlay_info *oi;
265                 int r;
266
267                 oi = overlay_infos[ovl->id];
268
269                 if (oi == NULL)
270                         continue;
271
272                 r = dss_ovl_check(ovl, oi, mgr_timings);
273                 if (r)
274                         return r;
275         }
276
277         return 0;
278 }