Lines Matching +full:cd +full:- +full:inverted
1 /*-
53 * variable-duty-cycle PWM output.
62 #define PWM_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
63 #define PWM_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
64 #define PWM_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
65 #define PWM_LOCK_INIT(_sc) mtx_init(&(_sc)->sc_mtx, \
66 device_get_nameunit(_sc->sc_dev), "am335x_ehrpwm softc", MTX_DEF)
67 #define PWM_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
69 #define EPWM_READ2(_sc, reg) bus_read_2((_sc)->sc_mem_res, reg)
71 bus_write_2((_sc)->sc_mem_res, reg, value)
102 /* Counter-compare */
142 /* Trip-Zone module */
155 /* PWM-chopper */
161 /* High-Resolution PWM */
174 bool inverted; /* signal inverted? */ member
193 {"ti,am3352-ehrpwm", true},
194 {"ti,am33xx-ehrpwm", true},
207 tbcmp = max(1, duty / sc->sc_clktick); in am335x_ehrpwm_cfg_duty()
209 sc->sc_channels[chan].duty = tbcmp * sc->sc_clktick; in am335x_ehrpwm_cfg_duty()
220 sc->sc_channels[chan].enabled = enable; in am335x_ehrpwm_cfg_enable()
223 * Turn off any existing software-force of the channel, then force in am335x_ehrpwm_cfg_enable()
229 if (!sc->sc_channels[chan].enabled) { in am335x_ehrpwm_cfg_enable()
230 if (sc->sc_channels[chan].inverted) in am335x_ehrpwm_cfg_enable()
246 sc->sc_clkfreq = 0; in am335x_ehrpwm_cfg_period()
247 sc->sc_clktick = 0; in am335x_ehrpwm_cfg_period()
248 sc->sc_period = 0; in am335x_ehrpwm_cfg_period()
254 * that we can express the requested period as a 16-bit tick count. in am335x_ehrpwm_cfg_period()
258 const u_int cd = 1 << clkdiv; in am335x_ehrpwm_cfg_period() local
261 pwmclk = PWM_CLOCK / (cd * cdhs); in am335x_ehrpwm_cfg_period()
280 if (sc->sc_clkfreq != pwmclk || sc->sc_clktick != pwmtick || in am335x_ehrpwm_cfg_period()
281 sc->sc_period != tbprd * pwmtick) { in am335x_ehrpwm_cfg_period()
282 sc->sc_clkfreq = pwmclk; in am335x_ehrpwm_cfg_period()
283 sc->sc_clktick = pwmtick; in am335x_ehrpwm_cfg_period()
284 sc->sc_period = tbprd * pwmtick; in am335x_ehrpwm_cfg_period()
291 EPWM_WRITE2(sc, EPWM_TBPRD, tbprd - 1); in am335x_ehrpwm_cfg_period()
293 device_printf(sc->sc_dev, "clkdiv %u hspclkdiv %u tbprd %u " in am335x_ehrpwm_cfg_period()
295 clkdiv, hspclkdiv, tbprd - 1, in am335x_ehrpwm_cfg_period()
296 sc->sc_clkfreq, sc->sc_clktick, sc->sc_period, period); in am335x_ehrpwm_cfg_period()
348 *period = sc->sc_period; in am335x_ehrpwm_channel_get_config()
349 *duty = sc->sc_channels[channel].duty; in am335x_ehrpwm_channel_get_config()
366 sc->sc_channels[channel].inverted = true; in am335x_ehrpwm_channel_set_flags()
367 /* Action-Qualifier 15.2.2.5 */ in am335x_ehrpwm_channel_set_flags()
375 sc->sc_channels[channel].inverted = false; in am335x_ehrpwm_channel_set_flags()
398 if (sc->sc_channels[channel].inverted == true) in am335x_ehrpwm_channel_get_flags()
434 *enabled = sc->sc_channels[channel].enabled; in am335x_ehrpwm_channel_is_enabled()
446 if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data) in am335x_ehrpwm_probe()
461 sc->sc_dev = dev; in am335x_ehrpwm_attach()
465 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in am335x_ehrpwm_attach()
466 &sc->sc_mem_rid, RF_ACTIVE); in am335x_ehrpwm_attach()
467 if (sc->sc_mem_res == NULL) { in am335x_ehrpwm_attach()
477 EPWM_WRITE2(sc, EPWM_TBPRD, DEFAULT_PWM_PERIOD - 1); in am335x_ehrpwm_attach()
481 /* Action-Qualifier 15.2.2.5 */ in am335x_ehrpwm_attach()
491 /* PWM-chopper described in 15.2.2.7 */ in am335x_ehrpwm_attach()
493 * to control the power switching-elements in am335x_ehrpwm_attach()
504 /* disable TZn as one-shot / CVC trip source 15.2.4.18 */ in am335x_ehrpwm_attach()
515 if ((sc->sc_busdev = device_add_child(dev, "pwmbus", -1)) == NULL) { in am335x_ehrpwm_attach()
525 if (sc->sc_mem_res) in am335x_ehrpwm_attach()
527 sc->sc_mem_rid, sc->sc_mem_res); in am335x_ehrpwm_attach()
540 if ((error = bus_generic_detach(sc->sc_dev)) != 0) in am335x_ehrpwm_detach()
545 if (sc->sc_busdev != NULL) in am335x_ehrpwm_detach()
546 device_delete_child(dev, sc->sc_busdev); in am335x_ehrpwm_detach()
548 if (sc->sc_mem_res) in am335x_ehrpwm_detach()
550 sc->sc_mem_rid, sc->sc_mem_res); in am335x_ehrpwm_detach()