blob: 2551eaa14c42537fb8ed38464b68eb42b0259b85 [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030027#include <linux/module.h>
28#include <linux/platform_device.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030029#include <linux/jiffies.h>
30
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030031#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030032
33#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053034#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030035
36static int num_managers;
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020037static struct omap_overlay_manager *managers;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030038
Tomi Valkeineneed07e02009-08-07 13:43:20 +030039int dss_init_overlay_managers(struct platform_device *pdev)
40{
41 int i, r;
42
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020043 num_managers = dss_feat_get_num_mgrs();
Tomi Valkeineneed07e02009-08-07 13:43:20 +030044
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020045 managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
46 GFP_KERNEL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030047
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020048 BUG_ON(managers == NULL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030049
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020050 for (i = 0; i < num_managers; ++i) {
51 struct omap_overlay_manager *mgr = &managers[i];
Tomi Valkeineneed07e02009-08-07 13:43:20 +030052
53 switch (i) {
54 case 0:
55 mgr->name = "lcd";
56 mgr->id = OMAP_DSS_CHANNEL_LCD;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030057 break;
58 case 1:
59 mgr->name = "tv";
60 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030061 break;
Sumit Semwal18faa1b2010-12-02 11:27:14 +000062 case 2:
63 mgr->name = "lcd2";
64 mgr->id = OMAP_DSS_CHANNEL_LCD2;
65 break;
Chandrabhanu Mahapatrae86d4562012-06-29 10:43:13 +053066 case 3:
67 mgr->name = "lcd3";
68 mgr->id = OMAP_DSS_CHANNEL_LCD3;
69 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030070 }
71
Tomi Valkeinen4a9e78a2011-08-15 11:22:21 +030072 mgr->caps = 0;
Archit Tanejaa0acb552010-09-15 19:20:00 +053073 mgr->supported_displays =
74 dss_feat_get_supported_displays(mgr->id);
Archit Taneja97f01b32012-09-26 16:42:39 +053075 mgr->supported_outputs =
76 dss_feat_get_supported_outputs(mgr->id);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030077
Tomi Valkeinen07e327c2011-11-05 10:59:59 +020078 INIT_LIST_HEAD(&mgr->overlays);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030079
Tomi Valkeinenf6a04922012-08-06 14:44:09 +030080 r = dss_manager_kobj_init(mgr, pdev);
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020081 if (r)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030082 DSSERR("failed to create sysfs file\n");
Tomi Valkeineneed07e02009-08-07 13:43:20 +030083 }
84
Tomi Valkeineneed07e02009-08-07 13:43:20 +030085 return 0;
86}
87
88void dss_uninit_overlay_managers(struct platform_device *pdev)
89{
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020090 int i;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030091
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020092 for (i = 0; i < num_managers; ++i) {
93 struct omap_overlay_manager *mgr = &managers[i];
Tomi Valkeinenf6a04922012-08-06 14:44:09 +030094 dss_manager_kobj_uninit(mgr);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030095 }
96
Tomi Valkeinen5617ad092011-11-05 10:44:48 +020097 kfree(managers);
98 managers = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030099 num_managers = 0;
100}
101
102int omap_dss_get_num_overlay_managers(void)
103{
104 return num_managers;
105}
106EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
107
108struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
109{
Tomi Valkeinen5617ad092011-11-05 10:44:48 +0200110 if (num >= num_managers)
111 return NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300112
Tomi Valkeinen5617ad092011-11-05 10:44:48 +0200113 return &managers[num];
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300114}
115EXPORT_SYMBOL(omap_dss_get_overlay_manager);
116
Tomi Valkeinen54540d42011-12-13 13:18:52 +0200117int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
118 const struct omap_overlay_manager_info *info)
119{
120 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
121 /*
122 * OMAP3 supports only graphics source transparency color key
123 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
124 * Alpha Mode.
125 */
126 if (info->partial_alpha_enabled && info->trans_enabled
127 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
128 DSSERR("check_manager: illegal transparency key\n");
129 return -EINVAL;
130 }
131 }
132
133 return 0;
134}
135
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200136static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
137 struct omap_overlay_info **overlay_infos)
138{
139 struct omap_overlay *ovl1, *ovl2;
140 struct omap_overlay_info *info1, *info2;
141
142 list_for_each_entry(ovl1, &mgr->overlays, list) {
143 info1 = overlay_infos[ovl1->id];
144
145 if (info1 == NULL)
146 continue;
147
148 list_for_each_entry(ovl2, &mgr->overlays, list) {
149 if (ovl1 == ovl2)
150 continue;
151
152 info2 = overlay_infos[ovl2->id];
153
154 if (info2 == NULL)
155 continue;
156
157 if (info1->zorder == info2->zorder) {
158 DSSERR("overlays %d and %d have the same "
159 "zorder %d\n",
160 ovl1->id, ovl2->id, info1->zorder);
161 return -EINVAL;
162 }
163 }
164 }
165
166 return 0;
167}
168
Archit Tanejab917fa32012-04-27 01:07:28 +0530169int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
170 const struct omap_video_timings *timings)
171{
172 if (!dispc_mgr_timings_ok(mgr->id, timings)) {
173 DSSERR("check_manager: invalid timings\n");
174 return -EINVAL;
175 }
176
177 return 0;
178}
179
Archit Taneja6e543592012-05-23 17:01:35 +0530180static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
181 const struct dss_lcd_mgr_config *config)
182{
183 struct dispc_clock_info cinfo = config->clock_info;
184 int dl = config->video_port_width;
185 bool stallmode = config->stallmode;
186 bool fifohandcheck = config->fifohandcheck;
187
188 if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
189 return -EINVAL;
190
191 if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
192 return -EINVAL;
193
194 if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
195 return -EINVAL;
196
197 /* fifohandcheck should be used only with stallmode */
198 if (stallmode == false && fifohandcheck == true)
199 return -EINVAL;
200
201 /*
202 * io pad mode can be only checked by using dssdev connected to the
203 * manager. Ignore checking these for now, add checks when manager
204 * is capable of holding information related to the connected interface
205 */
206
207 return 0;
208}
209
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200210int dss_mgr_check(struct omap_overlay_manager *mgr,
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200211 struct omap_overlay_manager_info *info,
Archit Taneja228b2132012-04-27 01:22:28 +0530212 const struct omap_video_timings *mgr_timings,
Archit Taneja6e543592012-05-23 17:01:35 +0530213 const struct dss_lcd_mgr_config *lcd_config,
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200214 struct omap_overlay_info **overlay_infos)
215{
216 struct omap_overlay *ovl;
217 int r;
218
219 if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
220 r = dss_mgr_check_zorder(mgr, overlay_infos);
221 if (r)
222 return r;
223 }
224
Archit Taneja228b2132012-04-27 01:22:28 +0530225 r = dss_mgr_check_timings(mgr, mgr_timings);
Archit Tanejab917fa32012-04-27 01:07:28 +0530226 if (r)
227 return r;
228
Archit Taneja6e543592012-05-23 17:01:35 +0530229 r = dss_mgr_check_lcd_config(mgr, lcd_config);
230 if (r)
231 return r;
232
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200233 list_for_each_entry(ovl, &mgr->overlays, list) {
234 struct omap_overlay_info *oi;
235 int r;
236
237 oi = overlay_infos[ovl->id];
238
239 if (oi == NULL)
240 continue;
241
Archit Taneja228b2132012-04-27 01:22:28 +0530242 r = dss_ovl_check(ovl, oi, mgr_timings);
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200243 if (r)
244 return r;
245 }
246
247 return 0;
248}