]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/video/fb_draw.h
pm2fb: replace busy waiting with cpu_relax
[karo-tx-linux.git] / drivers / video / fb_draw.h
1 #ifndef _FB_DRAW_H
2 #define _FB_DRAW_H
3
4 #include <asm/types.h>
5 #include <linux/fb.h>
6
7     /*
8      *  Compose two values, using a bitmask as decision value
9      *  This is equivalent to (a & mask) | (b & ~mask)
10      */
11
12 static inline unsigned long
13 comp(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
23 static inline unsigned long
24 pixel_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
48 static inline unsigned long
49 pixel_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
73
74 #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE
75
76 static inline u32 fb_shifted_pixels_mask_u32(u32 index, u32 bswapmask)
77 {
78         u32 mask;
79
80         if (!bswapmask) {
81                 mask = FB_SHIFT_HIGH(~(u32)0, index);
82         } else {
83                 mask = 0xff << FB_LEFT_POS(8);
84                 mask = FB_SHIFT_LOW(mask, index & (bswapmask)) & mask;
85                 mask = FB_SHIFT_HIGH(mask, index & ~(bswapmask));
86 #if defined(__i386__) || defined(__x86_64__)
87                 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
88                 if(index + bswapmask < 32)
89 #endif
90                         mask |= FB_SHIFT_HIGH(~(u32)0,
91                                         (index + bswapmask) & ~(bswapmask));
92         }
93         return mask;
94 }
95
96 static inline unsigned long fb_shifted_pixels_mask_long(u32 index, u32 bswapmask)
97 {
98         unsigned long mask;
99
100         if (!bswapmask) {
101                 mask = FB_SHIFT_HIGH(~0UL, index);
102         } else {
103                 mask = 0xff << FB_LEFT_POS(8);
104                 mask = FB_SHIFT_LOW(mask, index & (bswapmask)) & mask;
105                 mask = FB_SHIFT_HIGH(mask, index & ~(bswapmask));
106 #if defined(__i386__) || defined(__x86_64__)
107                 /* Shift argument is limited to 0 - 31 on x86 based CPU's */
108                 if(index + bswapmask < BITS_PER_LONG)
109 #endif
110                         mask |= FB_SHIFT_HIGH(~0UL,
111                                         (index + bswapmask) & ~(bswapmask));
112         }
113         return mask;
114 }
115
116
117 static inline u32 fb_compute_bswapmask(struct fb_info *info)
118 {
119         u32 bswapmask = 0;
120         unsigned bpp = info->var.bits_per_pixel;
121
122         if ((bpp < 8) && (info->var.nonstd & FB_NONSTD_REV_PIX_IN_B)) {
123                 /*
124                  * Reversed order of pixel layout in bytes
125                  * works only for 1, 2 and 4 bpp
126                  */
127                 bswapmask = 7 - bpp + 1;
128         }
129         return bswapmask;
130 }
131
132 #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
133
134 #define fb_shifted_pixels_mask_u32(i, b) FB_SHIFT_HIGH(~(u32)0, (i))
135 #define fb_shifted_pixels_mask_long(i, b) FB_SHIFT_HIGH(~0UL, (i))
136 #define fb_compute_bswapmask(...) 0
137
138 #endif  /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */
139
140 #endif /* FB_DRAW_H */