diff mbox series

[v7,2/5] drivers: thermal: tsens: Add support for combined interrupt

Message ID 20220818220245.338396-2-robimarko@gmail.com
State Accepted
Commit 4360af35273b742ffc6605ce44f37ac654272443
Headers show
Series [v7,1/5] dt-bindings: thermal: tsens: Add ipq8074 compatible | expand

Commit Message

Robert Marko Aug. 18, 2022, 10:02 p.m. UTC
Despite using tsens v2.3 IP, IPQ8074 and IPQ6018 only have one IRQ for
signaling both up/low and critical trips.

Signed-off-by: Robert Marko <robimarko@gmail.com>
---
Changes in v7:
* Rebase to apply on next-20220818

Changes in v6:
* Check critical IRQ handler return, simplify up/low return
---
 drivers/thermal/qcom/tsens-8960.c |  1 +
 drivers/thermal/qcom/tsens-v0_1.c |  1 +
 drivers/thermal/qcom/tsens-v1.c   |  1 +
 drivers/thermal/qcom/tsens-v2.c   |  1 +
 drivers/thermal/qcom/tsens.c      | 38 ++++++++++++++++++++++++++-----
 drivers/thermal/qcom/tsens.h      |  2 ++
 6 files changed, 38 insertions(+), 6 deletions(-)

Comments

Bjorn Andersson Oct. 17, 2022, 7:01 p.m. UTC | #1
On Fri, Aug 19, 2022 at 12:02:42AM +0200, Robert Marko wrote:
> Despite using tsens v2.3 IP, IPQ8074 and IPQ6018 only have one IRQ for
> signaling both up/low and critical trips.
> 
> Signed-off-by: Robert Marko <robimarko@gmail.com>
> ---
> Changes in v7:
> * Rebase to apply on next-20220818
> 
> Changes in v6:
> * Check critical IRQ handler return, simplify up/low return
> ---
>  drivers/thermal/qcom/tsens-8960.c |  1 +
>  drivers/thermal/qcom/tsens-v0_1.c |  1 +
>  drivers/thermal/qcom/tsens-v1.c   |  1 +
>  drivers/thermal/qcom/tsens-v2.c   |  1 +
>  drivers/thermal/qcom/tsens.c      | 38 ++++++++++++++++++++++++++-----
>  drivers/thermal/qcom/tsens.h      |  2 ++
>  6 files changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
> index 67c1748cdf73..ee584e5b07e5 100644
> --- a/drivers/thermal/qcom/tsens-8960.c
> +++ b/drivers/thermal/qcom/tsens-8960.c
> @@ -269,6 +269,7 @@ static const struct tsens_ops ops_8960 = {
>  static struct tsens_features tsens_8960_feat = {
>  	.ver_major	= VER_0,
>  	.crit_int	= 0,
> +	.combo_int	= 0,
>  	.adc		= 1,
>  	.srot_split	= 0,
>  	.max_sensors	= 11,
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index f136cb350238..6effb822bf3c 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -539,6 +539,7 @@ static int calibrate_9607(struct tsens_priv *priv)
>  static struct tsens_features tsens_v0_1_feat = {
>  	.ver_major	= VER_0_1,
>  	.crit_int	= 0,
> +	.combo_int	= 0,
>  	.adc		= 1,
>  	.srot_split	= 1,
>  	.max_sensors	= 11,
> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> index 573e261ccca7..a4f561a6e582 100644
> --- a/drivers/thermal/qcom/tsens-v1.c
> +++ b/drivers/thermal/qcom/tsens-v1.c
> @@ -302,6 +302,7 @@ static int calibrate_8976(struct tsens_priv *priv)
>  static struct tsens_features tsens_v1_feat = {
>  	.ver_major	= VER_1_X,
>  	.crit_int	= 0,
> +	.combo_int	= 0,
>  	.adc		= 1,
>  	.srot_split	= 1,
>  	.max_sensors	= 11,
> diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
> index b293ed32174b..129cdb247381 100644
> --- a/drivers/thermal/qcom/tsens-v2.c
> +++ b/drivers/thermal/qcom/tsens-v2.c
> @@ -31,6 +31,7 @@
>  static struct tsens_features tsens_v2_feat = {
>  	.ver_major	= VER_2_X,
>  	.crit_int	= 1,
> +	.combo_int	= 0,
>  	.adc		= 0,
>  	.srot_split	= 1,
>  	.max_sensors	= 16,
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index b1b10005fb28..816769af8813 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -532,6 +532,27 @@ static irqreturn_t tsens_irq_thread(int irq, void *data)
>  	return IRQ_HANDLED;
>  }
>  
> +/**
> + * tsens_combined_irq_thread - Threaded interrupt handler for combined interrupts

This should have () after the function name. Perhaps Daniel could add
that as he picks the patch?

Reviewed-by: Bjorn Andersson <andersson@kernel.org>

Regards,
Bjorn

> + * @irq: irq number
> + * @data: tsens controller private data
> + *
> + * Handle the combined interrupt as if it were 2 separate interrupts, so call the
> + * critical handler first and then the up/low one.
> + *
> + * Return: IRQ_HANDLED
> + */
> +static irqreturn_t tsens_combined_irq_thread(int irq, void *data)
> +{
> +	irqreturn_t ret;
> +
> +	ret = tsens_critical_irq_thread(irq, data);
> +	if (ret != IRQ_HANDLED)
> +		return ret;
> +
> +	return tsens_irq_thread(irq, data);
> +}
> +
>  static int tsens_set_trips(struct thermal_zone_device *tz, int low, int high)
>  {
>  	struct tsens_sensor *s = tz->devdata;
> @@ -1071,13 +1092,18 @@ static int tsens_register(struct tsens_priv *priv)
>  				   tsens_mC_to_hw(priv->sensor, 0));
>  	}
>  
> -	ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
> -	if (ret < 0)
> -		return ret;
> +	if (priv->feat->combo_int) {
> +		ret = tsens_register_irq(priv, "combined",
> +					 tsens_combined_irq_thread);
> +	} else {
> +		ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
> +		if (ret < 0)
> +			return ret;
>  
> -	if (priv->feat->crit_int)
> -		ret = tsens_register_irq(priv, "critical",
> -					 tsens_critical_irq_thread);
> +		if (priv->feat->crit_int)
> +			ret = tsens_register_irq(priv, "critical",
> +						 tsens_critical_irq_thread);
> +	}
>  
>  	return ret;
>  }
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index ba05c8233356..1678c5e9e60b 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -493,6 +493,7 @@ enum regfield_ids {
>   * struct tsens_features - Features supported by the IP
>   * @ver_major: Major number of IP version
>   * @crit_int: does the IP support critical interrupts?
> + * @combo_int: does the IP use one IRQ for up, low and critical thresholds?
>   * @adc:      do the sensors only output adc code (instead of temperature)?
>   * @srot_split: does the IP neatly splits the register space into SROT and TM,
>   *              with SROT only being available to secure boot firmware?
> @@ -502,6 +503,7 @@ enum regfield_ids {
>  struct tsens_features {
>  	unsigned int ver_major;
>  	unsigned int crit_int:1;
> +	unsigned int combo_int:1;
>  	unsigned int adc:1;
>  	unsigned int srot_split:1;
>  	unsigned int has_watchdog:1;
> -- 
> 2.37.2
>
Daniel Lezcano Oct. 21, 2022, 4:52 p.m. UTC | #2
On 17/10/2022 21:01, Bjorn Andersson wrote:

[ ... ]

> 
> This should have () after the function name. Perhaps Daniel could add
> that as he picks the patch?

Applied and parenthesis added

> Reviewed-by: Bjorn Andersson <andersson@kernel.org>
> 
> Regards,
> Bjorn
[ ... ]
diff mbox series

Patch

diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index 67c1748cdf73..ee584e5b07e5 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -269,6 +269,7 @@  static const struct tsens_ops ops_8960 = {
 static struct tsens_features tsens_8960_feat = {
 	.ver_major	= VER_0,
 	.crit_int	= 0,
+	.combo_int	= 0,
 	.adc		= 1,
 	.srot_split	= 0,
 	.max_sensors	= 11,
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index f136cb350238..6effb822bf3c 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -539,6 +539,7 @@  static int calibrate_9607(struct tsens_priv *priv)
 static struct tsens_features tsens_v0_1_feat = {
 	.ver_major	= VER_0_1,
 	.crit_int	= 0,
+	.combo_int	= 0,
 	.adc		= 1,
 	.srot_split	= 1,
 	.max_sensors	= 11,
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 573e261ccca7..a4f561a6e582 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -302,6 +302,7 @@  static int calibrate_8976(struct tsens_priv *priv)
 static struct tsens_features tsens_v1_feat = {
 	.ver_major	= VER_1_X,
 	.crit_int	= 0,
+	.combo_int	= 0,
 	.adc		= 1,
 	.srot_split	= 1,
 	.max_sensors	= 11,
diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
index b293ed32174b..129cdb247381 100644
--- a/drivers/thermal/qcom/tsens-v2.c
+++ b/drivers/thermal/qcom/tsens-v2.c
@@ -31,6 +31,7 @@ 
 static struct tsens_features tsens_v2_feat = {
 	.ver_major	= VER_2_X,
 	.crit_int	= 1,
+	.combo_int	= 0,
 	.adc		= 0,
 	.srot_split	= 1,
 	.max_sensors	= 16,
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index b1b10005fb28..816769af8813 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -532,6 +532,27 @@  static irqreturn_t tsens_irq_thread(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
+/**
+ * tsens_combined_irq_thread - Threaded interrupt handler for combined interrupts
+ * @irq: irq number
+ * @data: tsens controller private data
+ *
+ * Handle the combined interrupt as if it were 2 separate interrupts, so call the
+ * critical handler first and then the up/low one.
+ *
+ * Return: IRQ_HANDLED
+ */
+static irqreturn_t tsens_combined_irq_thread(int irq, void *data)
+{
+	irqreturn_t ret;
+
+	ret = tsens_critical_irq_thread(irq, data);
+	if (ret != IRQ_HANDLED)
+		return ret;
+
+	return tsens_irq_thread(irq, data);
+}
+
 static int tsens_set_trips(struct thermal_zone_device *tz, int low, int high)
 {
 	struct tsens_sensor *s = tz->devdata;
@@ -1071,13 +1092,18 @@  static int tsens_register(struct tsens_priv *priv)
 				   tsens_mC_to_hw(priv->sensor, 0));
 	}
 
-	ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
-	if (ret < 0)
-		return ret;
+	if (priv->feat->combo_int) {
+		ret = tsens_register_irq(priv, "combined",
+					 tsens_combined_irq_thread);
+	} else {
+		ret = tsens_register_irq(priv, "uplow", tsens_irq_thread);
+		if (ret < 0)
+			return ret;
 
-	if (priv->feat->crit_int)
-		ret = tsens_register_irq(priv, "critical",
-					 tsens_critical_irq_thread);
+		if (priv->feat->crit_int)
+			ret = tsens_register_irq(priv, "critical",
+						 tsens_critical_irq_thread);
+	}
 
 	return ret;
 }
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index ba05c8233356..1678c5e9e60b 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -493,6 +493,7 @@  enum regfield_ids {
  * struct tsens_features - Features supported by the IP
  * @ver_major: Major number of IP version
  * @crit_int: does the IP support critical interrupts?
+ * @combo_int: does the IP use one IRQ for up, low and critical thresholds?
  * @adc:      do the sensors only output adc code (instead of temperature)?
  * @srot_split: does the IP neatly splits the register space into SROT and TM,
  *              with SROT only being available to secure boot firmware?
@@ -502,6 +503,7 @@  enum regfield_ids {
 struct tsens_features {
 	unsigned int ver_major;
 	unsigned int crit_int:1;
+	unsigned int combo_int:1;
 	unsigned int adc:1;
 	unsigned int srot_split:1;
 	unsigned int has_watchdog:1;