From patchwork Wed Sep 13 22:12:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813661 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KNJLY0Bz"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsx4h0FRTz9t0F for ; Thu, 14 Sep 2017 08:22:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 69C28C21EBC; Wed, 13 Sep 2017 22:18:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9A603C22732; Wed, 13 Sep 2017 22:18:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 04524C22617; Wed, 13 Sep 2017 22:12:48 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by lists.denx.de (Postfix) with ESMTPS id CE13BC2245A for ; Wed, 13 Sep 2017 22:12:41 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id o77so953535qke.2 for ; Wed, 13 Sep 2017 15:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p7enxtz18WXGN7EXeQYhuvP58LRIwvSyBPEQDaCdY/Q=; b=KNJLY0Bz9IN2/45ShxjPTEXqpilWZFjthqklpPTh/qTenoMmdM6xJf0qiSKpb2Avt8 KBJm0Q7xIPUVyEoA4I6NjbAkmm/h1bJopHouMgADrXbm5uLfmNvv1xvMNUfu4KdLbfdq 8H93dekuZHnuaNN31z7UZSFPkorVTSLKSRywIrnhSOWe8Z2DcLEATmv99hXnxsY1Ro9v Nghuw1dPNsSp1pFJ+T+oAOPBC1VT1b/7OZ4/pAndY3UASzLvPjnmtmn4QyA3DLr/oHuy OnDlyonX4/5lqvWX1ZntdSXEqnuTNdLrYIoqXGZjt+uPkePwSlqYAqbQkMDum5qSQfbw jQgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p7enxtz18WXGN7EXeQYhuvP58LRIwvSyBPEQDaCdY/Q=; b=Z81a7Dw4lp/Lc7vsEcaEcelyFVfuFeYB5WvaUOVO/DyIhItTE3XeAua9O4yiv3zTeu DDfHsV4uJN0HQJpeKlsqO+xWwFs7PgGbVhtOhYMdLGdWKkR12f53FYlR5rYoQmZkDz5Q DC20ww0QMkd5beIjXqkt4ZUkcTGQ0EEZrKUEWLlt+lxC66ymimDH9Jc5hpSRhdIq6wHL w9DNEWZjqK43XMi9AFsbN05wo4sCOTzkjCFwdFkgE38DYQ3XuQ6SM97PqI9qKqPqY8yK rxcgaBWcF92SbYlQ4X8KCPkyk81UIBrTBQOt7Gdg5maEzb0jYFPIi2VsG5dMGpwQV+ge 0r8A== X-Gm-Message-State: AHPjjUgCYTZgXt8ClaaPb2GLzkajYBqLmGsoUBm+88n89NjRFkPdvwyG W3O4HlK4wOgK2XUljUA= X-Google-Smtp-Source: AOwi7QDk16Fyp+wbONdZiDgxq8obCcfsCIctJgL2rmReWZphwUnvcQieZ+phdqYTUolxVZ7g21YPdQ== X-Received: by 10.233.220.199 with SMTP id q190mr31466qkf.268.1505340760550; Wed, 13 Sep 2017 15:12:40 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id a22sm7713848qte.32.2017.09.13.15.12.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:12:39 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:12:22 -0400 Message-Id: <20170913221227.21091-4-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913221227.21091-1-robdclark@gmail.com> References: <20170913221227.21091-1-robdclark@gmail.com> Subject: [U-Boot] [PATCH 3/3] dm: video: Add color ANSI escape sequence support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Note that this doesn't differentiate (due to lack of information in video_priv) between different possible component orders for 32bpp. But the main user at this point is efi_loader, and GOP expects xBGR so any video drivers that this is incorrect for already have problems. (Also, conveniently, this matches what simple-framebuffer bindings expect for kernels that use the simple-framebuffer DT binding to take over the bootloader display.) Signed-off-by: Rob Clark --- drivers/video/vidconsole-uclass.c | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 0a88cc0a42..820540b1bf 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -108,6 +108,41 @@ static void vidconsole_newline(struct udevice *dev) video_sync(dev->parent); } +static const struct { + unsigned r; + unsigned g; + unsigned b; +} colors[] = { + { 0x00, 0x00, 0x00 }, /* black */ + { 0xff, 0x00, 0x00 }, /* red */ + { 0x00, 0xff, 0x00 }, /* green */ + { 0xff, 0xff, 0x00 }, /* yellow */ + { 0x00, 0x00, 0xff }, /* blue */ + { 0xff, 0x00, 0xff }, /* magenta */ + { 0x00, 0xff, 0xff }, /* cyan */ + { 0xff, 0xff, 0xff }, /* white */ +}; + +static void set_color(struct video_priv *priv, unsigned idx, unsigned *c) +{ + switch (priv->bpix) { + case VIDEO_BPP16: + *c = ((colors[idx].r >> 3) << 0) | + ((colors[idx].g >> 2) << 5) | + ((colors[idx].b >> 3) << 11); + break; + case VIDEO_BPP32: + *c = 0xff000000 | + (colors[idx].r << 0) | + (colors[idx].g << 8) | + (colors[idx].b << 16); + break; + default: + /* unsupported, leave current color in place */ + break; + } +} + static char *parsenum(char *s, int *num) { char *end; @@ -194,6 +229,65 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } break; } + case 'm': { + struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); + char *s = priv->escape_buf; + char *end = &priv->escape_buf[priv->escape_len]; + + /* + * Set graphics mode: [%d;...;%dm + * + * Currently only supports the color attributes: + * + * Foreground Colors: + * + * 30 Black + * 31 Red + * 32 Green + * 33 Yellow + * 34 Blue + * 35 Magenta + * 36 Cyan + * 37 White + * + * Background Colors: + * + * 40 Black + * 41 Red + * 42 Green + * 43 Yellow + * 44 Blue + * 45 Magenta + * 46 Cyan + * 47 White + */ + + s++; /* [ */ + while (s < end) { + int val; + + s = parsenum(s, &val); + s++; + + switch (val) { + case 30 ... 37: + /* fg color */ + set_color(vid_priv, val - 30, + (unsigned *)&vid_priv->colour_fg); + break; + case 40 ... 47: + /* bg color */ + set_color(vid_priv, val - 40, + (unsigned *)&vid_priv->colour_bg); + break; + default: + /* unknown/unsupported */ + break; + } + } + + break; + } default: debug("unrecognized escape sequence: %*s\n", priv->escape_len, priv->escape_buf);