]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
leds-lp55xx: use lp55xx common init function - post int
authorMilo(Woogyom) Kim <milo.kim@ti.com>
Tue, 5 Feb 2013 09:57:36 +0000 (18:57 +0900)
committerBryan Wu <cooloney@gmail.com>
Wed, 6 Feb 2013 23:59:27 +0000 (15:59 -0800)
 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>
drivers/leds/leds-lp5521.c
drivers/leds/leds-lp5523.c
drivers/leds/leds-lp55xx-common.c
drivers/leds/leds-lp55xx-common.h

index 0e27f7eb5d092c052a08a289e7a0097ec2b9b8ca..faab44900c2355484920462d472652bbe4a4c1c9 100644 (file)
@@ -238,11 +238,9 @@ static int lp5521_set_led_current(struct lp5521_chip *chip, int led, u8 curr)
                    curr);
 }
 
-static int lp5521_configure(struct i2c_client *client)
+static int lp5521_post_init_device(struct lp55xx_chip *chip)
 {
-       struct lp5521_chip *chip = i2c_get_clientdata(client);
        int ret;
-       u8 cfg;
        u8 val;
 
        /*
@@ -251,13 +249,13 @@ static int lp5521_configure(struct i2c_client *client)
         * otherwise further access to the R G B channels in the
         * LP5521_REG_ENABLE register will not have any effect - strange!
         */
-       ret = lp5521_read(client, LP5521_REG_R_CURRENT, &val);
+       ret = lp55xx_read(chip, LP5521_REG_R_CURRENT, &val);
        if (ret) {
-               dev_err(&client->dev, "error in resetting chip\n");
+               dev_err(&chip->cl->dev, "error in resetting chip\n");
                return ret;
        }
        if (val != LP5521_REG_R_CURR_DEFAULT) {
-               dev_err(&client->dev,
+               dev_err(&chip->cl->dev,
                        "unexpected data in register (expected 0x%x got 0x%x)\n",
                        LP5521_REG_R_CURR_DEFAULT, val);
                ret = -EINVAL;
@@ -266,22 +264,21 @@ static int lp5521_configure(struct i2c_client *client)
        usleep_range(10000, 20000);
 
        /* Set all PWMs to direct control mode */
-       ret = lp5521_write(client, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
+       ret = lp55xx_write(chip, LP5521_REG_OP_MODE, LP5521_CMD_DIRECT);
 
-       cfg = chip->pdata->update_config ?
+       val = chip->pdata->update_config ?
                : (LP5521_PWRSAVE_EN | LP5521_CP_MODE_AUTO | LP5521_R_TO_BATT);
-       ret = lp5521_write(client, LP5521_REG_CONFIG, cfg);
+       ret = lp55xx_write(chip, LP5521_REG_CONFIG, val);
        if (ret)
                return ret;
 
        /* Initialize all channels PWM to zero -> leds off */
-       lp5521_write(client, LP5521_REG_R_PWM, 0);
-       lp5521_write(client, LP5521_REG_G_PWM, 0);
-       lp5521_write(client, LP5521_REG_B_PWM, 0);
+       lp55xx_write(chip, LP5521_REG_R_PWM, 0);
+       lp55xx_write(chip, LP5521_REG_G_PWM, 0);
+       lp55xx_write(chip, LP5521_REG_B_PWM, 0);
 
        /* Set engines are set to run state when OP_MODE enables engines */
-       ret = lp5521_write(client, LP5521_REG_ENABLE,
-                       LP5521_ENABLE_RUN_PROGRAM);
+       ret = lp55xx_write(chip, LP5521_REG_ENABLE, LP5521_ENABLE_RUN_PROGRAM);
        if (ret)
                return ret;
 
@@ -696,9 +693,10 @@ static void lp5521_deinit_device(struct lp5521_chip *chip);
 static int lp5521_init_device(struct lp5521_chip *chip)
 {
        struct i2c_client *client = chip->client;
+       struct lp55xx_chip *temp;
        int ret;
 
-       ret = lp5521_configure(client);
+       ret = lp5521_post_init_device(temp);
        if (ret < 0) {
                dev_err(&client->dev, "error configuring chip\n");
                goto err_config;
@@ -828,6 +826,7 @@ static struct lp55xx_device_config lp5521_cfg = {
                .addr = LP5521_REG_ENABLE,
                .val  = LP5521_ENABLE_DEFAULT,
        },
+       .post_init_device   = lp5521_post_init_device,
 };
 
 static int lp5521_probe(struct i2c_client *client,
index b3698e85d51f4e0d6dca90c9837fd712bb752557..110565b066e2d124a444137a15f76e2c2fbae659 100644 (file)
@@ -181,18 +181,18 @@ static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
        return 0;
 }
 
-static int lp5523_configure(struct i2c_client *client)
+static int lp5523_post_init_device(struct lp55xx_chip *chip)
 {
-       int ret = 0;
+       int ret;
 
-       ret = lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
+       ret = lp55xx_write(chip, LP5523_REG_ENABLE, LP5523_ENABLE);
        if (ret)
                return ret;
 
        /* Chip startup time is 500 us, 1 - 2 ms gives some margin */
        usleep_range(1000, 2000);
 
-       ret = lp5523_write(client, LP5523_REG_CONFIG,
+       ret = lp55xx_write(chip, LP5523_REG_CONFIG,
                            LP5523_AUTO_INC | LP5523_PWR_SAVE |
                            LP5523_CP_AUTO | LP5523_AUTO_CLK |
                            LP5523_PWM_PWR_SAVE);
@@ -200,11 +200,11 @@ static int lp5523_configure(struct i2c_client *client)
                return ret;
 
        /* turn on all leds */
-       ret = lp5523_write(client, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
+       ret = lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_MSB, 0x01);
        if (ret)
                return ret;
 
-       return lp5523_write(client, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
+       return lp55xx_write(chip, LP5523_REG_ENABLE_LEDS_LSB, 0xff);
 }
 
 static int lp5523_set_engine_mode(struct lp5523_engine *engine, u8 mode)
@@ -888,9 +888,10 @@ static void lp5523_deinit_device(struct lp5523_chip *chip);
 static int lp5523_init_device(struct lp5523_chip *chip)
 {
        struct i2c_client *client = chip->client;
+       struct lp55xx_chip *temp;
        int ret;
 
-       ret = lp5523_configure(client);
+       ret = lp5523_post_init_device(temp);
        if (ret < 0) {
                dev_err(&client->dev, "error configuring chip\n");
                goto err_config;
@@ -923,6 +924,7 @@ static struct lp55xx_device_config lp5523_cfg = {
                .addr = LP5523_REG_ENABLE,
                .val  = LP5523_ENABLE,
        },
+       .post_init_device   = lp5523_post_init_device,
 };
 
 static int lp5523_probe(struct i2c_client *client,
index 6fede0b96715d2b85e4a1ca5cb907fbc24a696ab..74beb363b7873bdc2670693acf615d5ef5a456ea 100644 (file)
@@ -53,6 +53,16 @@ static int lp55xx_detect_device(struct lp55xx_chip *chip)
        return 0;
 }
 
+static int lp55xx_post_init_device(struct lp55xx_chip *chip)
+{
+       struct lp55xx_device_config *cfg = chip->cfg;
+
+       if (!cfg->post_init_device)
+               return 0;
+
+       return cfg->post_init_device(chip);
+}
+
 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
 {
        return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -132,6 +142,11 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
                goto err;
        }
 
+       /* chip specific initialization */
+       ret = lp55xx_post_init_device(chip);
+
+       return 0;
+
 err:
        return ret;
 }
index 81753012ba273ca35a6fe53cb6acd4863bb2df35..ffedc7723d846d5b62afb891e04aa77deab3f45c 100644 (file)
@@ -32,10 +32,14 @@ struct lp55xx_reg {
  * struct lp55xx_device_config
  * @reset              : Chip specific reset command
  * @enable             : Chip specific enable command
+ * @post_init_device   : Chip specific initialization code
  */
 struct lp55xx_device_config {
        const struct lp55xx_reg reset;
        const struct lp55xx_reg enable;
+
+       /* define if the device has specific initialization process */
+       int (*post_init_device) (struct lp55xx_chip *chip);
 };
 
 /*