Re: [PATCH v4 3/6] thermal: tsens: Rename tsens-8996 to tsens-v2 for reuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 3, 2018 at 12:23 AM Bjorn Andersson
<bjorn.andersson@xxxxxxxxxx> 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 <amit.kucheria@xxxxxxxxxx>
> > ---
> >  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 <linux/platform_device.h>
> >  #include <linux/regmap.h>
> >  #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 <linux/io.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/of_address.h>
+#include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #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];

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [Linux for Sparc]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux