Annotation of sys/arch/arm/sa11x0/sa11x0_com.c, Revision 1.1
1.1 ! nbrk 1: #include <sys/param.h>
! 2: #include <sys/systm.h>
! 3: #include <sys/proc.h>
! 4: #include <sys/tty.h>
! 5: #include <sys/conf.h>
! 6: #include <sys/device.h>
! 7:
! 8: #include <machine/bus.h>
! 9: #include <machine/cpu.h>
! 10: #include <machine/intr.h>
! 11:
! 12: #include <dev/cons.h>
! 13:
! 14: #include <arm/sa11x0/sa11x0_comreg.h>
! 15: #include <arm/sa11x0/sa11x0_reg.h>
! 16: #include <arm/sa11x0/sa11x0_var.h>
! 17:
! 18: #ifdef DDB
! 19: #include <ddb/db_var.h>
! 20: #endif
! 21:
! 22: cons_decl(sacom);
! 23: cons_decl(sacomfake);
! 24: void sacominit(bus_space_tag_t bust, bus_addr_t busa, int speed);
! 25: int sacomcnattach(bus_space_tag_t bust, bus_addr_t busa, int speed);
! 26: void sacomfakecnattach(bus_addr_t addr);
! 27:
! 28: /*
! 29: * Fake autoconf stuff.
! 30: */
! 31: struct cfdriver sacom_cd = {
! 32: NULL,
! 33: "sacom",
! 34: DV_TTY
! 35: };
! 36:
! 37: struct sacom_softc {
! 38: struct device sc_dev;
! 39: };
! 40:
! 41: int sacom_match(struct device *parent, void *match, void *aux);
! 42: void sacom_attach(struct device *parent, struct device *self, void *aux);
! 43:
! 44: struct cfattach sacom_ca = {
! 45: sizeof(struct sacom_softc),
! 46: sacom_match,
! 47: sacom_attach,
! 48: };
! 49:
! 50: int
! 51: sacom_match(struct device *parent, void *match, void *aux)
! 52: {
! 53: return (1);
! 54: }
! 55:
! 56: void
! 57: sacom_attach(struct device *parent, struct device *self, void *aux)
! 58: {
! 59: printf(": SA-11x0 UART\n");
! 60: return;
! 61: }
! 62:
! 63: /*
! 64: * Stuff for early sacom console support.
! 65: */
! 66: bus_space_tag_t sacom_bust;
! 67: bus_space_handle_t sacom_bush;
! 68: bus_addr_t sacom_base; /* XXX for early sacom */
! 69: int sacom_speed;
! 70: int sacom_attached;
! 71: struct consdev sacom_consdev = {
! 72: NULL /* probe */,
! 73: NULL, /* init */
! 74: sacomcngetc,
! 75: sacomcnputc,
! 76: NULL /* poll */,
! 77: NULL /* bell */,
! 78: NODEV,
! 79: CN_NORMAL
! 80: };
! 81: /* fake one (to use in bootstrap) */
! 82: struct consdev sacom_fakeconsdev = {
! 83: NULL /* probe */,
! 84: NULL, /* init */
! 85: sacomfakecngetc,
! 86: sacomfakecnputc,
! 87: NULL /* poll */,
! 88: NULL /* bell */,
! 89: NODEV,
! 90: CN_NORMAL
! 91: };
! 92:
! 93:
! 94: void
! 95: sacominit(bus_space_tag_t bust, bus_addr_t busa, int speed)
! 96: {
! 97: if (!sacom_attached && bus_space_map(bust, busa, 0x24, 0, &sacom_bush))
! 98: panic("sacomcninit: mapping failed");
! 99:
! 100: sacom_bust = bust;
! 101: sacom_attached = 1;
! 102: sacom_speed = speed;
! 103: }
! 104:
! 105: void
! 106: sacomcninit(struct consdev *p)
! 107: {
! 108: sacominit(sacom_bust, sacom_bush, sacom_speed);
! 109: }
! 110:
! 111: void
! 112: sacomfakecnattach(bus_addr_t addr)
! 113: {
! 114: /*
! 115: * XXX assume that loader (hpcboot) already set up UART3.
! 116: * Just point cn_tab at our fake putc & getc routines.
! 117: */
! 118:
! 119: sacom_base = addr;
! 120: cn_tab = &sacom_fakeconsdev;
! 121:
! 122: // sacom_attached = 1;
! 123: }
! 124:
! 125: int
! 126: sacomcnattach(bus_space_tag_t bust, bus_addr_t busa, int speed)
! 127: {
! 128: /*
! 129: * Early console attachment.
! 130: * Called from initarm() to print messages on boot.
! 131: */
! 132: // int s = splhigh();
! 133:
! 134: /* TODO: check state in which hpcboot leaves uart */
! 135:
! 136: if (!sacom_attached) {
! 137: sacominit(bust, busa, speed);
! 138:
! 139: cn_tab = &sacom_consdev;
! 140: sacom_attached = 1;
! 141: }
! 142:
! 143: // splx(s);
! 144:
! 145: return(0);
! 146: }
! 147:
! 148: /* ARGSUSED */
! 149: int
! 150: sacomcngetc(dev_t dev)
! 151: {
! 152: /* TODO */
! 153: #if 0
! 154: u_char stat;
! 155: int c, s;
! 156:
! 157: #ifdef lint
! 158: stat = dev; if (stat) return (0);
! 159: #endif
! 160:
! 161: s = splhigh();
! 162: while (((stat = sacom_cn->sacom_lsr) & LSR_RXRDY) == 0)
! 163: ;
! 164: c = sacom_cn->sacom_data;
! 165: stat = sacom_cn->sacom_iir;
! 166: splx(s);
! 167: return (c);
! 168: #endif /* 0 */
! 169: return(0);
! 170: }
! 171:
! 172: /* ARGSUSED */
! 173: int
! 174: sacomfakecngetc(dev_t dev)
! 175: {
! 176: /* TODO */
! 177: return(0);
! 178: }
! 179:
! 180: /*
! 181: * Console kernel output character routine.
! 182: */
! 183: /* ARGSUSED */
! 184: void
! 185: sacomcnputc(dev_t dev, int c)
! 186: {
! 187: int timo;
! 188: // int s = splhigh();
! 189: if (sacom_attached == 0) {
! 190: /* XXX */
! 191: panic("sacomcnputc: write to unattached device");
! 192:
! 193: }
! 194: /* wait for any pending transmission to finish */
! 195: timo = 50000;
! 196: while ((bus_space_read_4(sacom_bust, sacom_bush, SACOM_SR1) & SR1_TBY) == 1 && --timo)
! 197: ;
! 198:
! 199: bus_space_write_4(sacom_bust, sacom_bush, SACOM_DR, c);
! 200:
! 201: /* wait for this transmission to complete */
! 202: timo = 1500000;
! 203: while ((bus_space_read_4(sacom_bust, sacom_bush, SACOM_SR1) & SR1_TBY) == 1 && --timo)
! 204: ;
! 205: /* XXX clear just generated intrs */
! 206: // splx(s);
! 207:
! 208: }
! 209: /* ARGSUSED */
! 210: void
! 211: sacomfakecnputc(dev_t dev, int c)
! 212: {
! 213: int timo;
! 214:
! 215: /* wait for any pending transmission to finish */
! 216: timo = 50000;
! 217: while (((*(uint32_t *)(sacom_base + SACOM_SR1)) & SR1_TBY) == 1 && --timo)
! 218: ;
! 219:
! 220: *(uint32_t *)(sacom_base + SACOM_DR) = c;
! 221:
! 222: /* wait for this transmission to complete */
! 223: timo = 1500000;
! 224: while (((*(uint32_t *)(sacom_base + SACOM_SR1)) & SR1_TBY) == 1 && --timo)
! 225: ;
! 226: }
CVSweb