Skip to content

Commit 4e4c535

Browse files
committed
input: it8xxx2_kbd: add a kso-ignore-mask property
The it8xxx2_kbd KSO pins can be used as both keyboard scan and GPIO. By default the keyboard scanning driver controls the output level of all the KSO signals from 0 to (col-size - 1), meaning that any line in between used as GPIO is going to have its output value overridden. Add a kso-ignore-mask property to the keyboard scan driver to allow specifiying extra pins that should not be controlled by the driver. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 022c8ee commit 4e4c535

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

drivers/input/input_ite_it8xxx2_kbd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct it8xxx2_kbd_config {
4444
struct gpio_dt_spec kso16_gpios;
4545
/* KSO17 GPIO cells */
4646
struct gpio_dt_spec kso17_gpios;
47+
/* Mask of signals to ignore */
48+
uint32_t kso_ignore_mask;
4749
};
4850

4951
struct it8xxx2_kbd_data {
@@ -59,7 +61,7 @@ static void it8xxx2_kbd_drive_column(const struct device *dev, int col)
5961
const struct it8xxx2_kbd_config *const config = dev->config;
6062
const struct input_kbd_matrix_common_config *common = &config->common;
6163
struct kscan_it8xxx2_regs *const inst = config->base;
62-
const uint32_t kso_mask = BIT_MASK(common->col_size);
64+
const uint32_t kso_mask = BIT_MASK(common->col_size) & ~config->kso_ignore_mask;
6365
const uint8_t ksol_mask = kso_mask & 0xff;
6466
const uint8_t ksoh1_mask = (kso_mask >> 8) & 0xff;
6567
uint32_t kso_val;
@@ -76,17 +78,14 @@ static void it8xxx2_kbd_drive_column(const struct device *dev, int col)
7678
kso_val = kso_mask ^ BIT(col);
7779
}
7880

79-
/* Set KSO[17:0] output data */
80-
inst->KBS_KSOL = (inst->KBS_KSOL & ~ksol_mask) | (kso_val & ksol_mask);
81-
/*
82-
* Disable global interrupts for critical section
83-
* The KBS_KSOH1 register contains both keyboard and GPIO output settings.
81+
/* Set KSO[17:0] output data, disable global interrupts for critical section.
82+
* The KBS_KSO* registers contains both keyboard and GPIO output settings.
8483
* Not all bits are for the keyboard will be driven, so a critical section
8584
* is needed to avoid race conditions.
8685
*/
8786
key = irq_lock();
87+
inst->KBS_KSOL = (inst->KBS_KSOL & ~ksol_mask) | (kso_val & ksol_mask);
8888
inst->KBS_KSOH1 = (inst->KBS_KSOH1 & ~ksoh1_mask) | ((kso_val >> 8) & ksoh1_mask);
89-
/* Restore interrupts */
9089
irq_unlock(key);
9190

9291
if (common->col_size > 16) {
@@ -153,7 +152,7 @@ static int it8xxx2_kbd_init(const struct device *dev)
153152
const struct input_kbd_matrix_common_config *common = &config->common;
154153
struct it8xxx2_kbd_data *data = dev->data;
155154
struct kscan_it8xxx2_regs *const inst = config->base;
156-
const uint32_t kso_mask = BIT_MASK(common->col_size);
155+
const uint32_t kso_mask = BIT_MASK(common->col_size) & ~config->kso_ignore_mask;
157156
const uint8_t ksol_mask = kso_mask & 0xff;
158157
const uint8_t ksoh1_mask = (kso_mask >> 8) & 0xff;
159158
int status;
@@ -248,6 +247,7 @@ static const struct it8xxx2_kbd_config it8xxx2_kbd_cfg_0 = {
248247
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
249248
.kso16_gpios = GPIO_DT_SPEC_INST_GET(0, kso16_gpios),
250249
.kso17_gpios = GPIO_DT_SPEC_INST_GET(0, kso17_gpios),
250+
.kso_ignore_mask = DT_INST_PROP(0, kso_ignore_mask),
251251
};
252252

253253
static struct it8xxx2_kbd_data it8xxx2_kbd_data_0;

dts/bindings/input/ite,it8xxx2-kbd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ properties:
3535
description: |
3636
The KSO17 pin for the selected port.
3737
38+
kso-ignore-mask:
39+
type: int
40+
default: 0
41+
description: |
42+
Bitmask of KSO signals to ignore, this can be used to instruct the driver
43+
to skip KSO signals between 0 and (col-size - 1) that are used as GPIOs.
44+
Default to 0 (no signals masked).
45+
3846
pinctrl-0:
3947
required: true
4048

0 commit comments

Comments
 (0)