123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #include <types.h>
- #include <lib.h>
- #include <spinlock.h>
- #include <platform/bus.h>
- #include <lamebus/lser.h>
- #include "autoconf.h"
- #define LSER_REG_CHAR 0
- #define LSER_REG_WIRQ 4
- #define LSER_REG_RIRQ 8
- #define LSER_IRQ_ENABLE 1
- #define LSER_IRQ_ACTIVE 2
- void
- lser_irq(void *vsc)
- {
- struct lser_softc *sc = vsc;
- uint32_t x;
- bool clear_to_write = false;
- bool got_a_read = false;
- uint32_t ch = 0;
- spinlock_acquire(&sc->ls_lock);
- x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_WIRQ);
- if (x & LSER_IRQ_ACTIVE) {
- x = LSER_IRQ_ENABLE;
- sc->ls_wbusy = 0;
- clear_to_write = true;
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_WIRQ, x);
- }
- x = bus_read_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_RIRQ);
- if (x & LSER_IRQ_ACTIVE) {
- x = LSER_IRQ_ENABLE;
- ch = bus_read_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_CHAR);
- got_a_read = true;
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_RIRQ, x);
- }
- spinlock_release(&sc->ls_lock);
- if (clear_to_write && sc->ls_start != NULL) {
- sc->ls_start(sc->ls_devdata);
- }
- if (got_a_read && sc->ls_input != NULL) {
- sc->ls_input(sc->ls_devdata, ch);
- }
- }
- void
- lser_write(void *vls, int ch)
- {
- struct lser_softc *ls = vls;
- spinlock_acquire(&ls->ls_lock);
- if (ls->ls_wbusy) {
-
- panic("lser: Not clear to write\n");
- }
- ls->ls_wbusy = true;
- bus_write_register(ls->ls_busdata, ls->ls_buspos, LSER_REG_CHAR, ch);
- spinlock_release(&ls->ls_lock);
- }
- static
- void
- lser_poll_until_write(struct lser_softc *sc)
- {
- uint32_t val;
- KASSERT(spinlock_do_i_hold(&sc->ls_lock));
- do {
- val = bus_read_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_WIRQ);
- }
- while ((val & LSER_IRQ_ACTIVE) == 0);
- }
- void
- lser_writepolled(void *vsc, int ch)
- {
- struct lser_softc *sc = vsc;
- bool irqpending = false;
- spinlock_acquire(&sc->ls_lock);
- if (sc->ls_wbusy) {
- irqpending = true;
- lser_poll_until_write(sc);
-
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_WIRQ, LSER_IRQ_ENABLE);
- }
-
- bus_write_register(sc->ls_busdata, sc->ls_buspos, LSER_REG_CHAR, ch);
-
- lser_poll_until_write(sc);
-
- if (!irqpending) {
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_WIRQ, LSER_IRQ_ENABLE);
- }
- spinlock_release(&sc->ls_lock);
- }
- void
- lser_startpolling(void *vsc)
- {
- struct lser_softc *sc = vsc;
- sc->ls_maskinterrupt(sc->ls_busdata, sc->ls_buspos);
- }
- void
- lser_endpolling(void *vsc)
- {
- struct lser_softc *sc = vsc;
- sc->ls_unmaskinterrupt(sc->ls_busdata, sc->ls_buspos);
- }
- int
- config_lser(struct lser_softc *sc, int lserno)
- {
- (void)lserno;
-
- spinlock_init(&sc->ls_lock);
- sc->ls_wbusy = false;
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_RIRQ, LSER_IRQ_ENABLE);
- bus_write_register(sc->ls_busdata, sc->ls_buspos,
- LSER_REG_WIRQ, LSER_IRQ_ENABLE);
- return 0;
- }
|