From patchwork Sun Sep 10 13:22:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812146 X-Patchwork-Delegate: agraf@suse.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="IkGB8ZpK"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqsMR6M8Cz9s7g for ; Sun, 10 Sep 2017 23:28:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 902E3C21E8C; Sun, 10 Sep 2017 13:27:09 +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 66F96C21F9C; Sun, 10 Sep 2017 13:24:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A8A9DC21F7E; Sun, 10 Sep 2017 13:23:29 +0000 (UTC) Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by lists.denx.de (Postfix) with ESMTPS id 08936C21F26 for ; Sun, 10 Sep 2017 13:23:20 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id r66so3910387qke.4 for ; Sun, 10 Sep 2017 06:23:19 -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=pSolHKWIFOYLriYRoaJrrVzZEfv3e0nodFSb8VLTvys=; b=IkGB8ZpK5bj3JzTcZFf/edG9GM+Q9xqR8G24TxdMoBb4ilAuXhVbVLSyOE05qpmEvC BFpmU+PaSXDPfTcD2e7B1HfwSVc3EpB/GJYz1mLu+cIhiRhQqdJm9VBqnHEgiKFkkwFp TpBwHzNFvG85Z+bGDqHTA4G4+WywP9d2wFx7IESxIAV00H2BzxP1xDHvcZUdViY+y1Kr tY7Lg7fduJAjGv9PT1BtP2pczI52n4zmUjZ7CgkyfdTmyK/0d6h6bM1JrrnyuCboSpiR dzc214NcqcFC9NBEV3d1SGKNqdmz69jZ0MRki1sglLnee4y3sEZUF6sZA98QsX5ETGya xUeA== 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=pSolHKWIFOYLriYRoaJrrVzZEfv3e0nodFSb8VLTvys=; b=XYSXfJNx0GIMhS9quiMvi7ZCiP4TSYt1bRBScOLap6c56TOTWGDS2uPsYf/ZE5SALy ignvvEdNqVfVVKCha1v/TId1Xt2GB7HRIDhXQSApqX4fjOw8Nl3YL1Bl7077d9+jJb+k 6X2JqMnMlA2PPSqImMtrhzkdbU2+Y9UEx5wxgZkAcHkVIi9w8ANhbg8LfVdtwo2ulhqk dJp/zBVt0Rgr6xUeu3zGx1aks/bM8S17eKktFmX7Q/d8Q5d2NTNHJfPpyMYk7H36MVYE 4SK25K4bcAVZ/G7l5mBvDulwRZUZZcW0T0FtVuU06MnqNSuWpIgs74N6H/xg0lvE0E4M tMkQ== X-Gm-Message-State: AHPjjUgiJU9ILdCuR13IYr3ehjABNXmeR5p4Sqt0QNTyYZ5w4TS6Bknm d4+4xP9ZOC0HdsQuq1s= X-Google-Smtp-Source: ADKCNb747oukZBi7ORFsqjCBqBLXfi/JHPKcy87+WT4qnEbFR3J9hbmpVNrFgK5VrrwArbJvTT8lXQ== X-Received: by 10.55.141.66 with SMTP id p63mr11236283qkd.210.1505049798745; Sun, 10 Sep 2017 06:23:18 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id m14sm4407130qti.51.2017.09.10.06.23.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 06:23:17 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 09:22:32 -0400 Message-Id: <20170910132236.14318-12-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910132236.14318-1-robdclark@gmail.com> References: <20170910132236.14318-1-robdclark@gmail.com> Cc: Heinrich Schuchardt , Leif Lindholm Subject: [U-Boot] [PATCH v1 11/12] 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 7998b4cf5f..dae65a21ed 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; + } +} + /* * Parse a number from string that ends in a non-numeric character.. * sscanf() would be nice. This is just enough for parsing ANSI escape @@ -197,6 +232,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);