asio.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* $OpenBSD: asio.c,v 1.10 2003/06/27 01:50:52 jason Exp $ */
  2. /*
  3. * Copyright (c) 2002 Jason L. Wright (jason@thought.net)
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  24. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * Effort sponsored in part by the Defense Advanced Research Projects
  28. * Agency (DARPA) and Air Force Research Laboratory, Air Force
  29. * Materiel Command, USAF, under agreement number F30602-01-2-0537.
  30. *
  31. */
  32. /*
  33. * Driver for Aurora 210SJ serial ports.
  34. */
  35. #include <sys/types.h>
  36. #include <sys/param.h>
  37. #include <sys/systm.h>
  38. #include <sys/kernel.h>
  39. #include <sys/device.h>
  40. #include <sys/conf.h>
  41. #include <sys/timeout.h>
  42. #include <sys/tty.h>
  43. #include <machine/bus.h>
  44. #include <machine/autoconf.h>
  45. #include <machine/openfirm.h>
  46. #include <dev/sbus/sbusvar.h>
  47. #include <dev/sbus/asioreg.h>
  48. #include <dev/ic/comvar.h>
  49. #include "asio.h"
  50. #define BAUD_BASE (1843200)
  51. struct asio_port {
  52. u_int8_t ap_inten;
  53. bus_space_handle_t ap_bh;
  54. struct device *ap_dev;
  55. };
  56. struct asio_softc {
  57. struct device sc_dev;
  58. bus_space_tag_t sc_bt;
  59. bus_space_handle_t sc_csr_h;
  60. void *sc_ih;
  61. struct asio_port sc_ports[2];
  62. int sc_nports;
  63. };
  64. struct asio_attach_args {
  65. char *aaa_name;
  66. int aaa_port;
  67. bus_space_tag_t aaa_iot;
  68. bus_space_handle_t aaa_ioh;
  69. u_int32_t aaa_pri;
  70. u_int8_t aaa_inten;
  71. };
  72. int asio_match(struct device *, void *, void *);
  73. void asio_attach(struct device *, struct device *, void *);
  74. int asio_print(void *, const char *);
  75. void asio_intr_enable(struct device *, u_int8_t);
  76. struct cfattach asio_ca = {
  77. sizeof(struct asio_softc), asio_match, asio_attach
  78. };
  79. struct cfdriver asio_cd = {
  80. NULL, "asio", DV_DULL
  81. };
  82. int
  83. asio_match(struct device *parent, void *match, void *aux)
  84. {
  85. struct sbus_attach_args *sa = aux;
  86. if (strcmp(sa->sa_name, "sio2") == 0)
  87. return (1);
  88. return (0);
  89. }
  90. void
  91. asio_attach(struct device *parent, struct device *self, void *aux)
  92. {
  93. struct asio_softc *sc = (void *)self;
  94. struct sbus_attach_args *sa = aux;
  95. struct asio_attach_args aaa;
  96. int i;
  97. char *model;
  98. sc->sc_bt = sa->sa_bustag;
  99. sc->sc_nports = 2;
  100. model = getpropstring(sa->sa_node, "model");
  101. if (model == NULL) {
  102. printf(": empty model, unsupported\n");
  103. return;
  104. }
  105. if (strcmp(model, "210sj") != 0) {
  106. printf(": unsupported model %s\n", model);
  107. return;
  108. }
  109. if (sa->sa_nreg < 3) {
  110. printf(": %d registers expected, got %d\n",
  111. 3, sa->sa_nreg);
  112. return;
  113. }
  114. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  115. sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
  116. 0, 0, &sc->sc_csr_h)) {
  117. printf(": couldn't map csr\n");
  118. return;
  119. }
  120. for (i = 0; i < sc->sc_nports; i++) {
  121. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[i + 1].sbr_slot,
  122. sa->sa_reg[i + 1].sbr_offset, sa->sa_reg[i + 1].sbr_size,
  123. 0, 0, &sc->sc_ports[i].ap_bh)) {
  124. printf(": couldn't map uart%d\n", i);
  125. return;
  126. }
  127. }
  128. sc->sc_ports[0].ap_inten = ASIO_CSR_SJ_UART0_INTEN;
  129. sc->sc_ports[1].ap_inten = ASIO_CSR_UART1_INTEN;
  130. printf(": %s\n", model);
  131. for (i = 0; i < sc->sc_nports; i++) {
  132. aaa.aaa_name = "com";
  133. aaa.aaa_port = i;
  134. aaa.aaa_iot = sc->sc_bt;
  135. aaa.aaa_ioh = sc->sc_ports[i].ap_bh;
  136. aaa.aaa_inten = sc->sc_ports[i].ap_inten;
  137. aaa.aaa_pri = sa->sa_intr[0].sbi_pri;
  138. sc->sc_ports[i].ap_dev = config_found(self, &aaa, asio_print);
  139. }
  140. }
  141. int
  142. asio_print(void *aux, const char *name)
  143. {
  144. struct asio_attach_args *aaa = aux;
  145. if (name != NULL)
  146. printf("%s at %s", aaa->aaa_name, name);
  147. printf(" port %d", aaa->aaa_port);
  148. return (UNCONF);
  149. }
  150. #if NCOM_ASIO > 0
  151. int com_asio_match(struct device *, void *, void *);
  152. void com_asio_attach(struct device *, struct device *, void *);
  153. struct cfattach com_asio_ca = {
  154. sizeof(struct com_softc), com_asio_match, com_asio_attach
  155. };
  156. void
  157. asio_intr_enable(struct device *dv, u_int8_t en)
  158. {
  159. struct asio_softc *sc = (struct asio_softc *)dv;
  160. u_int8_t csr;
  161. csr = bus_space_read_1(sc->sc_bt, sc->sc_csr_h, 0);
  162. csr &= ~(ASIO_CSR_SBUS_INT7 | ASIO_CSR_SBUS_INT6);
  163. csr |= ASIO_CSR_SBUS_INT5 | en;
  164. bus_space_write_1(sc->sc_bt, sc->sc_csr_h, 0, csr);
  165. }
  166. int
  167. com_asio_match(struct device *parent, void *match, void *aux)
  168. {
  169. return (1);
  170. }
  171. void
  172. com_asio_attach(struct device *parent, struct device *self, void *aux)
  173. {
  174. struct com_softc *sc = (struct com_softc *)self;
  175. struct asio_attach_args *aaa = aux;
  176. sc->sc_iot = aaa->aaa_iot;
  177. sc->sc_ioh = aaa->aaa_ioh;
  178. sc->sc_iobase = 0; /* XXX WTF is iobase for? It used to be the lower 32 bits of ioh's vaddr... */
  179. sc->sc_hwflags = 0;
  180. sc->sc_swflags = 0;
  181. sc->sc_frequency = BAUD_BASE;
  182. sc->sc_ih = bus_intr_establish(aaa->aaa_iot, aaa->aaa_pri,
  183. IPL_TTY, 0, comintr, sc, self->dv_xname);
  184. if (sc->sc_ih == NULL) {
  185. printf(": cannot allocate intr\n");
  186. return;
  187. }
  188. asio_intr_enable(parent, aaa->aaa_inten);
  189. com_attach_subr(sc);
  190. }
  191. #endif