Browse Source
IT8801 support GPIO alternate function switching. Some GPIO pins can be switched as KSO or PWM function. Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>pull/82508/head
9 changed files with 233 additions and 0 deletions
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ITE Corporation. All Rights Reserved. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
#define DT_DRV_COMPAT ite_it8801_altctrl |
||||
|
||||
#include <zephyr/drivers/i2c.h> |
||||
#include <zephyr/drivers/mfd/mfd_ite_it8801.h> |
||||
#include <zephyr/dt-bindings/mfd/mfd_it8801_altctrl.h> |
||||
|
||||
#include <zephyr/logging/log.h> |
||||
LOG_MODULE_REGISTER(mfd_it8801_altctrl, LOG_LEVEL_ERR); |
||||
|
||||
struct mfd_altfunc_config { |
||||
/* gpiocr register */ |
||||
uint8_t reg_gpiocr; |
||||
}; |
||||
|
||||
int mfd_it8801_configure_pins(const struct i2c_dt_spec *i2c_dev, const struct device *dev, |
||||
uint8_t pin, uint8_t func) |
||||
{ |
||||
const struct mfd_altfunc_config *config = dev->config; |
||||
int ret; |
||||
uint8_t reg_gpiocr = config->reg_gpiocr + pin; |
||||
uint8_t alt_val; |
||||
|
||||
switch (func) { |
||||
case IT8801_ALT_FUNC_1: |
||||
/* Func1: Default GPIO setting */ |
||||
alt_val = IT8801_GPIOAFS_FUN1; |
||||
break; |
||||
case IT8801_ALT_FUNC_2: |
||||
/* Func2: KSO or PWM setting */ |
||||
alt_val = IT8801_GPIOAFS_FUN2; |
||||
break; |
||||
case IT8801_ALT_FUNC_3: |
||||
/* Func3: PWM setting */ |
||||
alt_val = IT8801_GPIOAFS_FUN3; |
||||
break; |
||||
case IT8801_ALT_DEFAULT: |
||||
alt_val = IT8801_GPIOAFS_FUN1; |
||||
break; |
||||
default: |
||||
LOG_ERR("This function is not supported."); |
||||
return -EINVAL; |
||||
} |
||||
|
||||
/* Common settings for alternate function. */ |
||||
ret = i2c_reg_update_byte_dt(i2c_dev, reg_gpiocr, GENMASK(7, 6), alt_val << 6); |
||||
if (ret != 0) { |
||||
LOG_ERR("Failed to update gpiocr (ret %d)", ret); |
||||
return ret; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
#define MFD_IT8801_ALTCTRL_INIT(inst) \ |
||||
static const struct mfd_altfunc_config it8801_mfd_alt_cfg_##inst = { \ |
||||
.reg_gpiocr = DT_INST_REG_ADDR(inst), \ |
||||
}; \ |
||||
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, NULL, &it8801_mfd_alt_cfg_##inst, POST_KERNEL, \ |
||||
CONFIG_MFD_INIT_PRIORITY, NULL); |
||||
DT_INST_FOREACH_STATUS_OKAY(MFD_IT8801_ALTCTRL_INIT) |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2024 ITE Corporation. All Rights Reserved. |
||||
# SPDX-License-Identifier: Apache-2.0 |
||||
|
||||
description: ITE IT8801 GPIO controller node |
||||
|
||||
compatible: "ite,it8801-altctrl" |
||||
|
||||
include: base.yaml |
||||
|
||||
altctrl-cells: |
||||
- pin |
||||
- alt_func |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2024 ITE Corporation. All Rights Reserved. |
||||
# SPDX-License-Identifier: Apache-2.0 |
||||
|
||||
description: ITE IT8801 alternate controller node |
||||
|
||||
compatible: "ite,it8801-mfd-map" |
||||
|
||||
child-binding: |
||||
description: Child node to present the mapping of IT8801 altternate function |
||||
properties: |
||||
altctrls: |
||||
type: phandle-array |
||||
required: true |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
/* |
||||
* Copyright (c) 2024 ITE Corporation. All Rights Reserved. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
/ { |
||||
it8801-mfd { |
||||
#address-cells = <1>; |
||||
#size-cells = <1>; |
||||
|
||||
it8801_gpio0: gpiocr@0a { |
||||
compatible = "ite,it8801-altctrl"; |
||||
reg = <0x0a 8>; |
||||
#altctrl-cells = <2>; |
||||
}; |
||||
|
||||
it8801_gpio1: gpiocr@12 { |
||||
compatible = "ite,it8801-altctrl"; |
||||
reg = <0x12 6>; |
||||
#altctrl-cells = <2>; |
||||
}; |
||||
|
||||
it8801_gpio2: gpiocr@1a { |
||||
compatible = "ite,it8801-altctrl"; |
||||
reg = <0x1a 4>; |
||||
#altctrl-cells = <2>; |
||||
}; |
||||
}; |
||||
}; |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
/* |
||||
* Copyright (c) 2024 ITE Corporation. All Rights Reserved. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
#include <ite/it8801-mfd-gpiocr.dtsi> |
||||
#include <zephyr/dt-bindings/mfd/mfd_it8801_altctrl.h> |
||||
|
||||
|
||||
/ { |
||||
/* GPIO pin mapping to alternate function */ |
||||
it8801-mfd-map { |
||||
compatible = "ite,it8801-mfd-map"; |
||||
|
||||
/* PWM alternate function */ |
||||
pwm1_gp12_default: pwm1_gp12_default { |
||||
altctrls = <&it8801_gpio1 2 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
pwm2_gp13_default: pwm2_gp13_default { |
||||
altctrls = <&it8801_gpio1 3 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
pwm3_gp14_default: pwm3_gp14_default { |
||||
altctrls = <&it8801_gpio1 4 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
pwm4_gp15_default: pwm4_gp15_default { |
||||
altctrls = <&it8801_gpio1 5 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
pwm7_gp20_default: pwm7_gp20_default { |
||||
altctrls = <&it8801_gpio2 0 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
pwm8_gp23_default: pwm8_gp23_default { |
||||
altctrls = <&it8801_gpio2 3 IT8801_ALT_FUNC_3>; |
||||
}; |
||||
pwm9_gp22_default: pwm9_gp22_default { |
||||
altctrls = <&it8801_gpio2 2 IT8801_ALT_FUNC_3>; |
||||
}; |
||||
|
||||
/* Keyboard alternate function */ |
||||
kso18_gp01_default: kso18_gp01_default { |
||||
altctrls = <&it8801_gpio0 1 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
kso19_gp00_default: kso19_gp00_default { |
||||
altctrls = <&it8801_gpio0 0 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
kso20_gp23_default: kso20_gp23_default { |
||||
altctrls = <&it8801_gpio2 3 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
kso21_gp22_default: kso21_gp22_default { |
||||
altctrls = <&it8801_gpio2 2 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
kso22_gp21_default: kso22_gp21_default { |
||||
altctrls = <&it8801_gpio2 1 IT8801_ALT_FUNC_2>; |
||||
}; |
||||
}; |
||||
}; |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ITE Technology Corporation. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_MFD_IT8801_ALTCTRL_H_ |
||||
#define ZEPHYR_INCLUDE_DT_BINDINGS_MFD_IT8801_ALTCTRL_H_ |
||||
|
||||
/**
|
||||
* @brief PIN alternate function. |
||||
*/ |
||||
#define IT8801_ALT_FUNC_1 0U |
||||
#define IT8801_ALT_FUNC_2 1U |
||||
#define IT8801_ALT_FUNC_3 2U |
||||
#define IT8801_ALT_DEFAULT 3U |
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_MFD_IT8801_ALTCTRL_H_ */ |
Loading…
Reference in new issue