global: Migrate CONFIG_STACKBASE to CFG
[platform/kernel/u-boot.git] / drivers / video / console_rotate.c
index b485255..36c8d06 100644 (file)
@@ -15,11 +15,13 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
        int pbytes = VNBYTES(vid_priv->bpix);
-       void *line;
+       void *start, *line;
        int i, j;
+       int ret;
 
-       line = vid_priv->fb + vid_priv->line_length -
+       start = vid_priv->fb + vid_priv->line_length -
                (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
+       line = start;
        for (j = 0; j < vid_priv->ysize; j++) {
                switch (vid_priv->bpix) {
                case VIDEO_BPP8:
@@ -51,6 +53,9 @@ static int console_set_row_1(struct udevice *dev, uint row, int clr)
                }
                line += vid_priv->line_length;
        }
+       ret = vidconsole_sync_copy(dev, start, line);
+       if (ret)
+               return ret;
 
        return 0;
 }
@@ -59,10 +64,10 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
                               uint count)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+       int pbytes = VNBYTES(vid_priv->bpix);
        void *dst;
        void *src;
-       int pbytes = VNBYTES(vid_priv->bpix);
-       int j;
+       int j, ret;
 
        dst = vid_priv->fb + vid_priv->line_length -
                (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
@@ -70,7 +75,10 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
                (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
 
        for (j = 0; j < vid_priv->ysize; j++) {
-               memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
+               ret = vidconsole_memmove(dev, dst, src,
+                                        VIDEO_FONT_HEIGHT * pbytes * count);
+               if (ret)
+                       return ret;
                src += vid_priv->line_length;
                dst += vid_priv->line_length;
        }
@@ -83,14 +91,16 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
        struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
        struct udevice *vid = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
        int pbytes = VNBYTES(vid_priv->bpix);
-       int i, col;
+       int i, col, x, linenum, ret;
        int mask = 0x80;
-       void *line;
-       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+       void *start, *line;
 
-       line = vid_priv->fb + (VID_TO_PIXEL(x_frac) + 1) *
-                       vid_priv->line_length - (y + 1) * pbytes;
+       linenum = VID_TO_PIXEL(x_frac) + 1;
+       x = y + 1;
+       start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
+       line = start;
        if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
                return -EAGAIN;
 
@@ -135,6 +145,10 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
                line += vid_priv->line_length;
                mask >>= 1;
        }
+       /* We draw backwards from 'start, so account for the first line */
+       ret = vidconsole_sync_copy(dev, start - vid_priv->line_length, line);
+       if (ret)
+               return ret;
 
        return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
@@ -143,12 +157,13 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 static int console_set_row_2(struct udevice *dev, uint row, int clr)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-       void *line;
+       void *start, *line, *end;
        int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
-       int i;
+       int i, ret;
 
-       line = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
+       start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
                (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+       line = start;
        switch (vid_priv->bpix) {
        case VIDEO_BPP8:
                if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
@@ -156,6 +171,7 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 
                        for (i = 0; i < pixels; i++)
                                *dst++ = clr;
+                       end = dst;
                        break;
                }
        case VIDEO_BPP16:
@@ -164,6 +180,7 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 
                        for (i = 0; i < pixels; i++)
                                *dst++ = clr;
+                       end = dst;
                        break;
                }
        case VIDEO_BPP32:
@@ -172,11 +189,15 @@ static int console_set_row_2(struct udevice *dev, uint row, int clr)
 
                        for (i = 0; i < pixels; i++)
                                *dst++ = clr;
+                       end = dst;
                        break;
                }
        default:
                return -ENOSYS;
        }
+       ret = vidconsole_sync_copy(dev, start, end);
+       if (ret)
+               return ret;
 
        return 0;
 }
@@ -194,7 +215,8 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
                vid_priv->line_length;
        src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
                vid_priv->line_length;
-       memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
+       vidconsole_memmove(dev, dst, src,
+                          VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
 
        return 0;
 }
@@ -204,16 +226,16 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
        struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
        struct udevice *vid = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid);
-       int i, row;
-       void *line;
+       int pbytes = VNBYTES(vid_priv->bpix);
+       int i, row, x, linenum, ret;
+       void *start, *line;
 
        if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
                return -EAGAIN;
-
-       line = vid_priv->fb + (vid_priv->ysize - y - 1) *
-                       vid_priv->line_length +
-                       (vid_priv->xsize - VID_TO_PIXEL(x_frac) -
-                       VIDEO_FONT_WIDTH - 1) * VNBYTES(vid_priv->bpix);
+       linenum = vid_priv->ysize - y - 1;
+       x = vid_priv->xsize - VID_TO_PIXEL(x_frac) - 1;
+       start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
+       line = start;
 
        for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
                unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
@@ -261,6 +283,10 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
                }
                line -= vid_priv->line_length;
        }
+       /* Add 4 bytes to allow for the first pixel writen */
+       ret = vidconsole_sync_copy(dev, start + 4, line);
+       if (ret)
+               return ret;
 
        return VID_TO_POS(VIDEO_FONT_WIDTH);
 }
@@ -269,10 +295,11 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
        int pbytes = VNBYTES(vid_priv->bpix);
-       void *line;
-       int i, j;
+       void *start, *line;
+       int i, j, ret;
 
-       line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
+       start = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
+       line = start;
        for (j = 0; j < vid_priv->ysize; j++) {
                switch (vid_priv->bpix) {
                case VIDEO_BPP8:
@@ -304,6 +331,9 @@ static int console_set_row_3(struct udevice *dev, uint row, int clr)
                }
                line += vid_priv->line_length;
        }
+       ret = vidconsole_sync_copy(dev, start, line);
+       if (ret)
+               return ret;
 
        return 0;
 }
@@ -312,16 +342,19 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
                               uint count)
 {
        struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+       int pbytes = VNBYTES(vid_priv->bpix);
        void *dst;
        void *src;
-       int pbytes = VNBYTES(vid_priv->bpix);
-       int j;
+       int j, ret;
 
        dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
        src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
 
        for (j = 0; j < vid_priv->ysize; j++) {
-               memmove(dst, src, VIDEO_FONT_HEIGHT * pbytes * count);
+               ret = vidconsole_memmove(dev, dst, src,
+                                        VIDEO_FONT_HEIGHT * pbytes * count);
+               if (ret)
+                       return ret;
                src += vid_priv->line_length;
                dst += vid_priv->line_length;
        }
@@ -334,17 +367,17 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
        struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
        struct udevice *vid = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
        int pbytes = VNBYTES(vid_priv->bpix);
-       int i, col;
+       int i, col, x, ret;
        int mask = 0x80;
-       void *line = vid_priv->fb +
-               (vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1) *
-               vid_priv->line_length + y * pbytes;
-       uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+       void *start, *line;
 
        if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
                return -EAGAIN;
-
+       x = vid_priv->ysize - VID_TO_PIXEL(x_frac) - 1;
+       start = vid_priv->fb + x * vid_priv->line_length + y * pbytes;
+       line = start;
        for (col = 0; col < VIDEO_FONT_HEIGHT; col++) {
                switch (vid_priv->bpix) {
                case VIDEO_BPP8:
@@ -386,6 +419,10 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
                line -= vid_priv->line_length;
                mask >>= 1;
        }
+       /* Add a line to allow for the first pixels writen */
+       ret = vidconsole_sync_copy(dev, start + vid_priv->line_length, line);
+       if (ret)
+               return ret;
 
        return VID_TO_POS(VIDEO_FONT_WIDTH);
 }