From patchwork Tue Jan 10 23:47:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 90780 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp865473qgi; Tue, 10 Jan 2017 15:48:00 -0800 (PST) X-Received: by 10.84.218.205 with SMTP id g13mr8499262plm.78.1484092080765; Tue, 10 Jan 2017 15:48:00 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si3691003pfk.217.2017.01.10.15.48.00; Tue, 10 Jan 2017 15:48:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758516AbdAJXr7 (ORCPT + 13 others); Tue, 10 Jan 2017 18:47:59 -0500 Received: from mail-lf0-f54.google.com ([209.85.215.54]:33628 "EHLO mail-lf0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758511AbdAJXr5 (ORCPT ); Tue, 10 Jan 2017 18:47:57 -0500 Received: by mail-lf0-f54.google.com with SMTP id k86so126235324lfi.0 for ; Tue, 10 Jan 2017 15:47:56 -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=23h1WYE7SrCiTCyLULZmHuJNUNQ+8zLxDY7nLsXIaxw=; b=GlvqY4ViT4X1ggzaCd/sCiEMKC/4O/TCGM689l4meN5wPoVChlADMJUD+t9bOx/dBj kfuOdPVQsMYp0c0IlCkPs2CKTQCbEuJRHMhRIrDtlp4sTztMWsvc3F2MFK9LGwaSvIiL 4uRpeQ3Phz1tdI35IfvE2JUkwJiGup7OrRVxg= 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=23h1WYE7SrCiTCyLULZmHuJNUNQ+8zLxDY7nLsXIaxw=; b=WS/36wgPs6sWJf3lNokTSXEMBCQv5U/4xsN7nRIB5hQr2X+ahplAwuIqOGpAblrdR2 VAn+9I8OK9p2FCDX9BPtnpFJ/pfyf2/gr/IpxvRYO9ihqJe7i8New03d9UblRVdz5ppY 10n1twn1EEl/jUnUoVJDhbJkVj3sS2Sk2AUc8KSoqcKy7bPCfSsVS8Vgyf6olTLgLNaV dI0EPXfjw0MzsWcHaj39joeE3Fdx1WvRoma1geEDviAVHgBAxxbSzoenqY4+5eBeLzhE 6qEPNgSrfq/+a6OvkEW3VTe2WtUHMRcq2FdrzIMR7Z/Hx8wjQvKrlFIApsw4dFucHc/i PMWA== X-Gm-Message-State: AIkVDXJxWPQj6S5/I+ACj5Cm/he7ZIubMQDyThatqtXZt+01uxnK+EVLOOwVGmg44ibgvpIa X-Received: by 10.25.43.8 with SMTP id r8mr1822712lfr.26.1484092075467; Tue, 10 Jan 2017 15:47:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 15:47:54 -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 2/7] power: supply: ab8500_charger: convert to IIO ADC Date: Wed, 11 Jan 2017 00:47:40 +0100 Message-Id: <20170110234745.29691-3-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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This switches the AB8500 battery charger driver to using the standard IIO ADC channel lookup and conversion routines. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_charger.c | 78 ++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 20 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-By: Sebastian Reichel Acked-by: Jonathan Cameron diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index 5cee9aa87aa3..c1c4873899e9 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -29,10 +29,10 @@ #include #include #include -#include #include #include #include +#include /* Charger constants */ #define NO_PW_CONN 0 @@ -235,7 +235,10 @@ struct ab8500_charger_max_usb_in_curr { * @current_stepping_sessions: * Counter for current stepping sessions * @parent: Pointer to the struct ab8500 - * @gpadc: Pointer to the struct gpadc + * @adc_main_charger_v ADC channel for main charger voltage + * @adc_main_charger_c ADC channel for main charger current + * @adc_vbus_v ADC channel for USB charger voltage + * @adc_usb_charger_c ADC channel for USB charger current * @bm: Platform specific battery management information * @flags: Structure for information about events triggered * @usb_state: Structure for usb stack information @@ -285,7 +288,10 @@ struct ab8500_charger { int is_aca_rid; atomic_t current_stepping_sessions; struct ab8500 *parent; - struct ab8500_gpadc *gpadc; + struct iio_channel *adc_main_charger_v; + struct iio_channel *adc_main_charger_c; + struct iio_channel *adc_vbus_v; + struct iio_channel *adc_usb_charger_c; struct abx500_bm_data *bm; struct ab8500_charger_event_flags flags; struct ab8500_charger_usb_state usb_state; @@ -461,13 +467,13 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di, */ static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di) { - int vch; + int vch, ret; /* Only measure voltage if the charger is connected */ if (di->ac.charger_connected) { - vch = ab8500_gpadc_convert(di->gpadc, MAIN_CHARGER_V); - if (vch < 0) - dev_err(di->dev, "%s gpadc conv failed,\n", __func__); + ret = iio_read_channel_processed(di->adc_main_charger_v, &vch); + if (ret < 0) + dev_err(di->dev, "%s ADC conv failed,\n", __func__); } else { vch = 0; } @@ -512,13 +518,13 @@ static int ab8500_charger_ac_cv(struct ab8500_charger *di) */ static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di) { - int vch; + int vch, ret; /* Only measure voltage if the charger is connected */ if (di->usb.charger_connected) { - vch = ab8500_gpadc_convert(di->gpadc, VBUS_V); - if (vch < 0) - dev_err(di->dev, "%s gpadc conv failed\n", __func__); + ret = iio_read_channel_processed(di->adc_vbus_v, &vch); + if (ret < 0) + dev_err(di->dev, "%s ADC conv failed,\n", __func__); } else { vch = 0; } @@ -534,13 +540,13 @@ static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di) */ static int ab8500_charger_get_usb_current(struct ab8500_charger *di) { - int ich; + int ich, ret; /* Only measure current if the charger is online */ if (di->usb.charger_online) { - ich = ab8500_gpadc_convert(di->gpadc, USB_CHARGER_C); - if (ich < 0) - dev_err(di->dev, "%s gpadc conv failed\n", __func__); + ret = iio_read_channel_processed(di->adc_usb_charger_c, &ich); + if (ret < 0) + dev_err(di->dev, "%s ADC conv failed,\n", __func__); } else { ich = 0; } @@ -556,13 +562,13 @@ static int ab8500_charger_get_usb_current(struct ab8500_charger *di) */ static int ab8500_charger_get_ac_current(struct ab8500_charger *di) { - int ich; + int ich, ret; /* Only measure current if the charger is online */ if (di->ac.charger_online) { - ich = ab8500_gpadc_convert(di->gpadc, MAIN_CHARGER_C); - if (ich < 0) - dev_err(di->dev, "%s gpadc conv failed\n", __func__); + ret = iio_read_channel_processed(di->adc_main_charger_c, &ich); + if (ret < 0) + dev_err(di->dev, "%s ADC conv failed,\n", __func__); } else { ich = 0; } @@ -3485,7 +3491,39 @@ static int ab8500_charger_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"); + + /* Get ADC channels */ + di->adc_main_charger_v = devm_iio_channel_get(&pdev->dev, + "main_charger_v"); + if (IS_ERR(di->adc_main_charger_v)) { + if (PTR_ERR(di->adc_main_charger_v) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get ADC main charger voltage\n"); + return PTR_ERR(di->adc_main_charger_v); + } + di->adc_main_charger_c = devm_iio_channel_get(&pdev->dev, + "main_charger_c"); + if (IS_ERR(di->adc_main_charger_c)) { + if (PTR_ERR(di->adc_main_charger_c) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get ADC main charger current\n"); + return PTR_ERR(di->adc_main_charger_v); + } + di->adc_vbus_v = devm_iio_channel_get(&pdev->dev, "vbus_v"); + if (IS_ERR(di->adc_vbus_v)) { + if (PTR_ERR(di->adc_vbus_v) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get ADC USB charger voltage\n"); + return PTR_ERR(di->adc_vbus_v); + } + di->adc_usb_charger_c = devm_iio_channel_get(&pdev->dev, + "usb_charger_c"); + if (IS_ERR(di->adc_usb_charger_c)) { + if (PTR_ERR(di->adc_usb_charger_c) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get ADC USB charger current\n"); + return PTR_ERR(di->adc_usb_charger_c); + } /* initialize lock */ spin_lock_init(&di->usb_state.usb_lock);