1 /*-*- linux-c -*-
2  *  linux/drivers/video/savage/savage_accel.c -- Hardware Acceleration
3  *
4  *      Copyright (C) 2004 Antonino Daplas<adaplas@pol.net>
5  *      All Rights Reserved
6  *
7  *  This file is subject to the terms and conditions of the GNU General Public
8  *  License. See the file COPYING in the main directory of this archive for
9  *  more details.
10  */
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/fb.h>
14 #include <linux/module.h>
15 
16 #include "savagefb.h"
17 
18 static u32 savagefb_rop[] = {
19 	0xCC, /* ROP_COPY */
20 	0x5A  /* ROP_XOR  */
21 };
22 
savagefb_sync(struct fb_info * info)23 int savagefb_sync(struct fb_info *info)
24 {
25 	struct savagefb_par *par = info->par;
26 
27 	par->SavageWaitIdle(par);
28 	return 0;
29 }
30 
savagefb_copyarea(struct fb_info * info,const struct fb_copyarea * region)31 void savagefb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
32 {
33 	struct savagefb_par *par = info->par;
34 	int sx = region->sx, dx = region->dx;
35 	int sy = region->sy, dy = region->dy;
36 	int cmd;
37 
38 	if (!region->width || !region->height)
39 		return;
40 	par->bci_ptr = 0;
41 	cmd = BCI_CMD_RECT | BCI_CMD_DEST_GBD | BCI_CMD_SRC_GBD;
42 	BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
43 
44 	if (dx <= sx) {
45 		cmd |= BCI_CMD_RECT_XP;
46 	} else {
47 		sx += region->width - 1;
48 		dx += region->width - 1;
49 	}
50 
51 	if (dy <= sy) {
52 		cmd |= BCI_CMD_RECT_YP;
53 	} else {
54 		sy += region->height - 1;
55 		dy += region->height - 1;
56 	}
57 
58 	par->SavageWaitFifo(par,4);
59 	BCI_SEND(cmd);
60 	BCI_SEND(BCI_X_Y(sx, sy));
61 	BCI_SEND(BCI_X_Y(dx, dy));
62 	BCI_SEND(BCI_W_H(region->width, region->height));
63 }
64 
savagefb_fillrect(struct fb_info * info,const struct fb_fillrect * rect)65 void savagefb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
66 {
67 	struct savagefb_par *par = info->par;
68 	int cmd, color;
69 
70 	if (!rect->width || !rect->height)
71 		return;
72 
73 	if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
74 		color = rect->color;
75 	else
76 		color = ((u32 *)info->pseudo_palette)[rect->color];
77 
78 	cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
79 	      BCI_CMD_DEST_GBD | BCI_CMD_SRC_SOLID |
80 	      BCI_CMD_SEND_COLOR;
81 
82 	par->bci_ptr = 0;
83 	BCI_CMD_SET_ROP(cmd, savagefb_rop[rect->rop]);
84 
85 	par->SavageWaitFifo(par,4);
86 	BCI_SEND(cmd);
87 	BCI_SEND(color);
88 	BCI_SEND( BCI_X_Y(rect->dx, rect->dy) );
89 	BCI_SEND( BCI_W_H(rect->width, rect->height) );
90 }
91 
savagefb_imageblit(struct fb_info * info,const struct fb_image * image)92 void savagefb_imageblit(struct fb_info *info, const struct fb_image *image)
93 {
94 	struct savagefb_par *par = info->par;
95 	int fg, bg, size, i, width;
96 	int cmd;
97 	u32 *src = (u32 *) image->data;
98 
99 	if (!image->width || !image->height)
100 		return;
101 
102 	if (image->depth != 1) {
103 		cfb_imageblit(info, image);
104 		return;
105 	}
106 
107 	if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
108 		fg = image->fg_color;
109 		bg = image->bg_color;
110 	} else {
111 		fg = ((u32 *)info->pseudo_palette)[image->fg_color];
112 		bg = ((u32 *)info->pseudo_palette)[image->bg_color];
113 	}
114 
115 	cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
116 	      BCI_CMD_CLIP_LR | BCI_CMD_DEST_GBD | BCI_CMD_SRC_MONO |
117 	      BCI_CMD_SEND_COLOR;
118 
119 	par->bci_ptr = 0;
120 	BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
121 
122 	width = (image->width + 31) & ~31;
123 	size = (width * image->height)/8;
124 	size >>= 2;
125 
126 	par->SavageWaitFifo(par, size + 5);
127 	BCI_SEND(cmd);
128 	BCI_SEND(BCI_CLIP_LR(image->dx, image->dx + image->width - 1));
129 	BCI_SEND(fg);
130 	BCI_SEND(bg);
131 	BCI_SEND(BCI_X_Y(image->dx, image->dy));
132 	BCI_SEND(BCI_W_H(width, image->height));
133 	for (i = 0; i < size; i++)
134 		BCI_SEND(src[i]);
135 }
136 
137 MODULE_LICENSE("GPL");
138