Input: ads7846 - assorted updates

This updates the ads7846 touchscreen driver:
- to allow faster clocking (this driver doesn't push sample rates);
- bugfixes the conversion of spi_transfer to lists;
- some dma-unsafe command buffers are fixed.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by David Brownell and committed by Dmitry Torokhov d93f70b2 a90f7e98

+44 -24
+44 -24
drivers/input/touchscreen/ads7846.c
··· 48 48 49 49 #define TS_POLL_PERIOD msecs_to_jiffies(10) 50 50 51 + /* this driver doesn't aim at the peak continuous sample rate */ 52 + #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) 53 + 51 54 struct ts_event { 52 55 /* For portability, we can't read 12 bit values using SPI (which 53 56 * would make the controller deliver them as native byteorder u16 54 - * with msbs zeroed). Instead, we read them as two 8-byte values, 57 + * with msbs zeroed). Instead, we read them as two 8-bit values, 55 58 * which need byteswapping then range adjustment. 56 59 */ 57 60 __be16 x; ··· 71 68 u16 vref_delay_usecs; 72 69 u16 x_plate_ohms; 73 70 71 + u8 read_x, read_y, read_z1, read_z2; 74 72 struct ts_event tc; 75 73 76 74 struct spi_transfer xfer[8]; ··· 121 117 #define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \ 122 118 | ADS_12_BIT | ADS_DFR) 123 119 124 - static const u8 read_y = READ_12BIT_DFR(y) | ADS_PD10_ADC_ON; 125 - static const u8 read_z1 = READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON; 126 - static const u8 read_z2 = READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON; 127 - static const u8 read_x = READ_12BIT_DFR(x) | ADS_PD10_PDOWN; /* LAST */ 120 + #define READ_Y (READ_12BIT_DFR(y) | ADS_PD10_ADC_ON) 121 + #define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON) 122 + #define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON) 123 + #define READ_X (READ_12BIT_DFR(x) | ADS_PD10_PDOWN) /* LAST */ 128 124 129 125 /* single-ended samples need to first power up reference voltage; 130 126 * we leave both ADC and VREF powered ··· 132 128 #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ 133 129 | ADS_12_BIT | ADS_SER) 134 130 135 - static const u8 ref_on = READ_12BIT_DFR(x) | ADS_PD10_ALL_ON; 136 - static const u8 ref_off = READ_12BIT_DFR(y) | ADS_PD10_PDOWN; 131 + #define REF_ON (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON) 132 + #define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) 137 133 138 134 /*--------------------------------------------------------------------------*/ 139 135 ··· 142 138 */ 143 139 144 140 struct ser_req { 141 + u8 ref_on; 145 142 u8 command; 143 + u8 ref_off; 146 144 u16 scratch; 147 145 __be16 sample; 148 146 struct spi_message msg; ··· 166 160 INIT_LIST_HEAD(&req->msg.transfers); 167 161 168 162 /* activate reference, so it has time to settle; */ 169 - req->xfer[0].tx_buf = &ref_on; 163 + req->ref_on = REF_ON; 164 + req->xfer[0].tx_buf = &req->ref_on; 170 165 req->xfer[0].len = 1; 171 166 req->xfer[1].rx_buf = &req->scratch; 172 167 req->xfer[1].len = 2; ··· 189 182 /* REVISIT: take a few more samples, and compare ... */ 190 183 191 184 /* turn off reference */ 192 - req->xfer[4].tx_buf = &ref_off; 185 + req->ref_off = REF_OFF; 186 + req->xfer[4].tx_buf = &req->ref_off; 193 187 req->xfer[4].len = 1; 194 188 req->xfer[5].rx_buf = &req->scratch; 195 189 req->xfer[5].len = 2; ··· 408 400 struct input_dev *input_dev; 409 401 struct ads7846_platform_data *pdata = spi->dev.platform_data; 410 402 struct spi_transfer *x; 411 - int i; 412 403 int err; 413 404 414 405 if (!spi->irq) { ··· 421 414 } 422 415 423 416 /* don't exceed max specified sample rate */ 424 - if (spi->max_speed_hz > (125000 * 16)) { 417 + if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { 425 418 dev_dbg(&spi->dev, "f(sample) %d KHz?\n", 426 - (spi->max_speed_hz/16)/1000); 419 + (spi->max_speed_hz/SAMPLE_BITS)/1000); 427 420 return -EINVAL; 428 421 } 429 422 ··· 476 469 /* set up the transfers to read touchscreen state; this assumes we 477 470 * use formula #2 for pressure, not #3. 478 471 */ 472 + INIT_LIST_HEAD(&ts->msg.transfers); 479 473 x = ts->xfer; 480 474 481 475 /* y- still on; turn on only y+ (and ADC) */ 482 - x->tx_buf = &read_y; 476 + ts->read_y = READ_Y; 477 + x->tx_buf = &ts->read_y; 483 478 x->len = 1; 479 + spi_message_add_tail(x, &ts->msg); 480 + 484 481 x++; 485 482 x->rx_buf = &ts->tc.y; 486 483 x->len = 2; 487 - x++; 484 + spi_message_add_tail(x, &ts->msg); 488 485 489 486 /* turn y+ off, x- on; we'll use formula #2 */ 490 487 if (ts->model == 7846) { 491 - x->tx_buf = &read_z1; 488 + x++; 489 + ts->read_z1 = READ_Z1; 490 + x->tx_buf = &ts->read_z1; 492 491 x->len = 1; 492 + spi_message_add_tail(x, &ts->msg); 493 + 493 494 x++; 494 495 x->rx_buf = &ts->tc.z1; 495 496 x->len = 2; 496 - x++; 497 + spi_message_add_tail(x, &ts->msg); 497 498 498 - x->tx_buf = &read_z2; 499 + x++; 500 + ts->read_z2 = READ_Z2; 501 + x->tx_buf = &ts->read_z2; 499 502 x->len = 1; 503 + spi_message_add_tail(x, &ts->msg); 504 + 500 505 x++; 501 506 x->rx_buf = &ts->tc.z2; 502 507 x->len = 2; 503 - x++; 508 + spi_message_add_tail(x, &ts->msg); 504 509 } 505 510 506 511 /* turn y- off, x+ on, then leave in lowpower */ 507 - x->tx_buf = &read_x; 512 + x++; 513 + ts->read_x = READ_X; 514 + x->tx_buf = &ts->read_x; 508 515 x->len = 1; 516 + spi_message_add_tail(x, &ts->msg); 517 + 509 518 x++; 510 519 x->rx_buf = &ts->tc.x; 511 520 x->len = 2; 512 - x++; 521 + CS_CHANGE(*x); 522 + spi_message_add_tail(x, &ts->msg); 513 523 514 - CS_CHANGE(x[-1]); 515 - 516 - for (i = 0; i < x - ts->xfer; i++) 517 - spi_message_add_tail(&ts->xfer[i], &ts->msg); 518 524 ts->msg.complete = ads7846_rx; 519 525 ts->msg.context = ts; 520 526