Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

power: ds2784: Updates for battery calibration

Change-Id: I42e00d2c0c97bcc0d269c0e9366fe1f6c2acd873
  • Loading branch information...
commit 0966b128c2a5c4a93860e9df4a9a0c416fa0ac5f 1 parent 78d746b
@thelogin thelogin authored cyanogen committed
Showing with 65 additions and 40 deletions.
  1. +65 −40 drivers/power/ds2784_battery.c
View
105 drivers/power/ds2784_battery.c
@@ -403,12 +403,26 @@ static int battery_get_property(struct power_supply *psy,
return 0;
}
-/* Here we begin to add the functions for our device attribute
- * files which act as our link from kernel space to user space.
+/* Here we begin to add our device attribute files which is our link from
+ * kernel space to user space. These files appear under
+ * /sys/devices/platform/ds2784-battery/ and are named setreg, dumpreg,
+ * statusreg, getvoltage and getcurrent. These files/functions allow us to
+ * interact with the battery's read and write functions which is the
+ * foundation for a re-calibration mode app along with a number of other
+ * features/advantages.
*
+ * Here we call out the functions and the device attribute macros, and in the
+ * probe function (end of this driver) we call out the actual file creations.
* --RogerPodacter, theloginwithnoname
*/
+/* setreg - this creates a file called "setreg" and allows us to
+ * echo 2 values with a space between them, register and value, which
+ * calls the battery write function. For example, "echo 0x14 0x80"
+ * writes register 0x14 with a value of 0x80.
+ *
+ * --RogerPodacter
+ */
static ssize_t store_set_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -437,6 +451,11 @@ static ssize_t store_set_reg(struct device *dev, struct device_attribute *attr,
/*This is the actual device attr macro call-out for "setreg" file*/
static DEVICE_ATTR(setreg, 0644, NULL, store_set_reg);
+/* dumpreg - this creates a file called "dumpreg" and this is a read-only
+ * file. When this file is read, it returns all values from the battery
+ * EEPROM chip.
+ * --RP
+ */
static ssize_t show_dump_reg(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -486,9 +505,16 @@ static ssize_t show_dump_reg(struct device *dev, struct device_attribute *attr,
return ret;
}
-
+/*This is the actual device attr macro call-out for "dumpreg" file*/
static DEVICE_ATTR(dumpreg, 0644, show_dump_reg, NULL);
+/* statusreg - this creates a file called "statusreg" which is needed.
+ * This allows us to read the status register more frequently than
+ * the driver's 1-minute intervals. We often only get a 3-5 second
+ * window from the status reg updating to shutdown to hit learn mode,
+ * so this gives us more accurate polling of the status register.
+ * --RP
+ */
static ssize_t show_status_reg(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -530,9 +556,16 @@ static ssize_t store_status_reg(struct device *dev, struct device_attribute *att
return count;
}
-
+/*This is the actual device attr macro call-out for "statusreg" file*/
static DEVICE_ATTR(statusreg, 0644, show_status_reg, store_status_reg);
+/* getvoltage - this creates a file called "getvoltage". This allows us
+ * to poll the battery voltage more frequently than the driver's 1-minute
+ * intervals should we want that option for the graphing portion of the
+ * calibration app.
+ *
+ * --RP
+ */
static ssize_t show_getvoltage(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -551,9 +584,16 @@ static ssize_t show_getvoltage(struct device *dev, struct device_attribute *attr
ret = sprintf(buf, "%d\n", getvoltage);
return ret;
}
-
+/*This is the actual device attr macro call-out for "getvoltage" file*/
static DEVICE_ATTR(getvoltage, 0644, show_getvoltage, NULL);
+/* getcurrent - this creates a file called "getcurrent". This allows us
+ * to poll the battery voltage more frequently than the driver's 1-minute
+ * intervals should we want that option for the graphing portion of the
+ * calibration app.
+ *
+ * --RP
+ */
static ssize_t show_getcurrent(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -574,9 +614,16 @@ static ssize_t show_getcurrent(struct device *dev, struct device_attribute *attr
ret = sprintf(buf, "%d\n", getcurrent);
return ret;
}
-
+/*This is the actual device attr macro call-out for "getcurrent" file*/
static DEVICE_ATTR(getcurrent, 0644, show_getcurrent, NULL);
+/* getavgcurrent - this creates a file called "getavgcurrent". This allows us
+ * to poll the battery voltage more frequently than the driver's 1-minute
+ * intervals should we want that option for the graphing portion of the
+ * calibration app.
+ *
+ * --RP
+ */
static ssize_t show_getavgcurrent(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ds2784_device_info *di = dev_get_drvdata(dev);
@@ -597,6 +644,7 @@ static ssize_t show_getavgcurrent(struct device *dev, struct device_attribute *a
ret = sprintf(buf, "%d\n", getavgcurrent);
return ret;
}
+/*This is the actual device attr macro call-out for "getavgcurrent" file*/
static DEVICE_ATTR(getavgcurrent, 0644, show_getavgcurrent, NULL);
static ssize_t show_set_age(struct device *dev, struct device_attribute *attr, char *buf)
@@ -618,7 +666,7 @@ static ssize_t show_set_age(struct device *dev, struct device_attribute *attr, c
pr_info("batt: age_scalar life left is: %d\n", age);
- ret = sprintf(buf, "Battery's age: %d", age);
+ ret = sprintf(buf, "%d\n", age);
return ret;
}
@@ -644,7 +692,7 @@ static ssize_t store_set_age(struct device *dev, struct device_attribute *attr,
return count;
}
-static DEVICE_ATTR(setage, 0644, show_set_age, store_set_age);
+static DEVICE_ATTR(age, 0644, show_set_age, store_set_age);
static ssize_t show_set_AEvolt(struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -688,12 +736,12 @@ static ssize_t store_set_AEvolt (struct device *dev, struct device_attribute *at
temp = ( ( val * 100 ) / 1952 ) ;
- pr_info("batt: Active Empty Voltage set to: %d percent\n", temp);
+ pr_info("batt: Active Empty Voltage set to: %d volts\n", temp);
return count;
}
-static DEVICE_ATTR(setAEvolt, 0644, show_set_AEvolt, store_set_AEvolt);
+static DEVICE_ATTR(voltAE, 0644, show_set_AEvolt, store_set_AEvolt);
static ssize_t show_get_full40(struct device *dev, struct device_attribute *attr, char *buf)
{
@@ -743,9 +791,7 @@ static ssize_t show_get_mAh(struct device *dev, struct device_attribute *attr, c
static DEVICE_ATTR(getmAh, 0644, show_get_mAh, NULL);
-/*End of file functions edits
- *--RP
- */
+/*End of file functions edits --RP*/
static void ds2784_battery_update_status(struct ds2784_device_info *di)
{
@@ -789,28 +835,6 @@ static int battery_adjust_charge_state(struct ds2784_device_info *di)
/* shut off charger when full:
* - CHGTF flag is set
*/
- /* We don't move from full to not-full until
- * we drop below 95%, to avoid confusing the
- * user while we're maintaining a full charge
- * (slowly draining to 95 and charging back
-
- * to 100)
- * Oddly, only Passion is for 99% cycles, HTC
- * set the Bravo to 95%.
- * -od of xbravoteam
- *
- * Set 99 for Passion - pershoot
- */
-
- if (di->status.percentage < 99) {
- di->status.battery_full = 0;
- }
-
- /* Changed this code if-statement back to stock because this
- * parameter is now user settable by changing the actual
- * register value inside the battery chip EEPROM.
- * --RP
- */
if (di->status.status_reg & 0x80) {
di->status.battery_full = 1;
@@ -819,6 +843,7 @@ static int battery_adjust_charge_state(struct ds2784_device_info *di)
else
di->status.battery_full = 0;
+
if (temp >= TEMP_HOT) {
if (temp >= TEMP_CRITICAL)
charge_mode = CHARGE_BATT_DISABLE;
@@ -841,7 +866,7 @@ static int battery_adjust_charge_state(struct ds2784_device_info *di)
charge_mode = CHARGE_BATT_DISABLE;
}
- if (di->status.battery_full == 1)
+ if (di->status.current_uA > 1024)
di->last_charge_seen = di->last_poll;
else if (di->last_charge_mode != CHARGE_OFF &&
check_timeout(di->last_poll, di->last_charge_seen, 60 * 60)) {
@@ -1058,13 +1083,13 @@ static int ds2784_battery_probe(struct platform_device *pdev)
if(ret < 0)
pr_err("%s: Failed to create sysfs entry for avg current\n", __func__);
- ret = device_create_file(&pdev->dev, &dev_attr_setage);
+ ret = device_create_file(&pdev->dev, &dev_attr_age);
if(ret < 0)
- pr_err("%s: Failed to create sysfs entry for setage\n", __func__);
+ pr_err("%s: Failed to create sysfs entry for age\n", __func__);
- ret = device_create_file(&pdev->dev, &dev_attr_setAEvolt);
+ ret = device_create_file(&pdev->dev, &dev_attr_voltAE);
if(ret < 0)
- pr_err("%s: Failed to create sysfs entry for setAEvolt\n", __func__);
+ pr_err("%s: Failed to create sysfs entry for voltAE\n", __func__);
ret = device_create_file(&pdev->dev, &dev_attr_getFull40);
if(ret < 0)

1 comment on commit 0966b12

@pershoot

cool.. you picked it up from their github... they have an app out now which works with the custom driver bits. http://forum.xda-developers.com/showpost.php?p=9407901&postcount=157

Please sign in to comment.
Something went wrong with that request. Please try again.