aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2006-05-25 21:44:20 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-05-26 14:55:46 -0400
commit9084533e797f131c923c8883adf91cc2f7ddcfae (patch)
treea5ef83c83d2053e2a8aa9a294ceab425c6e1c92d
parentf09de595b5eda6040cd733ecf1eb222e00b42517 (diff)
[PATCH] ads7846 conversion accuracy
This improves accuracy of the touchscreen and hwmon sensor readings, addressing an issue noted by Imre Deak: there's an extra bit written before the sample (12 bits) gets written out. It also catches up to various comments, and makes the /proc/interrupts entry sensible again. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Imre Deak <imre.deak@nokia.com> Cc: Jean Delvare <khali@linux-fr.org> Cc: Dmitry Torokhov <dtor_core@ameritech.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/input/touchscreen/ads7846.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 1494175ac6fe..161afddd0f44 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -36,13 +36,10 @@
36 36
37 37
38/* 38/*
39 * This code has been tested on an ads7846 / N770 device. 39 * This code has been heavily tested on a Nokia 770, and lightly
40 * tested on other ads7846 devices (OSK/Mistral, Lubbock).
40 * Support for ads7843 and ads7845 has only been stubbed in. 41 * Support for ads7843 and ads7845 has only been stubbed in.
41 * 42 *
42 * Not yet done: How accurate are the temperature and voltage
43 * readings? (System-specific calibration should support
44 * accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.)
45 *
46 * IRQ handling needs a workaround because of a shortcoming in handling 43 * IRQ handling needs a workaround because of a shortcoming in handling
47 * edge triggered IRQs on some platforms like the OMAP1/2. These 44 * edge triggered IRQs on some platforms like the OMAP1/2. These
48 * platforms don't handle the ARM lazy IRQ disabling properly, thus we 45 * platforms don't handle the ARM lazy IRQ disabling properly, thus we
@@ -248,10 +245,13 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
248 245
249 if (req->msg.status) 246 if (req->msg.status)
250 status = req->msg.status; 247 status = req->msg.status;
248
249 /* on-wire is a must-ignore bit, a BE12 value, then padding */
251 sample = be16_to_cpu(req->sample); 250 sample = be16_to_cpu(req->sample);
252 sample = sample >> 4; 251 sample = sample >> 3;
253 kfree(req); 252 sample &= 0x0fff;
254 253
254 kfree(req);
255 return status ? status : sample; 255 return status ? status : sample;
256} 256}
257 257
@@ -336,13 +336,13 @@ static void ads7846_rx(void *ads)
336 u16 x, y, z1, z2; 336 u16 x, y, z1, z2;
337 unsigned long flags; 337 unsigned long flags;
338 338
339 /* adjust: 12 bit samples (left aligned), built from 339 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding;
340 * two 8 bit values writen msb-first. 340 * built from two 8 bit values written msb-first.
341 */ 341 */
342 x = be16_to_cpu(ts->tc.x) >> 4; 342 x = (be16_to_cpu(ts->tc.x) >> 3) & 0x0fff;
343 y = be16_to_cpu(ts->tc.y) >> 4; 343 y = (be16_to_cpu(ts->tc.y) >> 3) & 0x0fff;
344 z1 = be16_to_cpu(ts->tc.z1) >> 4; 344 z1 = (be16_to_cpu(ts->tc.z1) >> 3) & 0x0fff;
345 z2 = be16_to_cpu(ts->tc.z2) >> 4; 345 z2 = (be16_to_cpu(ts->tc.z2) >> 3) & 0x0fff;
346 346
347 /* range filtering */ 347 /* range filtering */
348 if (x == MAX_12BIT) 348 if (x == MAX_12BIT)
@@ -420,7 +420,7 @@ static void ads7846_debounce(void *ads)
420 420
421 m = &ts->msg[ts->msg_idx]; 421 m = &ts->msg[ts->msg_idx];
422 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 422 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
423 val = (*(u16 *)t->rx_buf) >> 3; 423 val = (be16_to_cpu(*(__be16 *)t->rx_buf) >> 3) & 0x0fff;
424 if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol)) { 424 if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol)) {
425 /* Repeat it, if this was the first read or the read 425 /* Repeat it, if this was the first read or the read
426 * wasn't consistent enough. */ 426 * wasn't consistent enough. */
@@ -469,7 +469,7 @@ static void ads7846_timer(unsigned long handle)
469 spin_lock_irq(&ts->lock); 469 spin_lock_irq(&ts->lock);
470 470
471 if (unlikely(ts->msg_idx && !ts->pendown)) { 471 if (unlikely(ts->msg_idx && !ts->pendown)) {
472 /* measurment cycle ended */ 472 /* measurement cycle ended */
473 if (!device_suspended(&ts->spi->dev)) { 473 if (!device_suspended(&ts->spi->dev)) {
474 ts->irq_disabled = 0; 474 ts->irq_disabled = 0;
475 enable_irq(ts->spi->irq); 475 enable_irq(ts->spi->irq);
@@ -495,11 +495,10 @@ static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
495 spin_lock_irqsave(&ts->lock, flags); 495 spin_lock_irqsave(&ts->lock, flags);
496 if (likely(ts->get_pendown_state())) { 496 if (likely(ts->get_pendown_state())) {
497 if (!ts->irq_disabled) { 497 if (!ts->irq_disabled) {
498 /* REVISIT irq logic for many ARM chips has cloned a 498 /* The ARM do_simple_IRQ() dispatcher doesn't act
499 * bug wherein disabling an irq in its handler won't 499 * like the other dispatchers: it will report IRQs
500 * work;(it's disabled lazily, and too late to work. 500 * even after they've been disabled. We work around
501 * until all their irq logic is fixed, we must shadow 501 * that here. (The "generic irq" framework may help...)
502 * that state here.
503 */ 502 */
504 ts->irq_disabled = 1; 503 ts->irq_disabled = 1;
505 disable_irq(ts->spi->irq); 504 disable_irq(ts->spi->irq);
@@ -609,16 +608,20 @@ static int __devinit ads7846_probe(struct spi_device *spi)
609 return -EINVAL; 608 return -EINVAL;
610 } 609 }
611 610
611 /* REVISIT when the irq can be triggered active-low, or if for some
612 * reason the touchscreen isn't hooked up, we don't need to access
613 * the pendown state.
614 */
612 if (pdata->get_pendown_state == NULL) { 615 if (pdata->get_pendown_state == NULL) {
613 dev_dbg(&spi->dev, "no get_pendown_state function?\n"); 616 dev_dbg(&spi->dev, "no get_pendown_state function?\n");
614 return -EINVAL; 617 return -EINVAL;
615 } 618 }
616 619
617 /* We'd set the wordsize to 12 bits ... except that some controllers 620 /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except
618 * will then treat the 8 bit command words as 12 bits (and drop the 621 * that even if the hardware can do that, the SPI controller driver
619 * four MSBs of the 12 bit result). Result: inputs must be shifted 622 * may not. So we stick to very-portable 8 bit words, both RX and TX.
620 * to discard the four garbage LSBs.
621 */ 623 */
624 spi->bits_per_word = 8;
622 625
623 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 626 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
624 input_dev = input_allocate_device(); 627 input_dev = input_allocate_device();
@@ -772,7 +775,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
772 775
773 if (request_irq(spi->irq, ads7846_irq, 776 if (request_irq(spi->irq, ads7846_irq,
774 SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING, 777 SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING,
775 spi->dev.bus_id, ts)) { 778 spi->dev.driver->name, ts)) {
776 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 779 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
777 err = -EBUSY; 780 err = -EBUSY;
778 goto err_free_mem; 781 goto err_free_mem;