Skip to content

Commit 7c12a5b

Browse files
Linus Walleijdtor
authored andcommitted
Input: stmpe - bias keypad columns properly
All keypad column pins used as inputs should be pulled up on the STMPE24xx, but this is not done by the current driver. Add some logic that will do this properly. The STMPE1601 also has a keypad controller, but explicitly does *NOT* require you to set up any pull-ups. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent a416486 commit 7c12a5b

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

‎drivers/input/keyboard/stmpe-keypad.c‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* struct stmpe_keypad_variant - model-specific attributes
5353
* @auto_increment: whether the KPC_DATA_BYTE register address
5454
* auto-increments on multiple read
55+
* @set_pullup: whether the pins need to have their pull-ups set
5556
* @num_data: number of data bytes
5657
* @num_normal_data: number of normal keys' data bytes
5758
* @max_cols: maximum number of columns supported
@@ -61,6 +62,7 @@
6162
*/
6263
struct stmpe_keypad_variant {
6364
bool auto_increment;
65+
bool set_pullup;
6466
int num_data;
6567
int num_normal_data;
6668
int max_cols;
@@ -81,6 +83,7 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
8183
},
8284
[STMPE2401] = {
8385
.auto_increment = false,
86+
.set_pullup = true,
8487
.num_data = 3,
8588
.num_normal_data = 2,
8689
.max_cols = 8,
@@ -90,6 +93,7 @@ static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
9093
},
9194
[STMPE2403] = {
9295
.auto_increment = true,
96+
.set_pullup = true,
9397
.num_data = 5,
9498
.num_normal_data = 3,
9599
.max_cols = 8,
@@ -185,7 +189,10 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
185189
unsigned int col_gpios = variant->col_gpios;
186190
unsigned int row_gpios = variant->row_gpios;
187191
struct stmpe *stmpe = keypad->stmpe;
192+
u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB];
188193
unsigned int pins = 0;
194+
unsigned int pu_pins = 0;
195+
int ret;
189196
int i;
190197

191198
/*
@@ -202,8 +209,10 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
202209
for (i = 0; i < variant->max_cols; i++) {
203210
int num = __ffs(col_gpios);
204211

205-
if (keypad->cols & (1 << i))
212+
if (keypad->cols & (1 << i)) {
206213
pins |= 1 << num;
214+
pu_pins |= 1 << num;
215+
}
207216

208217
col_gpios &= ~(1 << num);
209218
}
@@ -217,7 +226,31 @@ static int stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
217226
row_gpios &= ~(1 << num);
218227
}
219228

220-
return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
229+
ret = stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
230+
if (ret)
231+
return ret;
232+
233+
/*
234+
* On STMPE24xx, set pin bias to pull-up on all keypad input
235+
* pins (columns), this incidentally happen to be maximum 8 pins
236+
* and placed at GPIO0-7 so only the LSB of the pull up register
237+
* ever needs to be written.
238+
*/
239+
if (variant->set_pullup) {
240+
u8 val;
241+
242+
ret = stmpe_reg_read(stmpe, pureg);
243+
if (ret)
244+
return ret;
245+
246+
/* Do not touch unused pins, may be used for GPIO */
247+
val = ret & ~pu_pins;
248+
val |= pu_pins;
249+
250+
ret = stmpe_reg_write(stmpe, pureg, val);
251+
}
252+
253+
return 0;
221254
}
222255

223256
static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)

0 commit comments

Comments
 (0)