linux/drivers/video/omap2/dss/manager.c
<<
>>
Prefs
   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
  36static int num_managers;
  37static struct omap_overlay_manager *managers;
  38
  39static inline struct omap_dss_device *dss_mgr_get_device(struct omap_overlay_manager *mgr)
  40{
  41        return mgr->output ? mgr->output->device : NULL;
  42}
  43
  44static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
  45{
  46        unsigned long timeout = msecs_to_jiffies(500);
  47        struct omap_dss_device *dssdev = mgr->get_device(mgr);
  48        u32 irq;
  49        int r;
  50
  51        r = dispc_runtime_get();
  52        if (r)
  53                return r;
  54
  55        if (dssdev->type == OMAP_DISPLAY_TYPE_VENC)
  56                irq = DISPC_IRQ_EVSYNC_ODD;
  57        else if (dssdev->type == OMAP_DISPLAY_TYPE_HDMI)
  58                irq = DISPC_IRQ_EVSYNC_EVEN;
  59        else
  60                irq = dispc_mgr_get_vsync_irq(mgr->id);
  61
  62        r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
  63
  64        dispc_runtime_put();
  65
  66        return r;
  67}
  68
  69int dss_init_overlay_managers(struct platform_device *pdev)
  70{
  71        int i, r;
  72
  73        num_managers = dss_feat_get_num_mgrs();
  74
  75        managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
  76                        GFP_KERNEL);
  77
  78        BUG_ON(managers == NULL);
  79
  80        for (i = 0; i < num_managers; ++i) {
  81                struct omap_overlay_manager *mgr = &managers[i];
  82
  83                switch (i) {
  84                case 0:
  85                        mgr->name = "lcd";
  86                        mgr->id = OMAP_DSS_CHANNEL_LCD;
  87                        break;
  88                case 1:
  89                        mgr->name = "tv";
  90                        mgr->id = OMAP_DSS_CHANNEL_DIGIT;
  91                        break;
  92                case 2:
  93                        mgr->name = "lcd2";
  94                        mgr->id = OMAP_DSS_CHANNEL_LCD2;
  95                        break;
  96                case 3:
  97                        mgr->name = "lcd3";
  98                        mgr->id = OMAP_DSS_CHANNEL_LCD3;
  99                        break;
 100                }
 101
 102                mgr->set_output = &dss_mgr_set_output;
 103                mgr->unset_output = &dss_mgr_unset_output;
 104                mgr->apply = &omap_dss_mgr_apply;
 105                mgr->set_manager_info = &dss_mgr_set_info;
 106                mgr->get_manager_info = &dss_mgr_get_info;
 107                mgr->wait_for_go = &dss_mgr_wait_for_go;
 108                mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
 109                mgr->get_device = &dss_mgr_get_device;
 110
 111                mgr->caps = 0;
 112                mgr->supported_displays =
 113                        dss_feat_get_supported_displays(mgr->id);
 114                mgr->supported_outputs =
 115                        dss_feat_get_supported_outputs(mgr->id);
 116
 117                INIT_LIST_HEAD(&mgr->overlays);
 118
 119                r = dss_manager_kobj_init(mgr, pdev);
 120                if (r)
 121                        DSSERR("failed to create sysfs file\n");
 122        }
 123
 124        return 0;
 125}
 126
 127void dss_uninit_overlay_managers(struct platform_device *pdev)
 128{
 129        int i;
 130
 131        for (i = 0; i < num_managers; ++i) {
 132                struct omap_overlay_manager *mgr = &managers[i];
 133                dss_manager_kobj_uninit(mgr);
 134        }
 135
 136        kfree(managers);
 137        managers = NULL;
 138        num_managers = 0;
 139}
 140
 141int omap_dss_get_num_overlay_managers(void)
 142{
 143        return num_managers;
 144}
 145EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
 146
 147struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
 148{
 149        if (num >= num_managers)
 150                return NULL;
 151
 152        return &managers[num];
 153}
 154EXPORT_SYMBOL(omap_dss_get_overlay_manager);
 155
 156int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
 157                const struct omap_overlay_manager_info *info)
 158{
 159        if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
 160                /*
 161                 * OMAP3 supports only graphics source transparency color key
 162                 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
 163                 * Alpha Mode.
 164                 */
 165                if (info->partial_alpha_enabled && info->trans_enabled
 166                        && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
 167                        DSSERR("check_manager: illegal transparency key\n");
 168                        return -EINVAL;
 169                }
 170        }
 171
 172        return 0;
 173}
 174
 175static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
 176                struct omap_overlay_info **overlay_infos)
 177{
 178        struct omap_overlay *ovl1, *ovl2;
 179        struct omap_overlay_info *info1, *info2;
 180
 181        list_for_each_entry(ovl1, &mgr->overlays, list) {
 182                info1 = overlay_infos[ovl1->id];
 183
 184                if (info1 == NULL)
 185                        continue;
 186
 187                list_for_each_entry(ovl2, &mgr->overlays, list) {
 188                        if (ovl1 == ovl2)
 189                                continue;
 190
 191                        info2 = overlay_infos[ovl2->id];
 192
 193                        if (info2 == NULL)
 194                                continue;
 195
 196                        if (info1->zorder == info2->zorder) {
 197                                DSSERR("overlays %d and %d have the same "
 198                                                "zorder %d\n",
 199                                        ovl1->id, ovl2->id, info1->zorder);
 200                                return -EINVAL;
 201                        }
 202                }
 203        }
 204
 205        return 0;
 206}
 207
 208int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
 209                const struct omap_video_timings *timings)
 210{
 211        if (!dispc_mgr_timings_ok(mgr->id, timings)) {
 212                DSSERR("check_manager: invalid timings\n");
 213                return -EINVAL;
 214        }
 215
 216        return 0;
 217}
 218
 219static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
 220                const struct dss_lcd_mgr_config *config)
 221{
 222        struct dispc_clock_info cinfo = config->clock_info;
 223        int dl = config->video_port_width;
 224        bool stallmode = config->stallmode;
 225        bool fifohandcheck = config->fifohandcheck;
 226
 227        if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
 228                return -EINVAL;
 229
 230        if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
 231                return -EINVAL;
 232
 233        if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
 234                return -EINVAL;
 235
 236        /* fifohandcheck should be used only with stallmode */
 237        if (stallmode == false && fifohandcheck == true)
 238                return -EINVAL;
 239
 240        /*
 241         * io pad mode can be only checked by using dssdev connected to the
 242         * manager. Ignore checking these for now, add checks when manager
 243         * is capable of holding information related to the connected interface
 244         */
 245
 246        return 0;
 247}
 248
 249int dss_mgr_check(struct omap_overlay_manager *mgr,
 250                struct omap_overlay_manager_info *info,
 251                const struct omap_video_timings *mgr_timings,
 252                const struct dss_lcd_mgr_config *lcd_config,
 253                struct omap_overlay_info **overlay_infos)
 254{
 255        struct omap_overlay *ovl;
 256        int r;
 257
 258        if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
 259                r = dss_mgr_check_zorder(mgr, overlay_infos);
 260                if (r)
 261                        return r;
 262        }
 263
 264        r = dss_mgr_check_timings(mgr, mgr_timings);
 265        if (r)
 266                return r;
 267
 268        r = dss_mgr_check_lcd_config(mgr, lcd_config);
 269        if (r)
 270                return r;
 271
 272        list_for_each_entry(ovl, &mgr->overlays, list) {
 273                struct omap_overlay_info *oi;
 274                int r;
 275
 276                oi = overlay_infos[ovl->id];
 277
 278                if (oi == NULL)
 279                        continue;
 280
 281                r = dss_ovl_check(ovl, oi, mgr_timings);
 282                if (r)
 283                        return r;
 284        }
 285
 286        return 0;
 287}
 288