bwtwo.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* $OpenBSD: bwtwo.c,v 1.19 2013/10/20 20:07:30 miod 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. #include <sys/param.h>
  33. #include <sys/systm.h>
  34. #include <sys/kernel.h>
  35. #include <sys/errno.h>
  36. #include <sys/device.h>
  37. #include <sys/ioctl.h>
  38. #include <sys/malloc.h>
  39. #include <machine/bus.h>
  40. #include <machine/intr.h>
  41. #include <machine/autoconf.h>
  42. #include <machine/openfirm.h>
  43. #include <dev/sbus/sbusvar.h>
  44. #include <dev/wscons/wsconsio.h>
  45. #include <dev/wscons/wsdisplayvar.h>
  46. #include <dev/rasops/rasops.h>
  47. #include <machine/fbvar.h>
  48. #define BWTWO_CTRL_OFFSET 0x400000
  49. #define BWTWO_CTRL_SIZE (sizeof(u_int32_t) * 8)
  50. #define BWTWO_VID_OFFSET 0x800000
  51. #define BWTWO_VID_SIZE (1024 * 1024)
  52. #define FBC_CTRL 0x10 /* control */
  53. #define FBC_STAT 0x11 /* status */
  54. #define FBC_START 0x12 /* cursor start */
  55. #define FBC_END 0x13 /* cursor end */
  56. #define FBC_VCTRL 0x14 /* 12 bytes of timing goo */
  57. #define FBC_CTRL_IENAB 0x80 /* interrupt enable */
  58. #define FBC_CTRL_VENAB 0x40 /* video enable */
  59. #define FBC_CTRL_TIME 0x20 /* timing enable */
  60. #define FBC_CTRL_CURS 0x10 /* cursor compare enable */
  61. #define FBC_CTRL_XTAL 0x0c /* xtal select (0,1,2,test): */
  62. #define FBC_CTRL_XTAL_0 0x00 /* 0 */
  63. #define FBC_CTRL_XTAL_1 0x04 /* 0 */
  64. #define FBC_CTRL_XTAL_2 0x08 /* 0 */
  65. #define FBC_CTRL_XTAL_TEST 0x0c /* 0 */
  66. #define FBC_CTRL_DIV 0x03 /* divisor (1,2,3,4): */
  67. #define FBC_CTRL_DIV_1 0x00 /* / 1 */
  68. #define FBC_CTRL_DIV_2 0x01 /* / 2 */
  69. #define FBC_CTRL_DIV_3 0x02 /* / 3 */
  70. #define FBC_CTRL_DIV_4 0x03 /* / 4 */
  71. #define FBC_STAT_INTR 0x80 /* interrupt pending */
  72. #define FBC_STAT_RES 0x70 /* monitor sense: */
  73. #define FBC_STAT_RES_1024 0x10 /* 1024x768 */
  74. #define FBC_STAT_RES_1280 0x40 /* 1280x1024 */
  75. #define FBC_STAT_RES_1152 0x30 /* 1152x900 */
  76. #define FBC_STAT_RES_1152A 0x40 /* 1152x900x76, A */
  77. #define FBC_STAT_RES_1600 0x50 /* 1600x1200 */
  78. #define FBC_STAT_RES_1152B 0x60 /* 1152x900x86, B */
  79. #define FBC_STAT_ID 0x0f /* id mask: */
  80. #define FBC_STAT_ID_COLOR 0x01 /* color */
  81. #define FBC_STAT_ID_MONO 0x02 /* monochrome */
  82. #define FBC_STAT_ID_MONOECL 0x03 /* monochrome, ecl */
  83. #define FBC_READ(sc, reg) \
  84. bus_space_read_1((sc)->sc_bustag, (sc)->sc_ctrl_regs, (reg))
  85. #define FBC_WRITE(sc, reg, val) \
  86. bus_space_write_1((sc)->sc_bustag, (sc)->sc_ctrl_regs, (reg), (val))
  87. struct bwtwo_softc {
  88. struct sunfb sc_sunfb;
  89. bus_space_tag_t sc_bustag;
  90. bus_addr_t sc_paddr;
  91. bus_space_handle_t sc_ctrl_regs;
  92. bus_space_handle_t sc_vid_regs;
  93. int sc_nscreens;
  94. };
  95. int bwtwo_ioctl(void *, u_long, caddr_t, int, struct proc *);
  96. paddr_t bwtwo_mmap(void *, off_t, int);
  97. int bwtwo_is_console(int);
  98. void bwtwo_burner(void *, u_int, u_int);
  99. struct wsdisplay_accessops bwtwo_accessops = {
  100. .ioctl = bwtwo_ioctl,
  101. .mmap = bwtwo_mmap,
  102. .burn_screen = bwtwo_burner
  103. };
  104. int bwtwomatch(struct device *, void *, void *);
  105. void bwtwoattach(struct device *, struct device *, void *);
  106. struct cfattach bwtwo_ca = {
  107. sizeof (struct bwtwo_softc), bwtwomatch, bwtwoattach
  108. };
  109. struct cfdriver bwtwo_cd = {
  110. NULL, "bwtwo", DV_DULL
  111. };
  112. int
  113. bwtwomatch(parent, vcf, aux)
  114. struct device *parent;
  115. void *vcf, *aux;
  116. {
  117. struct cfdata *cf = vcf;
  118. struct sbus_attach_args *sa = aux;
  119. return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
  120. }
  121. void
  122. bwtwoattach(parent, self, aux)
  123. struct device *parent, *self;
  124. void *aux;
  125. {
  126. struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
  127. struct sbus_attach_args *sa = aux;
  128. int node, console;
  129. const char *nam;
  130. node = sa->sa_node;
  131. sc->sc_bustag = sa->sa_bustag;
  132. sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
  133. fb_setsize(&sc->sc_sunfb, 1, 1152, 900, node, 0);
  134. if (sa->sa_nreg != 1) {
  135. printf(": expected %d registers, got %d\n", 1, sa->sa_nreg);
  136. goto fail;
  137. }
  138. /*
  139. * Map just CTRL and video RAM.
  140. */
  141. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  142. sa->sa_reg[0].sbr_offset + BWTWO_CTRL_OFFSET,
  143. BWTWO_CTRL_SIZE, 0, 0, &sc->sc_ctrl_regs) != 0) {
  144. printf(": cannot map ctrl registers\n");
  145. goto fail_ctrl;
  146. }
  147. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  148. sa->sa_reg[0].sbr_offset + BWTWO_VID_OFFSET,
  149. sc->sc_sunfb.sf_fbsize, BUS_SPACE_MAP_LINEAR,
  150. 0, &sc->sc_vid_regs) != 0) {
  151. printf(": cannot map vid registers\n");
  152. goto fail_vid;
  153. }
  154. nam = getpropstring(node, "model");
  155. if (*nam == '\0')
  156. nam = sa->sa_name;
  157. printf(": %s", nam);
  158. console = bwtwo_is_console(node);
  159. bwtwo_burner(sc, 1, 0);
  160. printf(", %dx%d\n", sc->sc_sunfb.sf_width, sc->sc_sunfb.sf_height);
  161. sc->sc_sunfb.sf_ro.ri_bits = (void *)bus_space_vaddr(sc->sc_bustag,
  162. sc->sc_vid_regs);
  163. sc->sc_sunfb.sf_ro.ri_hw = sc;
  164. fbwscons_init(&sc->sc_sunfb, 0, console);
  165. if (console)
  166. fbwscons_console_init(&sc->sc_sunfb, -1);
  167. fbwscons_attach(&sc->sc_sunfb, &bwtwo_accessops, console);
  168. return;
  169. fail_vid:
  170. bus_space_unmap(sa->sa_bustag, sc->sc_ctrl_regs, BWTWO_CTRL_SIZE);
  171. fail_ctrl:
  172. fail:
  173. ;
  174. }
  175. int
  176. bwtwo_ioctl(v, cmd, data, flags, p)
  177. void *v;
  178. u_long cmd;
  179. caddr_t data;
  180. int flags;
  181. struct proc *p;
  182. {
  183. struct bwtwo_softc *sc = v;
  184. struct wsdisplay_fbinfo *wdf;
  185. switch (cmd) {
  186. case WSDISPLAYIO_GTYPE:
  187. *(u_int *)data = WSDISPLAY_TYPE_SUNBW;
  188. break;
  189. case WSDISPLAYIO_GINFO:
  190. wdf = (void *)data;
  191. wdf->height = sc->sc_sunfb.sf_height;
  192. wdf->width = sc->sc_sunfb.sf_width;
  193. wdf->depth = sc->sc_sunfb.sf_depth;
  194. wdf->cmsize = 0;
  195. break;
  196. case WSDISPLAYIO_LINEBYTES:
  197. *(u_int *)data = sc->sc_sunfb.sf_linebytes;
  198. break;
  199. case WSDISPLAYIO_GETCMAP:
  200. case WSDISPLAYIO_PUTCMAP:
  201. break;
  202. case WSDISPLAYIO_SVIDEO:
  203. case WSDISPLAYIO_GVIDEO:
  204. break;
  205. case WSDISPLAYIO_GCURPOS:
  206. case WSDISPLAYIO_SCURPOS:
  207. case WSDISPLAYIO_GCURMAX:
  208. case WSDISPLAYIO_GCURSOR:
  209. case WSDISPLAYIO_SCURSOR:
  210. default:
  211. return -1; /* not supported yet */
  212. }
  213. return (0);
  214. }
  215. paddr_t
  216. bwtwo_mmap(v, offset, prot)
  217. void *v;
  218. off_t offset;
  219. int prot;
  220. {
  221. struct bwtwo_softc *sc = v;
  222. if (offset & PGOFSET)
  223. return (-1);
  224. if (offset >= 0 && offset < sc->sc_sunfb.sf_fbsize)
  225. return (bus_space_mmap(sc->sc_bustag, sc->sc_paddr,
  226. BWTWO_VID_OFFSET + offset, prot, BUS_SPACE_MAP_LINEAR));
  227. return (-1);
  228. }
  229. int
  230. bwtwo_is_console(node)
  231. int node;
  232. {
  233. extern int fbnode;
  234. return (fbnode == node);
  235. }
  236. void
  237. bwtwo_burner(vsc, on, flags)
  238. void *vsc;
  239. u_int on, flags;
  240. {
  241. struct bwtwo_softc *sc = vsc;
  242. int s;
  243. u_int8_t fbc;
  244. s = splhigh();
  245. fbc = FBC_READ(sc, FBC_CTRL);
  246. if (on)
  247. fbc |= FBC_CTRL_VENAB | FBC_CTRL_TIME;
  248. else {
  249. fbc &= ~FBC_CTRL_VENAB;
  250. if (flags & WSDISPLAY_BURN_VBLANK)
  251. fbc &= ~FBC_CTRL_TIME;
  252. }
  253. FBC_WRITE(sc, FBC_CTRL, fbc);
  254. splx(s);
  255. }