linux/drivers/video/omap2/dss/display.c
<<
>>
Prefs
   1/*
   2 * linux/drivers/video/omap2/dss/display.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 "DISPLAY"
  24
  25#include <linux/kernel.h>
  26#include <linux/module.h>
  27#include <linux/jiffies.h>
  28#include <linux/platform_device.h>
  29
  30#include <video/omapdss.h>
  31#include "dss.h"
  32#include "dss_features.h"
  33
  34void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
  35                        u16 *xres, u16 *yres)
  36{
  37        *xres = dssdev->panel.timings.x_res;
  38        *yres = dssdev->panel.timings.y_res;
  39}
  40EXPORT_SYMBOL(omapdss_default_get_resolution);
  41
  42int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
  43{
  44        switch (dssdev->type) {
  45        case OMAP_DISPLAY_TYPE_DPI:
  46                if (dssdev->phy.dpi.data_lines == 24)
  47                        return 24;
  48                else
  49                        return 16;
  50
  51        case OMAP_DISPLAY_TYPE_DBI:
  52                if (dssdev->ctrl.pixel_size == 24)
  53                        return 24;
  54                else
  55                        return 16;
  56        case OMAP_DISPLAY_TYPE_DSI:
  57                if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
  58                        return 24;
  59                else
  60                        return 16;
  61        case OMAP_DISPLAY_TYPE_VENC:
  62        case OMAP_DISPLAY_TYPE_SDI:
  63        case OMAP_DISPLAY_TYPE_HDMI:
  64                return 24;
  65        default:
  66                BUG();
  67                return 0;
  68        }
  69}
  70EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
  71
  72void omapdss_default_get_timings(struct omap_dss_device *dssdev,
  73                struct omap_video_timings *timings)
  74{
  75        *timings = dssdev->panel.timings;
  76}
  77EXPORT_SYMBOL(omapdss_default_get_timings);
  78
  79static int dss_suspend_device(struct device *dev, void *data)
  80{
  81        struct omap_dss_device *dssdev = to_dss_device(dev);
  82
  83        if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
  84                dssdev->activate_after_resume = false;
  85                return 0;
  86        }
  87
  88        dssdev->driver->disable(dssdev);
  89
  90        dssdev->activate_after_resume = true;
  91
  92        return 0;
  93}
  94
  95int dss_suspend_all_devices(void)
  96{
  97        int r;
  98        struct bus_type *bus = dss_get_bus();
  99
 100        r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
 101        if (r) {
 102                /* resume all displays that were suspended */
 103                dss_resume_all_devices();
 104                return r;
 105        }
 106
 107        return 0;
 108}
 109
 110static int dss_resume_device(struct device *dev, void *data)
 111{
 112        int r;
 113        struct omap_dss_device *dssdev = to_dss_device(dev);
 114
 115        if (dssdev->activate_after_resume) {
 116                r = dssdev->driver->enable(dssdev);
 117                if (r)
 118                        return r;
 119        }
 120
 121        dssdev->activate_after_resume = false;
 122
 123        return 0;
 124}
 125
 126int dss_resume_all_devices(void)
 127{
 128        struct bus_type *bus = dss_get_bus();
 129
 130        return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
 131}
 132
 133static int dss_disable_device(struct device *dev, void *data)
 134{
 135        struct omap_dss_device *dssdev = to_dss_device(dev);
 136
 137        if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
 138                dssdev->driver->disable(dssdev);
 139
 140        return 0;
 141}
 142
 143void dss_disable_all_devices(void)
 144{
 145        struct bus_type *bus = dss_get_bus();
 146        bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
 147}
 148
 149
 150void omap_dss_get_device(struct omap_dss_device *dssdev)
 151{
 152        get_device(&dssdev->dev);
 153}
 154EXPORT_SYMBOL(omap_dss_get_device);
 155
 156void omap_dss_put_device(struct omap_dss_device *dssdev)
 157{
 158        put_device(&dssdev->dev);
 159}
 160EXPORT_SYMBOL(omap_dss_put_device);
 161
 162/* ref count of the found device is incremented. ref count
 163 * of from-device is decremented. */
 164struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
 165{
 166        struct device *dev;
 167        struct device *dev_start = NULL;
 168        struct omap_dss_device *dssdev = NULL;
 169
 170        int match(struct device *dev, void *data)
 171        {
 172                return 1;
 173        }
 174
 175        if (from)
 176                dev_start = &from->dev;
 177        dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
 178        if (dev)
 179                dssdev = to_dss_device(dev);
 180        if (from)
 181                put_device(&from->dev);
 182
 183        return dssdev;
 184}
 185EXPORT_SYMBOL(omap_dss_get_next_device);
 186
 187struct omap_dss_device *omap_dss_find_device(void *data,
 188                int (*match)(struct omap_dss_device *dssdev, void *data))
 189{
 190        struct omap_dss_device *dssdev = NULL;
 191
 192        while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
 193                if (match(dssdev, data))
 194                        return dssdev;
 195        }
 196
 197        return NULL;
 198}
 199EXPORT_SYMBOL(omap_dss_find_device);
 200
 201int omap_dss_start_device(struct omap_dss_device *dssdev)
 202{
 203        if (!dssdev->driver) {
 204                DSSDBG("no driver\n");
 205                return -ENODEV;
 206        }
 207
 208        if (!try_module_get(dssdev->dev.driver->owner)) {
 209                return -ENODEV;
 210        }
 211
 212        return 0;
 213}
 214EXPORT_SYMBOL(omap_dss_start_device);
 215
 216void omap_dss_stop_device(struct omap_dss_device *dssdev)
 217{
 218        module_put(dssdev->dev.driver->owner);
 219}
 220EXPORT_SYMBOL(omap_dss_stop_device);
 221
 222