From patchwork Thu Dec 13 15:21:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13551 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 4095023E2A for ; Thu, 13 Dec 2012 15:22:21 +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 CC56DA185E5 for ; Thu, 13 Dec 2012 15:22:20 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so4139746ieb.11 for ; Thu, 13 Dec 2012 07:22:20 -0800 (PST) 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:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=fLSeqjfHkSgQK7O4wHvVW/62nZhwTGIAkEHhzjuaNSE=; b=OUpP437XiPp1DoBNmEld4YjOhsQVsDiYd6oHgPBj7j1XwjNpT0PVENAI7zvGd8ndHP cDo5Wj1nXGTfPS82gDQRnA/KlctGBudiDx9OYe99F7A69BT5YIgHSrklHvz/jhLulWah EMDV8WkHgfh8VkgkxSWpZQ0vANkHLKqa0cCJjBKwZRu4WwRIupfyI7jF6FNiSiS+pZjK 2OWgo0Z1ac9VgtgjhJge+hIxo+JqPNC0yfpyP0fFCSOjkDHTaXomCadTT/Z20noU9Zxl FwFQyfhrz9FPdW05HZvY9UwtaDGUbLlWL3SZwP2gMHLA5+PUcJvD95VGfVEa1bJwHWec o2oQ== Received: by 10.50.152.137 with SMTP id uy9mr1884710igb.62.1355412140291; Thu, 13 Dec 2012 07:22:20 -0800 (PST) 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.67.148 with SMTP id n20csp16272igt; Thu, 13 Dec 2012 07:22:19 -0800 (PST) Received: by 10.194.77.148 with SMTP id s20mr9030524wjw.52.1355412139360; Thu, 13 Dec 2012 07:22:19 -0800 (PST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id z2si3143919wix.31.2012.12.13.07.22.18 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.175 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.175; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.175 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f175.google.com with SMTP id hm11so3930963wib.14 for ; Thu, 13 Dec 2012 07:22:18 -0800 (PST) Received: by 10.194.71.140 with SMTP id v12mr9036772wju.36.1355412138745; Thu, 13 Dec 2012 07:22:18 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id i6sm8200894wix.5.2012.12.13.07.22.17 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:18 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: cbou@mail.ru, Daniel WILLERUD , Lee Jones , Marcus Cooper Subject: [PATCH 15/18] power: ab8500_fg: Add sysfs interfaces for capacity Date: Thu, 13 Dec 2012 15:21:38 +0000 Message-Id: <1355412102-14265-16-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> References: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlKlsCQkXQ0e3nxSroZORaZjFKDtuwsQJ+nOiyTSi5736JWY5stCLHAXnWeX1huRc1MuFAY From: Daniel WILLERUD Switchable depending on whether capacity scaling is enabled Signed-off-by: Lee Jones Signed-off-by: Marcus Cooper Signed-off-by: Daniel WILLERUD Reviewed-by: Jonas ABERG --- 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 <> */ #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;