Skip to content

Commit 7de90a8

Browse files
Imre DeakDmitry Torokhov
authored andcommitted
Input: ads7846 - miscellaneous fixes
- Add disable attribute to support device locking mode where unintentional touch event shouldn't wake up the system; - Update comments; - Add missing spin_lock_init; - Do device resume with the lock held; - Do cleanup calls / free memory in the reverse order of initialization. Signed-off-by: Imre Deak <imre.deak@nokia.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent c4febb9 commit 7de90a8

1 file changed

Lines changed: 114 additions & 30 deletions

File tree

‎drivers/input/touchscreen/ads7846.c‎

Lines changed: 114 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* ADS7846 based touchscreen and sensor driver
33
*
44
* Copyright (c) 2005 David Brownell
5+
* Copyright (c) 2006 Nokia Corporation
6+
* Various changes: Imre Deak <imre.deak@nokia.com>
57
*
68
* Using code from:
79
* - corgi_ts.c
@@ -34,17 +36,25 @@
3436

3537

3638
/*
37-
* This code has been lightly tested on an ads7846.
39+
* This code has been tested on an ads7846 / N770 device.
3840
* Support for ads7843 and ads7845 has only been stubbed in.
3941
*
40-
* Not yet done: investigate the values reported. Are x/y/pressure
41-
* event values sane enough for X11? How accurate are the temperature
42-
* and voltage readings? (System-specific calibration should support
42+
* Not yet done: How accurate are the temperature and voltage
43+
* readings? (System-specific calibration should support
4344
* accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.)
4445
*
46+
* IRQ handling needs a workaround because of a shortcoming in handling
47+
* edge triggered IRQs on some platforms like the OMAP1/2. These
48+
* platforms don't handle the ARM lazy IRQ disabling properly, thus we
49+
* have to maintain our own SW IRQ disabled status. This should be
50+
* removed as soon as the affected platform's IRQ handling is fixed.
51+
*
4552
* app note sbaa036 talks in more detail about accurate sampling...
4653
* that ought to help in situations like LCDs inducing noise (which
4754
* can also be helped by using synch signals) and more generally.
55+
* This driver tries to utilize the measures described in the app
56+
* note. The strength of filtering can be set in the board-* specific
57+
* files.
4858
*/
4959

5060
#define TS_POLL_PERIOD msecs_to_jiffies(10)
@@ -91,6 +101,7 @@ struct ads7846 {
91101
unsigned pending:1; /* P: lock */
92102
// FIXME remove "irq_disabled"
93103
unsigned irq_disabled:1; /* P: lock */
104+
unsigned disabled:1;
94105
};
95106

96107
/* leave chip selected when we're done, for quicker re-select? */
@@ -161,6 +172,9 @@ struct ser_req {
161172
struct spi_transfer xfer[6];
162173
};
163174

175+
static void ads7846_enable(struct ads7846 *ts);
176+
static void ads7846_disable(struct ads7846 *ts);
177+
164178
static int ads7846_read12_ser(struct device *dev, unsigned command)
165179
{
166180
struct spi_device *spi = to_spi_device(dev);
@@ -257,6 +271,37 @@ static ssize_t ads7846_pen_down_show(struct device *dev,
257271

258272
static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL);
259273

274+
static ssize_t ads7846_disable_show(struct device *dev,
275+
struct device_attribute *attr, char *buf)
276+
{
277+
struct ads7846 *ts = dev_get_drvdata(dev);
278+
279+
return sprintf(buf, "%u\n", ts->disabled);
280+
}
281+
282+
static ssize_t ads7846_disable_store(struct device *dev,
283+
struct device_attribute *attr,
284+
const char *buf, size_t count)
285+
{
286+
struct ads7846 *ts = dev_get_drvdata(dev);
287+
char *endp;
288+
int i;
289+
290+
i = simple_strtoul(buf, &endp, 10);
291+
spin_lock_irq(&ts->lock);
292+
293+
if (i)
294+
ads7846_disable(ts);
295+
else
296+
ads7846_enable(ts);
297+
298+
spin_unlock_irq(&ts->lock);
299+
300+
return count;
301+
}
302+
303+
static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
304+
260305
/*--------------------------------------------------------------------------*/
261306

262307
/*
@@ -396,12 +441,9 @@ static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
396441
{
397442
struct ads7846 *ts = handle;
398443
unsigned long flags;
399-
int r = IRQ_HANDLED;
400444

401445
spin_lock_irqsave(&ts->lock, flags);
402-
if (ts->irq_disabled)
403-
r = IRQ_HANDLED;
404-
else {
446+
if (likely(!ts->irq_disabled && !ts->disabled)) {
405447
if (!ts->irq_disabled) {
406448
/* REVISIT irq logic for many ARM chips has cloned a
407449
* bug wherein disabling an irq in its handler won't
@@ -419,20 +461,17 @@ static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
419461
}
420462
}
421463
spin_unlock_irqrestore(&ts->lock, flags);
422-
return r;
464+
465+
return IRQ_HANDLED;
423466
}
424467

425468
/*--------------------------------------------------------------------------*/
426469

427-
static int
428-
ads7846_suspend(struct spi_device *spi, pm_message_t message)
470+
/* Must be called with ts->lock held */
471+
static void ads7846_disable(struct ads7846 *ts)
429472
{
430-
struct ads7846 *ts = dev_get_drvdata(&spi->dev);
431-
unsigned long flags;
432-
433-
spin_lock_irqsave(&ts->lock, flags);
434-
435-
spi->dev.power.power_state = message;
473+
if (ts->disabled)
474+
return;
436475

437476
/* are we waiting for IRQ, or polling? */
438477
if (!ts->pendown) {
@@ -448,27 +487,56 @@ ads7846_suspend(struct spi_device *spi, pm_message_t message)
448487
mod_timer(&ts->timer, jiffies);
449488

450489
while (ts->pendown || ts->pending) {
451-
spin_unlock_irqrestore(&ts->lock, flags);
490+
spin_unlock_irq(&ts->lock);
452491
msleep(1);
453-
spin_lock_irqsave(&ts->lock, flags);
492+
spin_lock_irq(&ts->lock);
454493
}
455494
}
456495

457496
/* we know the chip's in lowpower mode since we always
458497
* leave it that way after every request
459498
*/
460499

461-
spin_unlock_irqrestore(&ts->lock, flags);
500+
ts->disabled = 1;
501+
}
502+
503+
/* Must be called with ts->lock held */
504+
static void ads7846_enable(struct ads7846 *ts)
505+
{
506+
if (!ts->disabled)
507+
return;
508+
509+
ts->disabled = 0;
510+
ts->irq_disabled = 0;
511+
enable_irq(ts->spi->irq);
512+
}
513+
514+
static int ads7846_suspend(struct spi_device *spi, pm_message_t message)
515+
{
516+
struct ads7846 *ts = dev_get_drvdata(&spi->dev);
517+
518+
spin_lock_irq(&ts->lock);
519+
520+
spi->dev.power.power_state = message;
521+
ads7846_disable(ts);
522+
523+
spin_unlock_irq(&ts->lock);
524+
462525
return 0;
526+
463527
}
464528

465529
static int ads7846_resume(struct spi_device *spi)
466530
{
467531
struct ads7846 *ts = dev_get_drvdata(&spi->dev);
468532

469-
ts->irq_disabled = 0;
470-
enable_irq(ts->spi->irq);
533+
spin_lock_irq(&ts->lock);
534+
471535
spi->dev.power.power_state = PMSG_ON;
536+
ads7846_enable(ts);
537+
538+
spin_unlock_irq(&ts->lock);
539+
472540
return 0;
473541
}
474542

@@ -521,6 +589,8 @@ static int __devinit ads7846_probe(struct spi_device *spi)
521589
ts->timer.data = (unsigned long) ts;
522590
ts->timer.function = ads7846_timer;
523591

592+
spin_lock_init(&ts->lock);
593+
524594
ts->model = pdata->model ? : 7846;
525595
ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
526596
ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
@@ -671,13 +741,25 @@ static int __devinit ads7846_probe(struct spi_device *spi)
671741

672742
device_create_file(&spi->dev, &dev_attr_pen_down);
673743

744+
device_create_file(&spi->dev, &dev_attr_disable);
745+
674746
err = input_register_device(input_dev);
675747
if (err)
676-
goto err_free_irq;
748+
goto err_remove_attr;
677749

678750
return 0;
679751

680-
err_free_irq:
752+
err_remove_attr:
753+
device_remove_file(&spi->dev, &dev_attr_disable);
754+
device_remove_file(&spi->dev, &dev_attr_pen_down);
755+
if (ts->model == 7846) {
756+
device_remove_file(&spi->dev, &dev_attr_temp1);
757+
device_remove_file(&spi->dev, &dev_attr_temp0);
758+
}
759+
if (ts->model != 7845)
760+
device_remove_file(&spi->dev, &dev_attr_vbatt);
761+
device_remove_file(&spi->dev, &dev_attr_vaux);
762+
681763
free_irq(spi->irq, ts);
682764
err_free_mem:
683765
input_free_device(input_dev);
@@ -689,22 +771,24 @@ static int __devexit ads7846_remove(struct spi_device *spi)
689771
{
690772
struct ads7846 *ts = dev_get_drvdata(&spi->dev);
691773

774+
input_unregister_device(ts->input);
775+
692776
ads7846_suspend(spi, PMSG_SUSPEND);
693-
free_irq(ts->spi->irq, ts);
694-
if (ts->irq_disabled)
695-
enable_irq(ts->spi->irq);
696777

778+
device_remove_file(&spi->dev, &dev_attr_disable);
697779
device_remove_file(&spi->dev, &dev_attr_pen_down);
698-
699780
if (ts->model == 7846) {
700-
device_remove_file(&spi->dev, &dev_attr_temp0);
701781
device_remove_file(&spi->dev, &dev_attr_temp1);
782+
device_remove_file(&spi->dev, &dev_attr_temp0);
702783
}
703784
if (ts->model != 7845)
704785
device_remove_file(&spi->dev, &dev_attr_vbatt);
705786
device_remove_file(&spi->dev, &dev_attr_vaux);
706787

707-
input_unregister_device(ts->input);
788+
free_irq(ts->spi->irq, ts);
789+
if (ts->irq_disabled)
790+
enable_irq(ts->spi->irq);
791+
708792
kfree(ts);
709793

710794
dev_dbg(&spi->dev, "unregistered touchscreen\n");

0 commit comments

Comments
 (0)