xref: /openbmc/linux/drivers/video/fbdev/atafb_iplan2p4.c (revision f7018c21350204c4cf628462f229d44d03545254)
1*f7018c21STomi Valkeinen /*
2*f7018c21STomi Valkeinen  *  linux/drivers/video/iplan2p4.c -- Low level frame buffer operations for
3*f7018c21STomi Valkeinen  *				      interleaved bitplanes à la Atari (4
4*f7018c21STomi Valkeinen  *				      planes, 2 bytes interleave)
5*f7018c21STomi Valkeinen  *
6*f7018c21STomi Valkeinen  *	Created 5 Apr 1997 by Geert Uytterhoeven
7*f7018c21STomi Valkeinen  *
8*f7018c21STomi Valkeinen  *  This file is subject to the terms and conditions of the GNU General Public
9*f7018c21STomi Valkeinen  *  License.  See the file COPYING in the main directory of this archive for
10*f7018c21STomi Valkeinen  *  more details.
11*f7018c21STomi Valkeinen  */
12*f7018c21STomi Valkeinen 
13*f7018c21STomi Valkeinen #include <linux/module.h>
14*f7018c21STomi Valkeinen #include <linux/string.h>
15*f7018c21STomi Valkeinen #include <linux/fb.h>
16*f7018c21STomi Valkeinen 
17*f7018c21STomi Valkeinen #include <asm/setup.h>
18*f7018c21STomi Valkeinen 
19*f7018c21STomi Valkeinen #include "atafb.h"
20*f7018c21STomi Valkeinen 
21*f7018c21STomi Valkeinen #define BPL	4
22*f7018c21STomi Valkeinen #include "atafb_utils.h"
23*f7018c21STomi Valkeinen 
24*f7018c21STomi Valkeinen void atafb_iplan2p4_copyarea(struct fb_info *info, u_long next_line,
25*f7018c21STomi Valkeinen 			     int sy, int sx, int dy, int dx,
26*f7018c21STomi Valkeinen 			     int height, int width)
27*f7018c21STomi Valkeinen {
28*f7018c21STomi Valkeinen 	/*  bmove() has to distinguish two major cases: If both, source and
29*f7018c21STomi Valkeinen 	 *  destination, start at even addresses or both are at odd
30*f7018c21STomi Valkeinen 	 *  addresses, just the first odd and last even column (if present)
31*f7018c21STomi Valkeinen 	 *  require special treatment (memmove_col()). The rest between
32*f7018c21STomi Valkeinen 	 *  then can be copied by normal operations, because all adjacent
33*f7018c21STomi Valkeinen 	 *  bytes are affected and are to be stored in the same order.
34*f7018c21STomi Valkeinen 	 *    The pathological case is when the move should go from an odd
35*f7018c21STomi Valkeinen 	 *  address to an even or vice versa. Since the bytes in the plane
36*f7018c21STomi Valkeinen 	 *  words must be assembled in new order, it seems wisest to make
37*f7018c21STomi Valkeinen 	 *  all movements by memmove_col().
38*f7018c21STomi Valkeinen 	 */
39*f7018c21STomi Valkeinen 
40*f7018c21STomi Valkeinen 	u8 *src, *dst;
41*f7018c21STomi Valkeinen 	u32 *s, *d;
42*f7018c21STomi Valkeinen 	int w, l , i, j;
43*f7018c21STomi Valkeinen 	u_int colsize;
44*f7018c21STomi Valkeinen 	u_int upwards = (dy < sy) || (dy == sy && dx < sx);
45*f7018c21STomi Valkeinen 
46*f7018c21STomi Valkeinen 	colsize = height;
47*f7018c21STomi Valkeinen 	if (!((sx ^ dx) & 15)) {
48*f7018c21STomi Valkeinen 		/* odd->odd or even->even */
49*f7018c21STomi Valkeinen 
50*f7018c21STomi Valkeinen 		if (upwards) {
51*f7018c21STomi Valkeinen 			src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
52*f7018c21STomi Valkeinen 			dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
53*f7018c21STomi Valkeinen 			if (sx & 15) {
54*f7018c21STomi Valkeinen 				memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
55*f7018c21STomi Valkeinen 				src += BPL * 2;
56*f7018c21STomi Valkeinen 				dst += BPL * 2;
57*f7018c21STomi Valkeinen 				width -= 8;
58*f7018c21STomi Valkeinen 			}
59*f7018c21STomi Valkeinen 			w = width >> 4;
60*f7018c21STomi Valkeinen 			if (w) {
61*f7018c21STomi Valkeinen 				s = (u32 *)src;
62*f7018c21STomi Valkeinen 				d = (u32 *)dst;
63*f7018c21STomi Valkeinen 				w *= BPL / 2;
64*f7018c21STomi Valkeinen 				l = next_line - w * 4;
65*f7018c21STomi Valkeinen 				for (j = height; j > 0; j--) {
66*f7018c21STomi Valkeinen 					for (i = w; i > 0; i--)
67*f7018c21STomi Valkeinen 						*d++ = *s++;
68*f7018c21STomi Valkeinen 					s = (u32 *)((u8 *)s + l);
69*f7018c21STomi Valkeinen 					d = (u32 *)((u8 *)d + l);
70*f7018c21STomi Valkeinen 				}
71*f7018c21STomi Valkeinen 			}
72*f7018c21STomi Valkeinen 			if (width & 15)
73*f7018c21STomi Valkeinen 				memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
74*f7018c21STomi Valkeinen 					      0xff00ff00, height, next_line - BPL * 2);
75*f7018c21STomi Valkeinen 		} else {
76*f7018c21STomi Valkeinen 			src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
77*f7018c21STomi Valkeinen 			dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
78*f7018c21STomi Valkeinen 
79*f7018c21STomi Valkeinen 			if ((sx + width) & 15) {
80*f7018c21STomi Valkeinen 				src -= BPL * 2;
81*f7018c21STomi Valkeinen 				dst -= BPL * 2;
82*f7018c21STomi Valkeinen 				memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
83*f7018c21STomi Valkeinen 				width -= 8;
84*f7018c21STomi Valkeinen 			}
85*f7018c21STomi Valkeinen 			w = width >> 4;
86*f7018c21STomi Valkeinen 			if (w) {
87*f7018c21STomi Valkeinen 				s = (u32 *)src;
88*f7018c21STomi Valkeinen 				d = (u32 *)dst;
89*f7018c21STomi Valkeinen 				w *= BPL / 2;
90*f7018c21STomi Valkeinen 				l = next_line - w * 4;
91*f7018c21STomi Valkeinen 				for (j = height; j > 0; j--) {
92*f7018c21STomi Valkeinen 					for (i = w; i > 0; i--)
93*f7018c21STomi Valkeinen 						*--d = *--s;
94*f7018c21STomi Valkeinen 					s = (u32 *)((u8 *)s - l);
95*f7018c21STomi Valkeinen 					d = (u32 *)((u8 *)d - l);
96*f7018c21STomi Valkeinen 				}
97*f7018c21STomi Valkeinen 			}
98*f7018c21STomi Valkeinen 			if (sx & 15)
99*f7018c21STomi Valkeinen 				memmove32_col(dst - (width - 16) / (8 / BPL),
100*f7018c21STomi Valkeinen 					      src - (width - 16) / (8 / BPL),
101*f7018c21STomi Valkeinen 					      0xff00ff, colsize, -next_line - BPL * 2);
102*f7018c21STomi Valkeinen 		}
103*f7018c21STomi Valkeinen 	} else {
104*f7018c21STomi Valkeinen 		/* odd->even or even->odd */
105*f7018c21STomi Valkeinen 		if (upwards) {
106*f7018c21STomi Valkeinen 			u32 *src32, *dst32;
107*f7018c21STomi Valkeinen 			u32 pval[4], v, v1, mask;
108*f7018c21STomi Valkeinen 			int i, j, w, f;
109*f7018c21STomi Valkeinen 
110*f7018c21STomi Valkeinen 			src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
111*f7018c21STomi Valkeinen 			dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
112*f7018c21STomi Valkeinen 
113*f7018c21STomi Valkeinen 			mask = 0xff00ff00;
114*f7018c21STomi Valkeinen 			f = 0;
115*f7018c21STomi Valkeinen 			w = width;
116*f7018c21STomi Valkeinen 			if (sx & 15) {
117*f7018c21STomi Valkeinen 				f = 1;
118*f7018c21STomi Valkeinen 				w += 8;
119*f7018c21STomi Valkeinen 			}
120*f7018c21STomi Valkeinen 			if ((sx + width) & 15)
121*f7018c21STomi Valkeinen 				f |= 2;
122*f7018c21STomi Valkeinen 			w >>= 4;
123*f7018c21STomi Valkeinen 			for (i = height; i; i--) {
124*f7018c21STomi Valkeinen 				src32 = (u32 *)src;
125*f7018c21STomi Valkeinen 				dst32 = (u32 *)dst;
126*f7018c21STomi Valkeinen 
127*f7018c21STomi Valkeinen 				if (f & 1) {
128*f7018c21STomi Valkeinen 					pval[0] = (*src32++ << 8) & mask;
129*f7018c21STomi Valkeinen 					pval[1] = (*src32++ << 8) & mask;
130*f7018c21STomi Valkeinen 				} else {
131*f7018c21STomi Valkeinen 					pval[0] = dst32[0] & mask;
132*f7018c21STomi Valkeinen 					pval[1] = dst32[1] & mask;
133*f7018c21STomi Valkeinen 				}
134*f7018c21STomi Valkeinen 
135*f7018c21STomi Valkeinen 				for (j = w; j > 0; j--) {
136*f7018c21STomi Valkeinen 					v = *src32++;
137*f7018c21STomi Valkeinen 					v1 = v & mask;
138*f7018c21STomi Valkeinen 					*dst32++ = pval[0] | (v1 >> 8);
139*f7018c21STomi Valkeinen 					pval[0] = (v ^ v1) << 8;
140*f7018c21STomi Valkeinen 					v = *src32++;
141*f7018c21STomi Valkeinen 					v1 = v & mask;
142*f7018c21STomi Valkeinen 					*dst32++ = pval[1] | (v1 >> 8);
143*f7018c21STomi Valkeinen 					pval[1] = (v ^ v1) << 8;
144*f7018c21STomi Valkeinen 				}
145*f7018c21STomi Valkeinen 
146*f7018c21STomi Valkeinen 				if (f & 2) {
147*f7018c21STomi Valkeinen 					dst32[0] = (dst32[0] & mask) | pval[0];
148*f7018c21STomi Valkeinen 					dst32[1] = (dst32[1] & mask) | pval[1];
149*f7018c21STomi Valkeinen 				}
150*f7018c21STomi Valkeinen 
151*f7018c21STomi Valkeinen 				src += next_line;
152*f7018c21STomi Valkeinen 				dst += next_line;
153*f7018c21STomi Valkeinen 			}
154*f7018c21STomi Valkeinen 		} else {
155*f7018c21STomi Valkeinen 			u32 *src32, *dst32;
156*f7018c21STomi Valkeinen 			u32 pval[4], v, v1, mask;
157*f7018c21STomi Valkeinen 			int i, j, w, f;
158*f7018c21STomi Valkeinen 
159*f7018c21STomi Valkeinen 			src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
160*f7018c21STomi Valkeinen 			dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
161*f7018c21STomi Valkeinen 
162*f7018c21STomi Valkeinen 			mask = 0xff00ff;
163*f7018c21STomi Valkeinen 			f = 0;
164*f7018c21STomi Valkeinen 			w = width;
165*f7018c21STomi Valkeinen 			if ((dx + width) & 15)
166*f7018c21STomi Valkeinen 				f = 1;
167*f7018c21STomi Valkeinen 			if (sx & 15) {
168*f7018c21STomi Valkeinen 				f |= 2;
169*f7018c21STomi Valkeinen 				w += 8;
170*f7018c21STomi Valkeinen 			}
171*f7018c21STomi Valkeinen 			w >>= 4;
172*f7018c21STomi Valkeinen 			for (i = height; i; i--) {
173*f7018c21STomi Valkeinen 				src32 = (u32 *)src;
174*f7018c21STomi Valkeinen 				dst32 = (u32 *)dst;
175*f7018c21STomi Valkeinen 
176*f7018c21STomi Valkeinen 				if (f & 1) {
177*f7018c21STomi Valkeinen 					pval[0] = dst32[-1] & mask;
178*f7018c21STomi Valkeinen 					pval[1] = dst32[-2] & mask;
179*f7018c21STomi Valkeinen 				} else {
180*f7018c21STomi Valkeinen 					pval[0] = (*--src32 >> 8) & mask;
181*f7018c21STomi Valkeinen 					pval[1] = (*--src32 >> 8) & mask;
182*f7018c21STomi Valkeinen 				}
183*f7018c21STomi Valkeinen 
184*f7018c21STomi Valkeinen 				for (j = w; j > 0; j--) {
185*f7018c21STomi Valkeinen 					v = *--src32;
186*f7018c21STomi Valkeinen 					v1 = v & mask;
187*f7018c21STomi Valkeinen 					*--dst32 = pval[0] | (v1 << 8);
188*f7018c21STomi Valkeinen 					pval[0] = (v ^ v1) >> 8;
189*f7018c21STomi Valkeinen 					v = *--src32;
190*f7018c21STomi Valkeinen 					v1 = v & mask;
191*f7018c21STomi Valkeinen 					*--dst32 = pval[1] | (v1 << 8);
192*f7018c21STomi Valkeinen 					pval[1] = (v ^ v1) >> 8;
193*f7018c21STomi Valkeinen 				}
194*f7018c21STomi Valkeinen 
195*f7018c21STomi Valkeinen 				if (!(f & 2)) {
196*f7018c21STomi Valkeinen 					dst32[-1] = (dst32[-1] & mask) | pval[0];
197*f7018c21STomi Valkeinen 					dst32[-2] = (dst32[-2] & mask) | pval[1];
198*f7018c21STomi Valkeinen 				}
199*f7018c21STomi Valkeinen 
200*f7018c21STomi Valkeinen 				src -= next_line;
201*f7018c21STomi Valkeinen 				dst -= next_line;
202*f7018c21STomi Valkeinen 			}
203*f7018c21STomi Valkeinen 		}
204*f7018c21STomi Valkeinen 	}
205*f7018c21STomi Valkeinen }
206*f7018c21STomi Valkeinen 
207*f7018c21STomi Valkeinen void atafb_iplan2p4_fillrect(struct fb_info *info, u_long next_line, u32 color,
208*f7018c21STomi Valkeinen                              int sy, int sx, int height, int width)
209*f7018c21STomi Valkeinen {
210*f7018c21STomi Valkeinen 	u32 *dest;
211*f7018c21STomi Valkeinen 	int rows, i;
212*f7018c21STomi Valkeinen 	u32 cval[4];
213*f7018c21STomi Valkeinen 
214*f7018c21STomi Valkeinen 	dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
215*f7018c21STomi Valkeinen 	if (sx & 15) {
216*f7018c21STomi Valkeinen 		u8 *dest8 = (u8 *)dest + 1;
217*f7018c21STomi Valkeinen 
218*f7018c21STomi Valkeinen 		expand8_col2mask(color, cval);
219*f7018c21STomi Valkeinen 
220*f7018c21STomi Valkeinen 		for (i = height; i; i--) {
221*f7018c21STomi Valkeinen 			fill8_col(dest8, cval);
222*f7018c21STomi Valkeinen 			dest8 += next_line;
223*f7018c21STomi Valkeinen 		}
224*f7018c21STomi Valkeinen 		dest += BPL / 2;
225*f7018c21STomi Valkeinen 		width -= 8;
226*f7018c21STomi Valkeinen 	}
227*f7018c21STomi Valkeinen 
228*f7018c21STomi Valkeinen 	expand16_col2mask(color, cval);
229*f7018c21STomi Valkeinen 	rows = width >> 4;
230*f7018c21STomi Valkeinen 	if (rows) {
231*f7018c21STomi Valkeinen 		u32 *d = dest;
232*f7018c21STomi Valkeinen 		u32 off = next_line - rows * BPL * 2;
233*f7018c21STomi Valkeinen 		for (i = height; i; i--) {
234*f7018c21STomi Valkeinen 			d = fill16_col(d, rows, cval);
235*f7018c21STomi Valkeinen 			d = (u32 *)((long)d + off);
236*f7018c21STomi Valkeinen 		}
237*f7018c21STomi Valkeinen 		dest += rows * BPL / 2;
238*f7018c21STomi Valkeinen 		width &= 15;
239*f7018c21STomi Valkeinen 	}
240*f7018c21STomi Valkeinen 
241*f7018c21STomi Valkeinen 	if (width) {
242*f7018c21STomi Valkeinen 		u8 *dest8 = (u8 *)dest;
243*f7018c21STomi Valkeinen 
244*f7018c21STomi Valkeinen 		expand8_col2mask(color, cval);
245*f7018c21STomi Valkeinen 
246*f7018c21STomi Valkeinen 		for (i = height; i; i--) {
247*f7018c21STomi Valkeinen 			fill8_col(dest8, cval);
248*f7018c21STomi Valkeinen 			dest8 += next_line;
249*f7018c21STomi Valkeinen 		}
250*f7018c21STomi Valkeinen 	}
251*f7018c21STomi Valkeinen }
252*f7018c21STomi Valkeinen 
253*f7018c21STomi Valkeinen void atafb_iplan2p4_linefill(struct fb_info *info, u_long next_line,
254*f7018c21STomi Valkeinen                              int dy, int dx, u32 width,
255*f7018c21STomi Valkeinen                              const u8 *data, u32 bgcolor, u32 fgcolor)
256*f7018c21STomi Valkeinen {
257*f7018c21STomi Valkeinen 	u32 *dest;
258*f7018c21STomi Valkeinen 	const u16 *data16;
259*f7018c21STomi Valkeinen 	int rows;
260*f7018c21STomi Valkeinen 	u32 fgm[4], bgm[4], m;
261*f7018c21STomi Valkeinen 
262*f7018c21STomi Valkeinen 	dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
263*f7018c21STomi Valkeinen 	if (dx & 15) {
264*f7018c21STomi Valkeinen 		fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
265*f7018c21STomi Valkeinen 		dest += BPL / 2;
266*f7018c21STomi Valkeinen 		width -= 8;
267*f7018c21STomi Valkeinen 	}
268*f7018c21STomi Valkeinen 
269*f7018c21STomi Valkeinen 	if (width >= 16) {
270*f7018c21STomi Valkeinen 		data16 = (const u16 *)data;
271*f7018c21STomi Valkeinen 		expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
272*f7018c21STomi Valkeinen 
273*f7018c21STomi Valkeinen 		for (rows = width / 16; rows; rows--) {
274*f7018c21STomi Valkeinen 			u16 d = *data16++;
275*f7018c21STomi Valkeinen 			m = d | ((u32)d << 16);
276*f7018c21STomi Valkeinen 			*dest++ = (m & fgm[0]) ^ bgm[0];
277*f7018c21STomi Valkeinen 			*dest++ = (m & fgm[1]) ^ bgm[1];
278*f7018c21STomi Valkeinen 		}
279*f7018c21STomi Valkeinen 
280*f7018c21STomi Valkeinen 		data = (const u8 *)data16;
281*f7018c21STomi Valkeinen 		width &= 15;
282*f7018c21STomi Valkeinen 	}
283*f7018c21STomi Valkeinen 
284*f7018c21STomi Valkeinen 	if (width)
285*f7018c21STomi Valkeinen 		fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
286*f7018c21STomi Valkeinen }
287*f7018c21STomi Valkeinen 
288*f7018c21STomi Valkeinen #ifdef MODULE
289*f7018c21STomi Valkeinen MODULE_LICENSE("GPL");
290*f7018c21STomi Valkeinen 
291*f7018c21STomi Valkeinen int init_module(void)
292*f7018c21STomi Valkeinen {
293*f7018c21STomi Valkeinen 	return 0;
294*f7018c21STomi Valkeinen }
295*f7018c21STomi Valkeinen 
296*f7018c21STomi Valkeinen void cleanup_module(void)
297*f7018c21STomi Valkeinen {
298*f7018c21STomi Valkeinen }
299*f7018c21STomi Valkeinen #endif /* MODULE */
300*f7018c21STomi Valkeinen 
301*f7018c21STomi Valkeinen 
302*f7018c21STomi Valkeinen     /*
303*f7018c21STomi Valkeinen      *  Visible symbols for modules
304*f7018c21STomi Valkeinen      */
305*f7018c21STomi Valkeinen 
306*f7018c21STomi Valkeinen EXPORT_SYMBOL(atafb_iplan2p4_copyarea);
307*f7018c21STomi Valkeinen EXPORT_SYMBOL(atafb_iplan2p4_fillrect);
308*f7018c21STomi Valkeinen EXPORT_SYMBOL(atafb_iplan2p4_linefill);
309