Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

David Brownell and committed by
Linus Torvalds
9084533e f09de595

+29 -26
+29 -26
drivers/input/touchscreen/ads7846.c
··· 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 41 * Support for ads7843 and ads7845 has only been stubbed in. 41 - * 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 42 * 46 43 * IRQ handling needs a workaround because of a shortcoming in handling 47 44 * edge triggered IRQs on some platforms like the OMAP1/2. These ··· 245 248 246 249 if (req->msg.status) 247 250 status = req->msg.status; 248 - sample = be16_to_cpu(req->sample); 249 - sample = sample >> 4; 250 - kfree(req); 251 251 252 + /* on-wire is a must-ignore bit, a BE12 value, then padding */ 253 + sample = be16_to_cpu(req->sample); 254 + sample = sample >> 3; 255 + sample &= 0x0fff; 256 + 257 + kfree(req); 252 258 return status ? status : sample; 253 259 } 254 260 ··· 336 336 u16 x, y, z1, z2; 337 337 unsigned long flags; 338 338 339 - /* adjust: 12 bit samples (left aligned), built from 340 - * two 8 bit values writen msb-first. 339 + /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; 340 + * built from two 8 bit values written msb-first. 341 341 */ 342 - x = be16_to_cpu(ts->tc.x) >> 4; 343 - y = be16_to_cpu(ts->tc.y) >> 4; 344 - z1 = be16_to_cpu(ts->tc.z1) >> 4; 345 - z2 = be16_to_cpu(ts->tc.z2) >> 4; 342 + x = (be16_to_cpu(ts->tc.x) >> 3) & 0x0fff; 343 + y = (be16_to_cpu(ts->tc.y) >> 3) & 0x0fff; 344 + z1 = (be16_to_cpu(ts->tc.z1) >> 3) & 0x0fff; 345 + z2 = (be16_to_cpu(ts->tc.z2) >> 3) & 0x0fff; 346 346 347 347 /* range filtering */ 348 348 if (x == MAX_12BIT) ··· 420 420 421 421 m = &ts->msg[ts->msg_idx]; 422 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 424 if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol)) { 425 425 /* Repeat it, if this was the first read or the read 426 426 * wasn't consistent enough. */ ··· 469 469 spin_lock_irq(&ts->lock); 470 470 471 471 if (unlikely(ts->msg_idx && !ts->pendown)) { 472 - /* measurment cycle ended */ 472 + /* measurement cycle ended */ 473 473 if (!device_suspended(&ts->spi->dev)) { 474 474 ts->irq_disabled = 0; 475 475 enable_irq(ts->spi->irq); ··· 495 495 spin_lock_irqsave(&ts->lock, flags); 496 496 if (likely(ts->get_pendown_state())) { 497 497 if (!ts->irq_disabled) { 498 - /* REVISIT irq logic for many ARM chips has cloned a 499 - * bug wherein disabling an irq in its handler won't 500 - * work;(it's disabled lazily, and too late to work. 501 - * until all their irq logic is fixed, we must shadow 502 - * that state here. 498 + /* The ARM do_simple_IRQ() dispatcher doesn't act 499 + * like the other dispatchers: it will report IRQs 500 + * even after they've been disabled. We work around 501 + * that here. (The "generic irq" framework may help...) 503 502 */ 504 503 ts->irq_disabled = 1; 505 504 disable_irq(ts->spi->irq); ··· 608 609 return -EINVAL; 609 610 } 610 611 612 + /* REVISIT when the irq can be triggered active-low, or if for some 613 + * reason the touchscreen isn't hooked up, we don't need to access 614 + * the pendown state. 615 + */ 611 616 if (pdata->get_pendown_state == NULL) { 612 617 dev_dbg(&spi->dev, "no get_pendown_state function?\n"); 613 618 return -EINVAL; 614 619 } 615 620 616 - /* We'd set the wordsize to 12 bits ... except that some controllers 617 - * will then treat the 8 bit command words as 12 bits (and drop the 618 - * four MSBs of the 12 bit result). Result: inputs must be shifted 619 - * to discard the four garbage LSBs. 621 + /* We'd set TX wordsize 8 bits and RX wordsize to 13 bits ... except 622 + * that even if the hardware can do that, the SPI controller driver 623 + * may not. So we stick to very-portable 8 bit words, both RX and TX. 620 624 */ 625 + spi->bits_per_word = 8; 621 626 622 627 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 623 628 input_dev = input_allocate_device(); ··· 775 772 776 773 if (request_irq(spi->irq, ads7846_irq, 777 774 SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING, 778 - spi->dev.bus_id, ts)) { 775 + spi->dev.driver->name, ts)) { 779 776 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 780 777 err = -EBUSY; 781 778 goto err_free_mem;