From patchwork Mon Feb 13 16:56:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 1741770 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=erxlaFtL; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PFrC151g0z23hX for ; Tue, 14 Feb 2023 03:58:36 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B4E09857CA; Mon, 13 Feb 2023 17:58:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="erxlaFtL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 06181857B1; Mon, 13 Feb 2023 17:57:16 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F08A08568E for ; Mon, 13 Feb 2023 17:57:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dsankouski@gmail.com Received: by mail-ed1-x52f.google.com with SMTP id eq11so13809316edb.6 for ; Mon, 13 Feb 2023 08:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C4tszw4bul5U5iFc/z7kZqcAucIZfzawL6nzxP8oJBU=; b=erxlaFtLf58T1WbT9iZuULxc9tkCLs/Mu2nnHsnLPa/+eAzRkdY+n+YoanG/EJOgAF OSe8XRSLSvNqDqfgEjxoRMTh5duHNEvYi5KZxoLlN4Uz3KsG9QiVC+sdjpYHihB2FuAM ybROLS+/W4dIwVI8p2yoVLh9V708QEkYQo/M9PUqu/Z+KqmpVM93K9t5Y9FeCvTGqAJm 36+/aZUCe+Mfue/FjhXEy80B6m5rvrcW5T94fP13ITJOTRHVgOx+Dhf05QRt9ULNt+iE 9/8m5fka+kLQ5VhfbbA2PbHuMZq5RyHkj2ek/5eG0maZIupwkjlI36BFERy/Nnb7Bgp/ XNfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C4tszw4bul5U5iFc/z7kZqcAucIZfzawL6nzxP8oJBU=; b=y+/qkeRRUNQS0VxuYtbhW+mOGRlyhFbuZTCEnB9iocjnediVKNnV2yu25YY7QgYwMU PehM2D6MrUlK9+1O96G3GARTabpaGYM3rfPgDfV50Parx8rjzMAgui0czizNVGipnRVS 3Go72II5D0TLVbyhz+vAaWMfGr5oamMy4L8rV+C+Yrlx2qlOlno0oRUsZ9he6mPOmVd3 K6Y5f06M0yXSimuAnfzJSipupIXSwrG7hQoDisHN7p5VxQcjhhvOZFvIe/+ijOsNtuLn Z5reKJX7J5i1FbHxmi5gVx/CCfQdriU8Ko6SUJYgXLEywKJAZqSER3MzZG5cFTZDlQ+F vHTA== X-Gm-Message-State: AO0yUKVwqal4UPa2BWmu6Rqcyio25pawKPMbYvNdQJzwspig51QIzy9o Uvkwo3usK6CnvEVyeovY1NL9r6fBQAY= X-Google-Smtp-Source: AK7set+WNcdiIbJ1vTFltp7LhZ7gP99cXdFU+CRw1PNBbjERgpIKGhtlHu/1j7NBKvP4u0LoMZz3Qw== X-Received: by 2002:a05:6402:5213:b0:4aa:cf80:44af with SMTP id s19-20020a056402521300b004aacf8044afmr8133708edd.7.1676307425306; Mon, 13 Feb 2023 08:57:05 -0800 (PST) Received: from debian.localdomain ([37.45.245.36]) by smtp.googlemail.com with ESMTPSA id v1-20020a50c401000000b004a249a97d84sm6897592edf.23.2023.02.13.08.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:57:05 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Anatolij Gustschin Subject: [PATCH v2 1/8] video console: unite normal and rotated files Date: Mon, 13 Feb 2023 19:56:53 +0300 Message-Id: <20230213165700.982691-2-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230213165700.982691-1-dsankouski@gmail.com> References: <20230213165700.982691-1-dsankouski@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Unite console_normal.c and console_rotate.c files. Those files have similar logic, and common logic may be extracted after putting code in single file. Signed-off-by: Dzmitry Sankouski --- Changes for v2: - none drivers/video/Kconfig | 8 +- drivers/video/Makefile | 3 +- drivers/video/console_normal.c | 178 ------------------ .../{console_rotate.c => console_simple.c} | 166 ++++++++++++++++ 4 files changed, 171 insertions(+), 184 deletions(-) delete mode 100644 drivers/video/console_normal.c rename drivers/video/{console_rotate.c => console_simple.c} (75%) diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index f539977d9b..1dfe11d182 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -124,17 +124,17 @@ config VIDEO_MIPI_DSI The MIPI Display Serial Interface (MIPI DSI) defines a high-speed serial interface between a host processor and a display module. -config CONSOLE_NORMAL +config VIDEO_CONSOLE bool "Support a simple text console" default y help Support drawing text on the frame buffer console so that it can be - used as a console. Rotation is not supported by this driver (see - CONFIG_CONSOLE_ROTATION for that). A built-in 8x16 font is used - for the display. + used as a console. See CONFIG_CONSOLE_ROTATION for rotation support. + A built-in 8x16 font is used for the display. config CONSOLE_ROTATION bool "Support rotated displays" + depends on VIDEO_CONSOLE help Sometimes, for example if the display is mounted in portrait mode or even if it's mounted landscape but rotated by 180degree, diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 40a871d638..75decf707d 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -7,8 +7,7 @@ ifdef CONFIG_DM obj-$(CONFIG_BACKLIGHT) += backlight-uclass.o obj-$(CONFIG_BACKLIGHT_GPIO) += backlight_gpio.o obj-$(CONFIG_BACKLIGHT_PWM) += pwm_backlight.o -obj-$(CONFIG_CONSOLE_NORMAL) += console_normal.o -obj-$(CONFIG_CONSOLE_ROTATION) += console_rotate.o +obj-$(CONFIG_VIDEO_CONSOLE) += console_simple.o obj-$(CONFIG_CONSOLE_TRUETYPE) += console_truetype.o fonts/ obj-$(CONFIG_DISPLAY) += display-uclass.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi-host-uclass.o diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c deleted file mode 100644 index 04f022491e..0000000000 --- a/drivers/video/console_normal.c +++ /dev/null @@ -1,178 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 2015 Google, Inc - * (C) Copyright 2001-2015 - * DENX Software Engineering -- wd@denx.de - * Compulab Ltd - http://compulab.co.il/ - * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com - */ - -#include -#include -#include -#include -#include /* Get font data, width and height */ - -static int console_normal_set_row(struct udevice *dev, uint row, int clr) -{ - struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - void *line, *end; - int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize; - int ret; - int i; - - line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length; - switch (vid_priv->bpix) { - case VIDEO_BPP8: - if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { - uint8_t *dst = line; - - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; - break; - } - case VIDEO_BPP16: - if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { - uint16_t *dst = line; - - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; - break; - } - case VIDEO_BPP32: - if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { - uint32_t *dst = line; - - for (i = 0; i < pixels; i++) - *dst++ = clr; - end = dst; - break; - } - default: - return -ENOSYS; - } - ret = vidconsole_sync_copy(dev, line, end); - if (ret) - return ret; - - return 0; -} - -static int console_normal_move_rows(struct udevice *dev, uint rowdst, - uint rowsrc, uint count) -{ - struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - void *dst; - void *src; - int size; - int ret; - - dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length; - src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length; - size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count; - ret = vidconsole_memmove(dev, dst, src, size); - if (ret) - return ret; - - return 0; -} - -static int console_normal_putc_xy(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 *start; - void *line; - int ret; - - start = vid_priv->fb + y * vid_priv->line_length + - VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix); - line = start; - - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) - return -EAGAIN; - - for (row = 0; row < VIDEO_FONT_HEIGHT; row++) { - unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row; - uchar bits = video_fontdata[idx]; - - switch (vid_priv->bpix) { - case VIDEO_BPP8: - if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { - uint8_t *dst = line; - - for (i = 0; i < VIDEO_FONT_WIDTH; i++) { - *dst++ = (bits & 0x80) ? - vid_priv->colour_fg : - vid_priv->colour_bg; - bits <<= 1; - } - break; - } - case VIDEO_BPP16: - if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { - uint16_t *dst = line; - - for (i = 0; i < VIDEO_FONT_WIDTH; i++) { - *dst++ = (bits & 0x80) ? - vid_priv->colour_fg : - vid_priv->colour_bg; - bits <<= 1; - } - break; - } - case VIDEO_BPP32: - if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { - uint32_t *dst = line; - - for (i = 0; i < VIDEO_FONT_WIDTH; i++) { - *dst++ = (bits & 0x80) ? - vid_priv->colour_fg : - vid_priv->colour_bg; - bits <<= 1; - } - break; - } - default: - return -ENOSYS; - } - line += vid_priv->line_length; - } - ret = vidconsole_sync_copy(dev, start, line); - if (ret) - return ret; - - return VID_TO_POS(VIDEO_FONT_WIDTH); -} - -static int console_normal_probe(struct udevice *dev) -{ - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); - struct udevice *vid_dev = dev->parent; - struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); - - vc_priv->x_charsize = VIDEO_FONT_WIDTH; - vc_priv->y_charsize = VIDEO_FONT_HEIGHT; - vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH; - vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT; - - return 0; -} - -struct vidconsole_ops console_normal_ops = { - .putc_xy = console_normal_putc_xy, - .move_rows = console_normal_move_rows, - .set_row = console_normal_set_row, -}; - -U_BOOT_DRIVER(vidconsole_normal) = { - .name = "vidconsole0", - .id = UCLASS_VIDEO_CONSOLE, - .ops = &console_normal_ops, - .probe = console_normal_probe, -}; diff --git a/drivers/video/console_rotate.c b/drivers/video/console_simple.c similarity index 75% rename from drivers/video/console_rotate.c rename to drivers/video/console_simple.c index 36c8d0609d..a4b3cfe3d8 100644 --- a/drivers/video/console_rotate.c +++ b/drivers/video/console_simple.c @@ -11,6 +11,171 @@ #include #include /* Get font data, width and height */ +static int console_normal_set_row(struct udevice *dev, uint row, int clr) +{ + struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); + void *line, *end; + int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize; + int ret; + int i; + + line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length; + switch (vid_priv->bpix) { + case VIDEO_BPP8: + if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { + uint8_t *dst = line; + + for (i = 0; i < pixels; i++) + *dst++ = clr; + end = dst; + break; + } + case VIDEO_BPP16: + if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { + uint16_t *dst = line; + + for (i = 0; i < pixels; i++) + *dst++ = clr; + end = dst; + break; + } + case VIDEO_BPP32: + if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { + uint32_t *dst = line; + + for (i = 0; i < pixels; i++) + *dst++ = clr; + end = dst; + break; + } + default: + return -ENOSYS; + } + ret = vidconsole_sync_copy(dev, line, end); + if (ret) + return ret; + + return 0; +} + +static int console_normal_move_rows(struct udevice *dev, uint rowdst, + uint rowsrc, uint count) +{ + struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); + void *dst; + void *src; + int size; + int ret; + + dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length; + src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length; + size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count; + ret = vidconsole_memmove(dev, dst, src, size); + if (ret) + return ret; + + return 0; +} + +static int console_normal_putc_xy(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 *start; + void *line; + int ret; + + start = vid_priv->fb + y * vid_priv->line_length + + VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix); + line = start; + + if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + return -EAGAIN; + + for (row = 0; row < VIDEO_FONT_HEIGHT; row++) { + unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row; + uchar bits = video_fontdata[idx]; + + switch (vid_priv->bpix) { + case VIDEO_BPP8: + if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { + uint8_t *dst = line; + + for (i = 0; i < VIDEO_FONT_WIDTH; i++) { + *dst++ = (bits & 0x80) ? + vid_priv->colour_fg : + vid_priv->colour_bg; + bits <<= 1; + } + break; + } + case VIDEO_BPP16: + if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { + uint16_t *dst = line; + + for (i = 0; i < VIDEO_FONT_WIDTH; i++) { + *dst++ = (bits & 0x80) ? + vid_priv->colour_fg : + vid_priv->colour_bg; + bits <<= 1; + } + break; + } + case VIDEO_BPP32: + if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { + uint32_t *dst = line; + + for (i = 0; i < VIDEO_FONT_WIDTH; i++) { + *dst++ = (bits & 0x80) ? + vid_priv->colour_fg : + vid_priv->colour_bg; + bits <<= 1; + } + break; + } + default: + return -ENOSYS; + } + line += vid_priv->line_length; + } + ret = vidconsole_sync_copy(dev, start, line); + if (ret) + return ret; + + return VID_TO_POS(VIDEO_FONT_WIDTH); +} + +static int console_normal_probe(struct udevice *dev) +{ + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct udevice *vid_dev = dev->parent; + struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev); + + vc_priv->x_charsize = VIDEO_FONT_WIDTH; + vc_priv->y_charsize = VIDEO_FONT_HEIGHT; + vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH; + vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT; + + return 0; +} + +struct vidconsole_ops console_normal_ops = { + .putc_xy = console_normal_putc_xy, + .move_rows = console_normal_move_rows, + .set_row = console_normal_set_row, +}; + +U_BOOT_DRIVER(vidconsole_normal) = { + .name = "vidconsole0", + .id = UCLASS_VIDEO_CONSOLE, + .ops = &console_normal_ops, + .probe = console_normal_probe, +}; + +#if defined(CONFIG_CONSOLE_ROTATION) static int console_set_row_1(struct udevice *dev, uint row, int clr) { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); @@ -495,3 +660,4 @@ U_BOOT_DRIVER(vidconsole_3) = { .ops = &console_ops_3, .probe = console_probe_1_3, }; +#endif