Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp318059imj; Thu, 7 Feb 2019 04:57:46 -0800 (PST) X-Google-Smtp-Source: AHgI3IahzSiN/PdGOT/FW1MjRtUV2nhG6hz4Y6f2fuK+xGBH0GdcpM1Z0ED6IK91L7ZwZdiVJCsz X-Received: by 2002:a65:4781:: with SMTP id e1mr14592736pgs.346.1549544266644; Thu, 07 Feb 2019 04:57:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549544266; cv=none; d=google.com; s=arc-20160816; b=GjPZRn3lJuR1ibEsA3zF+S8q8Jq5UF1ro1Oc+VURG7pB1JVubMJFU7fZUXHhdok/SJ HnGNICwjBmHbpKb+Ppl5v7W12GDpwOKpCGTZagpJEI3oZ+S7W3ejIWqWDfk2mZK7O2WY 3CQMZhFyW57SiowxR4cnUV83sBU8Pk9udsiBiek+axGVA2xrNJP0Fl7ABKWyvn2eHbtw EAH31UCpJGogSqe+TgSvJ6aTzUTtQrvY/h43GPSdbe7aDaEZ7SUqMPNkRkr3GR/uHRwt byR2KGZlsGfvFzA71OAL9YppTBXjfe6y3pjsXtGKlhnFs/324ro/a+Nn+RsTNc2ZEtAR zO2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=wVxETCRj9csXkr178RqwaQ70WDjkLA5uLcl3mAGgLOI=; b=E3yqLXxpGw7rcZhCNZD7DVT3N4rZHOJl+4VY3s00KxwxSKDfP+QYYN7VdZPnwQ+yrn 4NCvUlTViaqFymn6LW/ouzN+7Sscx1L/2DvPNCpiyyjMR89NvlZtOy31m1vItjvh2dgL zXXXlHcxkTVFo9pRtl0/RKI8TO03aa5w0f82O69sxTdSwQlxzj7WZw8+p3wsdSoX01I4 Uvt4Am6niPFprYBoFd7/lZxR4iyX0kIz+sIgSwLErwAaTUl6X43G37GcHW3zQHKNehye iYtWywRaNR7FxhHcTBx/i5/UpL65SqPzm3fdRHv9Eeze0KkTOHvovMBbbqq398cQ8ngF cdbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UW9DDb/p"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w9si4689457pgr.316.2019.02.07.04.57.30; Thu, 07 Feb 2019 04:57:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UW9DDb/p"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfBGM5F (ORCPT + 99 others); Thu, 7 Feb 2019 07:57:05 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45137 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbfBGM5E (ORCPT ); Thu, 7 Feb 2019 07:57:04 -0500 Received: by mail-pg1-f194.google.com with SMTP id y4so4441705pgc.12 for ; Thu, 07 Feb 2019 04:57:04 -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 :in-reply-to:references; bh=wVxETCRj9csXkr178RqwaQ70WDjkLA5uLcl3mAGgLOI=; b=UW9DDb/pi65Xvl3Vz6Dw/OUA3Fl59q2P8ug5ik4Lqrdku78njfs4S7lYoVItyoKwSS 0Jki7sO0+S3jNoH006zE3qz+5wKYGMmrzS5X5ddkHMtPV322cM/zL/bsSZP5t8iII9n8 l2mf+IDhm+NGDwIuFQ3JP2bmyNVO2NtB3ldcuMT0pFfuDVmv8fsojOhgkwOdMGZ0sF5J YvckbF/fXCv0PBXq3dYxqBNjrD7+P3qDvZ6h2mSsqjBd73D0T6tECYz9Cqb8+QtChgSI FVODwGrNHYkr6u9xokCGlkRK5tC1GJkoMfms/w8fpwfbFTUEWQpFTU/7HxNIwXcSMwuO 6aKw== 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:in-reply-to:references; bh=wVxETCRj9csXkr178RqwaQ70WDjkLA5uLcl3mAGgLOI=; b=DUeDF0T5tOPEHfDityLvNfrjrGcsrTJkqTZfYOABqEbu7YS7GCArtNjboMR0yFntPM RqEsvLfEU2sPjIrNbYMHVQr9dJAG3g2Nte82Wir9RwoZv8NB/M00/DUGLyBAskFYwKiw 10WOF25b72SoMaRRSa0Ewh7QvjojuG7NBi4AWYAiaSdp/E8wcvq7Jy9gfHNkHycX/K5S DU9LpWsMleLS5j7zSxRvNKrG1NopknLpoQvRZrlITk8lH+tUb+TkHFeA68iX7xu23Z9r obgHO+BRJU4xG4w6tPY3EJQTc0vjZuK4dVrCqXgEZEpIZ+OrI72blU3voC7aR1QEdYov RiLg== X-Gm-Message-State: AHQUAuZtIAEi0Hs/zXcn5LZ3YqlZR6bgi+N0TjU1g6WXuGlBa84lQuab eEMtW9mnE69C6rA7+ldotEQQcvD25ic= X-Received: by 2002:a63:4d22:: with SMTP id a34mr12920642pgb.432.1549544223702; Thu, 07 Feb 2019 04:57:03 -0800 (PST) Received: from localhost ([2402:3a80:c80:4138:75dd:3900:1d90:762f]) by smtp.gmail.com with ESMTPSA id l74sm19418631pfb.145.2019.02.07.04.57.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 04:57:03 -0800 (PST) From: Amit Kucheria To: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, andy.gross@linaro.org, Daniel Lezcano , David Brown , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH v1 18/24] drivers: thermal: tsens: Move get_temp_tsens_v2 to allow sharing Date: Thu, 7 Feb 2019 16:19:36 +0530 Message-Id: <461cc91a35b5766fe1b44a5fae647c40e4de7f80.1549525708.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just rename the function and move it to allow code sharing with future versions of TSENS IP Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-common.c | 35 +++++++++++++++++++++++++++ drivers/thermal/qcom/tsens-v2.c | 37 +---------------------------- drivers/thermal/qcom/tsens.h | 1 + 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index d981effed493..ed975a2430d9 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -102,6 +102,41 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) return degc; } +int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) +{ + struct tsens_sensor *s = &priv->sensor[i]; + u32 temp_idx = LAST_TEMP_0 + s->hw_id; + u32 valid_idx = VALID_0 + s->hw_id; + u32 last_temp = 0, valid, mask; + int ret; + + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; + while (!valid) { + /* Valid bit is 0 for 6 AHB clock cycles. + * At 19.2MHz, 1 AHB clock is ~60ns. + * We should enter this loop very, very rarely. + */ + ndelay(400); + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; + } + + /* Valid bit is set, OK to read the temperature */ + ret = regmap_field_read(priv->rf[temp_idx], &last_temp); + if (ret) + return ret; + + mask = GENMASK(priv->fields[LAST_TEMP_0].msb, + priv->fields[LAST_TEMP_0].lsb); + /* Convert temperature from deciCelsius to milliCelsius */ + *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; + + return 0; +} + int get_temp_common(struct tsens_priv *priv, int i, int *temp) { struct tsens_sensor *s = &priv->sensor[i]; diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 0ea93b89bc65..d436b96a6f18 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -25,41 +25,6 @@ #define TM_Sn_STATUS_OFF 0x00a0 #define TM_TRDY_OFF 0x00e4 -static int get_temp_tsens_v2(struct tsens_priv *priv, int i, int *temp) -{ - struct tsens_sensor *s = &priv->sensor[i]; - u32 temp_idx = LAST_TEMP_0 + s->hw_id; - u32 valid_idx = VALID_0 + s->hw_id; - u32 last_temp = 0, valid, mask; - int ret; - - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - while (!valid) { - /* Valid bit is 0 for 6 AHB clock cycles. - * At 19.2MHz, 1 AHB clock is ~60ns. - * We should enter this loop very, very rarely. - */ - ndelay(400); - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - } - - /* Valid bit is set, OK to read the temperature */ - ret = regmap_field_read(priv->rf[temp_idx], &last_temp); - if (ret) - return ret; - - mask = GENMASK(priv->fields[LAST_TEMP_0].msb, - priv->fields[LAST_TEMP_0].lsb); - /* Convert temperature from deciCelsius to milliCelsius */ - *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; - - return 0; -} - /* v2.x: 8996, 8998, sdm845 */ const struct tsens_features tsens_v2_feat = { @@ -136,7 +101,7 @@ const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { static const struct tsens_ops ops_generic_v2 = { .init = init_common, - .get_temp = get_temp_tsens_v2, + .get_temp = get_temp_tsens_valid, }; const struct tsens_plat_data data_tsens_v2 = { diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index 9db89dffb719..4b3d71b26c97 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -255,6 +255,7 @@ struct tsens_priv { char *qfprom_read(struct device *dev, const char *cname); void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode); int init_common(struct tsens_priv *priv); +int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp); int get_temp_common(struct tsens_priv *priv, int i, int *temp); bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id); -- 2.17.1