drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / drivers / video / fbdev / omap2 / omapfb / dss / manager.c
blob2c2da35345d02d6a8e40322f0788d22f7ce31ee4
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/drivers/video/omap2/dss/manager.c
5 * Copyright (C) 2009 Nokia Corporation
6 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
8 * Some code and ideas taken from drivers/video/omap/ driver
9 * by Imre Deak.
12 #define DSS_SUBSYS_NAME "MANAGER"
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/jiffies.h>
20 #include <video/omapfb_dss.h>
22 #include "dss.h"
23 #include "dss_features.h"
25 static int num_managers;
26 static struct omap_overlay_manager *managers;
28 int dss_init_overlay_managers(void)
30 int i;
32 num_managers = dss_feat_get_num_mgrs();
34 managers = kcalloc(num_managers, sizeof(struct omap_overlay_manager),
35 GFP_KERNEL);
37 BUG_ON(managers == NULL);
39 for (i = 0; i < num_managers; ++i) {
40 struct omap_overlay_manager *mgr = &managers[i];
42 switch (i) {
43 case 0:
44 mgr->name = "lcd";
45 mgr->id = OMAP_DSS_CHANNEL_LCD;
46 break;
47 case 1:
48 mgr->name = "tv";
49 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
50 break;
51 case 2:
52 mgr->name = "lcd2";
53 mgr->id = OMAP_DSS_CHANNEL_LCD2;
54 break;
55 case 3:
56 mgr->name = "lcd3";
57 mgr->id = OMAP_DSS_CHANNEL_LCD3;
58 break;
61 mgr->supported_displays =
62 dss_feat_get_supported_displays(mgr->id);
63 mgr->supported_outputs =
64 dss_feat_get_supported_outputs(mgr->id);
66 INIT_LIST_HEAD(&mgr->overlays);
69 return 0;
72 int dss_init_overlay_managers_sysfs(struct platform_device *pdev)
74 int i, r;
76 for (i = 0; i < num_managers; ++i) {
77 struct omap_overlay_manager *mgr = &managers[i];
79 r = dss_manager_kobj_init(mgr, pdev);
80 if (r)
81 DSSERR("failed to create sysfs file\n");
84 return 0;
87 void dss_uninit_overlay_managers(void)
89 kfree(managers);
90 managers = NULL;
91 num_managers = 0;
94 void dss_uninit_overlay_managers_sysfs(struct platform_device *pdev)
96 int i;
98 for (i = 0; i < num_managers; ++i) {
99 struct omap_overlay_manager *mgr = &managers[i];
101 dss_manager_kobj_uninit(mgr);
105 int omap_dss_get_num_overlay_managers(void)
107 return num_managers;
109 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
111 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
113 if (num >= num_managers)
114 return NULL;
116 return &managers[num];
118 EXPORT_SYMBOL(omap_dss_get_overlay_manager);
120 int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
121 const struct omap_overlay_manager_info *info)
123 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
125 * OMAP3 supports only graphics source transparency color key
126 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
127 * Alpha Mode.
129 if (info->partial_alpha_enabled && info->trans_enabled
130 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
131 DSSERR("check_manager: illegal transparency key\n");
132 return -EINVAL;
136 return 0;
139 static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
140 struct omap_overlay_info **overlay_infos)
142 struct omap_overlay *ovl1, *ovl2;
143 struct omap_overlay_info *info1, *info2;
145 list_for_each_entry(ovl1, &mgr->overlays, list) {
146 info1 = overlay_infos[ovl1->id];
148 if (info1 == NULL)
149 continue;
151 list_for_each_entry(ovl2, &mgr->overlays, list) {
152 if (ovl1 == ovl2)
153 continue;
155 info2 = overlay_infos[ovl2->id];
157 if (info2 == NULL)
158 continue;
160 if (info1->zorder == info2->zorder) {
161 DSSERR("overlays %d and %d have the same "
162 "zorder %d\n",
163 ovl1->id, ovl2->id, info1->zorder);
164 return -EINVAL;
169 return 0;
172 int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
173 const struct omap_video_timings *timings)
175 if (!dispc_mgr_timings_ok(mgr->id, timings)) {
176 DSSERR("check_manager: invalid timings\n");
177 return -EINVAL;
180 return 0;
183 static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
184 const struct dss_lcd_mgr_config *config)
186 struct dispc_clock_info cinfo = config->clock_info;
187 int dl = config->video_port_width;
188 bool stallmode = config->stallmode;
189 bool fifohandcheck = config->fifohandcheck;
191 if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
192 return -EINVAL;
194 if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
195 return -EINVAL;
197 if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
198 return -EINVAL;
200 /* fifohandcheck should be used only with stallmode */
201 if (!stallmode && fifohandcheck)
202 return -EINVAL;
205 * io pad mode can be only checked by using dssdev connected to the
206 * manager. Ignore checking these for now, add checks when manager
207 * is capable of holding information related to the connected interface
210 return 0;
213 int dss_mgr_check(struct omap_overlay_manager *mgr,
214 struct omap_overlay_manager_info *info,
215 const struct omap_video_timings *mgr_timings,
216 const struct dss_lcd_mgr_config *lcd_config,
217 struct omap_overlay_info **overlay_infos)
219 struct omap_overlay *ovl;
220 int r;
222 if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
223 r = dss_mgr_check_zorder(mgr, overlay_infos);
224 if (r)
225 return r;
228 r = dss_mgr_check_timings(mgr, mgr_timings);
229 if (r)
230 return r;
232 r = dss_mgr_check_lcd_config(mgr, lcd_config);
233 if (r)
234 return r;
236 list_for_each_entry(ovl, &mgr->overlays, list) {
237 struct omap_overlay_info *oi;
238 int r;
240 oi = overlay_infos[ovl->id];
242 if (oi == NULL)
243 continue;
245 r = dss_ovl_check(ovl, oi, mgr_timings);
246 if (r)
247 return r;
250 return 0;