ARC: [plat-hsdk]: unify memory apertures configuration
[linux-2.6-microblaze.git] / drivers / gpu / drm / omapdrm / dss / display.c
1 /*
2  * Copyright (C) 2009 Nokia Corporation
3  * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
4  *
5  * Some code and ideas taken from drivers/video/omap/ driver
6  * by Imre Deak.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #define DSS_SUBSYS_NAME "DISPLAY"
22
23 #include <linux/kernel.h>
24 #include <linux/of.h>
25
26 #include <drm/drm_connector.h>
27 #include <drm/drm_modes.h>
28
29 #include "omapdss.h"
30
31 static int disp_num_counter;
32
33 void omapdss_display_init(struct omap_dss_device *dssdev)
34 {
35         int id;
36
37         /*
38          * Note: this presumes that all displays either have an DT alias, or
39          * none has.
40          */
41         id = of_alias_get_id(dssdev->dev->of_node, "display");
42         if (id < 0)
43                 id = disp_num_counter++;
44
45         /* Use 'label' property for name, if it exists */
46         of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
47
48         if (dssdev->name == NULL)
49                 dssdev->name = devm_kasprintf(dssdev->dev, GFP_KERNEL,
50                                               "display%u", id);
51 }
52 EXPORT_SYMBOL_GPL(omapdss_display_init);
53
54 struct omap_dss_device *omapdss_display_get(struct omap_dss_device *output)
55 {
56         while (output->next)
57                 output = output->next;
58
59         return omapdss_device_get(output);
60 }
61 EXPORT_SYMBOL_GPL(omapdss_display_get);
62
63 int omapdss_display_get_modes(struct drm_connector *connector,
64                               const struct videomode *vm)
65 {
66         struct drm_display_mode *mode;
67
68         mode = drm_mode_create(connector->dev);
69         if (!mode)
70                 return 0;
71
72         drm_display_mode_from_videomode(vm, mode);
73
74         mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
75         drm_mode_set_name(mode);
76         drm_mode_probed_add(connector, mode);
77
78         return 1;
79 }
80 EXPORT_SYMBOL_GPL(omapdss_display_get_modes);