diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/video/aty/mach64_cursor.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/video/aty/mach64_cursor.c')
-rw-r--r-- | drivers/video/aty/mach64_cursor.c | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c new file mode 100644 index 000000000000..ad8b7496f853 --- /dev/null +++ b/drivers/video/aty/mach64_cursor.c | |||
@@ -0,0 +1,226 @@ | |||
1 | /* | ||
2 | * ATI Mach64 CT/VT/GT/LT Cursor Support | ||
3 | */ | ||
4 | |||
5 | #include <linux/slab.h> | ||
6 | #include <linux/fb.h> | ||
7 | #include <linux/init.h> | ||
8 | #include <linux/string.h> | ||
9 | |||
10 | #include <asm/io.h> | ||
11 | #include <asm/uaccess.h> | ||
12 | |||
13 | #ifdef __sparc__ | ||
14 | #include <asm/pbm.h> | ||
15 | #include <asm/fbio.h> | ||
16 | #endif | ||
17 | |||
18 | #include <video/mach64.h> | ||
19 | #include "atyfb.h" | ||
20 | |||
21 | /* | ||
22 | * The hardware cursor definition requires 2 bits per pixel. The | ||
23 | * Cursor size reguardless of the visible cursor size is 64 pixels | ||
24 | * by 64 lines. The total memory required to define the cursor is | ||
25 | * 16 bytes / line for 64 lines or 1024 bytes of data. The data | ||
26 | * must be in a contigiuos format. The 2 bit cursor code values are | ||
27 | * as follows: | ||
28 | * | ||
29 | * 00 - pixel colour = CURSOR_CLR_0 | ||
30 | * 01 - pixel colour = CURSOR_CLR_1 | ||
31 | * 10 - pixel colour = transparent (current display pixel) | ||
32 | * 11 - pixel colour = 1's complement of current display pixel | ||
33 | * | ||
34 | * Cursor Offset 64 pixels Actual Displayed Area | ||
35 | * \_________________________/ | ||
36 | * | | | | | ||
37 | * |<--------------->| | | | ||
38 | * | CURS_HORZ_OFFSET| | | | ||
39 | * | |_______| | 64 Lines | ||
40 | * | ^ | | | ||
41 | * | | | | | ||
42 | * | CURS_VERT_OFFSET| | | ||
43 | * | | | | | ||
44 | * |____________________|____| | | ||
45 | * | ||
46 | * | ||
47 | * The Screen position of the top left corner of the displayed | ||
48 | * cursor is specificed by CURS_HORZ_VERT_POSN. Care must be taken | ||
49 | * when the cursor hot spot is not the top left corner and the | ||
50 | * physical cursor position becomes negative. It will be be displayed | ||
51 | * if either the horizontal or vertical cursor position is negative | ||
52 | * | ||
53 | * If x becomes negative the cursor manager must adjust the CURS_HORZ_OFFSET | ||
54 | * to a larger number and saturate CUR_HORZ_POSN to zero. | ||
55 | * | ||
56 | * if Y becomes negative, CUR_VERT_OFFSET must be adjusted to a larger number, | ||
57 | * CUR_OFFSET must be adjusted to a point to the appropraite line in the cursor | ||
58 | * definitation and CUR_VERT_POSN must be saturated to zero. | ||
59 | */ | ||
60 | |||
61 | /* | ||
62 | * Hardware Cursor support. | ||
63 | */ | ||
64 | static const u8 cursor_bits_lookup[16] = { | ||
65 | 0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54, | ||
66 | 0x01, 0x41, 0x11, 0x51, 0x05, 0x45, 0x15, 0x55 | ||
67 | }; | ||
68 | |||
69 | static const u8 cursor_mask_lookup[16] = { | ||
70 | 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02, | ||
71 | 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00 | ||
72 | }; | ||
73 | |||
74 | static int atyfb_cursor(struct fb_info *info, struct fb_cursor *cursor) | ||
75 | { | ||
76 | struct atyfb_par *par = (struct atyfb_par *) info->par; | ||
77 | u16 xoff, yoff; | ||
78 | int x, y, h; | ||
79 | |||
80 | #ifdef __sparc__ | ||
81 | if (par->mmaped) | ||
82 | return -EPERM; | ||
83 | #endif | ||
84 | if (par->asleep) | ||
85 | return -EPERM; | ||
86 | |||
87 | /* Hide cursor */ | ||
88 | wait_for_fifo(1, par); | ||
89 | aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par) & ~HWCURSOR_ENABLE, par); | ||
90 | |||
91 | /* set position */ | ||
92 | if (cursor->set & FB_CUR_SETPOS) { | ||
93 | x = cursor->image.dx - cursor->hot.x - info->var.xoffset; | ||
94 | if (x < 0) { | ||
95 | xoff = -x; | ||
96 | x = 0; | ||
97 | } else { | ||
98 | xoff = 0; | ||
99 | } | ||
100 | |||
101 | y = cursor->image.dy - cursor->hot.y - info->var.yoffset; | ||
102 | if (y < 0) { | ||
103 | yoff = -y; | ||
104 | y = 0; | ||
105 | } else { | ||
106 | yoff = 0; | ||
107 | } | ||
108 | |||
109 | h = cursor->image.height; | ||
110 | |||
111 | /* | ||
112 | * In doublescan mode, the cursor location | ||
113 | * and heigh also needs to be doubled. | ||
114 | */ | ||
115 | if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN) { | ||
116 | y<<=1; | ||
117 | h<<=1; | ||
118 | } | ||
119 | wait_for_fifo(4, par); | ||
120 | aty_st_le32(CUR_OFFSET, (info->fix.smem_len >> 3) + (yoff << 1), par); | ||
121 | aty_st_le32(CUR_HORZ_VERT_OFF, | ||
122 | ((u32) (64 - h + yoff) << 16) | xoff, par); | ||
123 | aty_st_le32(CUR_HORZ_VERT_POSN, ((u32) y << 16) | x, par); | ||
124 | } | ||
125 | |||
126 | /* Set color map */ | ||
127 | if (cursor->set & FB_CUR_SETCMAP) { | ||
128 | u32 fg_idx, bg_idx, fg, bg; | ||
129 | |||
130 | fg_idx = cursor->image.fg_color; | ||
131 | bg_idx = cursor->image.bg_color; | ||
132 | |||
133 | fg = (info->cmap.red[fg_idx] << 24) | | ||
134 | (info->cmap.green[fg_idx] << 16) | | ||
135 | (info->cmap.blue[fg_idx] << 8) | 15; | ||
136 | |||
137 | bg = (info->cmap.red[bg_idx] << 24) | | ||
138 | (info->cmap.green[bg_idx] << 16) | | ||
139 | (info->cmap.blue[bg_idx] << 8); | ||
140 | |||
141 | wait_for_fifo(2, par); | ||
142 | aty_st_le32(CUR_CLR0, bg, par); | ||
143 | aty_st_le32(CUR_CLR1, fg, par); | ||
144 | } | ||
145 | |||
146 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { | ||
147 | u8 *src = (u8 *)cursor->image.data; | ||
148 | u8 *msk = (u8 *)cursor->mask; | ||
149 | u8 __iomem *dst = (u8 __iomem *)info->sprite.addr; | ||
150 | unsigned int width = (cursor->image.width + 7) >> 3; | ||
151 | unsigned int height = cursor->image.height; | ||
152 | unsigned int align = info->sprite.scan_align; | ||
153 | |||
154 | unsigned int i, j, offset; | ||
155 | u8 m, b; | ||
156 | |||
157 | // Clear cursor image with 1010101010... | ||
158 | fb_memset(dst, 0xaa, 1024); | ||
159 | |||
160 | offset = align - width*2; | ||
161 | |||
162 | for (i = 0; i < height; i++) { | ||
163 | for (j = 0; j < width; j++) { | ||
164 | b = *src++; | ||
165 | m = *msk++; | ||
166 | switch (cursor->rop) { | ||
167 | case ROP_XOR: | ||
168 | // Upper 4 bits of mask data | ||
169 | fb_writeb(cursor_mask_lookup[m >> 4 ] | | ||
170 | cursor_bits_lookup[(b ^ m) >> 4], dst++); | ||
171 | // Lower 4 bits of mask | ||
172 | fb_writeb(cursor_mask_lookup[m & 0x0f ] | | ||
173 | cursor_bits_lookup[(b ^ m) & 0x0f], dst++); | ||
174 | break; | ||
175 | case ROP_COPY: | ||
176 | // Upper 4 bits of mask data | ||
177 | fb_writeb(cursor_mask_lookup[m >> 4 ] | | ||
178 | cursor_bits_lookup[(b & m) >> 4], dst++); | ||
179 | // Lower 4 bits of mask | ||
180 | fb_writeb(cursor_mask_lookup[m & 0x0f ] | | ||
181 | cursor_bits_lookup[(b & m) & 0x0f], dst++); | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | dst += offset; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | if (cursor->enable) { | ||
190 | wait_for_fifo(1, par); | ||
191 | aty_st_le32(GEN_TEST_CNTL, aty_ld_le32(GEN_TEST_CNTL, par) | ||
192 | | HWCURSOR_ENABLE, par); | ||
193 | } | ||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | int __init aty_init_cursor(struct fb_info *info) | ||
198 | { | ||
199 | unsigned long addr; | ||
200 | |||
201 | info->fix.smem_len -= PAGE_SIZE; | ||
202 | |||
203 | #ifdef __sparc__ | ||
204 | addr = (unsigned long) info->screen_base - 0x800000 + info->fix.smem_len; | ||
205 | info->sprite.addr = (u8 *) addr; | ||
206 | #else | ||
207 | #ifdef __BIG_ENDIAN | ||
208 | addr = info->fix.smem_start - 0x800000 + info->fix.smem_len; | ||
209 | info->sprite.addr = (u8 *) ioremap(addr, 1024); | ||
210 | #else | ||
211 | addr = (unsigned long) info->screen_base + info->fix.smem_len; | ||
212 | info->sprite.addr = (u8 *) addr; | ||
213 | #endif | ||
214 | #endif | ||
215 | if (!info->sprite.addr) | ||
216 | return -ENXIO; | ||
217 | info->sprite.size = PAGE_SIZE; | ||
218 | info->sprite.scan_align = 16; /* Scratch pad 64 bytes wide */ | ||
219 | info->sprite.buf_align = 16; /* and 64 lines tall. */ | ||
220 | info->sprite.flags = FB_PIXMAP_IO; | ||
221 | |||
222 | info->fbops->fb_cursor = atyfb_cursor; | ||
223 | |||
224 | return 0; | ||
225 | } | ||
226 | |||