aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@marvell.com>2009-12-18 10:01:45 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2010-03-07 16:17:08 -0500
commit4f811ef0d40048ae80b6ea77080b814725bffc58 (patch)
tree497168c5c8059bed17c50c8b44d9691e5634f8bb
parent1ad998934e9c6cbae91662a05e0cb8772b1f4f75 (diff)
backlight: Enable max8925 backlight
Enable max8925 backlight sub device. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--drivers/video/backlight/Kconfig7
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/max8925_bl.c200
3 files changed, 208 insertions, 0 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 96a6b3060ac0..0c77fc610212 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -212,6 +212,13 @@ config BACKLIGHT_DA903X
212 If you have a LCD backlight connected to the WLED output of DA9030 212 If you have a LCD backlight connected to the WLED output of DA9030
213 or DA9034 WLED output, say Y here to enable this driver. 213 or DA9034 WLED output, say Y here to enable this driver.
214 214
215config BACKLIGHT_MAX8925
216 tristate "Backlight driver for MAX8925"
217 depends on BACKLIGHT_CLASS_DEVICE && MFD_MAX8925
218 help
219 If you have a LCD backlight connected to the WLED output of MAX8925
220 WLED output, say Y here to enable this driver.
221
215config BACKLIGHT_MBP_NVIDIA 222config BACKLIGHT_MBP_NVIDIA
216 tristate "MacBook Pro Nvidia Backlight Driver" 223 tristate "MacBook Pro Nvidia Backlight Driver"
217 depends on BACKLIGHT_CLASS_DEVICE && X86 224 depends on BACKLIGHT_CLASS_DEVICE && X86
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 802d467b08c0..6c704d41462d 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
22obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o 22obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
23obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o 23obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
24obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o 24obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o
25obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o
25obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o 26obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
26obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o 27obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
27obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o 28obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c
new file mode 100644
index 000000000000..c267069a52a3
--- /dev/null
+++ b/drivers/video/backlight/max8925_bl.c
@@ -0,0 +1,200 @@
1/*
2 * Backlight driver for Maxim MAX8925
3 *
4 * Copyright (C) 2009 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/platform_device.h>
15#include <linux/fb.h>
16#include <linux/i2c.h>
17#include <linux/backlight.h>
18#include <linux/mfd/max8925.h>
19
20#define MAX_BRIGHTNESS (0xff)
21#define MIN_BRIGHTNESS (0)
22
23#define LWX_FREQ(x) (((x - 601) / 100) & 0x7)
24
25struct max8925_backlight_data {
26 struct max8925_chip *chip;
27
28 int current_brightness;
29};
30
31static int max8925_backlight_set(struct backlight_device *bl, int brightness)
32{
33 struct max8925_backlight_data *data = bl_get_data(bl);
34 struct max8925_chip *chip = data->chip;
35 unsigned char value;
36 int ret;
37
38 if (brightness > MAX_BRIGHTNESS)
39 value = MAX_BRIGHTNESS;
40 else
41 value = brightness;
42
43 ret = max8925_reg_write(chip->i2c, MAX8925_WLED_CNTL, value);
44 if (ret < 0)
45 goto out;
46
47 if (!data->current_brightness && brightness)
48 /* enable WLED output */
49 ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 1);
50 else if (!brightness)
51 /* disable WLED output */
52 ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 0);
53 if (ret < 0)
54 goto out;
55 dev_dbg(chip->dev, "set brightness %d\n", value);
56 data->current_brightness = value;
57 return 0;
58out:
59 dev_dbg(chip->dev, "set brightness %d failure with return value:%d\n",
60 value, ret);
61 return ret;
62}
63
64static int max8925_backlight_update_status(struct backlight_device *bl)
65{
66 int brightness = bl->props.brightness;
67
68 if (bl->props.power != FB_BLANK_UNBLANK)
69 brightness = 0;
70
71 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
72 brightness = 0;
73
74 if (bl->props.state & BL_CORE_SUSPENDED)
75 brightness = 0;
76
77 return max8925_backlight_set(bl, brightness);
78}
79
80static int max8925_backlight_get_brightness(struct backlight_device *bl)
81{
82 struct max8925_backlight_data *data = bl_get_data(bl);
83 struct max8925_chip *chip = data->chip;
84 int ret;
85
86 ret = max8925_reg_read(chip->i2c, MAX8925_WLED_CNTL);
87 if (ret < 0)
88 return -EINVAL;
89 data->current_brightness = ret;
90 dev_dbg(chip->dev, "get brightness %d\n", data->current_brightness);
91 return ret;
92}
93
94static struct backlight_ops max8925_backlight_ops = {
95 .options = BL_CORE_SUSPENDRESUME,
96 .update_status = max8925_backlight_update_status,
97 .get_brightness = max8925_backlight_get_brightness,
98};
99
100static int __devinit max8925_backlight_probe(struct platform_device *pdev)
101{
102 struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
103 struct max8925_platform_data *max8925_pdata;
104 struct max8925_backlight_pdata *pdata = NULL;
105 struct max8925_backlight_data *data;
106 struct backlight_device *bl;
107 struct resource *res;
108 char name[MAX8925_NAME_SIZE];
109 unsigned char value;
110 int ret;
111
112 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
113 if (res == NULL) {
114 dev_err(&pdev->dev, "No I/O resource!\n");
115 return -EINVAL;
116 }
117
118 if (pdev->dev.parent->platform_data) {
119 max8925_pdata = pdev->dev.parent->platform_data;
120 pdata = max8925_pdata->backlight;
121 }
122
123 if (!pdata) {
124 dev_err(&pdev->dev, "platform data isn't assigned to "
125 "backlight\n");
126 return -EINVAL;
127 }
128
129 data = kzalloc(sizeof(struct max8925_backlight_data), GFP_KERNEL);
130 if (data == NULL)
131 return -ENOMEM;
132 strncpy(name, res->name, MAX8925_NAME_SIZE);
133 data->chip = chip;
134 data->current_brightness = 0;
135
136 bl = backlight_device_register(name, &pdev->dev, data,
137 &max8925_backlight_ops);
138 if (IS_ERR(bl)) {
139 dev_err(&pdev->dev, "failed to register backlight\n");
140 kfree(data);
141 return PTR_ERR(bl);
142 }
143 bl->props.max_brightness = MAX_BRIGHTNESS;
144 bl->props.brightness = MAX_BRIGHTNESS;
145
146 platform_set_drvdata(pdev, bl);
147
148 value = 0;
149 if (pdata->lxw_scl)
150 value |= (1 << 7);
151 if (pdata->lxw_freq)
152 value |= (LWX_FREQ(pdata->lxw_freq) << 4);
153 if (pdata->dual_string)
154 value |= (1 << 1);
155 ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 0xfe, value);
156 if (ret < 0)
157 goto out;
158
159 backlight_update_status(bl);
160 return 0;
161out:
162 kfree(data);
163 return ret;
164}
165
166static int __devexit max8925_backlight_remove(struct platform_device *pdev)
167{
168 struct backlight_device *bl = platform_get_drvdata(pdev);
169 struct max8925_backlight_data *data = bl_get_data(bl);
170
171 backlight_device_unregister(bl);
172 kfree(data);
173 return 0;
174}
175
176static struct platform_driver max8925_backlight_driver = {
177 .driver = {
178 .name = "max8925-backlight",
179 .owner = THIS_MODULE,
180 },
181 .probe = max8925_backlight_probe,
182 .remove = __devexit_p(max8925_backlight_remove),
183};
184
185static int __init max8925_backlight_init(void)
186{
187 return platform_driver_register(&max8925_backlight_driver);
188}
189module_init(max8925_backlight_init);
190
191static void __exit max8925_backlight_exit(void)
192{
193 platform_driver_unregister(&max8925_backlight_driver);
194};
195module_exit(max8925_backlight_exit);
196
197MODULE_DESCRIPTION("Backlight Driver for Maxim MAX8925");
198MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
199MODULE_LICENSE("GPL");
200MODULE_ALIAS("platform:max8925-backlight");