]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
input: ti_am33x_tsc: Step enable bits made configurable
authorPatil, Rachna <rachna@ti.com>
Thu, 24 Jan 2013 03:45:05 +0000 (03:45 +0000)
committerSebastian Andrzej Siewior <bigeasy@linutronix.de>
Wed, 12 Jun 2013 16:03:55 +0000 (18:03 +0200)
Current code has hard coded value written to
step enable bits. Now the bits are updated based
on how many steps are needed to be configured got
from platform data.

The user needs to take care not to exceed
the count more than 16. While using ADC and TSC
one should take care to set this parameter correctly.

Sebastian added the common lock and moved the code, that manipulates the
steps, from into the mfd module.

Signed-off-by: Patil, Rachna <rachna@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
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 9db352e413e49a1c2e90f59c9cd1e6a2f52d6620..543b9c42ac5f3cd6895d2a9f2e352c9a83c7d75b 100644 (file)
@@ -42,10 +42,20 @@ static void tiadc_writel(struct tiadc_device *adc, unsigned int reg,
        writel(val, adc->mfd_tscadc->tscadc_base + reg);
 }
 
+static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
+{
+       u32 step_en;
+
+       step_en = ((1 << adc_dev->channels) - 1);
+       step_en <<= TOTAL_STEPS - adc_dev->channels + 1;
+       return step_en;
+}
+
 static void tiadc_step_config(struct tiadc_device *adc_dev)
 {
        unsigned int stepconfig;
        int i, channels = 0, steps;
+       u32 step_en;
 
        /*
         * There are 16 configurable steps and 8 analog input
@@ -69,7 +79,8 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
                                STEPCONFIG_OPENDLY);
                channels++;
        }
-       tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB);
+       step_en = get_adc_step_mask(adc_dev);
+       am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
 }
 
 static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
@@ -127,7 +138,7 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
                if (i == chan->channel)
                        *val = readx1 & 0xfff;
        }
-       tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB);
+       am335x_tsc_se_update(adc_dev->mfd_tscadc);
 
        return IIO_VAL_INT;
 }
@@ -191,10 +202,15 @@ err_ret:
 static int tiadc_remove(struct platform_device *pdev)
 {
        struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+       struct tiadc_device *adc_dev = iio_priv(indio_dev);
+       u32 step_en;
 
        iio_device_unregister(indio_dev);
        tiadc_channels_remove(indio_dev);
 
+       step_en = get_adc_step_mask(adc_dev);
+       am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);
+
        iio_device_free(indio_dev);
 
        return 0;
index 16077d3d80ba6236bd6a508d1fec4137cacb9859..23d6a4dacc88d47cacf4874cb8133abb248cb3c5 100644 (file)
@@ -57,6 +57,7 @@ static void titsc_writel(struct titsc *tsc, unsigned int reg,
 static void titsc_step_config(struct titsc *ts_dev)
 {
        unsigned int    config;
+       unsigned int    stepenable = 0;
        int i, total_steps;
 
        /* Configure the Step registers */
@@ -128,7 +129,9 @@ static void titsc_step_config(struct titsc *ts_dev)
        titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2),
                        STEPCONFIG_OPENDLY);
 
-       titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC);
+       /* The steps1 … end and bit 0 for TS_Charge */
+       stepenable = (1 << (total_steps + 2)) - 1;
+       am335x_tsc_se_set(ts_dev->mfd_tscadc, stepenable);
 }
 
 static void titsc_read_coordinates(struct titsc *ts_dev,
@@ -250,7 +253,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 
        titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
 
-       titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC);
+       am335x_tsc_se_update(ts_dev->mfd_tscadc);
        return IRQ_HANDLED;
 }
 
@@ -334,6 +337,11 @@ static int titsc_remove(struct platform_device *pdev)
 
        free_irq(ts_dev->irq, ts_dev);
 
+       /* total steps followed by the enable mask */
+       steps = 2 * ts_dev->steps_to_configure + 2;
+       steps = (1 << steps) - 1;
+       am335x_tsc_se_clr(ts_dev->mfd_tscadc, steps);
+
        input_unregister_device(ts_dev->input);
 
        platform_set_drvdata(pdev, NULL);
index 772ea2adb539e62f40a47a60f8ae1af0e5b0bcc6..90ccfc07e16b009b27bcef40f9d133a859435d1a 100644 (file)
@@ -48,6 +48,32 @@ static const struct regmap_config tscadc_regmap_config = {
        .val_bits = 32,
 };
 
+void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc)
+{
+       tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
+}
+EXPORT_SYMBOL_GPL(am335x_tsc_se_update);
+
+void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val)
+{
+       spin_lock(&tsadc->reg_lock);
+       tsadc->reg_se_cache |= val;
+       spin_unlock(&tsadc->reg_lock);
+
+       am335x_tsc_se_update(tsadc);
+}
+EXPORT_SYMBOL_GPL(am335x_tsc_se_set);
+
+void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
+{
+       spin_lock(&tsadc->reg_lock);
+       tsadc->reg_se_cache &= ~val;
+       spin_unlock(&tsadc->reg_lock);
+
+       am335x_tsc_se_update(tsadc);
+}
+EXPORT_SYMBOL_GPL(am335x_tsc_se_clr);
+
 static void tscadc_idle_config(struct ti_tscadc_dev *config)
 {
        unsigned int idleconfig;
@@ -129,6 +155,7 @@ static      int ti_tscadc_probe(struct platform_device *pdev)
                goto ret;
        }
 
+       spin_lock_init(&tscadc->reg_lock);
        pm_runtime_enable(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
 
@@ -239,7 +266,7 @@ static int tscadc_resume(struct device *dev)
                        CNTRLREG_STEPID | CNTRLREG_4WIRE;
        tscadc_writel(tscadc_dev, REG_CTRL, ctrl);
        tscadc_idle_config(tscadc_dev);
-       tscadc_writel(tscadc_dev, REG_SE, STPENB_STEPENB);
+       am335x_tsc_se_update(tscadc_dev);
        restore = tscadc_readl(tscadc_dev, REG_CTRL);
        tscadc_writel(tscadc_dev, REG_CTRL,
                        (restore | CNTRLREG_TSCSSENB));
index 8114e4e8b91b2de512bb31dba7ef2724927f53e3..4258627d076a1b6e432df7c951f8df1f2134797e 100644 (file)
@@ -46,8 +46,6 @@
 /* Step Enable */
 #define STEPENB_MASK           (0x1FFFF << 0)
 #define STEPENB(val)           ((val) << 0)
-#define STPENB_STEPENB         STEPENB(0x1FFFF)
-#define STPENB_STEPENB_TC      STEPENB(0x1FFF)
 
 /* IRQ enable */
 #define IRQENB_HW_PEN          BIT(0)
@@ -141,6 +139,8 @@ struct ti_tscadc_dev {
        void __iomem *tscadc_base;
        int irq;
        struct mfd_cell cells[TSCADC_CELLS];
+       u32 reg_se_cache;
+       spinlock_t reg_lock;
 
        /* tsc device */
        struct titsc *tsc;
@@ -156,4 +156,8 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
        return *tscadc_dev;
 }
 
+void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc);
+void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
+void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
+
 #endif