From patchwork Tue Jan 10 23:47:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 9508859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C78606075C for ; Tue, 10 Jan 2017 23:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9D36285EC for ; Tue, 10 Jan 2017 23:48:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEBBA285F1; Tue, 10 Jan 2017 23:48:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E033285EE for ; Tue, 10 Jan 2017 23:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758563AbdAJXsA (ORCPT ); Tue, 10 Jan 2017 18:48:00 -0500 Received: from mail-lf0-f43.google.com ([209.85.215.43]:34755 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758539AbdAJXr6 (ORCPT ); Tue, 10 Jan 2017 18:47:58 -0500 Received: by mail-lf0-f43.google.com with SMTP id v186so71896559lfa.1 for ; Tue, 10 Jan 2017 15:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=84MEFbX1IsySxBvIje//1SF5U1f5RR/iuiK/RaBMkcQ=; b=YuCu6mIPjACtX4KKRTHWNKiB9S0DdD9zfGINGw4QPTMGMLrsfjCoOqZjb3QsnXkJuR Js6ZdtmVxQNuih91G1nj1Z88oLRZ/Ojny5FszUBkpg6T4Dz0/86GiE/iM5oKHR+tjy/0 pqBicwYpVErR5xVI3z0S5wHcQGPQx7af0aBdw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=84MEFbX1IsySxBvIje//1SF5U1f5RR/iuiK/RaBMkcQ=; b=ZG8P4Am+TByaYdM9F6c4yqC6l37fUojubWdx/jezilsEgybeAiTFX9eEs2GNwd84p+ EZEm+iKOeYAiAiR0ARZ9PdgmTYBL5IjmENDwetqavfd3B8IAjR5eu/sPWbIeoHFS83dD 9ZShTMRV4G3uhq2fMaEgn3oOYoaL5P6nYJImIoAHAxcXoDGSNj33A6ctsvXJxpg8O2IP 7UsKapVNjq0PjW5LTdLX1O1/91ubi7BrW1OjA1I8K8+fqUApp23H74DVdBbnmk87YI/F SxLdjLxqPo7frFFTk7euIqSaeEd9m7zoZsbtMMuOSbNUNEiwtrgr0kiEl3baWDmw2Jnd wcfQ== X-Gm-Message-State: AIkVDXKdOnzcoY2j15qwQv9yGeEJhePI5LrzLQLeXsFI+KQ1r9Ri3KbTEz8iMlbXPO5p8237 X-Received: by 10.46.15.26 with SMTP id 26mr2238503ljp.52.1484092077077; Tue, 10 Jan 2017 15:47:57 -0800 (PST) Received: from localhost.localdomain (c-357171d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.113.53]) by smtp.gmail.com with ESMTPSA id 17sm832038ljn.5.2017.01.10.15.47.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 15:47:56 -0800 (PST) From: Linus Walleij To: Lee Jones , Jonathan Cameron , linux-iio@vger.kernel.org, Sebastian Reichel , Guenter Roeck Cc: Mboumba Cedric Madianga , linux-pm@vger.kernel.org, linux-hwmon@vger.kernel.org, Linus Walleij Subject: [PATCH 3/7] power: supply: ab8500_fg: convert to IIO ADC Date: Wed, 11 Jan 2017 00:47:41 +0100 Message-Id: <20170110234745.29691-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170110234745.29691-1-linus.walleij@linaro.org> References: <20170110234745.29691-1-linus.walleij@linaro.org> Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This switches the AB8500 fuel gauge driver to using the standard IIO ADC channel lookup and conversion routines. Signed-off-by: Linus Walleij Acked-By: Sebastian Reichel Acked-by: Jonathan Cameron --- drivers/power/supply/ab8500_fg.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index c569f82a0071..b26122e1da51 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #define MILLI_TO_MICRO 1000 @@ -182,7 +182,7 @@ struct inst_curr_result_list { * @bat_cap: Structure for battery capacity specific parameters * @avg_cap: Average capacity filter * @parent: Pointer to the struct ab8500 - * @gpadc: Pointer to the struct gpadc + * @main_bat_v: ADC channel for the main battery voltage * @bm: Platform specific battery management information * @fg_psy: Structure that holds the FG specific battery properties * @fg_wq: Work queue for running the FG algorithm @@ -224,7 +224,7 @@ struct ab8500_fg { struct ab8500_fg_battery_capacity bat_cap; struct ab8500_fg_avg_cap avg_cap; struct ab8500 *parent; - struct ab8500_gpadc *gpadc; + struct iio_channel *main_bat_v; struct abx500_bm_data *bm; struct power_supply *fg_psy; struct workqueue_struct *fg_wq; @@ -831,13 +831,13 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) */ static int ab8500_fg_bat_voltage(struct ab8500_fg *di) { - int vbat; + int vbat, ret; static int prev; - vbat = ab8500_gpadc_convert(di->gpadc, MAIN_BAT_V); - if (vbat < 0) { + ret = iio_read_channel_processed(di->main_bat_v, &vbat); + if (ret < 0) { dev_err(di->dev, - "%s gpadc conversion failed, using previous value\n", + "%s ADC conversion failed, using previous value\n", __func__); return prev; } @@ -3072,7 +3072,14 @@ static int ab8500_fg_probe(struct platform_device *pdev) /* get parent data */ di->dev = &pdev->dev; di->parent = dev_get_drvdata(pdev->dev.parent); - di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0"); + + di->main_bat_v = devm_iio_channel_get(&pdev->dev, "main_bat_v"); + if (IS_ERR(di->main_bat_v)) { + if (PTR_ERR(di->main_bat_v) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get main battery ADC channel\n"); + return PTR_ERR(di->main_bat_v); + } psy_cfg.supplied_to = supply_interface; psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);