mach64_cursor.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * ATI Mach64 CT/VT/GT/LT Cursor Support
  3. */
  4. #include <linux/slab.h>
  5. #include <linux/fb.h>
  6. #include <linux/init.h>
  7. #include <linux/string.h>
  8. #include <asm/io.h>
  9. #include <asm/uaccess.h>
  10. #ifdef __sparc__
  11. #include <asm/pbm.h>
  12. #include <asm/fbio.h>
  13. #endif
  14. #include <video/mach64.h>
  15. #include "atyfb.h"
  16. /*
  17. * The hardware cursor definition requires 2 bits per pixel. The
  18. * Cursor size reguardless of the visible cursor size is 64 pixels
  19. * by 64 lines. The total memory required to define the cursor is
  20. * 16 bytes / line for 64 lines or 1024 bytes of data. The data
  21. * must be in a contigiuos format. The 2 bit cursor code values are
  22. * as follows:
  23. *
  24. * 00 - pixel colour = CURSOR_CLR_0
  25. * 01 - pixel colour = CURSOR_CLR_1
  26. * 10 - pixel colour = transparent (current display pixel)
  27. * 11 - pixel colour = 1's complement of current display pixel
  28. *
  29. * Cursor Offset 64 pixels Actual Displayed Area
  30. * \_________________________/
  31. * | | | |
  32. * |<--------------->| | |
  33. * | CURS_HORZ_OFFSET| | |
  34. * | |_______| | 64 Lines
  35. * | ^ | |
  36. * | | | |
  37. * | CURS_VERT_OFFSET| |
  38. * | | | |
  39. * |____________________|____| |
  40. *
  41. *
  42. * The Screen position of the top left corner of the displayed
  43. * cursor is specificed by CURS_HORZ_VERT_POSN. Care must be taken
  44. * when the cursor hot spot is not the top left corner and the
  45. * physical cursor position becomes negative. It will be be displayed
  46. * if either the horizontal or vertical cursor position is negative
  47. *
  48. * If x becomes negative the cursor manager must adjust the CURS_HORZ_OFFSET
  49. * to a larger number and saturate CUR_HORZ_POSN to zero.
  50. *
  51. * if Y becomes negative, CUR_VERT_OFFSET must be adjusted to a larger number,
  52. * CUR_OFFSET must be adjusted to a point to the appropraite line in the cursor
  53. * definitation and CUR_VERT_POSN must be saturated to zero.
  54. */
  55. /*
  56. * Hardware Cursor support.
  57. */
  58. static const u8 cursor_bits_lookup[16] = {
  59. 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
  60. 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
  61. };
  62. static const u8 cursor_mask_lookup[16] = {
  63. 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02,
  64. 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00
  65. };
  66. static int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  67. {
  68. struct atyfb_par *par = (struct atyfb_par *) info->par;
  69. u16 xoff, yoff;
  70. int x, y, h;
  71. #ifdef __sparc__
  72. if (par->mmaped)
  73. return -EPERM;
  74. #endif
  75. if (par->asleep)
  76. return -EPERM;
  77. /* Hide cursor */
  78. wait_for_fifo(1, par);
  79. aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par) & ~HWCURSOR_ENABLE, par);
  80. /* set position */
  81. if (cursor->set & FB_CUR_SETPOS) {
  82. x = cursor->image.dx - cursor->hot.x - info->var.xoffset;
  83. if (x < 0) {
  84. xoff = -x;
  85. x = 0;
  86. } else {
  87. xoff = 0;
  88. }
  89. y = cursor->image.dy - cursor->hot.y - info->var.yoffset;
  90. if (y < 0) {
  91. yoff = -y;
  92. y = 0;
  93. } else {
  94. yoff = 0;
  95. }
  96. h = cursor->image.height;
  97. /*
  98. * In doublescan mode, the cursor location
  99. * and heigh also needs to be doubled.
  100. */
  101. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN) {
  102. y<<=1;
  103. h<<=1;
  104. }
  105. wait_for_fifo(4, par);
  106. aty_st_le32(CUR_OFFSET, (info->fix.smem_len >> 3) + (yoff << 1), par);
  107. aty_st_le32(CUR_HORZ_VERT_OFF,
  108. ((u32) (64 - h + yoff) << 16) | xoff, par);
  109. aty_st_le32(CUR_HORZ_VERT_POSN, ((u32) y << 16) | x, par);
  110. }
  111. /* Set color map */
  112. if (cursor->set & FB_CUR_SETCMAP) {
  113. u32 fg_idx, bg_idx, fg, bg;
  114. fg_idx = cursor->image.fg_color;
  115. bg_idx = cursor->image.bg_color;
  116. fg = (info->cmap.red[fg_idx] << 24) |
  117. (info->cmap.green[fg_idx] << 16) |
  118. (info->cmap.blue[fg_idx] << 8) | 15;
  119. bg = (info->cmap.red[bg_idx] << 24) |
  120. (info->cmap.green[bg_idx] << 16) |
  121. (info->cmap.blue[bg_idx] << 8);
  122. wait_for_fifo(2, par);
  123. aty_st_le32(CUR_CLR0, bg, par);
  124. aty_st_le32(CUR_CLR1, fg, par);
  125. }
  126. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  127. u8 *src = (u8 *)cursor->image.data;
  128. u8 *msk = (u8 *)cursor->mask;
  129. u8 __iomem *dst = (u8 __iomem *)info->sprite.addr;
  130. unsigned int width = (cursor->image.width + 7) >> 3;
  131. unsigned int height = cursor->image.height;
  132. unsigned int align = info->sprite.scan_align;
  133. unsigned int i, j, offset;
  134. u8 m, b;
  135. // Clear cursor image with 1010101010...
  136. fb_memset(dst, 0xaa, 1024);
  137. offset = align - width*2;
  138. for (i = 0; i < height; i++) {
  139. for (j = 0; j < width; j++) {
  140. b = *src++;
  141. m = *msk++;
  142. switch (cursor->rop) {
  143. case ROP_XOR:
  144. // Upper 4 bits of mask data
  145. fb_writeb(cursor_mask_lookup[m >> 4 ] |
  146. cursor_bits_lookup[(b ^ m) >> 4], dst++);
  147. // Lower 4 bits of mask
  148. fb_writeb(cursor_mask_lookup[m & 0x0f ] |
  149. cursor_bits_lookup[(b ^ m) & 0x0f], dst++);
  150. break;
  151. case ROP_COPY:
  152. // Upper 4 bits of mask data
  153. fb_writeb(cursor_mask_lookup[m >> 4 ] |
  154. cursor_bits_lookup[(b & m) >> 4], dst++);
  155. // Lower 4 bits of mask
  156. fb_writeb(cursor_mask_lookup[m & 0x0f ] |
  157. cursor_bits_lookup[(b & m) & 0x0f], dst++);
  158. break;
  159. }
  160. }
  161. dst += offset;
  162. }
  163. }
  164. if (cursor->enable) {
  165. wait_for_fifo(1, par);
  166. aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par)
  167. | HWCURSOR_ENABLE, par);
  168. }
  169. return 0;
  170. }
  171. int __init aty_init_cursor(struct fb_info *info)
  172. {
  173. unsigned long addr;
  174. info->fix.smem_len -= PAGE_SIZE;
  175. #ifdef __sparc__
  176. addr = (unsigned long) info->screen_base - 0x800000 + info->fix.smem_len;
  177. info->sprite.addr = (u8 *) addr;
  178. #else
  179. #ifdef __BIG_ENDIAN
  180. addr = info->fix.smem_start - 0x800000 + info->fix.smem_len;
  181. info->sprite.addr = (u8 *) ioremap(addr, 1024);
  182. #else
  183. addr = (unsigned long) info->screen_base + info->fix.smem_len;
  184. info->sprite.addr = (u8 *) addr;
  185. #endif
  186. #endif
  187. if (!info->sprite.addr)
  188. return -ENXIO;
  189. info->sprite.size = PAGE_SIZE;
  190. info->sprite.scan_align = 16; /* Scratch pad 64 bytes wide */
  191. info->sprite.buf_align = 16; /* and 64 lines tall. */
  192. info->sprite.flags = FB_PIXMAP_IO;
  193. info->fbops->fb_cursor = atyfb_cursor;
  194. return 0;
  195. }