mach64_cursor.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  63. {
  64. struct atyfb_par *par = (struct atyfb_par *) info->par;
  65. u16 xoff, yoff;
  66. int x, y, h;
  67. #ifdef __sparc__
  68. if (par->mmaped)
  69. return -EPERM;
  70. #endif
  71. if (par->asleep)
  72. return -EPERM;
  73. /* Hide cursor */
  74. wait_for_fifo(1, par);
  75. aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par) & ~HWCURSOR_ENABLE, par);
  76. /* set position */
  77. if (cursor->set & FB_CUR_SETPOS) {
  78. x = cursor->image.dx - cursor->hot.x - info->var.xoffset;
  79. if (x < 0) {
  80. xoff = -x;
  81. x = 0;
  82. } else {
  83. xoff = 0;
  84. }
  85. y = cursor->image.dy - cursor->hot.y - info->var.yoffset;
  86. if (y < 0) {
  87. yoff = -y;
  88. y = 0;
  89. } else {
  90. yoff = 0;
  91. }
  92. h = cursor->image.height;
  93. /*
  94. * In doublescan mode, the cursor location
  95. * and heigh also needs to be doubled.
  96. */
  97. if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN) {
  98. y<<=1;
  99. h<<=1;
  100. }
  101. wait_for_fifo(4, par);
  102. aty_st_le32(CUR_OFFSET, (info->fix.smem_len >> 3) + (yoff << 1), par);
  103. aty_st_le32(CUR_HORZ_VERT_OFF,
  104. ((u32) (64 - h + yoff) << 16) | xoff, par);
  105. aty_st_le32(CUR_HORZ_VERT_POSN, ((u32) y << 16) | x, par);
  106. }
  107. /* Set color map */
  108. if (cursor->set & FB_CUR_SETCMAP) {
  109. u32 fg_idx, bg_idx, fg, bg;
  110. fg_idx = cursor->image.fg_color;
  111. bg_idx = cursor->image.bg_color;
  112. fg = ((info->cmap.red[fg_idx] & 0xff) << 24) |
  113. ((info->cmap.green[fg_idx] & 0xff) << 16) |
  114. ((info->cmap.blue[fg_idx] & 0xff) << 8) | 0xff;
  115. bg = ((info->cmap.red[bg_idx] & 0xff) << 24) |
  116. ((info->cmap.green[bg_idx] & 0xff) << 16) |
  117. ((info->cmap.blue[bg_idx] & 0xff) << 8);
  118. wait_for_fifo(2, par);
  119. aty_st_le32(CUR_CLR0, bg, par);
  120. aty_st_le32(CUR_CLR1, fg, par);
  121. }
  122. if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
  123. u8 *src = (u8 *)cursor->image.data;
  124. u8 *msk = (u8 *)cursor->mask;
  125. u8 __iomem *dst = (u8 __iomem *)info->sprite.addr;
  126. unsigned int width = (cursor->image.width + 7) >> 3;
  127. unsigned int height = cursor->image.height;
  128. unsigned int align = info->sprite.scan_align;
  129. unsigned int i, j, offset;
  130. u8 m, b;
  131. // Clear cursor image with 1010101010...
  132. fb_memset(dst, 0xaa, 1024);
  133. offset = align - width*2;
  134. for (i = 0; i < height; i++) {
  135. for (j = 0; j < width; j++) {
  136. b = *src++;
  137. m = *msk++;
  138. switch (cursor->rop) {
  139. case ROP_XOR:
  140. // Upper 4 bits of mask data
  141. fb_writeb(cursor_bits_lookup[(b ^ m) >> 4], dst++);
  142. // Lower 4 bits of mask
  143. fb_writeb(cursor_bits_lookup[(b ^ m) & 0x0f],
  144. dst++);
  145. break;
  146. case ROP_COPY:
  147. // Upper 4 bits of mask data
  148. fb_writeb(cursor_bits_lookup[(b & m) >> 4], dst++);
  149. // Lower 4 bits of mask
  150. fb_writeb(cursor_bits_lookup[(b & m) & 0x0f],
  151. dst++);
  152. break;
  153. }
  154. }
  155. dst += offset;
  156. }
  157. }
  158. if (cursor->enable) {
  159. wait_for_fifo(1, par);
  160. aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par)
  161. | HWCURSOR_ENABLE, par);
  162. }
  163. return 0;
  164. }
  165. int __devinit aty_init_cursor(struct fb_info *info)
  166. {
  167. unsigned long addr;
  168. info->fix.smem_len -= PAGE_SIZE;
  169. #ifdef __sparc__
  170. addr = (unsigned long) info->screen_base - 0x800000 + info->fix.smem_len;
  171. info->sprite.addr = (u8 *) addr;
  172. #else
  173. #ifdef __BIG_ENDIAN
  174. addr = info->fix.smem_start - 0x800000 + info->fix.smem_len;
  175. info->sprite.addr = (u8 *) ioremap(addr, 1024);
  176. #else
  177. addr = (unsigned long) info->screen_base + info->fix.smem_len;
  178. info->sprite.addr = (u8 *) addr;
  179. #endif
  180. #endif
  181. if (!info->sprite.addr)
  182. return -ENXIO;
  183. info->sprite.size = PAGE_SIZE;
  184. info->sprite.scan_align = 16; /* Scratch pad 64 bytes wide */
  185. info->sprite.buf_align = 16; /* and 64 lines tall. */
  186. info->sprite.flags = FB_PIXMAP_IO;
  187. info->fbops->fb_cursor = atyfb_cursor;
  188. return 0;
  189. }