pxa2x0_com.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* $OpenBSD: pxa2x0_com.c,v 1.12 2010/09/07 16:21:35 deraadt Exp $ */
  2. /* $NetBSD: pxa2x0_com.c,v 1.4 2003/07/15 00:24:55 lukem Exp $ */
  3. /*
  4. * Copyright 2003 Wasabi Systems, Inc.
  5. * All rights reserved.
  6. *
  7. * Written by Steve C. Woodford for Wasabi Systems, Inc.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed for the NetBSD Project by
  20. * Wasabi Systems, Inc.
  21. * 4. The name of Wasabi Systems, Inc. may not be used to endorse
  22. * or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
  29. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #ifndef COM_PXA2X0
  38. #error "You must use options COM_PXA2X0 to get PXA2x0 serial port support"
  39. #endif
  40. #include <sys/param.h>
  41. #include <sys/systm.h>
  42. #include <sys/device.h>
  43. #include <sys/tty.h>
  44. #include <machine/intr.h>
  45. #include <machine/bus.h>
  46. #include <dev/ic/comreg.h>
  47. #include <dev/ic/comvar.h>
  48. #define com_isr 8
  49. #define ISR_RECV (ISR_RXPL | ISR_XMODE | ISR_RCVEIR)
  50. #include <arm/xscale/pxa2x0reg.h>
  51. #include <arm/xscale/pxa2x0var.h>
  52. #ifdef __zaurus__
  53. #include <zaurus/dev/zaurus_scoopvar.h>
  54. #endif
  55. int pxauart_match(struct device *, void *, void *);
  56. void pxauart_attach(struct device *, struct device *, void *);
  57. int pxauart_activate(struct device *, int);
  58. struct cfattach com_pxaip_ca = {
  59. sizeof (struct com_softc), pxauart_match, pxauart_attach, NULL,
  60. pxauart_activate
  61. };
  62. int
  63. pxauart_match(struct device *parent, void *cf, void *aux)
  64. {
  65. struct pxaip_attach_args *pxa = aux;
  66. bus_space_tag_t bt = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
  67. bus_space_handle_t bh;
  68. int rv;
  69. switch (pxa->pxa_addr) {
  70. case PXA2X0_FFUART_BASE:
  71. if (pxa->pxa_intr != PXA2X0_INT_FFUART)
  72. return (0);
  73. break;
  74. case PXA2X0_STUART_BASE:
  75. if (pxa->pxa_intr != PXA2X0_INT_STUART)
  76. return (0);
  77. break;
  78. case PXA2X0_BTUART_BASE: /* XXX: Config file option ... */
  79. if (pxa->pxa_intr != PXA2X0_INT_BTUART)
  80. return (0);
  81. break;
  82. default:
  83. return (0);
  84. }
  85. pxa->pxa_size = 0x20;
  86. {
  87. extern bus_addr_t comconsaddr;
  88. if (comconsaddr == pxa->pxa_addr)
  89. return (1);
  90. }
  91. if (bus_space_map(bt, pxa->pxa_addr, pxa->pxa_size, 0, &bh))
  92. return (0);
  93. /* Make sure the UART is enabled */
  94. bus_space_write_1(bt, bh, com_ier, IER_EUART);
  95. rv = comprobe1(bt, bh);
  96. bus_space_unmap(bt, bh, pxa->pxa_size);
  97. return (rv);
  98. }
  99. void
  100. pxauart_attach(struct device *parent, struct device *self, void *aux)
  101. {
  102. struct com_softc *sc = (struct com_softc *)self;
  103. struct pxaip_attach_args *pxa = aux;
  104. sc->sc_iot = &pxa2x0_a4x_bs_tag; /* XXX: This sucks */
  105. sc->sc_iobase = pxa->pxa_addr;
  106. sc->sc_frequency = PXA2X0_COM_FREQ;
  107. sc->sc_uarttype = COM_UART_PXA2X0;
  108. #if 0
  109. if (com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) == 0 &&
  110. bus_space_map(sc->sc_iot, sc->sc_iobase, pxa->pxa_size, 0,
  111. &sc->sc_ioh)) {
  112. printf(": can't map registers\n");
  113. return;
  114. }
  115. #endif
  116. bus_space_map(sc->sc_iot, sc->sc_iobase, pxa->pxa_size, 0, &sc->sc_ioh);
  117. com_attach_subr(sc);
  118. (void)pxa2x0_intr_establish(pxa->pxa_intr, IPL_TTY, comintr,
  119. sc, sc->sc_dev.dv_xname);
  120. }
  121. int
  122. pxauart_activate(struct device *self, int act)
  123. {
  124. struct com_softc *sc = (struct com_softc *)self;
  125. bus_space_tag_t iot = sc->sc_iot;
  126. bus_space_handle_t ioh = sc->sc_ioh;
  127. struct tty *tp = sc->sc_tty;
  128. switch (act) {
  129. case DVACT_SUSPEND:
  130. #ifdef __zaurus__
  131. if (sc->enabled && ISSET(sc->sc_hwflags, COM_HW_SIR))
  132. scoop_set_irled(0);
  133. #endif
  134. break;
  135. case DVACT_RESUME:
  136. if (sc->enabled) {
  137. sc->sc_initialize = 1;
  138. comparam(tp, &tp->t_termios);
  139. bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
  140. if (ISSET(sc->sc_hwflags, COM_HW_SIR)) {
  141. #ifdef __zaurus__
  142. scoop_set_irled(1);
  143. #endif
  144. bus_space_write_1(iot, ioh, com_isr,
  145. ISR_RECV);
  146. }
  147. }
  148. break;
  149. }
  150. return 0;
  151. }