mach64_cursor.c 5.9 KB

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