drivers: mfd: it8801_altctrl: Add alternate controller for MFD
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>
This commit is contained in:
parent
3de8989852
commit
70739a1e74
9 changed files with 233 additions and 0 deletions
|
|
@ -17,3 +17,4 @@ zephyr_library_sources_ifdef(CONFIG_NXP_LP_FLEXCOMM mfd_nxp_lp_flexcomm.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_MFD_BD8LB600FS mfd_bd8lb600fs.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_TLE9104 mfd_tle9104.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_ITE_IT8801 mfd_ite_it8801.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_MFD_ITE_IT8801_ALTCTRL mfd_it8801_altctrl.c)
|
||||
|
|
|
|||
|
|
@ -9,3 +9,11 @@ config MFD_ITE_IT8801
|
|||
help
|
||||
Enable the ITE IT8801 ioexpander multi-function device driver.
|
||||
This ioexpander provides a GPIO/PWM/Keyboard function via I2C bus.
|
||||
|
||||
if MFD_ITE_IT8801
|
||||
|
||||
config MFD_ITE_IT8801_ALTCTRL
|
||||
bool "ITE IT8801 MFD alternate controller"
|
||||
default y
|
||||
|
||||
endif # MFD_ITE_IT8801
|
||||
|
|
|
|||
66
drivers/mfd/mfd_it8801_altctrl.c
Normal file
66
drivers/mfd/mfd_it8801_altctrl.c
Normal file
|
|
@ -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)
|
||||
12
dts/bindings/mfd/ite,it8801-altctrl.yaml
Normal file
12
dts/bindings/mfd/ite,it8801-altctrl.yaml
Normal file
|
|
@ -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
|
||||
13
dts/bindings/mfd/ite,it8801-mfd-map.yaml
Normal file
13
dts/bindings/mfd/ite,it8801-mfd-map.yaml
Normal file
|
|
@ -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
|
||||
30
dts/riscv/ite/it8801-mfd-gpiocr.dtsi
Normal file
30
dts/riscv/ite/it8801-mfd-gpiocr.dtsi
Normal file
|
|
@ -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>;
|
||||
};
|
||||
};
|
||||
};
|
||||
56
dts/riscv/ite/it8801-mfd-map.dtsi
Normal file
56
dts/riscv/ite/it8801-mfd-map.dtsi
Normal file
|
|
@ -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>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -87,6 +87,36 @@ static const struct it8801_vendor_id_t it8801_id_verify[] = {
|
|||
#define IT8801_PWMMCR_MCR_BREATHING 2
|
||||
#define IT8801_PWMMCR_MCR_ON 3
|
||||
|
||||
/*
|
||||
* For IT8801 MFD alternate function controller
|
||||
*/
|
||||
#define IT8801_DT_INST_MFDCTRL(inst, idx) DT_INST_PHANDLE_BY_IDX(inst, mfdctrl, idx)
|
||||
|
||||
#define IT8801_DT_INST_MFDCTRL_LEN(inst) DT_INST_PROP_LEN_OR(inst, mfdctrl, 0)
|
||||
|
||||
#define IT8801_DEV_MFD(idx, inst) \
|
||||
DEVICE_DT_GET(DT_PHANDLE(IT8801_DT_INST_MFDCTRL(inst, idx), altctrls))
|
||||
#define IT8801_DEV_MFD_PIN(idx, inst) DT_PHA(IT8801_DT_INST_MFDCTRL(inst, idx), altctrls, pin)
|
||||
#define IT8801_DEV_MFD_FUNC(idx, inst) DT_PHA(IT8801_DT_INST_MFDCTRL(inst, idx), altctrls, alt_func)
|
||||
|
||||
#define IT8801_DT_MFD_ITEMS_FUNC(idx, inst) \
|
||||
{ \
|
||||
.gpiocr = IT8801_DEV_MFD(idx, inst), \
|
||||
.pin = IT8801_DEV_MFD_PIN(idx, inst), \
|
||||
.alt_func = IT8801_DEV_MFD_FUNC(idx, inst), \
|
||||
}
|
||||
|
||||
#define IT8801_DT_MFD_ITEMS_LIST(inst) \
|
||||
{LISTIFY(IT8801_DT_INST_MFDCTRL_LEN(inst), \
|
||||
IT8801_DT_MFD_ITEMS_FUNC, (,), \
|
||||
inst) }
|
||||
|
||||
/*
|
||||
* Configure alternate function pin
|
||||
*/
|
||||
int mfd_it8801_configure_pins(const struct i2c_dt_spec *i2c_dev, const struct device *dev,
|
||||
uint8_t pin, uint8_t func);
|
||||
|
||||
/* Define the IT8801 MFD interrupt callback function handler */
|
||||
typedef void (*it8801_callback_handler_t)(const struct device *dev);
|
||||
|
||||
|
|
|
|||
17
include/zephyr/dt-bindings/mfd/mfd_it8801_altctrl.h
Normal file
17
include/zephyr/dt-bindings/mfd/mfd_it8801_altctrl.h
Normal file
|
|
@ -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 a new issue