Lines Matching +full:div +full:- +full:s
5 * SPDX-License-Identifier: Apache-2.0
63 uint8_t div; member
141 *on = ((on_off * dc) / XEC_PWM_DC_PF) - 1; in xec_compute_on_off()
142 *off = on_off - *on - 2; in xec_compute_on_off()
172 if ((target_freq - freq_a) < (target_freq - freq_b)) { in xec_compare_div_on_off()
193 uint8_t div; in xec_select_best_div_on_off() local
195 div = xec_select_div(target_freq, max_freq); in xec_select_best_div_on_off()
197 for (div_comp = (int)div - 1; div_comp >= 0; div_comp--) { in xec_select_best_div_on_off()
198 div = xec_compare_div_on_off(target_freq, dc, max_freq, in xec_select_best_div_on_off()
199 div, div_comp, on, off); in xec_select_best_div_on_off()
202 return div; in xec_select_best_div_on_off()
213 if (hc_params->div < NUM_DIV_ELEMS) { in xec_compare_params()
215 max_freq_high_on_div[hc_params->div], in xec_compare_params()
216 hc_params->on, in xec_compare_params()
217 hc_params->off); in xec_compare_params()
220 if (lc_params->div < NUM_DIV_ELEMS) { in xec_compare_params()
222 max_freq_low_on_div[lc_params->div], in xec_compare_params()
223 lc_params->on, in xec_compare_params()
224 lc_params->off); in xec_compare_params()
227 if (abs((int)target_freq - (int)freq_h) < in xec_compare_params()
228 abs((int)target_freq - (int)freq_l)) { in xec_compare_params()
235 LOG_DBG("\tOn %s clock, ON %u OFF %u DIV %u", in xec_compare_params()
237 params->on, params->off, params->div); in xec_compare_params()
246 const struct pwm_xec_config * const cfg = dev->config; in xec_compute_and_set_parameters()
247 struct pwm_regs * const regs = cfg->regs; in xec_compute_and_set_parameters()
259 LOG_DBG("Target freq (x%u): %u and DC %u per-cent", in xec_compute_and_set_parameters()
268 hc_params.div = 0; in xec_compute_and_set_parameters()
269 lc_params.div = UINT8_MAX; in xec_compute_and_set_parameters()
274 hc_params.div = xec_select_best_div_on_off( in xec_compute_and_set_parameters()
279 LOG_DBG("Best div high: %u (on/off: %u/%u)", in xec_compute_and_set_parameters()
280 hc_params.div, hc_params.on, hc_params.off); in xec_compute_and_set_parameters()
282 hc_params.div = UINT8_MAX; in xec_compute_and_set_parameters()
286 lc_params.div = xec_select_best_div_on_off( in xec_compute_and_set_parameters()
291 LOG_DBG("Best div low: %u (on/off: %u/%u)", in xec_compute_and_set_parameters()
292 lc_params.div, lc_params.on, lc_params.off); in xec_compute_and_set_parameters()
294 lc_params.div = UINT8_MAX; in xec_compute_and_set_parameters()
297 regs->CONFIG &= ~MCHP_PWM_CFG_ENABLE; in xec_compute_and_set_parameters()
299 cfgval = regs->CONFIG; in xec_compute_and_set_parameters()
308 regs->COUNT_ON = params->on; in xec_compute_and_set_parameters()
309 regs->COUNT_OFF = params->off; in xec_compute_and_set_parameters()
311 cfgval |= MCHP_PWM_CFG_CLK_PRE_DIV(params->div); in xec_compute_and_set_parameters()
314 regs->CONFIG = cfgval; in xec_compute_and_set_parameters()
321 const struct pwm_xec_config * const cfg = dev->config; in pwm_xec_set_cycles()
322 struct pwm_regs * const regs = cfg->regs; in pwm_xec_set_cycles()
327 return -EIO; in pwm_xec_set_cycles()
331 regs->CONFIG |= MCHP_PWM_CFG_ON_POL_LO; in pwm_xec_set_cycles()
335 off = period_cycles - pulse_cycles; in pwm_xec_set_cycles()
340 return -EINVAL; in pwm_xec_set_cycles()
344 regs->CONFIG &= ~MCHP_PWM_CFG_ENABLE; in pwm_xec_set_cycles()
346 regs->COUNT_ON = 0; in pwm_xec_set_cycles()
347 regs->COUNT_OFF = 1; in pwm_xec_set_cycles()
349 regs->COUNT_ON = 1; in pwm_xec_set_cycles()
350 regs->COUNT_OFF = 0; in pwm_xec_set_cycles()
364 return -EIO; in pwm_xec_get_cycles_per_sec()
380 const struct pwm_xec_config *const devcfg = dev->config; in pwm_xec_pm_action()
381 struct pwm_regs * const regs = devcfg->regs; in pwm_xec_pm_action()
382 struct pwm_xec_data * const data = dev->data; in pwm_xec_pm_action()
387 ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_DEFAULT); in pwm_xec_pm_action()
393 if ((data->config & MCHP_PWM_CFG_ENABLE) == MCHP_PWM_CFG_ENABLE) { in pwm_xec_pm_action()
395 regs->CONFIG |= MCHP_PWM_CFG_ENABLE; in pwm_xec_pm_action()
397 data->config &= (~MCHP_PWM_CFG_ENABLE); in pwm_xec_pm_action()
401 if ((regs->CONFIG & MCHP_PWM_CFG_ENABLE) == MCHP_PWM_CFG_ENABLE) { in pwm_xec_pm_action()
403 data->config = regs->CONFIG; in pwm_xec_pm_action()
405 regs->CONFIG &= ~(MCHP_PWM_CFG_ENABLE); in pwm_xec_pm_action()
408 ret = pinctrl_apply_state(devcfg->pcfg, PINCTRL_STATE_SLEEP); in pwm_xec_pm_action()
409 /* pinctrl-1 does not exist. */ in pwm_xec_pm_action()
410 if (ret == -ENOENT) { in pwm_xec_pm_action()
415 ret = -ENOTSUP; in pwm_xec_pm_action()
428 const struct pwm_xec_config * const cfg = dev->config; in pwm_xec_init()
429 int ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in pwm_xec_init()