backlight: remove use of __devinit
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / video / backlight / platform_lcd.c
CommitLineData
c25826a7
BD
1/* drivers/video/backlight/platform_lcd.c
2 *
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * Generic platform-device LCD power control interface.
7 *
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.
11 *
12*/
13
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>
52e84243 19#include <linux/of.h>
5a0e3ad6 20#include <linux/slab.h>
c25826a7
BD
21
22#include <video/platform_lcd.h>
23
24struct platform_lcd {
25 struct device *us;
26 struct lcd_device *lcd;
27 struct plat_lcd_data *pdata;
28
29 unsigned int power;
30 unsigned int suspended : 1;
31};
32
33static inline struct platform_lcd *to_our_lcd(struct lcd_device *lcd)
34{
35 return lcd_get_data(lcd);
36}
37
38static int platform_lcd_get_power(struct lcd_device *lcd)
39{
40 struct platform_lcd *plcd = to_our_lcd(lcd);
41
42 return plcd->power;
43}
44
45static int platform_lcd_set_power(struct lcd_device *lcd, int power)
46{
47 struct platform_lcd *plcd = to_our_lcd(lcd);
48 int lcd_power = 1;
49
50 if (power == FB_BLANK_POWERDOWN || plcd->suspended)
51 lcd_power = 0;
52
53 plcd->pdata->set_power(plcd->pdata, lcd_power);
54 plcd->power = power;
55
56 return 0;
57}
58
59static int platform_lcd_match(struct lcd_device *lcd, struct fb_info *info)
60{
61 struct platform_lcd *plcd = to_our_lcd(lcd);
62 struct plat_lcd_data *pdata = plcd->pdata;
63
64 if (pdata->match_fb)
65 return pdata->match_fb(pdata, info);
66
67 return plcd->us->parent == info->device;
68}
69
70static struct lcd_ops platform_lcd_ops = {
71 .get_power = platform_lcd_get_power,
72 .set_power = platform_lcd_set_power,
73 .check_fb = platform_lcd_match,
74};
75
1b9e450d 76static int platform_lcd_probe(struct platform_device *pdev)
c25826a7
BD
77{
78 struct plat_lcd_data *pdata;
79 struct platform_lcd *plcd;
80 struct device *dev = &pdev->dev;
81 int err;
82
83 pdata = pdev->dev.platform_data;
84 if (!pdata) {
85 dev_err(dev, "no platform data supplied\n");
86 return -EINVAL;
87 }
88
48e78e8c
MB
89 plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
90 GFP_KERNEL);
c25826a7
BD
91 if (!plcd) {
92 dev_err(dev, "no memory for state\n");
93 return -ENOMEM;
94 }
95
96 plcd->us = dev;
97 plcd->pdata = pdata;
e958d3ac 98 plcd->lcd = lcd_device_register(dev_name(dev), dev,
c25826a7
BD
99 plcd, &platform_lcd_ops);
100 if (IS_ERR(plcd->lcd)) {
101 dev_err(dev, "cannot register lcd device\n");
102 err = PTR_ERR(plcd->lcd);
48e78e8c 103 goto err;
c25826a7
BD
104 }
105
106 platform_set_drvdata(pdev, plcd);
126ed36d
BD
107 platform_lcd_set_power(plcd->lcd, FB_BLANK_NORMAL);
108
c25826a7
BD
109 return 0;
110
48e78e8c 111 err:
c25826a7
BD
112 return err;
113}
114
115static int __devexit platform_lcd_remove(struct platform_device *pdev)
116{
117 struct platform_lcd *plcd = platform_get_drvdata(pdev);
118
119 lcd_device_unregister(plcd->lcd);
c25826a7
BD
120
121 return 0;
122}
123
124#ifdef CONFIG_PM
67a67272 125static int platform_lcd_suspend(struct device *dev)
c25826a7 126{
67a67272 127 struct platform_lcd *plcd = dev_get_drvdata(dev);
c25826a7
BD
128
129 plcd->suspended = 1;
130 platform_lcd_set_power(plcd->lcd, plcd->power);
131
132 return 0;
133}
134
67a67272 135static int platform_lcd_resume(struct device *dev)
c25826a7 136{
67a67272 137 struct platform_lcd *plcd = dev_get_drvdata(dev);
c25826a7
BD
138
139 plcd->suspended = 0;
140 platform_lcd_set_power(plcd->lcd, plcd->power);
141
142 return 0;
143}
67a67272
JH
144
145static SIMPLE_DEV_PM_OPS(platform_lcd_pm_ops, platform_lcd_suspend,
146 platform_lcd_resume);
c25826a7
BD
147#endif
148
52e84243
JH
149#ifdef CONFIG_OF
150static const struct of_device_id platform_lcd_of_match[] = {
151 { .compatible = "platform-lcd" },
152 {},
153};
154MODULE_DEVICE_TABLE(of, platform_lcd_of_match);
155#endif
156
c25826a7
BD
157static struct platform_driver platform_lcd_driver = {
158 .driver = {
159 .name = "platform-lcd",
160 .owner = THIS_MODULE,
67a67272
JH
161#ifdef CONFIG_PM
162 .pm = &platform_lcd_pm_ops,
163#endif
52e84243 164 .of_match_table = of_match_ptr(platform_lcd_of_match),
c25826a7
BD
165 },
166 .probe = platform_lcd_probe,
d1723fa2 167 .remove = platform_lcd_remove,
c25826a7
BD
168};
169
81178e02 170module_platform_driver(platform_lcd_driver);
c25826a7
BD
171
172MODULE_AUTHOR("Ben Dooks <ben-linux@fluff.org>");
173MODULE_LICENSE("GPL v2");
174MODULE_ALIAS("platform:platform-lcd");