blob: 6b7b43c808e28d6d36be380da750e433c8b16fbe [file] [log] [blame]
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +02001/*
2 * LCD panel driver for Sharp LS037V7DW01
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/device.h>
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020023#include <linux/backlight.h>
24#include <linux/fb.h>
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020025#include <linux/err.h>
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020026#include <linux/slab.h>
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020027
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030028#include <video/omapdss.h>
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020029
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020030struct sharp_data {
31 struct backlight_device *bl;
32};
33
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020034static struct omap_video_timings sharp_ls_timings = {
35 .x_res = 480,
36 .y_res = 640,
37
38 .pixel_clock = 19200,
39
40 .hsw = 2,
41 .hfp = 1,
42 .hbp = 28,
43
44 .vsw = 1,
45 .vfp = 1,
46 .vbp = 1,
Archit Tanejaa8d5e412012-06-25 12:26:38 +053047
48 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
49 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
50 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
51 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
52 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020053};
54
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020055static int sharp_ls_bl_update_status(struct backlight_device *bl)
56{
57 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
58 int level;
59
60 if (!dssdev->set_backlight)
61 return -EINVAL;
62
63 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
64 bl->props.power == FB_BLANK_UNBLANK)
65 level = bl->props.brightness;
66 else
67 level = 0;
68
69 return dssdev->set_backlight(dssdev, level);
70}
71
72static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
73{
74 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
75 bl->props.power == FB_BLANK_UNBLANK)
76 return bl->props.brightness;
77
78 return 0;
79}
80
81static const struct backlight_ops sharp_ls_bl_ops = {
82 .get_brightness = sharp_ls_bl_get_brightness,
83 .update_status = sharp_ls_bl_update_status,
84};
85
86
87
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020088static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
89{
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020090 struct backlight_properties props;
91 struct backlight_device *bl;
92 struct sharp_data *sd;
93 int r;
94
Archit Taneja5ae9eaa2012-06-21 09:41:10 +053095 dssdev->panel.config = OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020096 dssdev->panel.timings = sharp_ls_timings;
97
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020098 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
99 if (!sd)
100 return -ENOMEM;
101
102 dev_set_drvdata(&dssdev->dev, sd);
103
104 memset(&props, 0, sizeof(struct backlight_properties));
105 props.max_brightness = dssdev->max_backlight_level;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700106 props.type = BACKLIGHT_RAW;
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +0200107
108 bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
109 &sharp_ls_bl_ops, &props);
110 if (IS_ERR(bl)) {
111 r = PTR_ERR(bl);
112 kfree(sd);
113 return r;
114 }
115 sd->bl = bl;
116
117 bl->props.fb_blank = FB_BLANK_UNBLANK;
118 bl->props.power = FB_BLANK_UNBLANK;
119 bl->props.brightness = dssdev->max_backlight_level;
120 r = sharp_ls_bl_update_status(bl);
121 if (r < 0)
122 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
123
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200124 return 0;
125}
126
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300127static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200128{
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +0200129 struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
130 struct backlight_device *bl = sd->bl;
131
132 bl->props.power = FB_BLANK_POWERDOWN;
133 sharp_ls_bl_update_status(bl);
134 backlight_device_unregister(bl);
135
136 kfree(sd);
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200137}
138
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200139static int sharp_ls_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200140{
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200141 int r = 0;
142
Stanley.Miao18016e32010-09-03 05:03:48 +0200143 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
144 return 0;
145
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200146 r = omapdss_dpi_display_enable(dssdev);
147 if (r)
148 goto err0;
149
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200150 /* wait couple of vsyncs until enabling the LCD */
151 msleep(50);
152
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200153 if (dssdev->platform_enable) {
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200154 r = dssdev->platform_enable(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200155 if (r)
156 goto err1;
157 }
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200158
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200159 return 0;
160err1:
161 omapdss_dpi_display_disable(dssdev);
162err0:
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200163 return r;
164}
165
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200166static void sharp_ls_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200167{
Stanley.Miao18016e32010-09-03 05:03:48 +0200168 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
169 return;
170
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200171 if (dssdev->platform_disable)
172 dssdev->platform_disable(dssdev);
173
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200174 /* wait at least 5 vsyncs after disabling the LCD */
175
176 msleep(100);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200177
178 omapdss_dpi_display_disable(dssdev);
179}
180
181static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
182{
183 int r;
184 r = sharp_ls_power_on(dssdev);
185 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
186 return r;
187}
188
189static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
190{
191 sharp_ls_power_off(dssdev);
192 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200193}
194
195static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
196{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200197 sharp_ls_power_off(dssdev);
198 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200199 return 0;
200}
201
202static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
203{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200204 int r;
205 r = sharp_ls_power_on(dssdev);
206 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
207 return r;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200208}
209
210static struct omap_dss_driver sharp_ls_driver = {
211 .probe = sharp_ls_panel_probe,
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300212 .remove = __exit_p(sharp_ls_panel_remove),
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200213
214 .enable = sharp_ls_panel_enable,
215 .disable = sharp_ls_panel_disable,
216 .suspend = sharp_ls_panel_suspend,
217 .resume = sharp_ls_panel_resume,
218
219 .driver = {
220 .name = "sharp_ls_panel",
221 .owner = THIS_MODULE,
222 },
223};
224
225static int __init sharp_ls_panel_drv_init(void)
226{
227 return omap_dss_register_driver(&sharp_ls_driver);
228}
229
230static void __exit sharp_ls_panel_drv_exit(void)
231{
232 omap_dss_unregister_driver(&sharp_ls_driver);
233}
234
235module_init(sharp_ls_panel_drv_init);
236module_exit(sharp_ls_panel_drv_exit);
237MODULE_LICENSE("GPL");