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