21 #include <linux/errno.h>
23 #include <linux/module.h>
27 #define BAT_POLL_INTERVAL 10000
28 #define JITTER_DELAY 500
44 static void s3c_adc_bat_ext_power_changed(
struct power_supply *psy)
59 for (i = 0; i < num; i++)
72 static int s3c_adc_backup_bat_get_property(
struct power_supply *psy,
79 dev_err(psy->
dev,
"%s: no battery infos ?!\n", __func__);
87 bat->
pdata->backup_volt_samples,
88 bat->
pdata->backup_volt_channel);
110 .name =
"backup-battery",
112 .properties = s3c_adc_backup_bat_props,
113 .num_properties =
ARRAY_SIZE(s3c_adc_backup_bat_props),
114 .get_property = s3c_adc_backup_bat_get_property,
128 static int calc_full_volt(
int volt_val,
int cur_val,
int impedance)
130 return volt_val + cur_val * impedance / 1000;
133 static int charge_finished(
struct s3c_adc_bat *bat)
135 return bat->
pdata->gpio_inverted ?
140 static int s3c_adc_bat_get_property(
struct power_supply *psy,
149 unsigned int lut_size = bat->
pdata->lut_noac_cnt;
160 bat->
pdata->volt_samples,
161 bat->
pdata->volt_channel) * bat->
pdata->volt_mult;
163 bat->
pdata->current_samples,
164 bat->
pdata->current_channel) * bat->
pdata->current_mult;
169 ((bat->
pdata->gpio_charge_finished < 0) ||
170 !charge_finished(bat))) {
171 lut = bat->
pdata->lut_acin;
172 lut_size = bat->
pdata->lut_acin_cnt;
176 full_volt = calc_full_volt((bat->
volt_value / 1000),
179 if (full_volt < calc_full_volt(lut->
volt, lut->
cur,
180 bat->
pdata->internal_impedance)) {
186 lut_volt1 = calc_full_volt(lut[0].
volt, lut[0].
cur,
187 bat->
pdata->internal_impedance);
188 lut_volt2 = calc_full_volt(lut[1].
volt, lut[1].
cur,
189 bat->
pdata->internal_impedance);
190 if (full_volt < lut_volt1 && full_volt >= lut_volt2) {
191 new_level = (lut[1].
level +
193 (full_volt - lut_volt2) /
194 (lut_volt1 - lut_volt2)) * 1000;
197 new_level = lut[1].
level * 1000;
202 bat->
level = new_level;
206 if (bat->
pdata->gpio_charge_finished < 0)
234 .name =
"main-battery",
236 .properties = s3c_adc_main_bat_props,
237 .num_properties =
ARRAY_SIZE(s3c_adc_main_bat_props),
238 .get_property = s3c_adc_bat_get_property,
239 .external_power_changed = s3c_adc_bat_ext_power_changed,
249 static int was_plugged;
253 if (is_plugged != was_plugged) {
254 was_plugged = is_plugged;
256 if (bat->
pdata->enable_charger)
257 bat->
pdata->enable_charger();
260 if (bat->
pdata->disable_charger)
261 bat->
pdata->disable_charger();
265 if ((bat->
pdata->gpio_charge_finished >= 0) && is_plugged) {
266 is_charged = charge_finished(&main_bat);
268 if (bat->
pdata->disable_charger)
269 bat->
pdata->disable_charger();
272 if (bat->
pdata->enable_charger)
273 bat->
pdata->enable_charger();
296 if (IS_ERR(client)) {
298 return PTR_ERR(client);
301 platform_set_drvdata(pdev, client);
315 backup_bat.
pdata = pdev->
dev.platform_data;
332 "battery charged",
NULL);
398 if (device_may_wakeup(&pdev->
dev))
403 main_bat.
pdata->disable_charger();
415 if (device_may_wakeup(&pdev->
dev))
429 #define s3c_adc_bat_suspend NULL
430 #define s3c_adc_bat_resume NULL
435 .name =
"s3c-adc-battery",
437 .probe = s3c_adc_bat_probe,
438 .remove = s3c_adc_bat_remove,