Skip to content

Commit 8317f9e

Browse files
GTLin08henrikbrixandersen
authored andcommitted
ITE: drivers/gpio: Add keyboard-controller property
When set, this GPIO controller has pins associated with the keyboard controller. In this case the reg_gpcr property is overloaded and used to write the keyboard GCTRL register Signed-off-by: Tim Lin <[email protected]>
1 parent 43d57ce commit 8317f9e

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed

drivers/gpio/gpio_ite_it8xxx2_v2.c

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct gpio_ite_cfg {
5454
uint8_t has_volt_sel[8];
5555
/* Number of pins per group of GPIO */
5656
uint8_t num_pins;
57+
/* gpioksi, gpioksoh and gpioksol extended setting */
58+
bool kbs_ctrl;
5759
};
5860

5961
/* Structure gpio_ite_data is about callback function */
@@ -159,25 +161,57 @@ static int gpio_ite_configure(const struct device *dev,
159161
}
160162

161163
/* Set input or output. */
162-
if (flags & GPIO_OUTPUT) {
163-
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_OUTPUT) &
164-
~GPCR_PORT_PIN_MODE_INPUT;
164+
if (gpio_config->kbs_ctrl) {
165+
/* Handle keyboard scan controller */
166+
uint8_t ksxgctrlr = ECREG(reg_gpcr);
167+
168+
ksxgctrlr |= KSIX_KSOX_KBS_GPIO_MODE;
169+
if (flags & GPIO_OUTPUT) {
170+
ksxgctrlr |= KSIX_KSOX_GPIO_OUTPUT;
171+
} else {
172+
ksxgctrlr &= ~KSIX_KSOX_GPIO_OUTPUT;
173+
}
174+
ECREG(reg_gpcr) = ksxgctrlr;
165175
} else {
166-
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_INPUT) &
176+
/* Handle regular GPIO controller */
177+
if (flags & GPIO_OUTPUT) {
178+
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_OUTPUT) &
179+
~GPCR_PORT_PIN_MODE_INPUT;
180+
} else {
181+
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_INPUT) &
167182
~GPCR_PORT_PIN_MODE_OUTPUT;
183+
}
168184
}
169185

170186
/* Handle pullup / pulldown */
171-
if (flags & GPIO_PULL_UP) {
172-
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_PULLUP) &
173-
~GPCR_PORT_PIN_MODE_PULLDOWN;
174-
} else if (flags & GPIO_PULL_DOWN) {
175-
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_PULLDOWN) &
176-
~GPCR_PORT_PIN_MODE_PULLUP;
187+
if (gpio_config->kbs_ctrl) {
188+
/* Handle keyboard scan controller */
189+
uint8_t ksxgctrlr = ECREG(reg_gpcr);
190+
191+
if (flags & GPIO_PULL_UP) {
192+
ksxgctrlr = (ksxgctrlr | KSIX_KSOX_GPIO_PULLUP) &
193+
~KSIX_KSOX_GPIO_PULLDOWN;
194+
} else if (flags & GPIO_PULL_DOWN) {
195+
ksxgctrlr = (ksxgctrlr | KSIX_KSOX_GPIO_PULLDOWN) &
196+
~KSIX_KSOX_GPIO_PULLUP;
197+
} else {
198+
/* No pull up/down */
199+
ksxgctrlr &= ~(KSIX_KSOX_GPIO_PULLUP | KSIX_KSOX_GPIO_PULLDOWN);
200+
}
201+
ECREG(reg_gpcr) = ksxgctrlr;
177202
} else {
178-
/* No pull up/down */
179-
ECREG(reg_gpcr) &= ~(GPCR_PORT_PIN_MODE_PULLUP |
180-
GPCR_PORT_PIN_MODE_PULLDOWN);
203+
/* Handle regular GPIO controller */
204+
if (flags & GPIO_PULL_UP) {
205+
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_PULLUP) &
206+
~GPCR_PORT_PIN_MODE_PULLDOWN;
207+
} else if (flags & GPIO_PULL_DOWN) {
208+
ECREG(reg_gpcr) = (ECREG(reg_gpcr) | GPCR_PORT_PIN_MODE_PULLDOWN) &
209+
~GPCR_PORT_PIN_MODE_PULLUP;
210+
} else {
211+
/* No pull up/down */
212+
ECREG(reg_gpcr) &= ~(GPCR_PORT_PIN_MODE_PULLUP |
213+
GPCR_PORT_PIN_MODE_PULLDOWN);
214+
}
181215
}
182216

183217
unlock_and_return:
@@ -512,6 +546,7 @@ static const struct gpio_ite_cfg gpio_ite_cfg_##inst = { \
512546
.gpio_irq = IT8XXX2_DT_GPIO_IRQ_LIST(inst), \
513547
.has_volt_sel = DT_INST_PROP_OR(inst, has_volt_sel, {0}), \
514548
.num_pins = DT_INST_PROP(inst, ngpios), \
549+
.kbs_ctrl = DT_INST_PROP_OR(inst, keyboard_controller, 0), \
515550
}; \
516551
DEVICE_DT_INST_DEFINE(inst, \
517552
gpio_ite_init, \

dts/bindings/gpio/ite,it8xxx2-gpio-v2.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ properties:
2727
wuc-mask:
2828
type: array
2929

30+
keyboard-controller:
31+
type: boolean
32+
description: |
33+
When set, this GPIO controller has pins associated with the
34+
keyboard controller. In this case the reg_gpcr property is
35+
overloaded and used to write the keyboard GCTRL register.
36+
This setting will be found in the gpio_ite_configure function
37+
when the judgment of gpio_config->ksb_ctrl is true.
38+
The GPIO control register that will be set for these three
39+
nodes is as follows:
40+
gpioksi: 0xf01d40-0xf01d47
41+
gpioksol: 0xf01d48-0xf01d4f
42+
gpioksoh: 0xf01d50-0xf01d57
43+
3044
gpio-cells:
3145
- pin
3246
- flags

dts/riscv/ite/it82xx2.dtsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
NO_FUNC 0
391391
NO_FUNC 0>;
392392
interrupt-parent = <&intc>;
393+
keyboard-controller;
393394
#gpio-cells = <2>;
394395
};
395396

@@ -411,6 +412,7 @@
411412
NO_FUNC 0
412413
NO_FUNC 0>;
413414
interrupt-parent = <&intc>;
415+
keyboard-controller;
414416
#gpio-cells = <2>;
415417
};
416418

@@ -432,6 +434,7 @@
432434
NO_FUNC 0
433435
NO_FUNC 0>;
434436
interrupt-parent = <&intc>;
437+
keyboard-controller;
435438
#gpio-cells = <2>;
436439
};
437440

soc/riscv/ite_ec/common/chip_chipregs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,11 @@ struct gpio_it8xxx2_regs {
10731073
#define IT8XXX2_GPIO_GPH1VS BIT(1)
10741074
#define IT8XXX2_GPIO_GPH2VS BIT(0)
10751075

1076+
#define KSIX_KSOX_KBS_GPIO_MODE BIT(7)
1077+
#define KSIX_KSOX_GPIO_OUTPUT BIT(6)
1078+
#define KSIX_KSOX_GPIO_PULLUP BIT(2)
1079+
#define KSIX_KSOX_GPIO_PULLDOWN BIT(1)
1080+
10761081
#define GPCR_PORT_PIN_MODE_INPUT BIT(7)
10771082
#define GPCR_PORT_PIN_MODE_OUTPUT BIT(6)
10781083
#define GPCR_PORT_PIN_MODE_PULLUP BIT(2)

0 commit comments

Comments
 (0)