Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 1 | #ifndef _FB_DRAW_H |
| 2 | #define _FB_DRAW_H |
| 3 | |
| 4 | #include <asm/types.h> |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 5 | #include <linux/fb.h> |
Benjamin Herrenschmidt | 3f6a558 | 2012-07-24 18:19:13 +1000 | [diff] [blame] | 6 | #include <linux/bug.h> |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 7 | |
| 8 | /* |
| 9 | * Compose two values, using a bitmask as decision value |
| 10 | * This is equivalent to (a & mask) | (b & ~mask) |
| 11 | */ |
| 12 | |
| 13 | static inline unsigned long |
| 14 | comp(unsigned long a, unsigned long b, unsigned long mask) |
| 15 | { |
| 16 | return ((a ^ b) & mask) ^ b; |
| 17 | } |
| 18 | |
| 19 | /* |
| 20 | * Create a pattern with the given pixel's color |
| 21 | */ |
| 22 | |
| 23 | #if BITS_PER_LONG == 64 |
| 24 | static inline unsigned long |
| 25 | pixel_to_pat( u32 bpp, u32 pixel) |
| 26 | { |
| 27 | switch (bpp) { |
| 28 | case 1: |
| 29 | return 0xfffffffffffffffful*pixel; |
| 30 | case 2: |
| 31 | return 0x5555555555555555ul*pixel; |
| 32 | case 4: |
| 33 | return 0x1111111111111111ul*pixel; |
| 34 | case 8: |
| 35 | return 0x0101010101010101ul*pixel; |
| 36 | case 12: |
Michal Januszewski | bdca0f9 | 2009-05-06 16:02:56 -0700 | [diff] [blame] | 37 | return 0x1001001001001001ul*pixel; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 38 | case 16: |
| 39 | return 0x0001000100010001ul*pixel; |
| 40 | case 24: |
Michal Januszewski | bdca0f9 | 2009-05-06 16:02:56 -0700 | [diff] [blame] | 41 | return 0x0001000001000001ul*pixel; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 42 | case 32: |
| 43 | return 0x0000000100000001ul*pixel; |
| 44 | default: |
Benjamin Herrenschmidt | 3f6a558 | 2012-07-24 18:19:13 +1000 | [diff] [blame] | 45 | WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp); |
| 46 | return 0; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | #else |
| 50 | static inline unsigned long |
| 51 | pixel_to_pat( u32 bpp, u32 pixel) |
| 52 | { |
| 53 | switch (bpp) { |
| 54 | case 1: |
| 55 | return 0xfffffffful*pixel; |
| 56 | case 2: |
| 57 | return 0x55555555ul*pixel; |
| 58 | case 4: |
| 59 | return 0x11111111ul*pixel; |
| 60 | case 8: |
| 61 | return 0x01010101ul*pixel; |
| 62 | case 12: |
Michal Januszewski | bdca0f9 | 2009-05-06 16:02:56 -0700 | [diff] [blame] | 63 | return 0x01001001ul*pixel; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 64 | case 16: |
| 65 | return 0x00010001ul*pixel; |
| 66 | case 24: |
Michal Januszewski | bdca0f9 | 2009-05-06 16:02:56 -0700 | [diff] [blame] | 67 | return 0x01000001ul*pixel; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 68 | case 32: |
| 69 | return 0x00000001ul*pixel; |
| 70 | default: |
Benjamin Herrenschmidt | 3f6a558 | 2012-07-24 18:19:13 +1000 | [diff] [blame] | 71 | WARN(1, "pixel_to_pat(): unsupported pixelformat %d\n", bpp); |
| 72 | return 0; |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | #endif |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 76 | |
| 77 | #ifdef CONFIG_FB_CFB_REV_PIXELS_IN_BYTE |
Pavel Pisa | 15afdd4 | 2007-10-16 01:29:55 -0700 | [diff] [blame] | 78 | #if BITS_PER_LONG == 64 |
| 79 | #define REV_PIXELS_MASK1 0x5555555555555555ul |
| 80 | #define REV_PIXELS_MASK2 0x3333333333333333ul |
| 81 | #define REV_PIXELS_MASK4 0x0f0f0f0f0f0f0f0ful |
| 82 | #else |
| 83 | #define REV_PIXELS_MASK1 0x55555555ul |
| 84 | #define REV_PIXELS_MASK2 0x33333333ul |
| 85 | #define REV_PIXELS_MASK4 0x0f0f0f0ful |
| 86 | #endif |
| 87 | |
| 88 | static inline unsigned long fb_rev_pixels_in_long(unsigned long val, |
| 89 | u32 bswapmask) |
| 90 | { |
| 91 | if (bswapmask & 1) |
| 92 | val = comp(val >> 1, val << 1, REV_PIXELS_MASK1); |
| 93 | if (bswapmask & 2) |
| 94 | val = comp(val >> 2, val << 2, REV_PIXELS_MASK2); |
| 95 | if (bswapmask & 3) |
| 96 | val = comp(val >> 4, val << 4, REV_PIXELS_MASK4); |
Anton Vorontsov | 55850f4 | 2008-02-06 01:40:23 -0800 | [diff] [blame] | 97 | return val; |
Pavel Pisa | 15afdd4 | 2007-10-16 01:29:55 -0700 | [diff] [blame] | 98 | } |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 99 | |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 100 | static inline u32 fb_shifted_pixels_mask_u32(struct fb_info *p, u32 index, |
| 101 | u32 bswapmask) |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 102 | { |
| 103 | u32 mask; |
| 104 | |
| 105 | if (!bswapmask) { |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 106 | mask = FB_SHIFT_HIGH(p, ~(u32)0, index); |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 107 | } else { |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 108 | mask = 0xff << FB_LEFT_POS(p, 8); |
| 109 | mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask; |
| 110 | mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask)); |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 111 | #if defined(__i386__) || defined(__x86_64__) |
| 112 | /* Shift argument is limited to 0 - 31 on x86 based CPU's */ |
| 113 | if(index + bswapmask < 32) |
| 114 | #endif |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 115 | mask |= FB_SHIFT_HIGH(p, ~(u32)0, |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 116 | (index + bswapmask) & ~(bswapmask)); |
| 117 | } |
| 118 | return mask; |
| 119 | } |
| 120 | |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 121 | static inline unsigned long fb_shifted_pixels_mask_long(struct fb_info *p, |
| 122 | u32 index, |
| 123 | u32 bswapmask) |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 124 | { |
| 125 | unsigned long mask; |
| 126 | |
| 127 | if (!bswapmask) { |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 128 | mask = FB_SHIFT_HIGH(p, ~0UL, index); |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 129 | } else { |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 130 | mask = 0xff << FB_LEFT_POS(p, 8); |
| 131 | mask = FB_SHIFT_LOW(p, mask, index & (bswapmask)) & mask; |
| 132 | mask = FB_SHIFT_HIGH(p, mask, index & ~(bswapmask)); |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 133 | #if defined(__i386__) || defined(__x86_64__) |
| 134 | /* Shift argument is limited to 0 - 31 on x86 based CPU's */ |
| 135 | if(index + bswapmask < BITS_PER_LONG) |
| 136 | #endif |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 137 | mask |= FB_SHIFT_HIGH(p, ~0UL, |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 138 | (index + bswapmask) & ~(bswapmask)); |
| 139 | } |
| 140 | return mask; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | static inline u32 fb_compute_bswapmask(struct fb_info *info) |
| 145 | { |
| 146 | u32 bswapmask = 0; |
| 147 | unsigned bpp = info->var.bits_per_pixel; |
| 148 | |
| 149 | if ((bpp < 8) && (info->var.nonstd & FB_NONSTD_REV_PIX_IN_B)) { |
| 150 | /* |
| 151 | * Reversed order of pixel layout in bytes |
| 152 | * works only for 1, 2 and 4 bpp |
| 153 | */ |
| 154 | bswapmask = 7 - bpp + 1; |
| 155 | } |
| 156 | return bswapmask; |
| 157 | } |
| 158 | |
| 159 | #else /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */ |
| 160 | |
Pavel Pisa | 15afdd4 | 2007-10-16 01:29:55 -0700 | [diff] [blame] | 161 | static inline unsigned long fb_rev_pixels_in_long(unsigned long val, |
| 162 | u32 bswapmask) |
| 163 | { |
| 164 | return val; |
| 165 | } |
| 166 | |
Anton Vorontsov | e4c690e | 2008-04-28 02:14:49 -0700 | [diff] [blame] | 167 | #define fb_shifted_pixels_mask_u32(p, i, b) FB_SHIFT_HIGH((p), ~(u32)0, (i)) |
| 168 | #define fb_shifted_pixels_mask_long(p, i, b) FB_SHIFT_HIGH((p), ~0UL, (i)) |
Pavel Pisa | 779121e | 2007-10-16 01:29:21 -0700 | [diff] [blame] | 169 | #define fb_compute_bswapmask(...) 0 |
| 170 | |
| 171 | #endif /* CONFIG_FB_CFB_REV_PIXELS_IN_BYTE */ |
| 172 | |
Michal Januszewski | bdca0f9 | 2009-05-06 16:02:56 -0700 | [diff] [blame] | 173 | #define cpu_to_le_long _cpu_to_le_long(BITS_PER_LONG) |
| 174 | #define _cpu_to_le_long(x) __cpu_to_le_long(x) |
| 175 | #define __cpu_to_le_long(x) cpu_to_le##x |
| 176 | |
| 177 | #define le_long_to_cpu _le_long_to_cpu(BITS_PER_LONG) |
| 178 | #define _le_long_to_cpu(x) __le_long_to_cpu(x) |
| 179 | #define __le_long_to_cpu(x) le##x##_to_cpu |
| 180 | |
| 181 | static inline unsigned long rolx(unsigned long word, unsigned int shift, unsigned int x) |
| 182 | { |
| 183 | return (word << shift) | (word >> (x - shift)); |
| 184 | } |
| 185 | |
Antonino A. Daplas | dc0e6e0 | 2007-05-08 00:39:08 -0700 | [diff] [blame] | 186 | #endif /* FB_DRAW_H */ |