1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#define DSS_SUBSYS_NAME "DISPLAY"
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/jiffies.h>
28#include <linux/platform_device.h>
29
30#include <video/omapdss.h>
31#include "dss.h"
32#include "dss_features.h"
33
34void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
35 u16 *xres, u16 *yres)
36{
37 *xres = dssdev->panel.timings.x_res;
38 *yres = dssdev->panel.timings.y_res;
39}
40EXPORT_SYMBOL(omapdss_default_get_resolution);
41
42int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
43{
44 switch (dssdev->type) {
45 case OMAP_DISPLAY_TYPE_DPI:
46 if (dssdev->phy.dpi.data_lines == 24)
47 return 24;
48 else
49 return 16;
50
51 case OMAP_DISPLAY_TYPE_DBI:
52 if (dssdev->ctrl.pixel_size == 24)
53 return 24;
54 else
55 return 16;
56 case OMAP_DISPLAY_TYPE_DSI:
57 if (dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt) > 16)
58 return 24;
59 else
60 return 16;
61 case OMAP_DISPLAY_TYPE_VENC:
62 case OMAP_DISPLAY_TYPE_SDI:
63 case OMAP_DISPLAY_TYPE_HDMI:
64 return 24;
65 default:
66 BUG();
67 return 0;
68 }
69}
70EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
71
72void omapdss_default_get_timings(struct omap_dss_device *dssdev,
73 struct omap_video_timings *timings)
74{
75 *timings = dssdev->panel.timings;
76}
77EXPORT_SYMBOL(omapdss_default_get_timings);
78
79static int dss_suspend_device(struct device *dev, void *data)
80{
81 struct omap_dss_device *dssdev = to_dss_device(dev);
82
83 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
84 dssdev->activate_after_resume = false;
85 return 0;
86 }
87
88 dssdev->driver->disable(dssdev);
89
90 dssdev->activate_after_resume = true;
91
92 return 0;
93}
94
95int dss_suspend_all_devices(void)
96{
97 int r;
98 struct bus_type *bus = dss_get_bus();
99
100 r = bus_for_each_dev(bus, NULL, NULL, dss_suspend_device);
101 if (r) {
102
103 dss_resume_all_devices();
104 return r;
105 }
106
107 return 0;
108}
109
110static int dss_resume_device(struct device *dev, void *data)
111{
112 int r;
113 struct omap_dss_device *dssdev = to_dss_device(dev);
114
115 if (dssdev->activate_after_resume) {
116 r = dssdev->driver->enable(dssdev);
117 if (r)
118 return r;
119 }
120
121 dssdev->activate_after_resume = false;
122
123 return 0;
124}
125
126int dss_resume_all_devices(void)
127{
128 struct bus_type *bus = dss_get_bus();
129
130 return bus_for_each_dev(bus, NULL, NULL, dss_resume_device);
131}
132
133static int dss_disable_device(struct device *dev, void *data)
134{
135 struct omap_dss_device *dssdev = to_dss_device(dev);
136
137 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
138 dssdev->driver->disable(dssdev);
139
140 return 0;
141}
142
143void dss_disable_all_devices(void)
144{
145 struct bus_type *bus = dss_get_bus();
146 bus_for_each_dev(bus, NULL, NULL, dss_disable_device);
147}
148
149
150void omap_dss_get_device(struct omap_dss_device *dssdev)
151{
152 get_device(&dssdev->dev);
153}
154EXPORT_SYMBOL(omap_dss_get_device);
155
156void omap_dss_put_device(struct omap_dss_device *dssdev)
157{
158 put_device(&dssdev->dev);
159}
160EXPORT_SYMBOL(omap_dss_put_device);
161
162
163
164struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from)
165{
166 struct device *dev;
167 struct device *dev_start = NULL;
168 struct omap_dss_device *dssdev = NULL;
169
170 int match(struct device *dev, void *data)
171 {
172 return 1;
173 }
174
175 if (from)
176 dev_start = &from->dev;
177 dev = bus_find_device(dss_get_bus(), dev_start, NULL, match);
178 if (dev)
179 dssdev = to_dss_device(dev);
180 if (from)
181 put_device(&from->dev);
182
183 return dssdev;
184}
185EXPORT_SYMBOL(omap_dss_get_next_device);
186
187struct omap_dss_device *omap_dss_find_device(void *data,
188 int (*match)(struct omap_dss_device *dssdev, void *data))
189{
190 struct omap_dss_device *dssdev = NULL;
191
192 while ((dssdev = omap_dss_get_next_device(dssdev)) != NULL) {
193 if (match(dssdev, data))
194 return dssdev;
195 }
196
197 return NULL;
198}
199EXPORT_SYMBOL(omap_dss_find_device);
200
201int omap_dss_start_device(struct omap_dss_device *dssdev)
202{
203 if (!dssdev->driver) {
204 DSSDBG("no driver\n");
205 return -ENODEV;
206 }
207
208 if (!try_module_get(dssdev->dev.driver->owner)) {
209 return -ENODEV;
210 }
211
212 return 0;
213}
214EXPORT_SYMBOL(omap_dss_start_device);
215
216void omap_dss_stop_device(struct omap_dss_device *dssdev)
217{
218 module_put(dssdev->dev.driver->owner);
219}
220EXPORT_SYMBOL(omap_dss_stop_device);
221
222