From c8d8dce7555bf2995b5a003521b809c985315762 Mon Sep 17 00:00:00 2001 From: Jiafei Pan Date: Thu, 25 Apr 2024 15:15:02 +0800 Subject: [PATCH] drivers: ptp_clock: ptp_enet: use MMIO mapped address Get MMIO mapped address from ENET module driver. Signed-off-by: Jiafei Pan --- drivers/ptp_clock/ptp_clock_nxp_enet.c | 37 +++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/ptp_clock/ptp_clock_nxp_enet.c b/drivers/ptp_clock/ptp_clock_nxp_enet.c index 286c6c91d57..b5e1cbb9bd3 100644 --- a/drivers/ptp_clock/ptp_clock_nxp_enet.c +++ b/drivers/ptp_clock/ptp_clock_nxp_enet.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 NXP + * Copyright 2023-2024 NXP * * Based on a commit to drivers/ethernet/eth_mcux.c which was: * Copyright (c) 2018 Intel Coporation @@ -19,8 +19,8 @@ #include struct ptp_clock_nxp_enet_config { - ENET_Type *base; const struct pinctrl_dev_config *pincfg; + const struct device *module_dev; const struct device *port; const struct device *clock_dev; struct device *clock_subsys; @@ -28,6 +28,7 @@ struct ptp_clock_nxp_enet_config { }; struct ptp_clock_nxp_enet_data { + ENET_Type *base; double clock_ratio; enet_handle_t enet_handle; struct k_mutex ptp_mutex; @@ -36,14 +37,13 @@ struct ptp_clock_nxp_enet_data { static int ptp_clock_nxp_enet_set(const struct device *dev, struct net_ptp_time *tm) { - const struct ptp_clock_nxp_enet_config *config = dev->config; struct ptp_clock_nxp_enet_data *data = dev->data; enet_ptp_time_t enet_time; enet_time.second = tm->second; enet_time.nanosecond = tm->nanosecond; - ENET_Ptp1588SetTimer(config->base, &data->enet_handle, &enet_time); + ENET_Ptp1588SetTimer(data->base, &data->enet_handle, &enet_time); return 0; } @@ -51,11 +51,10 @@ static int ptp_clock_nxp_enet_set(const struct device *dev, static int ptp_clock_nxp_enet_get(const struct device *dev, struct net_ptp_time *tm) { - const struct ptp_clock_nxp_enet_config *config = dev->config; struct ptp_clock_nxp_enet_data *data = dev->data; enet_ptp_time_t enet_time; - ENET_Ptp1588GetTimer(config->base, &data->enet_handle, &enet_time); + ENET_Ptp1588GetTimer(data->base, &data->enet_handle, &enet_time); tm->second = enet_time.second; tm->nanosecond = enet_time.nanosecond; @@ -66,7 +65,7 @@ static int ptp_clock_nxp_enet_get(const struct device *dev, static int ptp_clock_nxp_enet_adjust(const struct device *dev, int increment) { - const struct ptp_clock_nxp_enet_config *config = dev->config; + struct ptp_clock_nxp_enet_data *data = dev->data; int ret = 0; int key; @@ -75,13 +74,13 @@ static int ptp_clock_nxp_enet_adjust(const struct device *dev, ret = -EINVAL; } else { key = irq_lock(); - if (config->base->ATPER != NSEC_PER_SEC) { + if (data->base->ATPER != NSEC_PER_SEC) { ret = -EBUSY; } else { /* Seconds counter is handled by software. Change the * period of one software second to adjust the clock. */ - config->base->ATPER = NSEC_PER_SEC - increment; + data->base->ATPER = NSEC_PER_SEC - increment; ret = 0; } irq_unlock(key); @@ -144,7 +143,7 @@ static int ptp_clock_nxp_enet_rate_adjust(const struct device *dev, k_mutex_lock(&data->ptp_mutex, K_FOREVER); - ENET_Ptp1588AdjustTimer(config->base, corr, mul); + ENET_Ptp1588AdjustTimer(data->base, corr, mul); k_mutex_unlock(&data->ptp_mutex); @@ -167,17 +166,17 @@ void nxp_enet_ptp_clock_callback(const struct device *dev, (void) clock_control_get_rate(config->clock_dev, config->clock_subsys, &enet_ref_pll_rate); - ENET_AddMulticastGroup(config->base, ptp_multicast); - ENET_AddMulticastGroup(config->base, ptp_peer_multicast); + ENET_AddMulticastGroup(data->base, ptp_multicast); + ENET_AddMulticastGroup(data->base, ptp_peer_multicast); /* only for ERRATA_2579 */ ptp_config.channel = kENET_PtpTimerChannel3; ptp_config.ptp1588ClockSrc_Hz = enet_ref_pll_rate; data->clock_ratio = 1.0; - ENET_Ptp1588SetChannelMode(config->base, kENET_PtpTimerChannel3, + ENET_Ptp1588SetChannelMode(data->base, kENET_PtpTimerChannel3, kENET_PtpChannelPulseHighonCompare, true); - ENET_Ptp1588Configure(config->base, &data->enet_handle, + ENET_Ptp1588Configure(data->base, &data->enet_handle, &ptp_config); } @@ -193,6 +192,8 @@ static int ptp_clock_nxp_enet_init(const struct device *port) struct ptp_clock_nxp_enet_data *data = port->data; int ret; + data->base = (ENET_Type *)DEVICE_MMIO_GET(config->module_dev); + ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); if (ret) { return ret; @@ -207,7 +208,6 @@ static int ptp_clock_nxp_enet_init(const struct device *port) static void ptp_clock_nxp_enet_isr(const struct device *dev) { - const struct ptp_clock_nxp_enet_config *config = dev->config; struct ptp_clock_nxp_enet_data *data = dev->data; enet_ptp_timer_channel_t channel; @@ -215,12 +215,12 @@ static void ptp_clock_nxp_enet_isr(const struct device *dev) /* clear channel */ for (channel = kENET_PtpTimerChannel1; channel <= kENET_PtpTimerChannel4; channel++) { - if (ENET_Ptp1588GetChannelStatus(config->base, channel)) { - ENET_Ptp1588ClearChannelStatus(config->base, channel); + if (ENET_Ptp1588GetChannelStatus(data->base, channel)) { + ENET_Ptp1588ClearChannelStatus(data->base, channel); } } - ENET_TimeStampIRQHandler(config->base, &data->enet_handle); + ENET_TimeStampIRQHandler(data->base, &data->enet_handle); irq_unlock(irq_lock_key); } @@ -247,7 +247,6 @@ static const struct ptp_clock_driver_api ptp_clock_nxp_enet_api = { \ static const struct ptp_clock_nxp_enet_config \ ptp_clock_nxp_enet_##n##_config = { \ - .base = (ENET_Type *) DT_REG_ADDR(DT_INST_PARENT(n)), \ .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \ .port = DEVICE_DT_INST_GET(n), \ .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \