magmareg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* $OpenBSD: magmareg.h,v 1.9 2008/11/29 01:55:06 ray Exp $ */
  2. /*-
  3. * Copyright (c) 1998 Iain Hibbert
  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 WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifdef MAGMA_DEBUG
  27. #define dprintf(x) printf x
  28. #else
  29. #define dprintf(x)
  30. #endif
  31. /* The mapping of minor device number -> card and port is done as
  32. * follows by default:
  33. *
  34. * +---+---+---+---+---+---+---+---+
  35. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  36. * +---+---+---+---+---+---+---+---+
  37. * | | | | | | | |
  38. * | | | | +---+---+---+---> port number
  39. * | | | |
  40. * | | | +-------------------> dialout (on tty ports)
  41. * | | |
  42. * | | +-----------------------> unused
  43. * | |
  44. * +---+---------------------------> card number
  45. *
  46. */
  47. #define MAGMA_MAX_CARDS 4
  48. #define MAGMA_MAX_TTY 16
  49. #define MAGMA_MAX_BPP 2
  50. #define MAGMA_MAX_CD1400 4
  51. #define MAGMA_MAX_CD1190 2
  52. #define MAGMA_CARD(x) ((minor(x) >> 6) & 0x03)
  53. #define MAGMA_PORT(x) (minor(x) & 0x0f)
  54. #define MTTY_DIALOUT(x) (minor(x) & 0x10)
  55. /*
  56. * Supported Card Types
  57. */
  58. struct magma_board_info {
  59. const char *mb_sbusname; /* sbus name */
  60. const char *mb_name; /* cardname to match against */
  61. const char *mb_realname; /* english card name */
  62. int mb_nser; /* number of serial ports */
  63. int mb_npar; /* number of parallel ports */
  64. int mb_ncd1400; /* number of CD1400 chips */
  65. int mb_svcackr; /* svcackr offset */
  66. int mb_svcackt; /* svcackt offset */
  67. int mb_svcackm; /* svcackm offset */
  68. int mb_cd1400[MAGMA_MAX_CD1400];/* cd1400 chip register offsets */
  69. int mb_ncd1190; /* number of CD1190 chips */
  70. int mb_cd1190[MAGMA_MAX_CD1190];/* cd1190 chip register offsets */
  71. };
  72. /*
  73. * cd1400 chip data
  74. */
  75. struct cd1400 {
  76. bus_space_handle_t cd_regh; /* chip register handle */
  77. bus_space_tag_t cd_regt; /* chip register tag */
  78. int cd_chiprev; /* chip revision */
  79. int cd_clock; /* clock speed in MHz */
  80. int cd_parmode; /* parallel mode operation */
  81. };
  82. /*
  83. * cd1190 chip data
  84. */
  85. struct cd1190 {
  86. bus_space_handle_t cd_regh; /* chip register handle */
  87. bus_space_tag_t cd_regt; /* chip register tag */
  88. int cd_chiprev; /* chip revision */
  89. };
  90. /* software state for each card */
  91. struct magma_softc {
  92. struct device ms_dev; /* required. must be first in softc */
  93. bus_space_tag_t sc_bustag; /* our bus tag */
  94. bus_space_handle_t sc_iohandle; /* whole card registers */
  95. void *sc_ih; /* interrupt vector */
  96. void *sc_sih; /* softintr vector */
  97. /* cd1400 chip info */
  98. int ms_ncd1400;
  99. struct cd1400 ms_cd1400[MAGMA_MAX_CD1400];
  100. bus_space_handle_t sc_svcackrh; /* CD1400 service acknowledge receive */
  101. bus_space_handle_t sc_svcackth; /* CD1400 service acknowledge transmit */
  102. bus_space_handle_t sc_svcackmh; /* CD1400 service acknowledge modem */
  103. /* cd1190 chip info */
  104. int ms_ncd1190;
  105. struct cd1190 ms_cd1190[MAGMA_MAX_CD1190];
  106. const struct magma_board_info *ms_board; /* what am I? */
  107. struct mtty_softc *ms_mtty;
  108. struct mbpp_softc *ms_mbpp;
  109. struct intrhand ms_hardint; /* hard interrupt handler */
  110. struct intrhand ms_softint; /* soft interrupt handler */
  111. };
  112. #define MTTY_RBUF_SIZE (2 * 512)
  113. #define MTTY_RX_FIFO_THRESHOLD 6
  114. #define MTTY_RX_DTR_THRESHOLD 9
  115. struct mtty_port {
  116. struct cd1400 *mp_cd1400; /* ptr to chip */
  117. int mp_channel; /* and channel */
  118. struct tty *mp_tty;
  119. int mp_openflags; /* default tty flags */
  120. int mp_flags; /* port flags */
  121. int mp_carrier; /* state of carrier */
  122. u_char *mp_rbuf; /* ring buffer start */
  123. u_char *mp_rend; /* ring buffer end */
  124. u_char *mp_rget; /* ring buffer read pointer */
  125. u_char *mp_rput; /* ring buffer write pointer */
  126. u_char *mp_txp; /* transmit character pointer */
  127. int mp_txc; /* transmit character counter */
  128. };
  129. #define MTTYF_CARRIER_CHANGED (1<<0)
  130. #define MTTYF_SET_BREAK (1<<1)
  131. #define MTTYF_CLR_BREAK (1<<2)
  132. #define MTTYF_DONE (1<<3)
  133. #define MTTYF_STOP (1<<4)
  134. #define MTTYF_RING_OVERFLOW (1<<5)
  135. struct mtty_softc {
  136. struct device ms_dev; /* device info */
  137. int ms_nports; /* tty ports */
  138. struct mtty_port ms_port[MAGMA_MAX_TTY];
  139. };
  140. #define MBPP_RX_FIFO_THRESHOLD 25
  141. struct mbpp_port {
  142. struct cd1400 *mp_cd1400; /* for LC2+1Sp card */
  143. struct cd1190 *mp_cd1190; /* all the others */
  144. int mp_flags;
  145. struct bpp_param mp_param;
  146. #define mp_burst mp_param.bp_burst
  147. #define mp_timeout mp_param.bp_timeout
  148. #define mp_delay mp_param.bp_delay
  149. u_char *mp_ptr; /* pointer to io data */
  150. int mp_cnt; /* count of io chars */
  151. struct timeout mp_timeout_tmo; /* for mbpp_timeout() */
  152. struct timeout mp_start_tmo; /* for mbpp_start() */
  153. };
  154. #define MBPPF_OPEN (1<<0)
  155. #define MBPPF_TIMEOUT (1<<1)
  156. #define MBPPF_UIO (1<<2)
  157. #define MBPPF_DELAY (1<<3)
  158. #define MBPPF_WAKEUP (1<<4)
  159. struct mbpp_softc {
  160. struct device ms_dev; /* device info */
  161. int ms_nports; /* parallel ports */
  162. struct mbpp_port ms_port[MAGMA_MAX_BPP];
  163. };
  164. /* internal function prototypes */
  165. int cd1400_compute_baud(speed_t, int, int *, int *);
  166. __inline void cd1400_write_ccr(struct cd1400 *, u_char);
  167. __inline u_char cd1400_read_reg(struct cd1400 *, int);
  168. __inline void cd1400_write_reg(struct cd1400 *, int, u_char);
  169. void cd1400_enable_transmitter(struct cd1400 *, int);
  170. int magma_match(struct device *, void *, void *);
  171. void magma_attach(struct device *, struct device *, void *);
  172. int magma_hard(void *);
  173. void magma_soft(void *);
  174. int mtty_match(struct device *, void *, void *);
  175. void mtty_attach(struct device *, struct device *, void *);
  176. int mtty_modem_control(struct mtty_port *, int, int);
  177. int mtty_param(struct tty *, struct termios *);
  178. void mtty_start(struct tty *);
  179. int mbpp_match(struct device *, void *, void *);
  180. void mbpp_attach(struct device *, struct device *, void *);
  181. int mbpp_rw(dev_t, struct uio *);
  182. void mbpp_timeout(void *);
  183. void mbpp_start(void *);
  184. int mbpp_send(struct mbpp_port *, caddr_t, int);
  185. int mbpp_recv(struct mbpp_port *, caddr_t, int);
  186. int mbpp_hztoms(int);
  187. int mbpp_mstohz(int);
  188. #define CD1400_REGMAPSIZE 0x80
  189. #define CD1190_REGMAPSIZE 0x20