blob: 4dea91acea138037f29f07423375b06cebf7ab9a [file] [log] [blame]
Richard Purdied00ba722009-01-08 20:52:37 +00001/*
2 * Generic Backlight Driver
3 *
4 * Copyright (c) 2004-2008 Richard Purdie
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/mutex.h>
17#include <linux/fb.h>
18#include <linux/backlight.h>
19
20static int genericbl_intensity;
21static struct backlight_device *generic_backlight_device;
22static struct generic_bl_info *bl_machinfo;
23
Richard Purdied00ba722009-01-08 20:52:37 +000024static int genericbl_send_intensity(struct backlight_device *bd)
25{
26 int intensity = bd->props.brightness;
27
28 if (bd->props.power != FB_BLANK_UNBLANK)
29 intensity = 0;
30 if (bd->props.state & BL_CORE_FBBLANK)
31 intensity = 0;
32 if (bd->props.state & BL_CORE_SUSPENDED)
33 intensity = 0;
Richard Purdied00ba722009-01-08 20:52:37 +000034
35 bl_machinfo->set_bl_intensity(intensity);
36
37 genericbl_intensity = intensity;
38
39 if (bl_machinfo->kick_battery)
40 bl_machinfo->kick_battery();
41
42 return 0;
43}
44
45static int genericbl_get_intensity(struct backlight_device *bd)
46{
47 return genericbl_intensity;
48}
49
Emese Revfy9905a432009-12-14 00:58:57 +010050static const struct backlight_ops genericbl_ops = {
Richard Purdied00ba722009-01-08 20:52:37 +000051 .options = BL_CORE_SUSPENDRESUME,
52 .get_brightness = genericbl_get_intensity,
53 .update_status = genericbl_send_intensity,
54};
55
56static int genericbl_probe(struct platform_device *pdev)
57{
Matthew Garretta19a6ee2010-02-17 16:39:44 -050058 struct backlight_properties props;
Jingoo Hanc512794c2013-11-12 15:09:04 -080059 struct generic_bl_info *machinfo = dev_get_platdata(&pdev->dev);
Richard Purdied00ba722009-01-08 20:52:37 +000060 const char *name = "generic-bl";
61 struct backlight_device *bd;
62
63 bl_machinfo = machinfo;
64 if (!machinfo->limit_mask)
65 machinfo->limit_mask = -1;
66
67 if (machinfo->name)
68 name = machinfo->name;
69
Matthew Garretta19a6ee2010-02-17 16:39:44 -050070 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -070071 props.type = BACKLIGHT_RAW;
Matthew Garretta19a6ee2010-02-17 16:39:44 -050072 props.max_brightness = machinfo->max_intensity;
Jingoo Hande2efd22013-11-12 15:09:15 -080073 bd = devm_backlight_device_register(&pdev->dev, name, &pdev->dev,
74 NULL, &genericbl_ops, &props);
Jingoo Han933bd9b2012-12-17 16:00:17 -080075 if (IS_ERR(bd))
76 return PTR_ERR(bd);
Richard Purdied00ba722009-01-08 20:52:37 +000077
78 platform_set_drvdata(pdev, bd);
79
Richard Purdied00ba722009-01-08 20:52:37 +000080 bd->props.power = FB_BLANK_UNBLANK;
81 bd->props.brightness = machinfo->default_intensity;
82 backlight_update_status(bd);
83
84 generic_backlight_device = bd;
85
Jingoo Han8ab5aa62013-04-29 16:17:33 -070086 dev_info(&pdev->dev, "Generic Backlight Driver Initialized.\n");
Richard Purdied00ba722009-01-08 20:52:37 +000087 return 0;
88}
89
90static int genericbl_remove(struct platform_device *pdev)
91{
92 struct backlight_device *bd = platform_get_drvdata(pdev);
93
94 bd->props.power = 0;
95 bd->props.brightness = 0;
96 backlight_update_status(bd);
97
Jingoo Han8ab5aa62013-04-29 16:17:33 -070098 dev_info(&pdev->dev, "Generic Backlight Driver Unloaded\n");
Richard Purdied00ba722009-01-08 20:52:37 +000099 return 0;
100}
101
102static struct platform_driver genericbl_driver = {
103 .probe = genericbl_probe,
104 .remove = genericbl_remove,
105 .driver = {
106 .name = "generic-bl",
107 },
108};
109
Axel Lin81178e02012-01-10 15:09:11 -0800110module_platform_driver(genericbl_driver);
Richard Purdied00ba722009-01-08 20:52:37 +0000111
112MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
113MODULE_DESCRIPTION("Generic Backlight Driver");
114MODULE_LICENSE("GPL");