blob: ba38b3ad17d6d6c8dc8f3e0f2eb33a301f82d3eb [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,
47};
48
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020049static int sharp_ls_bl_update_status(struct backlight_device *bl)
50{
51 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
52 int level;
53
54 if (!dssdev->set_backlight)
55 return -EINVAL;
56
57 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
58 bl->props.power == FB_BLANK_UNBLANK)
59 level = bl->props.brightness;
60 else
61 level = 0;
62
63 return dssdev->set_backlight(dssdev, level);
64}
65
66static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
67{
68 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
69 bl->props.power == FB_BLANK_UNBLANK)
70 return bl->props.brightness;
71
72 return 0;
73}
74
75static const struct backlight_ops sharp_ls_bl_ops = {
76 .get_brightness = sharp_ls_bl_get_brightness,
77 .update_status = sharp_ls_bl_update_status,
78};
79
80
81
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020082static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
83{
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020084 struct backlight_properties props;
85 struct backlight_device *bl;
86 struct sharp_data *sd;
87 int r;
88
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +020089 dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
90 OMAP_DSS_LCD_IHS;
91 dssdev->panel.acb = 0x28;
92 dssdev->panel.timings = sharp_ls_timings;
93
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +020094 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
95 if (!sd)
96 return -ENOMEM;
97
98 dev_set_drvdata(&dssdev->dev, sd);
99
100 memset(&props, 0, sizeof(struct backlight_properties));
101 props.max_brightness = dssdev->max_backlight_level;
Matthew Garrettbb7ca742011-03-22 16:30:21 -0700102 props.type = BACKLIGHT_RAW;
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +0200103
104 bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
105 &sharp_ls_bl_ops, &props);
106 if (IS_ERR(bl)) {
107 r = PTR_ERR(bl);
108 kfree(sd);
109 return r;
110 }
111 sd->bl = bl;
112
113 bl->props.fb_blank = FB_BLANK_UNBLANK;
114 bl->props.power = FB_BLANK_UNBLANK;
115 bl->props.brightness = dssdev->max_backlight_level;
116 r = sharp_ls_bl_update_status(bl);
117 if (r < 0)
118 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
119
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200120 return 0;
121}
122
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300123static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200124{
Vaibhav Hiremath2b88c5b2010-04-15 16:00:00 +0200125 struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
126 struct backlight_device *bl = sd->bl;
127
128 bl->props.power = FB_BLANK_POWERDOWN;
129 sharp_ls_bl_update_status(bl);
130 backlight_device_unregister(bl);
131
132 kfree(sd);
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200133}
134
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200135static int sharp_ls_power_on(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200136{
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200137 int r = 0;
138
Stanley.Miao18016e32010-09-03 05:03:48 +0200139 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
140 return 0;
141
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200142 r = omapdss_dpi_display_enable(dssdev);
143 if (r)
144 goto err0;
145
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200146 /* wait couple of vsyncs until enabling the LCD */
147 msleep(50);
148
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200149 if (dssdev->platform_enable) {
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200150 r = dssdev->platform_enable(dssdev);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200151 if (r)
152 goto err1;
153 }
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200154
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200155 return 0;
156err1:
157 omapdss_dpi_display_disable(dssdev);
158err0:
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200159 return r;
160}
161
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200162static void sharp_ls_power_off(struct omap_dss_device *dssdev)
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200163{
Stanley.Miao18016e32010-09-03 05:03:48 +0200164 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
165 return;
166
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200167 if (dssdev->platform_disable)
168 dssdev->platform_disable(dssdev);
169
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200170 /* wait at least 5 vsyncs after disabling the LCD */
171
172 msleep(100);
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200173
174 omapdss_dpi_display_disable(dssdev);
175}
176
177static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
178{
179 int r;
180 r = sharp_ls_power_on(dssdev);
181 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
182 return r;
183}
184
185static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
186{
187 sharp_ls_power_off(dssdev);
188 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200189}
190
191static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
192{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200193 sharp_ls_power_off(dssdev);
194 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200195 return 0;
196}
197
198static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
199{
Tomi Valkeinen37ac60e2010-01-12 15:12:07 +0200200 int r;
201 r = sharp_ls_power_on(dssdev);
202 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
203 return r;
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200204}
205
206static struct omap_dss_driver sharp_ls_driver = {
207 .probe = sharp_ls_panel_probe,
Tomi Valkeinen14e4d782011-03-31 12:03:51 +0300208 .remove = __exit_p(sharp_ls_panel_remove),
Tomi Valkeinen3b8f29b2009-12-09 18:19:42 +0200209
210 .enable = sharp_ls_panel_enable,
211 .disable = sharp_ls_panel_disable,
212 .suspend = sharp_ls_panel_suspend,
213 .resume = sharp_ls_panel_resume,
214
215 .driver = {
216 .name = "sharp_ls_panel",
217 .owner = THIS_MODULE,
218 },
219};
220
221static int __init sharp_ls_panel_drv_init(void)
222{
223 return omap_dss_register_driver(&sharp_ls_driver);
224}
225
226static void __exit sharp_ls_panel_drv_exit(void)
227{
228 omap_dss_unregister_driver(&sharp_ls_driver);
229}
230
231module_init(sharp_ls_panel_drv_init);
232module_exit(sharp_ls_panel_drv_exit);
233MODULE_LICENSE("GPL");