apio.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* $OpenBSD: apio.c,v 1.7 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 parallel 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/lptvar.h>
  49. #include "apio.h"
  50. #include "lpt.h"
  51. struct apio_softc {
  52. struct device sc_dev;
  53. bus_space_tag_t sc_bt;
  54. bus_space_handle_t sc_csr_h;
  55. bus_space_handle_t sc_clk_h;
  56. bus_space_handle_t sc_lpt_h;
  57. void *sc_ih;
  58. struct device *sc_port;
  59. };
  60. struct apio_attach_args {
  61. char *aaa_name;
  62. bus_space_tag_t aaa_iot;
  63. bus_space_handle_t aaa_ioh;
  64. bus_space_handle_t aaa_clkh;
  65. u_int32_t aaa_pri;
  66. u_int8_t aaa_inten;
  67. };
  68. int apio_match(struct device *, void *, void *);
  69. void apio_attach(struct device *, struct device *, void *);
  70. int apio_print(void *, const char *);
  71. void apio_intr_enable(struct device *, u_int8_t);
  72. struct cfattach apio_ca = {
  73. sizeof(struct apio_softc), apio_match, apio_attach
  74. };
  75. struct cfdriver apio_cd = {
  76. NULL, "apio", DV_DULL
  77. };
  78. int
  79. apio_match(struct device *parent, void *match, void *aux)
  80. {
  81. struct sbus_attach_args *sa = aux;
  82. if (strcmp(sa->sa_name, "pio1") == 0)
  83. return (1);
  84. return (0);
  85. }
  86. void
  87. apio_attach(struct device *parent, struct device *self, void *aux)
  88. {
  89. struct apio_softc *sc = (void *)self;
  90. struct sbus_attach_args *sa = aux;
  91. struct apio_attach_args aaa;
  92. char *model;
  93. sc->sc_bt = sa->sa_bustag;
  94. model = getpropstring(sa->sa_node, "model");
  95. if (model == NULL) {
  96. printf(": empty model, unsupported\n");
  97. return;
  98. }
  99. if (strcmp(model, "210sj") != 0) {
  100. printf(": unsupported model %s\n", model);
  101. return;
  102. }
  103. if (sa->sa_nreg < 3) {
  104. printf(": %d registers expected, got %d\n",
  105. 3, sa->sa_nreg);
  106. return;
  107. }
  108. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  109. sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size,
  110. 0, 0, &sc->sc_csr_h)) {
  111. printf(": couldn't map csr\n");
  112. return;
  113. }
  114. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[1].sbr_slot,
  115. sa->sa_reg[1].sbr_offset, sa->sa_reg[1].sbr_size,
  116. 0, 0, &sc->sc_clk_h)) {
  117. printf(": couldn't map clk\n");
  118. return;
  119. }
  120. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[2].sbr_slot,
  121. sa->sa_reg[2].sbr_offset, sa->sa_reg[2].sbr_size,
  122. 0, 0, &sc->sc_lpt_h)) {
  123. printf(": couldn't map clk\n");
  124. return;
  125. }
  126. printf(": %s\n", model);
  127. aaa.aaa_name = "lpt";
  128. aaa.aaa_iot = sc->sc_bt;
  129. aaa.aaa_ioh = sc->sc_lpt_h;
  130. aaa.aaa_clkh = sc->sc_clk_h;
  131. aaa.aaa_inten = ASIO_CSR_SJ_PAR_INTEN;
  132. aaa.aaa_pri = sa->sa_intr[0].sbi_pri;
  133. sc->sc_port = config_found(self, &aaa, apio_print);
  134. }
  135. int
  136. apio_print(void *aux, const char *name)
  137. {
  138. struct apio_attach_args *aaa = aux;
  139. if (name != NULL)
  140. printf("%s at %s", aaa->aaa_name, name);
  141. return (UNCONF);
  142. }
  143. #if NLPT_APIO > 0
  144. int lpt_apio_match(struct device *, void *, void *);
  145. void lpt_apio_attach(struct device *, struct device *, void *);
  146. int lpt_apio_intr(void *);
  147. struct lpt_apio_softc {
  148. struct lpt_softc sc_lpt;
  149. bus_space_handle_t sc_clk_h;
  150. void *sc_ih;
  151. };
  152. struct cfattach lpt_apio_ca = {
  153. sizeof(struct lpt_apio_softc), lpt_apio_match, lpt_apio_attach
  154. };
  155. void
  156. apio_intr_enable(struct device *dv, u_int8_t en)
  157. {
  158. struct apio_softc *sc = (struct apio_softc *)dv;
  159. u_int8_t csr;
  160. csr = bus_space_read_1(sc->sc_bt, sc->sc_csr_h, 0);
  161. csr &= ~(ASIO_CSR_SBUS_INT7 | ASIO_CSR_SBUS_INT6);
  162. csr |= ASIO_CSR_SBUS_INT5 | en;
  163. bus_space_write_1(sc->sc_bt, sc->sc_csr_h, 0, csr);
  164. }
  165. int
  166. lpt_apio_match(struct device *parent, void *match, void *aux)
  167. {
  168. return (1);
  169. }
  170. void
  171. lpt_apio_attach(struct device *parent, struct device *self, void *aux)
  172. {
  173. struct lpt_apio_softc *sc = (struct lpt_apio_softc *)self;
  174. struct apio_attach_args *aaa = aux;
  175. sc->sc_lpt.sc_state = 0;
  176. sc->sc_lpt.sc_iot = aaa->aaa_iot;
  177. sc->sc_lpt.sc_ioh = aaa->aaa_ioh;
  178. sc->sc_clk_h = aaa->aaa_clkh;
  179. sc->sc_ih = bus_intr_establish(aaa->aaa_iot, aaa->aaa_pri,
  180. IPL_TTY, 0, lpt_apio_intr, sc, self->dv_xname);
  181. if (sc->sc_ih == NULL) {
  182. printf(": cannot allocate intr\n");
  183. return;
  184. }
  185. apio_intr_enable(parent, aaa->aaa_inten);
  186. lpt_attach_common(&sc->sc_lpt);
  187. }
  188. int
  189. lpt_apio_intr(void *vsc)
  190. {
  191. struct lpt_apio_softc *sc = vsc;
  192. int r;
  193. r = lptintr(&sc->sc_lpt);
  194. bus_space_read_1(sc->sc_lpt.sc_iot, sc->sc_clk_h, 0);
  195. return (r);
  196. }
  197. #endif