bt431.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * linux/drivers/video/bt431.h
  3. *
  4. * Copyright 2003 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file COPYING in the main directory of this
  8. * archive for more details.
  9. */
  10. #include <linux/types.h>
  11. /*
  12. * Bt431 cursor generator registers, 32-bit aligned.
  13. * Two twin Bt431 are used on the DECstation's PMAG-AA.
  14. */
  15. struct bt431_regs {
  16. volatile u16 addr_lo;
  17. u16 pad0;
  18. volatile u16 addr_hi;
  19. u16 pad1;
  20. volatile u16 addr_cmap;
  21. u16 pad2;
  22. volatile u16 addr_reg;
  23. u16 pad3;
  24. };
  25. static inline u16 bt431_set_value(u8 val)
  26. {
  27. return ((val << 8) | (val & 0xff)) & 0xffff;
  28. }
  29. static inline u8 bt431_get_value(u16 val)
  30. {
  31. return val & 0xff;
  32. }
  33. /*
  34. * Additional registers addressed indirectly.
  35. */
  36. #define BT431_REG_CMD 0x0000
  37. #define BT431_REG_CXLO 0x0001
  38. #define BT431_REG_CXHI 0x0002
  39. #define BT431_REG_CYLO 0x0003
  40. #define BT431_REG_CYHI 0x0004
  41. #define BT431_REG_WXLO 0x0005
  42. #define BT431_REG_WXHI 0x0006
  43. #define BT431_REG_WYLO 0x0007
  44. #define BT431_REG_WYHI 0x0008
  45. #define BT431_REG_WWLO 0x0009
  46. #define BT431_REG_WWHI 0x000a
  47. #define BT431_REG_WHLO 0x000b
  48. #define BT431_REG_WHHI 0x000c
  49. #define BT431_REG_CRAM_BASE 0x0000
  50. #define BT431_REG_CRAM_END 0x01ff
  51. /*
  52. * Command register.
  53. */
  54. #define BT431_CMD_CURS_ENABLE 0x40
  55. #define BT431_CMD_XHAIR_ENABLE 0x20
  56. #define BT431_CMD_OR_CURSORS 0x10
  57. #define BT431_CMD_AND_CURSORS 0x00
  58. #define BT431_CMD_1_1_MUX 0x00
  59. #define BT431_CMD_4_1_MUX 0x04
  60. #define BT431_CMD_5_1_MUX 0x08
  61. #define BT431_CMD_xxx_MUX 0x0c
  62. #define BT431_CMD_THICK_1 0x00
  63. #define BT431_CMD_THICK_3 0x01
  64. #define BT431_CMD_THICK_5 0x02
  65. #define BT431_CMD_THICK_7 0x03
  66. static inline void bt431_select_reg(struct bt431_regs *regs, int ir)
  67. {
  68. /*
  69. * The compiler splits the write in two bytes without these
  70. * helper variables.
  71. */
  72. volatile u16 *lo = &(regs->addr_lo);
  73. volatile u16 *hi = &(regs->addr_hi);
  74. mb();
  75. *lo = bt431_set_value(ir & 0xff);
  76. wmb();
  77. *hi = bt431_set_value((ir >> 8) & 0xff);
  78. }
  79. /* Autoincrement read/write. */
  80. static inline u8 bt431_read_reg_inc(struct bt431_regs *regs)
  81. {
  82. /*
  83. * The compiler splits the write in two bytes without the
  84. * helper variable.
  85. */
  86. volatile u16 *r = &(regs->addr_reg);
  87. mb();
  88. return bt431_get_value(*r);
  89. }
  90. static inline void bt431_write_reg_inc(struct bt431_regs *regs, u8 value)
  91. {
  92. /*
  93. * The compiler splits the write in two bytes without the
  94. * helper variable.
  95. */
  96. volatile u16 *r = &(regs->addr_reg);
  97. mb();
  98. *r = bt431_set_value(value);
  99. }
  100. static inline u8 bt431_read_reg(struct bt431_regs *regs, int ir)
  101. {
  102. bt431_select_reg(regs, ir);
  103. return bt431_read_reg_inc(regs);
  104. }
  105. static inline void bt431_write_reg(struct bt431_regs *regs, int ir, u8 value)
  106. {
  107. bt431_select_reg(regs, ir);
  108. bt431_write_reg_inc(regs, value);
  109. }
  110. /* Autoincremented read/write for the cursor map. */
  111. static inline u16 bt431_read_cmap_inc(struct bt431_regs *regs)
  112. {
  113. /*
  114. * The compiler splits the write in two bytes without the
  115. * helper variable.
  116. */
  117. volatile u16 *r = &(regs->addr_cmap);
  118. mb();
  119. return *r;
  120. }
  121. static inline void bt431_write_cmap_inc(struct bt431_regs *regs, u16 value)
  122. {
  123. /*
  124. * The compiler splits the write in two bytes without the
  125. * helper variable.
  126. */
  127. volatile u16 *r = &(regs->addr_cmap);
  128. mb();
  129. *r = value;
  130. }
  131. static inline u16 bt431_read_cmap(struct bt431_regs *regs, int cr)
  132. {
  133. bt431_select_reg(regs, cr);
  134. return bt431_read_cmap_inc(regs);
  135. }
  136. static inline void bt431_write_cmap(struct bt431_regs *regs, int cr, u16 value)
  137. {
  138. bt431_select_reg(regs, cr);
  139. bt431_write_cmap_inc(regs, value);
  140. }
  141. static inline void bt431_enable_cursor(struct bt431_regs *regs)
  142. {
  143. bt431_write_reg(regs, BT431_REG_CMD,
  144. BT431_CMD_CURS_ENABLE | BT431_CMD_OR_CURSORS
  145. | BT431_CMD_4_1_MUX | BT431_CMD_THICK_1);
  146. }
  147. static inline void bt431_erase_cursor(struct bt431_regs *regs)
  148. {
  149. bt431_write_reg(regs, BT431_REG_CMD, BT431_CMD_4_1_MUX);
  150. }
  151. static inline void bt431_position_cursor(struct bt431_regs *regs, u16 x, u16 y)
  152. {
  153. /*
  154. * Magic from the MACH sources.
  155. *
  156. * Cx = x + D + H - P
  157. * P = 37 if 1:1, 52 if 4:1, 57 if 5:1
  158. * D = pixel skew between outdata and external data
  159. * H = pixels between HSYNCH falling and active video
  160. *
  161. * Cy = y + V - 32
  162. * V = scanlines between HSYNCH falling, two or more
  163. * clocks after VSYNCH falling, and active video
  164. */
  165. x += 412 - 52;
  166. y += 68 - 32;
  167. /* Use autoincrement. */
  168. bt431_select_reg(regs, BT431_REG_CXLO);
  169. bt431_write_reg_inc(regs, x & 0xff); /* BT431_REG_CXLO */
  170. bt431_write_reg_inc(regs, (x >> 8) & 0x0f); /* BT431_REG_CXHI */
  171. bt431_write_reg_inc(regs, y & 0xff); /* BT431_REG_CYLO */
  172. bt431_write_reg_inc(regs, (y >> 8) & 0x0f); /* BT431_REG_CYHI */
  173. }
  174. static inline void bt431_set_font(struct bt431_regs *regs, u8 fgc,
  175. u16 width, u16 height)
  176. {
  177. int i;
  178. u16 fgp = fgc ? 0xffff : 0x0000;
  179. u16 bgp = fgc ? 0x0000 : 0xffff;
  180. bt431_select_reg(regs, BT431_REG_CRAM_BASE);
  181. for (i = BT431_REG_CRAM_BASE; i <= BT431_REG_CRAM_END; i++) {
  182. u16 value;
  183. if (height << 6 <= i << 3)
  184. value = bgp;
  185. else if (width <= i % 8 << 3)
  186. value = bgp;
  187. else if (((width >> 3) & 0xffff) > i % 8)
  188. value = fgp;
  189. else
  190. value = fgp & ~(bgp << (width % 8 << 1));
  191. bt431_write_cmap_inc(regs, value);
  192. }
  193. }
  194. static inline void bt431_init_cursor(struct bt431_regs *regs)
  195. {
  196. /* no crosshair window */
  197. bt431_select_reg(regs, BT431_REG_WXLO);
  198. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WXLO */
  199. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WXHI */
  200. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WYLO */
  201. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WYHI */
  202. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WWLO */
  203. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WWHI */
  204. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WHLO */
  205. bt431_write_reg_inc(regs, 0x00); /* BT431_REG_WHHI */
  206. }