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:
Mulin Chao 2022-02-21 19:38:22 -08:00 committed by Maureen Helm
commit 22f9036577
4 changed files with 19 additions and 14 deletions

View file

@ -103,7 +103,8 @@
&tach1 {
status = "okay";
pinctrl-0 = <&alt3_ta1_sl1>; /* Use TA1_SL1 (PIN40) as input pin */
pinctrl-0 = <&ta1_1_in_gp40>;
pinctrl-names = "default";
port = <NPCX_TACH_PORT_A>; /* port-A is selected */
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
pulses-per-round = <1>; /* number of pulses per round of encoder */

View file

@ -116,7 +116,8 @@
&tach1 {
status = "okay";
pinctrl-0 = <&alt3_ta1_sl1>; /* Use TA1_SL1 (PIN40) as input pin */
pinctrl-0 = <&ta1_1_in_gp40>;
pinctrl-names = "default";
port = <NPCX_TACH_PORT_A>; /* port-A is selected */
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
pulses-per-round = <1>; /* number of pulses per round of encoder */

View file

@ -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; \

View file

@ -5,7 +5,7 @@ description: Nuvoton, NPCX-Tachometer node
compatible: "nuvoton,npcx-tach"
include: tach.yaml
include: [tach.yaml, pinctrl-device.yaml]
properties:
reg:
@ -13,9 +13,9 @@ properties:
clocks:
required: true
pinctrl-0:
type: phandles
required: false
description: configurations of pinmux controllers in tachometers
required: true
pinctrl-names:
required: true
sample-clk:
type: int
required: false