aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatil, Rachna <rachna@ti.com>2013-01-23 22:45:05 -0500
committerSebastian Andrzej Siewior <bigeasy@linutronix.de>2013-06-12 12:03:55 -0400
commitabeccee40320245a2a6a006dc8466a703cbd1d5e (patch)
tree1c6709c2d53fd65f77a226abab9a552e5ce73fb5
parenta9bce1b03c2199e66d36cda8aac675338bc074a7 (diff)
input: ti_am33x_tsc: Step enable bits made configurable
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>
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c20
-rw-r--r--drivers/input/touchscreen/ti_am335x_tsc.c12
-rw-r--r--drivers/mfd/ti_am335x_tscadc.c29
-rw-r--r--include/linux/mfd/ti_am335x_tscadc.h8
4 files changed, 62 insertions, 7 deletions
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 9db352e413e4..543b9c42ac5f 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -42,10 +42,20 @@ static void tiadc_writel(struct tiadc_device *adc, unsigned int reg,
42 writel(val, adc->mfd_tscadc->tscadc_base + reg); 42 writel(val, adc->mfd_tscadc->tscadc_base + reg);
43} 43}
44 44
45static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
46{
47 u32 step_en;
48
49 step_en = ((1 << adc_dev->channels) - 1);
50 step_en <<= TOTAL_STEPS - adc_dev->channels + 1;
51 return step_en;
52}
53
45static void tiadc_step_config(struct tiadc_device *adc_dev) 54static void tiadc_step_config(struct tiadc_device *adc_dev)
46{ 55{
47 unsigned int stepconfig; 56 unsigned int stepconfig;
48 int i, channels = 0, steps; 57 int i, channels = 0, steps;
58 u32 step_en;
49 59
50 /* 60 /*
51 * There are 16 configurable steps and 8 analog input 61 * There are 16 configurable steps and 8 analog input
@@ -69,7 +79,8 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
69 STEPCONFIG_OPENDLY); 79 STEPCONFIG_OPENDLY);
70 channels++; 80 channels++;
71 } 81 }
72 tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); 82 step_en = get_adc_step_mask(adc_dev);
83 am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
73} 84}
74 85
75static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) 86static 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,
127 if (i == chan->channel) 138 if (i == chan->channel)
128 *val = readx1 & 0xfff; 139 *val = readx1 & 0xfff;
129 } 140 }
130 tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB); 141 am335x_tsc_se_update(adc_dev->mfd_tscadc);
131 142
132 return IIO_VAL_INT; 143 return IIO_VAL_INT;
133} 144}
@@ -191,10 +202,15 @@ err_ret:
191static int tiadc_remove(struct platform_device *pdev) 202static int tiadc_remove(struct platform_device *pdev)
192{ 203{
193 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 204 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
205 struct tiadc_device *adc_dev = iio_priv(indio_dev);
206 u32 step_en;
194 207
195 iio_device_unregister(indio_dev); 208 iio_device_unregister(indio_dev);
196 tiadc_channels_remove(indio_dev); 209 tiadc_channels_remove(indio_dev);
197 210
211 step_en = get_adc_step_mask(adc_dev);
212 am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en);
213
198 iio_device_free(indio_dev); 214 iio_device_free(indio_dev);
199 215
200 return 0; 216 return 0;
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index 16077d3d80ba..23d6a4dacc88 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -57,6 +57,7 @@ static void titsc_writel(struct titsc *tsc, unsigned int reg,
57static void titsc_step_config(struct titsc *ts_dev) 57static void titsc_step_config(struct titsc *ts_dev)
58{ 58{
59 unsigned int config; 59 unsigned int config;
60 unsigned int stepenable = 0;
60 int i, total_steps; 61 int i, total_steps;
61 62
62 /* Configure the Step registers */ 63 /* Configure the Step registers */
@@ -128,7 +129,9 @@ static void titsc_step_config(struct titsc *ts_dev)
128 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2), 129 titsc_writel(ts_dev, REG_STEPDELAY(total_steps + 2),
129 STEPCONFIG_OPENDLY); 130 STEPCONFIG_OPENDLY);
130 131
131 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC); 132 /* The steps1 … end and bit 0 for TS_Charge */
133 stepenable = (1 << (total_steps + 2)) - 1;
134 am335x_tsc_se_set(ts_dev->mfd_tscadc, stepenable);
132} 135}
133 136
134static void titsc_read_coordinates(struct titsc *ts_dev, 137static void titsc_read_coordinates(struct titsc *ts_dev,
@@ -250,7 +253,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
250 253
251 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr); 254 titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
252 255
253 titsc_writel(ts_dev, REG_SE, STPENB_STEPENB_TC); 256 am335x_tsc_se_update(ts_dev->mfd_tscadc);
254 return IRQ_HANDLED; 257 return IRQ_HANDLED;
255} 258}
256 259
@@ -334,6 +337,11 @@ static int titsc_remove(struct platform_device *pdev)
334 337
335 free_irq(ts_dev->irq, ts_dev); 338 free_irq(ts_dev->irq, ts_dev);
336 339
340 /* total steps followed by the enable mask */
341 steps = 2 * ts_dev->steps_to_configure + 2;
342 steps = (1 << steps) - 1;
343 am335x_tsc_se_clr(ts_dev->mfd_tscadc, steps);
344
337 input_unregister_device(ts_dev->input); 345 input_unregister_device(ts_dev->input);
338 346
339 platform_set_drvdata(pdev, NULL); 347 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index 772ea2adb539..90ccfc07e16b 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -48,6 +48,32 @@ static const struct regmap_config tscadc_regmap_config = {
48 .val_bits = 32, 48 .val_bits = 32,
49}; 49};
50 50
51void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc)
52{
53 tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache);
54}
55EXPORT_SYMBOL_GPL(am335x_tsc_se_update);
56
57void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val)
58{
59 spin_lock(&tsadc->reg_lock);
60 tsadc->reg_se_cache |= val;
61 spin_unlock(&tsadc->reg_lock);
62
63 am335x_tsc_se_update(tsadc);
64}
65EXPORT_SYMBOL_GPL(am335x_tsc_se_set);
66
67void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val)
68{
69 spin_lock(&tsadc->reg_lock);
70 tsadc->reg_se_cache &= ~val;
71 spin_unlock(&tsadc->reg_lock);
72
73 am335x_tsc_se_update(tsadc);
74}
75EXPORT_SYMBOL_GPL(am335x_tsc_se_clr);
76
51static void tscadc_idle_config(struct ti_tscadc_dev *config) 77static void tscadc_idle_config(struct ti_tscadc_dev *config)
52{ 78{
53 unsigned int idleconfig; 79 unsigned int idleconfig;
@@ -129,6 +155,7 @@ static int ti_tscadc_probe(struct platform_device *pdev)
129 goto ret; 155 goto ret;
130 } 156 }
131 157
158 spin_lock_init(&tscadc->reg_lock);
132 pm_runtime_enable(&pdev->dev); 159 pm_runtime_enable(&pdev->dev);
133 pm_runtime_get_sync(&pdev->dev); 160 pm_runtime_get_sync(&pdev->dev);
134 161
@@ -239,7 +266,7 @@ static int tscadc_resume(struct device *dev)
239 CNTRLREG_STEPID | CNTRLREG_4WIRE; 266 CNTRLREG_STEPID | CNTRLREG_4WIRE;
240 tscadc_writel(tscadc_dev, REG_CTRL, ctrl); 267 tscadc_writel(tscadc_dev, REG_CTRL, ctrl);
241 tscadc_idle_config(tscadc_dev); 268 tscadc_idle_config(tscadc_dev);
242 tscadc_writel(tscadc_dev, REG_SE, STPENB_STEPENB); 269 am335x_tsc_se_update(tscadc_dev);
243 restore = tscadc_readl(tscadc_dev, REG_CTRL); 270 restore = tscadc_readl(tscadc_dev, REG_CTRL);
244 tscadc_writel(tscadc_dev, REG_CTRL, 271 tscadc_writel(tscadc_dev, REG_CTRL,
245 (restore | CNTRLREG_TSCSSENB)); 272 (restore | CNTRLREG_TSCSSENB));
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index 8114e4e8b91b..4258627d076a 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -46,8 +46,6 @@
46/* Step Enable */ 46/* Step Enable */
47#define STEPENB_MASK (0x1FFFF << 0) 47#define STEPENB_MASK (0x1FFFF << 0)
48#define STEPENB(val) ((val) << 0) 48#define STEPENB(val) ((val) << 0)
49#define STPENB_STEPENB STEPENB(0x1FFFF)
50#define STPENB_STEPENB_TC STEPENB(0x1FFF)
51 49
52/* IRQ enable */ 50/* IRQ enable */
53#define IRQENB_HW_PEN BIT(0) 51#define IRQENB_HW_PEN BIT(0)
@@ -141,6 +139,8 @@ struct ti_tscadc_dev {
141 void __iomem *tscadc_base; 139 void __iomem *tscadc_base;
142 int irq; 140 int irq;
143 struct mfd_cell cells[TSCADC_CELLS]; 141 struct mfd_cell cells[TSCADC_CELLS];
142 u32 reg_se_cache;
143 spinlock_t reg_lock;
144 144
145 /* tsc device */ 145 /* tsc device */
146 struct titsc *tsc; 146 struct titsc *tsc;
@@ -156,4 +156,8 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
156 return *tscadc_dev; 156 return *tscadc_dev;
157} 157}
158 158
159void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc);
160void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
161void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
162
159#endif 163#endif