2 * drivers/video/backlight/ubicom32lcdpowerpower.c
3 * LCD power driver for the Ubicom32 platform
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/platform_device.h>
32 #include <linux/lcd.h>
34 #include <linux/gpio.h>
36 #include <asm/ubicom32lcdpower.h>
37 #include <asm/ip5000.h>
39 #define DRIVER_NAME "ubicom32lcdpower"
41 struct ubicom32lcdpower_data {
43 * Pointer to the platform data structure. Keep this around since we need values
44 * from it to set the backlight intensity.
46 const struct ubicom32lcdpower_platform_data *pdata;
49 * LCD device, we have to save this for use when we remove ourselves.
51 struct lcd_device *lcddev;
55 * ubicom32lcdpower_set_power
57 static int ubicom32lcdpower_set_power(struct lcd_device *ld, int power)
59 struct ubicom32lcdpower_data *ud = (struct ubicom32lcdpower_data *)lcd_get_data(ld);
60 if (power == FB_BLANK_UNBLANK) {
61 gpio_direction_output(ud->pdata->vgh_gpio, ud->pdata->vgh_polarity);
65 gpio_direction_output(ud->pdata->vgh_gpio, !ud->pdata->vgh_polarity);
70 * ubicom32lcdpower_get_power
72 static int ubicom32lcdpower_get_power(struct lcd_device *ld)
74 struct ubicom32lcdpower_data *ud = (struct ubicom32lcdpower_data *)lcd_get_data(ld);
75 int vgh = gpio_get_value(ud->pdata->vgh_gpio);
76 if ((vgh && ud->pdata->vgh_polarity) || (!vgh && !ud->pdata->vgh_polarity)) {
83 static struct lcd_ops ubicom32lcdpower_ops = {
84 .get_power = ubicom32lcdpower_get_power,
85 .set_power = ubicom32lcdpower_set_power,
89 * ubicom32lcdpower_probe
91 static int ubicom32lcdpower_probe(struct platform_device *pdev)
93 const struct ubicom32lcdpower_platform_data *pdata = pdev->dev.platform_data;
94 struct ubicom32lcdpower_data *ud;
95 struct lcd_device *lcddev;
99 * Check to see if we have any platform data, if we don't have a LCD to control
106 * Allocate our private data
108 ud = kzalloc(sizeof(struct ubicom32lcdpower_data), GFP_KERNEL);
118 retval = gpio_request(pdata->vgh_gpio, "vgh");
120 dev_err(&pdev->dev, "Failed to allocate vgh GPIO\n");
125 * Register our lcd device
127 lcddev = lcd_device_register(DRIVER_NAME, &pdev->dev, ud, &ubicom32lcdpower_ops);
128 if (IS_ERR(lcddev)) {
129 retval = PTR_ERR(lcddev);
134 platform_set_drvdata(pdev, ud);
136 ubicom32lcdpower_set_power(lcddev, FB_BLANK_UNBLANK);
138 printk(KERN_INFO DRIVER_NAME ": LCD driver started\n");
143 gpio_free(pdata->vgh_gpio);
146 platform_set_drvdata(pdev, NULL);
152 * ubicom32lcdpower_remove
154 static int __exit ubicom32lcdpower_remove(struct platform_device *pdev)
156 struct ubicom32lcdpower_data *ud = platform_get_drvdata(pdev);
158 lcd_device_unregister(ud->lcddev);
159 platform_set_drvdata(pdev, NULL);
165 static struct platform_driver ubicom32lcdpower_driver = {
168 .owner = THIS_MODULE,
171 .remove = __exit_p(ubicom32lcdpower_remove),
175 * ubicom32lcdpower_init
177 static int __init ubicom32lcdpower_init(void)
179 return platform_driver_probe(&ubicom32lcdpower_driver, ubicom32lcdpower_probe);
181 module_init(ubicom32lcdpower_init);
184 * ubicom32lcdpower_exit
186 static void __exit ubicom32lcdpower_exit(void)
188 platform_driver_unregister(&ubicom32lcdpower_driver);
190 module_exit(ubicom32lcdpower_exit);
192 MODULE_AUTHOR("Patrick Tjin <@ubicom.com>");
193 MODULE_DESCRIPTION("Ubicom32 lcd power driver");
194 MODULE_LICENSE("GPL");