blob: 425a5a8dff8bff04753489b38da3515463cd4fc4 [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
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>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030028#include <linux/platform_device.h>
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +030029#include <linux/of.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030030
Peter Ujfalusi32043da2016-05-27 14:40:49 +030031#include "omapdss.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030032#include "dss.h"
Tomi Valkeinen5ed8cf52011-06-21 09:35:36 +030033#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030034
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020035void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
Tomi Valkeineneed07e02009-08-07 13:43:20 +030036 u16 *xres, u16 *yres)
37{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030038 *xres = dssdev->panel.vm.hactive;
39 *yres = dssdev->panel.vm.vactive;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030040}
Tomi Valkeinen96adcec2010-01-11 13:54:33 +020041EXPORT_SYMBOL(omapdss_default_get_resolution);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030042
Tomi Valkeinena2699502010-01-11 14:33:40 +020043int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +030044{
Tomi Valkeineneed07e02009-08-07 13:43:20 +030045 switch (dssdev->type) {
46 case OMAP_DISPLAY_TYPE_DPI:
47 if (dssdev->phy.dpi.data_lines == 24)
48 return 24;
49 else
50 return 16;
51
52 case OMAP_DISPLAY_TYPE_DBI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030053 if (dssdev->ctrl.pixel_size == 24)
54 return 24;
55 else
56 return 16;
Archit Tanejaa3b3cc22011-09-08 18:42:16 +053057 case OMAP_DISPLAY_TYPE_DSI:
58 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
59 return 24;
60 else
61 return 16;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030062 case OMAP_DISPLAY_TYPE_VENC:
63 case OMAP_DISPLAY_TYPE_SDI:
Mythri P Kb1196012011-03-08 17:15:54 +053064 case OMAP_DISPLAY_TYPE_HDMI:
Tomi Valkeinenbc24b8b2013-05-13 13:40:33 +030065 case OMAP_DISPLAY_TYPE_DVI:
Tomi Valkeineneed07e02009-08-07 13:43:20 +030066 return 24;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030067 default:
68 BUG();
Tomi Valkeinenc6eee962012-05-18 11:47:02 +030069 return 0;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030070 }
71}
Tomi Valkeinena2699502010-01-11 14:33:40 +020072EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030073
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020074void omapdss_default_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030075 struct videomode *vm)
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020076{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030077 *vm = dssdev->panel.vm;
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020078}
79EXPORT_SYMBOL(omapdss_default_get_timings);
80
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020081static LIST_HEAD(panel_list);
82static DEFINE_MUTEX(panel_list_mutex);
83static int disp_num_counter;
84
85int omapdss_register_display(struct omap_dss_device *dssdev)
86{
87 struct omap_dss_driver *drv = dssdev->driver;
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030088 int id;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020089
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030090 /*
91 * Note: this presumes all the displays are either using DT or non-DT,
92 * which normally should be the case. This also presumes that all
93 * displays either have an DT alias, or none has.
94 */
95
96 if (dssdev->dev->of_node) {
97 id = of_alias_get_id(dssdev->dev->of_node, "display");
98
99 if (id < 0)
100 id = disp_num_counter++;
101 } else {
102 id = disp_num_counter++;
103 }
104
105 snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200106
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +0300107 /* Use 'label' property for name, if it exists */
108 if (dssdev->dev->of_node)
109 of_property_read_string(dssdev->dev->of_node, "label",
110 &dssdev->name);
111
112 if (dssdev->name == NULL)
113 dssdev->name = dssdev->alias;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +0200114
115 if (drv && drv->get_resolution == NULL)
116 drv->get_resolution = omapdss_default_get_resolution;
117 if (drv && drv->get_recommended_bpp == NULL)
118 drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
119 if (drv && drv->get_timings == NULL)
120 drv->get_timings = omapdss_default_get_timings;
121
122 mutex_lock(&panel_list_mutex);
123 list_add_tail(&dssdev->panel_list, &panel_list);
124 mutex_unlock(&panel_list_mutex);
125 return 0;
126}
127EXPORT_SYMBOL(omapdss_register_display);
128
129void omapdss_unregister_display(struct omap_dss_device *dssdev)
130{
131 mutex_lock(&panel_list_mutex);
132 list_del(&dssdev->panel_list);
133 mutex_unlock(&panel_list_mutex);
134}
135EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300136
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300137struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300138{
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300139 if (!try_module_get(dssdev->owner))
140 return NULL;
141
142 if (get_device(dssdev->dev) == NULL) {
143 module_put(dssdev->owner);
144 return NULL;
145 }
146
147 return dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300148}
149EXPORT_SYMBOL(omap_dss_get_device);
150
151void omap_dss_put_device(struct omap_dss_device *dssdev)
152{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200153 put_device(dssdev->dev);
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300154 module_put(dssdev->owner);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300155}
156EXPORT_SYMBOL(omap_dss_put_device);
157
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200158/*
159 * ref count of the found device is incremented.
160 * ref count of from-device is decremented.
161 */
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300162struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
163{
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200164 struct list_head *l;
165 struct omap_dss_device *dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300166
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200167 mutex_lock(&panel_list_mutex);
168
169 if (list_empty(&panel_list)) {
170 dssdev = NULL;
171 goto out;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300172 }
173
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200174 if (from == NULL) {
175 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
176 panel_list);
177 omap_dss_get_device(dssdev);
178 goto out;
179 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300180
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200181 omap_dss_put_device(from);
182
183 list_for_each(l, &panel_list) {
184 dssdev = list_entry(l, struct omap_dss_device, panel_list);
185 if (dssdev == from) {
186 if (list_is_last(l, &panel_list)) {
187 dssdev = NULL;
188 goto out;
189 }
190
191 dssdev = list_entry(l->next, struct omap_dss_device,
192 panel_list);
193 omap_dss_get_device(dssdev);
194 goto out;
195 }
196 }
197
198 WARN(1, "'from' dssdev not found\n");
199
200 dssdev = NULL;
201out:
202 mutex_unlock(&panel_list_mutex);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300203 return dssdev;
204}
205EXPORT_SYMBOL(omap_dss_get_next_device);
206
207struct omap_dss_device *omap_dss_find_device(void *data,
208 int (*match)(struct omap_dss_device *dssdev, void *data))
209{
210 struct omap_dss_device *dssdev = NULL;
211
212 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
213 if (match(dssdev, data))
214 return dssdev;
215 }
216
217 return NULL;
218}
219EXPORT_SYMBOL(omap_dss_find_device);