1 /* NXP ENET QOS Ethernet MAC Driver
2 *
3 * Copyright 2024 NXP
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #define DT_DRV_COMPAT nxp_enet_qos
9
10 #include <zephyr/drivers/pinctrl.h>
11 #include <zephyr/drivers/ethernet/eth_nxp_enet_qos.h>
12
nxp_enet_qos_init(const struct device * dev)13 int nxp_enet_qos_init(const struct device *dev)
14 {
15 const struct nxp_enet_qos_config *config = dev->config;
16 int ret;
17
18 /* TODO: once NXP reset drivers are created, use that to reset
19 * until then, make sure reset is done in platform init
20 */
21
22 ret = clock_control_on(config->clock_dev, config->clock_subsys);
23 if (ret) {
24 return ret;
25 }
26
27 return pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT);
28 }
29
30 #define NXP_ENET_QOS_INIT(n) \
31 PINCTRL_DT_INST_DEFINE(n); \
32 \
33 static const struct nxp_enet_qos_config enet_qos_##n##_config = { \
34 .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
35 .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
36 .clock_subsys = (void *)DT_INST_CLOCKS_CELL_BY_IDX(n, 0, name), \
37 .base = (enet_qos_t *)DT_INST_REG_ADDR(n), \
38 }; \
39 \
40 /* Init the module before any enet device inits so priority 0 */ \
41 DEVICE_DT_INST_DEFINE(n, nxp_enet_qos_init, NULL, NULL, \
42 &enet_qos_##n##_config, POST_KERNEL, 0, NULL);
43
44 DT_INST_FOREACH_STATUS_OKAY(NXP_ENET_QOS_INIT)
45