Lines Matching +full:ti +full:- +full:pruss

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
60 #include <arm/ti/ti_sysc.h>
61 #include <arm/ti/ti_pruss.h>
62 #include <arm/ti/ti_prm.h>
175 { -1, 0, 0 }
177 CTASSERT(TI_PRUSS_HOST_IRQS == nitems(ti_pruss_irq_spec) - 1);
184 sc = dev->si_drv1; in ti_pruss_irq_open()
187 irqs->cnt = sc->tstamps.ctl.cnt; in ti_pruss_irq_open()
188 irqs->idx = sc->tstamps.ctl.idx; in ti_pruss_irq_open()
204 sc = dev->si_drv1; in ti_pruss_irq_poll()
209 if (sc->tstamps.ctl.cnt != irqs->cnt) in ti_pruss_irq_poll()
212 selrecord(td, &sc->sc_selinfo); in ti_pruss_irq_poll()
227 irq = cdev->si_drv1; in ti_pruss_irq_read()
229 if (uio->uio_resid < ts_len) in ti_pruss_irq_read()
236 mtx_lock(&irq->sc_mtx); in ti_pruss_irq_read()
238 if (irq->tstamps.ctl.cnt - priv->cnt > TI_TS_ARRAY) in ti_pruss_irq_read()
240 priv->cnt = irq->tstamps.ctl.cnt; in ti_pruss_irq_read()
241 priv->idx = irq->tstamps.ctl.idx; in ti_pruss_irq_read()
242 mtx_unlock(&irq->sc_mtx); in ti_pruss_irq_read()
247 idx = priv->idx; in ti_pruss_irq_read()
248 level = irq->tstamps.ctl.idx - idx; in ti_pruss_irq_read()
254 mtx_unlock(&irq->sc_mtx); in ti_pruss_irq_read()
258 error = msleep(irq, &irq->sc_mtx, PCATCH | PDROP, in ti_pruss_irq_read()
263 mtx_lock(&irq->sc_mtx); in ti_pruss_irq_read()
267 mtx_unlock(&irq->sc_mtx); in ti_pruss_irq_read()
269 error = uiomove(&irq->tstamps.ts[idx], ts_len, uio); in ti_pruss_irq_read()
273 priv->idx = idx; in ti_pruss_irq_read()
275 atomic_add_32(&priv->cnt, 1); in ti_pruss_irq_read()
288 return (bus_space_read_4(sc->sc_bt, sc->sc_bh, reg)); in ti_pruss_reg_read()
294 bus_space_write_4(sc->sc_bt, sc->sc_bh, reg, val); in ti_pruss_reg_write()
314 if (enable && ((sc->sc_irq_devs[irq].channel == -1) || in ti_pruss_interrupts_enable()
315 (sc->sc_irq_devs[irq].event== -1))) in ti_pruss_interrupts_enable()
317 device_printf( sc->sc_pdev->si_drv1, in ti_pruss_interrupts_enable()
322 sc->sc_irq_devs[irq].enable = enable; in ti_pruss_interrupts_enable()
324 if (sc->sc_irq_devs[irq].sc_pdev) { in ti_pruss_interrupts_enable()
325 destroy_dev(sc->sc_irq_devs[irq].sc_pdev); in ti_pruss_interrupts_enable()
326 sc->sc_irq_devs[irq].sc_pdev = NULL; in ti_pruss_interrupts_enable()
330 sc->sc_irq_devs[irq].sc_pdev = make_dev(&ti_pruss_cdevirq, 0, UID_ROOT, GID_WHEEL, in ti_pruss_interrupts_enable()
331 0600, "pruss%d.irq%d", device_get_unit(sc->sc_pdev->si_drv1), irq); in ti_pruss_interrupts_enable()
332 sc->sc_irq_devs[irq].sc_pdev->si_drv1 = &sc->sc_irq_devs[irq]; in ti_pruss_interrupts_enable()
334 sc->sc_irq_devs[irq].tstamps.ctl.idx = 0; in ti_pruss_interrupts_enable()
338 ti_pruss_reg_write(sc, reg, sc->sc_irq_devs[irq].channel); in ti_pruss_interrupts_enable()
341 ti_pruss_reg_write(sc, reg, sc->sc_irq_devs[irq].event ); in ti_pruss_interrupts_enable()
366 if(sc->sc_irq_devs[irq].event == -1) in ti_pruss_event_map()
369 snprintf(event, sizeof(event), "%d", sc->sc_irq_devs[irq].event); in ti_pruss_event_map()
375 if (req->newptr) { // write event in ti_pruss_event_map()
378 sc->sc_irq_devs[irq].event = -1; in ti_pruss_event_map()
380 if (sc->sc_irq_devs[irq].channel == -1) { in ti_pruss_event_map()
381 device_printf( sc->sc_pdev->si_drv1, in ti_pruss_event_map()
386 const int8_t channelnr = sc->sc_irq_devs[irq].channel; in ti_pruss_event_map()
389 device_printf( sc->sc_pdev->si_drv1, in ti_pruss_event_map()
390 "Event number %d not valid (0 - %d)", in ti_pruss_event_map()
391 channelnr, TI_PRUSS_EVENTS -1); in ti_pruss_event_map()
395 sc->sc_irq_devs[irq].channel = channelnr; in ti_pruss_event_map()
396 sc->sc_irq_devs[irq].event = eventnr; in ti_pruss_event_map()
416 if (sc->sc_irq_devs[irq].channel == -1) in ti_pruss_channel_map()
419 snprintf(channel, sizeof(channel), "%d", sc->sc_irq_devs[irq].channel); in ti_pruss_channel_map()
425 if (req->newptr) { // write event in ti_pruss_channel_map()
429 sc->sc_irq_devs[irq].channel); in ti_pruss_channel_map()
430 sc->sc_irq_devs[irq].channel = -1; in ti_pruss_channel_map()
435 device_printf(sc->sc_pdev->si_drv1, in ti_pruss_channel_map()
436 "Channel number %d not valid (0 - %d)", in ti_pruss_channel_map()
437 channelnr, TI_PRUSS_IRQS-1); in ti_pruss_channel_map()
441 sc->sc_irq_devs[irq].channel = channelnr; in ti_pruss_channel_map()
442 sc->sc_irq_devs[irq].last = -1; in ti_pruss_channel_map()
462 irqenable = sc->sc_irq_devs[arg2].enable; in ti_pruss_interrupt_enable()
468 if (req->newptr) // write enable in ti_pruss_interrupt_enable()
482 glob_irqen = sc->sc_glob_irqen; in ti_pruss_global_interrupt_enable()
488 if (req->newptr) { in ti_pruss_global_interrupt_enable()
489 sc->sc_glob_irqen = glob_irqen; in ti_pruss_global_interrupt_enable()
502 if (ofw_bus_is_compatible(dev, "ti,pruss-v1") || in ti_pruss_probe()
503 ofw_bus_is_compatible(dev, "ti,pruss-v2")) { in ti_pruss_probe()
504 device_set_desc(dev, "TI Programmable Realtime Unit Subsystem"); in ti_pruss_probe()
530 * Follow activate pattern from sys/arm/ti/am335x/am335x_prcm.c in ti_pruss_attach()
537 device_printf(dev, "Could not enable PRUSS clock\n"); in ti_pruss_attach()
574 /* #reset-cells should not been used in this way but... */ in ti_pruss_attach()
575 err = ofw_bus_parse_xref_list_alloc(node, "resets", "#reset-cells", 0, in ti_pruss_attach()
597 mtx_init(&sc->sc_mtx, "TI PRUSS", NULL, MTX_DEF); in ti_pruss_attach()
598 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in ti_pruss_attach()
600 if (sc->sc_mem_res == NULL) { in ti_pruss_attach()
614 sc->sc_glob_irqen = false; in ti_pruss_attach()
617 "PRUSS Host Interrupts"); in ti_pruss_attach()
624 sc->sc_bt = rman_get_bustag(sc->sc_mem_res); in ti_pruss_attach()
625 sc->sc_bh = rman_get_bushandle(sc->sc_mem_res); in ti_pruss_attach()
626 if (bus_alloc_resources(dev, ti_pruss_irq_spec, sc->sc_irq_res) != 0) { in ti_pruss_attach()
640 "PRUSS Interrupts"); in ti_pruss_attach()
654 sc->sc_irq_devs[i].event = -1; in ti_pruss_attach()
655 sc->sc_irq_devs[i].channel = -1; in ti_pruss_attach()
656 sc->sc_irq_devs[i].tstamps.ctl.idx = 0; in ti_pruss_attach()
661 if (bus_setup_intr(dev, sc->sc_irq_res[i], in ti_pruss_attach()
664 &sc->sc_intr[i]) != 0) { in ti_pruss_attach()
671 mtx_init(&sc->sc_irq_devs[i].sc_mtx, "TI PRUSS IRQ", NULL, MTX_DEF); in ti_pruss_attach()
672 knlist_init_mtx(&sc->sc_irq_devs[i].sc_selinfo.si_note, &sc->sc_irq_devs[i].sc_mtx); in ti_pruss_attach()
677 device_printf(dev, "AM33xx PRU-ICSS\n"); in ti_pruss_attach()
679 sc->sc_pdev = make_dev(&ti_pruss_cdevsw, 0, UID_ROOT, GID_WHEEL, in ti_pruss_attach()
680 0600, "pruss%d", device_get_unit(dev)); in ti_pruss_attach()
681 sc->sc_pdev->si_drv1 = dev; in ti_pruss_attach()
704 if (sc->sc_intr[i]) in ti_pruss_detach()
705 bus_teardown_intr(dev, sc->sc_irq_res[i], sc->sc_intr[i]); in ti_pruss_detach()
706 if (sc->sc_irq_res[i]) in ti_pruss_detach()
708 rman_get_rid(sc->sc_irq_res[i]), in ti_pruss_detach()
709 sc->sc_irq_res[i]); in ti_pruss_detach()
710 knlist_clear(&sc->sc_irq_devs[i].sc_selinfo.si_note, 0); in ti_pruss_detach()
711 mtx_lock(&sc->sc_irq_devs[i].sc_mtx); in ti_pruss_detach()
712 if (!knlist_empty(&sc->sc_irq_devs[i].sc_selinfo.si_note)) in ti_pruss_detach()
714 mtx_unlock(&sc->sc_irq_devs[i].sc_mtx); in ti_pruss_detach()
715 knlist_destroy(&sc->sc_irq_devs[i].sc_selinfo.si_note); in ti_pruss_detach()
716 mtx_destroy(&sc->sc_irq_devs[i].sc_mtx); in ti_pruss_detach()
719 mtx_destroy(&sc->sc_mtx); in ti_pruss_detach()
720 if (sc->sc_mem_res) in ti_pruss_detach()
721 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->sc_mem_res), in ti_pruss_detach()
722 sc->sc_mem_res); in ti_pruss_detach()
723 if (sc->sc_pdev) in ti_pruss_detach()
724 destroy_dev(sc->sc_pdev); in ti_pruss_detach()
734 struct ti_pruss_softc *sc = iap->sc; in ti_pruss_intr()
737 * Host-2 to Host-9 of PRU-ICSS IRQ-controller. in ti_pruss_intr()
739 const int pru_int = iap->irq + TI_PRUSS_PRU_IRQS; in ti_pruss_intr()
741 const int pru_channel = sc->sc_irq_devs[pru_int].channel; in ti_pruss_intr()
742 const int pru_event = sc->sc_irq_devs[pru_channel].event; in ti_pruss_intr()
752 struct ti_pruss_irqsc* irq = &sc->sc_irq_devs[pru_channel]; in ti_pruss_intr()
753 size_t wr = irq->tstamps.ctl.idx; in ti_pruss_intr()
757 irq->tstamps.ts[wr] = ts.tv_sec * 1000000000 + ts.tv_nsec; in ti_pruss_intr()
761 atomic_add_32(&irq->tstamps.ctl.cnt, 1); in ti_pruss_intr()
763 irq->tstamps.ctl.idx = wr; in ti_pruss_intr()
765 KNOTE_UNLOCKED(&irq->sc_selinfo.si_note, pru_int); in ti_pruss_intr()
767 selwakeup(&irq->sc_selinfo); in ti_pruss_intr()
781 device_t dev = cdev->si_drv1; in ti_pruss_mmap()
784 if (offset >= rman_get_size(sc->sc_mem_res)) in ti_pruss_mmap()
786 *paddr = rman_get_start(sc->sc_mem_res) + offset; in ti_pruss_mmap()
801 struct ti_pruss_irqsc *sc = kn->kn_hook; in ti_pruss_irq_kqread_detach()
803 knlist_remove(&sc->sc_selinfo.si_note, kn, 0); in ti_pruss_irq_kqread_detach()
812 irq_sc = kn->kn_hook; in ti_pruss_irq_kqevent()
815 kn->kn_data = hint - 2; in ti_pruss_irq_kqevent()
817 if (hint > 0 || irq_sc->last > 0) in ti_pruss_irq_kqevent()
822 irq_sc->last = hint; in ti_pruss_irq_kqevent()
830 struct ti_pruss_irqsc *sc = cdev->si_drv1; in ti_pruss_irq_kqfilter()
832 switch (kn->kn_filter) { in ti_pruss_irq_kqfilter()
834 kn->kn_hook = sc; in ti_pruss_irq_kqfilter()
835 kn->kn_fop = &ti_pruss_kq_read; in ti_pruss_irq_kqfilter()
836 knlist_add(&sc->sc_selinfo.si_note, kn, 0); in ti_pruss_irq_kqfilter()