blob: b40130400553fcff3cb07256b50d0f2ba43aa958 [file] [log] [blame]
Bryan Wua9a62b62010-11-17 13:34:33 +00001/*
2 * Generic DPI Panels support
3 *
4 * Copyright (C) 2010 Canonical Ltd.
5 * Author: Bryan Wu <bryan.wu@canonical.com>
6 *
Bryan Wuac1427e2010-11-18 09:45:59 +08007 * LCD panel driver for Sharp LQ043T1DG01
8 *
9 * Copyright (C) 2009 Texas Instruments Inc
10 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
11 *
12 * LCD panel driver for Toppoly TDO35S
13 *
14 * Copyright (C) 2009 CompuLab, Ltd.
15 * Author: Mike Rapoport <mike@compulab.co.il>
16 *
Bryan Wua9a62b62010-11-17 13:34:33 +000017 * Copyright (C) 2008 Nokia Corporation
18 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
19 *
20 * This program is free software; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License version 2 as published by
22 * the Free Software Foundation.
23 *
24 * This program is distributed in the hope that it will be useful, but WITHOUT
25 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
27 * more details.
28 *
29 * You should have received a copy of the GNU General Public License along with
30 * this program. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33#include <linux/module.h>
34#include <linux/delay.h>
35#include <linux/slab.h>
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030036#include <video/omapdss.h>
Bryan Wua9a62b62010-11-17 13:34:33 +000037
Tomi Valkeinenf8ae2f02011-05-10 19:48:10 +030038#include <video/omap-panel-generic-dpi.h>
Bryan Wua9a62b62010-11-17 13:34:33 +000039
40struct panel_config {
41 struct omap_video_timings timings;
42
43 int acbi; /* ac-bias pin transitions per interrupt */
44 /* Unit: line clocks */
45 int acb; /* ac-bias pin frequency */
46
47 enum omap_panel_config config;
48
49 int power_on_delay;
50 int power_off_delay;
51
52 /*
53 * Used to match device to panel configuration
54 * when use generic panel driver
55 */
56 const char *name;
57};
58
59/* Panel configurations */
60static struct panel_config generic_dpi_panels[] = {
61 /* Generic Panel */
62 {
63 {
64 .x_res = 640,
65 .y_res = 480,
66
67 .pixel_clock = 23500,
68
69 .hfp = 48,
70 .hsw = 32,
71 .hbp = 80,
72
73 .vfp = 3,
74 .vsw = 4,
75 .vbp = 7,
76 },
77 .acbi = 0x0,
78 .acb = 0x0,
79 .config = OMAP_DSS_LCD_TFT,
80 .power_on_delay = 0,
81 .power_off_delay = 0,
82 .name = "generic",
83 },
84
85 /* Sharp LQ043T1DG01 */
86 {
87 {
88 .x_res = 480,
89 .y_res = 272,
90
91 .pixel_clock = 9000,
92
93 .hsw = 42,
94 .hfp = 3,
95 .hbp = 2,
96
97 .vsw = 11,
98 .vfp = 3,
99 .vbp = 2,
100 },
101 .acbi = 0x0,
102 .acb = 0x0,
103 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
104 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
105 .power_on_delay = 50,
106 .power_off_delay = 100,
107 .name = "sharp_lq",
108 },
109
110 /* Sharp LS037V7DW01 */
111 {
112 {
113 .x_res = 480,
114 .y_res = 640,
115
116 .pixel_clock = 19200,
117
118 .hsw = 2,
119 .hfp = 1,
120 .hbp = 28,
121
122 .vsw = 1,
123 .vfp = 1,
124 .vbp = 1,
125 },
126 .acbi = 0x0,
127 .acb = 0x28,
128 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
129 OMAP_DSS_LCD_IHS,
130 .power_on_delay = 50,
131 .power_off_delay = 100,
132 .name = "sharp_ls",
133 },
134
135 /* Toppoly TDO35S */
136 {
137 {
138 .x_res = 480,
139 .y_res = 640,
140
141 .pixel_clock = 26000,
142
143 .hfp = 104,
144 .hsw = 8,
145 .hbp = 8,
146
147 .vfp = 4,
148 .vsw = 2,
149 .vbp = 2,
150 },
151 .acbi = 0x0,
152 .acb = 0x0,
153 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
154 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC |
155 OMAP_DSS_LCD_ONOFF,
156 .power_on_delay = 0,
157 .power_off_delay = 0,
158 .name = "toppoly_tdo35s",
159 },
Tomi Valkeinen09dc89c2011-02-22 16:39:47 +0200160
161 /* Samsung LTE430WQ-F0C */
162 {
163 {
164 .x_res = 480,
165 .y_res = 272,
166
167 .pixel_clock = 9200,
168
169 .hfp = 8,
170 .hsw = 41,
171 .hbp = 45 - 41,
172
173 .vfp = 4,
174 .vsw = 10,
175 .vbp = 12 - 10,
176 },
177 .acbi = 0x0,
178 .acb = 0x0,
179 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
180 OMAP_DSS_LCD_IHS,
181 .power_on_delay = 0,
182 .power_off_delay = 0,
183 .name = "samsung_lte430wq_f0c",
184 },
Enric Balletbo i Serra50ca19d2011-05-03 09:07:36 +0200185
186 /* Seiko 70WVW1TZ3Z3 */
187 {
188 {
189 .x_res = 800,
190 .y_res = 480,
191
192 .pixel_clock = 33000,
193
194 .hsw = 128,
195 .hfp = 10,
196 .hbp = 10,
197
198 .vsw = 2,
199 .vfp = 4,
200 .vbp = 11,
201 },
202 .acbi = 0x0,
203 .acb = 0x0,
204 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
205 OMAP_DSS_LCD_IHS,
206 .power_on_delay = 0,
207 .power_off_delay = 0,
208 .name = "seiko_70wvw1tz3",
209 },
Enric Balletbo i Serraa0ce4cc2011-05-03 09:07:37 +0200210
211 /* Powertip PH480272T */
212 {
213 {
214 .x_res = 480,
215 .y_res = 272,
216
217 .pixel_clock = 9000,
218
219 .hsw = 40,
220 .hfp = 2,
221 .hbp = 2,
222
223 .vsw = 10,
224 .vfp = 2,
225 .vbp = 2,
226 },
227 .acbi = 0x0,
228 .acb = 0x0,
229 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
230 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IEO,
231 .power_on_delay = 0,
232 .power_off_delay = 0,
233 .name = "powertip_ph480272t",
234 },
Thomas Weber1e497c42011-09-01 15:05:07 +0200235
236 /* Innolux AT070TN83 */
237 {
238 {
239 .x_res = 800,
240 .y_res = 480,
241
242 .pixel_clock = 40000,
243
244 .hsw = 48,
245 .hfp = 1,
246 .hbp = 1,
247
248 .vsw = 3,
249 .vfp = 12,
250 .vbp = 25,
251 },
252 .acbi = 0x0,
253 .acb = 0x28,
254 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
255 OMAP_DSS_LCD_IHS,
256 .power_on_delay = 0,
257 .power_off_delay = 0,
258 .name = "innolux_at070tn83",
259 },
Bryan Wua9a62b62010-11-17 13:34:33 +0000260};
261
262struct panel_drv_data {
263
264 struct omap_dss_device *dssdev;
265
266 struct panel_config *panel_config;
267};
268
269static inline struct panel_generic_dpi_data
270*get_panel_data(const struct omap_dss_device *dssdev)
271{
272 return (struct panel_generic_dpi_data *) dssdev->data;
273}
274
275static int generic_dpi_panel_power_on(struct omap_dss_device *dssdev)
276{
277 int r;
278 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
279 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
280 struct panel_config *panel_config = drv_data->panel_config;
281
282 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
283 return 0;
284
285 r = omapdss_dpi_display_enable(dssdev);
286 if (r)
287 goto err0;
288
289 /* wait couple of vsyncs until enabling the LCD */
290 if (panel_config->power_on_delay)
291 msleep(panel_config->power_on_delay);
292
293 if (panel_data->platform_enable) {
294 r = panel_data->platform_enable(dssdev);
295 if (r)
296 goto err1;
297 }
298
299 return 0;
300err1:
301 omapdss_dpi_display_disable(dssdev);
302err0:
303 return r;
304}
305
306static void generic_dpi_panel_power_off(struct omap_dss_device *dssdev)
307{
308 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
309 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
310 struct panel_config *panel_config = drv_data->panel_config;
311
312 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
313 return;
314
315 if (panel_data->platform_disable)
316 panel_data->platform_disable(dssdev);
317
318 /* wait couple of vsyncs after disabling the LCD */
319 if (panel_config->power_off_delay)
320 msleep(panel_config->power_off_delay);
321
322 omapdss_dpi_display_disable(dssdev);
323}
324
325static int generic_dpi_panel_probe(struct omap_dss_device *dssdev)
326{
327 struct panel_generic_dpi_data *panel_data = get_panel_data(dssdev);
328 struct panel_config *panel_config = NULL;
329 struct panel_drv_data *drv_data = NULL;
330 int i;
331
332 dev_dbg(&dssdev->dev, "probe\n");
333
334 if (!panel_data || !panel_data->name)
335 return -EINVAL;
336
337 for (i = 0; i < ARRAY_SIZE(generic_dpi_panels); i++) {
338 if (strcmp(panel_data->name, generic_dpi_panels[i].name) == 0) {
339 panel_config = &generic_dpi_panels[i];
340 break;
341 }
342 }
343
344 if (!panel_config)
345 return -EINVAL;
346
347 dssdev->panel.config = panel_config->config;
348 dssdev->panel.timings = panel_config->timings;
349 dssdev->panel.acb = panel_config->acb;
350 dssdev->panel.acbi = panel_config->acbi;
351
352 drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
353 if (!drv_data)
354 return -ENOMEM;
355
356 drv_data->dssdev = dssdev;
357 drv_data->panel_config = panel_config;
358
359 dev_set_drvdata(&dssdev->dev, drv_data);
360
361 return 0;
362}
363
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300364static void __exit generic_dpi_panel_remove(struct omap_dss_device *dssdev)
Bryan Wua9a62b62010-11-17 13:34:33 +0000365{
366 struct panel_drv_data *drv_data = dev_get_drvdata(&dssdev->dev);
367
368 dev_dbg(&dssdev->dev, "remove\n");
369
370 kfree(drv_data);
371
372 dev_set_drvdata(&dssdev->dev, NULL);
373}
374
375static int generic_dpi_panel_enable(struct omap_dss_device *dssdev)
376{
377 int r = 0;
378
379 r = generic_dpi_panel_power_on(dssdev);
380 if (r)
381 return r;
382
383 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
384
385 return 0;
386}
387
388static void generic_dpi_panel_disable(struct omap_dss_device *dssdev)
389{
390 generic_dpi_panel_power_off(dssdev);
391
392 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
393}
394
395static int generic_dpi_panel_suspend(struct omap_dss_device *dssdev)
396{
397 generic_dpi_panel_power_off(dssdev);
398
399 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
400
401 return 0;
402}
403
404static int generic_dpi_panel_resume(struct omap_dss_device *dssdev)
405{
406 int r = 0;
407
408 r = generic_dpi_panel_power_on(dssdev);
409 if (r)
410 return r;
411
412 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
413
414 return 0;
415}
416
417static void generic_dpi_panel_set_timings(struct omap_dss_device *dssdev,
418 struct omap_video_timings *timings)
419{
420 dpi_set_timings(dssdev, timings);
421}
422
423static void generic_dpi_panel_get_timings(struct omap_dss_device *dssdev,
424 struct omap_video_timings *timings)
425{
426 *timings = dssdev->panel.timings;
427}
428
429static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev,
430 struct omap_video_timings *timings)
431{
432 return dpi_check_timings(dssdev, timings);
433}
434
435static struct omap_dss_driver dpi_driver = {
436 .probe = generic_dpi_panel_probe,
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300437 .remove = __exit_p(generic_dpi_panel_remove),
Bryan Wua9a62b62010-11-17 13:34:33 +0000438
439 .enable = generic_dpi_panel_enable,
440 .disable = generic_dpi_panel_disable,
441 .suspend = generic_dpi_panel_suspend,
442 .resume = generic_dpi_panel_resume,
443
444 .set_timings = generic_dpi_panel_set_timings,
445 .get_timings = generic_dpi_panel_get_timings,
446 .check_timings = generic_dpi_panel_check_timings,
447
448 .driver = {
449 .name = "generic_dpi_panel",
450 .owner = THIS_MODULE,
451 },
452};
453
454static int __init generic_dpi_panel_drv_init(void)
455{
456 return omap_dss_register_driver(&dpi_driver);
457}
458
459static void __exit generic_dpi_panel_drv_exit(void)
460{
461 omap_dss_unregister_driver(&dpi_driver);
462}
463
464module_init(generic_dpi_panel_drv_init);
465module_exit(generic_dpi_panel_drv_exit);
466MODULE_LICENSE("GPL");