aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Stein <alexander.stein@systec-electronic.com>2011-05-11 19:24:08 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-05-12 11:28:56 -0400
commitebcaaad9d5e8fd284b8dcf25a24999420f0f56d8 (patch)
tree041e210499460d21c7acb75ced6b819f88bb4749
parente70bdd41bd0ead91b4a43e9d656ac1569d7c8779 (diff)
Input: ads7846 - add possibility to use external vref on ads7846
Just set vref_mv in your platform config to use external vref. Otherwise the internal one is used. Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r--drivers/input/touchscreen/ads7846.c19
-rw-r--r--include/linux/spi/ads7846.h3
2 files changed, 13 insertions, 9 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index c24946f51256..e4ee43e159d2 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -109,6 +109,7 @@ struct ads7846 {
109 u16 pressure_max; 109 u16 pressure_max;
110 110
111 bool swap_xy; 111 bool swap_xy;
112 bool use_internal;
112 113
113 struct ads7846_packet *packet; 114 struct ads7846_packet *packet;
114 115
@@ -300,7 +301,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
300 struct ads7846 *ts = dev_get_drvdata(dev); 301 struct ads7846 *ts = dev_get_drvdata(dev);
301 struct ser_req *req; 302 struct ser_req *req;
302 int status; 303 int status;
303 int use_internal;
304 304
305 req = kzalloc(sizeof *req, GFP_KERNEL); 305 req = kzalloc(sizeof *req, GFP_KERNEL);
306 if (!req) 306 if (!req)
@@ -308,11 +308,8 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
308 308
309 spi_message_init(&req->msg); 309 spi_message_init(&req->msg);
310 310
311 /* FIXME boards with ads7846 might use external vref instead ... */
312 use_internal = (ts->model == 7846);
313
314 /* maybe turn on internal vREF, and let it settle */ 311 /* maybe turn on internal vREF, and let it settle */
315 if (use_internal) { 312 if (ts->use_internal) {
316 req->ref_on = REF_ON; 313 req->ref_on = REF_ON;
317 req->xfer[0].tx_buf = &req->ref_on; 314 req->xfer[0].tx_buf = &req->ref_on;
318 req->xfer[0].len = 1; 315 req->xfer[0].len = 1;
@@ -324,8 +321,14 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
324 /* for 1uF, settle for 800 usec; no cap, 100 usec. */ 321 /* for 1uF, settle for 800 usec; no cap, 100 usec. */
325 req->xfer[1].delay_usecs = ts->vref_delay_usecs; 322 req->xfer[1].delay_usecs = ts->vref_delay_usecs;
326 spi_message_add_tail(&req->xfer[1], &req->msg); 323 spi_message_add_tail(&req->xfer[1], &req->msg);
324
325 /* Enable reference voltage */
326 command |= ADS_PD10_REF_ON;
327 } 327 }
328 328
329 /* Enable ADC in every case */
330 command |= ADS_PD10_ADC_ON;
331
329 /* take sample */ 332 /* take sample */
330 req->command = (u8) command; 333 req->command = (u8) command;
331 req->xfer[2].tx_buf = &req->command; 334 req->xfer[2].tx_buf = &req->command;
@@ -409,7 +412,7 @@ name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
409{ \ 412{ \
410 struct ads7846 *ts = dev_get_drvdata(dev); \ 413 struct ads7846 *ts = dev_get_drvdata(dev); \
411 ssize_t v = ads7846_read12_ser(dev, \ 414 ssize_t v = ads7846_read12_ser(dev, \
412 READ_12BIT_SER(var) | ADS_PD10_ALL_ON); \ 415 READ_12BIT_SER(var)); \
413 if (v < 0) \ 416 if (v < 0) \
414 return v; \ 417 return v; \
415 return sprintf(buf, "%u\n", adjust(ts, v)); \ 418 return sprintf(buf, "%u\n", adjust(ts, v)); \
@@ -502,6 +505,7 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
502 if (!ts->vref_mv) { 505 if (!ts->vref_mv) {
503 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); 506 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
504 ts->vref_mv = 2500; 507 ts->vref_mv = 2500;
508 ts->use_internal = true;
505 } 509 }
506 break; 510 break;
507 case 7845: 511 case 7845:
@@ -1333,8 +1337,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1333 if (ts->model == 7845) 1337 if (ts->model == 7845)
1334 ads7845_read12_ser(&spi->dev, PWRDOWN); 1338 ads7845_read12_ser(&spi->dev, PWRDOWN);
1335 else 1339 else
1336 (void) ads7846_read12_ser(&spi->dev, 1340 (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux));
1337 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
1338 1341
1339 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); 1342 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group);
1340 if (err) 1343 if (err)
diff --git a/include/linux/spi/ads7846.h b/include/linux/spi/ads7846.h
index 92bd0839d5b4..c64de9dd7631 100644
--- a/include/linux/spi/ads7846.h
+++ b/include/linux/spi/ads7846.h
@@ -14,7 +14,8 @@ enum ads7846_filter {
14struct ads7846_platform_data { 14struct ads7846_platform_data {
15 u16 model; /* 7843, 7845, 7846, 7873. */ 15 u16 model; /* 7843, 7845, 7846, 7873. */
16 u16 vref_delay_usecs; /* 0 for external vref; etc */ 16 u16 vref_delay_usecs; /* 0 for external vref; etc */
17 u16 vref_mv; /* external vref value, milliVolts */ 17 u16 vref_mv; /* external vref value, milliVolts
18 * ads7846: if 0, use internal vref */
18 bool keep_vref_on; /* set to keep vref on for differential 19 bool keep_vref_on; /* set to keep vref on for differential
19 * measurements as well */ 20 * measurements as well */
20 bool swap_xy; /* swap x and y axes */ 21 bool swap_xy; /* swap x and y axes */