aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 04:57:36 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:27 -0500
commitffbdccdbbaee814963a09d25b1cc598cfe131366 (patch)
treeed487c6e89fb106fd7de798d166ee4342efac85e
parente3a700d8aae190e09fb06abe0ddd2e172a682508 (diff)
leds-lp55xx: use lp55xx common init function - post int
LP5521/5523 chip configuration is replaced with lp55xx common function, lp55xx_post_init_device(). Name change: lp5521/5523_configure() to lp5521/5523_post_init_device() These are called in init function. Register access function Argument type is changed from 'i2c_client' to 'lp55xx_chip'. Use exported R/W functions of lp55xx common driver. Temporary variables in lp5521/5523_init_device() These functions will be removed but temporary variables are needed for blocking build warnings - incompatible pointer. Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com> Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r--drivers/leds/leds-lp5521.c29
-rw-r--r--drivers/leds/leds-lp5523.c16
-rw-r--r--drivers/leds/leds-lp55xx-common.c15
-rw-r--r--drivers/leds/leds-lp55xx-common.h4
4 files changed, 42 insertions, 22 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 0e27f7eb5d09..faab44900c23 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -238,11 +238,9 @@ static int lp5521_set_led_current(struct lp5521_chip *chip, int led, u8 curr)
238 curr); 238 curr);
239} 239}
240 240
241static int lp5521_configure(struct i2c_client *client) 241static int lp5521_post_init_device(struct lp55xx_chip *chip)
242{ 242{
243 struct lp5521_chip *chip = i2c_get_clientdata(client);
244 int ret; 243 int ret;
245 u8 cfg;
246 u8 val; 244 u8 val;
247 245
248 /* 246 /*
@@ -251,13 +249,13 @@ static int lp5521_configure(struct i2c_client *client)
251 * otherwise further access to the R G B channels in the 249 * otherwise further access to the R G B channels in the
252 * LP5521_REG_ENABLE register will not have any effect - strange! 250 * LP5521_REG_ENABLE register will not have any effect - strange!
253 */ 251 */
254 ret = lp5521_read(client, LP5521_REG_R_CURRENT, &val); 252 ret = lp55xx_read(chip, LP5521_REG_R_CURRENT, &val);
255 if (ret) { 253 if (ret) {
256 dev_err(&client->dev, "error in resetting chip\n"); 254 dev_err(&chip->cl->dev, "error in resetting chip\n");
257 return ret; 255 return ret;
258 } 256 }
259 if (val != LP5521_REG_R_CURR_DEFAULT) { 257 if (val != LP5521_REG_R_CURR_DEFAULT) {
260 dev_err(&client->dev, 258 dev_err(&chip->cl->dev,
261 "unexpected data in register (expected 0x%x got 0x%x)\n", 259 "unexpected data in register (expected 0x%x got 0x%x)\n",
262 LP5521_REG_R_CURR_DEFAULT, val); 260 LP5521_REG_R_CURR_DEFAULT, val);
263 ret = -EINVAL; 261 ret = -EINVAL;
@@ -266,22 +264,21 @@ static int lp5521_configure(struct i2c_client *client)
266 usleep_range(10000, 20000); 264 usleep_range(10000, 20000);
267 265
268 /* Set all PWMs to direct control mode */ 266 /* Set all PWMs to direct control mode */
269 ret = lp5521_write(client, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT); 267 ret = lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
270 268
271 cfg = chip->pdata->update_config ? 269 val = chip->pdata->update_config ?
272 : (LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT); 270 : (LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT);
273 ret = lp5521_write(client, LP5521_REG_CONFIG, cfg); 271 ret = lp55xx_write(chip, LP5521_REG_CONFIG, val);
274 if (ret) 272 if (ret)
275 return ret; 273 return ret;
276 274
277 /* Initialize all channels PWM to zero -> leds off */ 275 /* Initialize all channels PWM to zero -> leds off */
278 lp5521_write(client, LP5521_REG_R_PWM, 0); 276 lp55xx_write(chip, LP5521_REG_R_PWM, 0);
279 lp5521_write(client, LP5521_REG_G_PWM, 0); 277 lp55xx_write(chip, LP5521_REG_G_PWM, 0);
280 lp5521_write(client, LP5521_REG_B_PWM, 0); 278 lp55xx_write(chip, LP5521_REG_B_PWM, 0);
281 279
282 /* Set engines are set to run state when OP_MODE enables engines */ 280 /* Set engines are set to run state when OP_MODE enables engines */
283 ret = lp5521_write(client, LP5521_REG_ENABLE, 281 ret = lp55xx_write(chip, LP5521_REG_ENABLE, LP5521_ENABLE_RUN_PROGRAM);
284 LP5521_ENABLE_RUN_PROGRAM);
285 if (ret) 282 if (ret)
286 return ret; 283 return ret;
287 284
@@ -696,9 +693,10 @@ static void lp5521_deinit_device(struct lp5521_chip *chip);
696static int lp5521_init_device(struct lp5521_chip *chip) 693static int lp5521_init_device(struct lp5521_chip *chip)
697{ 694{
698 struct i2c_client *client = chip->client; 695 struct i2c_client *client = chip->client;
696 struct lp55xx_chip *temp;
699 int ret; 697 int ret;
700 698
701 ret = lp5521_configure(client); 699 ret = lp5521_post_init_device(temp);
702 if (ret < 0) { 700 if (ret < 0) {
703 dev_err(&client->dev, "error configuring chip\n"); 701 dev_err(&client->dev, "error configuring chip\n");
704 goto err_config; 702 goto err_config;
@@ -828,6 +826,7 @@ static struct lp55xx_device_config lp5521_cfg = {
828 .addr = LP5521_REG_ENABLE, 826 .addr = LP5521_REG_ENABLE,
829 .val = LP5521_ENABLE_DEFAULT, 827 .val = LP5521_ENABLE_DEFAULT,
830 }, 828 },
829 .post_init_device = lp5521_post_init_device,
831}; 830};
832 831
833static int lp5521_probe(struct i2c_client *client, 832static int lp5521_probe(struct i2c_client *client,
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index b3698e85d51f..110565b066e2 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -181,18 +181,18 @@ static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
181 return 0; 181 return 0;
182} 182}
183 183
184static int lp5523_configure(struct i2c_client *client) 184static int lp5523_post_init_device(struct lp55xx_chip *chip)
185{ 185{
186 int ret = 0; 186 int ret;
187 187
188 ret = lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE); 188 ret = lp55xx_write(chip, LP5523_REG_ENABLE, LP5523_ENABLE);
189 if (ret) 189 if (ret)
190 return ret; 190 return ret;
191 191
192 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */ 192 /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
193 usleep_range(1000, 2000); 193 usleep_range(1000, 2000);
194 194
195 ret = lp5523_write(client, LP5523_REG_CONFIG, 195 ret = lp55xx_write(chip, LP5523_REG_CONFIG,
196 LP5523_AUTO_INC | LP5523_PWR_SAVE | 196 LP5523_AUTO_INC | LP5523_PWR_SAVE |
197 LP5523_CP_AUTO | LP5523_AUTO_CLK | 197 LP5523_CP_AUTO | LP5523_AUTO_CLK |
198 LP5523_PWM_PWR_SAVE); 198 LP5523_PWM_PWR_SAVE);
@@ -200,11 +200,11 @@ static int lp5523_configure(struct i2c_client *client)
200 return ret; 200 return ret;
201 201
202 /* turn on all leds */ 202 /* turn on all leds */
203 ret = lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01); 203 ret = lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
204 if (ret) 204 if (ret)
205 return ret; 205 return ret;
206 206
207 return lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff); 207 return lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
208} 208}
209 209
210static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode) 210static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode)
@@ -888,9 +888,10 @@ static void lp5523_deinit_device(struct lp5523_chip *chip);
888static int lp5523_init_device(struct lp5523_chip *chip) 888static int lp5523_init_device(struct lp5523_chip *chip)
889{ 889{
890 struct i2c_client *client = chip->client; 890 struct i2c_client *client = chip->client;
891 struct lp55xx_chip *temp;
891 int ret; 892 int ret;
892 893
893 ret = lp5523_configure(client); 894 ret = lp5523_post_init_device(temp);
894 if (ret < 0) { 895 if (ret < 0) {
895 dev_err(&client->dev, "error configuring chip\n"); 896 dev_err(&client->dev, "error configuring chip\n");
896 goto err_config; 897 goto err_config;
@@ -923,6 +924,7 @@ static struct lp55xx_device_config lp5523_cfg = {
923 .addr = LP5523_REG_ENABLE, 924 .addr = LP5523_REG_ENABLE,
924 .val = LP5523_ENABLE, 925 .val = LP5523_ENABLE,
925 }, 926 },
927 .post_init_device = lp5523_post_init_device,
926}; 928};
927 929
928static int lp5523_probe(struct i2c_client *client, 930static int lp5523_probe(struct i2c_client *client,
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 6fede0b96715..74beb363b787 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -53,6 +53,16 @@ static int lp55xx_detect_device(struct lp55xx_chip *chip)
53 return 0; 53 return 0;
54} 54}
55 55
56static int lp55xx_post_init_device(struct lp55xx_chip *chip)
57{
58 struct lp55xx_device_config *cfg = chip->cfg;
59
60 if (!cfg->post_init_device)
61 return 0;
62
63 return cfg->post_init_device(chip);
64}
65
56int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val) 66int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
57{ 67{
58 return i2c_smbus_write_byte_data(chip->cl, reg, val); 68 return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -132,6 +142,11 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
132 goto err; 142 goto err;
133 } 143 }
134 144
145 /* chip specific initialization */
146 ret = lp55xx_post_init_device(chip);
147
148 return 0;
149
135err: 150err:
136 return ret; 151 return ret;
137} 152}
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index 81753012ba27..ffedc7723d84 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -32,10 +32,14 @@ struct lp55xx_reg {
32 * struct lp55xx_device_config 32 * struct lp55xx_device_config
33 * @reset : Chip specific reset command 33 * @reset : Chip specific reset command
34 * @enable : Chip specific enable command 34 * @enable : Chip specific enable command
35 * @post_init_device : Chip specific initialization code
35 */ 36 */
36struct lp55xx_device_config { 37struct lp55xx_device_config {
37 const struct lp55xx_reg reset; 38 const struct lp55xx_reg reset;
38 const struct lp55xx_reg enable; 39 const struct lp55xx_reg enable;
40
41 /* define if the device has specific initialization process */
42 int (*post_init_device) (struct lp55xx_chip *chip);
39}; 43};
40 44
41/* 45/*