addcom_isa.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* $OpenBSD: addcom_isa.c,v 1.6 2002/03/14 01:26:56 millert Exp $ */
  2. /* $NetBSD: addcom_isa.c,v 1.2 2000/04/21 20:13:41 explorer Exp $ */
  3. /*
  4. * Copyright (c) 2000 Michael Graff. All rights reserved.
  5. * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
  6. * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
  7. *
  8. * This code is derived from public-domain software written by
  9. * Roland McGrath, and information provided by David Muir Sharnoff.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. All advertising materials mentioning features or use of this software
  20. * must display the following acknowledgement:
  21. * This product includes software developed by Charles M. Hannum.
  22. * 4. The name of the author may not be used to endorse or promote products
  23. * derived from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  26. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  27. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  28. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  30. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. /*
  37. * This code was written and tested with the Addonics FlexPort 8S.
  38. * It has 8 ports, using 16650-compatible chips, sharing a single
  39. * interrupt.
  40. *
  41. * An interrupt status register exists at 0x240, according to the
  42. * skimpy documentation supplied. It doesn't change depending on
  43. * io base address, so only one of these cards can ever be used at
  44. * a time.
  45. *
  46. * NOTE: the status register does not appear to work as advertised,
  47. * so instead we depend on the slave devices being intelligent enough
  48. * to determine whether they interrupted or not.
  49. *
  50. * This card is different from the boca or other cards in that ports
  51. * 0..5 are from addresses 0x108..0x137, and 6..7 are from 0x200..0x20f,
  52. * making a gap that the other cards do not have.
  53. *
  54. * The addresses which are documented are 0x108, 0x1108, 0x1d08, and
  55. * 0x8508, for the base (port 0) address.
  56. *
  57. * --Michael <explorer@netbsd.org> -- April 21, 2000
  58. */
  59. #include <sys/param.h>
  60. #include <sys/systm.h>
  61. #include <sys/device.h>
  62. #include <sys/termios.h>
  63. #include <machine/bus.h>
  64. #include <machine/intr.h>
  65. #include <dev/ic/comreg.h>
  66. #include <dev/ic/comvar.h>
  67. #include <dev/isa/isavar.h>
  68. #define NSLAVES 8
  69. /*
  70. * Grr. This card always uses 0x420 for the status register, regardless
  71. * of io base address.
  72. */
  73. #define STATUS_IOADDR 0x420
  74. #define STATUS_SIZE 8 /* May be bogus... */
  75. struct addcom_softc {
  76. struct device sc_dev;
  77. void *sc_ih;
  78. bus_space_tag_t sc_iot;
  79. bus_addr_t sc_iobase;
  80. int sc_alive[NSLAVES];
  81. void *sc_slaves[NSLAVES]; /* com device unit numbers */
  82. bus_space_handle_t sc_slaveioh[NSLAVES];
  83. bus_space_handle_t sc_statusioh;
  84. };
  85. #define SLAVE_IOBASE_OFFSET 0x108
  86. static int slave_iobases[8] = {
  87. 0x108, /* port 0, base port */
  88. 0x110,
  89. 0x118,
  90. 0x120,
  91. 0x128,
  92. 0x130,
  93. 0x200, /* port 7, note address skip... */
  94. 0x208
  95. };
  96. int addcomprobe(struct device *, void *, void *);
  97. void addcomattach(struct device *, struct device *, void *);
  98. int addcomintr(void *);
  99. int addcomprint(void *, const char *);
  100. struct cfattach addcom_isa_ca = {
  101. sizeof(struct addcom_softc), addcomprobe, addcomattach,
  102. };
  103. struct cfdriver addcom_cd = {
  104. NULL, "addcom", DV_TTY
  105. };
  106. int
  107. addcomprobe(parent, self, aux)
  108. struct device *parent;
  109. void *self, *aux;
  110. {
  111. struct isa_attach_args *ia = aux;
  112. int iobase = ia->ia_iobase;
  113. bus_space_tag_t iot = ia->ia_iot;
  114. bus_space_handle_t ioh;
  115. int i, rv = 1;
  116. /*
  117. * Do the normal com probe for the first UART and assume
  118. * its presence, and the ability to map the other UARTS,
  119. * means there is a multiport board there.
  120. * XXX Needs more robustness.
  121. */
  122. /* Disallow wildcarded i/o address. */
  123. if (ia->ia_iobase == -1 /* ISACF_PORT_DEFAULT */)
  124. return (0);
  125. /* if the first port is in use as console, then it. */
  126. if (iobase == comconsaddr && !comconsattached)
  127. goto checkmappings;
  128. if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
  129. rv = 0;
  130. goto out;
  131. }
  132. rv = comprobe1(iot, ioh);
  133. bus_space_unmap(iot, ioh, COM_NPORTS);
  134. if (rv == 0)
  135. goto out;
  136. checkmappings:
  137. for (i = 1; i < NSLAVES; i++) {
  138. iobase += slave_iobases[i] - slave_iobases[i - 1];
  139. if (iobase == comconsaddr && !comconsattached)
  140. continue;
  141. if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
  142. rv = 0;
  143. goto out;
  144. }
  145. bus_space_unmap(iot, ioh, COM_NPORTS);
  146. }
  147. out:
  148. if (rv)
  149. ia->ia_iosize = NSLAVES * COM_NPORTS;
  150. return (rv);
  151. }
  152. int
  153. addcomprint(aux, pnp)
  154. void *aux;
  155. const char *pnp;
  156. {
  157. struct commulti_attach_args *ca = aux;
  158. if (pnp)
  159. printf("com at %s", pnp);
  160. printf(" slave %d", ca->ca_slave);
  161. return (UNCONF);
  162. }
  163. void
  164. addcomattach(parent, self, aux)
  165. struct device *parent, *self;
  166. void *aux;
  167. {
  168. struct addcom_softc *sc = (void *)self;
  169. struct isa_attach_args *ia = aux;
  170. struct commulti_attach_args ca;
  171. bus_space_tag_t iot = ia->ia_iot;
  172. bus_addr_t iobase;
  173. int i;
  174. sc->sc_iot = ia->ia_iot;
  175. sc->sc_iobase = ia->ia_iobase;
  176. /* Disallow wildcard interrupt. */
  177. if (ia->ia_irq == IRQUNK) {
  178. printf(": wildcard interrupt not supported\n");
  179. return;
  180. }
  181. sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
  182. IPL_TTY, addcomintr, sc, sc->sc_dev.dv_xname);
  183. if (sc->sc_ih == NULL) {
  184. printf(": can't establish interrupt\n");
  185. return;
  186. }
  187. if (bus_space_map(iot, STATUS_IOADDR, STATUS_SIZE,
  188. 0, &sc->sc_statusioh)) {
  189. printf(": can't map status space\n");
  190. return;
  191. }
  192. for (i = 0; i < NSLAVES; i++) {
  193. iobase = sc->sc_iobase
  194. + slave_iobases[i]
  195. - SLAVE_IOBASE_OFFSET;
  196. if ((!(iobase == comconsaddr && !comconsattached)) &&
  197. bus_space_map(iot, iobase, COM_NPORTS, 0,
  198. &sc->sc_slaveioh[i])) {
  199. printf(": can't map i/o space for slave %d\n", i);
  200. return;
  201. }
  202. }
  203. printf("\n");
  204. for (i = 0; i < NSLAVES; i++) {
  205. ca.ca_slave = i;
  206. ca.ca_iot = sc->sc_iot;
  207. ca.ca_ioh = sc->sc_slaveioh[i];
  208. ca.ca_iobase = sc->sc_iobase
  209. + slave_iobases[i]
  210. - SLAVE_IOBASE_OFFSET;
  211. ca.ca_noien = 0;
  212. sc->sc_slaves[i] = config_found(self, &ca, addcomprint);
  213. if (sc->sc_slaves[i] != NULL)
  214. sc->sc_alive[i] = 1;
  215. }
  216. }
  217. int
  218. addcomintr(arg)
  219. void *arg;
  220. {
  221. struct addcom_softc *sc = arg;
  222. int intrd, r = 0, i;
  223. do {
  224. intrd = 0;
  225. for (i = 0; i < NSLAVES; i++)
  226. if (sc->sc_alive[i] && comintr(sc->sc_slaves[i])) {
  227. r = 1;
  228. intrd = 1;
  229. }
  230. } while (intrd);
  231. return (r);
  232. }