[v4,6/6] Input: imx6ul_tsc - set glitch threshold by DTS property

Message ID 20250917080534.1772202-7-dario.binacchi@amarulasolutions.com
State New
Headers show
Series
  • Input: imx6ul_tsc - set glitch threshold by dts property
Related show

Commit Message

Dario Binacchi Sept. 17, 2025, 8:05 a.m. UTC
Set the glitch threshold previously hardcoded in the driver. The change
is backward compatible.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

---

Changes in v4:
- Adjust property description fsl,imx6ul-tsc.yaml following the
  suggestions of Conor Dooley and Frank Li.

Changes in v3:
- Remove the final part of the description that refers to
  implementation details in fsl,imx6ul-tsc.yaml.

Changes in v2:
- Replace patch ("dt-bindings: input: touchscreen: fsl,imx6ul-tsc: add
  fsl,glitch-threshold") with ("dt-bindings: touchscreen: add
  touchscreen-glitch-threshold-ns property"), making the previous property
  general by moving it to touchscreen.yaml.
- Rework "Input: imx6ul_tsc - set glitch threshold by DTS property" patch
  to match changes made to the DTS property.
- Move "Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros"
  patch right after the patch fixing the typo.
- Rework to match changes made to the DTS property.

 drivers/input/touchscreen/imx6ul_tsc.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

Frank Li Sept. 17, 2025, 4:20 p.m. UTC | #1
On Wed, Sep 17, 2025 at 10:05:11AM +0200, Dario Binacchi wrote:
> Set the glitch threshold previously hardcoded in the driver. The change
> is backward compatible.

Set the glitch threshold by DTS property and keep the existing default
behavior if the 'touchscreen-glitch-threshold-ns' not present.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
>
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
>
> ---
>
> Changes in v4:
> - Adjust property description fsl,imx6ul-tsc.yaml following the
>   suggestions of Conor Dooley and Frank Li.
>
> Changes in v3:
> - Remove the final part of the description that refers to
>   implementation details in fsl,imx6ul-tsc.yaml.
>
> Changes in v2:
> - Replace patch ("dt-bindings: input: touchscreen: fsl,imx6ul-tsc: add
>   fsl,glitch-threshold") with ("dt-bindings: touchscreen: add
>   touchscreen-glitch-threshold-ns property"), making the previous property
>   general by moving it to touchscreen.yaml.
> - Rework "Input: imx6ul_tsc - set glitch threshold by DTS property" patch
>   to match changes made to the DTS property.
> - Move "Input: imx6ul_tsc - use BIT, FIELD_{GET,PREP} and GENMASK macros"
>   patch right after the patch fixing the typo.
> - Rework to match changes made to the DTS property.
>
>  drivers/input/touchscreen/imx6ul_tsc.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
> index e2c59cc7c82c..0d753aa05fbf 100644
> --- a/drivers/input/touchscreen/imx6ul_tsc.c
> +++ b/drivers/input/touchscreen/imx6ul_tsc.c
> @@ -79,7 +79,7 @@
>  #define MEASURE_SIG_EN		BIT(0)
>  #define VALID_SIG_EN		BIT(8)
>  #define DE_GLITCH_MASK		GENMASK(30, 29)
> -#define DE_GLITCH_2		0x02
> +#define DE_GLITCH_DEF		0x02
>  #define START_SENSE		BIT(12)
>  #define TSC_DISABLE		BIT(16)
>  #define DETECT_MODE		0x2
> @@ -98,6 +98,7 @@ struct imx6ul_tsc {
>  	u32 pre_charge_time;
>  	bool average_enable;
>  	u32 average_select;
> +	u32 de_glitch;
>
>  	struct completion completion;
>  };
> @@ -205,7 +206,7 @@ static void imx6ul_tsc_set(struct imx6ul_tsc *tsc)
>  	basic_setting |= AUTO_MEASURE;
>  	writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING);
>
> -	debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, DE_GLITCH_2);
> +	debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, tsc->de_glitch);
>  	writel(debug_mode2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
>
>  	writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME);
> @@ -391,6 +392,7 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
>  	int tsc_irq;
>  	int adc_irq;
>  	u32 average_samples;
> +	u32 de_glitch;
>
>  	tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
>  	if (!tsc)
> @@ -513,6 +515,26 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  	}
>
> +	err = of_property_read_u32(np, "touchscreen-glitch-threshold-ns",
> +				   &de_glitch);
> +	if (err) {
> +		tsc->de_glitch = DE_GLITCH_DEF;
> +	} else {
> +		u64 cycles;
> +		unsigned long rate = clk_get_rate(tsc->tsc_clk);
> +
> +		cycles = DIV64_U64_ROUND_UP((u64)de_glitch * rate, NSEC_PER_SEC);
> +
> +		if (cycles <= 0x3ff)
> +			tsc->de_glitch = 3;
> +		else if (cycles <= 0x7ff)
> +			tsc->de_glitch = 2;
> +		else if (cycles <= 0xfff)
> +			tsc->de_glitch = 1;
> +		else
> +			tsc->de_glitch = 0;
> +	}
> +
>  	err = input_register_device(tsc->input);
>  	if (err) {
>  		dev_err(&pdev->dev,
> --
> 2.43.0
>

To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.

Patch

diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
index e2c59cc7c82c..0d753aa05fbf 100644
--- a/drivers/input/touchscreen/imx6ul_tsc.c
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -79,7 +79,7 @@ 
 #define MEASURE_SIG_EN		BIT(0)
 #define VALID_SIG_EN		BIT(8)
 #define DE_GLITCH_MASK		GENMASK(30, 29)
-#define DE_GLITCH_2		0x02
+#define DE_GLITCH_DEF		0x02
 #define START_SENSE		BIT(12)
 #define TSC_DISABLE		BIT(16)
 #define DETECT_MODE		0x2
@@ -98,6 +98,7 @@  struct imx6ul_tsc {
 	u32 pre_charge_time;
 	bool average_enable;
 	u32 average_select;
+	u32 de_glitch;
 
 	struct completion completion;
 };
@@ -205,7 +206,7 @@  static void imx6ul_tsc_set(struct imx6ul_tsc *tsc)
 	basic_setting |= AUTO_MEASURE;
 	writel(basic_setting, tsc->tsc_regs + REG_TSC_BASIC_SETTING);
 
-	debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, DE_GLITCH_2);
+	debug_mode2 = FIELD_PREP(DE_GLITCH_MASK, tsc->de_glitch);
 	writel(debug_mode2, tsc->tsc_regs + REG_TSC_DEBUG_MODE2);
 
 	writel(tsc->pre_charge_time, tsc->tsc_regs + REG_TSC_PRE_CHARGE_TIME);
@@ -391,6 +392,7 @@  static int imx6ul_tsc_probe(struct platform_device *pdev)
 	int tsc_irq;
 	int adc_irq;
 	u32 average_samples;
+	u32 de_glitch;
 
 	tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
 	if (!tsc)
@@ -513,6 +515,26 @@  static int imx6ul_tsc_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	err = of_property_read_u32(np, "touchscreen-glitch-threshold-ns",
+				   &de_glitch);
+	if (err) {
+		tsc->de_glitch = DE_GLITCH_DEF;
+	} else {
+		u64 cycles;
+		unsigned long rate = clk_get_rate(tsc->tsc_clk);
+
+		cycles = DIV64_U64_ROUND_UP((u64)de_glitch * rate, NSEC_PER_SEC);
+
+		if (cycles <= 0x3ff)
+			tsc->de_glitch = 3;
+		else if (cycles <= 0x7ff)
+			tsc->de_glitch = 2;
+		else if (cycles <= 0xfff)
+			tsc->de_glitch = 1;
+		else
+			tsc->de_glitch = 0;
+	}
+
 	err = input_register_device(tsc->input);
 	if (err) {
 		dev_err(&pdev->dev,