Lines Matching +full:slice +full:- +full:prescaler

4  * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/dt-bindings/pwm/pwm.h>
38 const struct pwm_xmc4xxx_ccu8_config *config = dev->config; in pwm_xmc4xxx_ccu8_init()
41 XMC_CCU8_EnableModule(config->ccu8); in pwm_xmc4xxx_ccu8_init()
42 XMC_CCU8_StartPrescaler(config->ccu8); in pwm_xmc4xxx_ccu8_init()
45 XMC_CCU8_SLICE_t *slice; in pwm_xmc4xxx_ccu8_init() local
48 .prescaler_initval = config->slice_prescaler[i], in pwm_xmc4xxx_ccu8_init()
53 if (config->slice_prescaler[i] > MAX_SLICE_PRESCALER) { in pwm_xmc4xxx_ccu8_init()
55 config->slice_prescaler[i]); in pwm_xmc4xxx_ccu8_init()
56 return -EINVAL; in pwm_xmc4xxx_ccu8_init()
59 if (config->slice_deadtime_prescaler[i] > MAX_DEADTIME_PRESCALER) { in pwm_xmc4xxx_ccu8_init()
60 LOG_ERR("Invalid dead time prescaler value %d. Range [0, 3]", in pwm_xmc4xxx_ccu8_init()
61 config->slice_deadtime_prescaler[i]); in pwm_xmc4xxx_ccu8_init()
62 return -EINVAL; in pwm_xmc4xxx_ccu8_init()
65 slice = (XMC_CCU8_SLICE_t *)SLICE_ADDR_FROM_MODULE(config->ccu8, i); in pwm_xmc4xxx_ccu8_init()
66 XMC_CCU8_SLICE_CompareInit(slice, &slice_conf); in pwm_xmc4xxx_ccu8_init()
68 deadtime_conf.div = config->slice_deadtime_prescaler[i]; in pwm_xmc4xxx_ccu8_init()
69 if (config->deadtime_high_ns[2*i] > 0 || config->deadtime_low_ns[2*i] > 0) { in pwm_xmc4xxx_ccu8_init()
72 deadtime_conf.channel1_st_path = config->deadtime_high_ns[2*i] > 0; in pwm_xmc4xxx_ccu8_init()
73 deadtime_conf.channel1_inv_st_path = config->deadtime_low_ns[2*i] > 0; in pwm_xmc4xxx_ccu8_init()
75 if (config->deadtime_high_ns[2*i + 1] > 0 || config->deadtime_low_ns[2*i + 1] > 0) { in pwm_xmc4xxx_ccu8_init()
78 deadtime_conf.channel2_st_path = config->deadtime_high_ns[2*i + 1] > 0; in pwm_xmc4xxx_ccu8_init()
79 deadtime_conf.channel2_inv_st_path = config->deadtime_low_ns[2*i + 1] > 0; in pwm_xmc4xxx_ccu8_init()
81 XMC_CCU8_SLICE_DeadTimeInit(slice, &deadtime_conf); in pwm_xmc4xxx_ccu8_init()
84 return pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in pwm_xmc4xxx_ccu8_init()
91 const struct pwm_xmc4xxx_ccu8_config *config = dev->config; in pwm_xmc4xxx_ccu8_set_cycles()
92 XMC_CCU8_SLICE_t *slice; in pwm_xmc4xxx_ccu8_set_cycles() local
98 return -EINVAL; in pwm_xmc4xxx_ccu8_set_cycles()
102 return -EINVAL; in pwm_xmc4xxx_ccu8_set_cycles()
105 slice = (XMC_CCU8_SLICE_t *)SLICE_ADDR_FROM_MODULE(config->ccu8, slice_idx); in pwm_xmc4xxx_ccu8_set_cycles()
106 slice->PRS = period_cycles - 1; in pwm_xmc4xxx_ccu8_set_cycles()
109 slice->CR2S = period_cycles - pulse_cycles; in pwm_xmc4xxx_ccu8_set_cycles()
111 slice->CR1S = period_cycles - pulse_cycles; in pwm_xmc4xxx_ccu8_set_cycles()
113 slice->PSL = flags & PWM_POLARITY_INVERTED; in pwm_xmc4xxx_ccu8_set_cycles()
116 cycles = XMC_SCU_CLOCK_GetCcuClockFrequency() >> config->slice_prescaler[slice_idx]; in pwm_xmc4xxx_ccu8_set_cycles()
117 cycles >>= config->slice_deadtime_prescaler[slice_idx]; in pwm_xmc4xxx_ccu8_set_cycles()
118 high_deadtime_value = config->deadtime_high_ns[channel] * cycles / NSEC_PER_SEC; in pwm_xmc4xxx_ccu8_set_cycles()
119 low_deadtime_value = config->deadtime_low_ns[channel] * cycles / NSEC_PER_SEC; in pwm_xmc4xxx_ccu8_set_cycles()
122 return -EINVAL; in pwm_xmc4xxx_ccu8_set_cycles()
125 XMC_CCU8_SLICE_SetDeadTimeValue(slice, channel & 0x1, high_deadtime_value, in pwm_xmc4xxx_ccu8_set_cycles()
128 XMC_CCU8_EnableShadowTransfer(config->ccu8, BIT(slice_idx * 4)); in pwm_xmc4xxx_ccu8_set_cycles()
131 XMC_CCU8_EnableClock(config->ccu8, slice_idx); in pwm_xmc4xxx_ccu8_set_cycles()
132 XMC_CCU8_SLICE_StartTimer(slice); in pwm_xmc4xxx_ccu8_set_cycles()
140 const struct pwm_xmc4xxx_ccu8_config *config = dev->config; in pwm_xmc4xxx_ccu8_get_cycles_per_sec()
143 return -EINVAL; in pwm_xmc4xxx_ccu8_get_cycles_per_sec()
146 *cycles = XMC_SCU_CLOCK_GetCcuClockFrequency() >> config->slice_prescaler[channel / 2]; in pwm_xmc4xxx_ccu8_get_cycles_per_sec()