aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Shapiro <guy.shapiro@mobi-wize.com>2016-12-16 00:23:02 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2016-12-16 00:34:35 -0500
commitf43d3ec3a889c7f6a196f3b6d6b13345ee46af8a (patch)
tree37114b0cc7036faad3f3c81253b63a21e8dfb48d
parent34888602eb99df174e76eafeb613ad857f534ebb (diff)
Input: imx6ul_tsc - generalize the averaging property
Make the avarage-samples property a general touchscreen property rather than imx6ul device specific. Signed-off-by: Guy Shapiro <guy.shapiro@mobi-wize.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r--Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt11
-rw-r--r--Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt3
-rw-r--r--drivers/input/touchscreen/imx6ul_tsc.c38
3 files changed, 33 insertions, 19 deletions
diff --git a/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
index a66069f6db66..d4927c202aef 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/imx6ul_tsc.txt
@@ -17,13 +17,8 @@ Optional properties:
17 This value depends on the touch screen. 17 This value depends on the touch screen.
18- pre-charge-time: the touch screen need some time to precharge. 18- pre-charge-time: the touch screen need some time to precharge.
19 This value depends on the touch screen. 19 This value depends on the touch screen.
20- average-samples: Number of data samples which are averaged for each read. 20- touchscreen-average-samples: Number of data samples which are averaged for
21 Valid values 0-4 21 each read. Valid values are 1, 4, 8, 16 and 32.
22 0 = 1 sample
23 1 = 4 samples
24 2 = 8 samples
25 3 = 16 samples
26 4 = 32 samples
27 22
28Example: 23Example:
29 tsc: tsc@02040000 { 24 tsc: tsc@02040000 {
@@ -39,6 +34,6 @@ Example:
39 xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>; 34 xnur-gpio = <&gpio1 3 GPIO_ACTIVE_LOW>;
40 measure-delay-time = <0xfff>; 35 measure-delay-time = <0xfff>;
41 pre-charge-time = <0xffff>; 36 pre-charge-time = <0xffff>;
42 average-samples = <4>; 37 touchscreen-average-samples = <32>;
43 status = "okay"; 38 status = "okay";
44 }; 39 };
diff --git a/Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt b/Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt
index bccaa4e73045..537643e86f61 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt
@@ -14,6 +14,9 @@ Optional properties for Touchscreens:
14 - touchscreen-fuzz-pressure : pressure noise value of the absolute input 14 - touchscreen-fuzz-pressure : pressure noise value of the absolute input
15 device (arbitrary range dependent on the 15 device (arbitrary range dependent on the
16 controller) 16 controller)
17 - touchscreen-average-samples : Number of data samples which are averaged
18 for each read (valid values dependent on the
19 controller)
17 - touchscreen-inverted-x : X axis is inverted (boolean) 20 - touchscreen-inverted-x : X axis is inverted (boolean)
18 - touchscreen-inverted-y : Y axis is inverted (boolean) 21 - touchscreen-inverted-y : Y axis is inverted (boolean)
19 - touchscreen-swapped-x-y : X and Y axis are swapped (boolean) 22 - touchscreen-swapped-x-y : X and Y axis are swapped (boolean)
diff --git a/drivers/input/touchscreen/imx6ul_tsc.c b/drivers/input/touchscreen/imx6ul_tsc.c
index d2a39120f37f..7098e0a47019 100644
--- a/drivers/input/touchscreen/imx6ul_tsc.c
+++ b/drivers/input/touchscreen/imx6ul_tsc.c
@@ -21,6 +21,7 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/log2.h>
24 25
25/* ADC configuration registers field define */ 26/* ADC configuration registers field define */
26#define ADC_AIEN (0x1 << 7) 27#define ADC_AIEN (0x1 << 7)
@@ -93,7 +94,8 @@ struct imx6ul_tsc {
93 94
94 u32 measure_delay_time; 95 u32 measure_delay_time;
95 u32 pre_charge_time; 96 u32 pre_charge_time;
96 u32 average_samples; 97 bool average_enable;
98 u32 average_select;
97 99
98 struct completion completion; 100 struct completion completion;
99}; 101};
@@ -117,9 +119,9 @@ static int imx6ul_adc_init(struct imx6ul_tsc *tsc)
117 adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK; 119 adc_cfg |= ADC_12BIT_MODE | ADC_IPG_CLK;
118 adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK); 120 adc_cfg &= ~(ADC_CLK_DIV_MASK | ADC_SAMPLE_MODE_MASK);
119 adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE; 121 adc_cfg |= ADC_CLK_DIV_8 | ADC_SHORT_SAMPLE_MODE;
120 if (tsc->average_samples) { 122 if (tsc->average_enable) {
121 adc_cfg &= ~ADC_AVGS_MASK; 123 adc_cfg &= ~ADC_AVGS_MASK;
122 adc_cfg |= (tsc->average_samples - 1) << ADC_AVGS_SHIFT; 124 adc_cfg |= (tsc->average_select) << ADC_AVGS_SHIFT;
123 } 125 }
124 adc_cfg &= ~ADC_HARDWARE_TRIGGER; 126 adc_cfg &= ~ADC_HARDWARE_TRIGGER;
125 writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG); 127 writel(adc_cfg, tsc->adc_regs + REG_ADC_CFG);
@@ -132,7 +134,7 @@ static int imx6ul_adc_init(struct imx6ul_tsc *tsc)
132 /* start ADC calibration */ 134 /* start ADC calibration */
133 adc_gc = readl(tsc->adc_regs + REG_ADC_GC); 135 adc_gc = readl(tsc->adc_regs + REG_ADC_GC);
134 adc_gc |= ADC_CAL; 136 adc_gc |= ADC_CAL;
135 if (tsc->average_samples) 137 if (tsc->average_enable)
136 adc_gc |= ADC_AVGE; 138 adc_gc |= ADC_AVGE;
137 writel(adc_gc, tsc->adc_regs + REG_ADC_GC); 139 writel(adc_gc, tsc->adc_regs + REG_ADC_GC);
138 140
@@ -362,6 +364,7 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
362 int err; 364 int err;
363 int tsc_irq; 365 int tsc_irq;
364 int adc_irq; 366 int adc_irq;
367 u32 average_samples;
365 368
366 tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL); 369 tsc = devm_kzalloc(&pdev->dev, sizeof(*tsc), GFP_KERNEL);
367 if (!tsc) 370 if (!tsc)
@@ -466,14 +469,27 @@ static int imx6ul_tsc_probe(struct platform_device *pdev)
466 if (err) 469 if (err)
467 tsc->pre_charge_time = 0xfff; 470 tsc->pre_charge_time = 0xfff;
468 471
469 err = of_property_read_u32(np, "average-samples", 472 err = of_property_read_u32(np, "touchscreen-average-samples",
470 &tsc->average_samples); 473 &average_samples);
471 if (err) 474 if (err)
472 tsc->average_samples = 0; 475 average_samples = 1;
473 476
474 if (tsc->average_samples > 4) { 477 switch (average_samples) {
475 dev_err(&pdev->dev, "average-samples (%u) must be [0-4]\n", 478 case 1:
476 tsc->average_samples); 479 tsc->average_enable = false;
480 tsc->average_select = 0; /* value unused; initialize anyway */
481 break;
482 case 4:
483 case 8:
484 case 16:
485 case 32:
486 tsc->average_enable = true;
487 tsc->average_select = ilog2(average_samples) - 2;
488 break;
489 default:
490 dev_err(&pdev->dev,
491 "touchscreen-average-samples (%u) must be 1, 4, 8, 16 or 32\n",
492 average_samples);
477 return -EINVAL; 493 return -EINVAL;
478 } 494 }
479 495