mach64_cursor.c 5.6 KB

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