From patchwork Tue May 23 00:51:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 9741615 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 BAD4760388 for ; Tue, 23 May 2017 00:51:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF14126E51 for ; Tue, 23 May 2017 00:51:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3E9528779; Tue, 23 May 2017 00:51:59 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 41DCB26E51 for ; Tue, 23 May 2017 00:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763438AbdEWAv5 (ORCPT ); Mon, 22 May 2017 20:51:57 -0400 Received: from muru.com ([72.249.23.125]:48926 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758076AbdEWAv4 (ORCPT ); Mon, 22 May 2017 20:51:56 -0400 Received: from sampyla.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 82BE18529; Tue, 23 May 2017 00:55:15 +0000 (UTC) From: Tony Lindgren To: Jonathan Cameron Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-omap@vger.kernel.org, Marcel Partap , Michael Scott , Sebastian Reichel Subject: [PATCH 2/3] iio: adc: cpcap: Fix die temperature Date: Mon, 22 May 2017 17:51:45 -0700 Message-Id: <20170523005146.726-3-tony@atomide.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170523005146.726-1-tony@atomide.com> References: <20170523005146.726-1-tony@atomide.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It seems that "MC13783 Power Management and Audio Ciruit User's Guide" MC1378UG.pdf documents several similar components as in the CPCAP PMIC. Chapter "9.5.5 Die Temperature and UID" says that the die temperature value is 282 at 25C with LSB of -1.14C. Converting CPCAP PMIC channel3 values with following seems to produce values that make sense for a PMIC die: temperature = 25000 + ((regval - 282) * 114) As we don't have any other documentation, let's assume the die temperature is unconfigured in the Motorola mapphone Linux kernel and the current temperature conversion table should be only used for the battery thermistor and not for the die temperature. Cc: Marcel Partap Cc: Michael Scott Cc: Sebastian Reichel Signed-off-by: Tony Lindgren --- drivers/iio/adc/cpcap-adc.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/cpcap-adc.c b/drivers/iio/adc/cpcap-adc.c --- a/drivers/iio/adc/cpcap-adc.c +++ b/drivers/iio/adc/cpcap-adc.c @@ -875,6 +875,22 @@ static int cpcap_adc_init_request(struct cpcap_adc_request *req, return 0; } +static int cpcap_adc_read_st_die_temp(struct cpcap_adc *ddata, + int addr, int *val) +{ + int error; + + error = regmap_read(ddata->reg, addr, val); + if (error) + return error; + + *val -= 282; + *val *= 114; + *val += 25000; + + return 0; +} + static int cpcap_adc_read(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -906,9 +922,18 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error = cpcap_adc_start_bank(ddata, &req); if (error) goto err_unlock; - error = cpcap_adc_read_bank_scaled(ddata, &req); - if (error) - goto err_unlock; + if ((ddata->vendor == CPCAP_VENDOR_ST) && + (chan->channel == CPCAP_ADC_AD3)) { + error = cpcap_adc_read_st_die_temp(ddata, + chan->address, + &req.result); + if (error) + goto err_unlock; + } else { + error = cpcap_adc_read_bank_scaled(ddata, &req); + if (error) + goto err_unlock; + } error = cpcap_adc_stop_bank(ddata); if (error) goto err_unlock;