linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/qoriq: fix getting tmu range
@ 2023-10-20  8:13 Peng Fan (OSS)
  2024-01-11  9:56 ` Sascha Hauer
  2024-01-25 11:07 ` Peng Fan
  0 siblings, 2 replies; 4+ messages in thread
From: Peng Fan (OSS) @ 2023-10-20  8:13 UTC (permalink / raw)
  To: rafael, daniel.lezcano; +Cc: rui.zhang, linux-pm, linux-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

TMU Version 1 has 4 TTRCRs, while TMU Version >=2 has 16 TTRCRs.
So limit the len to 4 will report "invalid range data" for i.MX93.

This patch drop the local array with allocated ttrcr array and
able to support larger tmu ranges.

Fixes: f12d60c81fce ("thermal/drivers/qoriq: Support version 2.1")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/thermal/qoriq_thermal.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index ccc2eea7f9f5..404f01cca4da 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -57,6 +57,9 @@
 #define REGS_TTRnCR(n)	(0xf10 + 4 * (n)) /* Temperature Range n
 					   * Control Register
 					   */
+#define NUM_TTRCR_V1	4
+#define NUM_TTRCR_MAX	16
+
 #define REGS_IPBRR(n)		(0xbf8 + 4 * (n)) /* IP Block Revision
 						   * Register n
 						   */
@@ -71,6 +74,7 @@ struct qoriq_sensor {
 
 struct qoriq_tmu_data {
 	int ver;
+	u32 ttrcr[NUM_TTRCR_MAX];
 	struct regmap *regmap;
 	struct clk *clk;
 	struct qoriq_sensor	sensor[SITES_MAX];
@@ -182,17 +186,17 @@ static int qoriq_tmu_calibration(struct device *dev,
 				 struct qoriq_tmu_data *data)
 {
 	int i, val, len;
-	u32 range[4];
 	const u32 *calibration;
 	struct device_node *np = dev->of_node;
 
 	len = of_property_count_u32_elems(np, "fsl,tmu-range");
-	if (len < 0 || len > 4) {
+	if (len < 0 || (data->ver == TMU_VER1 && len > NUM_TTRCR_V1) ||
+	    (data->ver > TMU_VER1 && len > NUM_TTRCR_MAX)) {
 		dev_err(dev, "invalid range data.\n");
 		return len;
 	}
 
-	val = of_property_read_u32_array(np, "fsl,tmu-range", range, len);
+	val = of_property_read_u32_array(np, "fsl,tmu-range", data->ttrcr, len);
 	if (val != 0) {
 		dev_err(dev, "failed to read range data.\n");
 		return val;
@@ -200,7 +204,7 @@ static int qoriq_tmu_calibration(struct device *dev,
 
 	/* Init temperature range registers */
 	for (i = 0; i < len; i++)
-		regmap_write(data->regmap, REGS_TTRnCR(i), range[i]);
+		regmap_write(data->regmap, REGS_TTRnCR(i), data->ttrcr[i]);
 
 	calibration = of_get_property(np, "fsl,tmu-calibration", &len);
 	if (calibration == NULL || len % 8) {
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal/drivers/qoriq: fix getting tmu range
  2023-10-20  8:13 [PATCH] thermal/drivers/qoriq: fix getting tmu range Peng Fan (OSS)
@ 2024-01-11  9:56 ` Sascha Hauer
  2024-01-11 10:47   ` Peng Fan
  2024-01-25 11:07 ` Peng Fan
  1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2024-01-11  9:56 UTC (permalink / raw)
  To: Peng Fan (OSS)
  Cc: rafael, daniel.lezcano, rui.zhang, linux-pm, linux-kernel, Peng Fan

Hi Peng,

On Fri, Oct 20, 2023 at 04:13:37PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> TMU Version 1 has 4 TTRCRs, while TMU Version >=2 has 16 TTRCRs.
> So limit the len to 4 will report "invalid range data" for i.MX93.
> 
> This patch drop the local array with allocated ttrcr array and
> able to support larger tmu ranges.
> 
> Fixes: f12d60c81fce ("thermal/drivers/qoriq: Support version 2.1")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/thermal/qoriq_thermal.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index ccc2eea7f9f5..404f01cca4da 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -57,6 +57,9 @@
>  #define REGS_TTRnCR(n)	(0xf10 + 4 * (n)) /* Temperature Range n
>  					   * Control Register
>  					   */
> +#define NUM_TTRCR_V1	4
> +#define NUM_TTRCR_MAX	16
> +
>  #define REGS_IPBRR(n)		(0xbf8 + 4 * (n)) /* IP Block Revision
>  						   * Register n
>  						   */
> @@ -71,6 +74,7 @@ struct qoriq_sensor {
>  
>  struct qoriq_tmu_data {
>  	int ver;
> +	u32 ttrcr[NUM_TTRCR_MAX];
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	struct qoriq_sensor	sensor[SITES_MAX];
> @@ -182,17 +186,17 @@ static int qoriq_tmu_calibration(struct device *dev,
>  				 struct qoriq_tmu_data *data)
>  {
>  	int i, val, len;
> -	u32 range[4];

Why don't you keep the array locally on the stack? Will it be needed
elsewhere later?

Other than that:

Tested-by: Sascha Hauer <s.hauer@pengutronix.de>

Would be great if this could be picked up anytime soon.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] thermal/drivers/qoriq: fix getting tmu range
  2024-01-11  9:56 ` Sascha Hauer
@ 2024-01-11 10:47   ` Peng Fan
  0 siblings, 0 replies; 4+ messages in thread
From: Peng Fan @ 2024-01-11 10:47 UTC (permalink / raw)
  To: Sascha Hauer, Peng Fan (OSS)
  Cc: rafael, daniel.lezcano, rui.zhang, linux-pm, linux-kernel

Hi Sascha,

> Subject: Re: [PATCH] thermal/drivers/qoriq: fix getting tmu range
>
> Hi Peng,
>
> On Fri, Oct 20, 2023 at 04:13:37PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > TMU Version 1 has 4 TTRCRs, while TMU Version >=2 has 16 TTRCRs.
> > So limit the len to 4 will report "invalid range data" for i.MX93.
> >
> > This patch drop the local array with allocated ttrcr array and able to
> > support larger tmu ranges.
> >
> > Fixes: f12d60c81fce ("thermal/drivers/qoriq: Support version 2.1")
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/thermal/qoriq_thermal.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/thermal/qoriq_thermal.c
> > b/drivers/thermal/qoriq_thermal.c index ccc2eea7f9f5..404f01cca4da
> > 100644
> > --- a/drivers/thermal/qoriq_thermal.c
> > +++ b/drivers/thermal/qoriq_thermal.c
> > @@ -57,6 +57,9 @@
> >  #define REGS_TTRnCR(n)     (0xf10 + 4 * (n)) /* Temperature Range n
> >                                        * Control Register
> >                                        */
> > +#define NUM_TTRCR_V1       4
> > +#define NUM_TTRCR_MAX      16
> > +
> >  #define REGS_IPBRR(n)              (0xbf8 + 4 * (n)) /* IP Block Revision
> >                                                * Register n
> >                                                */
> > @@ -71,6 +74,7 @@ struct qoriq_sensor {
> >
> >  struct qoriq_tmu_data {
> >     int ver;
> > +   u32 ttrcr[NUM_TTRCR_MAX];
> >     struct regmap *regmap;
> >     struct clk *clk;
> >     struct qoriq_sensor     sensor[SITES_MAX];
> > @@ -182,17 +186,17 @@ static int qoriq_tmu_calibration(struct device
> *dev,
> >                              struct qoriq_tmu_data *data)
> >  {
> >     int i, val, len;
> > -   u32 range[4];
>
> Why don't you keep the array locally on the stack? Will it be needed
> elsewhere later?

Because max 16 as of now, it will consume 64bytes in stack, so I
move it out.

>
> Other than that:
>
> Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
>

Thanks for testing this patch.

Thanks,
Peng.

> Would be great if this could be picked up anytime soon.
>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       |
> http://www.p/
> engutronix.de%2F&data=05%7C02%7Cpeng.fan%40nxp.com%7C227277d8c0
> 20468aaf6e08dc128ba2ab%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%
> 7C0%7C638405638133353126%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC
> 4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%
> 7C%7C%7C&sdata=ilwPz4Bs6f7CLf2snic7S%2FUsff0AYCgsFuZP9d2UExo%3D&
> reserved=0  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] thermal/drivers/qoriq: fix getting tmu range
  2023-10-20  8:13 [PATCH] thermal/drivers/qoriq: fix getting tmu range Peng Fan (OSS)
  2024-01-11  9:56 ` Sascha Hauer
@ 2024-01-25 11:07 ` Peng Fan
  1 sibling, 0 replies; 4+ messages in thread
From: Peng Fan @ 2024-01-25 11:07 UTC (permalink / raw)
  To: Peng Fan (OSS), rafael, daniel.lezcano
  Cc: rui.zhang, linux-pm, linux-kernel, Sascha Hauer

Hi Daniel,

> Subject: [PATCH] thermal/drivers/qoriq: fix getting tmu range
> 

Would you pick up this patch?

Thanks,
Peng.

> From: Peng Fan <peng.fan@nxp.com>
> 
> TMU Version 1 has 4 TTRCRs, while TMU Version >=2 has 16 TTRCRs.
> So limit the len to 4 will report "invalid range data" for i.MX93.
> 
> This patch drop the local array with allocated ttrcr array and able to support
> larger tmu ranges.
> 
> Fixes: f12d60c81fce ("thermal/drivers/qoriq: Support version 2.1")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/thermal/qoriq_thermal.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/thermal/qoriq_thermal.c
> b/drivers/thermal/qoriq_thermal.c index ccc2eea7f9f5..404f01cca4da
> 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -57,6 +57,9 @@
>  #define REGS_TTRnCR(n)	(0xf10 + 4 * (n)) /* Temperature Range n
>  					   * Control Register
>  					   */
> +#define NUM_TTRCR_V1	4
> +#define NUM_TTRCR_MAX	16
> +
>  #define REGS_IPBRR(n)		(0xbf8 + 4 * (n)) /* IP Block Revision
>  						   * Register n
>  						   */
> @@ -71,6 +74,7 @@ struct qoriq_sensor {
> 
>  struct qoriq_tmu_data {
>  	int ver;
> +	u32 ttrcr[NUM_TTRCR_MAX];
>  	struct regmap *regmap;
>  	struct clk *clk;
>  	struct qoriq_sensor	sensor[SITES_MAX];
> @@ -182,17 +186,17 @@ static int qoriq_tmu_calibration(struct device *dev,
>  				 struct qoriq_tmu_data *data)
>  {
>  	int i, val, len;
> -	u32 range[4];
>  	const u32 *calibration;
>  	struct device_node *np = dev->of_node;
> 
>  	len = of_property_count_u32_elems(np, "fsl,tmu-range");
> -	if (len < 0 || len > 4) {
> +	if (len < 0 || (data->ver == TMU_VER1 && len > NUM_TTRCR_V1) ||
> +	    (data->ver > TMU_VER1 && len > NUM_TTRCR_MAX)) {
>  		dev_err(dev, "invalid range data.\n");
>  		return len;
>  	}
> 
> -	val = of_property_read_u32_array(np, "fsl,tmu-range", range, len);
> +	val = of_property_read_u32_array(np, "fsl,tmu-range", data->ttrcr,
> +len);
>  	if (val != 0) {
>  		dev_err(dev, "failed to read range data.\n");
>  		return val;
> @@ -200,7 +204,7 @@ static int qoriq_tmu_calibration(struct device *dev,
> 
>  	/* Init temperature range registers */
>  	for (i = 0; i < len; i++)
> -		regmap_write(data->regmap, REGS_TTRnCR(i), range[i]);
> +		regmap_write(data->regmap, REGS_TTRnCR(i), data->ttrcr[i]);
> 
>  	calibration = of_get_property(np, "fsl,tmu-calibration", &len);
>  	if (calibration == NULL || len % 8) {
> --
> 2.37.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-25 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-20  8:13 [PATCH] thermal/drivers/qoriq: fix getting tmu range Peng Fan (OSS)
2024-01-11  9:56 ` Sascha Hauer
2024-01-11 10:47   ` Peng Fan
2024-01-25 11:07 ` Peng Fan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).