aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/ti_am335x_tscadc.c
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2013-12-19 10:28:31 -0500
committerLee Jones <lee.jones@linaro.org>2014-01-07 03:45:00 -0500
commit7ca6740cd1cd410828a01151a044b51910d06eff (patch)
treee9527767fefbe621dfdeca70e0a310c818f9175d /drivers/mfd/ti_am335x_tscadc.c
parent3954b7bfc665fed878cabe57342bae34d2391478 (diff)
mfd: input: iio: ti_amm335x: Rework TSC/ADC synchronization
The ADC driver always programs all possible ADC values and discards them except for the value IIO asked for. On the am335x-evm the driver programs four values and it takes 500us to gather them. Reducing the number of conversations down to the (required) one also reduces the busy loop down to 125us. This leads to another error, namely the FIFOCOUNT register is sometimes (like one out of 10 attempts) not updated in time leading to EBUSY. The next read has the FIFOCOUNT register updated. Checking for the ADCSTAT register for being idle isn't a good choice either. The problem is that if TSC is used at the same time, the HW completes the conversation for ADC *and* before the driver noticed it, the HW begins to perform a TSC conversation and so the driver never seen the HW idle. The next time we would have two values in the FIFO but since the driver reads everything we always see the current one. So instead of polling for the IDLE bit in ADCStatus register, we should check the FIFOCOUNT register. It should be one instead of zero because we request one value. This change in turn leads to another error. Sometimes if TSC & ADC are used together the TSC starts generating interrupts even if nobody actually touched the touchscreen. The interrupts seem valid because TSC's FIFO is filled with values for each channel of the TSC. This condition stops after a few ADC reads but will occur again. Not good. On top of this (even without the changes I just mentioned) there is a ADC & TSC lockup condition which was reported to me by Jeff Lance including the following test case: A busy loop of "cat /sys/bus/iio/devices/iio\:device0/in_voltage4_raw" and a mug on touch screen. With this setup, the hardware will lockup after something between 20 minutes and it could take up to a couple of hours. During that lockup, the ADCSTAT register says 0x30 (or 0x70) which means STEP_ID = IDLE and FSM_BUSY = yes. That means the hardware says that it is idle and busy at the same time which is an invalid condition. For all this reasons I decided to rework this TSC/ADC part and add a handshake / synchronization here: First the ADC signals that it needs the HW and writes a 0 mask into the SE register. The HW (if active) will complete the current conversation and become idle. The TSC driver will gather the values from the FIFO (woken up by an interrupt) and won't "enable" another conversation. Instead it will wake up the ADC driver which is already waiting. The ADC driver will start "its" conversation and once it is done, it will enable the TSC steps so the TSC will work again. After this rework I haven't observed the lockup so far. Plus the busy loop has been reduced from 500us to 125us. The continues-read mode remains unchanged. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/ti_am335x_tscadc.c')
-rw-r--r--drivers/mfd/ti_am335x_tscadc.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index 157f5699a33c..d4e860413bb5 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -24,6 +24,7 @@
24#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
25#include <linux/of.h> 25#include <linux/of.h>
26#include <linux/of_device.h> 26#include <linux/of_device.h>
27#include <linux/sched.h>
27 28
28#include <linux/mfd/ti_am335x_tscadc.h> 29#include <linux/mfd/ti_am335x_tscadc.h>
29 30
@@ -48,31 +49,71 @@ static const struct regmap_config tscadc_regmap_config = {
48 .val_bits = 32, 49 .val_bits = 32,
49}; 50};
50 51
51static void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc)
52{
53 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
54}
55
56void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val) 52void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val)
57{ 53{
58 unsigned long flags; 54 unsigned long flags;
59 55
60 spin_lock_irqsave(&tsadc->reg_lock, flags); 56 spin_lock_irqsave(&tsadc->reg_lock, flags);
61 tsadc->reg_se_cache |= val; 57 tsadc->reg_se_cache = val;
62 am335x_tsc_se_update(tsadc); 58 if (tsadc->adc_waiting)
59 wake_up(&tsadc->reg_se_wait);
60 else if (!tsadc->adc_in_use)
61 tscadc_writel(tsadc, REG_SE, val);
62
63 spin_unlock_irqrestore(&tsadc->reg_lock, flags); 63 spin_unlock_irqrestore(&tsadc->reg_lock, flags);
64} 64}
65EXPORT_SYMBOL_GPL(am335x_tsc_se_set_cache); 65EXPORT_SYMBOL_GPL(am335x_tsc_se_set_cache);
66 66
67static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc)
68{
69 DEFINE_WAIT(wait);
70 u32 reg;
71
72 /*
73 * disable TSC steps so it does not run while the ADC is using it. If
74 * write 0 while it is running (it just started or was already running)
75 * then it completes all steps that were enabled and stops then.
76 */
77 tscadc_writel(tsadc, REG_SE, 0);
78 reg = tscadc_readl(tsadc, REG_ADCFSM);
79 if (reg & SEQ_STATUS) {
80 tsadc->adc_waiting = true;
81 prepare_to_wait(&tsadc->reg_se_wait, &wait,
82 TASK_UNINTERRUPTIBLE);
83 spin_unlock_irq(&tsadc->reg_lock);
84
85 schedule();
86
87 spin_lock_irq(&tsadc->reg_lock);
88 finish_wait(&tsadc->reg_se_wait, &wait);
89
90 reg = tscadc_readl(tsadc, REG_ADCFSM);
91 WARN_ON(reg & SEQ_STATUS);
92 tsadc->adc_waiting = false;
93 }
94 tsadc->adc_in_use = true;
95}
96
67void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val) 97void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val)
68{ 98{
99 spin_lock_irq(&tsadc->reg_lock);
100 am335x_tscadc_need_adc(tsadc);
101
102 tscadc_writel(tsadc, REG_SE, val);
103 spin_unlock_irq(&tsadc->reg_lock);
104}
105EXPORT_SYMBOL_GPL(am335x_tsc_se_set_once);
106
107void am335x_tsc_se_adc_done(struct ti_tscadc_dev *tsadc)
108{
69 unsigned long flags; 109 unsigned long flags;
70 110
71 spin_lock_irqsave(&tsadc->reg_lock, flags); 111 spin_lock_irqsave(&tsadc->reg_lock, flags);
72 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache | val); 112 tsadc->adc_in_use = false;
113 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
73 spin_unlock_irqrestore(&tsadc->reg_lock, flags); 114 spin_unlock_irqrestore(&tsadc->reg_lock, flags);
74} 115}
75EXPORT_SYMBOL_GPL(am335x_tsc_se_set_once); 116EXPORT_SYMBOL_GPL(am335x_tsc_se_adc_done);
76 117
77void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val) 118void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
78{ 119{
@@ -80,7 +121,7 @@ void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
80 121
81 spin_lock_irqsave(&tsadc->reg_lock, flags); 122 spin_lock_irqsave(&tsadc->reg_lock, flags);
82 tsadc->reg_se_cache &= ~val; 123 tsadc->reg_se_cache &= ~val;
83 am335x_tsc_se_update(tsadc); 124 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
84 spin_unlock_irqrestore(&tsadc->reg_lock, flags); 125 spin_unlock_irqrestore(&tsadc->reg_lock, flags);
85} 126}
86EXPORT_SYMBOL_GPL(am335x_tsc_se_clr); 127EXPORT_SYMBOL_GPL(am335x_tsc_se_clr);
@@ -188,6 +229,8 @@ static int ti_tscadc_probe(struct platform_device *pdev)
188 } 229 }
189 230
190 spin_lock_init(&tscadc->reg_lock); 231 spin_lock_init(&tscadc->reg_lock);
232 init_waitqueue_head(&tscadc->reg_se_wait);
233
191 pm_runtime_enable(&pdev->dev); 234 pm_runtime_enable(&pdev->dev);
192 pm_runtime_get_sync(&pdev->dev); 235 pm_runtime_get_sync(&pdev->dev);
193 236