aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorMilo(Woogyom) Kim <milo.kim@ti.com>2013-02-05 04:08:49 -0500
committerBryan Wu <cooloney@gmail.com>2013-02-06 18:59:27 -0500
commit48068d5de16c23c256c085b2cd3ff03bec393900 (patch)
tree08307d1f09040ef20677b15db0a21113a3ba7842 /drivers/leds
parenta85908dd7799e4fa242812ce27a8f774c721d1fb (diff)
leds-lp55xx: use lp55xx common init function - reset
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>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-lp5521.c26
-rw-r--r--drivers/leds/leds-lp5523.c23
-rw-r--r--drivers/leds/leds-lp55xx-common.c22
-rw-r--r--drivers/leds/leds-lp55xx-common.h20
4 files changed, 63 insertions, 28 deletions
diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c
index 124ce80fa115..e1f1dfcd1547 100644
--- a/drivers/leds/leds-lp5521.c
+++ b/drivers/leds/leds-lp5521.c
@@ -98,6 +98,9 @@
98/* Pattern Mode */ 98/* Pattern Mode */
99#define PATTERN_OFF 0 99#define PATTERN_OFF 0
100 100
101/* Reset register value */
102#define LP5521_RESET 0xFF
103
101struct lp5521_engine { 104struct lp5521_engine {
102 int id; 105 int id;
103 u8 mode; 106 u8 mode;
@@ -709,26 +712,12 @@ static void lp5521_unregister_sysfs(struct i2c_client *client)
709 &lp5521_led_attribute_group); 712 &lp5521_led_attribute_group);
710} 713}
711 714
712static void lp5521_reset_device(struct lp5521_chip *chip)
713{
714 struct i2c_client *client = chip->client;
715
716 lp5521_write(client, LP5521_REG_RESET, 0xff);
717}
718
719static void lp5521_deinit_device(struct lp5521_chip *chip); 715static void lp5521_deinit_device(struct lp5521_chip *chip);
720static int lp5521_init_device(struct lp5521_chip *chip) 716static int lp5521_init_device(struct lp5521_chip *chip)
721{ 717{
722 struct i2c_client *client = chip->client; 718 struct i2c_client *client = chip->client;
723 int ret; 719 int ret;
724 720
725 lp5521_reset_device(chip);
726
727 usleep_range(10000, 20000); /*
728 * Exact value is not available. 10 - 20ms
729 * appears to be enough for reset.
730 */
731
732 ret = lp5521_detect(client); 721 ret = lp5521_detect(client);
733 if (ret) { 722 if (ret) {
734 dev_err(&client->dev, "Chip not found\n"); 723 dev_err(&client->dev, "Chip not found\n");
@@ -856,6 +845,14 @@ static void lp5521_unregister_leds(struct lp5521_chip *chip)
856 } 845 }
857} 846}
858 847
848/* Chip specific configurations */
849static struct lp55xx_device_config lp5521_cfg = {
850 .reset = {
851 .addr = LP5521_REG_RESET,
852 .val = LP5521_RESET,
853 },
854};
855
859static int lp5521_probe(struct i2c_client *client, 856static int lp5521_probe(struct i2c_client *client,
860 const struct i2c_device_id *id) 857 const struct i2c_device_id *id)
861{ 858{
@@ -881,6 +878,7 @@ static int lp5521_probe(struct i2c_client *client,
881 878
882 chip->cl = client; 879 chip->cl = client;
883 chip->pdata = pdata; 880 chip->pdata = pdata;
881 chip->cfg = &lp5521_cfg;
884 882
885 mutex_init(&chip->lock); 883 mutex_init(&chip->lock);
886 884
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 8e602047ce35..00547783db77 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -87,6 +87,7 @@
87#define LP5523_AUTO_CLK 0x02 87#define LP5523_AUTO_CLK 0x02
88#define LP5523_EN_LEDTEST 0x80 88#define LP5523_EN_LEDTEST 0x80
89#define LP5523_LEDTEST_DONE 0x80 89#define LP5523_LEDTEST_DONE 0x80
90#define LP5523_RESET 0xFF
90 91
91#define LP5523_DEFAULT_CURRENT 50 /* microAmps */ 92#define LP5523_DEFAULT_CURRENT 50 /* microAmps */
92#define LP5523_PROGRAM_LENGTH 32 /* in bytes */ 93#define LP5523_PROGRAM_LENGTH 32 /* in bytes */
@@ -900,25 +901,12 @@ static void lp5523_unregister_leds(struct lp5523_chip *chip)
900 } 901 }
901} 902}
902 903
903static void lp5523_reset_device(struct lp5523_chip *chip)
904{
905 struct i2c_client *client = chip->client;
906
907 lp5523_write(client, LP5523_REG_RESET, 0xff);
908}
909
910static void lp5523_deinit_device(struct lp5523_chip *chip); 904static void lp5523_deinit_device(struct lp5523_chip *chip);
911static int lp5523_init_device(struct lp5523_chip *chip) 905static int lp5523_init_device(struct lp5523_chip *chip)
912{ 906{
913 struct i2c_client *client = chip->client; 907 struct i2c_client *client = chip->client;
914 int ret; 908 int ret;
915 909
916 lp5523_reset_device(chip);
917
918 usleep_range(10000, 20000); /*
919 * Exact value is not available. 10 - 20ms
920 * appears to be enough for reset.
921 */
922 ret = lp5523_detect(client); 910 ret = lp5523_detect(client);
923 if (ret) 911 if (ret)
924 goto err; 912 goto err;
@@ -947,6 +935,14 @@ static void lp5523_deinit_device(struct lp5523_chip *chip)
947 pdata->release_resources(); 935 pdata->release_resources();
948} 936}
949 937
938/* Chip specific configurations */
939static struct lp55xx_device_config lp5523_cfg = {
940 .reset = {
941 .addr = LP5523_REG_RESET,
942 .val = LP5523_RESET,
943 },
944};
945
950static int lp5523_probe(struct i2c_client *client, 946static int lp5523_probe(struct i2c_client *client,
951 const struct i2c_device_id *id) 947 const struct i2c_device_id *id)
952{ 948{
@@ -972,6 +968,7 @@ static int lp5523_probe(struct i2c_client *client,
972 968
973 chip->cl = client; 969 chip->cl = client;
974 chip->pdata = pdata; 970 chip->pdata = pdata;
971 chip->cfg = &lp5523_cfg;
975 972
976 mutex_init(&chip->lock); 973 mutex_init(&chip->lock);
977 974
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 05a854c0d9b2..bbf2bbf03807 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -20,6 +20,16 @@
20 20
21#include "leds-lp55xx-common.h" 21#include "leds-lp55xx-common.h"
22 22
23static void lp55xx_reset_device(struct lp55xx_chip *chip)
24{
25 struct lp55xx_device_config *cfg = chip->cfg;
26 u8 addr = cfg->reset.addr;
27 u8 val = cfg->reset.val;
28
29 /* no error checking here because no ACK from the device after reset */
30 lp55xx_write(chip, addr, val);
31}
32
23int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val) 33int lp55xx_write(struct lp55xx_chip *chip, u8 reg, u8 val)
24{ 34{
25 return i2c_smbus_write_byte_data(chip->cl, reg, val); 35 return i2c_smbus_write_byte_data(chip->cl, reg, val);
@@ -58,14 +68,16 @@ EXPORT_SYMBOL_GPL(lp55xx_update_bits);
58int lp55xx_init_device(struct lp55xx_chip *chip) 68int lp55xx_init_device(struct lp55xx_chip *chip)
59{ 69{
60 struct lp55xx_platform_data *pdata; 70 struct lp55xx_platform_data *pdata;
71 struct lp55xx_device_config *cfg;
61 struct device *dev = &chip->cl->dev; 72 struct device *dev = &chip->cl->dev;
62 int ret = 0; 73 int ret = 0;
63 74
64 WARN_ON(!chip); 75 WARN_ON(!chip);
65 76
66 pdata = chip->pdata; 77 pdata = chip->pdata;
78 cfg = chip->cfg;
67 79
68 if (!pdata) 80 if (!pdata || !cfg)
69 return -EINVAL; 81 return -EINVAL;
70 82
71 if (pdata->setup_resources) { 83 if (pdata->setup_resources) {
@@ -83,6 +95,14 @@ int lp55xx_init_device(struct lp55xx_chip *chip)
83 usleep_range(1000, 2000); /* 500us abs min. */ 95 usleep_range(1000, 2000); /* 500us abs min. */
84 } 96 }
85 97
98 lp55xx_reset_device(chip);
99
100 /*
101 * Exact value is not available. 10 - 20ms
102 * appears to be enough for reset.
103 */
104 usleep_range(10000, 20000);
105
86err: 106err:
87 return ret; 107 return ret;
88} 108}
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index 09d1882ce58e..a73ee0b9a0bd 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -19,17 +19,37 @@ struct lp55xx_led;
19struct lp55xx_chip; 19struct lp55xx_chip;
20 20
21/* 21/*
22 * struct lp55xx_reg
23 * @addr : Register address
24 * @val : Register value
25 */
26struct lp55xx_reg {
27 u8 addr;
28 u8 val;
29};
30
31/*
32 * struct lp55xx_device_config
33 * @reset : Chip specific reset command
34 */
35struct lp55xx_device_config {
36 const struct lp55xx_reg reset;
37};
38
39/*
22 * struct lp55xx_chip 40 * struct lp55xx_chip
23 * @cl : I2C communication for access registers 41 * @cl : I2C communication for access registers
24 * @pdata : Platform specific data 42 * @pdata : Platform specific data
25 * @lock : Lock for user-space interface 43 * @lock : Lock for user-space interface
26 * @num_leds : Number of registered LEDs 44 * @num_leds : Number of registered LEDs
45 * @cfg : Device specific configuration data
27 */ 46 */
28struct lp55xx_chip { 47struct lp55xx_chip {
29 struct i2c_client *cl; 48 struct i2c_client *cl;
30 struct lp55xx_platform_data *pdata; 49 struct lp55xx_platform_data *pdata;
31 struct mutex lock; /* lock for user-space interface */ 50 struct mutex lock; /* lock for user-space interface */
32 int num_leds; 51 int num_leds;
52 struct lp55xx_device_config *cfg;
33}; 53};
34 54
35/* 55/*