Mike Rapoport | 67088d4 | 2015-09-22 12:01:16 +0300 | [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> |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 14 | #include <linux/console.h> |
Mike Rapoport | 67088d4 | 2015-09-22 12:01:16 +0300 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/screen_info.h> |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 17 | |
| 18 | #include "sm750.h" |
| 19 | #include "sm750_accel.h" |
| 20 | #include "sm750_help.h" |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [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 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [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 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [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 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [diff] [blame] | 36 | void hw_de_init(struct lynx_accel *accel) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 37 | { |
| 38 | /* setup 2d engine registers */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 39 | u32 reg, clr; |
Juston Li | 919ca7c | 2015-07-14 21:14:43 -0700 | [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 | |
Matej Vasek | fbb8c96 | 2016-01-25 16:02:33 +0100 | [diff] [blame] | 56 | /* DE_STRETCH bpp format need be initialized 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 | |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 66 | clr = DE_CONTROL_TRANSPARENCY | DE_CONTROL_TRANSPARENCY_MATCH | |
| 67 | DE_CONTROL_TRANSPARENCY_SELECT; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 68 | |
| 69 | /* dpr0c */ |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 70 | write_dpr(accel, DE_CONTROL, read_dpr(accel, DE_CONTROL) & ~clr); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* set2dformat only be called from setmode functions |
| 74 | * but if you need dual framebuffer driver,need call set2dformat |
| 75 | * every time you use 2d function */ |
| 76 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [diff] [blame] | 77 | void hw_set2dformat(struct lynx_accel *accel, int fmt) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 78 | { |
| 79 | u32 reg; |
Juston Li | 919ca7c | 2015-07-14 21:14:43 -0700 | [diff] [blame] | 80 | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 81 | /* 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] | 82 | reg = read_dpr(accel, DE_STRETCH_FORMAT); |
| 83 | reg = FIELD_VALUE(reg, DE_STRETCH_FORMAT, PIXEL_FORMAT, fmt); |
| 84 | write_dpr(accel, DE_STRETCH_FORMAT, reg); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 85 | } |
| 86 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [diff] [blame] | 87 | int hw_fillrect(struct lynx_accel *accel, |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 88 | u32 base, u32 pitch, u32 Bpp, |
| 89 | u32 x, u32 y, u32 width, u32 height, |
| 90 | u32 color, u32 rop) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 91 | { |
| 92 | u32 deCtrl; |
| 93 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 94 | if (accel->de_wait() != 0) { |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 95 | /* int time wait and always busy,seems hardware |
| 96 | * got something error */ |
Hari Prasath Gujulan Elango | 7211f6f | 2015-06-24 16:51:21 +0000 | [diff] [blame] | 97 | pr_debug("De engine always busy\n"); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 98 | return -1; |
| 99 | } |
| 100 | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 101 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 102 | write_dpr(accel, DE_PITCH, |
| 103 | FIELD_VALUE(0, DE_PITCH, DESTINATION, pitch/Bpp)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 104 | FIELD_VALUE(0, DE_PITCH, SOURCE, pitch/Bpp)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 105 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 106 | write_dpr(accel, DE_WINDOW_WIDTH, |
| 107 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, pitch/Bpp)| |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 108 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, pitch/Bpp)); /* dpr44 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 109 | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 110 | write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ |
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_DESTINATION, |
Mike Rapoport | aeaab18 | 2016-02-15 19:53:58 +0200 | [diff] [blame] | 113 | ((x << DE_DESTINATION_X_SHIFT) & DE_DESTINATION_X_MASK) | |
| 114 | (y & DE_DESTINATION_Y_MASK)); /* dpr4 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 115 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 116 | write_dpr(accel, DE_DIMENSION, |
Mike Rapoport | 0fab34b | 2016-02-15 19:53:59 +0200 | [diff] [blame] | 117 | ((width << DE_DIMENSION_X_SHIFT) & DE_DIMENSION_X_MASK) | |
| 118 | (height & DE_DIMENSION_Y_ET_MASK)); /* dpr8 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 119 | |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 120 | deCtrl = DE_CONTROL_STATUS | DE_CONTROL_LAST_PIXEL | |
| 121 | DE_CONTROL_COMMAND_RECTANGLE_FILL | DE_CONTROL_ROP_SELECT | |
| 122 | (rop & DE_CONTROL_ROP_MASK); /* dpr0xc */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 123 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 124 | write_dpr(accel, DE_CONTROL, deCtrl); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int hw_copyarea( |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [diff] [blame] | 129 | struct lynx_accel *accel, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 130 | unsigned int sBase, /* Address of source: offset in frame buffer */ |
| 131 | unsigned int sPitch, /* Pitch value of source surface in BYTE */ |
| 132 | unsigned int sx, |
| 133 | unsigned int sy, /* Starting coordinate of source surface */ |
| 134 | unsigned int dBase, /* Address of destination: offset in frame buffer */ |
| 135 | unsigned int dPitch, /* Pitch value of destination surface in BYTE */ |
| 136 | unsigned int Bpp, /* Color depth of destination surface */ |
| 137 | unsigned int dx, |
| 138 | unsigned int dy, /* Starting coordinate of destination surface */ |
| 139 | unsigned int width, |
| 140 | unsigned int height, /* width and height of rectangle in pixel value */ |
| 141 | unsigned int rop2) /* ROP value */ |
| 142 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 143 | unsigned int nDirection, de_ctrl; |
| 144 | int opSign; |
Juston Li | 40403c1 | 2015-07-14 21:14:48 -0700 | [diff] [blame] | 145 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 146 | nDirection = LEFT_TO_RIGHT; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 147 | /* Direction of ROP2 operation: 1 = Left to Right, (-1) = Right to Left */ |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 148 | opSign = 1; |
| 149 | de_ctrl = 0; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 150 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 151 | /* If source and destination are the same surface, need to check for overlay cases */ |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 152 | if (sBase == dBase && sPitch == dPitch) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 153 | /* Determine direction of operation */ |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 154 | if (sy < dy) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 155 | /* +----------+ |
| 156 | |S | |
| 157 | | +----------+ |
| 158 | | | | | |
| 159 | | | | | |
| 160 | +---|------+ | |
| 161 | | D| |
| 162 | +----------+ */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 163 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 164 | nDirection = BOTTOM_TO_TOP; |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 165 | } else if (sy > dy) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 166 | /* +----------+ |
| 167 | |D | |
| 168 | | +----------+ |
| 169 | | | | | |
| 170 | | | | | |
| 171 | +---|------+ | |
| 172 | | S| |
| 173 | +----------+ */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 174 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 175 | nDirection = TOP_TO_BOTTOM; |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 176 | } else { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 177 | /* sy == dy */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 178 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 179 | if (sx <= dx) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 180 | /* +------+---+------+ |
| 181 | |S | | D| |
| 182 | | | | | |
| 183 | | | | | |
| 184 | | | | | |
| 185 | +------+---+------+ */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 186 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 187 | nDirection = RIGHT_TO_LEFT; |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 188 | } else { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 189 | /* sx > dx */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 190 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 191 | /* +------+---+------+ |
| 192 | |D | | S| |
| 193 | | | | | |
| 194 | | | | | |
| 195 | | | | | |
| 196 | +------+---+------+ */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 197 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 198 | nDirection = LEFT_TO_RIGHT; |
| 199 | } |
| 200 | } |
| 201 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 202 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 203 | if ((nDirection == BOTTOM_TO_TOP) || (nDirection == RIGHT_TO_LEFT)) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 204 | sx += width - 1; |
| 205 | sy += height - 1; |
| 206 | dx += width - 1; |
| 207 | dy += height - 1; |
| 208 | opSign = (-1); |
| 209 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 210 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 211 | /* Note: |
| 212 | DE_FOREGROUND are DE_BACKGROUND are don't care. |
| 213 | DE_COLOR_COMPARE and DE_COLOR_COMPARE_MAKS are set by set deSetTransparency(). |
| 214 | */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 215 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 216 | /* 2D Source Base. |
| 217 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 218 | */ |
| 219 | write_dpr(accel, DE_WINDOW_SOURCE_BASE, sBase); /* dpr40 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 220 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 221 | /* 2D Destination Base. |
| 222 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 223 | */ |
| 224 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); /* dpr44 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 225 | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 226 | /* Program pitch (distance between the 1st points of two adjacent lines). |
| 227 | 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] | 228 | pixel values. Need Byte to pixel conversion. |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 229 | */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 230 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 231 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 232 | FIELD_VALUE(0, DE_PITCH, DESTINATION, (dPitch/Bpp)) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 233 | FIELD_VALUE(0, DE_PITCH, SOURCE, (sPitch/Bpp))); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* Screen Window width in Pixels. |
| 237 | 2D engine uses this value to calculate the linear address in frame buffer for a given point. |
| 238 | */ |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 239 | write_dpr(accel, DE_WINDOW_WIDTH, |
| 240 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/Bpp)) | |
| 241 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (sPitch/Bpp))); /* dpr3c */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 242 | |
Juston Li | 7b05cbe | 2015-07-14 21:14:47 -0700 | [diff] [blame] | 243 | if (accel->de_wait() != 0) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 244 | return -1; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 245 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 246 | { |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 247 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 248 | write_dpr(accel, DE_SOURCE, |
Mike Rapoport | cf6d8f0 | 2016-02-15 19:53:57 +0200 | [diff] [blame] | 249 | ((sx << DE_SOURCE_X_K1_SHIFT) & DE_SOURCE_X_K1_MASK) | |
| 250 | (sy & DE_SOURCE_Y_K2_MASK)); /* dpr0 */ |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 251 | write_dpr(accel, DE_DESTINATION, |
Mike Rapoport | aeaab18 | 2016-02-15 19:53:58 +0200 | [diff] [blame] | 252 | ((dx << DE_DESTINATION_X_SHIFT) & DE_DESTINATION_X_MASK) | |
| 253 | (dy & DE_DESTINATION_Y_MASK)); /* dpr04 */ |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 254 | write_dpr(accel, DE_DIMENSION, |
Mike Rapoport | 0fab34b | 2016-02-15 19:53:59 +0200 | [diff] [blame] | 255 | ((width << DE_DIMENSION_X_SHIFT) & DE_DIMENSION_X_MASK) | |
| 256 | (height & DE_DIMENSION_Y_ET_MASK)); /* dpr08 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 257 | |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 258 | de_ctrl = (rop2 & DE_CONTROL_ROP_MASK) | DE_CONTROL_ROP_SELECT | |
| 259 | ((nDirection == RIGHT_TO_LEFT) ? DE_CONTROL_DIRECTION : 0) | |
| 260 | DE_CONTROL_COMMAND_BITBLT | DE_CONTROL_STATUS; |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 261 | write_dpr(accel, DE_CONTROL, de_ctrl); /* dpr0c */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 262 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | return 0; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 266 | } |
| 267 | |
Greg Donald | eb0f427 | 2015-06-18 15:06:56 -0500 | [diff] [blame] | 268 | static unsigned int deGetTransparency(struct lynx_accel *accel) |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 269 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 270 | unsigned int de_ctrl; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 271 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 272 | de_ctrl = read_dpr(accel, DE_CONTROL); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 273 | |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 274 | de_ctrl &= (DE_CONTROL_TRANSPARENCY_MATCH | |
| 275 | DE_CONTROL_TRANSPARENCY_SELECT | DE_CONTROL_TRANSPARENCY); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 276 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 277 | return de_ctrl; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 278 | } |
| 279 | |
Greg Kroah-Hartman | 7c6f3fd | 2015-03-10 22:03:01 +0100 | [diff] [blame] | 280 | int hw_imageblit(struct lynx_accel *accel, |
| 281 | const char *pSrcbuf, /* pointer to start of source buffer in system memory */ |
| 282 | u32 srcDelta, /* Pitch value (in bytes) of the source buffer, +ive means top down and -ive mean button up */ |
| 283 | u32 startBit, /* Mono data can start at any bit in a byte, this value should be 0 to 7 */ |
| 284 | u32 dBase, /* Address of destination: offset in frame buffer */ |
| 285 | u32 dPitch, /* Pitch value of destination surface in BYTE */ |
| 286 | u32 bytePerPixel, /* Color depth of destination surface */ |
| 287 | u32 dx, |
| 288 | u32 dy, /* Starting coordinate of destination surface */ |
| 289 | u32 width, |
Matej Vasek | fbb8c96 | 2016-01-25 16:02:33 +0100 | [diff] [blame] | 290 | u32 height, /* width and height of rectangle in pixel value */ |
Greg Kroah-Hartman | 7c6f3fd | 2015-03-10 22:03:01 +0100 | [diff] [blame] | 291 | u32 fColor, /* Foreground color (corresponding to a 1 in the monochrome data */ |
| 292 | u32 bColor, /* Background color (corresponding to a 0 in the monochrome data */ |
| 293 | u32 rop2) /* ROP value */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 294 | { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 295 | unsigned int ulBytesPerScan; |
| 296 | unsigned int ul4BytesPerScan; |
| 297 | unsigned int ulBytesRemain; |
| 298 | unsigned int de_ctrl = 0; |
| 299 | unsigned char ajRemain[4]; |
| 300 | int i, j; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 301 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 302 | startBit &= 7; /* Just make sure the start bit is within legal range */ |
| 303 | ulBytesPerScan = (width + startBit + 7) / 8; |
| 304 | ul4BytesPerScan = ulBytesPerScan & ~3; |
| 305 | ulBytesRemain = ulBytesPerScan & 3; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 306 | |
Juston Li | 7b05cbe | 2015-07-14 21:14:47 -0700 | [diff] [blame] | 307 | if (accel->de_wait() != 0) |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 308 | return -1; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 309 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 310 | /* 2D Source Base. |
| 311 | Use 0 for HOST Blt. |
| 312 | */ |
| 313 | write_dpr(accel, DE_WINDOW_SOURCE_BASE, 0); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 314 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 315 | /* 2D Destination Base. |
| 316 | It is an address offset (128 bit aligned) from the beginning of frame buffer. |
| 317 | */ |
| 318 | write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 319 | /* Program pitch (distance between the 1st points of two adjacent lines). |
| 320 | 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] | 321 | pixel values. Need Byte to pixel conversion. |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 322 | */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 323 | { |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 324 | write_dpr(accel, DE_PITCH, |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 325 | FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch/bytePerPixel) | |
Juston Li | 5ee35ea | 2015-06-12 03:17:22 -0700 | [diff] [blame] | 326 | FIELD_VALUE(0, DE_PITCH, SOURCE, dPitch/bytePerPixel)); /* dpr10 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 327 | } |
| 328 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 329 | /* Screen Window width in Pixels. |
| 330 | 2D engine uses this value to calculate the linear address in frame buffer for a given point. |
| 331 | */ |
| 332 | write_dpr(accel, DE_WINDOW_WIDTH, |
| 333 | FIELD_VALUE(0, DE_WINDOW_WIDTH, DESTINATION, (dPitch/bytePerPixel)) | |
| 334 | FIELD_VALUE(0, DE_WINDOW_WIDTH, SOURCE, (dPitch/bytePerPixel))); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 335 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 336 | /* Note: For 2D Source in Host Write, only X_K1_MONO field is needed, and Y_K2 field is not used. |
| 337 | For mono bitmap, use startBit for X_K1. */ |
| 338 | write_dpr(accel, DE_SOURCE, |
Mike Rapoport | cf6d8f0 | 2016-02-15 19:53:57 +0200 | [diff] [blame] | 339 | (startBit << DE_SOURCE_X_K1_SHIFT) & |
| 340 | DE_SOURCE_X_K1_MONO_MASK); /* dpr00 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 341 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 342 | write_dpr(accel, DE_DESTINATION, |
Mike Rapoport | aeaab18 | 2016-02-15 19:53:58 +0200 | [diff] [blame] | 343 | ((dx << DE_DESTINATION_X_SHIFT) & DE_DESTINATION_X_MASK) | |
| 344 | (dy & DE_DESTINATION_Y_MASK)); /* dpr04 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 345 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 346 | write_dpr(accel, DE_DIMENSION, |
Mike Rapoport | 0fab34b | 2016-02-15 19:53:59 +0200 | [diff] [blame] | 347 | ((width << DE_DIMENSION_X_SHIFT) & DE_DIMENSION_X_MASK) | |
| 348 | (height & DE_DIMENSION_Y_ET_MASK)); /* dpr08 */ |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 349 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 350 | write_dpr(accel, DE_FOREGROUND, fColor); |
| 351 | write_dpr(accel, DE_BACKGROUND, bColor); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 352 | |
Mike Rapoport | e2e2258 | 2016-02-15 19:54:00 +0200 | [diff] [blame^] | 353 | de_ctrl = (rop2 & DE_CONTROL_ROP_MASK) | |
| 354 | DE_CONTROL_ROP_SELECT | DE_CONTROL_COMMAND_HOST_WRITE | |
| 355 | DE_CONTROL_HOST | DE_CONTROL_STATUS; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 356 | |
Isaac Assegai | b5d6397 | 2015-06-02 03:14:27 -0700 | [diff] [blame] | 357 | write_dpr(accel, DE_CONTROL, de_ctrl | deGetTransparency(accel)); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 358 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 359 | /* Write MONO data (line by line) to 2D Engine data port */ |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 360 | for (i = 0; i < height; i++) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 361 | /* For each line, send the data in chunks of 4 bytes */ |
Juston Li | 7b05cbe | 2015-07-14 21:14:47 -0700 | [diff] [blame] | 362 | for (j = 0; j < (ul4BytesPerScan/4); j++) |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 363 | write_dpPort(accel, *(unsigned int *)(pSrcbuf + (j * 4))); |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 364 | |
Juston Li | 259fef3 | 2015-07-14 21:14:45 -0700 | [diff] [blame] | 365 | if (ulBytesRemain) { |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 366 | memcpy(ajRemain, pSrcbuf+ul4BytesPerScan, ulBytesRemain); |
| 367 | write_dpPort(accel, *(unsigned int *)ajRemain); |
| 368 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 369 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 370 | pSrcbuf += srcDelta; |
| 371 | } |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 372 | |
Juston Li | 7837653 | 2015-07-14 21:14:30 -0700 | [diff] [blame] | 373 | return 0; |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 374 | } |
| 375 | |