Skip to content

Commit 9eff794

Browse files
mhennerichdtor
authored andcommitted
Input: ad714x - read the interrupt status registers in a row
The interrupt status registers should be read in row to avoid invalid data. Alter "read" method for both bus options to allow reading several registers in a row and make sure we read interrupt status registers properly. Read sequence saves 50% of bus transactions compared to single register reads. So use it also for the result registers, which are also located in a row. Also update copyright notice. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent c0409fe commit 9eff794

4 files changed

Lines changed: 49 additions & 41 deletions

File tree

‎drivers/input/misc/ad714x-i2c.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* AD714X CapTouch Programmable Controller driver (I2C bus)
33
*
4-
* Copyright 2009 Analog Devices Inc.
4+
* Copyright 2009-2011 Analog Devices Inc.
55
*
66
* Licensed under the GPL-2 or later.
77
*/
@@ -47,9 +47,10 @@ static int ad714x_i2c_write(struct ad714x_chip *chip,
4747
}
4848

4949
static int ad714x_i2c_read(struct ad714x_chip *chip,
50-
unsigned short reg, unsigned short *data)
50+
unsigned short reg, unsigned short *data, size_t len)
5151
{
5252
struct i2c_client *client = to_i2c_client(chip->dev);
53+
int i;
5354
int error;
5455

5556
chip->xfer_buf[0] = cpu_to_be16(reg);
@@ -58,14 +59,16 @@ static int ad714x_i2c_read(struct ad714x_chip *chip,
5859
sizeof(*chip->xfer_buf));
5960
if (error >= 0)
6061
error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
61-
sizeof(*chip->xfer_buf));
62+
len * sizeof(*chip->xfer_buf));
6263

6364
if (unlikely(error < 0)) {
6465
dev_err(&client->dev, "I2C read error: %d\n", error);
6566
return error;
6667
}
6768

68-
*data = be16_to_cpup(chip->xfer_buf);
69+
for (i = 0; i < len; i++)
70+
data[i] = be16_to_cpu(chip->xfer_buf[i]);
71+
6972
return 0;
7073
}
7174

‎drivers/input/misc/ad714x-spi.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* AD714X CapTouch Programmable Controller driver (SPI bus)
33
*
4-
* Copyright 2009 Analog Devices Inc.
4+
* Copyright 2009-2011 Analog Devices Inc.
55
*
66
* Licensed under the GPL-2 or later.
77
*/
@@ -31,11 +31,12 @@ static int ad714x_spi_resume(struct device *dev)
3131
static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume);
3232

3333
static int ad714x_spi_read(struct ad714x_chip *chip,
34-
unsigned short reg, unsigned short *data)
34+
unsigned short reg, unsigned short *data, size_t len)
3535
{
3636
struct spi_device *spi = to_spi_device(chip->dev);
3737
struct spi_message message;
3838
struct spi_transfer xfer[2];
39+
int i;
3940
int error;
4041

4142
spi_message_init(&message);
@@ -48,7 +49,7 @@ static int ad714x_spi_read(struct ad714x_chip *chip,
4849
spi_message_add_tail(&xfer[0], &message);
4950

5051
xfer[1].rx_buf = &chip->xfer_buf[1];
51-
xfer[1].len = sizeof(chip->xfer_buf[1]);
52+
xfer[1].len = sizeof(chip->xfer_buf[1]) * len;
5253
spi_message_add_tail(&xfer[1], &message);
5354

5455
error = spi_sync(spi, &message);
@@ -57,7 +58,9 @@ static int ad714x_spi_read(struct ad714x_chip *chip,
5758
return error;
5859
}
5960

60-
*data = be16_to_cpu(chip->xfer_buf[1]);
61+
for (i = 0; i < len; i++)
62+
data[i] = be16_to_cpu(chip->xfer_buf[i + 1]);
63+
6164
return 0;
6265
}
6366

‎drivers/input/misc/ad714x.c‎

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* AD714X CapTouch Programmable Controller driver supporting AD7142/3/7/8/7A
33
*
4-
* Copyright 2009 Analog Devices Inc.
4+
* Copyright 2009-2011 Analog Devices Inc.
55
*
66
* Licensed under the GPL-2 or later.
77
*/
@@ -123,6 +123,7 @@ struct ad714x_driver_data {
123123
* information to integrate all things which will be private data
124124
* of spi/i2c device
125125
*/
126+
126127
static void ad714x_use_com_int(struct ad714x_chip *ad714x,
127128
int start_stage, int end_stage)
128129
{
@@ -131,11 +132,11 @@ static void ad714x_use_com_int(struct ad714x_chip *ad714x,
131132

132133
mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1);
133134

134-
ad714x->read(ad714x, STG_COM_INT_EN_REG, &data);
135+
ad714x->read(ad714x, STG_COM_INT_EN_REG, &data, 1);
135136
data |= 1 << end_stage;
136137
ad714x->write(ad714x, STG_COM_INT_EN_REG, data);
137138

138-
ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data);
139+
ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data, 1);
139140
data &= ~mask;
140141
ad714x->write(ad714x, STG_HIGH_INT_EN_REG, data);
141142
}
@@ -148,11 +149,11 @@ static void ad714x_use_thr_int(struct ad714x_chip *ad714x,
148149

149150
mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1);
150151

151-
ad714x->read(ad714x, STG_COM_INT_EN_REG, &data);
152+
ad714x->read(ad714x, STG_COM_INT_EN_REG, &data, 1);
152153
data &= ~(1 << end_stage);
153154
ad714x->write(ad714x, STG_COM_INT_EN_REG, data);
154155

155-
ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data);
156+
ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data, 1);
156157
data |= mask;
157158
ad714x->write(ad714x, STG_HIGH_INT_EN_REG, data);
158159
}
@@ -250,13 +251,16 @@ static void ad714x_slider_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
250251
struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx];
251252
int i;
252253

254+
ad714x->read(ad714x, CDC_RESULT_S0 + hw->start_stage,
255+
&ad714x->adc_reg[hw->start_stage],
256+
hw->end_stage - hw->start_stage + 1);
257+
253258
for (i = hw->start_stage; i <= hw->end_stage; i++) {
254-
ad714x->read(ad714x, CDC_RESULT_S0 + i, &ad714x->adc_reg[i]);
255259
ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM,
256-
&ad714x->amb_reg[i]);
260+
&ad714x->amb_reg[i], 1);
257261

258-
ad714x->sensor_val[i] = abs(ad714x->adc_reg[i] -
259-
ad714x->amb_reg[i]);
262+
ad714x->sensor_val[i] =
263+
abs(ad714x->adc_reg[i] - ad714x->amb_reg[i]);
260264
}
261265
}
262266

@@ -419,13 +423,16 @@ static void ad714x_wheel_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
419423
struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx];
420424
int i;
421425

426+
ad714x->read(ad714x, CDC_RESULT_S0 + hw->start_stage,
427+
&ad714x->adc_reg[hw->start_stage],
428+
hw->end_stage - hw->start_stage + 1);
429+
422430
for (i = hw->start_stage; i <= hw->end_stage; i++) {
423-
ad714x->read(ad714x, CDC_RESULT_S0 + i, &ad714x->adc_reg[i]);
424431
ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM,
425-
&ad714x->amb_reg[i]);
432+
&ad714x->amb_reg[i], 1);
426433
if (ad714x->adc_reg[i] > ad714x->amb_reg[i])
427-
ad714x->sensor_val[i] = ad714x->adc_reg[i] -
428-
ad714x->amb_reg[i];
434+
ad714x->sensor_val[i] =
435+
ad714x->adc_reg[i] - ad714x->amb_reg[i];
429436
else
430437
ad714x->sensor_val[i] = 0;
431438
}
@@ -570,13 +577,16 @@ static void touchpad_cal_sensor_val(struct ad714x_chip *ad714x, int idx)
570577
struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx];
571578
int i;
572579

580+
ad714x->read(ad714x, CDC_RESULT_S0 + hw->x_start_stage,
581+
&ad714x->adc_reg[hw->x_start_stage],
582+
hw->x_end_stage - hw->x_start_stage + 1);
583+
573584
for (i = hw->x_start_stage; i <= hw->x_end_stage; i++) {
574-
ad714x->read(ad714x, CDC_RESULT_S0 + i, &ad714x->adc_reg[i]);
575585
ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM,
576-
&ad714x->amb_reg[i]);
586+
&ad714x->amb_reg[i], 1);
577587
if (ad714x->adc_reg[i] > ad714x->amb_reg[i])
578-
ad714x->sensor_val[i] = ad714x->adc_reg[i] -
579-
ad714x->amb_reg[i];
588+
ad714x->sensor_val[i] =
589+
ad714x->adc_reg[i] - ad714x->amb_reg[i];
580590
else
581591
ad714x->sensor_val[i] = 0;
582592
}
@@ -862,7 +872,7 @@ static int ad714x_hw_detect(struct ad714x_chip *ad714x)
862872
{
863873
unsigned short data;
864874

865-
ad714x->read(ad714x, AD714X_PARTID_REG, &data);
875+
ad714x->read(ad714x, AD714X_PARTID_REG, &data, 1);
866876
switch (data & 0xFFF0) {
867877
case AD7142_PARTID:
868878
ad714x->product = 0x7142;
@@ -919,14 +929,12 @@ static void ad714x_hw_init(struct ad714x_chip *ad714x)
919929
ad714x->write(ad714x, AD714X_SYSCFG_REG + i,
920930
ad714x->hw->sys_cfg_reg[i]);
921931
for (i = 0; i < SYS_CFGREG_NUM; i++)
922-
ad714x->read(ad714x, AD714X_SYSCFG_REG + i, &data);
932+
ad714x->read(ad714x, AD714X_SYSCFG_REG + i, &data, 1);
923933

924934
ad714x->write(ad714x, AD714X_STG_CAL_EN_REG, 0xFFF);
925935

926936
/* clear all interrupts */
927-
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &data);
928-
ad714x->read(ad714x, STG_HIGH_INT_STA_REG, &data);
929-
ad714x->read(ad714x, STG_COM_INT_STA_REG, &data);
937+
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3);
930938
}
931939

932940
static irqreturn_t ad714x_interrupt_thread(int irq, void *data)
@@ -936,9 +944,7 @@ static irqreturn_t ad714x_interrupt_thread(int irq, void *data)
936944

937945
mutex_lock(&ad714x->mutex);
938946

939-
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state);
940-
ad714x->read(ad714x, STG_HIGH_INT_STA_REG, &ad714x->h_state);
941-
ad714x->read(ad714x, STG_COM_INT_STA_REG, &ad714x->c_state);
947+
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3);
942948

943949
for (i = 0; i < ad714x->hw->button_num; i++)
944950
ad714x_button_state_machine(ad714x, i);
@@ -1225,8 +1231,6 @@ EXPORT_SYMBOL(ad714x_disable);
12251231

12261232
int ad714x_enable(struct ad714x_chip *ad714x)
12271233
{
1228-
unsigned short data;
1229-
12301234
dev_dbg(ad714x->dev, "%s enter\n", __func__);
12311235

12321236
mutex_lock(&ad714x->mutex);
@@ -1240,9 +1244,7 @@ int ad714x_enable(struct ad714x_chip *ad714x)
12401244
* otherwise we will get no chance to enter falling-edge irq again
12411245
*/
12421246

1243-
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &data);
1244-
ad714x->read(ad714x, STG_HIGH_INT_STA_REG, &data);
1245-
ad714x->read(ad714x, STG_COM_INT_STA_REG, &data);
1247+
ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3);
12461248

12471249
mutex_unlock(&ad714x->mutex);
12481250

‎drivers/input/misc/ad714x.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* AD714X CapTouch Programmable Controller driver (bus interfaces)
33
*
4-
* Copyright 2009 Analog Devices Inc.
4+
* Copyright 2009-2011 Analog Devices Inc.
55
*
66
* Licensed under the GPL-2 or later.
77
*/
@@ -18,12 +18,12 @@ struct ad714x_platform_data;
1818
struct ad714x_driver_data;
1919
struct ad714x_chip;
2020

21-
typedef int (*ad714x_read_t)(struct ad714x_chip *, unsigned short, unsigned short *);
21+
typedef int (*ad714x_read_t)(struct ad714x_chip *, unsigned short, unsigned short *, size_t);
2222
typedef int (*ad714x_write_t)(struct ad714x_chip *, unsigned short, unsigned short);
2323

2424
struct ad714x_chip {
25-
unsigned short h_state;
2625
unsigned short l_state;
26+
unsigned short h_state;
2727
unsigned short c_state;
2828
unsigned short adc_reg[STAGE_NUM];
2929
unsigned short amb_reg[STAGE_NUM];

0 commit comments

Comments
 (0)