]> git.sur5r.net Git - u-boot/blobdiff - drivers/video/vidconsole-uclass.c
rockchip: video: vop: Reserve enough space for mipi dispaly
[u-boot] / drivers / video / vidconsole-uclass.c
index ea10189432fcae3145bb8974d763f9bd22f318a4..e9a90b1b9bc375137cb93d4bdb1efa1ad6f66e4f 100644 (file)
@@ -47,19 +47,38 @@ int vidconsole_set_row(struct udevice *dev, uint row, int clr)
        return ops->set_row(dev, row, clr);
 }
 
+static int vidconsole_entry_start(struct udevice *dev)
+{
+       struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+       if (!ops->entry_start)
+               return -ENOSYS;
+       return ops->entry_start(dev);
+}
+
 /* Move backwards one space */
-static void vidconsole_back(struct udevice *dev)
+static int vidconsole_back(struct udevice *dev)
 {
        struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+       struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+       int ret;
+
+       if (ops->backspace) {
+               ret = ops->backspace(dev);
+               if (ret != -ENOSYS)
+                       return ret;
+       }
 
-       if (--priv->curr_col < 0) {
-               priv->curr_col = priv->cols - 1;
-               if (--priv->curr_row < 0)
-                       priv->curr_row = 0;
+       priv->xcur_frac -= VID_TO_POS(priv->x_charsize);
+       if (priv->xcur_frac < priv->xstart_frac) {
+               priv->xcur_frac = (priv->cols - 1) *
+                       VID_TO_POS(priv->x_charsize);
+               priv->ycur -= priv->y_charsize;
+               if (priv->ycur < 0)
+                       priv->ycur = 0;
        }
 
-       vidconsole_putc_xy(dev, priv->curr_col * VIDEO_FONT_WIDTH,
-                          priv->curr_row * VIDEO_FONT_HEIGHT, ' ');
+       return 0;
 }
 
 /* Move to a newline, scrolling the display if necessary */
@@ -71,16 +90,19 @@ static void vidconsole_newline(struct udevice *dev)
        const int rows = CONFIG_CONSOLE_SCROLL_LINES;
        int i;
 
-       priv->curr_col = 0;
+       priv->xcur_frac = priv->xstart_frac;
+       priv->ycur += priv->y_charsize;
 
        /* Check if we need to scroll the terminal */
-       if (++priv->curr_row >= priv->rows) {
+       if ((priv->ycur + priv->y_charsize) / priv->y_charsize > priv->rows) {
                vidconsole_move_rows(dev, 0, rows, priv->rows - rows);
                for (i = 0; i < rows; i++)
                        vidconsole_set_row(dev, priv->rows - i - 1,
                                           vid_priv->colour_bg);
-               priv->curr_row -= rows;
+               priv->ycur -= rows * priv->y_charsize;
        }
+       priv->last_ch = 0;
+
        video_sync(dev->parent);
 }
 
@@ -90,21 +112,26 @@ int vidconsole_put_char(struct udevice *dev, char ch)
        int ret;
 
        switch (ch) {
+       case '\a':
+               /* beep */
+               break;
        case '\r':
-               priv->curr_col = 0;
+               priv->xcur_frac = priv->xstart_frac;
                break;
        case '\n':
                vidconsole_newline(dev);
+               vidconsole_entry_start(dev);
                break;
        case '\t':      /* Tab (8 chars alignment) */
-               priv->curr_col +=  8;
-               priv->curr_col &= ~7;
+               priv->xcur_frac = ((priv->xcur_frac / priv->tab_width_frac)
+                               + 1) * priv->tab_width_frac;
 
-               if (priv->curr_col >= priv->cols)
+               if (priv->xcur_frac >= priv->xsize_frac)
                        vidconsole_newline(dev);
                break;
        case '\b':
                vidconsole_back(dev);
+               priv->last_ch = 0;
                break;
        default:
                /*
@@ -112,13 +139,17 @@ int vidconsole_put_char(struct udevice *dev, char ch)
                 * colour depth. Check this and return an error to help with
                 * diagnosis.
                 */
-               ret = vidconsole_putc_xy(dev,
-                                        priv->curr_col * VIDEO_FONT_WIDTH,
-                                        priv->curr_row * VIDEO_FONT_HEIGHT,
-                                        ch);
-               if (ret)
+               ret = vidconsole_putc_xy(dev, priv->xcur_frac, priv->ycur, ch);
+               if (ret == -EAGAIN) {
+                       vidconsole_newline(dev);
+                       ret = vidconsole_putc_xy(dev, priv->xcur_frac,
+                                                priv->ycur, ch);
+               }
+               if (ret < 0)
                        return ret;
-               if (++priv->curr_col >= priv->cols)
+               priv->xcur_frac += ret;
+               priv->last_ch = ch;
+               if (priv->xcur_frac >= priv->xsize_frac)
                        vidconsole_newline(dev);
                break;
        }
@@ -139,6 +170,7 @@ static void vidconsole_puts(struct stdio_dev *sdev, const char *s)
 
        while (*s)
                vidconsole_put_char(dev, *s++);
+       video_sync(dev->parent);
 }
 
 /* Set up the number of rows and colours (rotated drivers override this) */
@@ -148,8 +180,7 @@ static int vidconsole_pre_probe(struct udevice *dev)
        struct udevice *vid = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid);
 
-       priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
-       priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
+       priv->xsize_frac = VID_TO_POS(vid_priv->xsize);
 
        return 0;
 }
@@ -159,18 +190,23 @@ static int vidconsole_post_probe(struct udevice *dev)
 {
        struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
        struct stdio_dev *sdev = &priv->sdev;
-       int ret;
 
-       strlcpy(sdev->name, dev->name, sizeof(sdev->name));
+       if (!priv->tab_width_frac)
+               priv->tab_width_frac = VID_TO_POS(priv->x_charsize) * 8;
+
+       if (dev->seq) {
+               snprintf(sdev->name, sizeof(sdev->name), "vidconsole%d",
+                        dev->seq);
+       } else {
+               strcpy(sdev->name, "vidconsole");
+       }
+
        sdev->flags = DEV_FLAGS_OUTPUT;
        sdev->putc = vidconsole_putc;
        sdev->puts = vidconsole_puts;
        sdev->priv = dev;
-       ret = stdio_register(sdev);
-       if (ret)
-               return ret;
 
-       return 0;
+       return stdio_register(sdev);
 }
 
 UCLASS_DRIVER(vidconsole) = {
@@ -184,9 +220,11 @@ UCLASS_DRIVER(vidconsole) = {
 void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
 {
        struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+       struct udevice *vid_dev = dev->parent;
+       struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
 
-       priv->curr_col = min_t(short, col, priv->cols - 1);
-       priv->curr_row = min_t(short, row, priv->rows - 1);
+       priv->xcur_frac = VID_TO_POS(min_t(short, col, vid_priv->xsize - 1));
+       priv->ycur = min_t(short, row, vid_priv->ysize - 1);
 }
 
 static int do_video_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -198,8 +236,7 @@ static int do_video_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
        if (argc != 3)
                return CMD_RET_USAGE;
 
-       uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
-       if (!dev)
+       if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
                return CMD_RET_FAILURE;
        col = simple_strtoul(argv[1], NULL, 10);
        row = simple_strtoul(argv[2], NULL, 10);
@@ -217,8 +254,7 @@ static int do_video_puts(cmd_tbl_t *cmdtp, int flag, int argc,
        if (argc != 2)
                return CMD_RET_USAGE;
 
-       uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
-       if (!dev)
+       if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
                return CMD_RET_FAILURE;
        for (s = argv[1]; *s; s++)
                vidconsole_put_char(dev, *s);