From patchwork Thu Sep 27 20:08:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11791 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id AF82724140 for ; Thu, 27 Sep 2012 20:09:44 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 60401A18968 for ; Thu, 27 Sep 2012 20:09:44 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5234801iej.11 for ; Thu, 27 Sep 2012 13:09:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=YEuN6H3YDO/ndZ7I1RBeCqS6Cu23grSI0MpIdqXgjCs=; b=RuGr15XoDxFIakK8yhnw3wpqng3vSy5N239Jnb4M5gJxLICaGbJO+IcHjGGwZkoMmY Jitp2ht43qmjvZ6/4bT8f1qX4zPJUlE49DvT51ZWccDDUJAj8VYKBdUy04Zp9D9zHVRZ cPFmxjS7FAZ6UL+6VhfkebJni3GJ3/txgJmxzk+m9BVw1Jofi6GHkiG6IkK1dvQhrzN0 r2zwDqtUi5sOdODlENKgUziA0++KdbZJu6vYPQJvSLNFybavy9TWd+OGrOSVNNlEnNd0 2YVJkPamydGQ8y5j29hl/+J9Zy5DdN8QyxNZsm0sZsYp1YJl6fky6lilkjROkcg0ojHw LOlQ== Received: by 10.50.217.229 with SMTP id pb5mr4698535igc.28.1348776584189; Thu, 27 Sep 2012 13:09:44 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp436300igc; Thu, 27 Sep 2012 13:09:43 -0700 (PDT) Received: by 10.66.83.234 with SMTP id t10mr12149427pay.39.1348776583577; Thu, 27 Sep 2012 13:09:43 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pi9si5467641pbb.12.2012.09.27.13.09.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) smtp.mail=mathieu.poirier@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md4so1686045pbc.37 for ; Thu, 27 Sep 2012 13:09:43 -0700 (PDT) Received: by 10.68.203.195 with SMTP id ks3mr14484631pbc.79.1348776583316; Thu, 27 Sep 2012 13:09:43 -0700 (PDT) Received: from localhost.localdomain (S0106002369de4dac.cg.shawcable.net. [70.73.24.112]) by mx.google.com with ESMTPS id sa2sm1587890pbc.4.2012.09.27.13.09.42 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:42 -0700 (PDT) From: mathieu.poirier@linaro.org To: patches@linaro.org Subject: [PATCH 18/57] power: Add sysfs interfaces for capacity Date: Thu, 27 Sep 2012 14:08:35 -0600 Message-Id: <1348776554-10019-19-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> References: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> X-Gm-Message-State: ALoCoQludCD4ejh5KKqutuDYAvcjDYRXaZSAMgxADXh4r7HumCbaU5+DXlQZ4KsSm6gBcJhNcTgM From: Daniel WILLERUD Switchable depending on whether capacity scaling is enabled Signed-off-by: Marcus Cooper Signed-off-by: Daniel WILLERUD Signed-off-by: Mathieu Poirier Reviewed-by: Jonas ABERG --- drivers/power/ab8500_fg.c | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 56 insertions(+), 1 deletions(-) diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 8507254..46010ec 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -266,7 +266,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, }; @@ -2543,6 +2542,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->bat->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 <> */ #if defined(CONFIG_PM) @@ -2599,6 +2646,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); kfree(di); @@ -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;