diff options
author | Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> | 2013-07-04 15:13:25 -0400 |
---|---|---|
committer | Simon Horman <horms+renesas@verge.net.au> | 2013-07-16 00:01:10 -0400 |
commit | 82e5c40d88f928afffe7bd4027719d3184433908 (patch) | |
tree | b2bc3910006badb3bdb1291f305dc97a4d7ed53a | |
parent | 8b770e3c9824c98eafe67950ad6e41e09ec9c98a (diff) |
backlight: Add Sanyo LV5207LP backlight driver
The LV5207LP is a multi-purpose 7 LEDs driver for the mobile market.
Only the main LED is supported by this driver.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
-rw-r--r-- | drivers/video/backlight/Kconfig | 6 | ||||
-rw-r--r-- | drivers/video/backlight/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/backlight/lv5207lp.c | 171 | ||||
-rw-r--r-- | include/linux/platform_data/lv5207lp.h | 19 |
4 files changed, 197 insertions, 0 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 5ab64237c972..b304e075cf3a 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig | |||
@@ -432,6 +432,12 @@ config BACKLIGHT_GPIO | |||
432 | If you have a LCD backlight adjustable by GPIO, say Y to enable | 432 | If you have a LCD backlight adjustable by GPIO, say Y to enable |
433 | this driver. | 433 | this driver. |
434 | 434 | ||
435 | config BACKLIGHT_LV5207LP | ||
436 | tristate "Sanyo LV5207LP Backlight" | ||
437 | depends on I2C | ||
438 | help | ||
439 | If you have a Sanyo LV5207LP say Y to enable the backlight driver. | ||
440 | |||
435 | endif # BACKLIGHT_CLASS_DEVICE | 441 | endif # BACKLIGHT_CLASS_DEVICE |
436 | 442 | ||
437 | endif # BACKLIGHT_LCD_SUPPORT | 443 | endif # BACKLIGHT_LCD_SUPPORT |
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 65698a882c2f..4e5e8116c8c4 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_BACKLIGHT_LM3639) += lm3639_bl.o | |||
41 | obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o | 41 | obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o |
42 | obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o | 42 | obj-$(CONFIG_BACKLIGHT_LP855X) += lp855x_bl.o |
43 | obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o | 43 | obj-$(CONFIG_BACKLIGHT_LP8788) += lp8788_bl.o |
44 | obj-$(CONFIG_BACKLIGHT_LV5207LP) += lv5207lp.o | ||
44 | obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o | 45 | obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o |
45 | obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o | 46 | obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o |
46 | obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o | 47 | obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o |
diff --git a/drivers/video/backlight/lv5207lp.c b/drivers/video/backlight/lv5207lp.c new file mode 100644 index 000000000000..498fd73d59b9 --- /dev/null +++ b/drivers/video/backlight/lv5207lp.c | |||
@@ -0,0 +1,171 @@ | |||
1 | /* | ||
2 | * Sanyo LV5207LP LED Driver | ||
3 | * | ||
4 | * Copyright (C) 2013 Ideas on board SPRL | ||
5 | * | ||
6 | * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> | ||
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 | #include <linux/backlight.h> | ||
14 | #include <linux/err.h> | ||
15 | #include <linux/fb.h> | ||
16 | #include <linux/i2c.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/platform_data/lv5207lp.h> | ||
19 | #include <linux/slab.h> | ||
20 | |||
21 | #define LV5207LP_CTRL1 0x00 | ||
22 | #define LV5207LP_CPSW (1 << 7) | ||
23 | #define LV5207LP_SCTEN (1 << 6) | ||
24 | #define LV5207LP_C10 (1 << 5) | ||
25 | #define LV5207LP_CKSW (1 << 4) | ||
26 | #define LV5207LP_RSW (1 << 3) | ||
27 | #define LV5207LP_GSW (1 << 2) | ||
28 | #define LV5207LP_BSW (1 << 1) | ||
29 | #define LV5207LP_CTRL2 0x01 | ||
30 | #define LV5207LP_MSW (1 << 7) | ||
31 | #define LV5207LP_MLED4 (1 << 6) | ||
32 | #define LV5207LP_RED 0x02 | ||
33 | #define LV5207LP_GREEN 0x03 | ||
34 | #define LV5207LP_BLUE 0x04 | ||
35 | |||
36 | #define LV5207LP_MAX_BRIGHTNESS 32 | ||
37 | |||
38 | struct lv5207lp { | ||
39 | struct i2c_client *client; | ||
40 | struct backlight_device *backlight; | ||
41 | struct lv5207lp_platform_data *pdata; | ||
42 | }; | ||
43 | |||
44 | static int lv5207lp_write(struct lv5207lp *lv, u8 reg, u8 data) | ||
45 | { | ||
46 | return i2c_smbus_write_byte_data(lv->client, reg, data); | ||
47 | } | ||
48 | |||
49 | static int lv5207lp_backlight_update_status(struct backlight_device *backlight) | ||
50 | { | ||
51 | struct lv5207lp *lv = bl_get_data(backlight); | ||
52 | int brightness = backlight->props.brightness; | ||
53 | |||
54 | if (backlight->props.power != FB_BLANK_UNBLANK || | ||
55 | backlight->props.fb_blank != FB_BLANK_UNBLANK || | ||
56 | backlight->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) | ||
57 | brightness = 0; | ||
58 | |||
59 | if (brightness) { | ||
60 | lv5207lp_write(lv, LV5207LP_CTRL1, | ||
61 | LV5207LP_CPSW | LV5207LP_C10 | LV5207LP_CKSW); | ||
62 | lv5207lp_write(lv, LV5207LP_CTRL2, | ||
63 | LV5207LP_MSW | LV5207LP_MLED4 | | ||
64 | (brightness - 1)); | ||
65 | } else { | ||
66 | lv5207lp_write(lv, LV5207LP_CTRL1, 0); | ||
67 | lv5207lp_write(lv, LV5207LP_CTRL2, 0); | ||
68 | } | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int lv5207lp_backlight_get_brightness(struct backlight_device *backlight) | ||
74 | { | ||
75 | return backlight->props.brightness; | ||
76 | } | ||
77 | |||
78 | static int lv5207lp_backlight_check_fb(struct backlight_device *backlight, | ||
79 | struct fb_info *info) | ||
80 | { | ||
81 | struct lv5207lp *lv = bl_get_data(backlight); | ||
82 | |||
83 | return lv->pdata->fbdev == NULL || lv->pdata->fbdev == info->dev; | ||
84 | } | ||
85 | |||
86 | static const struct backlight_ops lv5207lp_backlight_ops = { | ||
87 | .options = BL_CORE_SUSPENDRESUME, | ||
88 | .update_status = lv5207lp_backlight_update_status, | ||
89 | .get_brightness = lv5207lp_backlight_get_brightness, | ||
90 | .check_fb = lv5207lp_backlight_check_fb, | ||
91 | }; | ||
92 | |||
93 | static int lv5207lp_probe(struct i2c_client *client, | ||
94 | const struct i2c_device_id *id) | ||
95 | { | ||
96 | struct lv5207lp_platform_data *pdata = client->dev.platform_data; | ||
97 | struct backlight_device *backlight; | ||
98 | struct backlight_properties props; | ||
99 | struct lv5207lp *lv; | ||
100 | |||
101 | if (pdata == NULL) { | ||
102 | dev_err(&client->dev, "No platform data supplied\n"); | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | if (!i2c_check_functionality(client->adapter, | ||
107 | I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
108 | dev_warn(&client->dev, | ||
109 | "I2C adapter doesn't support I2C_FUNC_SMBUS_BYTE\n"); | ||
110 | return -EIO; | ||
111 | } | ||
112 | |||
113 | lv = devm_kzalloc(&client->dev, sizeof(*lv), GFP_KERNEL); | ||
114 | if (!lv) | ||
115 | return -ENOMEM; | ||
116 | |||
117 | lv->client = client; | ||
118 | lv->pdata = pdata; | ||
119 | |||
120 | memset(&props, 0, sizeof(props)); | ||
121 | props.type = BACKLIGHT_RAW; | ||
122 | props.max_brightness = min_t(unsigned int, pdata->max_value, | ||
123 | LV5207LP_MAX_BRIGHTNESS); | ||
124 | props.brightness = clamp_t(unsigned int, pdata->def_value, 0, | ||
125 | props.max_brightness); | ||
126 | |||
127 | backlight = backlight_device_register(dev_name(&client->dev), | ||
128 | &lv->client->dev, lv, | ||
129 | &lv5207lp_backlight_ops, &props); | ||
130 | if (IS_ERR(backlight)) { | ||
131 | dev_err(&client->dev, "failed to register backlight\n"); | ||
132 | return PTR_ERR(backlight); | ||
133 | } | ||
134 | |||
135 | backlight_update_status(backlight); | ||
136 | i2c_set_clientdata(client, backlight); | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | |||
141 | static int lv5207lp_remove(struct i2c_client *client) | ||
142 | { | ||
143 | struct backlight_device *backlight = i2c_get_clientdata(client); | ||
144 | |||
145 | backlight->props.brightness = 0; | ||
146 | backlight_update_status(backlight); | ||
147 | backlight_device_unregister(backlight); | ||
148 | |||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | static const struct i2c_device_id lv5207lp_ids[] = { | ||
153 | { "lv5207lp", 0 }, | ||
154 | { } | ||
155 | }; | ||
156 | MODULE_DEVICE_TABLE(i2c, lv5207lp_ids); | ||
157 | |||
158 | static struct i2c_driver lv5207lp_driver = { | ||
159 | .driver = { | ||
160 | .name = "lv5207lp", | ||
161 | }, | ||
162 | .probe = lv5207lp_probe, | ||
163 | .remove = lv5207lp_remove, | ||
164 | .id_table = lv5207lp_ids, | ||
165 | }; | ||
166 | |||
167 | module_i2c_driver(lv5207lp_driver); | ||
168 | |||
169 | MODULE_DESCRIPTION("Sanyo LV5207LP Backlight Driver"); | ||
170 | MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>"); | ||
171 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/linux/platform_data/lv5207lp.h b/include/linux/platform_data/lv5207lp.h new file mode 100644 index 000000000000..7dc4d9a219a6 --- /dev/null +++ b/include/linux/platform_data/lv5207lp.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * lv5207lp.h - Sanyo LV5207LP LEDs Driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | #ifndef __LV5207LP_H__ | ||
9 | #define __LV5207LP_H__ | ||
10 | |||
11 | struct device; | ||
12 | |||
13 | struct lv5207lp_platform_data { | ||
14 | struct device *fbdev; | ||
15 | unsigned int max_value; | ||
16 | unsigned int def_value; | ||
17 | }; | ||
18 | |||
19 | #endif | ||