mach64_cursor.c 5.7 KB

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