drivers: sensor: npcx_tach: add pinctrl driver support
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in npcx tachometer driver. Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
This commit is contained in:
parent
95f6dc6c35
commit
22f9036577
4 changed files with 19 additions and 14 deletions
|
@ -42,6 +42,7 @@
|
|||
#include <errno.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/dt-bindings/sensor/npcx_tach.h>
|
||||
#include <soc.h>
|
||||
|
@ -55,15 +56,14 @@ struct tach_npcx_config {
|
|||
uintptr_t base;
|
||||
/* clock configuration */
|
||||
struct npcx_clk_cfg clk_cfg;
|
||||
/* pinmux configuration */
|
||||
const uint8_t alts_size;
|
||||
const struct npcx_alt *alts_list;
|
||||
/* sampling clock frequency of tachometer */
|
||||
uint32_t sample_clk;
|
||||
/* selected port of tachometer */
|
||||
int port;
|
||||
/* number of pulses (holes) per round of tachometer's input (encoder) */
|
||||
int pulses_per_round;
|
||||
/* pinmux configuration */
|
||||
const struct pinctrl_dev_config *pcfg;
|
||||
};
|
||||
|
||||
/* Driver data */
|
||||
|
@ -332,7 +332,12 @@ static int tach_npcx_init(const struct device *dev)
|
|||
}
|
||||
|
||||
/* Configure pin-mux for tachometer device */
|
||||
npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1);
|
||||
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Tacho pinctrl setup failed (%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Configure tachometer and its operate freq. */
|
||||
ret = tach_npcx_configure(dev);
|
||||
|
@ -359,17 +364,15 @@ static const struct sensor_driver_api tach_npcx_driver_api = {
|
|||
};
|
||||
|
||||
#define NPCX_TACH_INIT(inst) \
|
||||
static const struct npcx_alt tach_alts##inst[] = \
|
||||
NPCX_DT_ALT_ITEMS_LIST(inst); \
|
||||
PINCTRL_DT_INST_DEFINE(inst); \
|
||||
\
|
||||
static const struct tach_npcx_config tach_cfg_##inst = { \
|
||||
.base = DT_INST_REG_ADDR(inst), \
|
||||
.clk_cfg = NPCX_DT_CLK_CFG_ITEM(inst), \
|
||||
.alts_size = ARRAY_SIZE(tach_alts##inst), \
|
||||
.alts_list = tach_alts##inst, \
|
||||
.sample_clk = DT_INST_PROP(inst, sample_clk), \
|
||||
.port = DT_INST_PROP(inst, port), \
|
||||
.pulses_per_round = DT_INST_PROP(inst, pulses_per_round), \
|
||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
|
||||
}; \
|
||||
\
|
||||
static struct tach_npcx_data tach_data_##inst; \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue