diff --git a/drivers/pwm/pwm_mcux_ftm.c b/drivers/pwm/pwm_mcux_ftm.c index 3f595da1567..33153dd8d3b 100644 --- a/drivers/pwm/pwm_mcux_ftm.c +++ b/drivers/pwm/pwm_mcux_ftm.c @@ -162,82 +162,37 @@ static const struct pwm_driver_api mcux_ftm_driver_api = { .get_cycles_per_sec = mcux_ftm_get_cycles_per_sec, }; -#ifdef CONFIG_PWM_0 -static const struct mcux_ftm_config mcux_ftm_config_0 = { - .base = (FTM_Type *)DT_FTM_0_BASE_ADDRESS, - .clock_name = DT_FTM_0_CLOCK_NAME, - .clock_subsys = - (clock_control_subsys_t) DT_FTM_0_CLOCK_SUBSYS, - .ftm_clock_source = kFTM_FixedClock, - .prescale = kFTM_Prescale_Divide_16, - .channel_count = FSL_FEATURE_FTM_CHANNEL_COUNTn(FTM0), - .mode = kFTM_EdgeAlignedPwm, -}; +#define FTM_DEVICE(n) \ + static const struct mcux_ftm_config mcux_ftm_config_##n = { \ + .base = (FTM_Type *)DT_INST_##n##_NXP_KINETIS_FTM_BASE_ADDRESS,\ + .clock_name = DT_INST_##n##_NXP_KINETIS_FTM_CLOCK_CONTROLLER, \ + .clock_subsys = (clock_control_subsys_t) \ + DT_INST_##n##_NXP_KINETIS_FTM_CLOCK_NAME, \ + .ftm_clock_source = kFTM_FixedClock, \ + .prescale = kFTM_Prescale_Divide_16, \ + .channel_count = FSL_FEATURE_FTM_CHANNEL_COUNTn((FTM_Type *) \ + DT_INST_##n##_NXP_KINETIS_FTM_BASE_ADDRESS), \ + .mode = kFTM_EdgeAlignedPwm, \ + }; \ + static struct mcux_ftm_data mcux_ftm_data_##n; \ + DEVICE_AND_API_INIT(mcux_ftm_##n, DT_INST_##n##_NXP_KINETIS_FTM_LABEL, \ + &mcux_ftm_init, &mcux_ftm_data_##n, \ + &mcux_ftm_config_##n, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + &mcux_ftm_driver_api) -static struct mcux_ftm_data mcux_ftm_data_0; +#if DT_INST_0_NXP_KINETIS_FTM +FTM_DEVICE(0); +#endif /* DT_INST_0_NXP_KINETIS_FTM */ -DEVICE_AND_API_INIT(mcux_ftm_0, DT_FTM_0_NAME, &mcux_ftm_init, - &mcux_ftm_data_0, &mcux_ftm_config_0, - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - &mcux_ftm_driver_api); -#endif /* CONFIG_PWM_0 */ +#if DT_INST_1_NXP_KINETIS_FTM +FTM_DEVICE(1); +#endif /* DT_INST_1_NXP_KINETIS_FTM */ -#ifdef CONFIG_PWM_1 -static const struct mcux_ftm_config mcux_ftm_config_1 = { - .base = (FTM_Type *)DT_FTM_1_BASE_ADDRESS, - .clock_name = DT_FTM_1_CLOCK_NAME, - .clock_subsys = - (clock_control_subsys_t) DT_FTM_1_CLOCK_SUBSYS, - .ftm_clock_source = kFTM_FixedClock, - .prescale = kFTM_Prescale_Divide_16, - .channel_count = FSL_FEATURE_FTM_CHANNEL_COUNTn(FTM1), - .mode = kFTM_EdgeAlignedPwm, -}; +#if DT_INST_2_NXP_KINETIS_FTM +FTM_DEVICE(2); +#endif /* DT_INST_2_NXP_KINETIS_FTM */ -static struct mcux_ftm_data mcux_ftm_data_1; - -DEVICE_AND_API_INIT(mcux_ftm_1, DT_FTM_1_NAME, &mcux_ftm_init, - &mcux_ftm_data_1, &mcux_ftm_config_1, - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - &mcux_ftm_driver_api); -#endif /* CONFIG_PWM_1 */ - -#ifdef CONFIG_PWM_2 -static const struct mcux_ftm_config mcux_ftm_config_2 = { - .base = (FTM_Type *)DT_FTM_2_BASE_ADDRESS, - .clock_name = DT_FTM_2_CLOCK_NAME, - .clock_subsys = - (clock_control_subsys_t) DT_FTM_2_CLOCK_SUBSYS, - .ftm_clock_source = kFTM_FixedClock, - .prescale = kFTM_Prescale_Divide_16, - .channel_count = FSL_FEATURE_FTM_CHANNEL_COUNTn(FTM2), - .mode = kFTM_EdgeAlignedPwm, -}; - -static struct mcux_ftm_data mcux_ftm_data_2; - -DEVICE_AND_API_INIT(mcux_ftm_2, DT_FTM_2_NAME, &mcux_ftm_init, - &mcux_ftm_data_2, &mcux_ftm_config_2, - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - &mcux_ftm_driver_api); -#endif /* CONFIG_PWM_2 */ - -#ifdef CONFIG_PWM_3 -static const struct mcux_ftm_config mcux_ftm_config_3 = { - .base = (FTM_Type *)DT_FTM_3_BASE_ADDRESS, - .clock_name = DT_FTM_3_CLOCK_NAME, - .clock_subsys = - (clock_control_subsys_t) DT_FTM_3_CLOCK_SUBSYS, - .ftm_clock_source = kFTM_FixedClock, - .prescale = kFTM_Prescale_Divide_16, - .channel_count = FSL_FEATURE_FTM_CHANNEL_COUNTn(FTM3), - .mode = kFTM_EdgeAlignedPwm, -}; - -static struct mcux_ftm_data mcux_ftm_data_3; - -DEVICE_AND_API_INIT(mcux_ftm_3, DT_FTM_3_NAME, &mcux_ftm_init, - &mcux_ftm_data_3, &mcux_ftm_config_3, - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, - &mcux_ftm_driver_api); -#endif /* CONFIG_PWM_3 */ +#if DT_INST_3_NXP_KINETIS_FTM +FTM_DEVICE(3); +#endif /* DT_INST_3_NXP_KINETIS_FTM */