From: Lee Jones <lee.jones@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: cbou@mail.ru, Daniel WILLERUD <daniel.willerud@stericsson.com>,
Lee Jones <lee.jones@linaro.org>,
Marcus Cooper <marcus.xm.cooper@stericsson.com>
Subject: [PATCH 15/18] power: ab8500_fg: Add sysfs interfaces for capacity
Date: Thu, 13 Dec 2012 15:21:38 +0000 [thread overview]
Message-ID: <1355412102-14265-16-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1355412102-14265-1-git-send-email-lee.jones@linaro.org>
From: Daniel WILLERUD <daniel.willerud@stericsson.com>
Switchable depending on whether capacity scaling is enabled
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Marcus Cooper <marcus.xm.cooper@stericsson.com>
Signed-off-by: Daniel WILLERUD <daniel.willerud@stericsson.com>
Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com>
---
drivers/power/ab8500_fg.c | 57 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index f931bf8..ec122d0 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -265,7 +265,6 @@ static enum power_supply_property ab8500_fg_props[] = {
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_NOW,
- POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
};
@@ -2539,6 +2538,54 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)
return ret;
}
+
+static ssize_t ab8500_show_capacity(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct power_supply *psy = dev_get_drvdata(dev);
+ struct ab8500_fg *di;
+ int capacity;
+
+ di = to_ab8500_fg_device_info(psy);
+
+ if (di->bm->capacity_scaling)
+ capacity = di->bat_cap.cap_scale.scaled_cap;
+ else
+ capacity = DIV_ROUND_CLOSEST(di->bat_cap.permille, 10);
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", capacity);
+}
+
+static struct device_attribute ab8500_fg_sysfs_psy_attrs[] = {
+ __ATTR(capacity, S_IRUGO, ab8500_show_capacity, NULL),
+};
+
+static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(ab8500_fg_sysfs_psy_attrs); i++)
+ if (device_create_file(dev, &ab8500_fg_sysfs_psy_attrs[i]))
+ goto sysfs_psy_create_attrs_failed;
+
+ return 0;
+
+sysfs_psy_create_attrs_failed:
+ dev_err(dev, "Failed creating sysfs psy attrs.\n");
+ while (i--)
+ device_remove_file(dev, &ab8500_fg_sysfs_psy_attrs[i]);
+
+ return -EIO;
+}
+
+static void ab8500_fg_sysfs_psy_remove_attrs(struct device *dev)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(ab8500_fg_sysfs_psy_attrs); i++)
+ (void)device_remove_file(dev, &ab8500_fg_sysfs_psy_attrs[i]);
+}
/* Exposure to the sysfs interface <<END>> */
#if defined(CONFIG_PM)
@@ -2595,6 +2642,7 @@ static int __devexit ab8500_fg_remove(struct platform_device *pdev)
ab8500_fg_sysfs_exit(di);
flush_scheduled_work();
+ ab8500_fg_sysfs_psy_remove_attrs(di->fg_psy.dev);
power_supply_unregister(&di->fg_psy);
platform_set_drvdata(pdev, NULL);
return ret;
@@ -2754,6 +2802,13 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev)
goto free_irq;
}
+ ret = ab8500_fg_sysfs_psy_create_attrs(di->fg_psy.dev);
+ if (ret) {
+ dev_err(di->dev, "failed to create FG psy\n");
+ ab8500_fg_sysfs_exit(di);
+ goto free_irq;
+ }
+
/* Calibrate the fg first time */
di->flags.calibrate = true;
di->calib_state = AB8500_FG_CALIB_INIT;
--
1.7.9.5
next prev parent reply other threads:[~2012-12-13 15:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-13 15:21 [PATCH 00/18] AB8500 battery management series upgrade Lee Jones
2012-12-13 15:21 ` [PATCH 01/18] power: ab8500_charger: Rename the power_loss function Lee Jones
2013-01-03 11:55 ` Lee Jones
2012-12-13 15:21 ` [PATCH 02/18] power: ab8500_bm: Skip first CCEOC irq for instant current Lee Jones
2012-12-13 15:21 ` [PATCH 03/18] power: ab8500_charger: Detect removed charger Lee Jones
2012-12-13 15:21 ` [PATCH 04/18] power: ab8500_fg: flush sync on suspend Lee Jones
2012-12-13 15:21 ` [PATCH 05/18] power: ab8500_fg: usleep_range instead of short msleep Lee Jones
2012-12-13 15:21 ` [PATCH 06/18] power: ab8500_charger: Handle gpadc errors Lee Jones
2012-12-13 15:21 ` [PATCH 07/18] power: ab8500_bm: Recharge condition not optimal for battery Lee Jones
2012-12-13 15:21 ` [PATCH 08/18] power: ab8500_fg: balance IRQ enable Lee Jones
2012-12-13 15:21 ` [PATCH 09/18] power: ab8500_btemp: Ignore false btemp low interrupt Lee Jones
2012-12-13 15:21 ` [PATCH 10/18] power: ab8500_bm: Adds support for Car/Travel Adapters Lee Jones
2012-12-13 15:21 ` [PATCH 11/18] power: ab8500_fg: Round capacity output Lee Jones
2012-12-13 15:21 ` [PATCH 12/18] power: ab8500_btemp: remove superfluous BTEMP thermal comp Lee Jones
2012-12-13 15:21 ` [PATCH 13/18] power: ab8500_fg: Added support for BATT_OVV Lee Jones
2012-12-13 15:21 ` [PATCH 14/18] power: pm2301: Add pm2301 charger Lee Jones
2012-12-13 15:21 ` Lee Jones [this message]
2012-12-13 15:21 ` [PATCH 16/18] power: ab8500_charger: remove unused defines Lee Jones
2012-12-13 15:21 ` [PATCH 17/18] power: ab8500_charger: Adds support for legacy USB chargers Lee Jones
2012-12-13 15:21 ` [PATCH 18/18] Power: ab8500_fg: Overflow in current calculation Lee Jones
2013-01-05 21:20 ` [PATCH 00/18] AB8500 battery management series upgrade Anton Vorontsov
2013-01-07 9:30 ` Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1355412102-14265-16-git-send-email-lee.jones@linaro.org \
--to=lee.jones@linaro.org \
--cc=cbou@mail.ru \
--cc=daniel.willerud@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcus.xm.cooper@stericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®