All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: linux-pm@vger.kernel.org,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	linux-renesas-soc@vger.kernel.org,
	Zhang Rui <rui.zhang@intel.com>,
	Eduardo Valentin <edubezval@gmail.com>
Subject: Re: [PATCH v2 5/7] thermal: rcar_gen3_thermal: enable hardware interrupts for trip points
Date: Mon, 20 Mar 2017 21:25:50 +0100	[thread overview]
Message-ID: <20170320202550.GC1587@katana> (raw)
In-Reply-To: <20170317155300.21566-6-niklas.soderlund+renesas@ragnatech.se>

[-- Attachment #1: Type: text/plain, Size: 4765 bytes --]

Hi Niklas,

On Fri, Mar 17, 2017 at 04:52:58PM +0100, Niklas Söderlund wrote:
> Enable hardware trip points by implementing the set_trips callback. The
> thermal core will take care of setting the initial trip point window and
> to update it once the driver reports a TSC has moved outside it.
> 
> The interrupt structure for this device is a bit odd. There is not a
> dedicated IRQ for each TSC, instead the interrupts are shared between
> all TSCs. IRQn is fired if the temp monitored in IRQTEMPn is reached in
> any of the TSCs, example IRQ3 is fired if temperature in IRQTEMP3 is
> reached in either TSC0, TSC1 or TSC2.
> 
> For this reason the usage of interrupts in this driver is an all-on or
> all-off design. When an interrupt happens all TSCs are checked and all
> thermal zones are updated. This could be refined to be more fine grained
> but the thermal core takes care of only updating the thermal zones that
> have left their trip point window.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Looks mostly good, thanks!

...

>  static struct thermal_zone_of_device_ops rcar_gen3_tz_of_ops = {
>  	.get_temp	= rcar_gen3_thermal_get_temp,
> +	.set_trips	= rcar_gen3_thermal_set_trips,
>  };
>  
> +static void rcar_thermal_irq_set(struct rcar_gen3_thermal_priv *priv, int on)

'bool' instead of 'int'?

> +{
> +	unsigned int i;
> +	u32 val;
> +
> +	val = on ? IRQ_TEMPD1 | IRQ_TEMP2 : 0;

Very minor, merge the 2 lines?

	u32 val = on ? IRQ_TEMPD1 | IRQ_TEMP2 : 0;


> +
> +	for (i = 0; i < priv->num_tscs; i++)
> +		rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQMSK, val);
> +}
> +
> +static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
> +{
> +	struct rcar_gen3_thermal_priv *priv = data;
> +	unsigned long flags;
> +	u32 status;
> +	int i, ret = IRQ_HANDLED;
> +
> +	spin_lock_irqsave(&priv->lock, flags);

Why _irqsave? You are in interrupt context already.

> +	for (i = 0; i < priv->num_tscs; i++) {
> +		status = rcar_gen3_thermal_read(priv->tscs[i], REG_GEN3_IRQSTR);
> +		rcar_gen3_thermal_write(priv->tscs[i], REG_GEN3_IRQSTR, 0);
> +		if (status)
> +			ret = IRQ_WAKE_THREAD;
> +	}
> +
> +	if (ret == IRQ_WAKE_THREAD)
> +		rcar_thermal_irq_set(priv, 0);

'false' instead of '0'? I think this is more readable.

> +	spin_unlock_irqrestore(&priv->lock, flags);

Add a blank line before unlock?

> +
> +	return ret;
> +}
> +
> +static irqreturn_t rcar_gen3_thermal_irq_thread(int irq, void *data)
> +{
> +	struct rcar_gen3_thermal_priv *priv = data;
> +	unsigned long flags;
> +	int i;
> +
> +	for (i = 0; i < priv->num_tscs; i++)
> +		thermal_zone_device_update(priv->tscs[i]->zone,
> +					   THERMAL_EVENT_UNSPECIFIED);
> +
> +	spin_lock_irqsave(&priv->lock, flags);
> +	rcar_thermal_irq_set(priv, 1);

'true' instead of '1'?

> +	spin_unlock_irqrestore(&priv->lock, flags);
> +
> +	return IRQ_HANDLED;
> +}
> +

...

> @@ -252,7 +351,8 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct resource *res;
>  	struct thermal_zone_device *zone;
> -	int ret, i;
> +	int ret, irq, i;
> +	char *irqname;
>  	const struct rcar_gen3_thermal_data *match_data =
>  		of_device_get_match_data(dev);
>  
> @@ -269,8 +369,27 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
>  	if (!priv)
>  		return -ENOMEM;
>  
> +	spin_lock_init(&priv->lock);
> +
>  	platform_set_drvdata(pdev, priv);
>  
> +	for (i = 0; i < 2; i++) {

Maybe a comment saying that the driver works with two interrupts
currently, so the '2' gets explained?

> +		irq = platform_get_irq(pdev, i);
> +		if (irq < 0)
> +			return irq;
> +
> +		irqname = devm_kasprintf(dev, GFP_KERNEL, "%s:ch%d",
> +					 dev_name(dev), i);
> +		if (!irqname)
> +			return -ENOMEM;
> +
> +		ret = devm_request_threaded_irq(dev, irq, rcar_gen3_thermal_irq,
> +						rcar_gen3_thermal_irq_thread,
> +						IRQF_SHARED, irqname, priv);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	pm_runtime_enable(dev);
>  	pm_runtime_get_sync(dev);
>  
> @@ -307,6 +426,12 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
>  		}
>  		tsc->zone = zone;
>  		priv->num_tscs++;
> +
> +		ret = of_thermal_get_ntrips(tsc->zone);
> +		if (ret < 0)
> +			goto error_unregister;
> +
> +		dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret);
>  	}
>  
>  	if (!priv->num_tscs) {
> @@ -314,6 +439,8 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
>  		goto error_unregister;
>  	}
>  
> +	rcar_thermal_irq_set(priv, 1)

'true' instead of '1' again?

> +

Kind regards,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2017-03-20 20:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-17 15:52 [PATCH v2 0/7] thermal: rcar_gen3_thermal: add support for interrupt triggerd trip points Niklas Söderlund
2017-03-17 15:52 ` [PATCH v2 1/7] thermal: rcar_gen3_thermal: add delay in .thermal_init on r8a7796 Niklas Söderlund
2017-03-17 15:52 ` [PATCH v2 2/7] thermal: rcar_gen3_thermal: remove unneeded mutex Niklas Söderlund
2017-03-18  9:30   ` Sergei Shtylyov
2017-03-17 15:52 ` [PATCH v2 3/7] thermal: rcar_gen3_thermal: check that TSC exists before memory allocation Niklas Söderlund
2017-03-18 14:06   ` Geert Uytterhoeven
2017-03-20 20:02   ` Wolfram Sang
2017-03-17 15:52 ` [PATCH v2 4/7] thermal: rcar_gen3_thermal: record and check number of TSCs found Niklas Söderlund
2017-03-18 14:09   ` Geert Uytterhoeven
2017-03-20 20:09   ` Wolfram Sang
2017-03-17 15:52 ` [PATCH v2 5/7] thermal: rcar_gen3_thermal: enable hardware interrupts for trip points Niklas Söderlund
2017-03-20 20:25   ` Wolfram Sang [this message]
2017-03-17 15:52 ` [PATCH v2 6/7] thermal: rcar_gen3_thermal: store device match data in private structure Niklas Söderlund
2017-03-17 15:53 ` [PATCH v2 7/7] thermal: rcar_gen3_thermal: add suspend and resume support Niklas Söderlund
2017-03-20 20:27   ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170320202550.GC1587@katana \
    --to=wsa@the-dreams.de \
    --cc=edubezval@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=rui.zhang@intel.com \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.