Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f43d3ec3 authored by Guy Shapiro's avatar Guy Shapiro Committed by Dmitry Torokhov
Browse files

Input: imx6ul_tsc - generalize the averaging property



Make the avarage-samples property a general touchscreen property
rather than imx6ul device specific.

Signed-off-by: default avatarGuy Shapiro <guy.shapiro@mobi-wize.com>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 34888602
Loading
Loading
Loading
Loading
+3 −8
Original line number Original line Diff line number Diff line
@@ -17,13 +17,8 @@ Optional properties:
  This value depends on the touch screen.
  This value depends on the touch screen.
- pre-charge-time: the touch screen need some time to precharge.
- pre-charge-time: the touch screen need some time to precharge.
  This value depends on the touch screen.
  This value depends on the touch screen.
- average-samples: Number of data samples which are averaged for each read.
- touchscreen-average-samples: Number of data samples which are averaged for
	Valid values 0-4
  each read. Valid values are 1, 4, 8, 16 and 32.
	0 =  1 sample
	1 =  4 samples
	2 =  8 samples
	3 = 16 samples
	4 = 32 samples


Example:
Example:
	tsc: tsc@02040000 {
	tsc: tsc@02040000 {
@@ -39,6 +34,6 @@ Example:
		xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
		xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
		measure-delay-time = <0xfff>;
		measure-delay-time = <0xfff>;
		pre-charge-time = <0xffff>;
		pre-charge-time = <0xffff>;
		average-samples = <4>;
		touchscreen-average-samples = <32>;
		status = "okay";
		status = "okay";
	};
	};
+3 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,9 @@ Optional properties for Touchscreens:
 - touchscreen-fuzz-pressure	: pressure noise value of the absolute input
 - touchscreen-fuzz-pressure	: pressure noise value of the absolute input
				  device (arbitrary range dependent on the
				  device (arbitrary range dependent on the
				  controller)
				  controller)
 - touchscreen-average-samples : Number of data samples which are averaged
				  for each read (valid values dependent on the
				  controller)
 - touchscreen-inverted-x	: X axis is inverted (boolean)
 - touchscreen-inverted-x	: X axis is inverted (boolean)
 - touchscreen-inverted-y	: Y axis is inverted (boolean)
 - touchscreen-inverted-y	: Y axis is inverted (boolean)
 - touchscreen-swapped-x-y	: X and Y axis are swapped (boolean)
 - touchscreen-swapped-x-y	: X and Y axis are swapped (boolean)
+27 −11
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/io.h>
#include <linux/log2.h>


/* ADC configuration registers field define */
/* ADC configuration registers field define */
#define ADC_AIEN		(0x1 << 7)
#define ADC_AIEN		(0x1 << 7)
@@ -93,7 +94,8 @@ struct imx6ul_tsc {


	u32 measure_delay_time;
	u32 measure_delay_time;
	u32 pre_charge_time;
	u32 pre_charge_time;
	u32 average_samples;
	bool average_enable;
	u32 average_select;


	struct completion completion;
	struct completion completion;
};
};
@@ -117,9 +119,9 @@ static int imx6ul_adc_init(struct imx6ul_tsc *tsc)
	adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK;
	adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK;
	adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK);
	adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK);
	adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE;
	adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE;
	if (tsc->average_samples) {
	if (tsc->average_enable) {
		adc_cfg &= ~ADC_AVGS_MASK;
		adc_cfg &= ~ADC_AVGS_MASK;
		adc_cfg |= (tsc->average_samples - 1) << ADC_AVGS_SHIFT;
		adc_cfg |= (tsc->average_select) << ADC_AVGS_SHIFT;
	}
	}
	adc_cfg &= ~ADC_HARDWARE_TRIGGER;
	adc_cfg &= ~ADC_HARDWARE_TRIGGER;
	writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG);
	writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG);
@@ -132,7 +134,7 @@ static int imx6ul_adc_init(struct imx6ul_tsc *tsc)
	/* start ADC calibration */
	/* start ADC calibration */
	adc_gc = readl(tsc->adc_regs + REG_ADC_GC);
	adc_gc = readl(tsc->adc_regs + REG_ADC_GC);
	adc_gc |= ADC_CAL;
	adc_gc |= ADC_CAL;
	if (tsc->average_samples)
	if (tsc->average_enable)
		adc_gc |= ADC_AVGE;
		adc_gc |= ADC_AVGE;
	writel(adc_gc, tsc->adc_regs + REG_ADC_GC);
	writel(adc_gc, tsc->adc_regs + REG_ADC_GC);


@@ -362,6 +364,7 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
	int err;
	int err;
	int tsc_irq;
	int tsc_irq;
	int adc_irq;
	int adc_irq;
	u32 average_samples;


	tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
	tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
	if (!tsc)
	if (!tsc)
@@ -466,14 +469,27 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
	if (err)
	if (err)
		tsc->pre_charge_time = 0xfff;
		tsc->pre_charge_time = 0xfff;


	err = of_property_read_u32(np, "average-samples",
	err = of_property_read_u32(np, "touchscreen-average-samples",
				   &tsc->average_samples);
				   &average_samples);
	if (err)
	if (err)
		tsc->average_samples = 0;
		average_samples = 1;


	if (tsc->average_samples > 4) {
	switch (average_samples) {
		dev_err(&pdev->dev, "average-samples (%u) must be [0-4]\n",
	case 1:
			tsc->average_samples);
		tsc->average_enable = false;
		tsc->average_select = 0; /* value unused; initialize anyway */
		break;
	case 4:
	case 8:
	case 16:
	case 32:
		tsc->average_enable = true;
		tsc->average_select = ilog2(average_samples) - 2;
		break;
	default:
		dev_err(&pdev->dev,
			"touchscreen-average-samples (%u) must be 1, 4, 8, 16 or 32\n",
			average_samples);
		return -EINVAL;
		return -EINVAL;
	}
	}