i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / video / backlight / platform_lcd.c
blobf0bf491ed087a57d86fade373ad326fb6c68300d
1 /* drivers/video/backlight/platform_lcd.c
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Generic platform-device LCD power control interface.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/fb.h>
17 #include <linux/backlight.h>
18 #include <linux/lcd.h>
19 #include <linux/slab.h>
21 #include <video/platform_lcd.h>
23 struct platform_lcd {
24 struct device *us;
25 struct lcd_device *lcd;
26 struct plat_lcd_data *pdata;
28 unsigned int power;
29 unsigned int suspended : 1;
32 static inline struct platform_lcd *to_our_lcd(struct lcd_device *lcd)
34 return lcd_get_data(lcd);
37 static int platform_lcd_get_power(struct lcd_device *lcd)
39 struct platform_lcd *plcd = to_our_lcd(lcd);
41 return plcd->power;
44 static int platform_lcd_set_power(struct lcd_device *lcd, int power)
46 struct platform_lcd *plcd = to_our_lcd(lcd);
47 int lcd_power = 1;
49 if (power == FB_BLANK_POWERDOWN || plcd->suspended)
50 lcd_power = 0;
52 plcd->pdata->set_power(plcd->pdata, lcd_power);
53 plcd->power = power;
55 return 0;
58 static int platform_lcd_match(struct lcd_device *lcd, struct fb_info *info)
60 struct platform_lcd *plcd = to_our_lcd(lcd);
61 struct plat_lcd_data *pdata = plcd->pdata;
63 if (pdata->match_fb)
64 return pdata->match_fb(pdata, info);
66 return plcd->us->parent == info->device;
69 static struct lcd_ops platform_lcd_ops = {
70 .get_power = platform_lcd_get_power,
71 .set_power = platform_lcd_set_power,
72 .check_fb = platform_lcd_match,
75 static int __devinit platform_lcd_probe(struct platform_device *pdev)
77 struct plat_lcd_data *pdata;
78 struct platform_lcd *plcd;
79 struct device *dev = &pdev->dev;
80 int err;
82 pdata = pdev->dev.platform_data;
83 if (!pdata) {
84 dev_err(dev, "no platform data supplied\n");
85 return -EINVAL;
88 plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
89 GFP_KERNEL);
90 if (!plcd) {
91 dev_err(dev, "no memory for state\n");
92 return -ENOMEM;
95 plcd->us = dev;
96 plcd->pdata = pdata;
97 plcd->lcd = lcd_device_register(dev_name(dev), dev,
98 plcd, &platform_lcd_ops);
99 if (IS_ERR(plcd->lcd)) {
100 dev_err(dev, "cannot register lcd device\n");
101 err = PTR_ERR(plcd->lcd);
102 goto err;
105 platform_set_drvdata(pdev, plcd);
106 platform_lcd_set_power(plcd->lcd, FB_BLANK_NORMAL);
108 return 0;
110 err:
111 return err;
114 static int __devexit platform_lcd_remove(struct platform_device *pdev)
116 struct platform_lcd *plcd = platform_get_drvdata(pdev);
118 lcd_device_unregister(plcd->lcd);
120 return 0;
123 #ifdef CONFIG_PM
124 static int platform_lcd_suspend(struct platform_device *pdev, pm_message_t st)
126 struct platform_lcd *plcd = platform_get_drvdata(pdev);
128 plcd->suspended = 1;
129 platform_lcd_set_power(plcd->lcd, plcd->power);
131 return 0;
134 static int platform_lcd_resume(struct platform_device *pdev)
136 struct platform_lcd *plcd = platform_get_drvdata(pdev);
138 plcd->suspended = 0;
139 platform_lcd_set_power(plcd->lcd, plcd->power);
141 return 0;
143 #else
144 #define platform_lcd_suspend NULL
145 #define platform_lcd_resume NULL
146 #endif
148 static struct platform_driver platform_lcd_driver = {
149 .driver = {
150 .name = "platform-lcd",
151 .owner = THIS_MODULE,
153 .probe = platform_lcd_probe,
154 .remove = __devexit_p(platform_lcd_remove),
155 .suspend = platform_lcd_suspend,
156 .resume = platform_lcd_resume,
159 module_platform_driver(platform_lcd_driver);
161 MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
162 MODULE_LICENSE("GPL v2");
163 MODULE_ALIAS("platform:platform-lcd");