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