mfd: ti_am335x_tscadc: Don't read back REG_SE
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 19 Dec 2013 15:28:29 +0000 (16:28 +0100)
committerLee Jones <lee.jones@linaro.org>
Tue, 7 Jan 2014 08:41:15 +0000 (08:41 +0000)
The purpose of reg_se_cache has been defeated. It should avoid the
read-back of the register to avoid the latency and the fact that the
bits are reset to 0 after the individual conversation took place.

The reason why this is required like this to work, is that read-back of
the register removes the bits of the ADC so they do not start another
conversation after the register is re-written from the TSC side for the
update.
To avoid the not required read-back I introduce a "set once" variant which
does not update the cache mask. After the conversation completes, the
bit is removed from the SE register anyway and we don't plan a new
conversation "any time soon". The current set function is renamed to
set_cache to distinguish the two operations.
This is a small preparation for a larger sync-rework.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/iio/adc/ti_am335x_adc.c
drivers/input/touchscreen/ti_am335x_tsc.c
drivers/mfd/ti_am335x_tscadc.c
include/linux/mfd/ti_am335x_tscadc.h

index ce8d03ac900fdd444f60e49e5f536aabce0074b4..95eef8e8997982431b845d3109f284de4dff237f 100644 (file)
@@ -181,7 +181,7 @@ static int tiadc_buffer_postenable(struct iio_dev *indio_dev)
                enb |= (get_adc_step_bit(adc_dev, bit) << 1);
        adc_dev->buffer_en_ch_steps = enb;
 
-       am335x_tsc_se_set(adc_dev->mfd_tscadc, enb);
+       am335x_tsc_se_set_cache(adc_dev->mfd_tscadc, enb);
 
        tiadc_writel(adc_dev,  REG_IRQSTATUS, IRQENB_FIFO1THRES
                                | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW);
@@ -332,7 +332,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
                return -EBUSY;
 
        step_en = get_adc_step_mask(adc_dev);
-       am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
+       am335x_tsc_se_set_once(adc_dev->mfd_tscadc, step_en);
 
        /* Wait for ADC sequencer to complete sampling */
        while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) {
index 68beadaabcebb134adc4ad1e9a9a8fdc6ec590d6..2ca5a7bee04e45c3b5661df8a54ed97fdefbd1fa 100644 (file)
@@ -198,7 +198,7 @@ static void titsc_step_config(struct titsc *ts_dev)
        /* The steps1 … end and bit 0 for TS_Charge */
        stepenable = (1 << (end_step + 2)) - 1;
        ts_dev->step_mask = stepenable;
-       am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask);
+       am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask);
 }
 
 static void titsc_read_coordinates(struct titsc *ts_dev,
@@ -322,7 +322,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 
        if (irqclr) {
                titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
-               am335x_tsc_se_set(ts_dev->mfd_tscadc, ts_dev->step_mask);
+               am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask);
                return IRQ_HANDLED;
        }
        return IRQ_NONE;
index 67d0eb469a45e25043fcb44eb3e6e2f701511481..cb0c211fc7d8adb0063230179886e51f8e4663aa 100644 (file)
@@ -53,24 +53,32 @@ static void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc)
        tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
 }
 
-void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val)
+void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val)
 {
        unsigned long flags;
 
        spin_lock_irqsave(&tsadc->reg_lock, flags);
-       tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE);
        tsadc->reg_se_cache |= val;
        am335x_tsc_se_update(tsadc);
        spin_unlock_irqrestore(&tsadc->reg_lock, flags);
 }
-EXPORT_SYMBOL_GPL(am335x_tsc_se_set);
+EXPORT_SYMBOL_GPL(am335x_tsc_se_set_cache);
+
+void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&tsadc->reg_lock, flags);
+       tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache | val);
+       spin_unlock_irqrestore(&tsadc->reg_lock, flags);
+}
+EXPORT_SYMBOL_GPL(am335x_tsc_se_set_once);
 
 void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
 {
        unsigned long flags;
 
        spin_lock_irqsave(&tsadc->reg_lock, flags);
-       tsadc->reg_se_cache = tscadc_readl(tsadc, REG_SE);
        tsadc->reg_se_cache &= ~val;
        am335x_tsc_se_update(tsadc);
        spin_unlock_irqrestore(&tsadc->reg_lock, flags);
index 1fe72199e670de07f0b9c51a305dc88a8ffdd560..2fa9c0613da41a568312f0ad3d61b4e26a4a20c2 100644 (file)
@@ -176,7 +176,8 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
        return *tscadc_dev;
 }
 
-void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
+void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val);
+void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val);
 void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
 
 #endif