2 * linux/drivers/video/omap2/dss/display.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
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.
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
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/>.
23 #define DSS_SUBSYS_NAME "DISPLAY"
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/jiffies.h>
28 #include <linux/platform_device.h>
33 void omapdss_default_get_resolution(struct omap_dss_device
*dssdev
,
36 *xres
= dssdev
->panel
.vm
.hactive
;
37 *yres
= dssdev
->panel
.vm
.vactive
;
39 EXPORT_SYMBOL(omapdss_default_get_resolution
);
41 int omapdss_default_get_recommended_bpp(struct omap_dss_device
*dssdev
)
43 switch (dssdev
->type
) {
44 case OMAP_DISPLAY_TYPE_DPI
:
45 if (dssdev
->phy
.dpi
.data_lines
== 24)
50 case OMAP_DISPLAY_TYPE_DBI
:
51 if (dssdev
->ctrl
.pixel_size
== 24)
55 case OMAP_DISPLAY_TYPE_DSI
:
56 if (dssdev
->panel
.dsi_pix_fmt
== OMAP_DSS_DSI_FMT_RGB565
)
60 case OMAP_DISPLAY_TYPE_VENC
:
61 case OMAP_DISPLAY_TYPE_SDI
:
62 case OMAP_DISPLAY_TYPE_HDMI
:
63 case OMAP_DISPLAY_TYPE_DVI
:
70 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp
);
72 void omapdss_default_get_timings(struct omap_dss_device
*dssdev
,
75 *vm
= dssdev
->panel
.vm
;
77 EXPORT_SYMBOL(omapdss_default_get_timings
);
79 static LIST_HEAD(panel_list
);
80 static DEFINE_MUTEX(panel_list_mutex
);
81 static int disp_num_counter
;
83 int omapdss_register_display(struct omap_dss_device
*dssdev
)
85 struct omap_dss_driver
*drv
= dssdev
->driver
;
89 * Note: this presumes all the displays are either using DT or non-DT,
90 * which normally should be the case. This also presumes that all
91 * displays either have an DT alias, or none has.
94 if (dssdev
->dev
->of_node
) {
95 id
= of_alias_get_id(dssdev
->dev
->of_node
, "display");
98 id
= disp_num_counter
++;
100 id
= disp_num_counter
++;
103 snprintf(dssdev
->alias
, sizeof(dssdev
->alias
), "display%d", id
);
105 /* Use 'label' property for name, if it exists */
106 if (dssdev
->dev
->of_node
)
107 of_property_read_string(dssdev
->dev
->of_node
, "label",
110 if (dssdev
->name
== NULL
)
111 dssdev
->name
= dssdev
->alias
;
113 if (drv
&& drv
->get_resolution
== NULL
)
114 drv
->get_resolution
= omapdss_default_get_resolution
;
115 if (drv
&& drv
->get_recommended_bpp
== NULL
)
116 drv
->get_recommended_bpp
= omapdss_default_get_recommended_bpp
;
117 if (drv
&& drv
->get_timings
== NULL
)
118 drv
->get_timings
= omapdss_default_get_timings
;
120 mutex_lock(&panel_list_mutex
);
121 list_add_tail(&dssdev
->panel_list
, &panel_list
);
122 mutex_unlock(&panel_list_mutex
);
125 EXPORT_SYMBOL(omapdss_register_display
);
127 void omapdss_unregister_display(struct omap_dss_device
*dssdev
)
129 mutex_lock(&panel_list_mutex
);
130 list_del(&dssdev
->panel_list
);
131 mutex_unlock(&panel_list_mutex
);
133 EXPORT_SYMBOL(omapdss_unregister_display
);
135 struct omap_dss_device
*omap_dss_get_device(struct omap_dss_device
*dssdev
)
137 if (!try_module_get(dssdev
->owner
))
140 if (get_device(dssdev
->dev
) == NULL
) {
141 module_put(dssdev
->owner
);
147 EXPORT_SYMBOL(omap_dss_get_device
);
149 void omap_dss_put_device(struct omap_dss_device
*dssdev
)
151 put_device(dssdev
->dev
);
152 module_put(dssdev
->owner
);
154 EXPORT_SYMBOL(omap_dss_put_device
);
157 * ref count of the found device is incremented.
158 * ref count of from-device is decremented.
160 struct omap_dss_device
*omap_dss_get_next_device(struct omap_dss_device
*from
)
163 struct omap_dss_device
*dssdev
;
165 mutex_lock(&panel_list_mutex
);
167 if (list_empty(&panel_list
)) {
173 dssdev
= list_first_entry(&panel_list
, struct omap_dss_device
,
175 omap_dss_get_device(dssdev
);
179 omap_dss_put_device(from
);
181 list_for_each(l
, &panel_list
) {
182 dssdev
= list_entry(l
, struct omap_dss_device
, panel_list
);
183 if (dssdev
== from
) {
184 if (list_is_last(l
, &panel_list
)) {
189 dssdev
= list_entry(l
->next
, struct omap_dss_device
,
191 omap_dss_get_device(dssdev
);
196 WARN(1, "'from' dssdev not found\n");
200 mutex_unlock(&panel_list_mutex
);
203 EXPORT_SYMBOL(omap_dss_get_next_device
);
205 struct omap_dss_device
*omap_dss_find_device(void *data
,
206 int (*match
)(struct omap_dss_device
*dssdev
, void *data
))
208 struct omap_dss_device
*dssdev
= NULL
;
210 while ((dssdev
= omap_dss_get_next_device(dssdev
)) != NULL
) {
211 if (match(dssdev
, data
))
217 EXPORT_SYMBOL(omap_dss_find_device
);