13 #include <linux/module.h>
18 #include <linux/i2c.h>
22 #include <linux/slab.h>
24 #define MAX17040_VCELL_MSB 0x02
25 #define MAX17040_VCELL_LSB 0x03
26 #define MAX17040_SOC_MSB 0x04
27 #define MAX17040_SOC_LSB 0x05
28 #define MAX17040_MODE_MSB 0x06
29 #define MAX17040_MODE_LSB 0x07
30 #define MAX17040_VER_MSB 0x08
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
37 #define MAX17040_DELAY 1000
38 #define MAX17040_BATTERY_FULL 95
56 static int max17040_get_property(
struct power_supply *psy,
89 dev_err(&client->
dev,
"%s: err %d\n", __func__, ret);
94 static int max17040_read_reg(
struct i2c_client *client,
int reg)
101 dev_err(&client->
dev,
"%s: err %d\n", __func__, ret);
106 static void max17040_reset(
struct i2c_client *client)
112 static void max17040_get_vcell(
struct i2c_client *client)
124 static void max17040_get_soc(
struct i2c_client *client)
136 static void max17040_get_version(
struct i2c_client *client)
144 dev_info(&client->
dev,
"MAX17040 Fuel-Gauge Ver %d%d\n", msb, lsb);
147 static void max17040_get_online(
struct i2c_client *client)
151 if (chip->
pdata->battery_online)
157 static void max17040_get_status(
struct i2c_client *client)
161 if (!chip->
pdata->charger_online || !chip->
pdata->charger_enable) {
166 if (chip->
pdata->charger_online()) {
167 if (chip->
pdata->charger_enable())
185 max17040_get_vcell(chip->
client);
186 max17040_get_soc(chip->
client);
187 max17040_get_online(chip->
client);
188 max17040_get_status(chip->
client);
215 chip->
pdata = client->
dev.platform_data;
217 i2c_set_clientdata(client, chip);
219 chip->
battery.name =
"battery";
221 chip->
battery.get_property = max17040_get_property;
222 chip->
battery.properties = max17040_battery_props;
227 dev_err(&client->
dev,
"failed: power supply register\n");
232 max17040_reset(client);
233 max17040_get_version(client);
272 #define max17040_suspend NULL
273 #define max17040_resume NULL
283 static struct i2c_driver max17040_i2c_driver = {
287 .probe = max17040_probe,
291 .id_table = max17040_id,