blob: 0c9480ba85c09f028b23ecb69a28ba53a29a30f1 [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
Tomi Valkeineneed07e02009-08-07 13:43:20 +03002 * Copyright (C) 2009 Nokia Corporation
3 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.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/module.h>
25#include <linux/jiffies.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030026#include <linux/platform_device.h>
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +030027#include <linux/of.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030028
Peter Ujfalusi32043da2016-05-27 14:40:49 +030029#include "omapdss.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030030
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020031void omapdss_default_get_timings(struct omap_dss_device *dssdev,
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030032 struct videomode *vm)
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020033{
Peter Ujfalusida11bbbb2016-09-22 14:07:04 +030034 *vm = dssdev->panel.vm;
Grazvydas Ignotas4b6430f2012-03-15 20:00:23 +020035}
36EXPORT_SYMBOL(omapdss_default_get_timings);
37
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020038static LIST_HEAD(panel_list);
39static DEFINE_MUTEX(panel_list_mutex);
40static int disp_num_counter;
41
42int omapdss_register_display(struct omap_dss_device *dssdev)
43{
44 struct omap_dss_driver *drv = dssdev->driver;
Peter Ujfalusi389c5762016-08-11 10:20:23 +030045 struct list_head *cur;
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030046 int id;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020047
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030048 /*
Laurent Pinchart1dff2122017-05-07 00:42:26 +030049 * Note: this presumes that all displays either have an DT alias, or
50 * none has.
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030051 */
Laurent Pinchart1dff2122017-05-07 00:42:26 +030052 id = of_alias_get_id(dssdev->dev->of_node, "display");
53 if (id < 0)
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030054 id = disp_num_counter++;
Tomi Valkeinen3e22b352013-08-06 09:50:22 +030055
56 snprintf(dssdev->alias, sizeof(dssdev->alias), "display%d", id);
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020057
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +030058 /* Use 'label' property for name, if it exists */
Laurent Pinchart1dff2122017-05-07 00:42:26 +030059 of_property_read_string(dssdev->dev->of_node, "label", &dssdev->name);
Tomi Valkeinen7f2bcd02013-08-06 09:41:32 +030060
61 if (dssdev->name == NULL)
62 dssdev->name = dssdev->alias;
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020063
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020064 if (drv && drv->get_timings == NULL)
65 drv->get_timings = omapdss_default_get_timings;
66
67 mutex_lock(&panel_list_mutex);
Peter Ujfalusi389c5762016-08-11 10:20:23 +030068 list_for_each(cur, &panel_list) {
69 struct omap_dss_device *ldev = list_entry(cur,
70 struct omap_dss_device,
71 panel_list);
72 if (strcmp(ldev->alias, dssdev->alias) > 0)
73 break;
74 }
75 list_add_tail(&dssdev->panel_list, cur);
Tomi Valkeinen2e7e3dc2012-11-16 15:45:26 +020076 mutex_unlock(&panel_list_mutex);
77 return 0;
78}
79EXPORT_SYMBOL(omapdss_register_display);
80
81void omapdss_unregister_display(struct omap_dss_device *dssdev)
82{
83 mutex_lock(&panel_list_mutex);
84 list_del(&dssdev->panel_list);
85 mutex_unlock(&panel_list_mutex);
86}
87EXPORT_SYMBOL(omapdss_unregister_display);
Tomi Valkeineneed07e02009-08-07 13:43:20 +030088
Peter Ujfalusi7c79e8d2016-05-02 14:55:38 +030089bool omapdss_component_is_display(struct device_node *node)
90{
91 struct omap_dss_device *dssdev;
92 bool found = false;
93
94 mutex_lock(&panel_list_mutex);
95 list_for_each_entry(dssdev, &panel_list, panel_list) {
96 if (dssdev->dev->of_node == node) {
97 found = true;
98 goto out;
99 }
100 }
101out:
102 mutex_unlock(&panel_list_mutex);
103 return found;
104}
105EXPORT_SYMBOL(omapdss_component_is_display);
106
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300107struct omap_dss_device *omap_dss_get_device(struct omap_dss_device *dssdev)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300108{
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300109 if (!try_module_get(dssdev->owner))
110 return NULL;
111
112 if (get_device(dssdev->dev) == NULL) {
113 module_put(dssdev->owner);
114 return NULL;
115 }
116
117 return dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300118}
119EXPORT_SYMBOL(omap_dss_get_device);
120
121void omap_dss_put_device(struct omap_dss_device *dssdev)
122{
Tomi Valkeinenecc8b372013-02-14 14:17:28 +0200123 put_device(dssdev->dev);
Tomi Valkeinend35317a2013-05-03 11:40:54 +0300124 module_put(dssdev->owner);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300125}
126EXPORT_SYMBOL(omap_dss_put_device);
127
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200128/*
129 * ref count of the found device is incremented.
130 * ref count of from-device is decremented.
131 */
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300132struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
133{
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200134 struct list_head *l;
135 struct omap_dss_device *dssdev;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300136
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200137 mutex_lock(&panel_list_mutex);
138
139 if (list_empty(&panel_list)) {
140 dssdev = NULL;
141 goto out;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300142 }
143
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200144 if (from == NULL) {
145 dssdev = list_first_entry(&panel_list, struct omap_dss_device,
146 panel_list);
147 omap_dss_get_device(dssdev);
148 goto out;
149 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300150
Tomi Valkeinen67b23ca2013-03-15 16:33:29 +0200151 omap_dss_put_device(from);
152
153 list_for_each(l, &panel_list) {
154 dssdev = list_entry(l, struct omap_dss_device, panel_list);
155 if (dssdev == from) {
156 if (list_is_last(l, &panel_list)) {
157 dssdev = NULL;
158 goto out;
159 }
160
161 dssdev = list_entry(l->next, struct omap_dss_device,
162 panel_list);
163 omap_dss_get_device(dssdev);
164 goto out;
165 }
166 }
167
168 WARN(1, "'from' dssdev not found\n");
169
170 dssdev = NULL;
171out:
172 mutex_unlock(&panel_list_mutex);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300173 return dssdev;
174}
175EXPORT_SYMBOL(omap_dss_get_next_device);