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>
30 #include <video/omapdss.h>
32 #include "dss_features.h"
34 void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
37 *xres = dssdev->panel.timings.x_res;
38 *yres = dssdev->panel.timings.y_res;
40 EXPORT_SYMBOL(omapdss_default_get_resolution);
42 int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
44 switch (dssdev->type) {
45 case OMAP_DISPLAY_TYPE_DPI:
46 if (dssdev->phy.dpi.data_lines == 24)
51 case OMAP_DISPLAY_TYPE_DBI:
52 if (dssdev->ctrl.pixel_size == 24)
56 case OMAP_DISPLAY_TYPE_DSI:
57 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
61 case OMAP_DISPLAY_TYPE_VENC:
62 case OMAP_DISPLAY_TYPE_SDI:
63 case OMAP_DISPLAY_TYPE_HDMI:
70 EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
72 void omapdss_default_get_timings(struct omap_dss_device *dssdev,
73 struct omap_video_timings *timings)
75 *timings = dssdev->panel.timings;
77 EXPORT_SYMBOL(omapdss_default_get_timings);
79 int dss_init_device(struct platform_device *pdev,
80 struct omap_dss_device *dssdev)
84 r = display_init_sysfs(pdev, dssdev);
86 omapdss_output_unset_device(dssdev->output);
93 void dss_uninit_device(struct platform_device *pdev,
94 struct omap_dss_device *dssdev)
96 display_uninit_sysfs(pdev, dssdev);
99 static int dss_suspend_device(struct device *dev, void *data)
101 struct omap_dss_device *dssdev = to_dss_device(dev);
103 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
104 dssdev->activate_after_resume = false;
108 dssdev->driver->disable(dssdev);
110 dssdev->activate_after_resume = true;
115 int dss_suspend_all_devices(void)
118 struct bus_type *bus = dss_get_bus();
120 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
122 /* resume all displays that were suspended */
123 dss_resume_all_devices();
130 static int dss_resume_device(struct device *dev, void *data)
133 struct omap_dss_device *dssdev = to_dss_device(dev);
135 if (dssdev->activate_after_resume) {
136 r = dssdev->driver->enable(dssdev);
141 dssdev->activate_after_resume = false;
146 int dss_resume_all_devices(void)
148 struct bus_type *bus = dss_get_bus();
150 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
153 static int dss_disable_device(struct device *dev, void *data)
155 struct omap_dss_device *dssdev = to_dss_device(dev);
157 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
158 dssdev->driver->disable(dssdev);
163 void dss_disable_all_devices(void)
165 struct bus_type *bus = dss_get_bus();
166 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
170 void omap_dss_get_device(struct omap_dss_device *dssdev)
172 get_device(&dssdev->dev);
174 EXPORT_SYMBOL(omap_dss_get_device);
176 void omap_dss_put_device(struct omap_dss_device *dssdev)
178 put_device(&dssdev->dev);
180 EXPORT_SYMBOL(omap_dss_put_device);
182 /* ref count of the found device is incremented. ref count
183 * of from-device is decremented. */
184 struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
187 struct device *dev_start = NULL;
188 struct omap_dss_device *dssdev = NULL;
190 int match(struct device *dev, void *data)
196 dev_start = &from->dev;
197 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
199 dssdev = to_dss_device(dev);
201 put_device(&from->dev);
205 EXPORT_SYMBOL(omap_dss_get_next_device);
207 struct omap_dss_device *omap_dss_find_device(void *data,
208 int (*match)(struct omap_dss_device *dssdev, void *data))
210 struct omap_dss_device *dssdev = NULL;
212 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
213 if (match(dssdev, data))
219 EXPORT_SYMBOL(omap_dss_find_device);
221 int omap_dss_start_device(struct omap_dss_device *dssdev)
223 if (!dssdev->driver) {
224 DSSDBG("no driver\n");
228 if (!try_module_get(dssdev->dev.driver->owner)) {
234 EXPORT_SYMBOL(omap_dss_start_device);
236 void omap_dss_stop_device(struct omap_dss_device *dssdev)
238 module_put(dssdev->dev.driver->owner);
240 EXPORT_SYMBOL(omap_dss_stop_device);