aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight
diff options
context:
space:
mode:
authorKim, Milo <Milo.Kim@ti.com>2013-02-21 19:44:05 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 20:22:25 -0500
commit68853bc2b360c06094477523f7d28efd2d9e3bf3 (patch)
tree990be260ebba4ab9ffd8ca57f8c05fad9245afd0 /drivers/video/backlight
parent5eb02c01bd1f3ef195989ab05e835e2b0711b5a9 (diff)
backlight: lp855x_bl: introduce device configuration flow
At this moment, LP855x device driver has fixed register configuration. For example, fixed register addresses and values are set on the device initialization. But new device of LP855x family, LP8557 has different register map and initialization sequence. To support new device architecture, initialization process should be changed. Introduce new structure: lp855x_device_config ============================================= With lp855x_device_config, device specific features are configurable. Use configurable function calls and register addresses rather than fixed values. Change on device initialization =============================== In old LP855x driver architecture, the device initialization was simple. - Just update the brightness/device control register/ROM area(optional). In new LP855x driver architecture, two more works are added - pre_init and post_init. Those init functions are optional, used for new device LP8557. New device initialization flow: generic sequence ================================================= 1) pre_init_device() 2) update the brightness register 3) update the device control register 4) update ROM area if need 5) post_init_device() Name change =========== Use generic name 'lp855x_configure()' instead of 'lp855x_init_registers()'. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Acked-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video/backlight')
-rw-r--r--drivers/video/backlight/lp855x_bl.c78
1 files changed, 68 insertions, 10 deletions
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index 6e4db0c874c8..050cfbb53667 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -29,9 +29,26 @@
29#define DEFAULT_BL_NAME "lcd-backlight" 29#define DEFAULT_BL_NAME "lcd-backlight"
30#define MAX_BRIGHTNESS 255 30#define MAX_BRIGHTNESS 255
31 31
32struct lp855x;
33
34/*
35 * struct lp855x_device_config
36 * @pre_init_device: init device function call before updating the brightness
37 * @reg_brightness: register address for brigthenss control
38 * @reg_devicectrl: register address for device control
39 * @post_init_device: late init device function call
40 */
41struct lp855x_device_config {
42 int (*pre_init_device)(struct lp855x *);
43 u8 reg_brightness;
44 u8 reg_devicectrl;
45 int (*post_init_device)(struct lp855x *);
46};
47
32struct lp855x { 48struct lp855x {
33 const char *chipname; 49 const char *chipname;
34 enum lp855x_chip_id chip_id; 50 enum lp855x_chip_id chip_id;
51 struct lp855x_device_config *cfg;
35 struct i2c_client *client; 52 struct i2c_client *client;
36 struct backlight_device *bl; 53 struct backlight_device *bl;
37 struct device *dev; 54 struct device *dev;
@@ -81,21 +98,52 @@ static bool lp855x_is_valid_rom_area(struct lp855x *lp, u8 addr)
81 return (addr >= start && addr <= end); 98 return (addr >= start && addr <= end);
82} 99}
83 100
84static int lp855x_init_registers(struct lp855x *lp) 101static struct lp855x_device_config lp855x_dev_cfg = {
102 .reg_brightness = BRIGHTNESS_CTRL,
103 .reg_devicectrl = DEVICE_CTRL,
104};
105
106/*
107 * Device specific configuration flow
108 *
109 * a) pre_init_device(optional)
110 * b) update the brightness register
111 * c) update device control register
112 * d) update ROM area(optional)
113 * e) post_init_device(optional)
114 *
115 */
116static int lp855x_configure(struct lp855x *lp)
85{ 117{
86 u8 val, addr; 118 u8 val, addr;
87 int i, ret; 119 int i, ret;
88 struct lp855x_platform_data *pd = lp->pdata; 120 struct lp855x_platform_data *pd = lp->pdata;
89 121
122 switch (lp->chip_id) {
123 case LP8550 ... LP8556:
124 lp->cfg = &lp855x_dev_cfg;
125 break;
126 default:
127 return -EINVAL;
128 }
129
130 if (lp->cfg->pre_init_device) {
131 ret = lp->cfg->pre_init_device(lp);
132 if (ret) {
133 dev_err(lp->dev, "pre init device err: %d\n", ret);
134 goto err;
135 }
136 }
137
90 val = pd->initial_brightness; 138 val = pd->initial_brightness;
91 ret = lp855x_write_byte(lp, BRIGHTNESS_CTRL, val); 139 ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, val);
92 if (ret) 140 if (ret)
93 return ret; 141 goto err;
94 142
95 val = pd->device_control; 143 val = pd->device_control;
96 ret = lp855x_write_byte(lp, DEVICE_CTRL, val); 144 ret = lp855x_write_byte(lp, lp->cfg->reg_devicectrl, val);
97 if (ret) 145 if (ret)
98 return ret; 146 goto err;
99 147
100 if (pd->load_new_rom_data && pd->size_program) { 148 if (pd->load_new_rom_data && pd->size_program) {
101 for (i = 0; i < pd->size_program; i++) { 149 for (i = 0; i < pd->size_program; i++) {
@@ -106,10 +154,21 @@ static int lp855x_init_registers(struct lp855x *lp)
106 154
107 ret = lp855x_write_byte(lp, addr, val); 155 ret = lp855x_write_byte(lp, addr, val);
108 if (ret) 156 if (ret)
109 return ret; 157 goto err;
158 }
159 }
160
161 if (lp->cfg->post_init_device) {
162 ret = lp->cfg->post_init_device(lp);
163 if (ret) {
164 dev_err(lp->dev, "post init device err: %d\n", ret);
165 goto err;
110 } 166 }
111 } 167 }
112 168
169 return 0;
170
171err:
113 return ret; 172 return ret;
114} 173}
115 174
@@ -271,11 +330,10 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
271 lp->chip_id = id->driver_data; 330 lp->chip_id = id->driver_data;
272 i2c_set_clientdata(cl, lp); 331 i2c_set_clientdata(cl, lp);
273 332
274 ret = lp855x_init_registers(lp); 333 ret = lp855x_configure(lp);
275 if (ret) { 334 if (ret) {
276 dev_err(lp->dev, "i2c communication err: %d", ret); 335 dev_err(lp->dev, "device config err: %d", ret);
277 if (mode == REGISTER_BASED) 336 goto err_dev;
278 goto err_dev;
279 } 337 }
280 338
281 ret = lp855x_backlight_register(lp); 339 ret = lp855x_backlight_register(lp);