12 #include <linux/module.h>
14 #include <linux/i2c.h>
18 #include <linux/slab.h>
21 #define Z2_DEFAULT_NAME "Z2"
32 static unsigned long z2_read_bat(
struct z2_charger *charger)
36 charger->
info->batt_I2C_reg);
40 return data * charger->
info->batt_mult / charger->
info->batt_div;
43 static int z2_batt_get_property(
struct power_supply *batt_ps,
60 val->
intval = z2_read_bat(charger);
86 static void z2_batt_ext_power_changed(
struct power_supply *batt_ps)
93 static void z2_batt_update(
struct z2_charger *charger)
121 z2_batt_update(charger);
131 static int z2_batt_ps_init(
struct z2_charger *charger,
int props)
148 prop = kzalloc(props *
sizeof(*prop),
GFP_KERNEL);
166 "Please consider setting proper battery "
167 "name in platform definition file, falling "
168 "back to name \" Z2_DEFAULT_NAME \"\n");
173 charger->
batt_ps.properties = prop;
174 charger->
batt_ps.num_properties = props;
176 charger->
batt_ps.get_property = z2_batt_get_property;
177 charger->
batt_ps.external_power_changed = z2_batt_ext_power_changed;
178 charger->
batt_ps.use_for_apm = 1;
193 "Please set platform device platform_data"
194 " to a valid z2_battery_info pointer!\n");
198 charger = kzalloc(
sizeof(*charger),
GFP_KERNEL);
205 i2c_set_clientdata(client, charger);
221 z2_charge_switch_irq, 0,
222 "AC Detect", charger);
227 ret = z2_batt_ps_init(charger, props);
256 struct z2_charger *charger = i2c_get_clientdata(client);
274 static int z2_batt_suspend(
struct device *
dev)
277 struct z2_charger *charger = i2c_get_clientdata(client);
283 static int z2_batt_resume(
struct device *
dev)
286 struct z2_charger *charger = i2c_get_clientdata(client);
292 static const struct dev_pm_ops z2_battery_pm_ops = {
294 .resume = z2_batt_resume,
297 #define Z2_BATTERY_PM_OPS (&z2_battery_pm_ops)
300 #define Z2_BATTERY_PM_OPS (NULL)
311 .name =
"z2-battery",
315 .probe = z2_batt_probe,
317 .id_table = z2_batt_id,