3 * ATI Mach64 CT/VT/GT/LT Cursor Support
6 #include <linux/slab.h>
7 #include <linux/console.h>
9 #include <linux/init.h>
12 #include <asm/uaccess.h>
19 #include <video/mach64.h>
23 * Hardware Cursor support.
26 static const u8 cursor_pixel_map[2] = { 0, 15 };
27 static const u8 cursor_color_map[2] = { 0, 0xff };
29 static const u8 cursor_bits_lookup[16] = {
30 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54,
31 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55
34 static const u8 cursor_mask_lookup[16] = {
35 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02,
36 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00
39 void aty_set_cursor_color(struct fb_info *info)
41 struct atyfb_par *par = (struct atyfb_par *) info->par;
42 struct aty_cursor *c = par->cursor;
43 const u8 *pixel = cursor_pixel_map; /* ++Geert: Why?? */
44 const u8 *red = cursor_color_map;
45 const u8 *green = cursor_color_map;
46 const u8 *blue = cursor_color_map;
47 u32 fg_color, bg_color;
56 fg_color = (u32) red[0] << 24;
57 fg_color |= (u32) green[0] << 16;
58 fg_color |= (u32) blue[0] << 8;
59 fg_color |= (u32) pixel[0];
61 bg_color = (u32) red[1] << 24;
62 bg_color |= (u32) green[1] << 16;
63 bg_color |= (u32) blue[1] << 8;
64 bg_color |= (u32) pixel[1];
66 wait_for_fifo(2, par);
67 aty_st_le32(CUR_CLR0, fg_color, par);
68 aty_st_le32(CUR_CLR1, bg_color, par);
71 void aty_set_cursor_shape(struct fb_info *info)
73 struct atyfb_par *par = (struct atyfb_par *) info->par;
74 struct fb_cursor *cursor = &info->cursor;
75 struct aty_cursor *c = par->cursor;
87 for (y = 0; y < cursor->image.height; y++) {
88 for (x = 0; x < cursor->image.width >> 2; x++) {
91 fb_writeb(cursor_mask_lookup[m >> 4] |
92 cursor_bits_lookup[(b & m) >> 4], ram++);
93 fb_writeb(cursor_mask_lookup[m & 0x0f] |
94 cursor_bits_lookup[(b & m) & 0x0f],
98 fb_writeb(0xaa, ram++);
99 fb_writeb(0xaa, ram++);
102 fb_memset(ram, 0xaa, (64 - cursor->image.height) * 16);
105 static void aty_set_cursor(struct fb_info *info)
107 struct atyfb_par *par = (struct atyfb_par *) info->par;
108 struct fb_cursor *cursor = &info->cursor;
109 struct aty_cursor *c = par->cursor;
121 if (cursor->enable) {
122 x = cursor->image.dx - cursor->hot.x - info->var.xoffset;
130 y = cursor->image.dy - cursor->hot.y - info->var.yoffset;
138 wait_for_fifo(4, par);
139 aty_st_le32(CUR_OFFSET, (info->fix.smem_len >> 3) + (yoff << 1),
141 aty_st_le32(CUR_HORZ_VERT_OFF,
142 ((u32) (64 - cursor->image.height + yoff) << 16) | xoff,
144 aty_st_le32(CUR_HORZ_VERT_POSN, ((u32) y << 16) | x, par);
145 aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par)
146 | HWCURSOR_ENABLE, par);
148 wait_for_fifo(1, par);
149 aty_st_le32(GEN_TEST_CNTL,
150 aty_ld_le32(GEN_TEST_CNTL,
151 par) & ~HWCURSOR_ENABLE, par);
153 if (par->blitter_may_be_busy)
157 int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
159 struct atyfb_par *par = (struct atyfb_par *) info->par;
160 struct aty_cursor *c = par->cursor;
170 aty_set_cursor(info);
171 cursor->image.dx = info->cursor.image.dx;
172 cursor->image.dy = info->cursor.image.dy;
174 aty_set_cursor(info);
178 struct aty_cursor *__init aty_init_cursor(struct fb_info *info)
180 struct aty_cursor *cursor;
183 cursor = kmalloc(sizeof(struct aty_cursor), GFP_ATOMIC);
186 memset(cursor, 0, sizeof(*cursor));
188 info->fix.smem_len -= PAGE_SIZE;
191 addr = (unsigned long) info->screen_base - 0x800000 + info->fix.smem_len;
192 cursor->ram = (u8 *) addr;
195 addr = info->fix.smem_start - 0x800000 + info->fix.smem_len;
196 cursor->ram = (u8 *) ioremap(addr, 1024);
198 addr = (unsigned long) info->screen_base + info->fix.smem_len;
199 cursor->ram = (u8 *) addr;
209 int atyfb_set_font(struct fb_info *info, int width, int height)
211 struct atyfb_par *par = (struct atyfb_par *) info->par;
212 struct fb_cursor *cursor = &info->cursor;
213 struct aty_cursor *c = par->cursor;
217 if (!width || !height) {
224 cursor->image.width = width;
225 cursor->image.height = height;
227 memset(c->bits, 0xff, sizeof(c->bits));
228 memset(c->mask, 0, sizeof(c->mask));
230 for (i = 0, j = width; j >= 0; j -= 8, i++) {
231 c->mask[i][height - 2] =
232 (j >= 8) ? 0xff : (0xff << (8 - j));
233 c->mask[i][height - 1] =
234 (j >= 8) ? 0xff : (0xff << (8 - j));
237 aty_set_cursor_color(info);
238 aty_set_cursor_shape(info);