blob: 1db622192bde2252553eb91ce69123d6fc69512f [file] [log] [blame]
Antonino A. Daplasdc0e6e02007-05-08 00:39:08 -07001#ifndef _FB_DRAW_H
2#define _FB_DRAW_H
3
4#include <asm/types.h>
Pavel Pisa779121e2007-10-16 01:29:21 -07005#include <linux/fb.h>
Antonino A. Daplasdc0e6e02007-05-08 00:39:08 -07006
7 /*
8 * Compose two values, using a bitmask as decision value
9 * This is equivalent to (a & mask) | (b & ~mask)
10 */
11
12static inline unsigned long
13comp(unsigned long a, unsigned long b, unsigned long mask)
14{
15 return ((a ^ b) & mask) ^ b;
16}
17
18 /*
19 * Create a pattern with the given pixel's color
20 */
21
22#if BITS_PER_LONG == 64
23static inline unsigned long
24pixel_to_pat( u32 bpp, u32 pixel)
25{
26 switch (bpp) {
27 case 1:
28 return 0xfffffffffffffffful*pixel;
29 case 2:
30 return 0x5555555555555555ul*pixel;
31 case 4:
32 return 0x1111111111111111ul*pixel;
33 case 8:
34 return 0x0101010101010101ul*pixel;
35 case 12:
36 return 0x0001001001001001ul*pixel;
37 case 16:
38 return 0x0001000100010001ul*pixel;
39 case 24:
40 return 0x0000000001000001ul*pixel;
41 case 32:
42 return 0x0000000100000001ul*pixel;
43 default:
44 panic("pixel_to_pat(): unsupported pixelformat\n");
45 }
46}
47#else
48static inline unsigned long
49pixel_to_pat( u32 bpp, u32 pixel)
50{
51 switch (bpp) {
52 case 1:
53 return 0xfffffffful*pixel;
54 case 2:
55 return 0x55555555ul*pixel;
56 case 4:
57 return 0x11111111ul*pixel;
58 case 8:
59 return 0x01010101ul*pixel;
60 case 12:
61 return 0x00001001ul*pixel;
62 case 16:
63 return 0x00010001ul*pixel;
64 case 24:
65 return 0x00000001ul*pixel;
66 case 32:
67 return 0x00000001ul*pixel;
68 default:
69 panic("pixel_to_pat(): unsupported pixelformat\n");
70 }
71}
72#endif
Pavel Pisa779121e2007-10-16 01:29:21 -070073
74#ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
Pavel Pisa15afdd42007-10-16 01:29:55 -070075#if BITS_PER_LONG == 64
76#define REV_PIXELS_MASK1 0x5555555555555555ul
77#define REV_PIXELS_MASK2 0x3333333333333333ul
78#define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful
79#else
80#define REV_PIXELS_MASK1 0x55555555ul
81#define REV_PIXELS_MASK2 0x33333333ul
82#define REV_PIXELS_MASK4 0x0f0f0f0ful
83#endif
84
85static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
86 u32 bswapmask)
87{
88 if (bswapmask & 1)
89 val = comp(val >> 1, val << 1, REV_PIXELS_MASK1);
90 if (bswapmask & 2)
91 val = comp(val >> 2, val << 2, REV_PIXELS_MASK2);
92 if (bswapmask & 3)
93 val = comp(val >> 4, val << 4, REV_PIXELS_MASK4);
Anton Vorontsov55850f42008-02-06 01:40:23 -080094 return val;
Pavel Pisa15afdd42007-10-16 01:29:55 -070095}
Pavel Pisa779121e2007-10-16 01:29:21 -070096
Anton Vorontsove4c690e2008-04-28 02:14:49 -070097static inline u32 fb_shifted_pixels_mask_u32(struct fb_info *p, u32 index,
98 u32 bswapmask)
Pavel Pisa779121e2007-10-16 01:29:21 -070099{
100 u32 mask;
101
102 if (!bswapmask) {
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700103 mask = FB_SHIFT_HIGH(p, ~(u32)0, index);
Pavel Pisa779121e2007-10-16 01:29:21 -0700104 } else {
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700105 mask = 0xff << FB_LEFT_POS(p, 8);
106 mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask;
107 mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask));
Pavel Pisa779121e2007-10-16 01:29:21 -0700108#if defined(__i386__) || defined(__x86_64__)
109 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
110 if(index + bswapmask < 32)
111#endif
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700112 mask |= FB_SHIFT_HIGH(p, ~(u32)0,
Pavel Pisa779121e2007-10-16 01:29:21 -0700113 (index + bswapmask) & ~(bswapmask));
114 }
115 return mask;
116}
117
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700118static inline unsigned long fb_shifted_pixels_mask_long(struct fb_info *p,
119 u32 index,
120 u32 bswapmask)
Pavel Pisa779121e2007-10-16 01:29:21 -0700121{
122 unsigned long mask;
123
124 if (!bswapmask) {
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700125 mask = FB_SHIFT_HIGH(p, ~0UL, index);
Pavel Pisa779121e2007-10-16 01:29:21 -0700126 } else {
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700127 mask = 0xff << FB_LEFT_POS(p, 8);
128 mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask;
129 mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask));
Pavel Pisa779121e2007-10-16 01:29:21 -0700130#if defined(__i386__) || defined(__x86_64__)
131 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
132 if(index + bswapmask < BITS_PER_LONG)
133#endif
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700134 mask |= FB_SHIFT_HIGH(p, ~0UL,
Pavel Pisa779121e2007-10-16 01:29:21 -0700135 (index + bswapmask) & ~(bswapmask));
136 }
137 return mask;
138}
139
140
141static inline u32 fb_compute_bswapmask(struct fb_info *info)
142{
143 u32 bswapmask = 0;
144 unsigned bpp = info->var.bits_per_pixel;
145
146 if ((bpp < 8) && (info->var.nonstd & FB_NONSTD_REV_PIX_IN_B)) {
147 /*
148 * Reversed order of pixel layout in bytes
149 * works only for 1, 2 and 4 bpp
150 */
151 bswapmask = 7 - bpp + 1;
152 }
153 return bswapmask;
154}
155
156#else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
157
Pavel Pisa15afdd42007-10-16 01:29:55 -0700158static inline unsigned long fb_rev_pixels_in_long(unsigned long val,
159 u32 bswapmask)
160{
161 return val;
162}
163
Anton Vorontsove4c690e2008-04-28 02:14:49 -0700164#define fb_shifted_pixels_mask_u32(p, i, b) FB_SHIFT_HIGH((p), ~(u32)0, (i))
165#define fb_shifted_pixels_mask_long(p, i, b) FB_SHIFT_HIGH((p), ~0UL, (i))
Pavel Pisa779121e2007-10-16 01:29:21 -0700166#define fb_compute_bswapmask(...) 0
167
168#endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
169
Antonino A. Daplasdc0e6e02007-05-08 00:39:08 -0700170#endif /* FB_DRAW_H */