From 3d1b834b57d4710a48d61c794a38b28be56a67ce Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Mon, 13 Sep 2021 17:44:22 +0800 Subject: rt1718s: refactor: move gpio control to driver module This CL moves RT1718S gpio control from board file to common driver codebase, and implements the set flag and get/set level functions. Note that this CL does not fully implement IOEX interface because TCPC has different init process than usual ioexpanders. BUG=none TEST=1) pass faft_pd 2) manually test pd source/sink/frs on port 1 BRANCH=main Signed-off-by: Ting Shen Change-Id: If2a0bca2b13ad4748eea54b4c8004da7dc6fc6a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3159643 Reviewed-by: Rong Chang Commit-Queue: Ting Shen Tested-by: Ting Shen --- driver/tcpm/rt1718s.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'driver/tcpm/rt1718s.c') diff --git a/driver/tcpm/rt1718s.c b/driver/tcpm/rt1718s.c index 9a2f6319c7..9d5a8895ad 100644 --- a/driver/tcpm/rt1718s.c +++ b/driver/tcpm/rt1718s.c @@ -487,6 +487,39 @@ out: return rv; } +void rt1718s_gpio_set_flags(int port, enum rt1718s_gpio signal, uint32_t flags) +{ + int val = 0; + + if (!(flags & GPIO_OPEN_DRAIN)) + val |= RT1718S_GPIO_CTRL_OD_N; + if (flags & GPIO_PULL_UP) + val |= RT1718S_GPIO_CTRL_PU; + if (flags & GPIO_PULL_DOWN) + val |= RT1718S_GPIO_CTRL_PD; + if (flags & GPIO_HIGH) + val |= RT1718S_GPIO_CTRL_O; + if (flags & GPIO_OUTPUT) + val |= RT1718S_GPIO_CTRL_OE; + + rt1718s_write8(port, RT1718S_GPIO_CTRL(signal), val); +} + +void rt1718s_gpio_set_level(int port, enum rt1718s_gpio signal, int value) +{ + rt1718s_update_bits8(port, RT1718S_GPIO_CTRL(signal), + RT1718S_GPIO_CTRL_O, + value ? 0xFF : 0); +} + +int rt1718s_gpio_get_level(int port, enum rt1718s_gpio signal) +{ + int val; + + rt1718s_read8(port, RT1718S_GPIO_CTRL(signal), &val); + return !!(val & RT1718S_GPIO_CTRL_I); +} + /* RT1718S is a TCPCI compatible port controller */ const struct tcpm_drv rt1718s_tcpm_drv = { .init = &rt1718s_init, -- cgit v1.2.1