I am backporting the Zephyr nxp_hpdac driver to Zephyr 4.3 for an MCXN947-based board.
The upstream driver does not use a device init callback. However, on Zephyr 4.3 the HPDAC does not work correctly unless I explicitly initialize the DAC2 clock, SPC analog modules and reset before using the peripheral.
I added an nxp_hpdac_init() function which performs the following steps:
CLOCK_SetClkDiv(kCLOCK_DivDac2Clk, 1U)
CLOCK_AttachClk(kFRO_HF_to_DAC2)
CLOCK_EnableClock(kCLOCK_Dac2)
SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlDac2)
SPC_EnableLowPowerModeAnalogModules(SPC0, kSPC_controlDac2)
RESET_PeripheralReset(kDAC2_RST_SHIFT_RSTn)
DAC14_DoSoftwareReset()
DAC14_DoFIFOReset()
SPC_EnableActiveModeAnalogModules(SPC0, kSPC_controlVref)
These initialization steps were based on the MCXN947 reference manual and implemented using the corresponding MCUX SDK APIs.
The init function is registered as the device init callback through DEVICE_DT_INST_DEFINE(). With these changes, the HPDAC works correctly.
I also checked the Zephyr MCUX SYSCON clock-control driver and the mcux_lpc_syscon_clock.h bindings, but I could not find an HPDAC/DAC2 clock identifier or clock-control implementation for this peripheral, so I am currently using the MCUX SDK clock, SPC and reset APIs directly.
My questions are:
1. Is this the correct approach when backporting the MCXN947 HPDAC driver?
2. In newer Zephyr versions, are these resources initialized somewhere else, or does the upstream nxp_hpdac driver assume that they have already been configured?
3. Is the HPDAC device init callback the correct place for this MCXN947-specific initialization, or should these steps be handled elsewhere in Zephyr?
I have attached the complete backported driver for reference.