summaryrefslogtreecommitdiff
path: root/chip/it83xx/gpio.c
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2019-10-25 03:38:30 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-01 02:46:00 +0000
commit3b390264a415ce121a8c6f8db9fa9c42c647aaec (patch)
treeef137798bf0672d035e644784c27f2f7162d3db2 /chip/it83xx/gpio.c
parent946402100fd0589b5480eebd8444a7c3eb9b6aa5 (diff)
downloadchrome-ec-3b390264a415ce121a8c6f8db9fa9c42c647aaec.tar.gz
Cleanup: Correct GPIO alternate function parameter
Added code to correct the GPIO alternate function parameter at Chipset level. Optionally board level functions can cleanup the code in additional change lists. BUG=b:139427854 BRANCH=none TEST=make buildall -j Change-Id: I1171ca36a703291070fc89f972f84414adcf04fc Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1880974 Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'chip/it83xx/gpio.c')
-rw-r--r--chip/it83xx/gpio.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/chip/it83xx/gpio.c b/chip/it83xx/gpio.c
index 158c267f9f..19a244c93a 100644
--- a/chip/it83xx/gpio.c
+++ b/chip/it83xx/gpio.c
@@ -368,21 +368,28 @@ static void gpio_1p8v_3p3v_sel_by_pin(uint8_t port, uint8_t pin, int sel_1p8v)
*reg_1p8v &= ~sel;
}
-void gpio_set_alternate_function(uint32_t port, uint32_t mask, int func)
+static inline void it83xx_set_alt_func(uint32_t port, uint32_t pin,
+ enum gpio_alternate_func func)
+{
+ /*
+ * If func is not ALT_FUNC_NONE, set for alternate function.
+ * Otherwise, turn the pin into an input as it's default.
+ */
+ if (func != GPIO_ALT_FUNC_NONE)
+ IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) &= ~0xc0;
+ else
+ IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) =
+ (IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) | 0x80) & ~0x40;
+}
+void gpio_set_alternate_function(uint32_t port, uint32_t mask,
+ enum gpio_alternate_func func)
{
uint32_t pin = 0;
/* For each bit high in the mask, set that pin to use alt. func. */
while (mask > 0) {
- /*
- * If func is non-negative, set for alternate function.
- * Otherwise, turn the pin into an input as it's default.
- */
- if ((mask & 1) && func >= 0)
- IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) &= ~0xc0;
- else if ((mask & 1) && func < 0)
- IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) =
- (IT83XX_GPIO_CTRL(CTRL_BASE(port), pin) | 0x80) & ~0x40;
+ if (mask & 1)
+ it83xx_set_alt_func(port, pin, func);
pin++;
mask >>= 1;