diff options
-rw-r--r-- | drivers/power/supply/max17040_battery.c | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c index 8689c80202b5..e7c3649b31a0 100644 --- a/drivers/power/supply/max17040_battery.c +++ b/drivers/power/supply/max17040_battery.c | |||
@@ -21,18 +21,13 @@ | |||
21 | #include <linux/max17040_battery.h> | 21 | #include <linux/max17040_battery.h> |
22 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
23 | 23 | ||
24 | #define MAX17040_VCELL_MSB 0x02 | 24 | #define MAX17040_VCELL 0x02 |
25 | #define MAX17040_VCELL_LSB 0x03 | 25 | #define MAX17040_SOC 0x04 |
26 | #define MAX17040_SOC_MSB 0x04 | 26 | #define MAX17040_MODE 0x06 |
27 | #define MAX17040_SOC_LSB 0x05 | 27 | #define MAX17040_VER 0x08 |
28 | #define MAX17040_MODE_MSB 0x06 | 28 | #define MAX17040_RCOMP 0x0C |
29 | #define MAX17040_MODE_LSB 0x07 | 29 | #define MAX17040_CMD 0xFE |
30 | #define MAX17040_VER_MSB 0x08 | 30 | |
31 | #define MAX17040_VER_LSB 0x09 | ||
32 | #define MAX17040_RCOMP_MSB 0x0C | ||
33 | #define MAX17040_RCOMP_LSB 0x0D | ||
34 | #define MAX17040_CMD_MSB 0xFE | ||
35 | #define MAX17040_CMD_LSB 0xFF | ||
36 | 31 | ||
37 | #define MAX17040_DELAY 1000 | 32 | #define MAX17040_DELAY 1000 |
38 | #define MAX17040_BATTERY_FULL 95 | 33 | #define MAX17040_BATTERY_FULL 95 |
@@ -78,11 +73,11 @@ static int max17040_get_property(struct power_supply *psy, | |||
78 | return 0; | 73 | return 0; |
79 | } | 74 | } |
80 | 75 | ||
81 | static int max17040_write_reg(struct i2c_client *client, int reg, u8 value) | 76 | static int max17040_write_reg(struct i2c_client *client, int reg, u16 value) |
82 | { | 77 | { |
83 | int ret; | 78 | int ret; |
84 | 79 | ||
85 | ret = i2c_smbus_write_byte_data(client, reg, value); | 80 | ret = i2c_smbus_write_word_swapped(client, reg, value); |
86 | 81 | ||
87 | if (ret < 0) | 82 | if (ret < 0) |
88 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); | 83 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); |
@@ -94,7 +89,7 @@ static int max17040_read_reg(struct i2c_client *client, int reg) | |||
94 | { | 89 | { |
95 | int ret; | 90 | int ret; |
96 | 91 | ||
97 | ret = i2c_smbus_read_byte_data(client, reg); | 92 | ret = i2c_smbus_read_word_swapped(client, reg); |
98 | 93 | ||
99 | if (ret < 0) | 94 | if (ret < 0) |
100 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); | 95 | dev_err(&client->dev, "%s: err %d\n", __func__, ret); |
@@ -104,43 +99,36 @@ static int max17040_read_reg(struct i2c_client *client, int reg) | |||
104 | 99 | ||
105 | static void max17040_reset(struct i2c_client *client) | 100 | static void max17040_reset(struct i2c_client *client) |
106 | { | 101 | { |
107 | max17040_write_reg(client, MAX17040_CMD_MSB, 0x54); | 102 | max17040_write_reg(client, MAX17040_CMD, 0x0054); |
108 | max17040_write_reg(client, MAX17040_CMD_LSB, 0x00); | ||
109 | } | 103 | } |
110 | 104 | ||
111 | static void max17040_get_vcell(struct i2c_client *client) | 105 | static void max17040_get_vcell(struct i2c_client *client) |
112 | { | 106 | { |
113 | struct max17040_chip *chip = i2c_get_clientdata(client); | 107 | struct max17040_chip *chip = i2c_get_clientdata(client); |
114 | u8 msb; | 108 | u16 vcell; |
115 | u8 lsb; | ||
116 | 109 | ||
117 | msb = max17040_read_reg(client, MAX17040_VCELL_MSB); | 110 | vcell = max17040_read_reg(client, MAX17040_VCELL); |
118 | lsb = max17040_read_reg(client, MAX17040_VCELL_LSB); | ||
119 | 111 | ||
120 | chip->vcell = (msb << 4) + (lsb >> 4); | 112 | chip->vcell = vcell; |
121 | } | 113 | } |
122 | 114 | ||
123 | static void max17040_get_soc(struct i2c_client *client) | 115 | static void max17040_get_soc(struct i2c_client *client) |
124 | { | 116 | { |
125 | struct max17040_chip *chip = i2c_get_clientdata(client); | 117 | struct max17040_chip *chip = i2c_get_clientdata(client); |
126 | u8 msb; | 118 | u16 soc; |
127 | u8 lsb; | ||
128 | 119 | ||
129 | msb = max17040_read_reg(client, MAX17040_SOC_MSB); | 120 | soc = max17040_read_reg(client, MAX17040_SOC); |
130 | lsb = max17040_read_reg(client, MAX17040_SOC_LSB); | ||
131 | 121 | ||
132 | chip->soc = msb; | 122 | chip->soc = (soc >> 8); |
133 | } | 123 | } |
134 | 124 | ||
135 | static void max17040_get_version(struct i2c_client *client) | 125 | static void max17040_get_version(struct i2c_client *client) |
136 | { | 126 | { |
137 | u8 msb; | 127 | u16 version; |
138 | u8 lsb; | ||
139 | 128 | ||
140 | msb = max17040_read_reg(client, MAX17040_VER_MSB); | 129 | version = max17040_read_reg(client, MAX17040_VER); |
141 | lsb = max17040_read_reg(client, MAX17040_VER_LSB); | ||
142 | 130 | ||
143 | dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver %d%d\n", msb, lsb); | 131 | dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", version); |
144 | } | 132 | } |
145 | 133 | ||
146 | static void max17040_get_online(struct i2c_client *client) | 134 | static void max17040_get_online(struct i2c_client *client) |