Touchscreen performance related fixes
Subsystems (5)
v3 cover Touchscreen performance related fixes
This series of patches fix TSC defects related to lag in touchscreen performance and cursor jump at touch release. The lag was result of udelay in TSC interrupt handler. Cursor jump due to false pen-up event. The patches implement Advisory 1.0.31 in silicon errata of am335x-evm to avoid false pen-up events and remove udelay. The advisory says to use steps 1 to 4 for ADC and 5 to 16 for TSC (assuming 4 wire TSC and 4 channel ADC). Further the X co-ordinate must be the last one to be sampled just before charge step. The first two patches implement the required changes.
A DT parameter to configure the duration of tsc charge step. It represents number of ADC clock cycles to wait between applying the step configuration registers and going back to the IDLE state. The charge delay value can vary across boards. Configuring correct value of charge delay is important to avoid false pen-up events. Hence it is necessary to expose charge-delay value as DT parameter. The pen-up detection happens immediately after the charge step so this does in fact function as a hardware knob for adjusting the amount of settling time.
After applying these changes false pen-up events have not be observed and smooth circles can be drawn on touch screen. The performance is much better in recognizing quick movement across the screen. No lag or cursor jump is observed.
Change log:
v3:
- Replace delta filtering logic in TSC driver with median filtering as suggested by Richard.
- Addressed Lee Jones comments.
v2:
- Addressed comments by Hartmut Knaack
- patch 2 was split into two as per Lee Jones comment
Brad Griffis (2):
input: touchscreen: ti_am335x_tsc Interchange touchscreen and ADC
steps
input: touchscreen: ti_am335x_tsc: Remove udelay in interrupt handler
Vignesh R (4):
mfd: ti_am335x_tscadc: Remove unwanted reg_se_cache save
ARM: dts: AM335x: Make charge delay a DT parameter for tsc
input: touchscreen: ti_am335x_tsc: Use charge delay DT parameter
input: touchscreen: ti_am335x_tsc: Replace delta filtering with median
filtering
.../bindings/input/touchscreen/ti-tsc-adc.txt | 15 ++ arch/arm/boot/dts/am335x-evm.dts | 1 + drivers/iio/adc/ti_am335x_adc.c | 5 +- drivers/input/touchscreen/ti_am335x_tsc.c | 179 +++++++++++---------- drivers/mfd/ti_am335x_tscadc.c | 7 +- include/linux/mfd/ti_am335x_tscadc.h | 4 +- 6 files changed, 121 insertions(+), 90 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/6 input: touchscreen: ti_am335x_tsc Interchange touchscreen and ADC steps
From: Brad Griffis <[email protected]>
This patch makes the initial changes required to workaround TSC-false pen-up interrupts. It is required to implement these changes in order to remove udelay in the TSC interrupt handler and false pen-up events. The charge step is to be executed immediately after sampling X+. Hence TSC is made to use higher numbered steps (steps 5 to 16 for 5 co-ordinate readouts, 4 wire TSC configuration) and ADC to use lower ones. Further X co-ordinate readouts must be the last to be sampled, thus co-ordinates are sampled in the order Y-Z-X.
--- drivers/iio/adc/ti_am335x_adc.c | 5 ++-- drivers/input/touchscreen/ti_am335x_tsc.c | 42 ++++++++++++++++++------------- 2 files changed, 26 insertions(+), 21 deletions(-)
drivers/iio/adc/ti_am335x_adc.c +2 -3
@@ -86,19 +86,18 @@ static void tiadc_step_config(struct iio_dev *indio_dev) {struct tiadc_device *adc_dev =iio_priv (indio_dev);unsigned int stepconfig; -int i, steps; +int i, steps =0 ;/* * There are 16 configurable steps and 8 analog input * lines available which are shared between Touchscreen and ADC. * -* Steps backwards i.e. from 16 towards 0 are used by ADC +* Steps forwards i.e. from 0 towards 16 are used by ADC * depending on number of input lines needed. * Channel would represent which analog input * needs to be given to ADC to digitalize data. */ - steps =TOTAL_STEPS - adc_dev->channels;if (iio_buffer_enabled (indio_dev)) stepconfig =STEPCONFIG_AVG_16 |STEPCONFIG_FIFO1 |STEPCONFIG_MODE_SWCNT ;
drivers/input/touchscreen/ti_am335x_tsc.c +24 -18
96 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 2/6 input: touchscreen: ti_am335x_tsc: Remove udelay in interrupt handler
In reply to Vignesh RFrom: Brad Griffis <[email protected]>
TSC interrupt handler had udelay to avoid reporting of false pen-up interrupt to user space. This patch implements workaround suggesting in Advisory 1.0.31 of silicon errata for am335x, thus eliminating udelay and touchscreen lag. This also improves performance of touchscreen and eliminates sudden jump of cursor at touch release.
IDLECONFIG and CHARGECONFIG registers are to be configured with same values in order to eliminate false pen-up events. This workaround may result in false pen-down to be detected, hence considerable charge step delay needs to be added. The charge delay is set to 0xB000 (in terms of ADC clock cycles) by default.
TSC steps are disabled at the end of every sampling cycle and EOS bit is set. Once the EOS bit is set, the TSC steps need to be re-enabled to begin next sampling cycle.
--- drivers/input/touchscreen/ti_am335x_tsc.c | 56 ++++++++++++------------------- include/linux/mfd/ti_am335x_tscadc.h | 3 +- 2 files changed, 24 insertions(+), 35 deletions(-)
drivers/input/touchscreen/ti_am335x_tsc.c +22 -34
@@ -173,11 +173,9 @@ static void titsc_step_config(struct titsc *ts_dev)titsc_writel (ts_dev,REG_STEPDELAY (i),STEPCONFIG_OPENDLY ); } -/* Charge step configuration */ - config = ts_dev->bit_xp | ts_dev->bit_yn | -STEPCHARGE_RFP_XPUL |STEPCHARGE_RFM_XNUR | -STEPCHARGE_INM_AN1 |STEPCHARGE_INP (ts_dev->inp_yp); +/* Make CHARGECONFIG same as IDLECONFIG */ + config =titsc_readl (ts_dev,REG_IDLECONFIG );titsc_writel (ts_dev,REG_CHARGECONFIG , config);titsc_writel (ts_dev,REG_CHARGEDELAY ,CHARGEDLY_OPENDLY );
@@ -264,9 +262,26 @@ static irqreturn_t titsc_irq(int irq, void *dev)unsigned int status, irqclr =0 ;unsigned int x =0 , y =0 ;unsigned int z1, z2, z; -unsigned int fsm; - status =titsc_readl (ts_dev,REG_IRQSTATUS ); + status =titsc_readl (ts_dev,REG_RAWIRQSTATUS ); +if (status &IRQENB_HW_PEN ) { + ts_dev->pen_down = true; +titsc_writel (ts_dev,REG_IRQWAKEUP ,0x00 ); +titsc_writel (ts_dev,REG_IRQCLR ,IRQENB_HW_PEN ); + irqclr |=IRQENB_HW_PEN ; + } + +if (status &IRQENB_PENUP ) { + ts_dev->pen_down = false; +input_report_key (input_dev,BTN_TOUCH ,0 ); +input_report_abs (input_dev,ABS_PRESSURE ,0 ); +input_sync (input_dev); + irqclr |=IRQENB_PENUP ; + } + +if (status &IRQENB_EOS ) + irqclr |=IRQENB_EOS ; +/* * ADC and touchscreen share the IRQ line. * FIFO1 interrupts are used by ADC. Handle FIFO0 IRQs here only
@@ -297,34 +312,6 @@ static irqreturn_t titsc_irq(int irq, void *dev) } irqclr |=IRQENB_FIFO0THRES ; } - -/* -* Time for sequencer to settle, to read -* correct state of the sequencer. -*/ -udelay (SEQ_SETTLE ); - - status =titsc_readl (ts_dev,REG_RAWIRQSTATUS ); -if (status &IRQENB_PENUP ) { -/* Pen up event */ - fsm =titsc_readl (ts_dev,REG_ADCFSM ); -if (fsm ==ADCFSM_STEPID ) { - ts_dev->pen_down = false; -input_report_key (input_dev,BTN_TOUCH ,0 ); -input_report_abs (input_dev,ABS_PRESSURE ,0 ); -input_sync (input_dev); - }else { - ts_dev->pen_down = true; - } - irqclr |=IRQENB_PENUP ; - } - -if (status &IRQENB_HW_PEN ) { - -titsc_writel (ts_dev,REG_IRQWAKEUP ,0x00 ); -titsc_writel (ts_dev,REG_IRQCLR ,IRQENB_HW_PEN ); - } -if (irqclr) {titsc_writel (ts_dev,REG_IRQSTATUS , irqclr);am335x_tsc_se_set_cache (ts_dev->mfd_tscadc, ts_dev->step_mask);
@@ -417,6 +404,7 @@ static int titsc_probe(struct platform_device *pdev) }titsc_writel (ts_dev,REG_IRQENABLE ,IRQENB_FIFO0THRES ); +titsc_writel (ts_dev,REG_IRQENABLE ,IRQENB_EOS ); err =titsc_config_wires (ts_dev);if (err) {dev_err (&pdev->dev,"wrong i/p wire configuration\n" );
include/linux/mfd/ti_am335x_tscadc.h +2 -1
@@ -52,6 +52,7 @@/* IRQ enable */ #define IRQENB_HW_PEN BIT(0) +#define IRQENB_EOS BIT(1)#define IRQENB_FIFO0THRES BIT(2)#define IRQENB_FIFO0OVRRUN BIT(3)#define IRQENB_FIFO0UNDRFLW BIT(4)
@@ -107,7 +108,7 @@/* Charge delay */ #define CHARGEDLY_OPEN_MASK (0x3FFFF << 0)#define CHARGEDLY_OPEN (val) ((val) << 0) -#define CHARGEDLY_OPENDLY CHARGEDLY_OPEN(1) +#define CHARGEDLY_OPENDLY CHARGEDLY_OPEN(0xB000)/* Control register */ #define CNTRLREG_TSCSSENB BIT(0)
Signature · 1 line
1.9.1
PATCH v3 3/6 mfd: ti_am335x_tscadc: Remove unwanted reg_se_cache save
In reply to Vignesh RIn one shot mode, sequencer automatically disables all enabled steps at the end of each cycle. (both ADC steps and TSC steps) Hence these steps need not be saved in reg_se_cache for clearing these steps at a later stage.
Also, when ADC wakes up Sequencer should not be busy executing any of the config steps except for the charge step. Previously charge step was 1 ADC clock cycle and hence it was ignored.
--- drivers/mfd/ti_am335x_tscadc.c | 7 +++++-- include/linux/mfd/ti_am335x_tscadc.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/mfd/ti_am335x_tscadc.c +5 -2
@@ -86,8 +86,12 @@ static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)spin_lock_irq (&tsadc->reg_lock);finish_wait (&tsadc->reg_se_wait, &wait); +/* +* Sequencer should either be idle or +* busy applying the charge step. +*/ reg =tscadc_readl (tsadc,REG_ADCFSM ); -WARN_ON (reg &SEQ_STATUS ); +WARN_ON ((reg &SEQ_STATUS ) && !(reg &CHARGE_STEP )); tsadc->adc_waiting = false; } tsadc->adc_in_use = true;
@@ -96,7 +100,6 @@ static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)void am335x_tsc_se_set_once (struct ti_tscadc_dev *tsadc,u32 val) {spin_lock_irq (&tsadc->reg_lock); - tsadc->reg_se_cache |= val;am335x_tscadc_need_adc (tsadc);tscadc_writel (tsadc,REG_SE , val);
include/linux/mfd/ti_am335x_tscadc.h +1 -0
@@ -128,6 +128,7 @@/* Sequencer Status */ #define SEQ_STATUS BIT(5) +#define CHARGE_STEP 0x11#define ADC_CLK 3000000#define TOTAL_STEPS 16
Signature · 1 line
1.9.1
Re: [PATCH v3 3/6] mfd: ti_am335x_tscadc: Remove unwanted reg_se_cache save
Quoted 10 lines · Vignesh R
In one shot mode, sequencer automatically disables all enabled steps at the end of each cycle. (both ADC steps and TSC steps) Hence these steps need not be saved in
reg_se_cachefor clearing these steps at a later stage.
Also, when ADC wakes up Sequencer should not be busy executing any of the config steps except for the charge step. Previously charge step was 1 ADC clock cycle and hence it was ignored.Signed-off-by Vignesh R <[email protected]>---
You need to provide a changelog here when submitting new versions.
Quoted 23 lines
drivers/mfd/ti_am335x_tscadc.c | 7 +++++-- include/linux/mfd/ti_am335x_tscadc.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)drivers/mfd/ti_am335x_tscadc.c +5
-1@@ -86,8 +86,12 @@ static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)spin_lock_irq (&tsadc->reg_lock);finish_wait (&tsadc->reg_se_wait, &wait); +/* +* Sequencer should either be idle or +* busy applying the charge step. +*/ reg =tscadc_readl (tsadc,REG_ADCFSM ); -WARN_ON (reg &SEQ_STATUS ); +WARN_ON ((reg &SEQ_STATUS ) && !(reg &CHARGE_STEP )); tsadc->adc_waiting = false; } tsadc->adc_in_use = true;
drivers/mfd/ti_am335x_tscadc.c static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc) · line 99
Quoted 4 lines
drivers/mfd/ti_am335x_tscadc.c +0
-1@@ -96,7 +100,6 @@ static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)void am335x_tsc_se_set_once (struct ti_tscadc_dev *tsadc,u32 val) {spin_lock_irq (&tsadc->reg_lock); - tsadc->reg_se_cache |= val;
You didn't answer my question about this?
Quoted 15 lines
drivers/mfd/ti_am335x_tscadc.c +0
-0am335x_tscadc_need_adc (tsadc);tscadc_writel (tsadc,REG_SE , val);include/linux/mfd/ti_am335x_tscadc.h +1
-0@@ -128,6 +128,7 @@/* Sequencer Status */ #define SEQ_STATUS BIT(5) +#define CHARGE_STEP 0x11#define ADC_CLK 3000000#define TOTAL_STEPS 16
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
RE: [PATCH v3 3/6] mfd: ti_am335x_tscadc: Remove unwanted reg_se_cache save
Quoted 10 lines · Vignesh R
In one shot mode, sequencer automatically disables all enabled steps at the end of each cycle. (both ADC steps and TSC steps) Hence these steps need not be saved in
reg_se_cachefor clearing these steps at a later stage.
Also, when ADC wakes up Sequencer should not be busy executing any of the config steps except for the charge step. Previously charge step was 1 ADC clock cycle and hence it was ignored.Signed-off-by Vignesh R <[email protected]>---
You need to provide a changelog here when submitting new versions.
I have included changelog in the cover page. Will include them in individual patches next time.
Quoted 26 lines
drivers/mfd/ti_am335x_tscadc.c | 7 +++++-- include/linux/mfd/ti_am335x_tscadc.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/drivers/mfd/ti_am335x_tscadc.cindexd877e777cce6..110038859a8d100644drivers/mfd/ti_am335x_tscadc.c +5
-1@@ -86,8 +86,12 @@ static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)spin_lock_irq (&tsadc->reg_lock);finish_wait (&tsadc->reg_se_wait, &wait); +/* +* Sequencer should either be idle or +* busy applying the charge step. +*/ reg =tscadc_readl (tsadc,REG_ADCFSM ); -WARN_ON (reg &SEQ_STATUS ); +WARN_ON ((reg &SEQ_STATUS ) && !(reg &CHARGE_STEP )); tsadc->adc_waiting = false; } tsadc->adc_in_use = true;@@ -96,7 +100,6 @@ static void am335x_tscadc_need_adc(struct
ti_tscadc_dev*tsadc) voidam335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val){
drivers/mfd/ti_am335x_tscadc.c static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc) · line 99
Quoted 2 lines
drivers/mfd/ti_am335x_tscadc.c +0
-1spin_lock_irq (&tsadc->reg_lock); - tsadc->reg_se_cache |= val;
You didn't answer my question about this?
I did reply to the question in the previous thread.
Previously, TSC did not reliably re-enable its steps as the TSC irq handler received false pen up events. Hence, in order to use TSC after ADC operation, it was necessary to
save and re-enable TSC steps (basically, to keep TSC steps enabled always).
The change was more of a workaround to overcome limitation of TSC irq handler. With this series of patches, TSC irq handler is very reliable and the workaround is no longer required.
Quoted 9 lines
drivers/mfd/ti_am335x_tscadc.c +0
-0am335x_tscadc_need_adc (tsadc);tscadc_writel (tsadc,REG_SE , val);include/linux/mfd/ti_am335x_tscadc.h +0
-0
include/linux/mfd/ti_am335x_tscadc.h line 134
Quoted 7 lines
include/linux/mfd/ti_am335x_tscadc.h +1
-0@@ -128,6 +128,7 @@/* Sequencer Status */ #define SEQ_STATUS BIT(5) +#define CHARGE_STEP 0x11#define ADC_CLK 3000000#define TOTAL_STEPS 16
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v3 3/6] mfd: ti_am335x_tscadc: Remove unwanted reg_se_cache save
Quoted 11 lines · Vignesh
Quoted 10 lines · Vignesh R
In one shot mode, sequencer automatically disables all enabled steps at the end of each cycle. (both ADC steps and TSC steps) Hence these steps need not be saved in
reg_se_cachefor clearing these steps at a later stage.
Also, when ADC wakes up Sequencer should not be busy executing any of the config steps except for the charge step. Previously charge step was 1 ADC clock cycle and hence it was ignored.Signed-off-by Vignesh R <[email protected]>---
[...]
Quoted 10 lines
drivers/mfd/ti_am335x_tscadc.c static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc) · line 99
Quoted 1 line
drivers/mfd/ti_am335x_tscadc.c +0
-1- tsadc->reg_se_cache |= val;You didn't answer my question about this?
I did reply to the question in the previous thread.Previously, TSC did not reliably re-enable its steps as the TSC irq handler received false pen up events. Hence, in order to use TSC after ADC operation, it was necessary to
save and re-enable TSC steps (basically, to keep TSC steps enabled always).
The change was more of a workaround to overcome limitation of TSC irq handler. With this series of patches, TSC irq handler is very reliable and the workaround is no longer required.
Okay, thanks for the explanation.
By the way, your mailer doesn't appear to quote previous messages. Is there any way to fix that?
Quoted 17 lines
Quoted 16 lines
drivers/mfd/ti_am335x_tscadc.c +0
-0am335x_tscadc_need_adc (tsadc);tscadc_writel (tsadc,REG_SE , val);include/linux/mfd/ti_am335x_tscadc.h +1
-0@@ -128,6 +128,7 @@/* Sequencer Status */ #define SEQ_STATUS BIT(5) +#define CHARGE_STEP 0x11#define ADC_CLK 3000000#define TOTAL_STEPS 16
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v3 4/6 ARM: dts: AM335x: Make charge delay a DT parameter for tsc
In reply to Vignesh RThe charge delay value is by default 0xB000. But it can be set to lower values on some boards as long as false pen-ups are avoided. Lowering the value increases the sampling rate (though current sampling rate is sufficient for tsc operation). Hence charge delay has been made a DT parameter.
--- .../devicetree/bindings/input/touchscreen/ti-tsc-adc.txt | 15 +++++++++++++++ arch/arm/boot/dts/am335x-evm.dts | 1 + 2 files changed, 16 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt +15 -0
@@ -28,6 +28,20 @@ Required properties: ti,adc-channels: List of analog inputs available for ADC. AIN0 = 0, AIN1 = 1 and so on till AIN7 = 7. +Optional properties: +- child "tsc" + ti,charge-delay: Length of touch screen charge delay step in terms of + ADC clock cycles. Charge delay value should be large + in order to avoid false pen-up events. This value + affects the overall sampling speed, hence need to be + kept as low as possible, while avoiding false pen-up + event. Start from a lower value, say 0x400, and + increase value until false pen-up events are avoided. + The pen-up detection happens immediately after the + charge step, so this does in fact function as a + hardware knob for adjusting the amount of "settling + time". + Example: tscadc: tscadc at 44e0d000 { compatible = "ti,am3359-tscadc";
@@ -36,6 +50,7 @@ Example: ti,x-plate-resistance = <200>; ti,coordiante-readouts = <5>; ti,wire-config = <0x00 0x11 0x22 0x33>; + ti,charge-delay = <0xB000>; }; adc {
arch/arm/boot/dts/am335x-evm.dts +1 -0
@@ -641,6 +641,7 @@ ti,x-plate-resistance = <200>; ti,coordinate-readouts = <5>; ti,wire-config = <0x00 0x11 0x22 0x33>; + ti,charge-delay = <0xB000>; }; adc {
Signature · 1 line
1.9.1
PATCH v3 5/6 input: touchscreen: ti_am335x_tsc: Use charge delay DT parameter
In reply to Vignesh RThis patch reads charge delay from tsc DT node and writes to REG_CHARGEDELAY register. If the charge delay is not specified in DT then default value of 0xB000(CHARGEDLY_OPENDLY) is used.
--- drivers/input/touchscreen/ti_am335x_tsc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/input/touchscreen/ti_am335x_tsc.c +7 -1
@@ -52,6 +52,7 @@ struct titsc {u32 bit_xp, bit_xn, bit_yp, bit_yn;u32 inp_xp, inp_xn, inp_yp, inp_yn;u32 step_mask; +u32 charge_delay; };static unsigned int titsc_readl (struct titsc *ts,unsigned int reg)
@@ -177,7 +178,7 @@ static void titsc_step_config(struct titsc *ts_dev) config =titsc_readl (ts_dev,REG_IDLECONFIG );titsc_writel (ts_dev,REG_CHARGECONFIG , config); -titsc_writel (ts_dev,REG_CHARGEDELAY ,CHARGEDLY_OPENDLY ); +titsc_writel (ts_dev,REG_CHARGEDELAY , ts_dev->charge_delay);/* coordinate_readouts + 1 ... coordinate_readouts + 2 is for Z */ config = STEPCONFIG_MODE_HWSYNC |
@@ -361,6 +362,11 @@ static int titsc_parse_dt(struct platform_device *pdev,if (err <0 )return err; + err =of_property_read_u32 (node,"ti,charge-delay" , + &ts_dev->charge_delay); +if (err <0 ) + ts_dev->charge_delay =CHARGEDLY_OPENDLY ; +return of_property_read_u32_array (node,"ti,wire-config" , ts_dev->config_inp,ARRAY_SIZE (ts_dev->config_inp)); }
Signature · 1 line
1.9.1
PATCH v3 6/6 input: touchscreen: ti_am335x_tsc: Replace delta filtering with median filtering
In reply to Vignesh RPreviously, delta filtering was applied TSC co-ordinate readouts before reporting a single value to user space. This patch replaces delta filtering with median filtering. Median filtering sorts co-ordinate readouts, drops min and max values, and reports the average of remaining values. This method is more sensible than delta filering. Median filtering is applied only if number of readouts is greater than 3 else just average of co-ordinate readouts is reported.
--- drivers/input/touchscreen/ti_am335x_tsc.c | 91 +++++++++++++++++-------------- 1 file changed, 51 insertions(+), 40 deletions(-)
drivers/input/touchscreen/ti_am335x_tsc.c +51 -40
@@ -26,6 +26,7 @@#include <linux/delay.h> #include <linux/of.h> #include <linux/of_device.h> +#include <linux/sort.h> #include <linux/mfd/ti_am335x_tscadc.h>
@@ -204,56 +205,61 @@ static void titsc_step_config(struct titsc *ts_dev)am335x_tsc_se_set_cache (ts_dev->mfd_tscadc, ts_dev->step_mask); } +static int titsc_cmp_coord (const void *a,const void *b) +{ +return *(int *)a - *(int *)b; +} +static void titsc_read_coordinates (struct titsc *ts_dev,u32 *x,u32 *y,u32 *z1,u32 *z2) { -unsigned int fifocount =titsc_readl (ts_dev,REG_FIFO0CNT ); -unsigned int prev_val_x = ~0 , prev_val_y = ~0 ; -unsigned int prev_diff_x = ~0 , prev_diff_y = ~0 ; -unsigned int read, diff; -unsigned int i, channel; +unsigned int yvals[7 ], xvals[7 ]; +unsigned int i, xsum =0 , ysum =0 ;unsigned int creads = ts_dev->coordinate_readouts; -unsigned int first_step =TOTAL_STEPS - (creads *2 +2 ); - *z1 = *z2 =0 ; -if (fifocount % (creads *2 +2 )) - fifocount -= fifocount % (creads *2 +2 ); -/* -* Delta filter is used to remove large variations in sampled -* values from ADC. The filter tries to predict where the next -* coordinate could be. This is done by taking a previous -* coordinate and subtracting it form current one. Further the -* algorithm compares the difference with that of a present value, -* if true the value is reported to the sub system. -*/ -for (i =0 ; i < fifocount; i++) { - read =titsc_readl (ts_dev,REG_FIFO0 ); - - channel = (read &0xf0000 ) >>16 ; - read &=0xfff ; -if (channel > first_step + creads +2 ) { - diff =abs (read - prev_val_x); -if (diff < prev_diff_x) { - prev_diff_x = diff; - *x = read; - } - prev_val_x = read; +for (i =0 ; i < creads; i++) { + yvals[i] =titsc_readl (ts_dev,REG_FIFO0 ); + yvals[i] &=0xfff ; + } - }else if (channel == first_step + creads +1 ) { - *z1 = read; + *z1 =titsc_readl (ts_dev,REG_FIFO0 ); + *z1 &=0xfff ; + *z2 =titsc_readl (ts_dev,REG_FIFO0 ); + *z2 &=0xfff ; - }else if (channel == first_step + creads +2 ) { - *z2 = read; +for (i =0 ; i < creads; i++) { + xvals[i] =titsc_readl (ts_dev,REG_FIFO0 ); + xvals[i] &=0xfff ; + } - }else if (channel > first_step) { - diff =abs (read - prev_val_y); -if (diff < prev_diff_y) { - prev_diff_y = diff; - *y = read; - } - prev_val_y = read; +/* +* If co-ordinates readouts is less than 4 then +* report the average. In case of 4 or more +* readouts, sort the co-ordinate samples, drop +* min and max values and report the average of +* remaining values. +*/ +if (creads <=3 ) { +for (i =0 ; i < creads; i++) { + ysum += yvals[i]; + xsum += xvals[i]; } + ysum /= creads; + xsum /= creads; + }else { +sort (yvals, creads,sizeof (unsigned int ), + titsc_cmp_coord,NULL ); +sort (xvals, creads,sizeof (unsigned int ), + titsc_cmp_coord,NULL ); +for (i =1 ; i < creads -1 ; i++) { + ysum += yvals[i]; + xsum += xvals[i]; + } + ysum /= creads -2 ; + xsum /= creads -2 ; } + *y = ysum; + *x = xsum; }static irqreturn_t titsc_irq (int irq,void *dev)
@@ -362,6 +368,11 @@ static int titsc_parse_dt(struct platform_device *pdev,if (err <0 )return err; +if (ts_dev->coordinate_readouts <=0 ) { +dev_warn (&pdev->dev,"invalid co-ordinate readouts, resetting it to 5\n" ); + ts_dev->coordinate_readouts =5 ; + } + err =of_property_read_u32 (node,"ti,charge-delay" , &ts_dev->charge_delay);if (err <0 )
Signature · 1 line
1.9.1