[PATCH v3 14/39] leds-lp55xx: use lp55xx common init function - detect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 LP5521/5523 chip detection functions are replaced with lp55xx common function,
 lp55xx_detect_device().
 Chip dependant address and values are configurable in each driver.
 In init function, chip detection is executed.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@xxxxxx>
---
 drivers/leds/leds-lp5521.c        |   30 ++++--------------------------
 drivers/leds/leds-lp5523.c        |   25 ++++---------------------
 drivers/leds/leds-lp55xx-common.c |   29 +++++++++++++++++++++++++++++
 drivers/leds/leds-lp55xx-common.h |    2 ++
 4 files changed, 39 insertions(+), 47 deletions(-)

diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index a1c15e5..c1511f0 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -328,26 +328,6 @@ static void lp5521_led_brightness_work(struct work_struct *work)
 	mutex_unlock(&chip->lock);
 }
 
-/* Detect the chip by setting its ENABLE register and reading it back. */
-static int lp5521_detect(struct i2c_client *client)
-{
-	int ret;
-	u8 buf;
-
-	ret = lp5521_write(client, LP5521_REG_ENABLE, LP5521_ENABLE_DEFAULT);
-	if (ret)
-		return ret;
-	/* enable takes 500us. 1 - 2 ms leaves some margin */
-	usleep_range(1000, 2000);
-	ret = lp5521_read(client, LP5521_REG_ENABLE, &buf);
-	if (ret)
-		return ret;
-	if (buf != LP5521_ENABLE_DEFAULT)
-		return -ENODEV;
-
-	return 0;
-}
-
 /* Set engine mode and create appropriate sysfs attributes, if required. */
 static int lp5521_set_mode(struct lp5521_engine *engine, u8 mode)
 {
@@ -718,12 +698,6 @@ static int lp5521_init_device(struct lp5521_chip *chip)
 	struct i2c_client *client = chip->client;
 	int ret;
 
-	ret = lp5521_detect(client);
-	if (ret) {
-		dev_err(&client->dev, "Chip not found\n");
-		goto err;
-	}
-
 	ret = lp5521_configure(client);
 	if (ret < 0) {
 		dev_err(&client->dev, "error configuring chip\n");
@@ -851,6 +825,10 @@ static struct lp55xx_device_config lp5521_cfg = {
 		.addr = LP5521_REG_RESET,
 		.val  = LP5521_RESET,
 	},
+	.enable = {
+		.addr = LP5521_REG_ENABLE,
+		.val  = LP5521_ENABLE_DEFAULT,
+	},
 };
 
 static int lp5521_probe(struct i2c_client *client,
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index de15a9e..ca8d102 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -181,23 +181,6 @@ static int lp5523_read(struct i2c_client *client, u8 reg, u8 *buf)
 	return 0;
 }
 
-static int lp5523_detect(struct i2c_client *client)
-{
-	int ret;
-	u8 buf;
-
-	ret = lp5523_write(client, LP5523_REG_ENABLE, LP5523_ENABLE);
-	if (ret)
-		return ret;
-	ret = lp5523_read(client, LP5523_REG_ENABLE, &buf);
-	if (ret)
-		return ret;
-	if (buf == 0x40)
-		return 0;
-	else
-		return -ENODEV;
-}
-
 static int lp5523_configure(struct i2c_client *client)
 {
 	int ret = 0;
@@ -907,10 +890,6 @@ static int lp5523_init_device(struct lp5523_chip *chip)
 	struct i2c_client *client = chip->client;
 	int ret;
 
-	ret = lp5523_detect(client);
-	if (ret)
-		goto err;
-
 	ret = lp5523_configure(client);
 	if (ret < 0) {
 		dev_err(&client->dev, "error configuring chip\n");
@@ -941,6 +920,10 @@ static struct lp55xx_device_config lp5523_cfg = {
 		.addr = LP5523_REG_RESET,
 		.val  = LP5523_RESET,
 	},
+	.enable = {
+		.addr = LP5523_REG_ENABLE,
+		.val  = LP5523_ENABLE,
+	},
 };
 
 static int lp5523_probe(struct i2c_client *client,
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 26ce312..4bcea18 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -30,6 +30,29 @@ static void lp55xx_reset_device(struct lp55xx_chip *chip)
 	lp55xx_write(chip, addr, val);
 }
 
+static int lp55xx_detect_device(struct lp55xx_chip *chip)
+{
+	struct lp55xx_device_config *cfg = chip->cfg;
+	u8 addr = cfg->enable.addr;
+	u8 val  = cfg->enable.val;
+	int ret;
+
+	ret = lp55xx_write(chip, addr, val);
+	if (ret)
+		return ret;
+
+	usleep_range(1000, 2000);
+
+	ret = lp55xx_read(chip, addr, &val);
+	if (ret)
+		return ret;
+
+	if (val != cfg->enable.val)
+		return -ENODEV;
+
+	return 0;
+}
+
 int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
 {
 	return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -103,6 +126,12 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
 	 */
 	usleep_range(10000, 20000);
 
+	ret = lp55xx_detect_device(chip);
+	if (ret) {
+		dev_err(dev, "device detection err: %d\n", ret);
+		goto err;
+	}
+
 err:
 	return ret;
 }
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index a73ee0b..8175301 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -31,9 +31,11 @@ struct lp55xx_reg {
 /*
  * struct lp55xx_device_config
  * @reset              : Chip specific reset command
+ * @enable             : Chip specific enable command
  */
 struct lp55xx_device_config {
 	const struct lp55xx_reg reset;
+	const struct lp55xx_reg enable;
 };
 
 /*
-- 
1.7.9.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-leds" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux