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
|
@ -103,7 +103,8 @@
|
||||||
|
|
||||||
&tach1 {
|
&tach1 {
|
||||||
status = "okay";
|
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 */
|
port = <NPCX_TACH_PORT_A>; /* port-A is selected */
|
||||||
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
|
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
|
||||||
pulses-per-round = <1>; /* number of pulses per round of encoder */
|
pulses-per-round = <1>; /* number of pulses per round of encoder */
|
||||||
|
|
|
@ -116,7 +116,8 @@
|
||||||
|
|
||||||
&tach1 {
|
&tach1 {
|
||||||
status = "okay";
|
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 */
|
port = <NPCX_TACH_PORT_A>; /* port-A is selected */
|
||||||
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
|
sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */
|
||||||
pulses-per-round = <1>; /* number of pulses per round of encoder */
|
pulses-per-round = <1>; /* number of pulses per round of encoder */
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/drivers/clock_control.h>
|
#include <zephyr/drivers/clock_control.h>
|
||||||
|
#include <zephyr/drivers/pinctrl.h>
|
||||||
#include <zephyr/drivers/sensor.h>
|
#include <zephyr/drivers/sensor.h>
|
||||||
#include <zephyr/dt-bindings/sensor/npcx_tach.h>
|
#include <zephyr/dt-bindings/sensor/npcx_tach.h>
|
||||||
#include <soc.h>
|
#include <soc.h>
|
||||||
|
@ -55,15 +56,14 @@ struct tach_npcx_config {
|
||||||
uintptr_t base;
|
uintptr_t base;
|
||||||
/* clock configuration */
|
/* clock configuration */
|
||||||
struct npcx_clk_cfg clk_cfg;
|
struct npcx_clk_cfg clk_cfg;
|
||||||
/* pinmux configuration */
|
|
||||||
const uint8_t alts_size;
|
|
||||||
const struct npcx_alt *alts_list;
|
|
||||||
/* sampling clock frequency of tachometer */
|
/* sampling clock frequency of tachometer */
|
||||||
uint32_t sample_clk;
|
uint32_t sample_clk;
|
||||||
/* selected port of tachometer */
|
/* selected port of tachometer */
|
||||||
int port;
|
int port;
|
||||||
/* number of pulses (holes) per round of tachometer's input (encoder) */
|
/* number of pulses (holes) per round of tachometer's input (encoder) */
|
||||||
int pulses_per_round;
|
int pulses_per_round;
|
||||||
|
/* pinmux configuration */
|
||||||
|
const struct pinctrl_dev_config *pcfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Driver data */
|
/* Driver data */
|
||||||
|
@ -332,7 +332,12 @@ static int tach_npcx_init(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configure pin-mux for tachometer device */
|
/* 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. */
|
/* Configure tachometer and its operate freq. */
|
||||||
ret = tach_npcx_configure(dev);
|
ret = tach_npcx_configure(dev);
|
||||||
|
@ -359,17 +364,15 @@ static const struct sensor_driver_api tach_npcx_driver_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NPCX_TACH_INIT(inst) \
|
#define NPCX_TACH_INIT(inst) \
|
||||||
static const struct npcx_alt tach_alts##inst[] = \
|
PINCTRL_DT_INST_DEFINE(inst); \
|
||||||
NPCX_DT_ALT_ITEMS_LIST(inst); \
|
|
||||||
\
|
\
|
||||||
static const struct tach_npcx_config tach_cfg_##inst = { \
|
static const struct tach_npcx_config tach_cfg_##inst = { \
|
||||||
.base = DT_INST_REG_ADDR(inst), \
|
.base = DT_INST_REG_ADDR(inst), \
|
||||||
.clk_cfg = NPCX_DT_CLK_CFG_ITEM(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), \
|
.sample_clk = DT_INST_PROP(inst, sample_clk), \
|
||||||
.port = DT_INST_PROP(inst, port), \
|
.port = DT_INST_PROP(inst, port), \
|
||||||
.pulses_per_round = DT_INST_PROP(inst, pulses_per_round), \
|
.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; \
|
static struct tach_npcx_data tach_data_##inst; \
|
||||||
|
|
|
@ -5,7 +5,7 @@ description: Nuvoton, NPCX-Tachometer node
|
||||||
|
|
||||||
compatible: "nuvoton,npcx-tach"
|
compatible: "nuvoton,npcx-tach"
|
||||||
|
|
||||||
include: tach.yaml
|
include: [tach.yaml, pinctrl-device.yaml]
|
||||||
|
|
||||||
properties:
|
properties:
|
||||||
reg:
|
reg:
|
||||||
|
@ -13,9 +13,9 @@ properties:
|
||||||
clocks:
|
clocks:
|
||||||
required: true
|
required: true
|
||||||
pinctrl-0:
|
pinctrl-0:
|
||||||
type: phandles
|
required: true
|
||||||
required: false
|
pinctrl-names:
|
||||||
description: configurations of pinmux controllers in tachometers
|
required: true
|
||||||
sample-clk:
|
sample-clk:
|
||||||
type: int
|
type: int
|
||||||
required: false
|
required: false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue