2 * LCD panel driver for Sharp LS037V7DW01
4 * Copyright (C) 2008 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
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.
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
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/>.
20 #include <linux/module.h>
21 #include <linux/delay.h>
22 #include <linux/device.h>
23 #include <linux/backlight.h>
25 #include <linux/err.h>
26 #include <linux/slab.h>
28 #include <video/omapdss.h>
31 struct backlight_device *bl;
34 static struct omap_video_timings sharp_ls_timings = {
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,
55 static int sharp_ls_bl_update_status(struct backlight_device *bl)
57 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
60 if (!dssdev->set_backlight)
63 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
64 bl->props.power == FB_BLANK_UNBLANK)
65 level = bl->props.brightness;
69 return dssdev->set_backlight(dssdev, level);
72 static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
74 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
75 bl->props.power == FB_BLANK_UNBLANK)
76 return bl->props.brightness;
81 static const struct backlight_ops sharp_ls_bl_ops = {
82 .get_brightness = sharp_ls_bl_get_brightness,
83 .update_status = sharp_ls_bl_update_status,
88 static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
90 struct backlight_properties props;
91 struct backlight_device *bl;
92 struct sharp_data *sd;
95 dssdev->panel.timings = sharp_ls_timings;
97 sd = kzalloc(sizeof(*sd), GFP_KERNEL);
101 dev_set_drvdata(&dssdev->dev, sd);
103 memset(&props, 0, sizeof(struct backlight_properties));
104 props.max_brightness = dssdev->max_backlight_level;
105 props.type = BACKLIGHT_RAW;
107 bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
108 &sharp_ls_bl_ops, &props);
116 bl->props.fb_blank = FB_BLANK_UNBLANK;
117 bl->props.power = FB_BLANK_UNBLANK;
118 bl->props.brightness = dssdev->max_backlight_level;
119 r = sharp_ls_bl_update_status(bl);
121 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
126 static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
128 struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
129 struct backlight_device *bl = sd->bl;
131 bl->props.power = FB_BLANK_POWERDOWN;
132 sharp_ls_bl_update_status(bl);
133 backlight_device_unregister(bl);
138 static int sharp_ls_power_on(struct omap_dss_device *dssdev)
142 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
145 r = omapdss_dpi_display_enable(dssdev);
149 /* wait couple of vsyncs until enabling the LCD */
152 if (dssdev->platform_enable) {
153 r = dssdev->platform_enable(dssdev);
160 omapdss_dpi_display_disable(dssdev);
165 static void sharp_ls_power_off(struct omap_dss_device *dssdev)
167 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
170 if (dssdev->platform_disable)
171 dssdev->platform_disable(dssdev);
173 /* wait at least 5 vsyncs after disabling the LCD */
177 omapdss_dpi_display_disable(dssdev);
180 static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
183 r = sharp_ls_power_on(dssdev);
184 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
188 static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
190 sharp_ls_power_off(dssdev);
191 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
194 static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
196 sharp_ls_power_off(dssdev);
197 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
201 static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
204 r = sharp_ls_power_on(dssdev);
205 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
209 static struct omap_dss_driver sharp_ls_driver = {
210 .probe = sharp_ls_panel_probe,
211 .remove = __exit_p(sharp_ls_panel_remove),
213 .enable = sharp_ls_panel_enable,
214 .disable = sharp_ls_panel_disable,
215 .suspend = sharp_ls_panel_suspend,
216 .resume = sharp_ls_panel_resume,
219 .name = "sharp_ls_panel",
220 .owner = THIS_MODULE,
224 static int __init sharp_ls_panel_drv_init(void)
226 return omap_dss_register_driver(&sharp_ls_driver);
229 static void __exit sharp_ls_panel_drv_exit(void)
231 omap_dss_unregister_driver(&sharp_ls_driver);
234 module_init(sharp_ls_panel_drv_init);
235 module_exit(sharp_ls_panel_drv_exit);
236 MODULE_LICENSE("GPL");