From patchwork Tue Jan 10 23:47:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 90779 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp865454qgi; Tue, 10 Jan 2017 15:47:58 -0800 (PST) X-Received: by 10.98.32.221 with SMTP id m90mr6847797pfj.127.1484092078086; Tue, 10 Jan 2017 15:47:58 -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.47.57; Tue, 10 Jan 2017 15:47:58 -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 S1758534AbdAJXr4 (ORCPT + 13 others); Tue, 10 Jan 2017 18:47:56 -0500 Received: from mail-lf0-f45.google.com ([209.85.215.45]:34738 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758516AbdAJXrz (ORCPT ); Tue, 10 Jan 2017 18:47:55 -0500 Received: by mail-lf0-f45.google.com with SMTP id v186so71895827lfa.1 for ; Tue, 10 Jan 2017 15:47:54 -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=K4pHbaBPLWlp7M/neS3tNx6FZvxnj/UKUsVi1Hu+5hc=; b=bGzNA5W0xrncpRALKQitcILZZs3gQUD8z4PHyLjVU3AL2xA7VKeBiybWE3masBhXyO 1VVkB67q4v6NlT1Dh//SpXzjaPbMuUxmIgeN/jWg7lJzjznTpGSPYYkL4QA2H66bpE0d AnnM4AZIeo/PIrpenDhHsn0iwEmVUMTjDXimc= 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=K4pHbaBPLWlp7M/neS3tNx6FZvxnj/UKUsVi1Hu+5hc=; b=b0nHvHqlNOxDsXfxCEj5f/NFvPgQZhoHAKn0SDvn/1/BGzqyvy+WTW8oY1YwqYitll qhY+s8DgXFD0itQo3+I3n6t2QVNwDVJiTqWpIDUI0FCr7coXpnbhKz8zxMqH+nrxGJcm TMdK0AxtDK5k67SVivghuxa8OBoyzcEeIUsPoe8jOc7C/7MskpUNqgJ/ssC/C0rHWbn8 LKC+35PJ6zwduKguvn6M8VPSX9XBieBPOPnTzn5gTwUriSVZtCU5sRQT2ojJcpA0lV07 NhcS/U3+ERSyd9BAXZ+OsdRapd0Gq5pqUgrxGShuXCv2RqoUG54rSnFySz7PeIV9+DgD 5ATw== X-Gm-Message-State: AIkVDXKy9wc5KwPm3BfwduOzxUGeJunj6XyB1MAz00jBNd43Fr7GqH7mj+ExAEY6ZgxaQvM/ X-Received: by 10.25.137.193 with SMTP id l184mr1751680lfd.31.1484092073207; Tue, 10 Jan 2017 15:47:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jan 2017 15:47:52 -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 1/7] power: supply: ab8500_btemp: convert to IIO ADC Date: Wed, 11 Jan 2017 00:47:39 +0100 Message-Id: <20170110234745.29691-2-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 temperature driver to using the standard IIO ADC channel lookup and conversion routines. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_btemp.c | 41 ++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 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_btemp.c b/drivers/power/supply/ab8500_btemp.c index 6ffdc18f2599..61161db5cffa 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #define VTVOUT_V 1800 @@ -79,7 +79,8 @@ struct ab8500_btemp_ranges { * @bat_temp: Dispatched battery temperature in degree Celcius * @prev_bat_temp Last measured battery temperature in degree Celcius * @parent: Pointer to the struct ab8500 - * @gpadc: Pointer to the struct gpadc + * @adc_btemp_ball: ADC channel for the battery ball temperature + * @adc_bat_ctrl: ADC channel for the battery control * @fg: Pointer to the struct fg * @bm: Platform specific battery management information * @btemp_psy: Structure for BTEMP specific battery properties @@ -96,7 +97,8 @@ struct ab8500_btemp { int bat_temp; int prev_bat_temp; struct ab8500 *parent; - struct ab8500_gpadc *gpadc; + struct iio_channel *btemp_ball; + struct iio_channel *bat_ctrl; struct ab8500_fg *fg; struct abx500_bm_data *bm; struct power_supply *btemp_psy; @@ -180,13 +182,13 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di, */ static int ab8500_btemp_read_batctrl_voltage(struct ab8500_btemp *di) { - int vbtemp; + int vbtemp, ret; static int prev; - vbtemp = ab8500_gpadc_convert(di->gpadc, BAT_CTRL); - if (vbtemp < 0) { + ret = iio_read_channel_processed(di->bat_ctrl, &vbtemp); + if (ret < 0) { dev_err(di->dev, - "%s gpadc conversion failed, using previous value", + "%s ADC conversion failed, using previous value", __func__); return prev; } @@ -501,7 +503,7 @@ static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di, */ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) { - int temp; + int temp, ret; static int prev; int rbat, rntc, vntc; u8 id; @@ -526,10 +528,10 @@ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) di->bm->bat_type[id].r_to_t_tbl, di->bm->bat_type[id].n_temp_tbl_elements, rbat); } else { - vntc = ab8500_gpadc_convert(di->gpadc, BTEMP_BALL); - if (vntc < 0) { + ret = iio_read_channel_processed(di->btemp_ball, &vntc); + if (ret < 0) { dev_err(di->dev, - "%s gpadc conversion failed," + "%s ADC conversion failed," " using previous value\n", __func__); return prev; } @@ -1085,7 +1087,22 @@ static int ab8500_btemp_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->btemp_ball = devm_iio_channel_get(&pdev->dev, "btemp_ball"); + if (IS_ERR(di->btemp_ball)) { + if (PTR_ERR(di->btemp_ball) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get BTEMP BALL ADC channel\n"); + return PTR_ERR(di->btemp_ball); + } + di->bat_ctrl = devm_iio_channel_get(&pdev->dev, "bat_ctrl"); + if (IS_ERR(di->bat_ctrl)) { + if (PTR_ERR(di->bat_ctrl) == -ENODEV) + return -EPROBE_DEFER; + dev_err(&pdev->dev, "failed to get BAT CTRL ADC channel\n"); + return PTR_ERR(di->bat_ctrl); + } di->initialized = false;