2 * ATI Mach64 CT/VT/GT/LT Cursor Support
5 #include <linux/slab.h>
7 #include <linux/init.h>
8 #include <linux/string.h>
11 #include <asm/uaccess.h>
17 #include <video/mach64.h>
21 * The hardware cursor definition requires 2 bits per pixel. The
22 * Cursor size reguardless of the visible cursor size is 64 pixels
23 * by 64 lines. The total memory required to define the cursor is
24 * 16 bytes / line for 64 lines or 1024 bytes of data. The data
25 * must be in a contigiuos format. The 2 bit cursor code values are
28 * 00 - pixel colour = CURSOR_CLR_0
29 * 01 - pixel colour = CURSOR_CLR_1
30 * 10 - pixel colour = transparent (current display pixel)
31 * 11 - pixel colour = 1's complement of current display pixel
33 * Cursor Offset 64 pixels Actual Displayed Area
34 * \_________________________/
36 * |<--------------->| | |
37 * | CURS_HORZ_OFFSET| | |
38 * | |_______| | 64 Lines
41 * | CURS_VERT_OFFSET| |
43 * |____________________|____| |
46 * The Screen position of the top left corner of the displayed
47 * cursor is specificed by CURS_HORZ_VERT_POSN. Care must be taken
48 * when the cursor hot spot is not the top left corner and the
49 * physical cursor position becomes negative. It will be be displayed
50 * if either the horizontal or vertical cursor position is negative
52 * If x becomes negative the cursor manager must adjust the CURS_HORZ_OFFSET
53 * to a larger number and saturate CUR_HORZ_POSN to zero.
55 * if Y becomes negative, CUR_VERT_OFFSET must be adjusted to a larger number,
56 * CUR_OFFSET must be adjusted to a point to the appropraite line in the cursor
57 * definitation and CUR_VERT_POSN must be saturated to zero.
61 * Hardware Cursor support.
63 static const u8 cursor_bits_lookup[16] = {
64 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
65 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
68 static int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
70 struct atyfb_par *par = (struct atyfb_par *) info->par;
82 wait_for_fifo(1, par);
83 aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par) & ~HWCURSOR_ENABLE, par);
86 if (cursor->set & FB_CUR_SETPOS) {
87 x = cursor->image.dx - cursor->hot.x - info->var.xoffset;
95 y = cursor->image.dy - cursor->hot.y - info->var.yoffset;
103 h = cursor->image.height;
106 * In doublescan mode, the cursor location
107 * and heigh also needs to be doubled.
109 if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN) {
113 wait_for_fifo(4, par);
114 aty_st_le32(CUR_OFFSET, (info->fix.smem_len >> 3) + (yoff << 1), par);
115 aty_st_le32(CUR_HORZ_VERT_OFF,
116 ((u32) (64 - h + yoff) << 16) | xoff, par);
117 aty_st_le32(CUR_HORZ_VERT_POSN, ((u32) y << 16) | x, par);
121 if (cursor->set & FB_CUR_SETCMAP) {
122 u32 fg_idx, bg_idx, fg, bg;
124 fg_idx = cursor->image.fg_color;
125 bg_idx = cursor->image.bg_color;
127 fg = ((info->cmap.red[fg_idx] & 0xff) << 24) |
128 ((info->cmap.green[fg_idx] & 0xff) << 16) |
129 ((info->cmap.blue[fg_idx] & 0xff) << 8) | 0xff;
131 bg = ((info->cmap.red[bg_idx] & 0xff) << 24) |
132 ((info->cmap.green[bg_idx] & 0xff) << 16) |
133 ((info->cmap.blue[bg_idx] & 0xff) << 8);
135 wait_for_fifo(2, par);
136 aty_st_le32(CUR_CLR0, bg, par);
137 aty_st_le32(CUR_CLR1, fg, par);
140 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
141 u8 *src = (u8 *)cursor->image.data;
142 u8 *msk = (u8 *)cursor->mask;
143 u8 __iomem *dst = (u8 __iomem *)info->sprite.addr;
144 unsigned int width = (cursor->image.width + 7) >> 3;
145 unsigned int height = cursor->image.height;
146 unsigned int align = info->sprite.scan_align;
148 unsigned int i, j, offset;
151 // Clear cursor image with 1010101010...
152 fb_memset(dst, 0xaa, 1024);
154 offset = align - width*2;
156 for (i = 0; i < height; i++) {
157 for (j = 0; j < width; j++) {
160 switch (cursor->rop) {
162 // Upper 4 bits of mask data
163 fb_writeb(cursor_bits_lookup[(b ^ m) >> 4], dst++);
164 // Lower 4 bits of mask
165 fb_writeb(cursor_bits_lookup[(b ^ m) & 0x0f],
169 // Upper 4 bits of mask data
170 fb_writeb(cursor_bits_lookup[(b & m) >> 4], dst++);
171 // Lower 4 bits of mask
172 fb_writeb(cursor_bits_lookup[(b & m) & 0x0f],
181 if (cursor->enable) {
182 wait_for_fifo(1, par);
183 aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par)
184 | HWCURSOR_ENABLE, par);
189 int __devinit aty_init_cursor(struct fb_info *info)
193 info->fix.smem_len -= PAGE_SIZE;
196 addr = (unsigned long) info->screen_base - 0x800000 + info->fix.smem_len;
197 info->sprite.addr = (u8 *) addr;
200 addr = info->fix.smem_start - 0x800000 + info->fix.smem_len;
201 info->sprite.addr = (u8 *) ioremap(addr, 1024);
203 addr = (unsigned long) info->screen_base + info->fix.smem_len;
204 info->sprite.addr = (u8 *) addr;
207 if (!info->sprite.addr)
209 info->sprite.size = PAGE_SIZE;
210 info->sprite.scan_align = 16; /* Scratch pad 64 bytes wide */
211 info->sprite.buf_align = 16; /* and 64 lines tall. */
212 info->sprite.flags = FB_PIXMAP_IO;
214 info->fbops->fb_cursor = atyfb_cursor;