com_puc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* $OpenBSD: com_puc.c,v 1.22 2014/09/14 14:17:25 jsg Exp $ */
  2. /*
  3. * Copyright (c) 1997 - 1999, Jason Downs. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name(s) of the author(s) nor the name OpenBSD
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
  18. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
  21. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #include <sys/param.h>
  30. #include <sys/systm.h>
  31. #include <sys/ioctl.h>
  32. #include <sys/selinfo.h>
  33. #include <sys/tty.h>
  34. #include <sys/conf.h>
  35. #include <sys/file.h>
  36. #include <sys/uio.h>
  37. #include <sys/kernel.h>
  38. #include <sys/syslog.h>
  39. #include <sys/device.h>
  40. #include <machine/intr.h>
  41. #include <machine/bus.h>
  42. #include <dev/pci/pucvar.h>
  43. #include "com.h"
  44. #include <dev/ic/comreg.h>
  45. #include <dev/ic/comvar.h>
  46. #include <dev/ic/ns16550reg.h>
  47. #define com_lcr com_cfcr
  48. int com_puc_match(struct device *, void *, void *);
  49. void com_puc_attach(struct device *, struct device *, void *);
  50. int com_puc_detach(struct device *, int);
  51. struct cfattach com_puc_ca = {
  52. sizeof(struct com_softc), com_puc_match,
  53. com_puc_attach, com_puc_detach, com_activate
  54. };
  55. int
  56. com_puc_match(parent, match, aux)
  57. struct device *parent;
  58. void *match, *aux;
  59. {
  60. struct puc_attach_args *pa = aux;
  61. if (PUC_IS_COM(pa->type))
  62. return(1);
  63. return(0);
  64. }
  65. void
  66. com_puc_attach(parent, self, aux)
  67. struct device *parent, *self;
  68. void *aux;
  69. {
  70. struct com_softc *sc = (void *)self;
  71. struct puc_attach_args *pa = aux;
  72. const char *intrstr;
  73. /* Grab a PCI interrupt. */
  74. intrstr = pa->intr_string(pa);
  75. sc->sc_ih = pa->intr_establish(pa, IPL_TTY, comintr, sc,
  76. sc->sc_dev.dv_xname);
  77. if (sc->sc_ih == NULL) {
  78. printf(": couldn't establish interrupt");
  79. if (intrstr != NULL)
  80. printf(" at %s", intrstr);
  81. printf("\n");
  82. return;
  83. }
  84. printf(" %s", intrstr);
  85. sc->sc_iot = pa->t;
  86. sc->sc_ioh = pa->h;
  87. sc->sc_iobase = pa->a;
  88. if (PUC_IS_COM_MUL(pa->type))
  89. sc->sc_frequency = COM_FREQ * PUC_COM_GET_MUL(pa->type);
  90. else
  91. sc->sc_frequency = COM_FREQ * (1 << PUC_COM_GET_POW2(pa->type));
  92. com_attach_subr(sc);
  93. }
  94. int
  95. com_puc_detach(struct device *self, int flags)
  96. {
  97. return com_detach(self, flags);
  98. }