Commit 68853bc2b360c06094477523f7d28efd2d9e3bf3

Authored by Kim, Milo
Committed by Linus Torvalds
1 parent 5eb02c01bd

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>

Showing 1 changed file with 68 additions and 10 deletions Side-by-side Diff

drivers/video/backlight/lp855x_bl.c
... ... @@ -29,9 +29,26 @@
29 29 #define DEFAULT_BL_NAME "lcd-backlight"
30 30 #define MAX_BRIGHTNESS 255
31 31  
  32 +struct 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 + */
  41 +struct 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 +
32 48 struct lp855x {
33 49 const char *chipname;
34 50 enum lp855x_chip_id chip_id;
  51 + struct lp855x_device_config *cfg;
35 52 struct i2c_client *client;
36 53 struct backlight_device *bl;
37 54 struct device *dev;
38 55  
39 56  
40 57  
41 58  
42 59  
... ... @@ -81,21 +98,52 @@
81 98 return (addr >= start && addr <= end);
82 99 }
83 100  
84   -static int lp855x_init_registers(struct lp855x *lp)
  101 +static 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 + */
  116 +static int lp855x_configure(struct lp855x *lp)
85 117 {
86 118 u8 val, addr;
87 119 int i, ret;
88 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 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 140 if (ret)
93   - return ret;
  141 + goto err;
94 142  
95 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 145 if (ret)
98   - return ret;
  146 + goto err;
99 147  
100 148 if (pd->load_new_rom_data && pd->size_program) {
101 149 for (i = 0; i < pd->size_program; i++) {
102 150  
... ... @@ -106,10 +154,21 @@
106 154  
107 155 ret = lp855x_write_byte(lp, addr, val);
108 156 if (ret)
109   - return ret;
  157 + goto err;
110 158 }
111 159 }
112 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;
  166 + }
  167 + }
  168 +
  169 + return 0;
  170 +
  171 +err:
113 172 return ret;
114 173 }
115 174  
116 175  
... ... @@ -271,11 +330,10 @@
271 330 lp->chip_id = id->driver_data;
272 331 i2c_set_clientdata(cl, lp);
273 332  
274   - ret = lp855x_init_registers(lp);
  333 + ret = lp855x_configure(lp);
275 334 if (ret) {
276   - dev_err(lp->dev, "i2c communication err: %d", ret);
277   - if (mode == REGISTER_BASED)
278   - goto err_dev;
  335 + dev_err(lp->dev, "device config err: %d", ret);
  336 + goto err_dev;
279 337 }
280 338  
281 339 ret = lp855x_backlight_register(lp);