From patchwork Wed Jul 4 12:38:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10506773 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 8A34F601D7 for ; Wed, 4 Jul 2018 12:39:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CCA028DDD for ; Wed, 4 Jul 2018 12:39:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70CDA28DE3; Wed, 4 Jul 2018 12:39:15 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_TVD_MIME_EPI 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 CA93A28DDD for ; Wed, 4 Jul 2018 12:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934667AbeGDMil (ORCPT ); Wed, 4 Jul 2018 08:38:41 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:42810 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934563AbeGDMij (ORCPT ); Wed, 4 Jul 2018 08:38:39 -0400 Received: by mail-qt0-f195.google.com with SMTP id y31-v6so4365606qty.9 for ; Wed, 04 Jul 2018 05:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Rd4UUJQ6Zk3/xcTu4yTKZ7EMzqap7F6YLq2NRy1EvcI=; b=KwW2oZZ92Y8p48+QoyDaDy83n1dJhXHJoJgOERQ//v0FvqIunPSIoGWqJtx1YxUIkl 0Hf7yU69t5SECT5Oyturs9nJZXNFW4IrGLz7EunvhF7GHQ1HlraAQsWKDBiFXU8fvIs8 riTt3t2xQpiX5LLU48ri19vvK67doYY83CJQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Rd4UUJQ6Zk3/xcTu4yTKZ7EMzqap7F6YLq2NRy1EvcI=; b=lUwM4Zbu5W17U4IC61z7Z6+H14c6cIltspU4AlLjJLLJId5e9tkJVsc6kxMF4BcLr0 eAhx8l9Ad3BvHrnt7kFoLil5+R9TU/MoxRhzgYoMlL+flP7J+60CgDAHvtLe5aAQUXLk 9AdVJdJkmdGIeEUP/G4CZ3Za9b50UxD56vV7hWAA29tobdGncEAOXQN0NZV4LEcq3+nx 1ndhS1mTYYWrjF1FzWwQFot5MSFc1Yy0du6jQ/DcrI+ePN41jvkak4a005n+oogb3w6O NC4nJDdAUIyFYv4xFMWl5xHaPXpnbPhE1BXqe4W+cPHFkBxe5RbIoU0gaFJ2yH8p3xXp s6Qw== X-Gm-Message-State: APt69E0bzaRfFc+dY0zPefw9HDV15CJrKo4eP8YATE5V7GQTM9qdVTUK 6++gy16omoM5+2bcc86ZyStlxOT9nEtqNx6f9x5Paw== X-Google-Smtp-Source: AAOMgpdd+MKUDG7uSY3OGnu23svxAFf5zuJcbqyZqXPZixlEaeNqJ1T5Qs7Dwbcj0Fduxj57A0CRkDtrvB8L68CXT60= X-Received: by 2002:ac8:29e:: with SMTP id p30-v6mr1508255qtg.131.1530707918454; Wed, 04 Jul 2018 05:38:38 -0700 (PDT) MIME-Version: 1.0 References: <7e9beaa3218b1c46ea6a7399c5978c1538fce261.1530533998.git.amit.kucheria@linaro.org> <20180702185530.GD2050@tuxbook-pro> In-Reply-To: <20180702185530.GD2050@tuxbook-pro> From: Amit Kucheria Date: Wed, 4 Jul 2018 18:08:27 +0530 Message-ID: Subject: Re: [PATCH v4 3/6] thermal: tsens: Rename tsens-8996 to tsens-v2 for reuse To: Bjorn Andersson Cc: Linux Kernel Mailing List , Rajendra Nayak , linux-arm-msm , Eduardo Valentin , smohanad@codeaurora.org, Vivek Gautam , Andy Gross , Zhang Rui , Linux PM list Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Jul 3, 2018 at 12:23 AM Bjorn Andersson wrote: > > On Mon 02 Jul 05:44 PDT 2018, Amit Kucheria wrote: > > > The TSENS block inside the 8996 is internally classified as version 2 of > > the IP. Several other SoC families use this block and can share this code. > > > > We rename get_temp() to reflect that it can be used across the v2 family. > > > > Signed-off-by: Amit Kucheria > > --- > > drivers/thermal/qcom/Makefile | 2 +- > > drivers/thermal/qcom/{tsens-8996.c => tsens-v2.c} | 26 ++++++++--------------- > > 2 files changed, 10 insertions(+), 18 deletions(-) > > rename drivers/thermal/qcom/{tsens-8996.c => tsens-v2.c} (66%) > > > > diff --git a/drivers/thermal/qcom/Makefile b/drivers/thermal/qcom/Makefile > > index 2cc2193..a821929 100644 > > --- a/drivers/thermal/qcom/Makefile > > +++ b/drivers/thermal/qcom/Makefile > > @@ -1,2 +1,2 @@ > > obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o > > -qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-8996.o > > +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-v2.o > > diff --git a/drivers/thermal/qcom/tsens-8996.c b/drivers/thermal/qcom/tsens-v2.c > > similarity index 66% > > rename from drivers/thermal/qcom/tsens-8996.c > > rename to drivers/thermal/qcom/tsens-v2.c > > index e1f7781..2eca7ff 100644 > > --- a/drivers/thermal/qcom/tsens-8996.c > > +++ b/drivers/thermal/qcom/tsens-v2.c > > @@ -1,27 +1,18 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > /* > > * Copyright (c) 2015, The Linux Foundation. All rights reserved. > > - * > > - * This program is free software; you can redistribute it and/or modify > > - * it under the terms of the GNU General Public License version 2 and > > - * only version 2 as published by the Free Software Foundation. > > - * > > - * This program is distributed in the hope that it will be useful, > > - * but WITHOUT ANY WARRANTY; without even the implied warranty of > > - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > - * GNU General Public License for more details. > > - * > > + * Copyright (c) 2018, Linaro Limited > > */ > > > > -#include > > #include > > #include "tsens.h" > > > > -#define STATUS_OFFSET 0x10a0 > > -#define LAST_TEMP_MASK 0xfff > > +#define STATUS_OFFSET 0xa0 > > This is not backwards compatible with present day dts files, you need to > keep this effectively 0x10a0 when the memory region isn't split in two. Argh!! Good catch. > Perhaps you can just offset the ioremap by 4k when there's only one > region? That'll cause problems when we want to access some features exposed in the other register bank through the common get_temp_tsens_v2 function. The SW reset bit is in there that I'd like to add support for, for example. I can see a few other ways to detect this at runtime. None of them look pretty but option 3 looks least ugly at least to me. Any preferences? 1. Don't try to combine get_temp for 8996 with other v2 platforms. This would mean retaining a separate ops_8996, pointing to a custom get_temp(). We end up with two copies of the function. 2. In get_temp_tsens_v2(), check for number of regions but this has an overhead for each temperature read. struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); if (op->num_resources > 1) status_offset = 0xa0; else status_offset = 0x10a0; Read temperature(status_offset); 3. Restrict to init time (ideal) by storing the status_offset to struct tsens_device. This is then used directly in get_temp_generic_v2() to determine the actual address. This should work for 8996, 8916 and 8974 which all have a single memory region iomapp'ed. The last two don't even need this value since they have their own get_temp functions. See diff attached. I have to ask: Are there really devices in the field that rely on the existing *upstream* code and DT? If not, could we consider deprecating the "qcom,msm8996-tsens" property immediately or at least mark it for future removal? Regards, Amit diff --git i/drivers/thermal/qcom/tsens-common.c w/drivers/thermal/qcom/tsens-common.c index b1449ad..7982867 100644 --- i/drivers/thermal/qcom/tsens-common.c +++ w/drivers/thermal/qcom/tsens-common.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "tsens.h" @@ -126,6 +127,12 @@ static const struct regmap_config tsens_config = { int __init init_common(struct tsens_device *tmdev) { void __iomem *base; + struct platform_device *op = of_find_device_by_node(tmdev->dev->of_node); + + if (op->num_resources > 1) + tmdev->status_offset = 0xa0; + else + tmdev->status_offset = 0x10a0; base = of_iomap(tmdev->dev->of_node, 0); if (!base) diff --git i/drivers/thermal/qcom/tsens-v2.c w/drivers/thermal/qcom/tsens-v2.c index 0473f33..8400290 100644 --- i/drivers/thermal/qcom/tsens-v2.c +++ w/drivers/thermal/qcom/tsens-v2.c @@ -10,7 +10,6 @@ #define TRDY_OFFSET 0xe4 #define TRDY_READY_BIT BIT(0) -#define STATUS_OFFSET 0xa0 #define LAST_TEMP_MASK 0xfff #define STATUS_VALID_BIT BIT(21) #define CODE_SIGN_BIT BIT(11) @@ -28,7 +27,7 @@ static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp) if (code & TRDY_READY_BIT) return -ENODATA; - sensor_addr = STATUS_OFFSET + s->hw_id * 4; + sensor_addr = tmdev->status_offset + s->hw_id * 4; ret = regmap_read(tmdev->map, sensor_addr, &code); if (ret) return ret; diff --git i/drivers/thermal/qcom/tsens.h w/drivers/thermal/qcom/tsens.h index 69212cb..8a42a70 100644 --- i/drivers/thermal/qcom/tsens.h +++ w/drivers/thermal/qcom/tsens.h @@ -77,6 +77,7 @@ struct tsens_device { struct device *dev; u32 num_sensors; struct regmap *map; + u32 status_offset; struct tsens_context ctx; const struct tsens_ops *ops; struct tsens_sensor sensor[0];