Skip to content

Commit 7c6d0ee

Browse files
David Brownelldtor
authored andcommitted
Input: ads7846 - simplify support of external vREF (and ads7843)
This updates the ads7846 driver to handle external vREF (required on boards using ads7843 chips) without module parameters, and also removes a needless variable with its associated bogus gcc warning. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent e6cdd15 commit 7c6d0ee

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎drivers/input/touchscreen/ads7846.c‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct ads7846 {
8787
#endif
8888

8989
u16 model;
90+
u16 vref_mv;
9091
u16 vref_delay_usecs;
9192
u16 x_plate_ohms;
9293
u16 pressure_max;
@@ -184,9 +185,6 @@ struct ads7846 {
184185
* The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
185186
* ads7846 lets that pin be unconnected, to use internal vREF.
186187
*/
187-
static unsigned vREF_mV;
188-
module_param(vREF_mV, uint, 0);
189-
MODULE_PARM_DESC(vREF_mV, "external vREF voltage, in milliVolts");
190188

191189
struct ser_req {
192190
u8 ref_on;
@@ -213,7 +211,6 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
213211
struct ads7846 *ts = dev_get_drvdata(dev);
214212
struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL);
215213
int status;
216-
int uninitialized_var(sample);
217214
int use_internal;
218215

219216
if (!req)
@@ -270,13 +267,13 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
270267

271268
if (status == 0) {
272269
/* on-wire is a must-ignore bit, a BE12 value, then padding */
273-
sample = be16_to_cpu(req->sample);
274-
sample = sample >> 3;
275-
sample &= 0x0fff;
270+
status = be16_to_cpu(req->sample);
271+
status = status >> 3;
272+
status &= 0x0fff;
276273
}
277274

278275
kfree(req);
279-
return status ? status : sample;
276+
return status;
280277
}
281278

282279
#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
@@ -317,7 +314,7 @@ static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
317314
unsigned retval = v;
318315

319316
/* external resistors may scale vAUX into 0..vREF */
320-
retval *= vREF_mV;
317+
retval *= ts->vref_mv;
321318
retval = retval >> 12;
322319
return retval;
323320
}
@@ -375,14 +372,14 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
375372
/* hwmon sensors need a reference voltage */
376373
switch (ts->model) {
377374
case 7846:
378-
if (!vREF_mV) {
375+
if (!ts->vref_mv) {
379376
dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
380-
vREF_mV = 2500;
377+
ts->vref_mv = 2500;
381378
}
382379
break;
383380
case 7845:
384381
case 7843:
385-
if (!vREF_mV) {
382+
if (!ts->vref_mv) {
386383
dev_warn(&spi->dev,
387384
"external vREF for ADS%d not specified\n",
388385
ts->model);
@@ -875,6 +872,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
875872

876873
ts->spi = spi;
877874
ts->input = input_dev;
875+
ts->vref_mv = pdata->vref_mv;
878876

879877
hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
880878
ts->timer.function = ads7846_timer;

‎include/linux/spi/ads7846.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ enum ads7846_filter {
1414
struct ads7846_platform_data {
1515
u16 model; /* 7843, 7845, 7846. */
1616
u16 vref_delay_usecs; /* 0 for external vref; etc */
17-
int keep_vref_on:1; /* set to keep vref on for differential
17+
u16 vref_mv; /* external vref value, milliVolts */
18+
bool keep_vref_on; /* set to keep vref on for differential
1819
* measurements as well */
1920

2021
/* Settling time of the analog signals; a function of Vcc and the

0 commit comments

Comments
 (0)