ITE: drivers/pwm: Use pinctrl instead of pinmux driver

Use pinctrl instead of pinmux driver.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
This commit is contained in:
Tim Lin 2022-03-25 16:59:22 +08:00 committed by Carles Cufí
commit 8ecd5bb2f7
6 changed files with 49 additions and 60 deletions

View file

@ -8,7 +8,7 @@
#include <device.h>
#include <drivers/pwm.h>
#include <drivers/pinmux.h>
#include <drivers/pinctrl.h>
#include <dt-bindings/pwm/it8xxx2_pwm.h>
#include <errno.h>
#include <kernel.h>
@ -23,16 +23,6 @@ LOG_MODULE_REGISTER(pwm_ite_it8xxx2, CONFIG_PWM_LOG_LEVEL);
#define PWM_FREQ EC_FREQ
#define PCSSG_MASK 0x3
/* Device config */
struct pwm_alt_cfg {
/* Pinmux control device structure */
const struct device *pinctrls;
/* GPIO pin */
uint8_t pin;
/* Alternate function */
uint8_t alt_fun;
};
struct pwm_it8xxx2_cfg {
/* PWM channel duty cycle register */
uintptr_t reg_dcr;
@ -48,8 +38,8 @@ struct pwm_it8xxx2_cfg {
struct pwm_it8xxx2_regs *base;
/* Select PWM prescaler that output to PWM channel */
int prs_sel;
/* PWM alternate configuration list */
const struct pwm_alt_cfg *alt_list;
/* PWM alternate configuration */
const struct pinctrl_dev_config *pcfg;
};
static void pwm_enable(const struct device *dev, int enabled)
@ -216,6 +206,7 @@ static int pwm_it8xxx2_init(const struct device *dev)
int prs_sel = config->prs_sel;
int pcssg_shift;
int pcssg_mask;
int status;
/* PWM channel clock source gating before configuring */
pwm_enable(dev, 0);
@ -244,9 +235,12 @@ static int pwm_it8xxx2_init(const struct device *dev)
inst->ZTIER |= IT8XXX2_PWM_PCCE;
/* Set alternate mode of PWM pin */
pinmux_pin_set(config->alt_list->pinctrls,
config->alt_list->pin,
config->alt_list->alt_fun);
status = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
if (status < 0) {
LOG_ERR("Failed to configure PWM pins");
return status;
}
return 0;
}
@ -257,9 +251,7 @@ static const struct pwm_driver_api pwm_it8xxx2_api = {
/* Device Instance */
#define PWM_IT8XXX2_INIT(inst) \
static const struct pwm_alt_cfg \
pwm_alt_##inst[DT_INST_NUM_PINCTRLS_BY_IDX(inst, 0)] = \
IT8XXX2_DT_ALT_ITEMS_LIST(inst); \
PINCTRL_DT_INST_DEFINE(inst); \
\
static const struct pwm_it8xxx2_cfg pwm_it8xxx2_cfg_##inst = { \
.reg_dcr = DT_INST_REG_ADDR_BY_IDX(inst, 0), \
@ -269,7 +261,7 @@ static const struct pwm_driver_api pwm_it8xxx2_api = {
.channel = DT_PROP(DT_INST(inst, ite_it8xxx2_pwm), channel), \
.base = (struct pwm_it8xxx2_regs *) DT_REG_ADDR(DT_NODELABEL(prs)), \
.prs_sel = DT_PROP(DT_INST(inst, ite_it8xxx2_pwm), prescaler_cx), \
.alt_list = pwm_alt_##inst, \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, \