22 #include <linux/module.h>
27 #include <linux/slab.h>
32 #include "../w1/slaves/w1_ds2760.h"
63 static unsigned int cache_time = 1000;
67 static bool pmod_enabled;
71 static unsigned int rated_capacity;
75 static unsigned int current_accum;
81 static int rated_capacities[] = {
89 #ifdef CONFIG_MACH_H4700
99 #ifdef CONFIG_MACH_H4700
107 static int battery_interpolate(
int array[],
int temp)
119 return array[
index] + (((array[index + 1] - array[
index]) * dt) / 10);
142 dev_warn(di->
dev,
"call to w1_ds2760_read failed (0x%p)\n",
196 for (i = 1; i < 5; i++)
204 for (i = 3; i >= 0; i--)
233 unsigned int acr_val)
235 unsigned char acr[2];
241 acr[0] = acr_val >> 8;
242 acr[1] = acr_val & 0xff;
252 ds2760_battery_read_status(di);
263 dev_notice(di->
dev,
"not enough power to "
280 ds2760_battery_set_current_accum(di,
305 unsigned char rated_capacity)
318 unsigned char tmp[2] = {
345 ds2760_battery_update_status(di);
349 #define to_ds2760_device_info(x) container_of((x), struct ds2760_device_info, \
352 static void ds2760_battery_external_power_changed(
struct power_supply *psy)
370 ds2760_battery_read_status(di);
386 dev_dbg(di->
dev,
"%s: bias = %d\n", __func__, bias);
397 static void ds2760_battery_set_charged(
struct power_supply *psy)
406 static int ds2760_battery_get_property(
struct power_supply *psy,
420 ds2760_battery_read_status(di);
457 static int ds2760_battery_set_property(
struct power_supply *psy,
466 ds2760_battery_write_active_full(di, val->
intval / 1000L);
471 ds2760_battery_set_current_accum(di, val->
intval);
481 static int ds2760_battery_property_is_writeable(
struct power_supply *psy,
518 goto di_alloc_failed;
521 platform_set_drvdata(pdev, di);
525 di->
bat.name = dev_name(&pdev->
dev);
527 di->
bat.properties = ds2760_battery_props;
529 di->
bat.get_property = ds2760_battery_get_property;
530 di->
bat.set_property = ds2760_battery_set_property;
531 di->
bat.property_is_writeable =
532 ds2760_battery_property_is_writeable;
533 di->
bat.set_charged = ds2760_battery_set_charged;
534 di->
bat.external_power_changed =
535 ds2760_battery_external_power_changed;
540 ds2760_battery_read_status(di);
547 ds2760_battery_write_status(di, status);
551 ds2760_battery_write_rated_capacity(di, rated_capacity);
556 ds2760_battery_set_current_accum(di, current_accum);
560 dev_err(di->
dev,
"failed to register battery\n");
566 ds2760_battery_set_charged_work);
570 goto workqueue_failed;
624 #define ds2760_battery_suspend NULL
625 #define ds2760_battery_resume NULL
633 .name =
"ds2760-battery",
635 .probe = ds2760_battery_probe,
636 .remove = ds2760_battery_remove,