From: Rong Dian Date: Fri, 13 Jul 2012 05:07:38 +0000 (+0800) Subject: ENGR00216998: battery: add usb charger voltage offset sysfs interface X-Git-Tag: v3.0.35-fsl~765 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=05ff1eb1ab41f8fa5fc64c6cb761f696f2d05d2a;p=karo-tx-linux.git ENGR00216998: battery: add usb charger voltage offset sysfs interface add usb charger voltage offset sysfs interface Signed-off-by: Rong Dian --- diff --git a/drivers/power/sabresd_battery.c b/drivers/power/sabresd_battery.c index 0e748cd345a9..dd839868dc01 100755 --- a/drivers/power/sabresd_battery.c +++ b/drivers/power/sabresd_battery.c @@ -68,6 +68,8 @@ typedef struct { static int cpu_type_flag; static int offset_discharger; static int offset_charger; +static int offset_usb_charger; + static battery_capacity chargingTable[] = { {4060, 99}, @@ -225,7 +227,12 @@ u32 calibration_voltage(struct max8903_data *data) /* ADC offset when battery is discharger*/ volt[i] = max11801_read_adc()-offset_discharger; } else { - volt[i] = max11801_read_adc()-offset_charger; + if (data->charger_online == 1) + volt[i] = max11801_read_adc()-offset_charger; + else if (data->usb_charger_online == 1) + volt[i] = max11801_read_adc()-offset_usb_charger; + else if (data->charger_online == 1 && data->usb_charger_online == 1) + volt[i] = max11801_read_adc()-offset_charger; } } if (cpu_type_flag == 0) { @@ -233,7 +240,12 @@ u32 calibration_voltage(struct max8903_data *data) /* ADC offset when battery is discharger*/ volt[i] = max11801_read_adc()-offset_discharger; } else { - volt[i] = max11801_read_adc()-offset_charger; + if (data->charger_online == 1) + volt[i] = max11801_read_adc()-offset_charger; + else if (data->usb_charger_online == 1) + volt[i] = max11801_read_adc()-offset_usb_charger; + else if (data->charger_online == 1 && data->usb_charger_online == 1) + volt[i] = max11801_read_adc()-offset_charger; } } } @@ -515,6 +527,22 @@ static ssize_t max8903_voltage_offset_charger_store(struct device *dev, return count; } +static ssize_t max8903_voltage_offset_usb_charger_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "read offset_usb_charger:%04d\n", + offset_usb_charger); +} + +static ssize_t max8903_voltage_offset_usb_charger_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + offset_usb_charger = simple_strtoul(buf, NULL, 10); + pr_info("read offset_charger:%04d\n", offset_usb_charger); + return count; +} + static struct device_attribute max8903_discharger_dev_attr = { .attr = { .name = "max8903_ctl_offset_discharger", @@ -533,6 +561,15 @@ static struct device_attribute max8903_charger_dev_attr = { .store = max8903_voltage_offset_charger_store, }; +static struct device_attribute max8903_usb_charger_dev_attr = { + .attr = { + .name = "max8903_ctl_offset_usb_charger", + .mode = S_IRUSR | S_IWUSR, + }, + .show = max8903_voltage_offset_usb_charger_show, + .store = max8903_voltage_offset_usb_charger_store, +}; + static __devinit int max8903_probe(struct platform_device *pdev) { struct max8903_data *data; @@ -732,15 +769,20 @@ static __devinit int max8903_probe(struct platform_device *pdev) if (ret) dev_err(&pdev->dev, "create device file failed!\n"); ret = device_create_file(&pdev->dev, &max8903_charger_dev_attr); + if (ret) + dev_err(&pdev->dev, "create device file failed!\n"); + ret = device_create_file(&pdev->dev, &max8903_usb_charger_dev_attr); if (ret) dev_err(&pdev->dev, "create device file failed!\n"); if (cpu_type_flag == 1) { offset_discharger = 1694; offset_charger = 1900; + offset_usb_charger = 1685; } if (cpu_type_flag == 0) { offset_discharger = 1464; offset_charger = 1485; + offset_usb_charger = 1285; } max8903_charger_update_status(data);