Full support for Ginger Console
[linux-ginger.git] / drivers / video / backlight / platform_lcd.c
blob738694d23889069805a752f1be14ba9b3d102ece
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>
20 #include <video/platform_lcd.h>
22 struct platform_lcd {
23 struct device *us;
24 struct lcd_device *lcd;
25 struct plat_lcd_data *pdata;
27 unsigned int power;
28 unsigned int suspended : 1;
31 static inline struct platform_lcd *to_our_lcd(struct lcd_device *lcd)
33 return lcd_get_data(lcd);
36 static int platform_lcd_get_power(struct lcd_device *lcd)
38 struct platform_lcd *plcd = to_our_lcd(lcd);
40 return plcd->power;
43 static int platform_lcd_set_power(struct lcd_device *lcd, int power)
45 struct platform_lcd *plcd = to_our_lcd(lcd);
46 int lcd_power = 1;
48 if (power == FB_BLANK_POWERDOWN || plcd->suspended)
49 lcd_power = 0;
51 plcd->pdata->set_power(plcd->pdata, lcd_power);
52 plcd->power = power;
54 return 0;
57 static int platform_lcd_match(struct lcd_device *lcd, struct fb_info *info)
59 struct platform_lcd *plcd = to_our_lcd(lcd);
60 struct plat_lcd_data *pdata = plcd->pdata;
62 if (pdata->match_fb)
63 return pdata->match_fb(pdata, info);
65 return plcd->us->parent == info->device;
68 static struct lcd_ops platform_lcd_ops = {
69 .get_power = platform_lcd_get_power,
70 .set_power = platform_lcd_set_power,
71 .check_fb = platform_lcd_match,
74 static int __devinit platform_lcd_probe(struct platform_device *pdev)
76 struct plat_lcd_data *pdata;
77 struct platform_lcd *plcd;
78 struct device *dev = &pdev->dev;
79 int err;
81 pdata = pdev->dev.platform_data;
82 if (!pdata) {
83 dev_err(dev, "no platform data supplied\n");
84 return -EINVAL;
87 plcd = kzalloc(sizeof(struct platform_lcd), GFP_KERNEL);
88 if (!plcd) {
89 dev_err(dev, "no memory for state\n");
90 return -ENOMEM;
93 plcd->us = dev;
94 plcd->pdata = pdata;
95 plcd->lcd = lcd_device_register(dev_name(dev), dev,
96 plcd, &platform_lcd_ops);
97 if (IS_ERR(plcd->lcd)) {
98 dev_err(dev, "cannot register lcd device\n");
99 err = PTR_ERR(plcd->lcd);
100 goto err_mem;
103 platform_set_drvdata(pdev, plcd);
104 platform_lcd_set_power(plcd->lcd, FB_BLANK_NORMAL);
106 return 0;
108 err_mem:
109 kfree(plcd);
110 return err;
113 static int __devexit platform_lcd_remove(struct platform_device *pdev)
115 struct platform_lcd *plcd = platform_get_drvdata(pdev);
117 lcd_device_unregister(plcd->lcd);
118 kfree(plcd);
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 static int __init platform_lcd_init(void)
161 return platform_driver_register(&platform_lcd_driver);
164 static void __exit platform_lcd_cleanup(void)
166 platform_driver_unregister(&platform_lcd_driver);
169 module_init(platform_lcd_init);
170 module_exit(platform_lcd_cleanup);
172 MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
173 MODULE_LICENSE("GPL v2");
174 MODULE_ALIAS("platform:platform-lcd");