]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
leds-lp55xx: use lp55xx common init function - reset
authorMilo(Woogyom) Kim <milo.kim@ti.com>
Tue, 5 Feb 2013 09:08:49 +0000 (18:08 +0900)
committerBryan Wu <cooloney@gmail.com>
Wed, 6 Feb 2013 23:59:27 +0000 (15:59 -0800)
 LP5521/5523 reset device functions are moved to lp55xx common driver.
 Value of register address and value are chip dependent.
 Those are configured in each driver.
 In init function, reset command is executed.

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 124ce80fa115db51342d6f17c3d98dbcdc3253ac..e1f1dfcd154744025c6a6eec272c644852ed6368 100644 (file)
@@ -98,6 +98,9 @@
 /* Pattern Mode */
 #define PATTERN_OFF    0
 
+/* Reset register value */
+#define LP5521_RESET                   0xFF
+
 struct lp5521_engine {
        int             id;
        u8              mode;
@@ -709,26 +712,12 @@ static void lp5521_unregister_sysfs(struct i2c_client *client)
                                &lp5521_led_attribute_group);
 }
 
-static void lp5521_reset_device(struct lp5521_chip *chip)
-{
-       struct i2c_client *client = chip->client;
-
-       lp5521_write(client, LP5521_REG_RESET, 0xff);
-}
-
 static void lp5521_deinit_device(struct lp5521_chip *chip);
 static int lp5521_init_device(struct lp5521_chip *chip)
 {
        struct i2c_client *client = chip->client;
        int ret;
 
-       lp5521_reset_device(chip);
-
-       usleep_range(10000, 20000); /*
-                                    * Exact value is not available. 10 - 20ms
-                                    * appears to be enough for reset.
-                                    */
-
        ret = lp5521_detect(client);
        if (ret) {
                dev_err(&client->dev, "Chip not found\n");
@@ -856,6 +845,14 @@ static void lp5521_unregister_leds(struct lp5521_chip *chip)
        }
 }
 
+/* Chip specific configurations */
+static struct lp55xx_device_config lp5521_cfg = {
+       .reset = {
+               .addr = LP5521_REG_RESET,
+               .val  = LP5521_RESET,
+       },
+};
+
 static int lp5521_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
@@ -881,6 +878,7 @@ static int lp5521_probe(struct i2c_client *client,
 
        chip->cl = client;
        chip->pdata = pdata;
+       chip->cfg = &lp5521_cfg;
 
        mutex_init(&chip->lock);
 
index 8e602047ce35665f6ddfb80e8a8b5e1fe4b19cc7..00547783db77256fa103b8b8e2c91d490239ddfa 100644 (file)
@@ -87,6 +87,7 @@
 #define LP5523_AUTO_CLK                        0x02
 #define LP5523_EN_LEDTEST              0x80
 #define LP5523_LEDTEST_DONE            0x80
+#define LP5523_RESET                   0xFF
 
 #define LP5523_DEFAULT_CURRENT         50 /* microAmps */
 #define LP5523_PROGRAM_LENGTH          32 /* in bytes */
@@ -900,25 +901,12 @@ static void lp5523_unregister_leds(struct lp5523_chip *chip)
        }
 }
 
-static void lp5523_reset_device(struct lp5523_chip *chip)
-{
-       struct i2c_client *client = chip->client;
-
-       lp5523_write(client, LP5523_REG_RESET, 0xff);
-}
-
 static void lp5523_deinit_device(struct lp5523_chip *chip);
 static int lp5523_init_device(struct lp5523_chip *chip)
 {
        struct i2c_client *client = chip->client;
        int ret;
 
-       lp5523_reset_device(chip);
-
-       usleep_range(10000, 20000); /*
-                                    * Exact value is not available. 10 - 20ms
-                                    * appears to be enough for reset.
-                                    */
        ret = lp5523_detect(client);
        if (ret)
                goto err;
@@ -947,6 +935,14 @@ static void lp5523_deinit_device(struct lp5523_chip *chip)
                pdata->release_resources();
 }
 
+/* Chip specific configurations */
+static struct lp55xx_device_config lp5523_cfg = {
+       .reset = {
+               .addr = LP5523_REG_RESET,
+               .val  = LP5523_RESET,
+       },
+};
+
 static int lp5523_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
@@ -972,6 +968,7 @@ static int lp5523_probe(struct i2c_client *client,
 
        chip->cl = client;
        chip->pdata = pdata;
+       chip->cfg = &lp5523_cfg;
 
        mutex_init(&chip->lock);
 
index 05a854c0d9b2abee655d93cab63e97b4e7e80305..bbf2bbf03807e727e274bd96d4a6960854297d65 100644 (file)
 
 #include "leds-lp55xx-common.h"
 
+static void lp55xx_reset_device(struct lp55xx_chip *chip)
+{
+       struct lp55xx_device_config *cfg = chip->cfg;
+       u8 addr = cfg->reset.addr;
+       u8 val  = cfg->reset.val;
+
+       /* no error checking here because no ACK from the device after reset */
+       lp55xx_write(chip, addr, val);
+}
+
 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
 {
        return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -58,14 +68,16 @@ EXPORT_SYMBOL_GPL(lp55xx_update_bits);
 int lp55xx_init_device(struct lp55xx_chip *chip)
 {
        struct lp55xx_platform_data *pdata;
+       struct lp55xx_device_config *cfg;
        struct device *dev = &chip->cl->dev;
        int ret = 0;
 
        WARN_ON(!chip);
 
        pdata = chip->pdata;
+       cfg = chip->cfg;
 
-       if (!pdata)
+       if (!pdata || !cfg)
                return -EINVAL;
 
        if (pdata->setup_resources) {
@@ -83,6 +95,14 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
                usleep_range(1000, 2000); /* 500us abs min. */
        }
 
+       lp55xx_reset_device(chip);
+
+       /*
+        * Exact value is not available. 10 - 20ms
+        * appears to be enough for reset.
+        */
+       usleep_range(10000, 20000);
+
 err:
        return ret;
 }
index 09d1882ce58e81ee8dc26072b739b346e262bb0e..a73ee0b9a0bdeea8ab997584535f4dee2318150e 100644 (file)
 struct lp55xx_led;
 struct lp55xx_chip;
 
+/*
+ * struct lp55xx_reg
+ * @addr : Register address
+ * @val  : Register value
+ */
+struct lp55xx_reg {
+       u8 addr;
+       u8 val;
+};
+
+/*
+ * struct lp55xx_device_config
+ * @reset              : Chip specific reset command
+ */
+struct lp55xx_device_config {
+       const struct lp55xx_reg reset;
+};
+
 /*
  * struct lp55xx_chip
  * @cl         : I2C communication for access registers
  * @pdata      : Platform specific data
  * @lock       : Lock for user-space interface
  * @num_leds   : Number of registered LEDs
+ * @cfg        : Device specific configuration data
  */
 struct lp55xx_chip {
        struct i2c_client *cl;
        struct lp55xx_platform_data *pdata;
        struct mutex lock;      /* lock for user-space interface */
        int num_leds;
+       struct lp55xx_device_config *cfg;
 };
 
 /*