| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From f7ed64503d5e27571833b76acee721d00448fdec Mon Sep 17 00:00:00 2001 |
| 2 | From: Yangbo Lu <yangbo.lu@nxp.com> |
| 3 | Date: Mon, 2 Sep 2019 15:33:16 +0800 |
| 4 | Subject: [PATCH] LF-183 sdk_fman: add an option for RTC (1588 timer) |
| 5 | initialization and APIs |
| 6 | |
| 7 | The RTC (1588 timer) could be managed by either ptp_qoriq driver |
| 8 | or sdk_fman RTC driver. So add an option for sdk_fman RTC |
| 9 | (1588 timer) initialization and APIs, so that user could select |
| 10 | it or not. |
| 11 | |
| 12 | Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com> |
| 13 | --- |
| 14 | drivers/net/ethernet/freescale/sdk_fman/Kconfig | 9 +++++++++ |
| 15 | .../freescale/sdk_fman/Peripherals/FM/Makefile | 3 ++- |
| 16 | .../freescale/sdk_fman/Peripherals/FM/fm.c | 4 ++++ |
| 17 | .../sdk_fman/src/inc/wrapper/lnxwrp_fsl_fman.h | 22 ++++++++++++++++++++++ |
| 18 | .../freescale/sdk_fman/src/wrapper/lnxwrp_fm.c | 18 +++++++++++++----- |
| 19 | 5 files changed, 50 insertions(+), 6 deletions(-) |
| 20 | |
| 21 | --- a/drivers/net/ethernet/freescale/sdk_fman/Kconfig |
| 22 | +++ b/drivers/net/ethernet/freescale/sdk_fman/Kconfig |
| 23 | @@ -49,6 +49,15 @@ config FMAN_V3L |
| 24 | endchoice |
| 25 | endmenu |
| 26 | |
| 27 | +config FSL_SDK_FMAN_RTC_API |
| 28 | + bool "FMan RTC (1588 timer) APIs" |
| 29 | + default n |
| 30 | + help |
| 31 | + This option enables RTC (1588 timer) initialization and |
| 32 | + APIs support. The ptp_qoriq driver is not available if |
| 33 | + it is selected for RTC (1588 timer). Neither of them |
| 34 | + were not able to be used together. |
| 35 | + |
| 36 | config FMAN_MIB_CNT_OVF_IRQ_EN |
| 37 | bool "Enable the dTSEC MIB counters overflow interrupt" |
| 38 | default n |
| 39 | --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Makefile |
| 40 | +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/Makefile |
| 41 | @@ -19,5 +19,6 @@ obj-y += Pcd/ |
| 42 | obj-y += SP/ |
| 43 | obj-y += Port/ |
| 44 | obj-y += HC/ |
| 45 | -obj-y += Rtc/ |
| 46 | obj-y += MACSEC/ |
| 47 | + |
| 48 | +obj-$(CONFIG_FSL_SDK_FMAN_RTC_API) += Rtc/ |
| 49 | --- a/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c |
| 50 | +++ b/drivers/net/ethernet/freescale/sdk_fman/Peripherals/FM/fm.c |
| 51 | @@ -602,8 +602,10 @@ do { |
| 52 | FM_G_CALL_10G_MAC_ISR(0); |
| 53 | if (pending & INTR_EN_10G_MAC1) |
| 54 | FM_G_CALL_10G_MAC_ISR(1); |
| 55 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 56 | if (pending & INTR_EN_TMR) |
| 57 | p_Fm->intrMng[e_FM_EV_TMR].f_Isr(p_Fm->intrMng[e_FM_EV_TMR].h_SrcHandle); |
| 58 | +#endif |
| 59 | } |
| 60 | |
| 61 | #if (DPAA_VERSION >= 11) |
| 62 | @@ -4318,8 +4320,10 @@ void FM_EventIsr(t_Handle h_Fm) |
| 63 | p_Fm->intrMng[e_FM_EV_PRS].f_Isr(p_Fm->intrMng[e_FM_EV_PRS].h_SrcHandle); |
| 64 | if (pending & INTR_EN_PLCR) |
| 65 | p_Fm->intrMng[e_FM_EV_PLCR].f_Isr(p_Fm->intrMng[e_FM_EV_PLCR].h_SrcHandle); |
| 66 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 67 | if (pending & INTR_EN_TMR) |
| 68 | p_Fm->intrMng[e_FM_EV_TMR].f_Isr(p_Fm->intrMng[e_FM_EV_TMR].h_SrcHandle); |
| 69 | +#endif |
| 70 | |
| 71 | /* MAC events may belong to different partitions */ |
| 72 | if (pending & INTR_EN_1G_MAC0) |
| 73 | --- a/drivers/net/ethernet/freescale/sdk_fman/src/inc/wrapper/lnxwrp_fsl_fman.h |
| 74 | +++ b/drivers/net/ethernet/freescale/sdk_fman/src/inc/wrapper/lnxwrp_fsl_fman.h |
| 75 | @@ -802,6 +802,7 @@ int fm_mac_set_rx_pause_frames( |
| 76 | int fm_mac_set_tx_pause_frames(struct fm_mac_dev *fm_mac_dev, |
| 77 | bool en); |
| 78 | |
| 79 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 80 | int fm_rtc_enable(struct fm *fm_dev); |
| 81 | |
| 82 | int fm_rtc_disable(struct fm *fm_dev); |
| 83 | @@ -819,6 +820,27 @@ int fm_rtc_set_alarm(struct fm *fm_dev, |
| 84 | |
| 85 | int fm_rtc_set_fiper(struct fm *fm_dev, uint32_t id, |
| 86 | uint64_t fiper); |
| 87 | +#else |
| 88 | +static inline int fm_rtc_enable(struct fm *fm_dev) { return 0; } |
| 89 | + |
| 90 | +static inline int fm_rtc_disable(struct fm *fm_dev) { return 0; } |
| 91 | + |
| 92 | +static inline int fm_rtc_get_cnt(struct fm *fm_dev, uint64_t *ts) { return 0; } |
| 93 | + |
| 94 | +static inline int fm_rtc_set_cnt(struct fm *fm_dev, uint64_t ts) { return 0; } |
| 95 | + |
| 96 | +static inline int fm_rtc_get_drift(struct fm *fm_dev, uint32_t *drift) |
| 97 | +{ return 0; } |
| 98 | + |
| 99 | +static inline int fm_rtc_set_drift(struct fm *fm_dev, uint32_t drift) |
| 100 | +{ return 0; } |
| 101 | + |
| 102 | +static inline int fm_rtc_set_alarm(struct fm *fm_dev, uint32_t id, |
| 103 | + uint64_t time) { return 0; } |
| 104 | + |
| 105 | +static inline int fm_rtc_set_fiper(struct fm *fm_dev, uint32_t id, |
| 106 | + uint64_t fiper) { return 0; } |
| 107 | +#endif |
| 108 | |
| 109 | int fm_mac_set_wol(struct fm_port *port, struct fm_mac_dev *fm_mac_dev, |
| 110 | bool en); |
| 111 | --- a/drivers/net/ethernet/freescale/sdk_fman/src/wrapper/lnxwrp_fm.c |
| 112 | +++ b/drivers/net/ethernet/freescale/sdk_fman/src/wrapper/lnxwrp_fm.c |
| 113 | @@ -695,11 +695,7 @@ static t_LnxWrpFmDev * ReadFmDevTreeNode |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | -/* DPAA PTP timer was managed by ptp_qoriq driver in drivers/ptp/. |
| 118 | - * We will no longer manage it in sdk_fman driver and use related |
| 119 | - * APIs. |
| 120 | - */ |
| 121 | -#if 0 |
| 122 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 123 | /* Get the RTC base address and size */ |
| 124 | memset(ids, 0, sizeof(ids)); |
| 125 | if (WARN_ON(strlen("ptp-timer") >= sizeof(ids[0].name))) |
| 126 | @@ -941,6 +937,7 @@ static t_Error ConfigureFmDev(t_LnxWrpFm |
| 127 | if (SYS_RegisterIoMap((uint64_t)p_LnxWrpFmDev->fmMuramBaseAddr, (uint64_t)p_LnxWrpFmDev->fmMuramPhysBaseAddr, p_LnxWrpFmDev->fmMuramMemSize) != E_OK) |
| 128 | RETURN_ERROR(MAJOR, E_INVALID_STATE, ("FM MURAM memory map")); |
| 129 | |
| 130 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 131 | if (p_LnxWrpFmDev->fmRtcPhysBaseAddr) |
| 132 | { |
| 133 | dev_res = __devm_request_region(p_LnxWrpFmDev->dev, p_LnxWrpFmDev->res, p_LnxWrpFmDev->fmRtcPhysBaseAddr, p_LnxWrpFmDev->fmRtcMemSize, "fman-ptp-timer"); |
| 134 | @@ -954,6 +951,7 @@ static t_Error ConfigureFmDev(t_LnxWrpFm |
| 135 | if (SYS_RegisterIoMap((uint64_t)p_LnxWrpFmDev->fmRtcBaseAddr, (uint64_t)p_LnxWrpFmDev->fmRtcPhysBaseAddr, p_LnxWrpFmDev->fmRtcMemSize) != E_OK) |
| 136 | RETURN_ERROR(MAJOR, E_INVALID_STATE, ("FM-RTC memory map")); |
| 137 | } |
| 138 | +#endif |
| 139 | |
| 140 | #if (DPAA_VERSION >= 11) |
| 141 | if (p_LnxWrpFmDev->fmVspPhysBaseAddr) { |
| 142 | @@ -1187,6 +1185,7 @@ static t_Error InitFmDev(t_LnxWrpFmDev |
| 143 | * FM_SetException(p_LnxWrpFmDev->h_Dev,e_FM_EX_MURAM_ECC,FALSE);*/ |
| 144 | } |
| 145 | |
| 146 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 147 | if (p_LnxWrpFmDev->fmRtcBaseAddr) |
| 148 | { |
| 149 | t_FmRtcParams fmRtcParam; |
| 150 | @@ -1205,6 +1204,7 @@ static t_Error InitFmDev(t_LnxWrpFmDev |
| 151 | if (FM_RTC_Init(p_LnxWrpFmDev->h_RtcDev) != E_OK) |
| 152 | RETURN_ERROR(MAJOR, E_INVALID_STATE, ("FM-RTC")); |
| 153 | } |
| 154 | +#endif |
| 155 | |
| 156 | return E_OK; |
| 157 | } |
| 158 | @@ -1219,8 +1219,10 @@ static void FreeFmDev(t_LnxWrpFmDev *p_ |
| 159 | |
| 160 | FreeFmPcdDev(p_LnxWrpFmDev); |
| 161 | |
| 162 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 163 | if (p_LnxWrpFmDev->h_RtcDev) |
| 164 | FM_RTC_Free(p_LnxWrpFmDev->h_RtcDev); |
| 165 | +#endif |
| 166 | |
| 167 | if (p_LnxWrpFmDev->h_Dev) |
| 168 | FM_Free(p_LnxWrpFmDev->h_Dev); |
| 169 | @@ -1228,12 +1230,14 @@ static void FreeFmDev(t_LnxWrpFmDev *p_ |
| 170 | if (p_LnxWrpFmDev->h_MuramDev) |
| 171 | FM_MURAM_Free(p_LnxWrpFmDev->h_MuramDev); |
| 172 | |
| 173 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 174 | if (p_LnxWrpFmDev->fmRtcBaseAddr) |
| 175 | { |
| 176 | SYS_UnregisterIoMap(p_LnxWrpFmDev->fmRtcBaseAddr); |
| 177 | devm_iounmap(p_LnxWrpFmDev->dev, UINT_TO_PTR(p_LnxWrpFmDev->fmRtcBaseAddr)); |
| 178 | __devm_release_region(p_LnxWrpFmDev->dev, p_LnxWrpFmDev->res, p_LnxWrpFmDev->fmRtcPhysBaseAddr, p_LnxWrpFmDev->fmRtcMemSize); |
| 179 | } |
| 180 | +#endif |
| 181 | SYS_UnregisterIoMap(p_LnxWrpFmDev->fmMuramBaseAddr); |
| 182 | devm_iounmap(p_LnxWrpFmDev->dev, UINT_TO_PTR(p_LnxWrpFmDev->fmMuramBaseAddr)); |
| 183 | __devm_release_region(p_LnxWrpFmDev->dev, p_LnxWrpFmDev->res, p_LnxWrpFmDev->fmMuramPhysBaseAddr, p_LnxWrpFmDev->fmMuramMemSize); |
| 184 | @@ -1463,6 +1467,7 @@ void * fm_get_handle(struct fm *fm) |
| 185 | } |
| 186 | EXPORT_SYMBOL(fm_get_handle); |
| 187 | |
| 188 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 189 | void * fm_get_rtc_handle(struct fm *fm) |
| 190 | { |
| 191 | t_LnxWrpFmDev *p_LnxWrpFmDev = (t_LnxWrpFmDev*)fm; |
| 192 | @@ -1470,6 +1475,7 @@ void * fm_get_rtc_handle(struct fm *fm) |
| 193 | return (void *)p_LnxWrpFmDev->h_RtcDev; |
| 194 | } |
| 195 | EXPORT_SYMBOL(fm_get_rtc_handle); |
| 196 | +#endif |
| 197 | |
| 198 | struct fm_port * fm_port_bind (struct device *fm_port_dev) |
| 199 | { |
| 200 | @@ -2053,6 +2059,7 @@ int fm_mac_set_tx_pause_frames(struct fm |
| 201 | #endif |
| 202 | EXPORT_SYMBOL(fm_mac_set_tx_pause_frames); |
| 203 | |
| 204 | +#ifdef CONFIG_FSL_SDK_FMAN_RTC_API |
| 205 | int fm_rtc_enable(struct fm *fm_dev) |
| 206 | { |
| 207 | int _errno; |
| 208 | @@ -2209,6 +2216,7 @@ int fm_rtc_disable_interrupt(struct fm * |
| 209 | } |
| 210 | EXPORT_SYMBOL(fm_rtc_disable_interrupt); |
| 211 | #endif |
| 212 | +#endif /* CONFIG_FSL_SDK_FMAN_RTC_API */ |
| 213 | |
| 214 | int fm_mac_set_wol(struct fm_port *port, struct fm_mac_dev *fm_mac_dev, bool en) |
| 215 | { |