Lines Matching +full:output +full:- +full:polarity +full:- +full:invert

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2017 Poul-Henning Kamp <phk@FreeBSD.org>
49 {"broadcom,bcm2835-pwm", 1},
50 {"brcm,bcm2835-pwm", 1},
73 bus_space_write_4(_sc->sc_m_bst, _sc->sc_m_bsh, _off, _val)
75 bus_space_read_4(_sc->sc_m_bst, _sc->sc_m_bsh, _off)
77 bus_space_write_4(_sc->sc_c_bst, _sc->sc_c_bsh, _off, _val)
79 bus_space_read_4(_sc->sc_c_bst, _sc->sc_c_bsh, _off)
103 (void)bcm2835_clkman_set_frequency(sc->clkman, BCM_PWM_CLKSRC, 0); in bcm_pwm_reconf()
105 ctlr = 0; /* pre-assign zero, enable bits, write to CTL at end */ in bcm_pwm_reconf()
107 if (sc->mode == 0 && sc->mode2 == 0) /* both modes are zero */ in bcm_pwm_reconf()
108 return 0; /* device is now off - return */ in bcm_pwm_reconf()
112 u = bcm2835_clkman_set_frequency(sc->clkman, BCM_PWM_CLKSRC, sc->freq); in bcm_pwm_reconf()
115 sc->freq = u; in bcm_pwm_reconf()
123 * 12 POLA2 chan 2 invert polarity (0 normal, 1 inverted polarity) in bcm_pwm_reconf()
131 * 4 POLA1 chan 1 invert polarity (0 normal, 1 inverted polarity) in bcm_pwm_reconf()
139 * defined by 'period'. So if 'ratio' is 2500 and 'period' is 10000, then the output in bcm_pwm_reconf()
146 if (sc->mode != 0) { in bcm_pwm_reconf()
148 W_RNG(sc, sc->period); in bcm_pwm_reconf()
149 if (sc->ratio > sc->period) in bcm_pwm_reconf()
150 sc->ratio = sc->period; in bcm_pwm_reconf()
151 W_DAT(sc, sc->ratio); in bcm_pwm_reconf()
154 if (sc->mode == 1) in bcm_pwm_reconf()
160 if (sc->mode2 != 0) { in bcm_pwm_reconf()
162 W_RNG2(sc, sc->period2); in bcm_pwm_reconf()
163 if (sc->ratio2 > sc->period2) in bcm_pwm_reconf()
164 sc->ratio2 = sc->period2; in bcm_pwm_reconf()
165 W_DAT2(sc, sc->ratio2); in bcm_pwm_reconf()
168 if (sc->mode2 == 1) in bcm_pwm_reconf()
188 if (sc->mode == 1) in bcm_pwm_pwm_freq_proc()
189 r = sc->freq / sc->period; in bcm_pwm_pwm_freq_proc()
204 r = sc->mode; in bcm_pwm_mode_proc()
206 if (error != 0 || req->newptr == NULL) in bcm_pwm_mode_proc()
210 sc->mode = r; in bcm_pwm_mode_proc()
222 r = sc->freq; in bcm_pwm_freq_proc()
224 if (error != 0 || req->newptr == NULL) in bcm_pwm_freq_proc()
228 sc->freq = r; in bcm_pwm_freq_proc()
239 error = sysctl_handle_int(oidp, &sc->period, sizeof(sc->period), req); in bcm_pwm_period_proc()
240 if (error != 0 || req->newptr == NULL) in bcm_pwm_period_proc()
253 r = sc->ratio; in bcm_pwm_ratio_proc()
255 if (error != 0 || req->newptr == NULL) in bcm_pwm_ratio_proc()
257 if (r > sc->period) // XXX >= ? in bcm_pwm_ratio_proc()
259 sc->ratio = r; in bcm_pwm_ratio_proc()
260 W_DAT(sc, sc->ratio); in bcm_pwm_ratio_proc()
272 if (sc->mode2 == 1) in bcm_pwm_pwm_freq2_proc()
273 r = sc->freq / sc->period2; in bcm_pwm_pwm_freq2_proc()
288 r = sc->mode2; in bcm_pwm_mode2_proc()
290 if (error != 0 || req->newptr == NULL) in bcm_pwm_mode2_proc()
294 sc->mode2 = r; in bcm_pwm_mode2_proc()
305 error = sysctl_handle_int(oidp, &sc->period2, sizeof(sc->period2), req); in bcm_pwm_period2_proc()
306 if (error != 0 || req->newptr == NULL) in bcm_pwm_period2_proc()
319 r = sc->ratio2; in bcm_pwm_ratio2_proc()
321 if (error != 0 || req->newptr == NULL) in bcm_pwm_ratio2_proc()
323 if (r > sc->period2) // XXX >= ? in bcm_pwm_ratio2_proc()
325 sc->ratio2 = r; in bcm_pwm_ratio2_proc()
326 W_DAT(sc, sc->ratio2); in bcm_pwm_ratio2_proc()
341 if (error != 0 || req->newptr == NULL) in bcm_pwm_reg_proc()
358 ctx = device_get_sysctl_ctx(sc->sc_dev); in bcm_pwm_sysctl_init()
359 tree_node = device_get_sysctl_tree(sc->sc_dev); in bcm_pwm_sysctl_init()
415 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in bcm_pwm_probe()
435 sc->sc_dev = dev; in bcm_pwm_attach()
437 sc->clkman = devclass_get_device(devclass_find("bcm2835_clkman"), 0); in bcm_pwm_attach()
438 if (sc->clkman == NULL) { in bcm_pwm_attach()
444 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in bcm_pwm_attach()
446 if (!sc->sc_mem_res) { in bcm_pwm_attach()
451 sc->sc_m_bst = rman_get_bustag(sc->sc_mem_res); in bcm_pwm_attach()
452 sc->sc_m_bsh = rman_get_bushandle(sc->sc_mem_res); in bcm_pwm_attach()
457 sc->freq = 125000000; /* 125 Mhz */ in bcm_pwm_attach()
458 sc->period = 10000; /* 12.5 khz */ in bcm_pwm_attach()
459 sc->ratio = 2500; /* 25% */ in bcm_pwm_attach()
460 sc->period2 = 10000; /* 12.5 khz */ in bcm_pwm_attach()
461 sc->ratio2 = 2500; /* 25% */ in bcm_pwm_attach()
475 sc->mode = 0; in bcm_pwm_detach()
476 sc->mode2 = 0; in bcm_pwm_detach()
478 if (sc->sc_mem_res) in bcm_pwm_detach()
479 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); in bcm_pwm_detach()