diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/video/backlight/max8925_bl.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/video/backlight/max8925_bl.c')
-rw-r--r-- | drivers/video/backlight/max8925_bl.c | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c new file mode 100644 index 000000000000..b5accc957ad3 --- /dev/null +++ b/drivers/video/backlight/max8925_bl.c | |||
@@ -0,0 +1,203 @@ | |||
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 | #include <linux/slab.h> | ||
20 | |||
21 | #define MAX_BRIGHTNESS (0xff) | ||
22 | #define MIN_BRIGHTNESS (0) | ||
23 | |||
24 | #define LWX_FREQ(x) (((x - 601) / 100) & 0x7) | ||
25 | |||
26 | struct max8925_backlight_data { | ||
27 | struct max8925_chip *chip; | ||
28 | |||
29 | int current_brightness; | ||
30 | }; | ||
31 | |||
32 | static int max8925_backlight_set(struct backlight_device *bl, int brightness) | ||
33 | { | ||
34 | struct max8925_backlight_data *data = bl_get_data(bl); | ||
35 | struct max8925_chip *chip = data->chip; | ||
36 | unsigned char value; | ||
37 | int ret; | ||
38 | |||
39 | if (brightness > MAX_BRIGHTNESS) | ||
40 | value = MAX_BRIGHTNESS; | ||
41 | else | ||
42 | value = brightness; | ||
43 | |||
44 | ret = max8925_reg_write(chip->i2c, MAX8925_WLED_CNTL, value); | ||
45 | if (ret < 0) | ||
46 | goto out; | ||
47 | |||
48 | if (!data->current_brightness && brightness) | ||
49 | /* enable WLED output */ | ||
50 | ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 1); | ||
51 | else if (!brightness) | ||
52 | /* disable WLED output */ | ||
53 | ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 1, 0); | ||
54 | if (ret < 0) | ||
55 | goto out; | ||
56 | dev_dbg(chip->dev, "set brightness %d\n", value); | ||
57 | data->current_brightness = value; | ||
58 | return 0; | ||
59 | out: | ||
60 | dev_dbg(chip->dev, "set brightness %d failure with return value:%d\n", | ||
61 | value, ret); | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | static int max8925_backlight_update_status(struct backlight_device *bl) | ||
66 | { | ||
67 | int brightness = bl->props.brightness; | ||
68 | |||
69 | if (bl->props.power != FB_BLANK_UNBLANK) | ||
70 | brightness = 0; | ||
71 | |||
72 | if (bl->props.fb_blank != FB_BLANK_UNBLANK) | ||
73 | brightness = 0; | ||
74 | |||
75 | if (bl->props.state & BL_CORE_SUSPENDED) | ||
76 | brightness = 0; | ||
77 | |||
78 | return max8925_backlight_set(bl, brightness); | ||
79 | } | ||
80 | |||
81 | static int max8925_backlight_get_brightness(struct backlight_device *bl) | ||
82 | { | ||
83 | struct max8925_backlight_data *data = bl_get_data(bl); | ||
84 | struct max8925_chip *chip = data->chip; | ||
85 | int ret; | ||
86 | |||
87 | ret = max8925_reg_read(chip->i2c, MAX8925_WLED_CNTL); | ||
88 | if (ret < 0) | ||
89 | return -EINVAL; | ||
90 | data->current_brightness = ret; | ||
91 | dev_dbg(chip->dev, "get brightness %d\n", data->current_brightness); | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | static struct backlight_ops max8925_backlight_ops = { | ||
96 | .options = BL_CORE_SUSPENDRESUME, | ||
97 | .update_status = max8925_backlight_update_status, | ||
98 | .get_brightness = max8925_backlight_get_brightness, | ||
99 | }; | ||
100 | |||
101 | static int __devinit max8925_backlight_probe(struct platform_device *pdev) | ||
102 | { | ||
103 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | ||
104 | struct max8925_platform_data *max8925_pdata; | ||
105 | struct max8925_backlight_pdata *pdata = NULL; | ||
106 | struct max8925_backlight_data *data; | ||
107 | struct backlight_device *bl; | ||
108 | struct backlight_properties props; | ||
109 | struct resource *res; | ||
110 | char name[MAX8925_NAME_SIZE]; | ||
111 | unsigned char value; | ||
112 | int ret; | ||
113 | |||
114 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
115 | if (res == NULL) { | ||
116 | dev_err(&pdev->dev, "No I/O resource!\n"); | ||
117 | return -EINVAL; | ||
118 | } | ||
119 | |||
120 | if (pdev->dev.parent->platform_data) { | ||
121 | max8925_pdata = pdev->dev.parent->platform_data; | ||
122 | pdata = max8925_pdata->backlight; | ||
123 | } | ||
124 | |||
125 | if (!pdata) { | ||
126 | dev_err(&pdev->dev, "platform data isn't assigned to " | ||
127 | "backlight\n"); | ||
128 | return -EINVAL; | ||
129 | } | ||
130 | |||
131 | data = kzalloc(sizeof(struct max8925_backlight_data), GFP_KERNEL); | ||
132 | if (data == NULL) | ||
133 | return -ENOMEM; | ||
134 | strncpy(name, res->name, MAX8925_NAME_SIZE); | ||
135 | data->chip = chip; | ||
136 | data->current_brightness = 0; | ||
137 | |||
138 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
139 | props.max_brightness = MAX_BRIGHTNESS; | ||
140 | bl = backlight_device_register(name, &pdev->dev, data, | ||
141 | &max8925_backlight_ops, &props); | ||
142 | if (IS_ERR(bl)) { | ||
143 | dev_err(&pdev->dev, "failed to register backlight\n"); | ||
144 | kfree(data); | ||
145 | return PTR_ERR(bl); | ||
146 | } | ||
147 | bl->props.brightness = MAX_BRIGHTNESS; | ||
148 | |||
149 | platform_set_drvdata(pdev, bl); | ||
150 | |||
151 | value = 0; | ||
152 | if (pdata->lxw_scl) | ||
153 | value |= (1 << 7); | ||
154 | if (pdata->lxw_freq) | ||
155 | value |= (LWX_FREQ(pdata->lxw_freq) << 4); | ||
156 | if (pdata->dual_string) | ||
157 | value |= (1 << 1); | ||
158 | ret = max8925_set_bits(chip->i2c, MAX8925_WLED_MODE_CNTL, 0xfe, value); | ||
159 | if (ret < 0) | ||
160 | goto out; | ||
161 | |||
162 | backlight_update_status(bl); | ||
163 | return 0; | ||
164 | out: | ||
165 | kfree(data); | ||
166 | return ret; | ||
167 | } | ||
168 | |||
169 | static int __devexit max8925_backlight_remove(struct platform_device *pdev) | ||
170 | { | ||
171 | struct backlight_device *bl = platform_get_drvdata(pdev); | ||
172 | struct max8925_backlight_data *data = bl_get_data(bl); | ||
173 | |||
174 | backlight_device_unregister(bl); | ||
175 | kfree(data); | ||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | static struct platform_driver max8925_backlight_driver = { | ||
180 | .driver = { | ||
181 | .name = "max8925-backlight", | ||
182 | .owner = THIS_MODULE, | ||
183 | }, | ||
184 | .probe = max8925_backlight_probe, | ||
185 | .remove = __devexit_p(max8925_backlight_remove), | ||
186 | }; | ||
187 | |||
188 | static int __init max8925_backlight_init(void) | ||
189 | { | ||
190 | return platform_driver_register(&max8925_backlight_driver); | ||
191 | } | ||
192 | module_init(max8925_backlight_init); | ||
193 | |||
194 | static void __exit max8925_backlight_exit(void) | ||
195 | { | ||
196 | platform_driver_unregister(&max8925_backlight_driver); | ||
197 | }; | ||
198 | module_exit(max8925_backlight_exit); | ||
199 | |||
200 | MODULE_DESCRIPTION("Backlight Driver for Maxim MAX8925"); | ||
201 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
202 | MODULE_LICENSE("GPL"); | ||
203 | MODULE_ALIAS("platform:max8925-backlight"); | ||