drivers: PS/2: npcx: Replace device_get_binding with DEVICE_DT_GET

Replace device_get_binding() with DEVICE_DT_GET to obtain the PS/2
controller and clock control device objects. It helps to improve the
efficiency for driver initialization as DEVICE_DT_GET is processed
at the link time rather than run time.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
This commit is contained in:
Jun Lin 2021-06-28 11:20:01 +08:00 committed by Anas Nashif
commit 55f21ab846
2 changed files with 19 additions and 37 deletions

View file

@ -32,58 +32,48 @@ struct ps2_npcx_ch_config {
const struct npcx_alt *alts_list; const struct npcx_alt *alts_list;
/* Indicate the channel's number of the PS/2 channel device */ /* Indicate the channel's number of the PS/2 channel device */
uint8_t channel_id; uint8_t channel_id;
};
/* Driver data */
struct ps2_npcx_ch_data {
const struct device *ps2_ctrl; const struct device *ps2_ctrl;
}; };
/* Driver convenience defines */ /* Driver convenience defines */
#define DRV_CONFIG(dev) ((const struct ps2_npcx_ch_config *)(dev)->config) #define DRV_CONFIG(dev) ((const struct ps2_npcx_ch_config *)(dev)->config)
#define DRV_DATA(dev) ((struct ps2_npcx_ch_data *)(dev)->data)
/* PS/2 api functions */ /* PS/2 api functions */
static int ps2_npcx_ch_configure(const struct device *dev, static int ps2_npcx_ch_configure(const struct device *dev,
ps2_callback_t callback_isr) ps2_callback_t callback_isr)
{ {
const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev);
struct ps2_npcx_ch_data *const data = DRV_DATA(dev);
int ret; int ret;
ret = ps2_npcx_ctrl_configure(data->ps2_ctrl, config->channel_id, ret = ps2_npcx_ctrl_configure(config->ps2_ctrl, config->channel_id,
callback_isr); callback_isr);
if (ret != 0) if (ret != 0)
return ret; return ret;
return ps2_npcx_ctrl_enable_interface(data->ps2_ctrl, return ps2_npcx_ctrl_enable_interface(config->ps2_ctrl,
config->channel_id, 1); config->channel_id, 1);
} }
static int ps2_npcx_ch_write(const struct device *dev, uint8_t value) static int ps2_npcx_ch_write(const struct device *dev, uint8_t value)
{ {
const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev);
struct ps2_npcx_ch_data *const data = DRV_DATA(dev);
return ps2_npcx_ctrl_write(data->ps2_ctrl, config->channel_id, value); return ps2_npcx_ctrl_write(config->ps2_ctrl, config->channel_id, value);
} }
static int ps2_npcx_ch_enable_interface(const struct device *dev) static int ps2_npcx_ch_enable_interface(const struct device *dev)
{ {
const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev);
struct ps2_npcx_ch_data *const data = DRV_DATA(dev);
return ps2_npcx_ctrl_enable_interface(data->ps2_ctrl, return ps2_npcx_ctrl_enable_interface(config->ps2_ctrl,
config->channel_id, 1); config->channel_id, 1);
} }
static int ps2_npcx_ch_inhibit_interface(const struct device *dev) static int ps2_npcx_ch_inhibit_interface(const struct device *dev)
{ {
const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev);
struct ps2_npcx_ch_data *const data = DRV_DATA(dev);
return ps2_npcx_ctrl_enable_interface(data->ps2_ctrl, return ps2_npcx_ctrl_enable_interface(config->ps2_ctrl,
config->channel_id, 0); config->channel_id, 0);
} }
@ -92,6 +82,11 @@ static int ps2_npcx_channel_init(const struct device *dev)
{ {
const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ch_config *const config = DRV_CONFIG(dev);
if (!device_is_ready(config->ps2_ctrl)) {
LOG_ERR("%s device not ready", config->ps2_ctrl->name);
return -ENODEV;
}
/* Configure pin-mux for PS/2 device */ /* Configure pin-mux for PS/2 device */
npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1); npcx_pinctrl_mux_configure(config->alts_list, config->alts_size, 1);
@ -107,21 +102,7 @@ static const struct ps2_driver_api ps2_channel_npcx_driver_api = {
}; };
/* PS/2 channel initialization macro functions */ /* PS/2 channel initialization macro functions */
#define NPCX_PS2_CHANNEL_INIT_FUNC(inst) _CONCAT(ps2_npcx_channel_init_, inst)
#define NPCX_PS2_CHANNEL_INIT_FUNC_DECL(inst) \
static int ps2_npcx_channel_init_##inst(const struct device *dev)
#define NPCX_PS2_CHANNEL_INIT_FUNC_IMPL(inst) \
static int ps2_npcx_channel_init_##inst(const struct device *dev) \
{ \
struct ps2_npcx_ch_data *const data = DRV_DATA(dev); \
\
data->ps2_ctrl = device_get_binding(DT_INST_BUS_LABEL(inst)); \
return ps2_npcx_channel_init(dev); \
}
#define NPCX_PS2_CHANNEL_INIT(inst) \ #define NPCX_PS2_CHANNEL_INIT(inst) \
NPCX_PS2_CHANNEL_INIT_FUNC_DECL(inst); \
\ \
static const struct npcx_alt ps2_channel_alts##inst[] = \ static const struct npcx_alt ps2_channel_alts##inst[] = \
NPCX_DT_ALT_ITEMS_LIST(inst); \ NPCX_DT_ALT_ITEMS_LIST(inst); \
@ -130,17 +111,13 @@ static const struct ps2_driver_api ps2_channel_npcx_driver_api = {
.channel_id = DT_INST_PROP(inst, channel), \ .channel_id = DT_INST_PROP(inst, channel), \
.alts_size = ARRAY_SIZE(ps2_channel_alts##inst), \ .alts_size = ARRAY_SIZE(ps2_channel_alts##inst), \
.alts_list = ps2_channel_alts##inst, \ .alts_list = ps2_channel_alts##inst, \
.ps2_ctrl = DEVICE_DT_GET(DT_PARENT(DT_DRV_INST(inst))), \
}; \ }; \
\ \
static struct ps2_npcx_ch_data ps2_npcx_ch_data_##inst; \ DEVICE_DT_INST_DEFINE(inst, ps2_npcx_channel_init, NULL, NULL, \
\
DEVICE_DT_INST_DEFINE(inst, NPCX_PS2_CHANNEL_INIT_FUNC(inst), NULL, \
&ps2_npcx_ch_data_##inst, \
&ps2_npcx_ch_cfg_##inst, POST_KERNEL, \ &ps2_npcx_ch_cfg_##inst, POST_KERNEL, \
CONFIG_PS2_CHANNEL_INIT_PRIORITY, \ CONFIG_PS2_CHANNEL_INIT_PRIORITY, \
&ps2_channel_npcx_driver_api); \ &ps2_channel_npcx_driver_api);
\
NPCX_PS2_CHANNEL_INIT_FUNC_IMPL(inst)
DT_INST_FOREACH_STATUS_OKAY(NPCX_PS2_CHANNEL_INIT) DT_INST_FOREACH_STATUS_OKAY(NPCX_PS2_CHANNEL_INIT)

View file

@ -329,9 +329,14 @@ static int ps2_npcx_ctrl_init(const struct device *dev)
const struct ps2_npcx_ctrl_config *const config = DRV_CONFIG(dev); const struct ps2_npcx_ctrl_config *const config = DRV_CONFIG(dev);
struct ps2_npcx_ctrl_data *const data = DRV_DATA(dev); struct ps2_npcx_ctrl_data *const data = DRV_DATA(dev);
struct ps2_reg *const inst = HAL_PS2_INSTANCE(dev); struct ps2_reg *const inst = HAL_PS2_INSTANCE(dev);
const struct device *clk_dev = device_get_binding(NPCX_CLK_CTRL_NAME); const struct device *clk_dev = DEVICE_DT_GET(NPCX_CLK_CTRL_NODE);
int ret; int ret;
if (!device_is_ready(clk_dev)) {
LOG_ERR("%s device not ready", clk_dev->name);
return -ENODEV;
}
/* Turn on PS/2 controller device clock */ /* Turn on PS/2 controller device clock */
ret = clock_control_on(clk_dev, ret = clock_control_on(clk_dev,
(clock_control_subsys_t *)&config->clk_cfg); (clock_control_subsys_t *)&config->clk_cfg);