Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 1 | #include<linux/module.h> |
| 2 | #include<linux/kernel.h> |
| 3 | #include<linux/errno.h> |
| 4 | #include<linux/string.h> |
| 5 | #include<linux/mm.h> |
| 6 | #include<linux/slab.h> |
| 7 | #include<linux/delay.h> |
| 8 | #include<linux/fb.h> |
| 9 | #include<linux/ioport.h> |
| 10 | #include<linux/init.h> |
| 11 | #include<linux/pci.h> |
| 12 | #include<linux/vmalloc.h> |
| 13 | #include<linux/pagemap.h> |
| 14 | #include <linux/console.h> |
| 15 | #include<linux/platform_device.h> |
| 16 | #include<linux/screen_info.h> |
| 17 | |
| 18 | #include "sm750.h" |
| 19 | #include "sm750_accel.h" |
| 20 | #include "sm750_help.h" |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 21 | static inline void write_dpr(struct lynx_accel * accel, int offset, u32 regValue) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 22 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 23 | writel(regValue, accel->dprBase + offset); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 24 | } |
| 25 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 26 | static inline u32 read_dpr(struct lynx_accel * accel, int offset) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 27 | { |
| 28 | return readl(accel->dprBase + offset); |
| 29 | } |
| 30 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 31 | static inline void write_dpPort(struct lynx_accel * accel, u32 data) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 32 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 33 | writel(data, accel->dpPortBase); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void hw_de_init(struct lynx_accel * accel) |
| 37 | { |
| 38 | /* setup 2d engine registers */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 39 | u32 reg, clr; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 40 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 41 | write_dpr(accel, DE_MASKS, 0xFFFFFFFF); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 42 | |
| 43 | /* dpr1c */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 44 | reg = FIELD_SET(0, DE_STRETCH_FORMAT, PATTERN_XY, NORMAL)| |
| 45 | FIELD_VALUE(0, DE_STRETCH_FORMAT, PATTERN_Y, 0)| |
| 46 | FIELD_VALUE(0, DE_STRETCH_FORMAT, PATTERN_X, 0)| |
| 47 | FIELD_SET(0, DE_STRETCH_FORMAT, ADDRESSING, XY)| |
| 48 | FIELD_VALUE(0, DE_STRETCH_FORMAT, SOURCE_HEIGHT, 3); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 49 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 50 | clr = FIELD_CLEAR(DE_STRETCH_FORMAT, PATTERN_XY)& |
| 51 | FIELD_CLEAR(DE_STRETCH_FORMAT, PATTERN_Y)& |
| 52 | FIELD_CLEAR(DE_STRETCH_FORMAT, PATTERN_X)& |
| 53 | FIELD_CLEAR(DE_STRETCH_FORMAT, ADDRESSING)& |
| 54 | FIELD_CLEAR(DE_STRETCH_FORMAT, SOURCE_HEIGHT); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 55 | |
| 56 | /* DE_STRETCH bpp format need be initilized in setMode routine */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 57 | write_dpr(accel, DE_STRETCH_FORMAT, (read_dpr(accel, DE_STRETCH_FORMAT) & clr) | reg); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 58 | |
| 59 | /* disable clipping and transparent */ |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 60 | write_dpr(accel, DE_CLIP_TL, 0); /* dpr2c */ |
| 61 | write_dpr(accel, DE_CLIP_BR, 0); /* dpr30 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 62 | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 63 | write_dpr(accel, DE_COLOR_COMPARE_MASK, 0); /* dpr24 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 64 | write_dpr(accel, DE_COLOR_COMPARE, 0); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 65 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 66 | reg = FIELD_SET(0, DE_CONTROL, TRANSPARENCY, DISABLE)| |
| 67 | FIELD_SET(0, DE_CONTROL, TRANSPARENCY_MATCH, OPAQUE)| |
| 68 | FIELD_SET(0, DE_CONTROL, TRANSPARENCY_SELECT, SOURCE); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 69 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 70 | clr = FIELD_CLEAR(DE_CONTROL, TRANSPARENCY)& |
| 71 | FIELD_CLEAR(DE_CONTROL, TRANSPARENCY_MATCH)& |
| 72 | FIELD_CLEAR(DE_CONTROL, TRANSPARENCY_SELECT); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 73 | |
| 74 | /* dpr0c */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 75 | write_dpr(accel, DE_CONTROL, (read_dpr(accel, DE_CONTROL)&clr)|reg); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* set2dformat only be called from setmode functions |
| 79 | * but if you need dual framebuffer driver,need call set2dformat |
| 80 | * every time you use 2d function */ |
| 81 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 82 | void hw_set2dformat(struct lynx_accel * accel, int fmt) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 83 | { |
| 84 | u32 reg; |
| 85 | |
| 86 | /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 87 | reg = read_dpr(accel, DE_STRETCH_FORMAT); |
| 88 | reg = FIELD_VALUE(reg, DE_STRETCH_FORMAT, PIXEL_FORMAT, fmt); |
| 89 | write_dpr(accel, DE_STRETCH_FORMAT, reg); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 90 | } |
| 91 | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 92 | int hw_fillrect(struct lynx_accel * accel, |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 93 | u32 base, u32 pitch, u32 Bpp, |
| 94 | u32 x, u32 y, u32 width, u32 height, |
| 95 | u32 color, u32 rop) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 96 | { |
| 97 | u32 deCtrl; |
| 98 | |
| 99 | if(accel->de_wait() != 0) |
| 100 | { |
| 101 | /* int time wait and always busy,seems hardware |
| 102 | * got something error */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 103 | pr_debug("%s:De engine always bussy\n", __func__); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 104 | return -1; |
| 105 | } |
| 106 | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 107 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 108 | write_dpr(accel, DE_PITCH, |
| 109 | FIELD_VALUE(0, DE_PITCH, DESTINATION, pitch/Bpp)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 110 | FIELD_VALUE(0, DE_PITCH, SOURCE, pitch/Bpp)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 111 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 112 | write_dpr(accel, DE_WINDOW_WIDTH, |
| 113 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, pitch/Bpp)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 114 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, pitch/Bpp)); /* dpr44 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 115 | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 116 | write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 117 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 118 | write_dpr(accel, DE_DESTINATION, |
| 119 | FIELD_SET(0, DE_DESTINATION, WRAP, DISABLE)| |
| 120 | FIELD_VALUE(0, DE_DESTINATION, X, x)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 121 | FIELD_VALUE(0, DE_DESTINATION, Y, y)); /* dpr4 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 122 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 123 | write_dpr(accel, DE_DIMENSION, |
| 124 | FIELD_VALUE(0, DE_DIMENSION, X, width)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 125 | FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr8 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 126 | |
| 127 | deCtrl = |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 128 | FIELD_SET(0, DE_CONTROL, STATUS, START)| |
| 129 | FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)| |
| 130 | FIELD_SET(0, DE_CONTROL, LAST_PIXEL, ON)| |
| 131 | FIELD_SET(0, DE_CONTROL, COMMAND, RECTANGLE_FILL)| |
| 132 | FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 133 | FIELD_VALUE(0, DE_CONTROL, ROP, rop); /* dpr0xc */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 134 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 135 | write_dpr(accel, DE_CONTROL, deCtrl); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | int hw_copyarea( |
| 140 | struct lynx_accel * accel, |
| 141 | unsigned int sBase, /* Address of source: offset in frame buffer */ |
| 142 | unsigned int sPitch, /* Pitch value of source surface in BYTE */ |
| 143 | unsigned int sx, |
| 144 | unsigned int sy, /* Starting coordinate of source surface */ |
| 145 | unsigned int dBase, /* Address of destination: offset in frame buffer */ |
| 146 | unsigned int dPitch, /* Pitch value of destination surface in BYTE */ |
| 147 | unsigned int Bpp, /* Color depth of destination surface */ |
| 148 | unsigned int dx, |
| 149 | unsigned int dy, /* Starting coordinate of destination surface */ |
| 150 | unsigned int width, |
| 151 | unsigned int height, /* width and height of rectangle in pixel value */ |
| 152 | unsigned int rop2) /* ROP value */ |
| 153 | { |
| 154 | unsigned int nDirection, de_ctrl; |
| 155 | int opSign; |
| 156 | nDirection = LEFT_TO_RIGHT; |
| 157 | /* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */ |
| 158 | opSign = 1; |
| 159 | de_ctrl = 0; |
| 160 | |
| 161 | /* If source and destination are the same surface, need to check for overlay cases */ |
| 162 | if (sBase == dBase && sPitch == dPitch) |
| 163 | { |
| 164 | /* Determine direction of operation */ |
| 165 | if (sy < dy) |
| 166 | { |
| 167 | /* +----------+ |
| 168 | |S | |
| 169 | | +----------+ |
| 170 | | | | | |
| 171 | | | | | |
| 172 | +---|------+ | |
| 173 | | D| |
| 174 | +----------+ */ |
| 175 | |
| 176 | nDirection = BOTTOM_TO_TOP; |
| 177 | } |
| 178 | else if (sy > dy) |
| 179 | { |
| 180 | /* +----------+ |
| 181 | |D | |
| 182 | | +----------+ |
| 183 | | | | | |
| 184 | | | | | |
| 185 | +---|------+ | |
| 186 | | S| |
| 187 | +----------+ */ |
| 188 | |
| 189 | nDirection = TOP_TO_BOTTOM; |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | /* sy == dy */ |
| 194 | |
| 195 | if (sx <= dx) |
| 196 | { |
| 197 | /* +------+---+------+ |
| 198 | |S | | D| |
| 199 | | | | | |
| 200 | | | | | |
| 201 | | | | | |
| 202 | +------+---+------+ */ |
| 203 | |
| 204 | nDirection = RIGHT_TO_LEFT; |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | /* sx > dx */ |
| 209 | |
| 210 | /* +------+---+------+ |
| 211 | |D | | S| |
| 212 | | | | | |
| 213 | | | | | |
| 214 | | | | | |
| 215 | +------+---+------+ */ |
| 216 | |
| 217 | nDirection = LEFT_TO_RIGHT; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | if ((nDirection == BOTTOM_TO_TOP) || (nDirection == RIGHT_TO_LEFT)) |
| 223 | { |
| 224 | sx += width - 1; |
| 225 | sy += height - 1; |
| 226 | dx += width - 1; |
| 227 | dy += height - 1; |
| 228 | opSign = (-1); |
| 229 | } |
| 230 | |
| 231 | /* Note: |
| 232 | DE_FOREGROUND are DE_BACKGROUND are don't care. |
| 233 | DE_COLOR_COMPARE and DE_COLOR_COMPARE_MAKS are set by set deSetTransparency(). |
| 234 | */ |
| 235 | |
| 236 | /* 2D Source Base. |
| 237 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 238 | */ |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 239 | write_dpr(accel, DE_WINDOW_SOURCE_BASE, sBase); /* dpr40 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 240 | |
| 241 | /* 2D Destination Base. |
| 242 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 243 | */ |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 244 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); /* dpr44 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 245 | |
| 246 | #if 0 |
| 247 | /* Program pitch (distance between the 1st points of two adjacent lines). |
| 248 | Note that input pitch is BYTE value, but the 2D Pitch register uses |
Carlos E. Garcia | 69e98df | 2015-04-24 09:40:42 -0400 | [diff] [blame] | 249 | pixel values. Need Byte to pixel conversion. |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 250 | */ |
| 251 | if(Bpp == 3){ |
| 252 | sx *= 3; |
| 253 | dx *= 3; |
| 254 | width *= 3; |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 255 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 256 | FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 257 | FIELD_VALUE(0, DE_PITCH, SOURCE, sPitch)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 258 | } |
| 259 | else |
| 260 | #endif |
| 261 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 262 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 263 | FIELD_VALUE(0, DE_PITCH, DESTINATION, (dPitch/Bpp)) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 264 | FIELD_VALUE(0, DE_PITCH, SOURCE, (sPitch/Bpp))); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* Screen Window width in Pixels. |
| 268 | 2D engine uses this value to calculate the linear address in frame buffer for a given point. |
| 269 | */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 270 | write_dpr(accel, DE_WINDOW_WIDTH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 271 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/Bpp)) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 272 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (sPitch/Bpp))); /* dpr3c */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 273 | |
| 274 | if (accel->de_wait() != 0){ |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | { |
| 279 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 280 | write_dpr(accel, DE_SOURCE, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 281 | FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) | |
| 282 | FIELD_VALUE(0, DE_SOURCE, X_K1, sx) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 283 | FIELD_VALUE(0, DE_SOURCE, Y_K2, sy)); /* dpr0 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 284 | write_dpr(accel, DE_DESTINATION, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 285 | FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) | |
| 286 | FIELD_VALUE(0, DE_DESTINATION, X, dx) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 287 | FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 288 | write_dpr(accel, DE_DIMENSION, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 289 | FIELD_VALUE(0, DE_DIMENSION, X, width) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 290 | FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 291 | |
| 292 | de_ctrl = |
| 293 | FIELD_VALUE(0, DE_CONTROL, ROP, rop2) | |
| 294 | FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) | |
| 295 | FIELD_SET(0, DE_CONTROL, COMMAND, BITBLT) | |
| 296 | ((nDirection == RIGHT_TO_LEFT) ? |
| 297 | FIELD_SET(0, DE_CONTROL, DIRECTION, RIGHT_TO_LEFT) |
| 298 | : FIELD_SET(0, DE_CONTROL, DIRECTION, LEFT_TO_RIGHT)) | |
| 299 | FIELD_SET(0, DE_CONTROL, STATUS, START); |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 300 | write_dpr(accel, DE_CONTROL, de_ctrl); /* dpr0c */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static unsigned int deGetTransparency(struct lynx_accel * accel) |
| 307 | { |
| 308 | unsigned int de_ctrl; |
| 309 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 310 | de_ctrl = read_dpr(accel, DE_CONTROL); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 311 | |
| 312 | de_ctrl &= |
| 313 | FIELD_MASK(DE_CONTROL_TRANSPARENCY_MATCH) | |
| 314 | FIELD_MASK(DE_CONTROL_TRANSPARENCY_SELECT)| |
| 315 | FIELD_MASK(DE_CONTROL_TRANSPARENCY); |
| 316 | |
| 317 | return de_ctrl; |
| 318 | } |
| 319 | |
Greg Kroah-Hartman | 7c6f3fd | 2015-03-10 22:03:01 +0100 | [diff] [blame] | 320 | int hw_imageblit(struct lynx_accel *accel, |
| 321 | const char *pSrcbuf, /* pointer to start of source buffer in system memory */ |
| 322 | u32 srcDelta, /* Pitch value (in bytes) of the source buffer, +ive means top down and -ive mean button up */ |
| 323 | u32 startBit, /* Mono data can start at any bit in a byte, this value should be 0 to 7 */ |
| 324 | u32 dBase, /* Address of destination: offset in frame buffer */ |
| 325 | u32 dPitch, /* Pitch value of destination surface in BYTE */ |
| 326 | u32 bytePerPixel, /* Color depth of destination surface */ |
| 327 | u32 dx, |
| 328 | u32 dy, /* Starting coordinate of destination surface */ |
| 329 | u32 width, |
| 330 | u32 height, /* width and height of rectange in pixel value */ |
| 331 | u32 fColor, /* Foreground color (corresponding to a 1 in the monochrome data */ |
| 332 | u32 bColor, /* Background color (corresponding to a 0 in the monochrome data */ |
| 333 | u32 rop2) /* ROP value */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 334 | { |
| 335 | unsigned int ulBytesPerScan; |
| 336 | unsigned int ul4BytesPerScan; |
| 337 | unsigned int ulBytesRemain; |
| 338 | unsigned int de_ctrl = 0; |
| 339 | unsigned char ajRemain[4]; |
| 340 | int i, j; |
| 341 | |
| 342 | startBit &= 7; /* Just make sure the start bit is within legal range */ |
| 343 | ulBytesPerScan = (width + startBit + 7) / 8; |
| 344 | ul4BytesPerScan = ulBytesPerScan & ~3; |
| 345 | ulBytesRemain = ulBytesPerScan & 3; |
| 346 | |
| 347 | if(accel->de_wait() != 0) |
| 348 | { |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 349 | return -1; |
| 350 | } |
| 351 | |
| 352 | /* 2D Source Base. |
| 353 | Use 0 for HOST Blt. |
| 354 | */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 355 | write_dpr(accel, DE_WINDOW_SOURCE_BASE, 0); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 356 | |
| 357 | /* 2D Destination Base. |
| 358 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 359 | */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 360 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 361 | #if 0 |
| 362 | /* Program pitch (distance between the 1st points of two adjacent lines). |
| 363 | Note that input pitch is BYTE value, but the 2D Pitch register uses |
Carlos E. Garcia | 69e98df | 2015-04-24 09:40:42 -0400 | [diff] [blame] | 364 | pixel values. Need Byte to pixel conversion. |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 365 | */ |
| 366 | if(bytePerPixel == 3 ){ |
| 367 | dx *= 3; |
| 368 | width *= 3; |
| 369 | startBit *= 3; |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 370 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 371 | FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 372 | FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 373 | |
| 374 | } |
| 375 | else |
| 376 | #endif |
| 377 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 378 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 379 | FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch/bytePerPixel) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 380 | FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch/bytePerPixel)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Screen Window width in Pixels. |
| 384 | 2D engine uses this value to calculate the linear address in frame buffer for a given point. |
| 385 | */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 386 | write_dpr(accel, DE_WINDOW_WIDTH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 387 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/bytePerPixel)) | |
| 388 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (dPitch/bytePerPixel))); |
| 389 | |
| 390 | /* Note: For 2D Source in Host Write, only X_K1_MONO field is needed, and Y_K2 field is not used. |
| 391 | For mono bitmap, use startBit for X_K1. */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 392 | write_dpr(accel, DE_SOURCE, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 393 | FIELD_SET (0, DE_SOURCE, WRAP, DISABLE) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 394 | FIELD_VALUE(0, DE_SOURCE, X_K1_MONO, startBit)); /* dpr00 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 395 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 396 | write_dpr(accel, DE_DESTINATION, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 397 | FIELD_SET (0, DE_DESTINATION, WRAP, DISABLE) | |
| 398 | FIELD_VALUE(0, DE_DESTINATION, X, dx) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 399 | FIELD_VALUE(0, DE_DESTINATION, Y, dy)); /* dpr04 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 400 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 401 | write_dpr(accel, DE_DIMENSION, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 402 | FIELD_VALUE(0, DE_DIMENSION, X, width) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame^] | 403 | FIELD_VALUE(0, DE_DIMENSION, Y_ET, height)); /* dpr08 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 404 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 405 | write_dpr(accel, DE_FOREGROUND, fColor); |
| 406 | write_dpr(accel, DE_BACKGROUND, bColor); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 407 | |
| 408 | de_ctrl = FIELD_VALUE(0, DE_CONTROL, ROP, rop2) | |
| 409 | FIELD_SET(0, DE_CONTROL, ROP_SELECT, ROP2) | |
| 410 | FIELD_SET(0, DE_CONTROL, COMMAND, HOST_WRITE) | |
| 411 | FIELD_SET(0, DE_CONTROL, HOST, MONO) | |
| 412 | FIELD_SET(0, DE_CONTROL, STATUS, START); |
| 413 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 414 | write_dpr(accel, DE_CONTROL, de_ctrl | deGetTransparency(accel)); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 415 | |
| 416 | /* Write MONO data (line by line) to 2D Engine data port */ |
| 417 | for (i=0; i<height; i++) |
| 418 | { |
| 419 | /* For each line, send the data in chunks of 4 bytes */ |
| 420 | for (j=0; j<(ul4BytesPerScan/4); j++) |
| 421 | { |
| 422 | write_dpPort(accel, *(unsigned int *)(pSrcbuf + (j * 4))); |
| 423 | } |
| 424 | |
| 425 | if (ulBytesRemain) |
| 426 | { |
| 427 | memcpy(ajRemain, pSrcbuf+ul4BytesPerScan, ulBytesRemain); |
| 428 | write_dpPort(accel, *(unsigned int *)ajRemain); |
| 429 | } |
| 430 | |
| 431 | pSrcbuf += srcDelta; |
| 432 | } |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |