Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 283483
b: refs/heads/master
c: 34aed73
h: refs/heads/master
i:
  283481: 8230abb
  283479: 7e966c1
v: v3
  • Loading branch information
Heiko Stübner authored and Anton Vorontsov committed Jan 6, 2012
1 parent 2221efa commit ccb9ed1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ded7fc7b055055427d0d04958482dbe3d23e087d
refs/heads/master: 34aed73df3a9e75e313a7510b201f6755ae3e6bc
25 changes: 22 additions & 3 deletions trunk/drivers/power/s3c_adc_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ static void s3c_adc_bat_ext_power_changed(struct power_supply *psy)
msecs_to_jiffies(JITTER_DELAY));
}

static int gather_samples(struct s3c_adc_client *client, int num, int channel)
{
int value, i;

/* default to 1 if nothing is set */
if (num < 1)
num = 1;

value = 0;
for (i = 0; i < num; i++)
value += s3c_adc_read(client, channel);
value /= num;

return value;
}

static enum power_supply_property s3c_adc_backup_bat_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_MIN,
Expand All @@ -67,7 +83,8 @@ static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
if (bat->volt_value < 0 ||
jiffies_to_msecs(jiffies - bat->timestamp) >
BAT_POLL_INTERVAL) {
bat->volt_value = s3c_adc_read(bat->client,
bat->volt_value = gather_samples(bat->client,
bat->pdata->backup_volt_samples,
bat->pdata->backup_volt_channel);
bat->volt_value *= bat->pdata->backup_volt_mult;
bat->timestamp = jiffies;
Expand Down Expand Up @@ -139,9 +156,11 @@ static int s3c_adc_bat_get_property(struct power_supply *psy,
if (bat->volt_value < 0 || bat->cur_value < 0 ||
jiffies_to_msecs(jiffies - bat->timestamp) >
BAT_POLL_INTERVAL) {
bat->volt_value = s3c_adc_read(bat->client,
bat->volt_value = gather_samples(bat->client,
bat->pdata->volt_samples,
bat->pdata->volt_channel) * bat->pdata->volt_mult;
bat->cur_value = s3c_adc_read(bat->client,
bat->cur_value = gather_samples(bat->client,
bat->pdata->current_samples,
bat->pdata->current_channel) * bat->pdata->current_mult;
bat->timestamp = jiffies;
}
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/s3c_adc_battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct s3c_adc_bat_pdata {
const unsigned int current_channel;
const unsigned int backup_volt_channel;

const unsigned int volt_samples;
const unsigned int current_samples;
const unsigned int backup_volt_samples;

const unsigned int volt_mult;
const unsigned int current_mult;
const unsigned int backup_volt_mult;
Expand Down

0 comments on commit ccb9ed1

Please sign in to comment.