13 #include <linux/module.h>
14 #include <linux/slab.h>
16 #include <linux/prefetch.h>
21 #define MAX_CMD_PIXELS 255
23 #define RLX_HEADER_BYTES 7
24 #define MIN_RLX_PIX_BYTES 4
25 #define MIN_RLX_CMD_BYTES (RLX_HEADER_BYTES + MIN_RLX_PIX_BYTES)
27 #define RLE_HEADER_BYTES 6
28 #define MIN_RLE_PIX_BYTES 3
29 #define MIN_RLE_CMD_BYTES (RLE_HEADER_BYTES + MIN_RLE_PIX_BYTES)
31 #define RAW_HEADER_BYTES 6
32 #define MIN_RAW_PIX_BYTES 2
33 #define MIN_RAW_CMD_BYTES (RAW_HEADER_BYTES + MIN_RAW_PIX_BYTES)
43 static int udl_trim_hline(
const u8 *bback,
const u8 **bfront,
int *width_bytes)
46 const unsigned long *back = (
const unsigned long *) bback;
47 const unsigned long *front = (
const unsigned long *) *bfront;
48 const int width = *width_bytes /
sizeof(
unsigned long);
49 int identical =
width;
56 for (j = 0; j <
width; j++) {
57 if (back[j] != front[j]) {
63 for (k = width - 1; k >
j; k--) {
64 if (back[k] != front[k]) {
70 identical = start + (width -
end);
71 *bfront = (
u8 *) &front[start];
72 *width_bytes = (end -
start) *
sizeof(
unsigned long);
74 return identical *
sizeof(
unsigned long);
78 static inline u16 pixel32_to_be16p(
const uint8_t *pixel)
83 retval = (((pix >> 3) & 0x001f) |
84 ((pix >> 5) & 0x07e0) |
85 ((pix >> 8) & 0xf800));
116 static void udl_compress_hline16(
117 const u8 **pixel_start_ptr,
118 const u8 *
const pixel_end,
123 const u8 *pixel = *pixel_start_ptr;
127 while ((pixel_end > pixel) &&
131 const u8 *raw_pixel_start =
NULL;
132 const u8 *cmd_pixel_start, *cmd_pixel_end =
NULL;
138 *cmd++ = (
uint8_t) ((dev_addr >> 16) & 0xFF);
139 *cmd++ = (
uint8_t) ((dev_addr >> 8) & 0xFF);
140 *cmd++ = (
uint8_t) ((dev_addr) & 0xFF);
142 cmd_pixels_count_byte = cmd++;
143 cmd_pixel_start = pixel;
145 raw_pixels_count_byte = cmd++;
146 raw_pixel_start = pixel;
149 min((
int)(pixel_end - pixel) / bpp,
150 (
int)(cmd_buffer_end - cmd) / 2))) * bpp;
152 prefetch_range((
void *) pixel, (cmd_pixel_end - pixel) * bpp);
154 while (pixel < cmd_pixel_end) {
155 const u8 *
const repeating_pixel = pixel;
165 if (
unlikely((pixel < cmd_pixel_end) &&
166 (!
memcmp(pixel, repeating_pixel, bpp)))) {
168 *raw_pixels_count_byte = (((repeating_pixel -
169 raw_pixel_start) / bpp) + 1) & 0xFF;
171 while ((pixel < cmd_pixel_end)
172 && (!
memcmp(pixel, repeating_pixel, bpp))) {
177 *cmd++ = (((pixel - repeating_pixel) / bpp) - 1) & 0xFF;
180 raw_pixel_start = pixel;
181 raw_pixels_count_byte = cmd++;
185 if (pixel > raw_pixel_start) {
187 *raw_pixels_count_byte = ((pixel-raw_pixel_start) / bpp) & 0xFF;
190 *cmd_pixels_count_byte = ((pixel - cmd_pixel_start) / bpp) & 0xFF;
191 dev_addr += ((pixel - cmd_pixel_start) / bpp) * 2;
196 if (cmd_buffer_end > cmd)
197 memset(cmd, 0xAF, cmd_buffer_end - cmd);
198 cmd = (
uint8_t *) cmd_buffer_end;
201 *command_buffer_ptr =
cmd;
202 *pixel_start_ptr = pixel;
203 *device_address_ptr = dev_addr;
215 const char *front,
char **urb_buf_ptr,
218 int *ident_ptr,
int *sent_ptr)
220 const u8 *line_start, *line_end, *next_pixel;
221 u32 base16 = 0 + (device_byte_offset /
bpp) * 2;
222 struct urb *
urb = *urb_ptr;
223 u8 *cmd = *urb_buf_ptr;
224 u8 *cmd_end = (
u8 *) urb->transfer_buffer + urb->transfer_buffer_length;
227 next_pixel = line_start;
228 line_end = next_pixel + byte_width;
230 while (next_pixel < line_end) {
232 udl_compress_hline16(&next_pixel,
234 (
u8 **) &cmd, (
u8 *) cmd_end, bpp);
236 if (cmd >= cmd_end) {
237 int len = cmd - (
u8 *) urb->transfer_buffer;
245 cmd = urb->transfer_buffer;
246 cmd_end = &cmd[urb->transfer_buffer_length];