[PATCH 4/4] arm: dts: starqltechn: add muic i2c interface

2023-12-21 Thread Dzmitry Sankouski
It allows to multiplex debug uart onto usb port, using i2c command.

Signed-off-by: Dzmitry Sankouski 

Cc: Caleb Connolly 
Cc: Dzmitry Sankouski 
Cc: Simon Glass 
Cc: Sumit Garg 
Cc: Tom Rini 
Cc: Vladimir Zapolskiy 
---

 arch/arm/dts/starqltechn.dts | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/starqltechn.dts b/arch/arm/dts/starqltechn.dts
index 539c1b51ca..5b04c3219d 100644
--- a/arch/arm/dts/starqltechn.dts
+++ b/arch/arm/dts/starqltechn.dts
@@ -23,6 +23,16 @@
stdout-path = "serial0:921600n8";
};
 
+   i2c14 {
+   compatible = "i2c-gpio";
+   pinctrl-names = "default";
+   pinctrl-0 =  <_i2c>;
+   scl-gpios = < 34 0>;
+   sda-gpios = < 33 0>;
+   i2c-gpio,delay-us = <2>;
+   status = "okay";
+   };
+
memory@8000 {
device_type = "memory";
reg = <0 0x8000 0 0xfe1c>;
@@ -59,7 +69,7 @@
 };
 
  {
-   muic-i2c-n {
+   muic_i2c: muic-i2c-n {
pins = "gpio33", "gpio34";
drive-strength = <0x2>;
function = "gpio";
-- 
2.39.2



[PATCH 3/4] arm: dts: starqltechn: add buttons

2023-12-21 Thread Dzmitry Sankouski
Add volume up and Bixby buttons.

Signed-off-by: Dzmitry Sankouski 

Cc: Caleb Connolly 
Cc: Dzmitry Sankouski 
Cc: Simon Glass 
Cc: Sumit Garg 
Cc: Tom Rini 
Cc: Vladimir Zapolskiy 
---

 arch/arm/dts/starqltechn.dts | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/dts/starqltechn.dts b/arch/arm/dts/starqltechn.dts
index 5bb1a7f90a..539c1b51ca 100644
--- a/arch/arm/dts/starqltechn.dts
+++ b/arch/arm/dts/starqltechn.dts
@@ -36,6 +36,22 @@
stride = <(1440 * 4)>;
format = "a8r8g8b8";
};
+
+   gpio-keys {
+   compatible = "gpio-keys";
+
+   key-vol-up {
+   label = "Volume Up";
+   linux,code = ;
+   gpios = <_gpios 6 GPIO_ACTIVE_LOW>;
+   };
+
+   key-bixby {
+   label = "Bixby";
+   linux,code = ;
+   gpios = <_gpios 19 GPIO_ACTIVE_LOW>;
+   };
+   };
 };
 
 _resin {
-- 
2.39.2



[PATCH 2/4] arm: dts: starqltechn: add ufs support

2023-12-21 Thread Dzmitry Sankouski
Add ufs storage support.

Signed-off-by: Dzmitry Sankouski 

Cc: Caleb Connolly 
Cc: Dzmitry Sankouski 
Cc: Simon Glass 
Cc: Sumit Garg 
Cc: Tom Rini 
Cc: Vladimir Zapolskiy 
---

 arch/arm/dts/starqltechn.dts | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/dts/starqltechn.dts b/arch/arm/dts/starqltechn.dts
index e6d57d2668..5bb1a7f90a 100644
--- a/arch/arm/dts/starqltechn.dts
+++ b/arch/arm/dts/starqltechn.dts
@@ -54,3 +54,11 @@
  {
status = "okay";
 };
+
+_mem_hc {
+   status = "okay";
+};
+
+_mem_phy {
+   status = "okay";
+};
-- 
2.39.2



[PATCH 1/4] arm: dts: starqltechn: 4K align memory

2023-12-21 Thread Dzmitry Sankouski
Fix memory size to 4K aligned.

Signed-off-by: Dzmitry Sankouski 
Cc: Caleb Connolly 
Cc: Dzmitry Sankouski 
Cc: Simon Glass 
Cc: Sumit Garg 
Cc: Tom Rini 
Cc: Vladimir Zapolskiy 
---

 arch/arm/dts/starqltechn.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/dts/starqltechn.dts b/arch/arm/dts/starqltechn.dts
index 3c0f42c977..e6d57d2668 100644
--- a/arch/arm/dts/starqltechn.dts
+++ b/arch/arm/dts/starqltechn.dts
@@ -25,7 +25,7 @@
 
memory@8000 {
device_type = "memory";
-   reg = <0 0x8000 0 0xfe1b>;
+   reg = <0 0x8000 0 0xfe1c>;
};
 
framebuffer: framebuffer@9D40 {
-- 
2.39.2



[PATCH 0/4] This enables more recently added drivers for starqltechn.

2023-12-21 Thread Dzmitry Sankouski
Series is based on top of caleb work [1] and should
be merged after that.

[1]: 
https://lore.kernel.org/u-boot/20231219-b4-qcom-common-target-v2-0-b6dd97042...@linaro.org/


Dzmitry Sankouski (4):
  arm: dts: starqltechn: 4K align memory
  arm: dts: starqltechn: add ufs support
  arm: dts: starqltechn: add buttons
  arm: dts: starqltechn: add muic i2c interface

 arch/arm/dts/starqltechn.dts | 38 ++--
 1 file changed, 36 insertions(+), 2 deletions(-)

-- 
2.39.2



[PATCH 2/3] starqltechn: use button keyboard driver

2023-04-01 Thread Dzmitry Sankouski
Button keyboard driver used to navigate bootmenu entries.

Add gpio buttons, button keyboard driver.
Add gpio keys dts bindings.

Signed-off-by: Dzmitry Sankouski 
---

 arch/arm/dts/starqltechn.dts  | 18 ++
 configs/starqltechn_defconfig |  3 +++
 include/configs/sdm845.h  |  2 +-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/starqltechn.dts b/arch/arm/dts/starqltechn.dts
index 34a4f59cbd..6c90447362 100644
--- a/arch/arm/dts/starqltechn.dts
+++ b/arch/arm/dts/starqltechn.dts
@@ -9,6 +9,8 @@
 /dts-v1/;
 
 #include "sdm845.dtsi"
+#include 
+#include 
 
 / {
model = "Samsung S9 (SM-G9600)";
@@ -43,6 +45,22 @@
format = "a8r8g8b8";
};
 
+   gpio-keys {
+   compatible = "gpio-keys";
+
+   key-pwr {
+   label = "Power";
+   linux,code = ;
+   gpios = <_pon 0 GPIO_ACTIVE_LOW>;
+   };
+
+   key-vol-down {
+   label = "Volume Down";
+   linux,code = ;
+   gpios = <_pon 1 GPIO_ACTIVE_LOW>;
+   };
+   };
+
soc: soc {
serial@a84000 {
status = "okay";
diff --git a/configs/starqltechn_defconfig b/configs/starqltechn_defconfig
index 599d926058..92e7254c73 100644
--- a/configs/starqltechn_defconfig
+++ b/configs/starqltechn_defconfig
@@ -20,9 +20,12 @@ CONFIG_SYS_PBSIZE=532
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_BMP=y
 # CONFIG_NET is not set
+CONFIG_BUTTON=y
 CONFIG_CLK=y
 CONFIG_MSM_GPIO=y
 CONFIG_QCOM_PMIC_GPIO=y
+CONFIG_DM_KEYBOARD=y
+CONFIG_BUTTON_KEYBOARD=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_QCOM=y
diff --git a/include/configs/sdm845.h b/include/configs/sdm845.h
index 2211751b54..673268dca9 100644
--- a/include/configs/sdm845.h
+++ b/include/configs/sdm845.h
@@ -16,7 +16,7 @@
 #define CFG_EXTRA_ENV_SETTINGS \
"bootm_size=0x400\0"\
"bootm_low=0x8000\0"\
-   "stdin=serial\0"\
+   "stdin=serial,button-kbd\0" \
"stdout=serial,vidconsole\0"\
"stderr=serial,vidconsole\0"\
"preboot=source $prevbl_initrd_start_addr:prebootscript\0" \
-- 
2.30.2



[PATCH 3/3] starqltechn: enable bootmenu

2023-04-01 Thread Dzmitry Sankouski
Needed for multiboot with vendor's Android.

Signed-off-by: Dzmitry Sankouski 
---

 configs/starqltechn_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/starqltechn_defconfig b/configs/starqltechn_defconfig
index 92e7254c73..5b85ce5fe9 100644
--- a/configs/starqltechn_defconfig
+++ b/configs/starqltechn_defconfig
@@ -17,6 +17,7 @@ CONFIG_HUSH_PARSER=y
 CONFIG_SYS_MAXARGS=64
 CONFIG_SYS_CBSIZE=512
 CONFIG_SYS_PBSIZE=532
+CONFIG_CMD_BOOTMENU=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_BMP=y
 # CONFIG_NET is not set
-- 
2.30.2



[PATCH 1/3] starqltechn: use 16x32 font

2023-04-01 Thread Dzmitry Sankouski
This font is more readable on high ppi display

Signed-off-by: Dzmitry Sankouski 
---

 configs/starqltechn_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/starqltechn_defconfig b/configs/starqltechn_defconfig
index 3d96e0ae09..599d926058 100644
--- a/configs/starqltechn_defconfig
+++ b/configs/starqltechn_defconfig
@@ -29,6 +29,8 @@ CONFIG_PMIC_QCOM=y
 CONFIG_MSM_GENI_SERIAL=y
 CONFIG_SPMI_MSM=y
 CONFIG_VIDEO=y
+# CONFIG_VIDEO_FONT_8X16 is not set
+CONFIG_VIDEO_FONT_16X32=y
 CONFIG_SYS_WHITE_ON_BLACK=y
 CONFIG_VIDEO_SIMPLE=y
 CONFIG_VIDEO_DT_SIMPLEFB=y
-- 
2.30.2



[PATCH 0/3] Enable bootmenu, and button-kbd driver for menu entry navigation.

2023-04-01 Thread Dzmitry Sankouski
Bootmenu needed to multiboot Android with other OSes.
16x32 font used for starqltechn's high ppi display.


Dzmitry Sankouski (3):
  starqltechn: use 16x32 font
  starqltechn: use button keyboard driver
  starqltechn: enable bootmenu

 arch/arm/dts/starqltechn.dts  | 18 ++
 configs/starqltechn_defconfig |  6 ++
 include/configs/sdm845.h  |  2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)

-- 
2.30.2



Re: [PATCH v8 04/10] video console: implement multiple fonts configuration

2023-03-10 Thread Dzmitry Sankouski
вт, 7 мар. 2023 г. в 18:22, Anatolij Gustschin :
(...)
>
> there was another build error for boards with CONFIG_VIDEO_LOGO
> disabled:
>
>  https://source.denx.de/u-boot/custodians/u-boot-video/-/jobs/589501#L1430
>
> I changed this to
>
>  void splash_display_banner(void)
>  {
> +   struct video_fontdata __maybe_unused *fontdata = fonts;
> struct udevice *dev;
> char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
> int col, row, ret;
> @@ -138,9 +140,9 @@ void splash_display_banner(void)
> if (ret)
> return;
>
> -#ifdef CONFIG_VIDEO_LOGO
> -   col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
> -   row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
> +#if IS_ENABLED(CONFIG_VIDEO_LOGO)
> +   col = BMP_LOGO_WIDTH / fontdata->width + 1;
> +   row = BMP_LOGO_HEIGHT / fontdata->height + 1;
>  #else
> col = 0;
> row = 0;
>
> --
should I send v9 with this patch?


[PATCH v8 08/10] video console: add 16x32 Terminus font from linux

2023-03-07 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
none

Changes in v7:
none

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
none

Changes in v2:
- edit for runtime configuration

 drivers/video/Kconfig |7 +
 include/video_font.h  |6 +
 include/video_font_ter16x32.h | 2062 +
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a928ae498a..60f4a4bf9c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
  Provides character bitmap data in header file.
  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
 
+config VIDEO_FONT_16X32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/include/video_font.h b/include/video_font.h
index f354d0cc4d..05d3f989a7 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include 
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include 
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_8X16)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+   FONT_ENTRY(16, 32, 16x32),
 #endif
{/* list terminator */}
 };
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..bcf3d4b123
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2062 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_TER_16X32_
+#define _VIDEO_FONT_TER_16X32_
+
+#include 
+
+static unsigned char video_fontdata_16x32[VIDEO_FONT_SIZE(256, 16, 32)] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0,
+   0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0xff, 0xfe,
+   0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xe0,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0,
+   0x07, 0xc0, 0x03, 0x80, 0x3b, 0xb8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0x

[PATCH v8 09/10] video console: sandbox: add 12x22 font defconfigs

2023-03-07 Thread Dzmitry Sankouski
Add 12x22 font in order to write a test for it.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
- add 12X22 font in sandbox_flattree_defconfig for tests

Changes in v7:
none

Changes in v6:
N/A

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
N/A

Changes in v2:
N/A

 configs/sandbox_defconfig  | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 77ade1f1d8..a0fbdad20a 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -298,6 +298,7 @@ CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_USB_ETHER=y
 CONFIG_USB_ETH_CDC=y
 CONFIG_VIDEO=y
+CONFIG_VIDEO_FONT_SUN12X22=y
 CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
diff --git a/configs/sandbox_flattree_defconfig 
b/configs/sandbox_flattree_defconfig
index 5366b1ff1d..84d9da8184 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -206,6 +206,7 @@ CONFIG_USB=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_VIDEO=y
+CONFIG_VIDEO_FONT_SUN12X22=y
 CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
-- 
2.30.2



[PATCH v8 10/10] video console: add 12x22 console simple font test

2023-03-07 Thread Dzmitry Sankouski
Tests fonts wider than a byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
none

Changes in v7:
none

Changes in v6:
- rebase
- move sandbox defconfig change to separate patch
- run savedefconfig

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v2:
N/A
none

 test/dm/video.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/test/dm/video.c b/test/dm/video.c
index 17a33cc7af..30778157d9 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state *uts)
 
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
@@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_video_text_12x22(struct unit_test_state *uts)
+{
+   struct udevice *dev, *con;
+   int i;
+
+#define WHITE  0x
+#define SCROLL_LINES   100
+
+   ut_assertok(select_vidconsole(uts, "vidconsole0"));
+   ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "12x22", 0));
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   vidconsole_putc_xy(con, 0, 0, 'a');
+   ut_asserteq(89, compress_frame_buffer(uts, dev));
+
+   vidconsole_putc_xy(con, 0, 0, ' ');
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   vidconsole_set_row(con, 0, WHITE);
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   return 0;
+}
+DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test handling of special characters in the console */
 static int dm_test_video_chars(struct unit_test_state *uts)
 {
@@ -184,6 +222,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
 
@@ -201,6 +240,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
 
/* reference clear: */
video_clear(con->parent);
@@ -249,6 +289,7 @@ static int check_vidconsole_output(struct unit_test_state 
*uts, int rot,
 
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
/* Check display wrap */
-- 
2.30.2



[PATCH v8 05/10] video console: move vidconsole_get_font_size() logic to driver ops

2023-03-07 Thread Dzmitry Sankouski
Since multiple vidconsole drivers exists, vidconsole_get_font_size()
implementation cannot longer live in vidconsole_uclass.c file.

Move current vidconsole_get_font_size logic to truetype driver ops.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
none

Changes in v7:
N/A

Changes in v6:
N/A

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
N/A

Changes in v2:
N/A

 cmd/font.c|  6 +-
 drivers/video/console_truetype.c  |  3 ++-
 drivers/video/vidconsole-uclass.c | 11 +++
 include/video_console.h   | 14 --
 test/cmd/font.c   | 13 +++--
 5 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/cmd/font.c b/cmd/font.c
index 7b4347f32b..fe2d65caaf 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -61,7 +61,11 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int 
argc,
 
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, ))
return CMD_RET_FAILURE;
-   font_name = vidconsole_get_font_size(dev, );
+   ret = vidconsole_get_font_size(dev, _name, );
+   if (ret) {
+   printf("Failed (error %d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
 
size = dectoul(argv[1], NULL);
 
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 9cac9a6de4..6b5390136a 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -724,7 +724,7 @@ static int truetype_select_font(struct udevice *dev, const 
char *name,
return 0;
 }
 
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep)
+const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
struct console_tt_metrics *met = priv->cur_met;
@@ -773,6 +773,7 @@ struct vidconsole_ops console_truetype_ops = {
.backspace  = console_truetype_backspace,
.entry_start= console_truetype_entry_start,
.get_font   = console_truetype_get_font,
+   .get_font_size  = console_truetype_get_font_size,
.select_font= truetype_select_font,
 };
 
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 72a13d3052..a5f2350ca1 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -575,6 +575,17 @@ int vidconsole_get_font(struct udevice *dev, int seq,
return ops->get_font(dev, seq, info);
 }
 
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint 
*sizep)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+   if (!ops->get_font_size)
+   return -ENOSYS;
+
+   *name = ops->get_font_size(dev, sizep);
+   return 0;
+}
+
 int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 {
struct vidconsole_ops *ops = vidconsole_get_ops(dev);
diff --git a/include/video_console.h b/include/video_console.h
index 3e1e00c23f..770103284b 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -160,6 +160,15 @@ struct vidconsole_ops {
int (*get_font)(struct udevice *dev, int seq,
struct vidfont_info *info);
 
+   /**
+* get_font_size() - get the current font name and size
+*
+* @dev: vidconsole device
+* @sizep: Place to put the font size (nominal height in pixels)
+* Returns: Current font name
+*/
+   const char *(*get_font_size)(struct udevice *dev, uint *sizep);
+
/**
 * select_font() - Select a particular font by name / size
 *
@@ -303,9 +312,10 @@ void vidconsole_list_fonts(struct udevice *dev);
  *
  * @dev: vidconsole device
  * @sizep: Place to put the font size (nominal height in pixels)
- * Returns: Current font name
+ * @name: pointer to font name, a placeholder for result
+ * Return: 0 if OK, -ENOSYS if not implemented in driver
  */
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint 
*sizep);
 
 #ifdef CONFIG_VIDEO_COPY
 /**
diff --git a/test/cmd/font.c b/test/cmd/font.c
index adb353965a..40682e5ce4 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -19,6 +19,7 @@
 static int font_test_base(struct unit_test_state *uts)
 {
struct udevice *dev;
+   const char *name;
int max_metrics;
uint size;
int ret;
@@ -32,8 +33,8 @@ static int font_test_base(struct unit_test_state *uts)
ut_assert_nextline("cantoraone_regular");
ut_assertok(ut_check_console_end(uts));
 
-   ut_asserteq_str("nimbus_sans_l_regular",
-   vidconsole_get_font_size(dev, ));
+   ut_assertok(vidconsole_get_font_size(dev, , ));
+   ut_asserteq_str("nimbus_sans_l_regular", name);
ut_asserteq(18, size);
 
   

[PATCH v8 04/10] video console: implement multiple fonts configuration

2023-03-07 Thread Dzmitry Sankouski
This needed for unit testing different fonts.

Configured fonts are placed in an array of fonts.
First font is selected by default upon console probe.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 

---

Changes in v8:
none

Changes in v7:
- place 8x16 font first in list as default
- [0] - fonts

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
N/A

Changes in v2:
N/A

 common/splash.c | 17 +++---
 drivers/video/Kconfig   | 15 ++
 drivers/video/console_core.c| 81 +
 drivers/video/console_normal.c  | 32 +++-
 drivers/video/console_rotate.c  | 72 -
 drivers/video/vidconsole_internal.h | 20 ---
 include/video_font.h| 17 +-
 include/video_font_4x6.h| 11 ++--
 include/video_font_8x16.h   |  8 +--
 include/video_font_data.h   | 31 +++
 10 files changed, 207 insertions(+), 97 deletions(-)
 create mode 100644 include/video_font_data.h

diff --git a/common/splash.c b/common/splash.c
index 245ff680eb..c8f7ad98b3 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -127,6 +127,7 @@ void splash_get_pos(int *x, int *y)
 #include 
 #include 
 #include 
+#include 
 
 void splash_display_banner(void)
 {
@@ -138,13 +139,15 @@ void splash_display_banner(void)
if (ret)
return;
 
-#ifdef CONFIG_VIDEO_LOGO
-   col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-   row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
-#else
-   col = 0;
-   row = 0;
-#endif
+   if (IS_ENABLED(CONFIG_VIDEO_LOGO)) {
+   struct video_fontdata *fontdata = fonts;
+
+   col = BMP_LOGO_WIDTH / fontdata->width + 1;
+   row = BMP_LOGO_HEIGHT / fontdata->height + 1;
+   } else {
+   col = 0;
+   row = 0;
+   }
 
display_options_get_banner(false, buf, sizeof(buf));
vidconsole_position_cursor(dev, col, 1);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 2a76d19cc8..ce97eb4727 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+   bool "4 x 6 font size"
+   help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
+config VIDEO_FONT_8X16
+   bool "8 x 16 font size"
+   default y
+   help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index de004f585c..d019b985b4 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -9,8 +9,41 @@
 #include 
 #include 
 #include 
+#include 
 #include "vidconsole_internal.h"
 
+/**
+ * console_set_font() - prepare vidconsole for chosen font.
+ *
+ * @devvidconsole device
+ * @fontdata   pointer to font data struct
+ */
+static int console_set_font(struct udevice *dev, struct video_fontdata 
*fontdata)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+   debug("console_simple: setting %s font\n", fontdata->name);
+   debug("width: %d\n", fontdata->width);
+   debug("byte width: %d\n", fontdata->byte_width);
+   debug("height: %d\n", fontdata->height);
+
+   priv->fontdata = fontdata;
+   vc_priv->x_charsize = fontdata->width;
+   vc_priv->y_charsize = fontdata->height;
+   if (vid_priv->rot % 2) {
+   vc_priv->cols = vid_priv->ysize / fontdata->width;
+   vc_priv->rows = vid_priv->xsize / fontdata->height;
+   vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+   } else {
+   vc_priv->cols = vid_priv->xsize / fontdata->width;
+   vc_priv->rows = vid_priv->ysize / fontdata->height;
+   }
+
+   return 0;
+}
+
 int check_bpix_support(int bpix)
 {
if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
@@ -43,7 +76,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 }
 
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
-bool direction)
+struct video_fontdata *fontdata, bool direction)
 {
int step, l

[PATCH v8 06/10] video console: allow font size configuration at runtime

2023-03-07 Thread Dzmitry Sankouski
Allow font size configuration at runtime for console_simple.c
driver. This needed for unit testing different fonts.

Configuring is done by `font` command, also used for font
selection in true type console.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
none

Changes in v7:
- ([seq])->name
- fonts[seq].name

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
- move 8x16 font patch extracted
- implement multiple fonts patch extracted
- add static modifiers, where needed
- remove list fonts operation
- put fontdata in local var

Changes in v2:
N/A

 cmd/Kconfig |  8 
 cmd/Makefile|  2 +-
 drivers/video/Kconfig   |  1 +
 drivers/video/console_core.c| 30 +
 drivers/video/console_normal.c  |  3 +++
 drivers/video/console_rotate.c  |  9 +
 drivers/video/vidconsole_internal.h | 18 +
 7 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..a3512836c1 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2226,6 +2226,14 @@ config CMD_VIDCONSOLE
  The name 'lcdputs' is a bit of a misnomer, but so named because the
  video device is often an LCD.
 
+config CMD_SELECT_FONT
+   bool "select font size"
+   depends on VIDEO
+   default n
+   help
+ Enabling this will provide 'font' command.
+ Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..2d8bb4fc05 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -78,7 +78,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index ce97eb4727..e1bcc89b30 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -165,6 +165,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
bool "Support a console that uses TrueType fonts"
+   select CMD_SELECT_FONT
help
  TrueTrype fonts can provide outline-drawing capability rather than
  needing to provide a bitmap for each font and size that is needed.
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index d019b985b4..d4f79c656a 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -180,3 +180,33 @@ int console_probe(struct udevice *dev)
 {
return console_set_font(dev, fonts);
 }
+
+const char *console_simple_get_font_size(struct udevice *dev, uint *sizep)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+
+   *sizep = priv->fontdata->width;
+
+   return priv->fontdata->name;
+}
+
+int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info 
*info)
+{
+   info->name = fonts[seq].name;
+
+   return 0;
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint 
size)
+{
+   struct video_fontdata *font;
+
+   for (font = fonts; font->name; font++) {
+   if (!strcmp(name, font->name)) {
+   console_set_font(dev, font);
+   return 0;
+   }
+   };
+   printf("no such font: %s, make sure it's name has x 
format\n", name);
+   return -ENOENT;
+}
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 03e859898c..413c7abee9 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -101,6 +101,9 @@ struct vidconsole_ops console_ops = {
.putc_xy= console_putc_xy,
.move_rows  = console_move_rows,
.set_row= console_set_row,
+   .get_font_size  = console_simple_get_font_size,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index b924bc3459..65358a1c6e 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -262,18 +262,27 @@ struct vidconsole_ops console_ops_1 = {
.putc_xy= console_putc_xy_1,
.move_rows  = console_move_rows_1,
.set_row= console_set_row_1,
+   .get_font_size  = console_simple_get_font_size,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_2 = {
.putc_xy= console_putc_xy_2,
.move_rows  = console_move_rows_2,
.set_row= console_s

[PATCH v8 01/10] video console: refactoring and optimization

2023-03-07 Thread Dzmitry Sankouski
- move common code to vidconsole_internal.h and console_core.c
- unite probe functions
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 

---

Changes in v8:
- fix build with disabled CONFIG_VIDEO_COPY
- add 12X22 font to sandox defconfig
- fix build with disabled CONFIG_VIDEO_COPY

Changes in v7:
none

Changes in v6:
none

Changes in v5:
- move common functions to console-core.c file
- remove static keyword from shared functions

Changes in v4:
- move common code to vidconsole_internal.h
- unite probe functions

Changes in v3:
none

Changes in v2:
none

 drivers/video/Makefile  |   6 +
 drivers/video/console_core.c| 141 +
 drivers/video/console_normal.c  | 150 --
 drivers/video/console_rotate.c  | 308 
 drivers/video/vidconsole_internal.h |  95 +
 include/video_console.h |   3 +
 6 files changed, 327 insertions(+), 376 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cdb7d9a54d..cb3f373645 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -9,6 +9,12 @@ 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
+ifdef CONFIG_CONSOLE_NORMAL
+obj-y += console_core.o
+else ifdef CONFIG_CONSOLE_ROTATION
+obj-y += console_core.o
+endif
+obj-$(CONFIG_CONSOLE_ROTATION) += console_core.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_core.c b/drivers/video/console_core.c
new file mode 100644
index 00..9c2e4cb4ea
--- /dev/null
+++ b/drivers/video/console_core.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015 Google, Inc
+ * (C) Copyright 2015
+ * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include "vidconsole_internal.h"
+
+int check_bpix_support(int bpix)
+{
+   if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
+   else if (bpix == VIDEO_BPP16 && IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   else if (bpix == VIDEO_BPP32 && IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   else
+   return -ENOSYS;
+}
+
+inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int 
step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = -vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = vid_priv->line_length;
+   }
+
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   dst = *line;
+   uchar bits = pfont[row];
+
+   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
+   *line += line_step;
+   }
+   return ret;
+}
+
+int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+  bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbyt

[PATCH v8 02/10] video console: add support for fonts wider than 1 byte

2023-03-07 Thread Dzmitry Sankouski
Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 

---

Changes in v8:
none

Changes in v7:
none

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
none

Changes in v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring

 drivers/video/console_core.c| 84 ++---
 drivers/video/console_normal.c  |  2 +-
 drivers/video/console_rotate.c  |  6 +--
 drivers/video/vidconsole_internal.h |  1 +
 4 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 9c2e4cb4ea..de004f585c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -45,7 +45,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
 bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
 
ret = check_bpix_support(vid_priv->bpix);
@@ -61,23 +61,36 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
line_step = vid_priv->line_length;
}
 
+   width_remainder = VIDEO_FONT_WIDTH % 8;
for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   uchar bits;
+
+   bitcount = 8;
dst = *line;
-   uchar bits = pfont[row];
-
-   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-   u32 value = (bits & 0x80) ?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
-   bits <<= 1;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH 
- col == 1);
+
+   if (is_last_iteration)
+   bitcount = width_remainder;
+   }
+   bits = pfont[col];
+
+   for (int bit = 0; bit < bitcount; bit++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
}
*line += line_step;
+   pfont += VIDEO_FONT_BYTE_WIDTH;
}
return ret;
 }
@@ -85,9 +98,9 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
 int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
   bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
-   u8 mask = 0x80;
+   u8 mask;
 
ret = check_bpix_support(vid_priv->bpix);
if (ret)
@@ -101,21 +114,32 @@ int fill_char_horizontally(uchar *pfont, void **line, 
struct video_priv *vid_pri
step = pbytes;
line_step = -vid_priv->line_length;
}
-   for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-   dst = *line;
-   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) 
?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
+
+   width_remainder = VIDEO_FONT_WIDTH % 8;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   mask = 0x80;
+   if (width_remainder) {
+   

[PATCH v8 03/10] video console: move 8x16 font data in named header

2023-03-07 Thread Dzmitry Sankouski
Consistent font data header names needed to add new
fonts.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---

Changes in v8:
none

Changes in v7:
none

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
N/A

Changes in v2:
N/A

 include/video_font.h | 2 +-
 include/{video_font_data.h => video_font_8x16.h} | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
 rename include/{video_font_data.h => video_font_8x16.h} (99%)

diff --git a/include/video_font.h b/include/video_font.h
index 5e23f70f85..b07c07662c 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -10,7 +10,7 @@
 #ifdef CONFIG_VIDEO_FONT_4X6
 #include 
 #else
-#include 
+#include 
 #endif
 
 #endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_data.h b/include/video_font_8x16.h
similarity index 99%
rename from include/video_font_data.h
rename to include/video_font_8x16.h
index 6e64198d1a..d3d4295032 100644
--- a/include/video_font_data.h
+++ b/include/video_font_8x16.h
@@ -6,8 +6,8 @@
  * This file contains an 8x16 bitmap font for code page 437.
  */
 
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_8X16
+#define _VIDEO_FONT_8X16
 
 #define VIDEO_FONT_CHARS   256
 #define VIDEO_FONT_WIDTH   8
@@ -4623,7 +4623,6 @@ static unsigned char __maybe_unused 
video_fontdata[VIDEO_FONT_SIZE] = {
0x00, /*  */
0x00, /*  */
0x00, /*  */
-
 };
 
 #endif
-- 
2.30.2



[PATCH v8 00/10] vidconsole: refactoring and support for wider fonts

2023-03-07 Thread Dzmitry Sankouski


Version 7 has vidconsole_get_font_size() function reworked to use
driver ops.

Version 6 contains entire rebased patch series.
New patch 'move vidconsole_get_font_size() to test.h' added.

Version 5 contain minor changes:
- move common functions to console-core.c file
- remove static keyword from shared functions

In version 4, only first patch sent, because review fixes to this would add
large rebase & patch formatting overhead. When it'll receive reviewed tag,
I'll resent entire rebased series.

Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Changes in v8:
- fix build with disabled CONFIG_VIDEO_COPY
- add 12X22 font to sandox defconfig

Dzmitry Sankouski (10):
  video console: refactoring and optimization
  video console: add support for fonts wider than 1 byte
  video console: move 8x16 font data in named header
  video console: implement multiple fonts configuration
  video console: move vidconsole_get_font_size() logic to driver ops
  video console: allow font size configuration at runtime
  video console: add 12x22 Sun font from linux
  video console: add 16x32 Terminus font from linux
  video console: sandbox: add 12x22 font defconfigs
  video console: add 12x22 console simple font test

 cmd/Kconfig |8 +
 cmd/Makefile|2 +-
 cmd/font.c  |6 +-
 common/splash.c |   17 +-
 configs/sandbox_defconfig   |1 +
 configs/sandbox_flattree_defconfig  |1 +
 drivers/video/Kconfig   |   30 +
 drivers/video/Makefile  |6 +
 drivers/video/console_core.c|  212 +
 drivers/video/console_normal.c  |  177 +-
 drivers/video/console_rotate.c  |  371 +-
 drivers/video/console_truetype.c|3 +-
 drivers/video/vidconsole-uclass.c   |   11 +
 drivers/video/vidconsole_internal.h |  120 +
 include/video_console.h |   17 +-
 include/video_font.h|   31 +-
 include/video_font_4x6.h|   11 +-
 include/video_font_8x16.h   | 4624 
 include/video_font_data.h   | 4644 +---
 include/video_font_sun12x22.h   | 6158 +++
 include/video_font_ter16x32.h   | 2062 +
 test/cmd/font.c |   13 +-
 test/dm/video.c |   41 +
 23 files changed, 13518 insertions(+), 5048 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h

-- 
2.30.2



[PATCH v3 1/1] editorconfig: introduce .editorconfig

2023-03-03 Thread Dzmitry Sankouski
Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
EditorConfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.

Reviewed-by: Simon Glass 
Signed-off-by: Dzmitry Sankouski 

---

Changes in v3:
- add 'the' article in docs
- fix spacing
- add sign off tag

Changes in v2:
- add section in coding style rst doc
- unify Kconfig with other files

 .editorconfig   | 15 +++
 .gitignore  |  1 +
 doc/develop/codingstyle.rst |  4 
 3 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00..df69cee160
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; Plugins are available for notepad++, emacs, vim, gedit,
+; textmate, visual studio, and more.
+;
+; See http://editorconfig.org for details.
+
+# Top-most EditorConfig file.
+root = true
+
+[{**.c, **.h, **Kconfig}]
+indent_style = tab
+indent_size = 8
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true
diff --git a/.gitignore b/.gitignore
index 3a4d056edf..ed8ca226fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
 #
 .*
 !.checkpatch.conf
+!.editorconfig
 *.a
 *.asn1.[ch]
 *.bin
diff --git a/doc/develop/codingstyle.rst b/doc/develop/codingstyle.rst
index 1d5d0192b3..0bbac75d4e 100644
--- a/doc/develop/codingstyle.rst
+++ b/doc/develop/codingstyle.rst
@@ -27,6 +27,10 @@ The following rules apply:
   more information, read :doc:`checkpatch`. Note that this should be done
   *before* posting on the mailing list!
 
+* Some code style rules may be applied automatically by your editor using
+  the EditorConfig tool. Feel free to setup your editor to work with u-boot's
+  .editorconfig.
+
 * Source files originating from different projects (for example the MTD
   subsystem or the hush shell code from the BusyBox project) may, after
   careful consideration, be exempted from these rules. For such files, the
-- 
2.30.2



[PATCH v3 0/1] introduce .editorconfig

2023-03-03 Thread Dzmitry Sankouski


Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
Editorconfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.

Changes in v3:
- add 'the' article in docs
- fix spacing
- add sign off tag

Changes in v2:
- add section in coding style rst doc
- unify Kconfig with other files

Dzmitry Sankouski (1):
  editorconfig: introduce .editorconfig

 .editorconfig   | 15 +++
 .gitignore  |  1 +
 doc/develop/codingstyle.rst |  4 
 3 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

-- 
2.30.2



Re: [PATCH v2 1/1] editorconfig: introduce .editorconfig

2023-03-02 Thread Dzmitry Sankouski
ср, 1 мар. 2023 г. в 18:58, Tom Rini :
>
> On Wed, Mar 01, 2023 at 01:43:38PM +0300, Dzmitry Sankouski wrote:
> > Current process of sending patches includes running checkpatch.pl
> > script for each patch, and fixing found style problems.
> > EditorConfig may help to prevent some style related problems
> > (like spaces vs tab indentation) on the fly.
> >
> > Reviewed-by: Simon Glass 
> > ---
> > Changes for v2:
> > - add section in coding style rst doc
> > - unify Kconfig with other files
> >
> >  .editorconfig   | 15 +++
> >  .gitignore  |  1 +
> >  doc/develop/codingstyle.rst |  4 
> >  3 files changed, 20 insertions(+)
> >  create mode 100644 .editorconfig
> >
> > diff --git a/.editorconfig b/.editorconfig
> > new file mode 100644
> > index 00..10fe165f09
> > --- /dev/null
> > +++ b/.editorconfig
> > @@ -0,0 +1,15 @@
> > +; This file is for unifying the coding style for different editors and 
> > IDEs.
> > +; Plugins are available for notepad++, emacs, vim, gedit,
> > +; textmate, visual studio, and more.
> > +;
> > +; See http://editorconfig.org for details.
> > +
> > +# Top-most EditorConfig file.
> > +root = true
> > +
> > +[{**.c, **.h, **Kconfig}]
> > +indent_style = tab
> > +indent_size=8
>
> As Simon noted before, this should be " = 8".
>
oops, I thought he meant consistent spacing in a sense of 8 spaces.
I personally like Kconfigs with 4 indent more.


Re: [PATCH v7 10/10] video console: add 12x22 console simple font test

2023-03-02 Thread Dzmitry Sankouski
чт, 2 мар. 2023 г. в 01:20, Anatolij Gustschin :
>
> Hi Dzmitry,
>
> On Mon, 27 Feb 2023 20:37:10 +0300
> Dzmitry Sankouski dsankou...@gmail.com wrote:
>
> > Tests fonts wider than a byte.
> >
> > Signed-off-by: Dzmitry Sankouski 
> > Reviewed-by: Simon Glass 
> > ---
> > Changes for v2: N/A
> > Changes for v2: none
> > Charges for v4: N/A
> > Charges for v5: N/A
> > Charges for v6:
> > - rebase
> > - move sandbox defconfig change to separate patch
> > - run savedefconfig
> > Charges for v7: none
> >
> >  test/dm/video.c | 41 +
> >  1 file changed, 41 insertions(+)
>
> I've applied this patch series for build testing, this test fails:
>
>  https://source.denx.de/u-boot/custodians/u-boot-video/-/jobs/587666
>
> Could you please fix it? Thanks!
>
Seems like CONFIG_VIDEO_FONT_SUN12X22 should be enabled
somewhere


[PATCH v2 1/1] editorconfig: introduce .editorconfig

2023-03-01 Thread Dzmitry Sankouski
Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
EditorConfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.

Reviewed-by: Simon Glass 
---
Changes for v2:
- add section in coding style rst doc
- unify Kconfig with other files

 .editorconfig   | 15 +++
 .gitignore  |  1 +
 doc/develop/codingstyle.rst |  4 
 3 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00..10fe165f09
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; Plugins are available for notepad++, emacs, vim, gedit,
+; textmate, visual studio, and more.
+;
+; See http://editorconfig.org for details.
+
+# Top-most EditorConfig file.
+root = true
+
+[{**.c, **.h, **Kconfig}]
+indent_style = tab
+indent_size=8
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true
diff --git a/.gitignore b/.gitignore
index 3a4d056edf..ed8ca226fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
 #
 .*
 !.checkpatch.conf
+!.editorconfig
 *.a
 *.asn1.[ch]
 *.bin
diff --git a/doc/develop/codingstyle.rst b/doc/develop/codingstyle.rst
index 1d5d0192b3..741bc58b83 100644
--- a/doc/develop/codingstyle.rst
+++ b/doc/develop/codingstyle.rst
@@ -27,6 +27,10 @@ The following rules apply:
   more information, read :doc:`checkpatch`. Note that this should be done
   *before* posting on the mailing list!
 
+* Some code style rules may be applied automatically by your editor using
+  EditorConfig tool. Feel free to setup your editor to work with u-boot's
+  .editorconfig.
+
 * Source files originating from different projects (for example the MTD
   subsystem or the hush shell code from the BusyBox project) may, after
   careful consideration, be exempted from these rules. For such files, the
-- 
2.30.2



[PATCH v2 0/1] introduce .editorconfig

2023-03-01 Thread Dzmitry Sankouski
Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
Editorconfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.

Dzmitry Sankouski (1):
  editorconfig: introduce .editorconfig

 .editorconfig   | 15 +++
 .gitignore  |  1 +
 doc/develop/codingstyle.rst |  4 
 3 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

-- 
2.30.2



[PATCH 1/1] editorconfig: introduce .editorconfig

2023-02-28 Thread Dzmitry Sankouski
Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
Editorconfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.
---
 .editorconfig | 19 +++
 .gitignore|  1 +
 2 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00..b8a413fda1
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,19 @@
+; This file is for unifying the coding style for different editors and IDEs.
+; Plugins are available for notepad++, emacs, vim, gedit,
+; textmate, visual studio, and more.
+;
+; See http://editorconfig.org for details.
+
+# Top-most EditorConfig file.
+root = true
+
+[{**.c, **.h}]
+indent_style = tab
+indent_size=8
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[**Kconfig]
+indent_size=4
+
diff --git a/.gitignore b/.gitignore
index 3a4d056edf..ed8ca226fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
 #
 .*
 !.checkpatch.conf
+!.editorconfig
 *.a
 *.asn1.[ch]
 *.bin
-- 
2.30.2



[PATCH 0/1] introduce .editorconfig

2023-02-28 Thread Dzmitry Sankouski
Current process of sending patches includes running checkpatch.pl
script for each patch, and fixing found style problems.
Editorconfig may help to prevent some style related problems
(like spaces vs tab indentation) on the fly.

Dzmitry Sankouski (1):
  editorconfig: introduce .editorconfig

 .editorconfig | 19 +++
 .gitignore|  1 +
 2 files changed, 20 insertions(+)
 create mode 100644 .editorconfig

-- 
2.30.2



[PATCH v7 08/10] video console: add 16x32 Terminus font from linux

2023-02-27 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2:
- edit for runtime configuration
Changes for v3: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only
Charges for v7: none

 drivers/video/Kconfig |7 +
 include/video_font.h  |6 +
 include/video_font_ter16x32.h | 2062 +
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a928ae498a..60f4a4bf9c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
  Provides character bitmap data in header file.
  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
 
+config VIDEO_FONT_16X32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/include/video_font.h b/include/video_font.h
index f354d0cc4d..05d3f989a7 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include 
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include 
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_8X16)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+   FONT_ENTRY(16, 32, 16x32),
 #endif
{/* list terminator */}
 };
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..bcf3d4b123
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2062 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_TER_16X32_
+#define _VIDEO_FONT_TER_16X32_
+
+#include 
+
+static unsigned char video_fontdata_16x32[VIDEO_FONT_SIZE(256, 16, 32)] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0,
+   0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0xff, 0xfe,
+   0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xe0,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0,
+   0x07, 0xc0, 0x03, 0x80, 0x3b, 0xb8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3b, 0xb8, 0x

[PATCH v7 10/10] video console: add 12x22 console simple font test

2023-02-27 Thread Dzmitry Sankouski
Tests fonts wider than a byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v2: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6:
- rebase
- move sandbox defconfig change to separate patch
- run savedefconfig
Charges for v7: none

 test/dm/video.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/test/dm/video.c b/test/dm/video.c
index 17a33cc7af..30778157d9 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state *uts)
 
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
@@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_video_text_12x22(struct unit_test_state *uts)
+{
+   struct udevice *dev, *con;
+   int i;
+
+#define WHITE  0x
+#define SCROLL_LINES   100
+
+   ut_assertok(select_vidconsole(uts, "vidconsole0"));
+   ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "12x22", 0));
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   vidconsole_putc_xy(con, 0, 0, 'a');
+   ut_asserteq(89, compress_frame_buffer(uts, dev));
+
+   vidconsole_putc_xy(con, 0, 0, ' ');
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   vidconsole_set_row(con, 0, WHITE);
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   return 0;
+}
+DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test handling of special characters in the console */
 static int dm_test_video_chars(struct unit_test_state *uts)
 {
@@ -184,6 +222,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
 
@@ -201,6 +240,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
 
/* reference clear: */
video_clear(con->parent);
@@ -249,6 +289,7 @@ static int check_vidconsole_output(struct unit_test_state 
*uts, int rot,
 
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
/* Check display wrap */
-- 
2.30.2



[PATCH v7 09/10] video console: sandbox_defconfig: add 12x22 font

2023-02-27 Thread Dzmitry Sankouski
Add 12x22 font in order to write a test for it.
Run savedefconfig.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: N/A
Charges for v7: none

 configs/sandbox_defconfig | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 34c342b6f5..a0fbdad20a 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -2,6 +2,7 @@ CONFIG_TEXT_BASE=0
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
+CONFIG_DM_RESET=y
 CONFIG_PRE_CON_BUF_ADDR=0xf
 CONFIG_BOOTSTAGE_STASH_ADDR=0x0
 CONFIG_SYS_LOAD_ADDR=0x0
@@ -100,7 +101,6 @@ CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
 CONFIG_CMD_EFIDEBUG=y
-CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_PAUSE=y
@@ -263,7 +263,6 @@ CONFIG_DM_REBOOT_MODE=y
 CONFIG_DM_REBOOT_MODE_GPIO=y
 CONFIG_DM_REBOOT_MODE_RTC=y
 CONFIG_REMOTEPROC_SANDBOX=y
-CONFIG_DM_RESET=y
 CONFIG_SANDBOX_RESET=y
 CONFIG_RESET_SYSCON=y
 CONFIG_RESET_SCMI=y
@@ -299,10 +298,10 @@ CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_USB_ETHER=y
 CONFIG_USB_ETH_CDC=y
 CONFIG_VIDEO=y
+CONFIG_VIDEO_FONT_SUN12X22=y
 CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
-CONFIG_CONSOLE_TRUETYPE_MAX_METRICS=10
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_I2C_EDID=y
 CONFIG_VIDEO_SANDBOX_SDL=y
-- 
2.30.2



[PATCH v7 06/10] video console: allow font size configuration at runtime

2023-02-27 Thread Dzmitry Sankouski
Allow font size configuration at runtime for console_simple.c
driver. This needed for unit testing different fonts.

Configuring is done by `font` command, also used for font
selection in true type console.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3:
- move 8x16 font patch extracted
- implement multiple fonts patch extracted
- add static modifiers, where needed
- remove list fonts operation
- put fontdata in local var
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only
Charges for v7: rebase only
- ([seq])->name- fonts[seq].name

 cmd/Kconfig |  8 
 cmd/Makefile|  2 +-
 drivers/video/Kconfig   |  1 +
 drivers/video/console_core.c| 30 +
 drivers/video/console_normal.c  |  3 +++
 drivers/video/console_rotate.c  |  9 +
 drivers/video/vidconsole_internal.h | 18 +
 7 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..a3512836c1 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2226,6 +2226,14 @@ config CMD_VIDCONSOLE
  The name 'lcdputs' is a bit of a misnomer, but so named because the
  video device is often an LCD.
 
+config CMD_SELECT_FONT
+   bool "select font size"
+   depends on VIDEO
+   default n
+   help
+ Enabling this will provide 'font' command.
+ Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..2d8bb4fc05 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -78,7 +78,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index ce97eb4727..e1bcc89b30 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -165,6 +165,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
bool "Support a console that uses TrueType fonts"
+   select CMD_SELECT_FONT
help
  TrueTrype fonts can provide outline-drawing capability rather than
  needing to provide a bitmap for each font and size that is needed.
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index b82ca6d43c..d830738427 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -180,3 +180,33 @@ int console_probe(struct udevice *dev)
 {
return console_set_font(dev, fonts);
 }
+
+const char *console_simple_get_font_size(struct udevice *dev, uint *sizep)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+
+   *sizep = priv->fontdata->width;
+
+   return priv->fontdata->name;
+}
+
+int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info 
*info)
+{
+   info->name = fonts[seq].name;
+
+   return 0;
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint 
size)
+{
+   struct video_fontdata *font;
+
+   for (font = fonts; font->name; font++) {
+   if (!strcmp(name, font->name)) {
+   console_set_font(dev, font);
+   return 0;
+   }
+   };
+   printf("no such font: %s, make sure it's name has x 
format\n", name);
+   return -ENOENT;
+}
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 03e859898c..413c7abee9 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -101,6 +101,9 @@ struct vidconsole_ops console_ops = {
.putc_xy= console_putc_xy,
.move_rows  = console_move_rows,
.set_row= console_set_row,
+   .get_font_size  = console_simple_get_font_size,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index b924bc3459..65358a1c6e 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -262,18 +262,27 @@ struct vidconsole_ops console_ops_1 = {
.putc_xy= console_putc_xy_1,
.move_rows  = console_move_rows_1,
.set_row= console_set_row_1,
+   .get_font_size  = console_simple_get_font_size,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_2 = {
.putc_xy= console_putc_xy_2,
.move_rows  = console_move_rows_2,
.set_row= console_set_row_2,
+   .

[PATCH v7 04/10] video console: implement multiple fonts configuration

2023-02-27 Thread Dzmitry Sankouski
This needed for unit testing different fonts.

Configured fonts are placed in an array of fonts.
First font is selected by default upon console probe.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only
Charges for v7:
- place 8x16 font first in list as default
- [0] - fonts

 common/splash.c | 17 +++---
 drivers/video/Kconfig   | 15 ++
 drivers/video/console_core.c| 81 +
 drivers/video/console_normal.c  | 32 +++-
 drivers/video/console_rotate.c  | 72 -
 drivers/video/vidconsole_internal.h | 20 ---
 include/video_font.h| 17 +-
 include/video_font_4x6.h| 11 ++--
 include/video_font_8x16.h   |  8 +--
 include/video_font_data.h   | 31 +++
 10 files changed, 207 insertions(+), 97 deletions(-)
 create mode 100644 include/video_font_data.h

diff --git a/common/splash.c b/common/splash.c
index 245ff680eb..1cd9afae2d 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -127,6 +127,7 @@ void splash_get_pos(int *x, int *y)
 #include 
 #include 
 #include 
+#include 
 
 void splash_display_banner(void)
 {
@@ -138,13 +139,15 @@ void splash_display_banner(void)
if (ret)
return;
 
-#ifdef CONFIG_VIDEO_LOGO
-   col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-   row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
-#else
-   col = 0;
-   row = 0;
-#endif
+   if (IS_ENABLED(CONFIG_VIDEO_LOGO)) {
+   struct video_fontdata *fontdata = fonts;
+
+   col = BMP_LOGO_WIDTH / fontdata->width + 1;
+   row = BMP_LOGO_HEIGHT / fontdata->height + 1;
+   } else {
+   col = 0;
+   row = 0;
+   }
 
display_options_get_banner(false, buf, sizeof(buf));
vidconsole_position_cursor(dev, col, 1);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 2a76d19cc8..ce97eb4727 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+   bool "4 x 6 font size"
+   help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
+config VIDEO_FONT_8X16
+   bool "8 x 16 font size"
+   default y
+   help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index de004f585c..b82ca6d43c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -9,8 +9,41 @@
 #include 
 #include 
 #include 
+#include 
 #include "vidconsole_internal.h"
 
+/**
+ * console_set_font() - prepare vidconsole for chosen font.
+ *
+ * @devvidconsole device
+ * @fontdata   pointer to font data struct
+ */
+static int console_set_font(struct udevice *dev, struct video_fontdata 
*fontdata)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+   debug("console_simple: setting %s font\n", fontdata->name);
+   debug("width: %d\n", fontdata->width);
+   debug("byte width: %d\n", fontdata->byte_width);
+   debug("height: %d\n", fontdata->height);
+
+   priv->fontdata = fontdata;
+   vc_priv->x_charsize = fontdata->width;
+   vc_priv->y_charsize = fontdata->height;
+   if (vid_priv->rot % 2) {
+   vc_priv->cols = vid_priv->ysize / fontdata->width;
+   vc_priv->rows = vid_priv->xsize / fontdata->height;
+   vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+   } else {
+   vc_priv->cols = vid_priv->xsize / fontdata->width;
+   vc_priv->rows = vid_priv->ysize / fontdata->height;
+   }
+
+   return 0;
+}
+
 int check_bpix_support(int bpix)
 {
if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
@@ -43,7 +76,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 }
 
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
-bool direction)
+struct video_fontdata *fontdata, bool direction)
 {
int step, line_step, pbytes, bitcount, width_rema

[PATCH v7 05/10] video console: move vidconsole_get_font_size() logic to driver ops

2023-02-27 Thread Dzmitry Sankouski
Since multiple vidconsole drivers exists, vidconsole_get_font_size()
implementation cannot longer live in vidconsole_uclass.c file.

Move current vidconsole_get_font_size logic to truetype driver ops.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: N/A
Charges for v7: N/A

 cmd/font.c|  6 +-
 drivers/video/console_truetype.c  |  3 ++-
 drivers/video/vidconsole-uclass.c | 11 +++
 include/video_console.h   | 14 --
 test/cmd/font.c   | 13 +++--
 5 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/cmd/font.c b/cmd/font.c
index 7b4347f32b..fe2d65caaf 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -61,7 +61,11 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int 
argc,
 
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, ))
return CMD_RET_FAILURE;
-   font_name = vidconsole_get_font_size(dev, );
+   ret = vidconsole_get_font_size(dev, _name, );
+   if (ret) {
+   printf("Failed (error %d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
 
size = dectoul(argv[1], NULL);
 
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 9cac9a6de4..6b5390136a 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -724,7 +724,7 @@ static int truetype_select_font(struct udevice *dev, const 
char *name,
return 0;
 }
 
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep)
+const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
struct console_tt_metrics *met = priv->cur_met;
@@ -773,6 +773,7 @@ struct vidconsole_ops console_truetype_ops = {
.backspace  = console_truetype_backspace,
.entry_start= console_truetype_entry_start,
.get_font   = console_truetype_get_font,
+   .get_font_size  = console_truetype_get_font_size,
.select_font= truetype_select_font,
 };
 
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 72a13d3052..a5f2350ca1 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -575,6 +575,17 @@ int vidconsole_get_font(struct udevice *dev, int seq,
return ops->get_font(dev, seq, info);
 }
 
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint 
*sizep)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+   if (!ops->get_font_size)
+   return -ENOSYS;
+
+   *name = ops->get_font_size(dev, sizep);
+   return 0;
+}
+
 int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 {
struct vidconsole_ops *ops = vidconsole_get_ops(dev);
diff --git a/include/video_console.h b/include/video_console.h
index 9d2c0f210e..646c7e292b 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -160,6 +160,15 @@ struct vidconsole_ops {
int (*get_font)(struct udevice *dev, int seq,
struct vidfont_info *info);
 
+   /**
+* get_font_size() - get the current font name and size
+*
+* @dev: vidconsole device
+* @sizep: Place to put the font size (nominal height in pixels)
+* Returns: Current font name
+*/
+   const char *(*get_font_size)(struct udevice *dev, uint *sizep);
+
/**
 * select_font() - Select a particular font by name / size
 *
@@ -303,9 +312,10 @@ void vidconsole_list_fonts(struct udevice *dev);
  *
  * @dev: vidconsole device
  * @sizep: Place to put the font size (nominal height in pixels)
- * Returns: Current font name
+ * @name: pointer to font name, a placeholder for result
+ * Return: 0 if OK, -ENOSYS if not implemented in driver
  */
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
+int vidconsole_get_font_size(struct udevice *dev, const char **name, uint 
*sizep);
 
 #ifdef CONFIG_VIDEO_COPY
 /**
diff --git a/test/cmd/font.c b/test/cmd/font.c
index adb353965a..40682e5ce4 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -19,6 +19,7 @@
 static int font_test_base(struct unit_test_state *uts)
 {
struct udevice *dev;
+   const char *name;
int max_metrics;
uint size;
int ret;
@@ -32,8 +33,8 @@ static int font_test_base(struct unit_test_state *uts)
ut_assert_nextline("cantoraone_regular");
ut_assertok(ut_check_console_end(uts));
 
-   ut_asserteq_str("nimbus_sans_l_regular",
-   vidconsole_get_font_size(dev, ));
+   ut_assertok(vidconsole_get_font_size(dev, , ));
+   ut_asserteq_str("nimbus_sans_l_regular", name);
ut_asserteq(18, size);
 
max_metrics = 1;
@@ -52,15 +53,15 @@ s

[PATCH v7 03/10] video console: move 8x16 font data in named header

2023-02-27 Thread Dzmitry Sankouski
Consistent font data header names needed to add new
fonts.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only
Charges for v7: none

 include/video_font.h | 2 +-
 include/{video_font_data.h => video_font_8x16.h} | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
 rename include/{video_font_data.h => video_font_8x16.h} (99%)

diff --git a/include/video_font.h b/include/video_font.h
index 5e23f70f85..b07c07662c 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -10,7 +10,7 @@
 #ifdef CONFIG_VIDEO_FONT_4X6
 #include 
 #else
-#include 
+#include 
 #endif
 
 #endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_data.h b/include/video_font_8x16.h
similarity index 99%
rename from include/video_font_data.h
rename to include/video_font_8x16.h
index 6e64198d1a..d3d4295032 100644
--- a/include/video_font_data.h
+++ b/include/video_font_8x16.h
@@ -6,8 +6,8 @@
  * This file contains an 8x16 bitmap font for code page 437.
  */
 
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_8X16
+#define _VIDEO_FONT_8X16
 
 #define VIDEO_FONT_CHARS   256
 #define VIDEO_FONT_WIDTH   8
@@ -4623,7 +4623,6 @@ static unsigned char __maybe_unused 
video_fontdata[VIDEO_FONT_SIZE] = {
0x00, /*  */
0x00, /*  */
0x00, /*  */
-
 };
 
 #endif
-- 
2.30.2



[PATCH v7 01/10] video console: refactoring and optimization

2023-02-27 Thread Dzmitry Sankouski
- move common code to vidconsole_internal.h and console_core.c
- unite probe functions
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: none
Changes for v3: none
Changes for v4:
- move common code to vidconsole_internal.h
- unite probe functions
Changes for v5:
- move common functions to console-core.c file
- remove static keyword from shared functions
Changes for v6: none
Changes for v7: none

 drivers/video/Makefile  |   6 +
 drivers/video/console_core.c| 141 +
 drivers/video/console_normal.c  | 150 --
 drivers/video/console_rotate.c  | 308 
 drivers/video/vidconsole_internal.h |  95 +
 5 files changed, 324 insertions(+), 376 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cdb7d9a54d..cb3f373645 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -9,6 +9,12 @@ 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
+ifdef CONFIG_CONSOLE_NORMAL
+obj-y += console_core.o
+else ifdef CONFIG_CONSOLE_ROTATION
+obj-y += console_core.o
+endif
+obj-$(CONFIG_CONSOLE_ROTATION) += console_core.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_core.c b/drivers/video/console_core.c
new file mode 100644
index 00..9c2e4cb4ea
--- /dev/null
+++ b/drivers/video/console_core.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015 Google, Inc
+ * (C) Copyright 2015
+ * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include "vidconsole_internal.h"
+
+int check_bpix_support(int bpix)
+{
+   if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
+   else if (bpix == VIDEO_BPP16 && IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   else if (bpix == VIDEO_BPP32 && IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   else
+   return -ENOSYS;
+}
+
+inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int 
step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = -vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = vid_priv->line_length;
+   }
+
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   dst = *line;
+   uchar bits = pfont[row];
+
+   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
+   *line += line_step;
+   }
+   return ret;
+}
+
+int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+  bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = vid_priv->line_length;
+   } else {
+   step = pbyte

[PATCH v7 02/10] video console: add support for fonts wider than 1 byte

2023-02-27 Thread Dzmitry Sankouski
Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Charges for v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring
Charges for v3: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only
Charges for v7: none

 drivers/video/console_core.c| 84 ++---
 drivers/video/console_normal.c  |  2 +-
 drivers/video/console_rotate.c  |  6 +--
 drivers/video/vidconsole_internal.h |  1 +
 4 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 9c2e4cb4ea..de004f585c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -45,7 +45,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
 bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
 
ret = check_bpix_support(vid_priv->bpix);
@@ -61,23 +61,36 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
line_step = vid_priv->line_length;
}
 
+   width_remainder = VIDEO_FONT_WIDTH % 8;
for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   uchar bits;
+
+   bitcount = 8;
dst = *line;
-   uchar bits = pfont[row];
-
-   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-   u32 value = (bits & 0x80) ?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
-   bits <<= 1;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH 
- col == 1);
+
+   if (is_last_iteration)
+   bitcount = width_remainder;
+   }
+   bits = pfont[col];
+
+   for (int bit = 0; bit < bitcount; bit++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
}
*line += line_step;
+   pfont += VIDEO_FONT_BYTE_WIDTH;
}
return ret;
 }
@@ -85,9 +98,9 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
 int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
   bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
-   u8 mask = 0x80;
+   u8 mask;
 
ret = check_bpix_support(vid_priv->bpix);
if (ret)
@@ -101,21 +114,32 @@ int fill_char_horizontally(uchar *pfont, void **line, 
struct video_priv *vid_pri
step = pbytes;
line_step = -vid_priv->line_length;
}
-   for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-   dst = *line;
-   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) 
?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
+
+   width_remainder = VIDEO_FONT_WIDTH % 8;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   mask = 0x80;
+   if (width_remainder) {
+   

[PATCH v7 00/10] vidconsole: refactoring and support for wider fonts

2023-02-27 Thread Dzmitry Sankouski
Version 7 has vidconsole_get_font_size() function reworked to use
driver ops.

Version 6 contains entire rebased patch series.
New patch 'move vidconsole_get_font_size() to test.h' added.

Version 5 contain minor changes:
- move common functions to console-core.c file
- remove static keyword from shared functions

In version 4, only first patch sent, because review fixes to this would add
large rebase & patch formatting overhead. When it'll receive reviewed tag,
I'll resent entire rebased series.

Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Dzmitry Sankouski (10):
  video console: refactoring and optimization
  video console: add support for fonts wider than 1 byte
  video console: move 8x16 font data in named header
  video console: implement multiple fonts configuration
  video console: move vidconsole_get_font_size() logic to driver ops
  video console: allow font size configuration at runtime
  video console: add 12x22 Sun font from linux
  video console: add 16x32 Terminus font from linux
  video console: sandbox_defconfig: add 12x22 font
  video console: add 12x22 console simple font test

 cmd/Kconfig |8 +
 cmd/Makefile|2 +-
 cmd/font.c  |6 +-
 common/splash.c |   17 +-
 configs/sandbox_defconfig   |5 +-
 drivers/video/Kconfig   |   30 +
 drivers/video/Makefile  |6 +
 drivers/video/console_core.c|  212 +
 drivers/video/console_normal.c  |  177 +-
 drivers/video/console_rotate.c  |  371 +-
 drivers/video/console_truetype.c|3 +-
 drivers/video/vidconsole-uclass.c   |   11 +
 drivers/video/vidconsole_internal.h |  120 +
 include/video_console.h |   14 +-
 include/video_font.h|   31 +-
 include/video_font_4x6.h|   11 +-
 include/video_font_8x16.h   | 4624 
 include/video_font_data.h   | 4644 +---
 include/video_font_sun12x22.h   | 6158 +++
 include/video_font_ter16x32.h   | 2062 +
 test/cmd/font.c |   13 +-
 test/dm/video.c |   41 +
 22 files changed, 13515 insertions(+), 5051 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h

-- 
2.30.2



[PATCH v6 5/9] video console: move vidconsole_get_font_size() to test.h

2023-02-23 Thread Dzmitry Sankouski
vidconsole_get_font_size is only used in tests and in font
command. It's role in 'font size' command was to only fetch
current font name, to be used in select font function.
This is redundant, because it's easy to check for empty
string, and reuse current name right in select function.

Test functions in public API use memory and clutter interface.

Move vidconsole_get_font_size to new cmd/test.h file.
Wrap it's implementation with #ifdef only when tests enabled.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: N/A

 cmd/font.c   |  5 ++---
 drivers/video/console_truetype.c |  8 +++-
 include/cmd/test.h   | 19 +++
 include/video_console.h  |  9 -
 test/cmd/font.c  |  1 +
 5 files changed, 29 insertions(+), 13 deletions(-)
 create mode 100644 include/cmd/test.h

diff --git a/cmd/font.c b/cmd/font.c
index 7b4347f32b..af542b01ee 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -51,7 +51,7 @@ static int do_font_select(struct cmd_tbl *cmdtp, int flag, 
int argc,
 static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
 {
-   const char *font_name;
+   const char *empty_name = {'\0'};
struct udevice *dev;
uint size;
int ret;
@@ -61,11 +61,10 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, 
int argc,
 
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, ))
return CMD_RET_FAILURE;
-   font_name = vidconsole_get_font_size(dev, );
 
size = dectoul(argv[1], NULL);
 
-   ret = vidconsole_select_font(dev, font_name, size);
+   ret = vidconsole_select_font(dev, empty_name, size);
if (ret) {
printf("Failed (error %d)\n", ret);
return CMD_RET_FAILURE;
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 9cac9a6de4..f57d8b6dae 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2016 Google, Inc
+ * (C) Copyright 2023 Dzmitry Sankouski 
  */
 
 #include 
@@ -9,6 +10,9 @@
 #include 
 #include 
 #include 
+#if IS_ENABLED(CONFIG_UT_DM)
+#include 
+#endif
 
 /* Functions needed by stb_truetype.h */
 static int tt_floor(double val)
@@ -691,7 +695,7 @@ static int truetype_select_font(struct udevice *dev, const 
char *name,
if (!size)
size = CONFIG_CONSOLE_TRUETYPE_SIZE;
if (!name)
-   name = font_table->name;
+   name = priv->cur_met->font_name;
 
met = find_metrics(dev, name, size);
if (!met) {
@@ -724,6 +728,7 @@ static int truetype_select_font(struct udevice *dev, const 
char *name,
return 0;
 }
 
+#if IS_ENABLED(CONFIG_UT_DM)
 const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
@@ -733,6 +738,7 @@ const char *vidconsole_get_font_size(struct udevice *dev, 
uint *sizep)
 
return met->font_name;
 }
+#endif
 
 static int console_truetype_probe(struct udevice *dev)
 {
diff --git a/include/cmd/test.h b/include/cmd/test.h
new file mode 100644
index 00..39afb99b73
--- /dev/null
+++ b/include/cmd/test.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2015 Google, Inc
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#ifndef __cmd_test_h
+#define __cmd_test_h
+
+/**
+ * vidconsole_get_font_size() - get the current font name and size
+ *
+ * @dev: vidconsole device
+ * @sizep: Place to put the font size (nominal height in pixels)
+ * Returns: Current font name
+ */
+const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
+
+#endif
diff --git a/include/video_console.h b/include/video_console.h
index 9d2c0f210e..9c3d0ad305 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -298,15 +298,6 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, 
int y);
  */
 void vidconsole_list_fonts(struct udevice *dev);
 
-/**
- * vidconsole_get_font_size() - get the current font name and size
- *
- * @dev: vidconsole device
- * @sizep: Place to put the font size (nominal height in pixels)
- * Returns: Current font name
- */
-const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
-
 #ifdef CONFIG_VIDEO_COPY
 /**
  * vidconsole_sync_copy() - Sync back to the copy framebuffer
diff --git a/test/cmd/font.c b/test/cmd/font.c
index adb353965a..524004bed8 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Declare a new fdt test */
 #define FONT_TEST(_name, _flags)   UNIT_TEST(_name, _flags, font_test)
-- 
2.30.2



[PATCH v6 8/9] video console: add 16x32 Terminus font from linux

2023-02-23 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2:
- edit for runtime configuration
Changes for v3: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only

 drivers/video/Kconfig |7 +
 include/video_font.h  |6 +
 include/video_font_ter16x32.h | 2062 +
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a928ae498a..60f4a4bf9c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
  Provides character bitmap data in header file.
  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
 
+config VIDEO_FONT_16X32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/include/video_font.h b/include/video_font.h
index 03622adc7a..d4dd2b5eed 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include 
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include 
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_4X6)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+   FONT_ENTRY(16, 32, 16x32),
 #endif
{/* list terminator */}
 };
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..bcf3d4b123
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2062 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_TER_16X32_
+#define _VIDEO_FONT_TER_16X32_
+
+#include 
+
+static unsigned char video_fontdata_16x32[VIDEO_FONT_SIZE(256, 16, 32)] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0,
+   0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0xff, 0xfe,
+   0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xe0,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0,
+   0x07, 0xc0, 0x03, 0x80, 0x3b, 0xb8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3b, 0xb8, 0x03, 0x80, 0x03, 0x80,
+   

Re: [PATCH v3 9/9] video console: add 12x22 console simple font test

2023-02-23 Thread Dzmitry Sankouski
Hi Simon,

I investigated the usage of vidconsole_get_font_size, and it turned out,
it's only used for tests, and in the `font size` command to provide font name.

So I moved vidconsole_get_font_size from the public API to cmd/test.h.
I think it'll be
better than cluttering public API and driver ops functions with test stuff.
Please see patches for details.

сб, 18 февр. 2023 г. в 02:49, Simon Glass :
>
> Hi Dzmitry,
>
> On Fri, 17 Feb 2023 at 07:13, Dzmitry Sankouski  wrote:
> >
> > How does CONSOLE_TRUETYPE interfere with CONFIG_VIDEO_FONT_SUN12X22?
> >
>
> I don't mean that.
>
> I tried resyncing the sandbox defconfig, and found that the defconfig
> additions in this patch went away, meaning they are not used.
>
> I think I know what is needed:
>
> vidconsole_get_font_size()
>  - implement this in vidconsole-uclass.c by calling the method for the
> driver. See how this is done with vidconsole_putc_xy(), for example.
> You can see this problem if you enable CMD_SELECT_FONT but don't
> enable CONSOLE_TRUETYPE
>
> config CMD_SELECT_FONT
> - the 'bool' needs to be indented with a tab. I think it is is being
> ignored with Kconfig which is why it doesn't work
>
> resync configs with 'make savedefconfig'
> - patches should have the CONFIG options (in defconfigs) in the
> correct order, and this is how you check it.
>
> >
> > I've got all video tests passed:
> >
> > make sandbox_defconfig && make -j4 && ./u-boot -T -c 'ut dm'
> > (...)
> > Test: dm_test_video_ansi: video.c
> > Test: dm_test_video_base: video.c
> > Test: dm_test_video_base: video.c (flat tree)
> > Test: dm_test_video_bmp: video.c
> > Test: dm_test_video_bmp16: video.c
> > Test: dm_test_video_bmp24: video.c
> > Test: dm_test_video_bmp24_32: video.c
> > Test: dm_test_video_bmp32: video.c
> > Test: dm_test_video_bmp8: video.c
> > Test: dm_test_video_bmp_comp: video.c
> > Test: dm_test_video_chars: video.c
> > Test: dm_test_video_comp_bmp32: video.c
> > Test: dm_test_video_comp_bmp8: video.c
> > Test: dm_test_video_context: video.c
> > Test: dm_test_video_rotation1: video.c
> > Test: dm_test_video_rotation2: video.c
> > Test: dm_test_video_rotation3: video.c
> > Test: dm_test_video_text: video.c
> > Test: dm_test_video_text_12x22: video.c
> > Test: dm_test_video_truetype: video.c
> > Test: dm_test_video_truetype_bs: video.c
> > Test: dm_test_video_truetype_scroll: video.c
> > Test: dm_test_virtio_all_ops: virtio_device.c
> > Test: dm_test_virtio_all_ops: virtio_device.c (flat tree)
> > Test: dm_test_virtio_base: virtio_device.c
> > (...)
> >
>
> Yes, as you say, the tests pass and look good. I think my problem was
> the above issues.
>
> Regards,
> Simon
>
>
>
>
> > чт, 16 февр. 2023 г. в 02:50, Simon Glass :
> > >
> > > Hi Dzmitry,
> > >
> > > On Wed, 15 Feb 2023 at 04:43, Dzmitry Sankouski  
> > > wrote:
> > > >
> > > > Tests fonts wider than a byte.
> > > >
> > > > Signed-off-by: Dzmitry Sankouski 
> > > > Reviewed-by: Simon Glass 
> > >
> > > I found a problem with this
> > >
> > > > ---
> > > > Changes for v2: N/A
> > > > Changes for v2: none
> > > >
> > > >  configs/sandbox_defconfig |  3 +++
> > > >  test/dm/video.c   | 41 +++
> > > >  2 files changed, 44 insertions(+)
> > > >
> > > > diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> > > > index 34c342b6f5..625ca35f5c 100644
> > > > --- a/configs/sandbox_defconfig
> > > > +++ b/configs/sandbox_defconfig
> > > > @@ -337,3 +337,6 @@ CONFIG_TEST_FDTDEC=y
> > > >  CONFIG_UNIT_TEST=y
> > > >  CONFIG_UT_TIME=y
> > > >  CONFIG_UT_DM=y
> > > > +CONFIG_CMD_SELECT_FONT=y
> > > > +CONFIG_VIDEO_FONT_8X16=y
> > > > +CONFIG_VIDEO_FONT_SUN12X22=y
> > >
> > > I don't think you can enable this, since sandbox uses
> > > CONSOLE_TRUETYPE. Can we perhaps use sandbox_flattree to run this
> > > test?
> > >
> > > Also, for me the tests crash with signal 8 (I think).
> > >
> > > > diff --git a/test/dm/video.c b/test/dm/video.c
> > > > index 17a33cc7af..30778157d9 100644
> > > > --- a/test/dm/video.c
> > > > +++ b/test/dm/video.c
> > > > @@ -151,6 +151,8 @@ static int dm_test_video_text(struct 
> > > > unit_test_state *uts)

[PATCH v6 1/2] video console: sandbox_defconfig: add 12x22 font

2023-02-23 Thread Dzmitry Sankouski
Add 12x22 font in order to write a test for it.
Run savedefconfig.
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: N/A

 configs/sandbox_defconfig | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 34c342b6f5..a0fbdad20a 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -2,6 +2,7 @@ CONFIG_TEXT_BASE=0
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
+CONFIG_DM_RESET=y
 CONFIG_PRE_CON_BUF_ADDR=0xf
 CONFIG_BOOTSTAGE_STASH_ADDR=0x0
 CONFIG_SYS_LOAD_ADDR=0x0
@@ -100,7 +101,6 @@ CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
 CONFIG_CMD_EFIDEBUG=y
-CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_PAUSE=y
@@ -263,7 +263,6 @@ CONFIG_DM_REBOOT_MODE=y
 CONFIG_DM_REBOOT_MODE_GPIO=y
 CONFIG_DM_REBOOT_MODE_RTC=y
 CONFIG_REMOTEPROC_SANDBOX=y
-CONFIG_DM_RESET=y
 CONFIG_SANDBOX_RESET=y
 CONFIG_RESET_SYSCON=y
 CONFIG_RESET_SCMI=y
@@ -299,10 +298,10 @@ CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_USB_ETHER=y
 CONFIG_USB_ETH_CDC=y
 CONFIG_VIDEO=y
+CONFIG_VIDEO_FONT_SUN12X22=y
 CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_ROTATION=y
 CONFIG_CONSOLE_TRUETYPE=y
-CONFIG_CONSOLE_TRUETYPE_MAX_METRICS=10
 CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_I2C_EDID=y
 CONFIG_VIDEO_SANDBOX_SDL=y
-- 
2.30.2



[PATCH v6 2/2] video console: add 12x22 console simple font test

2023-02-23 Thread Dzmitry Sankouski
Tests fonts wider than a byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v2: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6:
- rebase
- move sandbox defconfig change to separate patch
- run savedefconfig

 test/dm/video.c | 41 +
 1 file changed, 41 insertions(+)

diff --git a/test/dm/video.c b/test/dm/video.c
index 17a33cc7af..30778157d9 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state *uts)
 
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
@@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_video_text_12x22(struct unit_test_state *uts)
+{
+   struct udevice *dev, *con;
+   int i;
+
+#define WHITE  0x
+#define SCROLL_LINES   100
+
+   ut_assertok(select_vidconsole(uts, "vidconsole0"));
+   ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "12x22", 0));
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   vidconsole_putc_xy(con, 0, 0, 'a');
+   ut_asserteq(89, compress_frame_buffer(uts, dev));
+
+   vidconsole_putc_xy(con, 0, 0, ' ');
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   vidconsole_set_row(con, 0, WHITE);
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   return 0;
+}
+DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test handling of special characters in the console */
 static int dm_test_video_chars(struct unit_test_state *uts)
 {
@@ -184,6 +222,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
 
@@ -201,6 +240,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
 
/* reference clear: */
video_clear(con->parent);
@@ -249,6 +289,7 @@ static int check_vidconsole_output(struct unit_test_state 
*uts, int rot,
 
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
/* Check display wrap */
-- 
2.30.2



[PATCH v6 4/9] video console: implement multiple fonts configuration

2023-02-23 Thread Dzmitry Sankouski
This needed for unit testing different fonts.

Configured fonts are placed in an array of fonts.
First font is selected by default upon console probe.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only

 common/splash.c | 17 +++---
 drivers/video/Kconfig   | 15 ++
 drivers/video/console_core.c| 81 +
 drivers/video/console_normal.c  | 32 +++-
 drivers/video/console_rotate.c  | 72 -
 drivers/video/vidconsole_internal.h | 20 ---
 include/video_font.h| 17 +-
 include/video_font_4x6.h| 11 ++--
 include/video_font_8x16.h   |  8 +--
 include/video_font_data.h   | 31 +++
 10 files changed, 207 insertions(+), 97 deletions(-)
 create mode 100644 include/video_font_data.h

diff --git a/common/splash.c b/common/splash.c
index 245ff680eb..1cd9afae2d 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -127,6 +127,7 @@ void splash_get_pos(int *x, int *y)
 #include 
 #include 
 #include 
+#include 
 
 void splash_display_banner(void)
 {
@@ -138,13 +139,15 @@ void splash_display_banner(void)
if (ret)
return;
 
-#ifdef CONFIG_VIDEO_LOGO
-   col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-   row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
-#else
-   col = 0;
-   row = 0;
-#endif
+   if (IS_ENABLED(CONFIG_VIDEO_LOGO)) {
+   struct video_fontdata *fontdata = [0];
+
+   col = BMP_LOGO_WIDTH / fontdata->width + 1;
+   row = BMP_LOGO_HEIGHT / fontdata->height + 1;
+   } else {
+   col = 0;
+   row = 0;
+   }
 
display_options_get_banner(false, buf, sizeof(buf));
vidconsole_position_cursor(dev, col, 1);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 2a76d19cc8..ce97eb4727 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+   bool "4 x 6 font size"
+   help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
+config VIDEO_FONT_8X16
+   bool "8 x 16 font size"
+   default y
+   help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index de004f585c..b82ca6d43c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -9,8 +9,41 @@
 #include 
 #include 
 #include 
+#include 
 #include "vidconsole_internal.h"
 
+/**
+ * console_set_font() - prepare vidconsole for chosen font.
+ *
+ * @devvidconsole device
+ * @fontdata   pointer to font data struct
+ */
+static int console_set_font(struct udevice *dev, struct video_fontdata 
*fontdata)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+   debug("console_simple: setting %s font\n", fontdata->name);
+   debug("width: %d\n", fontdata->width);
+   debug("byte width: %d\n", fontdata->byte_width);
+   debug("height: %d\n", fontdata->height);
+
+   priv->fontdata = fontdata;
+   vc_priv->x_charsize = fontdata->width;
+   vc_priv->y_charsize = fontdata->height;
+   if (vid_priv->rot % 2) {
+   vc_priv->cols = vid_priv->ysize / fontdata->width;
+   vc_priv->rows = vid_priv->xsize / fontdata->height;
+   vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+   } else {
+   vc_priv->cols = vid_priv->xsize / fontdata->width;
+   vc_priv->rows = vid_priv->ysize / fontdata->height;
+   }
+
+   return 0;
+}
+
 int check_bpix_support(int bpix)
 {
if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
@@ -43,7 +76,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 }
 
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
-bool direction)
+struct video_fontdata *fontdata, bool direction)
 {
int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
@@ -61,17 +94,17 @@ int fill_char_vertical

[PATCH v6 1/9] video console: refactoring and optimization

2023-02-23 Thread Dzmitry Sankouski
- move common code to vidconsole_internal.h and console_core.c
- unite probe functions
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: none
Changes for v3: none
Changes for v4:
- move common code to vidconsole_internal.h
- unite probe functions
Changes for v5:
- move common functions to console-core.c file
- remove static keyword from shared functions
Changes for v6: none

 drivers/video/Makefile  |   6 +
 drivers/video/console_core.c| 141 +
 drivers/video/console_normal.c  | 150 --
 drivers/video/console_rotate.c  | 308 
 drivers/video/vidconsole_internal.h |  95 +
 5 files changed, 324 insertions(+), 376 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cdb7d9a54d..cb3f373645 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -9,6 +9,12 @@ 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
+ifdef CONFIG_CONSOLE_NORMAL
+obj-y += console_core.o
+else ifdef CONFIG_CONSOLE_ROTATION
+obj-y += console_core.o
+endif
+obj-$(CONFIG_CONSOLE_ROTATION) += console_core.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_core.c b/drivers/video/console_core.c
new file mode 100644
index 00..9c2e4cb4ea
--- /dev/null
+++ b/drivers/video/console_core.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015 Google, Inc
+ * (C) Copyright 2015
+ * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include "vidconsole_internal.h"
+
+int check_bpix_support(int bpix)
+{
+   if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
+   else if (bpix == VIDEO_BPP16 && IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   else if (bpix == VIDEO_BPP32 && IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   else
+   return -ENOSYS;
+}
+
+inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int 
step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = -vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = vid_priv->line_length;
+   }
+
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   dst = *line;
+   uchar bits = pfont[row];
+
+   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
+   *line += line_step;
+   }
+   return ret;
+}
+
+int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+  bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = vid_priv->line_length;
+   } else {
+   step = pbytes;
+ 

[PATCH v6 6/9] video console: allow font size configuration at runtime

2023-02-23 Thread Dzmitry Sankouski
Allow font size configuration at runtime for console_simple.c
driver. This needed for unit testing different fonts.

Configuring is done by `font` command, also used for font
selection in true type console.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3:
- move 8x16 font patch extracted
- implement multiple fonts patch extracted
- add static modifiers, where needed
- remove list fonts operation
- put fontdata in local var
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only

 cmd/Kconfig |  8 
 cmd/Makefile|  2 +-
 drivers/video/Kconfig   |  1 +
 drivers/video/console_core.c| 21 +
 drivers/video/console_normal.c  |  2 ++
 drivers/video/console_rotate.c  |  6 ++
 drivers/video/vidconsole_internal.h | 12 
 7 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..a3512836c1 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2226,6 +2226,14 @@ config CMD_VIDCONSOLE
  The name 'lcdputs' is a bit of a misnomer, but so named because the
  video device is often an LCD.
 
+config CMD_SELECT_FONT
+   bool "select font size"
+   depends on VIDEO
+   default n
+   help
+ Enabling this will provide 'font' command.
+ Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..2d8bb4fc05 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -78,7 +78,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index ce97eb4727..e1bcc89b30 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -165,6 +165,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
bool "Support a console that uses TrueType fonts"
+   select CMD_SELECT_FONT
help
  TrueTrype fonts can provide outline-drawing capability rather than
  needing to provide a bitmap for each font and size that is needed.
diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index b82ca6d43c..ee340b1528 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -180,3 +180,24 @@ int console_probe(struct udevice *dev)
 {
return console_set_font(dev, [0]);
 }
+
+int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info 
*info)
+{
+   info->name = ([seq])->name;
+
+   return 0;
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint 
size)
+{
+   struct video_fontdata *font;
+
+   for (font = fonts; font->name; font++) {
+   if (!strcmp(name, font->name)) {
+   console_set_font(dev, font);
+   return 0;
+   }
+   };
+   printf("no such font: %s, make sure it's name has x 
format\n", name);
+   return -ENOENT;
+}
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 03e859898c..79eaa53b2d 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -101,6 +101,8 @@ struct vidconsole_ops console_ops = {
.putc_xy= console_putc_xy,
.move_rows  = console_move_rows,
.set_row= console_set_row,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index b924bc3459..f9f96835ee 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -262,18 +262,24 @@ struct vidconsole_ops console_ops_1 = {
.putc_xy= console_putc_xy_1,
.move_rows  = console_move_rows_1,
.set_row= console_set_row_1,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_2 = {
.putc_xy= console_putc_xy_2,
.move_rows  = console_move_rows_2,
.set_row= console_set_row_2,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_3 = {
.putc_xy= console_putc_xy_3,
.move_rows  = console_move_rows_3,
.set_row= console_set_row_3,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_1) = {
diff --git a/

[PATCH v6 3/9] video console: move 8x16 font data in named header

2023-02-23 Thread Dzmitry Sankouski
Consistent font data header names needed to add new
fonts.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v3: N/A
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only

 include/video_font.h | 2 +-
 include/{video_font_data.h => video_font_8x16.h} | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
 rename include/{video_font_data.h => video_font_8x16.h} (99%)

diff --git a/include/video_font.h b/include/video_font.h
index 5e23f70f85..b07c07662c 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -10,7 +10,7 @@
 #ifdef CONFIG_VIDEO_FONT_4X6
 #include 
 #else
-#include 
+#include 
 #endif
 
 #endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_data.h b/include/video_font_8x16.h
similarity index 99%
rename from include/video_font_data.h
rename to include/video_font_8x16.h
index 6e64198d1a..d3d4295032 100644
--- a/include/video_font_data.h
+++ b/include/video_font_8x16.h
@@ -6,8 +6,8 @@
  * This file contains an 8x16 bitmap font for code page 437.
  */
 
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_8X16
+#define _VIDEO_FONT_8X16
 
 #define VIDEO_FONT_CHARS   256
 #define VIDEO_FONT_WIDTH   8
@@ -4623,7 +4623,6 @@ static unsigned char __maybe_unused 
video_fontdata[VIDEO_FONT_SIZE] = {
0x00, /*  */
0x00, /*  */
0x00, /*  */
-
 };
 
 #endif
-- 
2.30.2



[PATCH v6 2/9] video console: add support for fonts wider than 1 byte

2023-02-23 Thread Dzmitry Sankouski
Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Charges for v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring
Charges for v3: none
Charges for v4: N/A
Charges for v5: N/A
Charges for v6: rebase only

 drivers/video/console_core.c| 84 ++---
 drivers/video/console_normal.c  |  2 +-
 drivers/video/console_rotate.c  |  6 +--
 drivers/video/vidconsole_internal.h |  1 +
 4 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 9c2e4cb4ea..de004f585c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -45,7 +45,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, 
int pbytes, int ste
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
 bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
 
ret = check_bpix_support(vid_priv->bpix);
@@ -61,23 +61,36 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
line_step = vid_priv->line_length;
}
 
+   width_remainder = VIDEO_FONT_WIDTH % 8;
for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   uchar bits;
+
+   bitcount = 8;
dst = *line;
-   uchar bits = pfont[row];
-
-   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-   u32 value = (bits & 0x80) ?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
-   bits <<= 1;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH 
- col == 1);
+
+   if (is_last_iteration)
+   bitcount = width_remainder;
+   }
+   bits = pfont[col];
+
+   for (int bit = 0; bit < bitcount; bit++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
}
*line += line_step;
+   pfont += VIDEO_FONT_BYTE_WIDTH;
}
return ret;
 }
@@ -85,9 +98,9 @@ int fill_char_vertically(uchar *pfont, void **line, struct 
video_priv *vid_priv,
 int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
   bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
-   u8 mask = 0x80;
+   u8 mask;
 
ret = check_bpix_support(vid_priv->bpix);
if (ret)
@@ -101,21 +114,32 @@ int fill_char_horizontally(uchar *pfont, void **line, 
struct video_priv *vid_pri
step = pbytes;
line_step = -vid_priv->line_length;
}
-   for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-   dst = *line;
-   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) 
?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
+
+   width_remainder = VIDEO_FONT_WIDTH % 8;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   mask = 0x80;
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FO

[PATCH v6 00/10] vidconsole: refactoring and support for wider fonts

2023-02-23 Thread Dzmitry Sankouski
Version 6 contains entire rebased patch series.
New patch 'move vidconsole_get_font_size() to test.h' added.

Version 5 contain minor changes:
- move common functions to console-core.c file
- remove static keyword from shared functions

In version 4, only first patch sent, because review fixes to this would add
large rebase & patch formatting overhead. When it'll receive reviewed tag,
I'll resent entire rebased series.

Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Dzmitry Sankouski (10):
  video console: refactoring and optimization
  video console: add support for fonts wider than 1 byte
  video console: move 8x16 font data in named header
  video console: implement multiple fonts configuration
  video console: move vidconsole_get_font_size() to test.h
  video console: allow font size configuration at runtime
  video console: add 12x22 Sun font from linux
  video console: add 16x32 Terminus font from linux
  video console: sandbox_defconfig: add 12x22 font
  video console: add 12x22 console simple font test

 cmd/Kconfig |8 +
 cmd/Makefile|2 +-
 cmd/font.c  |5 +-
 common/splash.c |   17 +-
 configs/sandbox_defconfig   |5 +-
 drivers/video/Kconfig   |   30 +
 drivers/video/Makefile  |6 +
 drivers/video/console_core.c|  203 +
 drivers/video/console_normal.c  |  176 +-
 drivers/video/console_rotate.c  |  368 +-
 drivers/video/console_truetype.c|8 +-
 drivers/video/vidconsole_internal.h |  114 +
 include/cmd/test.h  |   19 +
 include/video_console.h |9 -
 include/video_font.h|   31 +-
 include/video_font_4x6.h|   11 +-
 include/video_font_8x16.h   | 4624 
 include/video_font_data.h   | 4644 +---
 include/video_font_sun12x22.h   | 6158 +++
 include/video_font_ter16x32.h   | 2062 +
 test/cmd/font.c |1 +
 test/dm/video.c |   41 +
 22 files changed, 13488 insertions(+), 5054 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h
 create mode 100644 include/cmd/test.h
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h

-- 
2.30.2


[PATCH v5 1/1] video console: refactoring and optimization

2023-02-20 Thread Dzmitry Sankouski
- move common code to vidconsole_internal.h and console_core.c
- unite probe functions
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: none
Changes for v3: none
Changes for v4:
- move common code to vidconsole_internal.h
- unite probe functions
Changes for v5:
- move common functions to console-core.c file
- remove static keyword from shared functions

 drivers/video/Makefile  |   6 +
 drivers/video/console_core.c| 141 +
 drivers/video/console_normal.c  | 150 --
 drivers/video/console_rotate.c  | 308 
 drivers/video/vidconsole_internal.h |  95 +
 5 files changed, 324 insertions(+), 376 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cdb7d9a54d..cb3f373645 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -9,6 +9,12 @@ 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
+ifdef CONFIG_CONSOLE_NORMAL
+obj-y += console_core.o
+else ifdef CONFIG_CONSOLE_ROTATION
+obj-y += console_core.o
+endif
+obj-$(CONFIG_CONSOLE_ROTATION) += console_core.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_core.c b/drivers/video/console_core.c
new file mode 100644
index 00..9c2e4cb4ea
--- /dev/null
+++ b/drivers/video/console_core.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015 Google, Inc
+ * (C) Copyright 2015
+ * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include "vidconsole_internal.h"
+
+int check_bpix_support(int bpix)
+{
+   if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
+   else if (bpix == VIDEO_BPP16 && IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   else if (bpix == VIDEO_BPP32 && IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   else
+   return -ENOSYS;
+}
+
+inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int 
step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = -vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = vid_priv->line_length;
+   }
+
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   dst = *line;
+   uchar bits = pfont[row];
+
+   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
+   u32 value = (bits & 0x80) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   bits <<= 1;
+   }
+   *line += line_step;
+   }
+   return ret;
+}
+
+int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+  bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = -vid_priv->line_length;
+   

[PATCH v5 0/1] vidconsole: refactoring and support for wider fonts

2023-02-20 Thread Dzmitry Sankouski
Version 5 contain minor changes:
- move common functions to console-core.c file
- remove static keyword from shared functions

In version 4, only first patch sent, because review fixes to this would add
large rebase & patch formatting overhead. When it'll receive reviewed tag,
I'll resent entire rebased series.

Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Dzmitry Sankouski (1):
  video console: refactoring and optimization

 drivers/video/Makefile  |   6 +
 drivers/video/console_core.c| 141 +
 drivers/video/console_normal.c  | 150 --
 drivers/video/console_rotate.c  | 308 
 drivers/video/vidconsole_internal.h |  95 +
 5 files changed, 324 insertions(+), 376 deletions(-)
 create mode 100644 drivers/video/console_core.c
 create mode 100644 drivers/video/vidconsole_internal.h

-- 
2.30.2



Re: [PATCH v4 1/1] video console: refactoring and optimization

2023-02-20 Thread Dzmitry Sankouski
сб, 18 февр. 2023 г. в 02:49, Simon Glass :
>
> Hi Dzmitry,
>
> On Fri, 17 Feb 2023 at 08:01, Dzmitry Sankouski  wrote:
> >
> > - move common code to vidconsole_internal.h
> > - unite probe functions
> > - get rid of code duplications in switch across bpp values
> > - extract common pixel fill logic in two functions one per
> > horizontal and vertical filling
> > - rearrange statements in put_xy* methods in unified way
> > - replace types - uint*_t to u*
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> > Changes for v2: none
> > Changes for v3: none
> > Changes for v4:
> > - move common code to vidconsole_internal.h
> > - unite probe functions
> >
> >  drivers/video/console_normal.c  | 150 +++-
> >  drivers/video/console_rotate.c  | 364 
> >  drivers/video/vidconsole_internal.h | 148 +++
> >  3 files changed, 288 insertions(+), 374 deletions(-)
> >  create mode 100644 drivers/video/vidconsole_internal.h
>
> Can you put the actual code from the shared functions in
> vidconsole-uclass.c - that way it won't be compiled in twice into
> those two files.
>
I think vidconsole-uclass.c is a bad place for driver internals.
I'll put shared functions in a separate file.
>
>
(...)


[PATCH v4 1/1] video console: refactoring and optimization

2023-02-17 Thread Dzmitry Sankouski
- move common code to vidconsole_internal.h
- unite probe functions
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: none
Changes for v3: none
Changes for v4:
- move common code to vidconsole_internal.h
- unite probe functions

 drivers/video/console_normal.c  | 150 +++-
 drivers/video/console_rotate.c  | 364 
 drivers/video/vidconsole_internal.h | 148 +++
 3 files changed, 288 insertions(+), 374 deletions(-)
 create mode 100644 drivers/video/vidconsole_internal.h

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 04f022491e..57186bedd8 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -1,10 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2015 Google, Inc
- * (C) Copyright 2001-2015
- * DENX Software Engineering -- w...@denx.de
- * Compulab Ltd - http://compulab.co.il/
+ * (C) Copyright 2015
  * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
  */
 
 #include 
@@ -12,47 +11,28 @@
 #include 
 #include 
 #include /* Get font data, width and height */
+#include "vidconsole_internal.h"
 
-static int console_normal_set_row(struct udevice *dev, uint row, int clr)
+static int console_set_row(struct udevice *dev, uint row, int clr)
 {
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-   void *line, *end;
+   void *line, *dst, *end;
int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
int ret;
int i;
+   int pbytes;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
 
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;
-   }
+   dst = line;
+   pbytes = VNBYTES(vid_priv->bpix);
+   for (i = 0; i < pixels; i++)
+   fill_pixel_and_goto_next(, clr, pbytes, pbytes);
+   end = dst;
+
ret = vidconsole_sync_copy(dev, line, end);
if (ret)
return ret;
@@ -60,8 +40,8 @@ static int console_normal_set_row(struct udevice *dev, uint 
row, int clr)
return 0;
 }
 
-static int console_normal_move_rows(struct udevice *dev, uint rowdst,
-uint rowsrc, uint count)
+static int console_move_rows(struct udevice *dev, uint rowdst,
+uint rowsrc, uint count)
 {
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
void *dst;
@@ -79,70 +59,30 @@ static int console_normal_move_rows(struct udevice *dev, 
uint rowdst,
return 0;
 }
 
-static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
- char ch)
+static int console_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;
+   int pbytes = VNBYTES(vid_priv->bpix);
+   int x, linenum, ret;
+   void *start, *line;
+   uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
 
-   start = vid_priv->fb + y * vid_priv->line_length +
-   VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
+   if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
+   return -EAGAIN;
+   linenum = y;
+   x = VID_TO_PIXEL(x_frac);
+   start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
  

[PATCH v4 0/1] vidconsole: refactoring and support for wider fonts

2023-02-17 Thread Dzmitry Sankouski
In version 4, only first patch sent, because review fixes to this would add
large rebase & patch formatting overhead. When it'll receive reviewed tag,
I'll resent entire rebased series.

Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Dzmitry Sankouski (1):
  video console: refactoring and optimization

 drivers/video/console_normal.c  | 150 +++-
 drivers/video/console_rotate.c  | 364 
 drivers/video/vidconsole_internal.h | 148 +++
 3 files changed, 288 insertions(+), 374 deletions(-)
 create mode 100644 drivers/video/vidconsole_internal.h

-- 
2.30.2



Re: [PATCH v3 9/9] video console: add 12x22 console simple font test

2023-02-17 Thread Dzmitry Sankouski
How does CONSOLE_TRUETYPE interfere with CONFIG_VIDEO_FONT_SUN12X22?


I've got all video tests passed:

make sandbox_defconfig && make -j4 && ./u-boot -T -c 'ut dm'
(...)
Test: dm_test_video_ansi: video.c
Test: dm_test_video_base: video.c
Test: dm_test_video_base: video.c (flat tree)
Test: dm_test_video_bmp: video.c
Test: dm_test_video_bmp16: video.c
Test: dm_test_video_bmp24: video.c
Test: dm_test_video_bmp24_32: video.c
Test: dm_test_video_bmp32: video.c
Test: dm_test_video_bmp8: video.c
Test: dm_test_video_bmp_comp: video.c
Test: dm_test_video_chars: video.c
Test: dm_test_video_comp_bmp32: video.c
Test: dm_test_video_comp_bmp8: video.c
Test: dm_test_video_context: video.c
Test: dm_test_video_rotation1: video.c
Test: dm_test_video_rotation2: video.c
Test: dm_test_video_rotation3: video.c
Test: dm_test_video_text: video.c
Test: dm_test_video_text_12x22: video.c
Test: dm_test_video_truetype: video.c
Test: dm_test_video_truetype_bs: video.c
Test: dm_test_video_truetype_scroll: video.c
Test: dm_test_virtio_all_ops: virtio_device.c
Test: dm_test_virtio_all_ops: virtio_device.c (flat tree)
Test: dm_test_virtio_base: virtio_device.c
(...)

чт, 16 февр. 2023 г. в 02:50, Simon Glass :
>
> Hi Dzmitry,
>
> On Wed, 15 Feb 2023 at 04:43, Dzmitry Sankouski  wrote:
> >
> > Tests fonts wider than a byte.
> >
> > Signed-off-by: Dzmitry Sankouski 
> > Reviewed-by: Simon Glass 
>
> I found a problem with this
>
> > ---
> > Changes for v2: N/A
> > Changes for v2: none
> >
> >  configs/sandbox_defconfig |  3 +++
> >  test/dm/video.c   | 41 +++
> >  2 files changed, 44 insertions(+)
> >
> > diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> > index 34c342b6f5..625ca35f5c 100644
> > --- a/configs/sandbox_defconfig
> > +++ b/configs/sandbox_defconfig
> > @@ -337,3 +337,6 @@ CONFIG_TEST_FDTDEC=y
> >  CONFIG_UNIT_TEST=y
> >  CONFIG_UT_TIME=y
> >  CONFIG_UT_DM=y
> > +CONFIG_CMD_SELECT_FONT=y
> > +CONFIG_VIDEO_FONT_8X16=y
> > +CONFIG_VIDEO_FONT_SUN12X22=y
>
> I don't think you can enable this, since sandbox uses
> CONSOLE_TRUETYPE. Can we perhaps use sandbox_flattree to run this
> test?
>
> Also, for me the tests crash with signal 8 (I think).
>
> > diff --git a/test/dm/video.c b/test/dm/video.c
> > index 17a33cc7af..30778157d9 100644
> > --- a/test/dm/video.c
> > +++ b/test/dm/video.c
> > @@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state 
> > *uts)
> >
> > ut_assertok(select_vidconsole(uts, "vidconsole0"));
> > ut_assertok(video_get_nologo(uts, ));
> > +   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
> > +   ut_assertok(vidconsole_select_font(con, "8x16", 0));
> > ut_asserteq(46, compress_frame_buffer(uts, dev));
> >
> > ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
> > @@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state 
> > *uts)
> >  }
> >  DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
> >
> > +static int dm_test_video_text_12x22(struct unit_test_state *uts)
> > +{
> > +   struct udevice *dev, *con;
> > +   int i;
> > +
> > +#define WHITE  0x
> > +#define SCROLL_LINES   100
> > +
> > +   ut_assertok(select_vidconsole(uts, "vidconsole0"));
> > +   ut_assertok(video_get_nologo(uts, ));
> > +   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
> > +   ut_assertok(vidconsole_select_font(con, "12x22", 0));
> > +   ut_asserteq(46, compress_frame_buffer(uts, dev));
> > +
> > +   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
> > +   vidconsole_putc_xy(con, 0, 0, 'a');
> > +   ut_asserteq(89, compress_frame_buffer(uts, dev));
> > +
> > +   vidconsole_putc_xy(con, 0, 0, ' ');
> > +   ut_asserteq(46, compress_frame_buffer(uts, dev));
> > +
> > +   for (i = 0; i < 20; i++)
> > +   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
> > +   ut_asserteq(363, compress_frame_buffer(uts, dev));
> > +
> > +   vidconsole_set_row(con, 0, WHITE);
> > +   ut_asserteq(46, compress_frame_buffer(uts, dev));
> > +
> > +   for (i = 0; i < 20; i++)
> > +   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
> > +   ut_asserteq(363, compress_frame_buffer(uts, dev));
> > +
> > +   return 0;
> > +}
> > +DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_

[PATCH v3 8/9] video console: add 16x32 Terminus font from linux

2023-02-15 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2:
- edit for runtime configuration
Changes for v3: none

 drivers/video/Kconfig |7 +
 include/video_font.h  |6 +
 include/video_font_ter16x32.h | 2062 +
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index acce7c21e8..70ae66c53c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
  Provides character bitmap data in header file.
  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
 
+config VIDEO_FONT_16X32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/include/video_font.h b/include/video_font.h
index 03622adc7a..d4dd2b5eed 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include 
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include 
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_4X6)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+   FONT_ENTRY(16, 32, 16x32),
 #endif
{/* list terminator */}
 };
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..bcf3d4b123
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2062 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_TER_16X32_
+#define _VIDEO_FONT_TER_16X32_
+
+#include 
+
+static unsigned char video_fontdata_16x32[VIDEO_FONT_SIZE(256, 16, 32)] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0,
+   0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0xff, 0xfe,
+   0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xe0,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0,
+   0x07, 0xc0, 0x03, 0x80, 0x3b, 0xb8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3b, 0xb8, 0x03, 0x80, 0x03, 0x80,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x

[PATCH v3 9/9] video console: add 12x22 console simple font test

2023-02-15 Thread Dzmitry Sankouski
Tests fonts wider than a byte.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2: N/A
Changes for v2: none

 configs/sandbox_defconfig |  3 +++
 test/dm/video.c   | 41 +++
 2 files changed, 44 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 34c342b6f5..625ca35f5c 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -337,3 +337,6 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_CMD_SELECT_FONT=y
+CONFIG_VIDEO_FONT_8X16=y
+CONFIG_VIDEO_FONT_SUN12X22=y
diff --git a/test/dm/video.c b/test/dm/video.c
index 17a33cc7af..30778157d9 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state *uts)
 
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
@@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_video_text_12x22(struct unit_test_state *uts)
+{
+   struct udevice *dev, *con;
+   int i;
+
+#define WHITE  0x
+#define SCROLL_LINES   100
+
+   ut_assertok(select_vidconsole(uts, "vidconsole0"));
+   ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "12x22", 0));
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   vidconsole_putc_xy(con, 0, 0, 'a');
+   ut_asserteq(89, compress_frame_buffer(uts, dev));
+
+   vidconsole_putc_xy(con, 0, 0, ' ');
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   vidconsole_set_row(con, 0, WHITE);
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   return 0;
+}
+DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test handling of special characters in the console */
 static int dm_test_video_chars(struct unit_test_state *uts)
 {
@@ -184,6 +222,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
 
@@ -201,6 +240,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
 
/* reference clear: */
video_clear(con->parent);
@@ -249,6 +289,7 @@ static int check_vidconsole_output(struct unit_test_state 
*uts, int rot,
 
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
/* Check display wrap */
-- 
2.30.2



[PATCH v3 5/9] video console: implement multiple fonts configuration

2023-02-15 Thread Dzmitry Sankouski
This needed for unit testing different fonts.

Configured fonts are placed in an array of fonts.
First font is selected by default upon console probe.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A

 common/splash.c|  17 ++-
 drivers/video/Kconfig  |  15 +++
 drivers/video/console_simple.c | 232 -
 include/video_font.h   |  17 ++-
 include/video_font_4x6.h   |  11 +-
 include/video_font_8x16.h  |   8 +-
 include/video_font_data.h  |  31 +
 7 files changed, 216 insertions(+), 115 deletions(-)
 create mode 100644 include/video_font_data.h

diff --git a/common/splash.c b/common/splash.c
index 245ff680eb..1cd9afae2d 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -127,6 +127,7 @@ void splash_get_pos(int *x, int *y)
 #include 
 #include 
 #include 
+#include 
 
 void splash_display_banner(void)
 {
@@ -138,13 +139,15 @@ void splash_display_banner(void)
if (ret)
return;
 
-#ifdef CONFIG_VIDEO_LOGO
-   col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
-   row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
-#else
-   col = 0;
-   row = 0;
-#endif
+   if (IS_ENABLED(CONFIG_VIDEO_LOGO)) {
+   struct video_fontdata *fontdata = [0];
+
+   col = BMP_LOGO_WIDTH / fontdata->width + 1;
+   row = BMP_LOGO_HEIGHT / fontdata->height + 1;
+   } else {
+   col = 0;
+   row = 0;
+   }
 
display_options_get_banner(false, buf, sizeof(buf));
vidconsole_position_cursor(dev, col, 1);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f2e930ab68..47428ecb6c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -16,6 +16,21 @@ config VIDEO
 
 if VIDEO
 
+config VIDEO_FONT_4X6
+   bool "4 x 6 font size"
+   help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
+config VIDEO_FONT_8X16
+   bool "8 x 16 font size"
+   default y
+   help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index cdc26cac30..402d67f85f 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -12,12 +12,50 @@
 #include 
 #include /* Get font data, width and height */
 
-#define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 
> 0))
-#define VIDEO_FONT_CHAR_PIXEL_BYTES(VIDEO_FONT_HEIGHT * 
VIDEO_FONT_BYTE_WIDTH)
-
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
 
+/**
+ * struct console_simple_priv - Private data for this driver
+ *
+ * @video_fontdata font graphical representation data
+ */
+struct console_simple_priv {
+   struct video_fontdata *fontdata;
+};
+
+/**
+ * console_set_font() - prepare vidconsole for chosen font.
+ *
+ * @devvidconsole device
+ * @fontdata   pointer to font data struct
+ */
+static int console_set_font(struct udevice *dev, struct video_fontdata 
*fontdata)
+{
+   struct console_simple_priv *priv = dev_get_priv(dev);
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+   debug("console_simple: setting %s font\n", fontdata->name);
+   debug("width: %d\n", fontdata->width);
+   debug("byte width: %d\n", fontdata->byte_width);
+   debug("height: %d\n", fontdata->height);
+
+   priv->fontdata = fontdata;
+   vc_priv->x_charsize = fontdata->width;
+   vc_priv->y_charsize = fontdata->height;
+   if (vid_priv->rot % 2) {
+   vc_priv->cols = vid_priv->ysize / fontdata->width;
+   vc_priv->rows = vid_priv->xsize / fontdata->height;
+   vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+   } else {
+   vc_priv->cols = vid_priv->xsize / fontdata->width;
+   vc_priv->rows = vid_priv->ysize / fontdata->height;
+   }
+
+   return 0;
+}
+
 /**
  * Checks if bits per pixel supported.
  *
@@ -78,6 +116,7 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 
value, int pbytes,
  * @param pfonta pointer to character font data.
  * @param line a pointer to pointer to framebuffer. It's a point for 
upper left char corner
  * @param vid_priv driver private data.
+ * @fontdata   font gr

[PATCH v3 6/9] video console: allow font size configuration at runtime

2023-02-15 Thread Dzmitry Sankouski
Allow font size configuration at runtime for console_simple.c
driver. This needed for unit testing different fonts.

Configuring is done by `font` command, also used for font
selection in true type console.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3:
- move 8x16 font patch extracted
- implement multiple fonts patch extracted
- add static modifiers, where needed
- remove list fonts operation
- put fontdata in local var

 cmd/Kconfig|  8 
 cmd/Makefile   |  2 +-
 drivers/video/Kconfig  |  1 +
 drivers/video/console_simple.c | 30 ++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..f368ee7e9b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2226,6 +2226,14 @@ config CMD_VIDCONSOLE
  The name 'lcdputs' is a bit of a misnomer, but so named because the
  video device is often an LCD.
 
+config CMD_SELECT_FONT
+bool "select font size"
+   depends on VIDEO
+   default n
+   help
+ Enabling this will provide 'font' command.
+ Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..2d8bb4fc05 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -78,7 +78,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
 obj-$(CONFIG_CMD_FAT) += fat.o
 obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
-obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
+obj-$(CONFIG_CMD_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 47428ecb6c..419c53418d 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -165,6 +165,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
bool "Support a console that uses TrueType fonts"
+   select CMD_SELECT_FONT
help
  TrueTrype fonts can provide outline-drawing capability rather than
  needing to provide a bitmap for each font and size that is needed.
diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index 402d67f85f..2b39d724f4 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -56,6 +56,28 @@ static int console_set_font(struct udevice *dev, struct 
video_fontdata *fontdata
return 0;
 }
 
+static int console_simple_get_font(struct udevice *dev, int seq, struct 
vidfont_info *info)
+{
+   info->name = ([seq])->name;
+
+   return 0;
+}
+
+static int console_simple_select_font(struct udevice *dev, const char *name, 
uint size)
+{
+   console_set_font(dev, [1]);
+   struct video_fontdata *font;
+
+   for (font = fonts; font->name; font++) {
+   if (!strcmp(name, font->name)) {
+   console_set_font(dev, font);
+   return 0;
+   }
+   };
+   printf("no such font: %s, make sure it's name has x 
format\n", name);
+   return -ENOENT;
+}
+
 /**
  * Checks if bits per pixel supported.
  *
@@ -352,6 +374,8 @@ struct vidconsole_ops console_ops = {
.putc_xy= console_putc_xy,
.move_rows  = console_move_rows,
.set_row= console_set_row,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
@@ -612,18 +636,24 @@ struct vidconsole_ops console_ops_1 = {
.putc_xy= console_putc_xy_1,
.move_rows  = console_move_rows_1,
.set_row= console_set_row_1,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_2 = {
.putc_xy= console_putc_xy_2,
.move_rows  = console_move_rows_2,
.set_row= console_set_row_2,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_3 = {
.putc_xy= console_putc_xy_3,
.move_rows  = console_move_rows_3,
.set_row= console_set_row_3,
+   .get_font   = console_simple_get_font,
+   .select_font= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_1) = {
-- 
2.30.2



[PATCH v3 4/9] video console: move 8x16 font data in named header

2023-02-15 Thread Dzmitry Sankouski
Consistent font data header names needed to add new
fonts.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A

 include/video_font.h | 2 +-
 include/{video_font_data.h => video_font_8x16.h} | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)
 rename include/{video_font_data.h => video_font_8x16.h} (99%)

diff --git a/include/video_font.h b/include/video_font.h
index 5e23f70f85..b07c07662c 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -10,7 +10,7 @@
 #ifdef CONFIG_VIDEO_FONT_4X6
 #include 
 #else
-#include 
+#include 
 #endif
 
 #endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_data.h b/include/video_font_8x16.h
similarity index 99%
rename from include/video_font_data.h
rename to include/video_font_8x16.h
index 6e64198d1a..d3d4295032 100644
--- a/include/video_font_data.h
+++ b/include/video_font_8x16.h
@@ -6,8 +6,8 @@
  * This file contains an 8x16 bitmap font for code page 437.
  */
 
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_8X16
+#define _VIDEO_FONT_8X16
 
 #define VIDEO_FONT_CHARS   256
 #define VIDEO_FONT_WIDTH   8
@@ -4623,7 +4623,6 @@ static unsigned char __maybe_unused 
video_fontdata[VIDEO_FONT_SIZE] = {
0x00, /*  */
0x00, /*  */
0x00, /*  */
-
 };
 
 #endif
-- 
2.30.2



[PATCH v3 2/9] video console: refactoring and optimization

2023-02-15 Thread Dzmitry Sankouski
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- move width and pixel data size macros to console_simple.c
- performance: move if statement out of pixel fill loops
- document new functions
- remove console_probe_2 function
- make fill_pixel_and_goto_next void
- fix video unit tests failures
Changes for v3: none

 drivers/video/console_simple.c | 598 ++---
 1 file changed, 258 insertions(+), 340 deletions(-)

diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index a4b3cfe3d8..1eb47be449 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2015 Google, Inc
  * (C) Copyright 2015
  * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
  */
 
 #include 
@@ -11,46 +12,209 @@
 #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;
+#define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 
> 0))
 
-   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;
+#define FLIPPED_DIRECTION 1
+#define NORMAL_DIRECTION 0
 
-   for (i = 0; i < pixels; i++)
-   *dst++ = clr;
-   end = dst;
-   break;
-   }
+/**
+ * Checks if bits per pixel supported.
+ *
+ * @param bpix framebuffer bits per pixel.
+ *
+ * @returns 0, if supported, or else -ENOSYS.
+ */
+static int check_bpix_support(int bpix)
+{
+   switch (bpix) {
+   case VIDEO_BPP8:
+   if (IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
case VIDEO_BPP16:
-   if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-   uint16_t *dst = line;
+   if (IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   case VIDEO_BPP32:
+   if (IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   default:
+   return -ENOSYS;
+   }
+}
+
+/**
+ * Fill 1 pixel in framebuffer, and go to next one.
+ *
+ * @param dstp a pointer to pointer to framebuffer.
+ * @param valuevalue to write to framebuffer.
+ * @param pbytes   framebuffer bytes per pixel.
+ * @param step framebuffer pointer increment. Usually is equal to 
pbytes,
+ * and may be negative to control filling direction.
+ */
+static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int 
pbytes, int step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
+/**
+ * Fills 1 character in framebuffer horizontally.
+ * Horizontally means we're filling char font data columns across the lines.
+ *
+ * @param pfonta pointer to character font data.
+ * @param line a pointer to pointer to framebuffer. It's a point for 
upper left char corner
+ * @param vid_priv driver private data.
+ * @param directioncontrols character orientation. Can be normal or 
flipped.
+ * When normal:   When flipped:
+ *|---|
+ *|   *|   line stepping  |
+ *|^  * * * * *|   |  |
+ *||* *|   v   * *|
+ *||   |   * * * * *  |
+ *|  line stepping |   *  |
+ *||  |
+ *|  stepping ->   |<- stepping   |
+ *|---!!we're starting from upper left char corner|
+ *|---|
+ *
+ * @returns 0, if success, or else error code.
+ */
+static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+ bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = ch

[PATCH v3 3/9] video console: add support for fonts wider than 1 byte

2023-02-15 Thread Dzmitry Sankouski
Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski 
---
Charges for v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring
Charges for v3: none

 drivers/video/console_simple.c | 93 +-
 1 file changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index 1eb47be449..cdc26cac30 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -13,6 +13,7 @@
 #include /* Get font data, width and height */
 
 #define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 
> 0))
+#define VIDEO_FONT_CHAR_PIXEL_BYTES(VIDEO_FONT_HEIGHT * 
VIDEO_FONT_BYTE_WIDTH)
 
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
@@ -95,9 +96,9 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 
value, int pbytes,
 static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
  bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
-   u8 mask = 0x80;
+   u8 mask;
 
ret = check_bpix_support(vid_priv->bpix);
if (ret)
@@ -111,21 +112,32 @@ static int fill_char_horizontally(uchar *pfont, void 
**line, struct video_priv *
step = pbytes;
line_step = -vid_priv->line_length;
}
-   for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-   dst = *line;
-   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) 
?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
+
+   width_remainder = VIDEO_FONT_WIDTH % 8;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   mask = 0x80;
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col 
== 1);
+
+   if (is_last_iteration)
+   bitcount = width_remainder;
+   }
+   for (int bit = 0; bit < bitcount; bit++) {
+   dst = *line;
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] 
& mask) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   }
+   *line += line_step;
+   mask >>= 1;
}
-   *line += line_step;
-   mask >>= 1;
}
return ret;
 }
@@ -158,7 +170,7 @@ static int fill_char_horizontally(uchar *pfont, void 
**line, struct video_priv *
 static int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
 
ret = check_bpix_support(vid_priv->bpix);
@@ -174,23 +186,36 @@ static int fill_char_vertically(uchar *pfont, void 
**line, struct video_priv *vi
line_step = vid_priv->line_length;
}
 
+   width_remainder = VIDEO_FONT_WIDTH % 8;
for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   uchar bits;
+
+   bitcount = 8;
dst = *line;
-   uchar bits = pfont[row];
-
-   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-   u32 value = (bits & 0x80) ?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-

[PATCH v3 1/9] video console: unite normal and rotated files

2023-02-15 Thread Dzmitry Sankouski
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
Changes for v3: 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 2a76d19cc8..f2e930ab68 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -127,17 +127,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 cdb7d9a54d..0989c526be 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..00
--- 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 -- w...@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->

[PATCH v3 0/9] vidconsole: refactoring and support for wider fonts

2023-02-15 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 2:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

In version 3,
'video console: add select font logic to vidconsole uclass driver'
patch was removed in favor of already merged patch
'video: Add font functions to the vidconsole API'

Dzmitry Sankouski (9):
  video console: unite normal and rotated files
  video console: refactoring and optimization
  video console: add support for fonts wider than 1 byte
  video console: move 8x16 font data in named header
  video console: implement multiple fonts configuration
  video console: allow font size configuration at runtime
  video console: add 12x22 Sun font from linux
  video console: add 16x32 Terminus font from linux
  video console: add 12x22 console simple font test

 cmd/Kconfig|8 +
 cmd/Makefile   |2 +-
 common/splash.c|   17 +-
 configs/sandbox_defconfig  |3 +
 drivers/video/Kconfig  |   38 +-
 drivers/video/Makefile |3 +-
 drivers/video/console_normal.c |  178 -
 drivers/video/console_rotate.c |  497 ---
 drivers/video/console_simple.c |  682 
 include/video_font.h   |   31 +-
 include/video_font_4x6.h   |   11 +-
 include/video_font_8x16.h  | 4624 
 include/video_font_data.h  | 4644 +---
 include/video_font_sun12x22.h  | 6158 
 include/video_font_ter16x32.h  | 2062 +++
 test/dm/video.c|   41 +
 16 files changed, 13679 insertions(+), 5320 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 delete mode 100644 drivers/video/console_rotate.c
 create mode 100644 drivers/video/console_simple.c
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h

-- 
2.30.2



Re: [PATCH v2 5/8] video console: allow font size configuration at runtime

2023-02-15 Thread Dzmitry Sankouski
вт, 14 февр. 2023 г. в 23:13, Heinrich Schuchardt :
>
>
>
> Am 14. Februar 2023 20:48:53 MEZ schrieb Simon Glass :
> >Hi Dzmitry,
> >
> >On Mon, 13 Feb 2023 at 09:57, Dzmitry Sankouski  wrote:
> >>
(...)
> >>  drivers/video/Kconfig  |   16 +
> >>  drivers/video/console_simple.c |  178 +-
> >>  include/video_font.h   |   19 +-
> >>  include/video_font_4x6.h   |   11 +-
> >>  include/video_font_8x16.h  | 4624 +++
> >>  include/video_font_data.h  | 4644
>
> Shouldn't we have a font that is somehow legible on a 4k display, e.g. 16x32?
>
> Best regards
>
> Heinrich
>
>

There're new fonts in this patch series

>  +---
> >>  9 files changed, 4802 insertions(+), 4707 deletions(-)
> >>  create mode 100644 include/video_font_8x16.h
> >>
(...)


Re: [PATCH v2 0/8] vidconsole: refactoring and support for wider fonts

2023-02-14 Thread Dzmitry Sankouski
Hi, I'll rebase it

вт, 14 февр. 2023 г. в 16:14, Simon Glass :
>
> Hi Dzmitry,
>
> On Mon, 13 Feb 2023 at 10:03, Dzmitry Sankouski  wrote:
> >
> > Modern mobile phones typically have high pixel density.
> > Bootmenu is hardly readable on those with 8x16 font.
> >
> > This patch series aims to add wider fonts for devices with high ppi.
> >
> > Add 16x32, 12x22 fonts from linux, and allow font size configuration.
> >
> > There was significant changes in version 3:
> > - fix video tests failures
> > - add runtime font size configuration
> > - add test for 12x22 font
> >
> > Dzmitry Sankouski (8):
> >   video console: unite normal and rotated files
> >   video console: refactoring and optimization
> >   video console: add support for fonts wider than 1 byte
> >   video console: add select font logic to vidconsole uclass driver
> >   video console: allow font size configuration at runtime
> >   video console: add 12x22 Sun font from linux
> >   video console: add 16x32 Terminus font from linux
> >   video console: add 12x22 console simple font test
> >
> >  cmd/Kconfig   |8 +
> >  cmd/Makefile  |2 +-
> >  cmd/font.c|7 +-
> >  common/splash.c   |7 +-
> >  configs/qemu-x86_defconfig|1 +
> >  configs/sandbox_defconfig |3 +
> >  drivers/video/Kconfig |   38 +-
> >  drivers/video/Makefile|3 +-
> >  drivers/video/console_normal.c|  178 -
> >  drivers/video/console_rotate.c|  497 ---
> >  drivers/video/console_simple.c|  638 +++
> >  drivers/video/console_truetype.c  |6 +-
> >  drivers/video/vidconsole-uclass.c |   22 +
> >  include/video.h   |1 +
> >  include/video_console.h   |   18 +-
> >  include/video_font.h  |   31 +-
> >  include/video_font_4x6.h  |   11 +-
> >  include/video_font_8x16.h | 4624 ++
> >  include/video_font_data.h | 4644 +-
> >  include/video_font_sun12x22.h | 6158 +
> >  include/video_font_ter16x32.h | 2062 ++
> >  test/dm/video.c   |   41 +
> >  22 files changed, 13681 insertions(+), 5319 deletions(-)
> >  delete mode 100644 drivers/video/console_normal.c
> >  delete mode 100644 drivers/video/console_rotate.c
> >  create mode 100644 drivers/video/console_simple.c
> >  create mode 100644 include/video_font_8x16.h
> >  create mode 100644 include/video_font_sun12x22.h
> >  create mode 100644 include/video_font_ter16x32.h
> >
> > --
> > 2.30.2
> >
>
> I am unable to apply these. Can you please check that they are against
> -master or -next ?
>
> Thanks,
> Simon


[PATCH v2 7/8] video console: add 16x32 Terminus font from linux

2023-02-13 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- edit for runtime configuration

 drivers/video/Kconfig |7 +
 include/video_font.h  |6 +
 include/video_font_ter16x32.h | 2062 +
 3 files changed, 2075 insertions(+)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 2023572aa2..4d42c3fc56 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -38,6 +38,13 @@ config VIDEO_FONT_SUN12X22
  Provides character bitmap data in header file.
  When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
 
+config VIDEO_FONT_16X32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT 
too.
+
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/include/video_font.h b/include/video_font.h
index 03622adc7a..d4dd2b5eed 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -18,6 +18,9 @@
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
 #include 
 #endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+#include 
+#endif
 
 static struct video_fontdata __maybe_unused fonts[] = {
 #if defined(CONFIG_VIDEO_FONT_4X6)
@@ -28,6 +31,9 @@ static struct video_fontdata __maybe_unused fonts[] = {
 #endif
 #if defined(CONFIG_VIDEO_FONT_SUN12X22)
FONT_ENTRY(12, 22, 12x22),
+#endif
+#if defined(CONFIG_VIDEO_FONT_16X32)
+   FONT_ENTRY(16, 32, 16x32),
 #endif
{/* list terminator */}
 };
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..bcf3d4b123
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2062 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_TER_16X32_
+#define _VIDEO_FONT_TER_16X32_
+
+#include 
+
+static unsigned char video_fontdata_16x32[VIDEO_FONT_SIZE(256, 16, 32)] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 3 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0,
+   0x1f, 0xf0, 0x3f, 0xf8, 0x7f, 0xfc, 0xff, 0xfe,
+   0xff, 0xfe, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 4 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xe0,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0, 0x0f, 0xe0,
+   0x07, 0xc0, 0x03, 0x80, 0x3b, 0xb8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3b, 0xb8, 0x03, 0x80, 0x03, 0x80,
+   0x0f, 0xe0, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 *

Re: [PATCH 2/5] video console: refactoring and optimization

2023-02-13 Thread Dzmitry Sankouski
For version 3 patches:

Summary of 8 commits for 1232 boards (4 threads, 1 job per thread)
01: video console: unite normal and rotated files
02: video console: refactoring and optimization
   sandbox: (for 1/7 boards) all -64.0 text -64.0
03: video console: add support for fonts wider than 1 byte
04: video console: add select font logic to vidconsole uclass driver
   sandbox: (for 1/7 boards) all +288.0 data +32.0 text +256.0
05: video console: allow font size configuration at runtime
   sandbox: (for 1/7 boards) all +1208.0 data +64.0 rodata +96.0 text +1048.0
06: video console: add 12x22 Sun font from linux
07: video console: add 16x32 Terminus font from linux
08: video console: add 12x22 console simple font test
   sandbox: (for 1/7 boards) all +13152.0 data +11336.0 rodata +256.0
text +1560.0
(no errors to report)

ср, 4 янв. 2023 г. в 23:02, Simon Glass :

>
> Hi Dzmitry,
>
> On Wed, 4 Jan 2023 at 04:17, Dzmitry Sankouski  wrote:
> >
> > Regarding code-size there's a gain with CONFIG_CONSOLE_ROTATION
> > enabled, and penalty with disabled:
> >
> > New:
> > CONFIG_VIDEO_CONSOLE=y
> > CONFIG_CONSOLE_ROTATION=y
> > dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_simple.o
> > 108208  drivers/video/console_simple.o
> >
> > CONFIG_VIDEO_CONSOLE=y
> > # CONFIG_CONSOLE_ROTATION is not set
> > dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_simple.o
> > 53848   drivers/video/console_simple.o
> >
> > Old:
> > dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_normal.o
> > 44728   drivers/video/console_normal.o
> > dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_rotate.o
> > 85424   drivers/video/console_rotate.o
> >
> > In theory, there should be a small performance penalty for the `if
> > (direction)` statement -
> > for every row, and for each pixel. For an 8x16 font, it'll be 144 if 
> > statements.
> >
> > I'll comment on functions in the next patch versions.
>
> To check this, use:
>
> buildman -b  
>
> to build each commit, then
>
> buildman -b   -sS
>
> You can add -B for function bloat and --step 0 to diff just the first
> and last commits.
>
>
> - Simon
>
> >
> > пт, 30 дек. 2022 г. в 01:41, Simon Glass :
> > >
> > > Hi Dzmitry,
> > >
> > > On Mon, 26 Dec 2022 at 13:50, Dzmitry Sankouski  
> > > wrote:
> > > >
> > > > - get rid of code duplications in switch across bpp values
> > > > - extract common pixel fill logic in two functions one per
> > > > horizontal and vertical filling
> > > > - rearrange statements in put_xy* methods in unified way
> > > > - replace types - uint*_t to u*
> > > >
> > > > Signed-off-by: Dzmitry Sankouski 
> > > > ---
> > > >  drivers/video/console_simple.c | 508 -
> > > >  1 file changed, 184 insertions(+), 324 deletions(-)
> > >
> > > This looks like a nice tidy up.
> > >
> > > Is there a code-size or performance penalty with this? E.g. with
> > > CONFIG_CONSOLE_ROTATION disabled
> > >
> > > Please can you comment the functions property so we know what they do?
> > >
> > > Regards,
> > > Simon


[PATCH v2 8/8] video console: add 12x22 console simple font test

2023-02-13 Thread Dzmitry Sankouski
Tests fonts wider than a byte.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A

 configs/sandbox_defconfig |  3 +++
 test/dm/video.c   | 41 +++
 2 files changed, 44 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index de799b5cea..0d501c8f15 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -335,3 +335,6 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_CMD_SELECT_FONT=y
+CONFIG_VIDEO_FONT_8X16=y
+CONFIG_VIDEO_FONT_SUN12X22=y
diff --git a/test/dm/video.c b/test/dm/video.c
index 17a33cc7af..30778157d9 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -151,6 +151,8 @@ static int dm_test_video_text(struct unit_test_state *uts)
 
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
@@ -175,6 +177,42 @@ static int dm_test_video_text(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_text, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_video_text_12x22(struct unit_test_state *uts)
+{
+   struct udevice *dev, *con;
+   int i;
+
+#define WHITE  0x
+#define SCROLL_LINES   100
+
+   ut_assertok(select_vidconsole(uts, "vidconsole0"));
+   ut_assertok(video_get_nologo(uts, ));
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "12x22", 0));
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   vidconsole_putc_xy(con, 0, 0, 'a');
+   ut_asserteq(89, compress_frame_buffer(uts, dev));
+
+   vidconsole_putc_xy(con, 0, 0, ' ');
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   vidconsole_set_row(con, 0, WHITE);
+   ut_asserteq(46, compress_frame_buffer(uts, dev));
+
+   for (i = 0; i < 20; i++)
+   vidconsole_putc_xy(con, VID_TO_POS(i * 8), 0, ' ' + i);
+   ut_asserteq(363, compress_frame_buffer(uts, dev));
+
+   return 0;
+}
+DM_TEST(dm_test_video_text_12x22, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test handling of special characters in the console */
 static int dm_test_video_chars(struct unit_test_state *uts)
 {
@@ -184,6 +222,7 @@ static int dm_test_video_chars(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
vidconsole_put_string(con, test_string);
ut_asserteq(466, compress_frame_buffer(uts, dev));
 
@@ -201,6 +240,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
ut_assertok(select_vidconsole(uts, "vidconsole0"));
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
 
/* reference clear: */
video_clear(con->parent);
@@ -249,6 +289,7 @@ static int check_vidconsole_output(struct unit_test_state 
*uts, int rot,
 
ut_assertok(video_get_nologo(uts, ));
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, ));
+   ut_assertok(vidconsole_select_font(con, "8x16", 0));
ut_asserteq(46, compress_frame_buffer(uts, dev));
 
/* Check display wrap */
-- 
2.30.2



[PATCH v2 2/8] video console: refactoring and optimization

2023-02-13 Thread Dzmitry Sankouski
- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- move width and pixel data size macros to console_simple.c
- performance: move if statement out of pixel fill loops
- document new functions
- remove console_probe_2 function
- make fill_pixel_and_goto_next void
- fix video unit tests failures

 drivers/video/console_simple.c | 598 ++---
 1 file changed, 258 insertions(+), 340 deletions(-)

diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index a4b3cfe3d8..1eb47be449 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2015 Google, Inc
  * (C) Copyright 2015
  * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski 
  */
 
 #include 
@@ -11,46 +12,209 @@
 #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;
+#define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 
> 0))
 
-   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;
+#define FLIPPED_DIRECTION 1
+#define NORMAL_DIRECTION 0
 
-   for (i = 0; i < pixels; i++)
-   *dst++ = clr;
-   end = dst;
-   break;
-   }
+/**
+ * Checks if bits per pixel supported.
+ *
+ * @param bpix framebuffer bits per pixel.
+ *
+ * @returns 0, if supported, or else -ENOSYS.
+ */
+static int check_bpix_support(int bpix)
+{
+   switch (bpix) {
+   case VIDEO_BPP8:
+   if (IS_ENABLED(CONFIG_VIDEO_BPP8))
+   return 0;
case VIDEO_BPP16:
-   if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-   uint16_t *dst = line;
+   if (IS_ENABLED(CONFIG_VIDEO_BPP16))
+   return 0;
+   case VIDEO_BPP32:
+   if (IS_ENABLED(CONFIG_VIDEO_BPP32))
+   return 0;
+   default:
+   return -ENOSYS;
+   }
+}
+
+/**
+ * Fill 1 pixel in framebuffer, and go to next one.
+ *
+ * @param dstp a pointer to pointer to framebuffer.
+ * @param valuevalue to write to framebuffer.
+ * @param pbytes   framebuffer bytes per pixel.
+ * @param step framebuffer pointer increment. Usually is equal to 
pbytes,
+ * and may be negative to control filling direction.
+ */
+static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int 
pbytes, int step)
+{
+   u8 *dst_byte = *dstp;
+
+   if (pbytes == 4) {
+   u32 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 2) {
+   u16 *dst = *dstp;
+   *dst = value;
+   }
+   if (pbytes == 1) {
+   u8 *dst = *dstp;
+   *dst = value;
+   }
+   *dstp = dst_byte + step;
+}
+
+#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
+/**
+ * Fills 1 character in framebuffer horizontally.
+ * Horizontally means we're filling char font data columns across the lines.
+ *
+ * @param pfonta pointer to character font data.
+ * @param line a pointer to pointer to framebuffer. It's a point for 
upper left char corner
+ * @param vid_priv driver private data.
+ * @param directioncontrols character orientation. Can be normal or 
flipped.
+ * When normal:   When flipped:
+ *|---|
+ *|   *|   line stepping  |
+ *|^  * * * * *|   |  |
+ *||* *|   v   * *|
+ *||   |   * * * * *  |
+ *|  line stepping |   *  |
+ *||  |
+ *|  stepping ->   |<- stepping   |
+ *|---!!we're starting from upper left char corner|
+ *|---|
+ *
+ * @returns 0, if success, or else error code.
+ */
+static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
+ bool direction)
+{
+   int step, line_step, pbytes, ret;
+   void *dst;
+   u8 mask = 0x80;
+
+   ret = check_bpix_support(v

[PATCH v2 4/8] video console: add select font logic to vidconsole uclass driver

2023-02-13 Thread Dzmitry Sankouski
Select font logic at runtime needed to unit test different fonts.
This commit is a preparation to enable runtime font selection in
console_simple driver.

- move console true type select font logic to driver ops
- add select font logic to vidconsole-uclass.c

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A

 cmd/font.c|  7 ++-
 drivers/video/console_truetype.c  |  6 --
 drivers/video/vidconsole-uclass.c | 22 ++
 include/video.h   |  1 +
 include/video_console.h   | 18 +-
 5 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/cmd/font.c b/cmd/font.c
index 3e522f3aaa..769796c5ec 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -15,7 +15,12 @@
 static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
 {
-   vidconsole_list_fonts();
+   struct udevice *dev;
+
+   if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, ))
+   return CMD_RET_FAILURE;
+
+   vidconsole_list_fonts(dev);
 
return 0;
 }
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 6859c9fa11..389fa483fc 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -584,7 +584,7 @@ static struct font_info *console_truetype_find_font(void)
return NULL;
 }
 
-void vidconsole_list_fonts(void)
+void console_truetype_list_fonts(struct udevice __maybe_unused *dev)
 {
struct font_info *tab;
 
@@ -674,7 +674,7 @@ static void select_metrics(struct udevice *dev, struct 
console_tt_metrics *met)
vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
 }
 
-int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+int console_truetype_select_font(struct udevice *dev, const char *name, uint 
size)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
struct console_tt_metrics *met;
@@ -763,6 +763,8 @@ struct vidconsole_ops console_truetype_ops = {
.set_row= console_truetype_set_row,
.backspace  = console_truetype_backspace,
.entry_start= console_truetype_entry_start,
+   .list_fonts = console_truetype_list_fonts,
+   .select_font= console_truetype_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 6bdfb6e37d..5a08fdd689 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -85,6 +85,28 @@ static int vidconsole_back(struct udevice *dev)
return video_sync(dev->parent, false);
 }
 
+void vidconsole_list_fonts(struct udevice *dev)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+   if (ops->select_font)
+   ops->list_fonts(dev);
+}
+
+int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+   int ret;
+
+   if (ops->select_font) {
+   ret = ops->select_font(dev, name, size);
+   if (ret != -ENOSYS)
+   return ret;
+   }
+
+   return 0;
+}
+
 /* Move to a newline, scrolling the display if necessary */
 static void vidconsole_newline(struct udevice *dev)
 {
diff --git a/include/video.h b/include/video.h
index 43f2e2c02f..91c05fa9f0 100644
--- a/include/video.h
+++ b/include/video.h
@@ -115,6 +115,7 @@ struct video_priv {
bool flush_dcache;
u8 fg_col_idx;
u8 bg_col_idx;
+   struct video_fontdata *fontdata;
 };
 
 /**
diff --git a/include/video_console.h b/include/video_console.h
index d755eb73cf..fc702cc165 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -133,6 +133,22 @@ struct vidconsole_ops {
 * characters.
 */
int (*backspace)(struct udevice *dev);
+
+   /**
+* list_fonts() - List the available fonts
+*
+* This shows a list on the console
+*/
+   void (*list_fonts)(struct udevice *dev);
+
+   /**
+* select_font() - Select a font to use
+*
+* @dev: vidconsole device
+* @name: Font name
+* @size: Size of the font (norminal pixel height) or 0 for default
+*/
+   int (*select_font)(struct udevice *dev, const char *name, uint size);
 };
 
 /* Get a pointer to the driver operations for a video console device */
@@ -236,7 +252,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, 
int y);
  *
  * This shows a list on the console
  */
-void vidconsole_list_fonts(void);
+void vidconsole_list_fonts(struct udevice *dev);
 
 /**
  * vidconsole_select_font() - Select a font to use
-- 
2.30.2



[PATCH v2 3/8] video console: add support for fonts wider than 1 byte

2023-02-13 Thread Dzmitry Sankouski
Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski 
---
Charges for v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring

 drivers/video/console_simple.c | 93 +-
 1 file changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index 1eb47be449..cdc26cac30 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -13,6 +13,7 @@
 #include /* Get font data, width and height */
 
 #define VIDEO_FONT_BYTE_WIDTH  ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 
> 0))
+#define VIDEO_FONT_CHAR_PIXEL_BYTES(VIDEO_FONT_HEIGHT * 
VIDEO_FONT_BYTE_WIDTH)
 
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
@@ -95,9 +96,9 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 
value, int pbytes,
 static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv 
*vid_priv,
  bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
-   u8 mask = 0x80;
+   u8 mask;
 
ret = check_bpix_support(vid_priv->bpix);
if (ret)
@@ -111,21 +112,32 @@ static int fill_char_horizontally(uchar *pfont, void 
**line, struct video_priv *
step = pbytes;
line_step = -vid_priv->line_length;
}
-   for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-   dst = *line;
-   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) 
?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
-   );
+
+   width_remainder = VIDEO_FONT_WIDTH % 8;
+   for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+   mask = 0x80;
+   if (width_remainder) {
+   bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col 
== 1);
+
+   if (is_last_iteration)
+   bitcount = width_remainder;
+   }
+   for (int bit = 0; bit < bitcount; bit++) {
+   dst = *line;
+   for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] 
& mask) ?
+   vid_priv->colour_fg :
+   vid_priv->colour_bg;
+
+   fill_pixel_and_goto_next(,
+value,
+pbytes,
+step
+   );
+   }
+   *line += line_step;
+   mask >>= 1;
}
-   *line += line_step;
-   mask >>= 1;
}
return ret;
 }
@@ -158,7 +170,7 @@ static int fill_char_horizontally(uchar *pfont, void 
**line, struct video_priv *
 static int fill_char_vertically(uchar *pfont, void **line, struct video_priv 
*vid_priv,
bool direction)
 {
-   int step, line_step, pbytes, ret;
+   int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
 
ret = check_bpix_support(vid_priv->bpix);
@@ -174,23 +186,36 @@ static int fill_char_vertically(uchar *pfont, void 
**line, struct video_priv *vi
line_step = vid_priv->line_length;
}
 
+   width_remainder = VIDEO_FONT_WIDTH % 8;
for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+   uchar bits;
+
+   bitcount = 8;
dst = *line;
-   uchar bits = pfont[row];
-
-   for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-   u32 value = (bits & 0x80) ?
-   vid_priv->colour_fg :
-   vid_priv->colour_bg;
-
-   fill_pixel_and_goto_next(,
-value,
-pbytes,
-step
- 

[PATCH v2 1/8] video console: unite normal and rotated files

2023-02-13 Thread Dzmitry Sankouski
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..00
--- 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 -- w...@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;
-   

[PATCH v2 0/8] vidconsole: refactoring and support for wider fonts

2023-02-13 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

This patch series aims to add wider fonts for devices with high ppi.

Add 16x32, 12x22 fonts from linux, and allow font size configuration.

There was significant changes in version 3:
- fix video tests failures
- add runtime font size configuration
- add test for 12x22 font

Dzmitry Sankouski (8):
  video console: unite normal and rotated files
  video console: refactoring and optimization
  video console: add support for fonts wider than 1 byte
  video console: add select font logic to vidconsole uclass driver
  video console: allow font size configuration at runtime
  video console: add 12x22 Sun font from linux
  video console: add 16x32 Terminus font from linux
  video console: add 12x22 console simple font test

 cmd/Kconfig   |8 +
 cmd/Makefile  |2 +-
 cmd/font.c|7 +-
 common/splash.c   |7 +-
 configs/qemu-x86_defconfig|1 +
 configs/sandbox_defconfig |3 +
 drivers/video/Kconfig |   38 +-
 drivers/video/Makefile|3 +-
 drivers/video/console_normal.c|  178 -
 drivers/video/console_rotate.c|  497 ---
 drivers/video/console_simple.c|  638 +++
 drivers/video/console_truetype.c  |6 +-
 drivers/video/vidconsole-uclass.c |   22 +
 include/video.h   |1 +
 include/video_console.h   |   18 +-
 include/video_font.h  |   31 +-
 include/video_font_4x6.h  |   11 +-
 include/video_font_8x16.h | 4624 ++
 include/video_font_data.h | 4644 +-
 include/video_font_sun12x22.h | 6158 +
 include/video_font_ter16x32.h | 2062 ++
 test/dm/video.c   |   41 +
 22 files changed, 13681 insertions(+), 5319 deletions(-)
 delete mode 100644 drivers/video/console_normal.c
 delete mode 100644 drivers/video/console_rotate.c
 create mode 100644 drivers/video/console_simple.c
 create mode 100644 include/video_font_8x16.h
 create mode 100644 include/video_font_sun12x22.h
 create mode 100644 include/video_font_ter16x32.h

-- 
2.30.2



[PATCH v3 5/5] dm: input: add button_kbd driver

2023-01-22 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.
To use driver, add 'button-kbd' to stdin.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- add doc on driver private data struct
- use calloc instead of malloc
Changes for v3:
- none

 drivers/input/Kconfig  |   9 +++
 drivers/input/Makefile |   1 +
 drivers/input/button_kbd.c | 126 +
 3 files changed, 136 insertions(+)
 create mode 100644 drivers/input/button_kbd.c

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1c534be005..b9a4e443a3 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -46,6 +46,15 @@ config APPLE_SPI_KEYB
  laptops based on Apple SoCs. These keyboards use an
  Apple-specific HID-over-SPI protocol.
 
+config BUTTON_KEYBOARD
+   bool "Buttons as keyboard"
+   depends on BUTTON_GPIO
+   depends on DM_KEYBOARD
+   help
+ Enable support for mapping buttons to keycode events. Use linux,code 
button driver
+ dt node to define button-event mapping.
+ For example, an arrows and enter may be implemented to navigate boot 
menu.
+
 config CROS_EC_KEYB
bool "Enable Chrome OS EC keyboard support"
depends on INPUT
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index ded76bddb2..14c0ea7325 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_$(SPL_TPL_)CROS_EC_KEYB) += cros_ec_keyb.o
 obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += key_matrix.o
 obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += input.o keyboard-uclass.o
+obj-$(CONFIG_BUTTON_KEYBOARD) += button_kbd.o
 
 ifndef CONFIG_SPL_BUILD
 
diff --git a/drivers/input/button_kbd.c b/drivers/input/button_kbd.c
new file mode 100644
index 00..99e65f12f0
--- /dev/null
+++ b/drivers/input/button_kbd.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct button_kbd_priv - driver private data
+ *
+ * @input: input configuration
+ * @button_size: number of buttons found
+ * @old_state: a pointer to old button states array. Used to determine button 
state change.
+ */
+struct button_kbd_priv {
+   struct input_config *input;
+   u32 button_size;
+   u32 *old_state;
+};
+
+static int button_kbd_start(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   int i = 0;
+   struct udevice *button_gpio_devp;
+
+   uclass_foreach_dev_probe(UCLASS_BUTTON, button_gpio_devp) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   debug("Found button %s #%d - %s, probing...\n",
+ uc_plat->label, i, button_gpio_devp->name);
+   i++;
+   }
+
+   priv->button_size = i;
+   priv->old_state = calloc(i, sizeof(int));
+
+   return 0;
+}
+
+int button_read_keys(struct input_config *input)
+{
+   struct button_kbd_priv *priv = dev_get_priv(input->dev);
+   struct udevice *button_gpio_devp;
+   struct uclass *uc;
+   int i = 0;
+   u32 code, state, state_changed = 0;
+
+   uclass_id_foreach_dev(UCLASS_BUTTON, button_gpio_devp, uc) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   code = button_get_code(button_gpio_devp);
+   if (!code)
+   continue;
+
+   state = button_get_state(button_gpio_devp);
+   state_changed = state != priv->old_state[i];
+
+   if (state_changed) {
+   debug("%s: %d\n", uc_plat->label, code);
+   priv->old_state[i] = state;
+   input_add_keycode(input, code, state);
+   }
+   i++;
+   }
+   return 0;
+}
+
+static const struct keyboard_ops button_kbd_ops = {
+   .start  = button_kbd_start,
+};
+
+static int button_kbd_probe(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct stdio_dev *sdev = _priv->sdev;
+   struct input_config *input = _priv->input;
+   int ret = 0;
+
+   input_init(input, false);
+   input_add_tables(input, false);
+
+   /* Register the device. */
+   priv->input = input;
+   input->dev = dev;
+

[PATCH v3 3/5] test: create dedicated fdt node for ofnode_for_each_prop test

2023-01-22 Thread Dzmitry Sankouski
Property count may change in /buttons node, if more button tests added,
and this will break ofnode_for_each_prop.
Add separate node for mentioned test.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2: N/A
Changes for v3: N/A

 arch/sandbox/dts/test.dts | 14 ++
 test/dm/ofnode.c  |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 2e580f980f..06ad027638 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1517,6 +1517,20 @@
};
};
 
+   ofnode-foreach {
+   compatible = "foreach";
+
+   first {
+   prop1 = <1>;
+   prop2 = <2>;
+   };
+
+   second {
+   prop1 = <1>;
+   prop2 = <2>;
+   };
+   };
+
osd {
compatible = "sandbox,sandbox_osd";
};
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 8077affabb..473a8cef57 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -1046,7 +1046,7 @@ static int dm_test_ofnode_for_each_prop(struct 
unit_test_state *uts)
struct ofprop prop;
int count;
 
-   node = ofnode_path("/buttons");
+   node = ofnode_path("/ofnode-foreach");
count = 0;
 
/* we expect "compatible" for each node */
-- 
2.30.2



[PATCH v3 4/5] dm: button: add support for linux_code in button-gpio.c driver

2023-01-22 Thread Dzmitry Sankouski
Linux event code must be used in input devices, using buttons.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- fail, if linux,code not found
Changes for v3:
- add test for linux,code
- change linux,code type to int
- new line after return
- add specific error code in function docs

 arch/sandbox/dts/test.dts  |  2 ++
 drivers/button/button-gpio.c   | 17 -
 drivers/button/button-uclass.c | 10 ++
 include/button.h   | 16 
 test/dm/button.c   | 13 +
 5 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 06ad027638..f8d59f1ce1 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -172,11 +172,13 @@
btn1 {
gpios = <_a 3 0>;
label = "button1";
+   linux,code = ;
};
 
btn2 {
gpios = <_a 4 0>;
label = "button2";
+   linux,code = ;
};
};
 
diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index dbb000622c..7b5b3affe2 100644
--- a/drivers/button/button-gpio.c
+++ b/drivers/button/button-gpio.c
@@ -13,6 +13,7 @@
 
 struct button_gpio_priv {
struct gpio_desc gpio;
+   int linux_code;
 };
 
 static enum button_state_t button_gpio_get_state(struct udevice *dev)
@@ -29,6 +30,17 @@ static enum button_state_t button_gpio_get_state(struct 
udevice *dev)
return ret ? BUTTON_ON : BUTTON_OFF;
 }
 
+static int button_gpio_get_code(struct udevice *dev)
+{
+   struct button_gpio_priv *priv = dev_get_priv(dev);
+   int code = priv->linux_code;
+
+   if (!code)
+   return -ENODATA;
+
+   return code;
+}
+
 static int button_gpio_probe(struct udevice *dev)
 {
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -43,7 +55,9 @@ static int button_gpio_probe(struct udevice *dev)
if (ret)
return ret;
 
-   return 0;
+   ret = dev_read_u32(dev, "linux,code", >linux_code);
+
+   return ret;
 }
 
 static int button_gpio_remove(struct udevice *dev)
@@ -92,6 +106,7 @@ static int button_gpio_bind(struct udevice *parent)
 
 static const struct button_ops button_gpio_ops = {
.get_state  = button_gpio_get_state,
+   .get_code   = button_gpio_get_code,
 };
 
 static const struct udevice_id button_gpio_ids[] = {
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
index e33ed7d01d..032191d61a 100644
--- a/drivers/button/button-uclass.c
+++ b/drivers/button/button-uclass.c
@@ -38,6 +38,16 @@ enum button_state_t button_get_state(struct udevice *dev)
return ops->get_state(dev);
 }
 
+int button_get_code(struct udevice *dev)
+{
+   struct button_ops *ops = button_get_ops(dev);
+
+   if (!ops->get_code)
+   return -ENOSYS;
+
+   return ops->get_code(dev);
+}
+
 UCLASS_DRIVER(button) = {
.id = UCLASS_BUTTON,
.name   = "button",
diff --git a/include/button.h b/include/button.h
index 96e6b1901f..207f4a0f4d 100644
--- a/include/button.h
+++ b/include/button.h
@@ -37,6 +37,14 @@ struct button_ops {
 * @return button state button_state_t, or -ve on error
 */
enum button_state_t (*get_state)(struct udevice *dev);
+
+   /**
+* get_code() - get linux event code of a button
+*
+* @dev:button device to change
+* @return button code, or -ENODATA on error
+*/
+   int (*get_code)(struct udevice *dev);
 };
 
 #define button_get_ops(dev)((struct button_ops *)(dev)->driver->ops)
@@ -58,4 +66,12 @@ int button_get_by_label(const char *label, struct udevice 
**devp);
  */
 enum button_state_t button_get_state(struct udevice *dev);
 
+/**
+ * button_get_code() - get linux event code of a button
+ *
+ * @dev:   button device to change
+ * @return button code, or -ve on error
+ */
+int button_get_code(struct udevice *dev);
+
 #endif
diff --git a/test/dm/button.c b/test/dm/button.c
index e76c1ad030..3318668df2 100644
--- a/test/dm/button.c
+++ b/test/dm/button.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* Base test of the button uclass */
@@ -85,6 +86,18 @@ static int dm_test_button_label(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+/* Test button has linux,code */
+static int dm_test_button_linux_code(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+
+   ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, ));
+   ut_asserteq(BTN_1, button_get_code(dev));
+
+   return 0;
+}
+DM_TEST(dm_test_button_linux_code, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test adc-keys driver */
 static int dm_test_button_keys_adc(struct unit_test_state *uts)
 {
-- 
2.30.2



[PATCH v3 2/5] dts: add missing linux,code in gpio-keys

2023-01-22 Thread Dzmitry Sankouski
gpio-keys linux driver enforces user to specify linux,code.
Add missing linux,code before implementing button input support.

- arch/arm/dts/rk3288-popmetal.dtsi -> KEY_POWER
- arch/arm/dts/rk3288-tinker.dtsi -> KEY_POWER
- arch/arm/dts/am3517-evm-ui.dtsi -> KEY_RECORD
- sandbox/dts/sandbox.dtsi -> BTN_1
- sandbox/dts/sandbox.dts -> BTN_1

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2:
- N/A
Changes for v3:
- import input.h in dts to provide event constants

 arch/arm/dts/am3517-evm-ui.dtsi   | 2 +-
 arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi | 2 +-
 arch/arm/dts/rk3288-popmetal.dtsi | 2 ++
 arch/arm/dts/rk3288-tinker.dtsi   | 2 ++
 arch/sandbox/dts/sandbox.dtsi | 4 
 5 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am3517-evm-ui.dtsi b/arch/arm/dts/am3517-evm-ui.dtsi
index 7d8f32bf70..340e68178c 100644
--- a/arch/arm/dts/am3517-evm-ui.dtsi
+++ b/arch/arm/dts/am3517-evm-ui.dtsi
@@ -72,7 +72,7 @@
 
record {
label = "Record";
-   /* linux,code = ; */
+   linux,code = ;
gpios = <_2 15 GPIO_ACTIVE_LOW>;
};
 
diff --git a/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi 
b/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
index 2f3fd32a11..5f760ed698 100644
--- a/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
+++ b/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
@@ -8,7 +8,7 @@
 
 / {
gpio_keys: gpio-keys {
-   compatible = "gpio-key";
+   compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <_gpio_keys>;
status = "disabled";
diff --git a/arch/arm/dts/rk3288-popmetal.dtsi 
b/arch/arm/dts/rk3288-popmetal.dtsi
index 63785eb55e..0253933a11 100644
--- a/arch/arm/dts/rk3288-popmetal.dtsi
+++ b/arch/arm/dts/rk3288-popmetal.dtsi
@@ -38,6 +38,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include "rk3288.dtsi"
 
 / {
@@ -63,6 +64,7 @@
power {
gpios = < 5 GPIO_ACTIVE_LOW>;
label = "GPIO Key Power";
+   linux,code = ;
linux,input-type = <1>;
wakeup-source;
debounce-interval = <100>;
diff --git a/arch/arm/dts/rk3288-tinker.dtsi b/arch/arm/dts/rk3288-tinker.dtsi
index 2f816af47f..46460ae455 100644
--- a/arch/arm/dts/rk3288-tinker.dtsi
+++ b/arch/arm/dts/rk3288-tinker.dtsi
@@ -38,6 +38,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include 
 #include "rk3288.dtsi"
 
 / {
@@ -63,6 +64,7 @@
button@0 {
gpios = < 5 GPIO_ACTIVE_LOW>;
label = "GPIO Key Power";
+   linux,code = ;
linux,input-type = <1>;
gpio-key,wakeup = <1>;
debounce-interval = <100>;
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index afe598a4f5..c2c71505ce 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -4,6 +4,8 @@
  * and sandbox64 builds.
  */
 
+#include 
+
 #define USB_CLASS_HUB  9
 
 / {
@@ -49,11 +51,13 @@
btn1 {
gpios = <_a 3 0>;
label = "button1";
+   linux,code = ;
};
 
btn2 {
gpios = <_a 4 0>;
label = "button2";
+   linux,code = ;
};
};
 
-- 
2.30.2



[PATCH v3 1/5] gpio: qcom: add direction functions for pwrkey

2023-01-22 Thread Dzmitry Sankouski
GPIO button driver requires direction functions to probe
button gpio. Those functions are blank, since pwrkey is not
really gpio, and don't support direction settings.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Sumit Garg 
---
Changes for v2:
- none
Changes for v3:
- KDPWR and RESIN not gpio: fix comment and commit message

 drivers/gpio/qcom_pmic_gpio.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 3be1be8692..65feb453eb 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -303,9 +303,25 @@ static int qcom_pwrkey_get_value(struct udevice *dev, 
unsigned offset)
}
 }
 
+/*
+ * Since pmic buttons modelled as GPIO, we need empty direction functions
+ * to trick u-boot button driver
+ */
+static int qcom_pwrkey_direction_input(struct udevice *dev, unsigned int 
offset)
+{
+   return 0;
+}
+
+static int qcom_pwrkey_direction_output(struct udevice *dev, unsigned int 
offset, int value)
+{
+   return -EOPNOTSUPP;
+}
+
 static const struct dm_gpio_ops qcom_pwrkey_ops = {
.get_value  = qcom_pwrkey_get_value,
.get_function   = qcom_pwrkey_get_function,
+   .direction_input= qcom_pwrkey_direction_input,
+   .direction_output   = qcom_pwrkey_direction_output,
 };
 
 static int qcom_pwrkey_probe(struct udevice *dev)
-- 
2.30.2



[PATCH v3 0/5] dm: input: driver for buttons with linux, code declaration

2023-01-22 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.

Button keyboard driver relies on button driver - iterates over
all button with linux,code, checks state and sends events.
Add support for linux,code in button driver.
Fix qcom pwr-key gpio driver to work with button driver.

Dzmitry Sankouski (5):
  gpio: qcom: add direction functions for pwrkey
  dts: add missing linux,code in gpio-keys
  test: create dedicated fdt node for ofnode_for_each_prop test
  dm: button: add support for linux_code in button-gpio.c driver
  dm: input: add button_kbd driver

 arch/arm/dts/am3517-evm-ui.dtsi   |   2 +-
 .../dts/imx6ul-phytec-segin-peb-eval-01.dtsi  |   2 +-
 arch/arm/dts/rk3288-popmetal.dtsi |   2 +
 arch/arm/dts/rk3288-tinker.dtsi   |   2 +
 arch/sandbox/dts/sandbox.dtsi |   4 +
 arch/sandbox/dts/test.dts |  16 +++
 drivers/button/button-gpio.c  |  17 ++-
 drivers/button/button-uclass.c|  10 ++
 drivers/gpio/qcom_pmic_gpio.c |  16 +++
 drivers/input/Kconfig |   9 ++
 drivers/input/Makefile|   1 +
 drivers/input/button_kbd.c| 126 ++
 include/button.h  |  16 +++
 test/dm/button.c  |  13 ++
 test/dm/ofnode.c  |   2 +-
 15 files changed, 234 insertions(+), 4 deletions(-)
 create mode 100644 drivers/input/button_kbd.c

-- 
2.30.2



[PATCH v2 4/4] dm: input: add button_kbd driver

2023-01-19 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.
To use driver, add 'button-kbd' to stdin.

Signed-off-by: Dzmitry Sankouski 
Reviewed-by: Simon Glass 
---
Changes for v2:
- add doc on driver private data struct
- use calloc instead of malloc

 drivers/input/Kconfig  |   9 +++
 drivers/input/Makefile |   1 +
 drivers/input/button_kbd.c | 126 +
 3 files changed, 136 insertions(+)
 create mode 100644 drivers/input/button_kbd.c

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1c534be005..b9a4e443a3 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -46,6 +46,15 @@ config APPLE_SPI_KEYB
  laptops based on Apple SoCs. These keyboards use an
  Apple-specific HID-over-SPI protocol.
 
+config BUTTON_KEYBOARD
+   bool "Buttons as keyboard"
+   depends on BUTTON_GPIO
+   depends on DM_KEYBOARD
+   help
+ Enable support for mapping buttons to keycode events. Use linux,code 
button driver
+ dt node to define button-event mapping.
+ For example, an arrows and enter may be implemented to navigate boot 
menu.
+
 config CROS_EC_KEYB
bool "Enable Chrome OS EC keyboard support"
depends on INPUT
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index ded76bddb2..14c0ea7325 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_$(SPL_TPL_)CROS_EC_KEYB) += cros_ec_keyb.o
 obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += key_matrix.o
 obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += input.o keyboard-uclass.o
+obj-$(CONFIG_BUTTON_KEYBOARD) += button_kbd.o
 
 ifndef CONFIG_SPL_BUILD
 
diff --git a/drivers/input/button_kbd.c b/drivers/input/button_kbd.c
new file mode 100644
index 00..99e65f12f0
--- /dev/null
+++ b/drivers/input/button_kbd.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct button_kbd_priv - driver private data
+ *
+ * @input: input configuration
+ * @button_size: number of buttons found
+ * @old_state: a pointer to old button states array. Used to determine button 
state change.
+ */
+struct button_kbd_priv {
+   struct input_config *input;
+   u32 button_size;
+   u32 *old_state;
+};
+
+static int button_kbd_start(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   int i = 0;
+   struct udevice *button_gpio_devp;
+
+   uclass_foreach_dev_probe(UCLASS_BUTTON, button_gpio_devp) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   debug("Found button %s #%d - %s, probing...\n",
+ uc_plat->label, i, button_gpio_devp->name);
+   i++;
+   }
+
+   priv->button_size = i;
+   priv->old_state = calloc(i, sizeof(int));
+
+   return 0;
+}
+
+int button_read_keys(struct input_config *input)
+{
+   struct button_kbd_priv *priv = dev_get_priv(input->dev);
+   struct udevice *button_gpio_devp;
+   struct uclass *uc;
+   int i = 0;
+   u32 code, state, state_changed = 0;
+
+   uclass_id_foreach_dev(UCLASS_BUTTON, button_gpio_devp, uc) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   code = button_get_code(button_gpio_devp);
+   if (!code)
+   continue;
+
+   state = button_get_state(button_gpio_devp);
+   state_changed = state != priv->old_state[i];
+
+   if (state_changed) {
+   debug("%s: %d\n", uc_plat->label, code);
+   priv->old_state[i] = state;
+   input_add_keycode(input, code, state);
+   }
+   i++;
+   }
+   return 0;
+}
+
+static const struct keyboard_ops button_kbd_ops = {
+   .start  = button_kbd_start,
+};
+
+static int button_kbd_probe(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct stdio_dev *sdev = _priv->sdev;
+   struct input_config *input = _priv->input;
+   int ret = 0;
+
+   input_init(input, false);
+   input_add_tables(input, false);
+
+   /* Register the device. */
+   priv->input = input;
+   input->dev = dev;
+

[PATCH v2 3/4] dm: button: add support for linux_code in button-gpio.c driver

2023-01-19 Thread Dzmitry Sankouski
Linux event code may be used in input devices, using buttons.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- fail, if linux,code not found

 drivers/button/button-gpio.c   | 16 +++-
 drivers/button/button-uclass.c | 10 ++
 include/button.h   | 16 
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index dbb000622c..cfed9f17d1 100644
--- a/drivers/button/button-gpio.c
+++ b/drivers/button/button-gpio.c
@@ -13,6 +13,7 @@
 
 struct button_gpio_priv {
struct gpio_desc gpio;
+   u32 linux_code;
 };
 
 static enum button_state_t button_gpio_get_state(struct udevice *dev)
@@ -29,6 +30,17 @@ static enum button_state_t button_gpio_get_state(struct 
udevice *dev)
return ret ? BUTTON_ON : BUTTON_OFF;
 }
 
+static u32 button_gpio_get_code(struct udevice *dev)
+{
+   struct button_gpio_priv *priv = dev_get_priv(dev);
+   u32 code = priv->linux_code;
+
+   if (!code)
+   return 0;
+
+   return code;
+}
+
 static int button_gpio_probe(struct udevice *dev)
 {
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -43,7 +55,8 @@ static int button_gpio_probe(struct udevice *dev)
if (ret)
return ret;
 
-   return 0;
+   ret = dev_read_u32(dev, "linux,code", >linux_code);
+   return ret;
 }
 
 static int button_gpio_remove(struct udevice *dev)
@@ -92,6 +105,7 @@ static int button_gpio_bind(struct udevice *parent)
 
 static const struct button_ops button_gpio_ops = {
.get_state  = button_gpio_get_state,
+   .get_code   = button_gpio_get_code,
 };
 
 static const struct udevice_id button_gpio_ids[] = {
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
index e33ed7d01d..6d0c6f69c5 100644
--- a/drivers/button/button-uclass.c
+++ b/drivers/button/button-uclass.c
@@ -38,6 +38,16 @@ enum button_state_t button_get_state(struct udevice *dev)
return ops->get_state(dev);
 }
 
+u32 button_get_code(struct udevice *dev)
+{
+   struct button_ops *ops = button_get_ops(dev);
+
+   if (!ops->get_code)
+   return -ENOSYS;
+
+   return ops->get_code(dev);
+}
+
 UCLASS_DRIVER(button) = {
.id = UCLASS_BUTTON,
.name   = "button",
diff --git a/include/button.h b/include/button.h
index 96e6b1901f..27af4a6a1a 100644
--- a/include/button.h
+++ b/include/button.h
@@ -37,6 +37,14 @@ struct button_ops {
 * @return button state button_state_t, or -ve on error
 */
enum button_state_t (*get_state)(struct udevice *dev);
+
+   /**
+* get_code() - get linux event code of a button
+*
+* @dev:button device to change
+* @return button code, or -ve on error
+*/
+   u32 (*get_code)(struct udevice *dev);
 };
 
 #define button_get_ops(dev)((struct button_ops *)(dev)->driver->ops)
@@ -58,4 +66,12 @@ int button_get_by_label(const char *label, struct udevice 
**devp);
  */
 enum button_state_t button_get_state(struct udevice *dev);
 
+/**
+ * button_get_code() - get linux event code of a button
+ *
+ * @dev:   button device to change
+ * @return button code, or -ve on error
+ */
+u32 button_get_code(struct udevice *dev);
+
 #endif
-- 
2.30.2



[PATCH v2 2/4] dts: add missing linux,code in gpio-keys

2023-01-19 Thread Dzmitry Sankouski
gpio-keys linux driver enforces user to specify linux,code.
Add missing linux,code before implementing button input support.

- arch/arm/dts/rk3288-popmetal.dtsi -> KEY_POWER
- arch/arm/dts/rk3288-tinker.dtsi -> KEY_POWER
- arch/arm/dts/am3517-evm-ui.dtsi -> KEY_RECORD
- sandbox/dts/sandbox.dtsi -> BTN_1
- sandbox/dts/sandbox.dts -> BTN_1

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- N/A

 arch/arm/dts/am3517-evm-ui.dtsi   | 2 +-
 arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi | 2 +-
 arch/arm/dts/rk3288-popmetal.dtsi | 1 +
 arch/arm/dts/rk3288-tinker.dtsi   | 1 +
 arch/sandbox/dts/sandbox.dtsi | 2 ++
 5 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/am3517-evm-ui.dtsi b/arch/arm/dts/am3517-evm-ui.dtsi
index 7d8f32bf70..340e68178c 100644
--- a/arch/arm/dts/am3517-evm-ui.dtsi
+++ b/arch/arm/dts/am3517-evm-ui.dtsi
@@ -72,7 +72,7 @@
 
record {
label = "Record";
-   /* linux,code = ; */
+   linux,code = ;
gpios = <_2 15 GPIO_ACTIVE_LOW>;
};
 
diff --git a/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi 
b/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
index 2f3fd32a11..5f760ed698 100644
--- a/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
+++ b/arch/arm/dts/imx6ul-phytec-segin-peb-eval-01.dtsi
@@ -8,7 +8,7 @@
 
 / {
gpio_keys: gpio-keys {
-   compatible = "gpio-key";
+   compatible = "gpio-keys";
pinctrl-names = "default";
pinctrl-0 = <_gpio_keys>;
status = "disabled";
diff --git a/arch/arm/dts/rk3288-popmetal.dtsi 
b/arch/arm/dts/rk3288-popmetal.dtsi
index 63785eb55e..cfdfe5e44c 100644
--- a/arch/arm/dts/rk3288-popmetal.dtsi
+++ b/arch/arm/dts/rk3288-popmetal.dtsi
@@ -63,6 +63,7 @@
power {
gpios = < 5 GPIO_ACTIVE_LOW>;
label = "GPIO Key Power";
+   linux,code = ;
linux,input-type = <1>;
wakeup-source;
debounce-interval = <100>;
diff --git a/arch/arm/dts/rk3288-tinker.dtsi b/arch/arm/dts/rk3288-tinker.dtsi
index 2f816af47f..a7eeb56bf7 100644
--- a/arch/arm/dts/rk3288-tinker.dtsi
+++ b/arch/arm/dts/rk3288-tinker.dtsi
@@ -63,6 +63,7 @@
button@0 {
gpios = < 5 GPIO_ACTIVE_LOW>;
label = "GPIO Key Power";
+   linux,code = ;
linux,input-type = <1>;
gpio-key,wakeup = <1>;
debounce-interval = <100>;
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index afe598a4f5..f7f570be6f 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -49,11 +49,13 @@
btn1 {
gpios = <_a 3 0>;
label = "button1";
+   linux,code = ;
};
 
btn2 {
gpios = <_a 4 0>;
label = "button2";
+   linux,code = ;
};
};
 
-- 
2.30.2



[PATCH v2 1/4] gpio: qcom: add direction functions for pwrkey

2023-01-19 Thread Dzmitry Sankouski
GPIO button driver requires direction functions to probe
button gpio. Those functions are blank, since pwrkey gpio
configured earlier not by u-boot.

Signed-off-by: Dzmitry Sankouski 
---
Changes for v2:
- none

 drivers/gpio/qcom_pmic_gpio.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 3be1be8692..e46377ce3b 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -303,9 +303,24 @@ static int qcom_pwrkey_get_value(struct udevice *dev, 
unsigned offset)
}
 }
 
+/*
+ * Power button already configured as input by previous bootloader.
+ */
+static int qcom_pwrkey_direction_input(struct udevice *dev, unsigned int 
offset)
+{
+   return 0;
+}
+
+static int qcom_pwrkey_direction_output(struct udevice *dev, unsigned int 
offset, int value)
+{
+   return -EOPNOTSUPP;
+}
+
 static const struct dm_gpio_ops qcom_pwrkey_ops = {
.get_value  = qcom_pwrkey_get_value,
.get_function   = qcom_pwrkey_get_function,
+   .direction_input= qcom_pwrkey_direction_input,
+   .direction_output   = qcom_pwrkey_direction_output,
 };
 
 static int qcom_pwrkey_probe(struct udevice *dev)
-- 
2.30.2



[PATCH v2 0/4] dm: input: driver for buttons with linux, code declaration

2023-01-19 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.

Button keyboard driver relies on button driver - iterates over
all button with linux,code, checks state and sends events.
Add support for linux,code in button driver.
Fix qcom pwr-key gpio driver to work with button driver.

Dzmitry Sankouski (4):
  gpio: qcom: add direction functions for pwrkey
  dts: add missing linux,code in gpio-keys
  dm: button: add support for linux_code in button-gpio.c driver
  dm: input: add button_kbd driver

 arch/arm/dts/am3517-evm-ui.dtsi   |   2 +-
 .../dts/imx6ul-phytec-segin-peb-eval-01.dtsi  |   2 +-
 arch/arm/dts/rk3288-popmetal.dtsi |   1 +
 arch/arm/dts/rk3288-tinker.dtsi   |   1 +
 arch/sandbox/dts/sandbox.dtsi |   2 +
 drivers/button/button-gpio.c  |  16 ++-
 drivers/button/button-uclass.c|  10 ++
 drivers/gpio/qcom_pmic_gpio.c |  15 +++
 drivers/input/Kconfig |   9 ++
 drivers/input/Makefile|   1 +
 drivers/input/button_kbd.c| 126 ++
 include/button.h  |  16 +++
 12 files changed, 198 insertions(+), 3 deletions(-)
 create mode 100644 drivers/input/button_kbd.c

-- 
2.30.2



Re: [PATCH 2/3] dm: button: add support for linux_code in button-gpio.c driver

2023-01-16 Thread Dzmitry Sankouski
I guess, u-boot button driver was created as minimal as possible
intentionally, to keep the size small.
It may be used in scripts without event code with button command. Some
dts has no event code, for example
sandbox.dtsi.

пн, 16 янв. 2023 г. в 12:53, Quentin Schulz
:
>
> Hi Dzmitry,
>
> On 1/14/23 20:42, Dzmitry Sankouski wrote:
> > dev_read_u32 will fail, if linux,code is not found.
> > We shouldn't fail here, as linux,code is optional, so maybe 
> > dev_read_u32_default
> > with 0 default value, instead of negative error code?
> >
>
> No, 0 is an existing and valid code.
>
> FYI, linux,code is not optional for GPIO buttons in the Linux kernel and
> fails the device probing. What would be the usecase for GPIO buttons
> without a code?
>
> In the event we really want to allow no linux,cpde for GPIO button:
> It's fine if dev_read_u32 fails, you can use the return code as logic on
> what to do next.
>
> I believe you need to have a signed variable to store one invalid value
> (e.g. -EINVAL or -ENOTSUPP or something like that). You could also have
> a boolean stating whether a linux,code was found for this device. You
> could also use some pointer to an u32 which would be NULL if not
> present, but then you'd have to do memory allocation/freeing.
>
> > ср, 11 янв. 2023 г. в 18:48, Quentin Schulz
> > :
> >>
> >> Hi Dzmitry,
> >>
> >> On 1/11/23 11:19, Dzmitry Sankouski wrote:
> >>> Linux event code may be used in input devices, using buttons.
> >>>
> >>> Signed-off-by: Dzmitry Sankouski 
> >>> ---
> >>>drivers/button/button-gpio.c   | 20 
> >>>drivers/button/button-uclass.c | 10 ++
> >>>include/button.h   | 16 
> >>>3 files changed, 46 insertions(+)
> >>>
> >>> diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
> >>> index dbb000622c..e6eff5c1da 100644
> >>> --- a/drivers/button/button-gpio.c
> >>> +++ b/drivers/button/button-gpio.c
> >>> @@ -13,6 +13,7 @@
> >>>
> >>>struct button_gpio_priv {
> >>>struct gpio_desc gpio;
> >>> + u32 linux_code;
> >>>};
> >>>
> >>>static enum button_state_t button_gpio_get_state(struct udevice *dev)
> >>> @@ -29,10 +30,22 @@ static enum button_state_t 
> >>> button_gpio_get_state(struct udevice *dev)
> >>>return ret ? BUTTON_ON : BUTTON_OFF;
> >>>}
> >>>
> >>> +static u32 button_gpio_get_code(struct udevice *dev)
> >>> +{
> >>> + struct button_gpio_priv *priv = dev_get_priv(dev);
> >>> + u32 code = priv->linux_code;
> >>> +
> >>> + if (!code)
> >>> + return 0;
> >>> +
>
> I think we need something better than returning 0 in case there's no
> linux,code, since 0 is technically a valid linux,code.
>
> There are multiple ways of doing this, here are the two that comes to my
> mind right now.
>
> 1) have
> int (*get_code)(struct udevice *dev, u32 *code);
> instead of
> u32 (*get_code)(struct udevice *dev);
>
> and have the function return 0 on success or -EINVAL/-ENOTSUPP/whatever
> if linux,code was not set.
>
> 2) use a struct
> struct res {
>  int ret;
>  u32 code;
> };
> struct res (*get_code)(struct udevice *dev);
> instead of
> u32 (*get_code)(struct udevice *dev);
>
> and check on res.ret before reading res.code in your framework.
>
> Cheers,
> Quentin
>
> >>> + return code;
> >>> +}
> >>> +
> >>>static int button_gpio_probe(struct udevice *dev)
> >>>{
> >>>struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
> >>>struct button_gpio_priv *priv = dev_get_priv(dev);
> >>> + u32 linux_code;
> >>>int ret;
> >>>
> >>>/* Ignore the top-level button node */
> >>> @@ -43,6 +56,12 @@ static int button_gpio_probe(struct udevice *dev)
> >>>if (ret)
> >>>return ret;
> >>>
> >>> + linux_code = dev_read_u32_default(dev, "linux,code", -ENODATA);
> >>> + debug("linux code value: %d, ret: %d", linux_code, ret);
> >>> + if (ret)
> >>> + return ret;
> >>
> >> ret is not modified here so it'll always pass even if it fails to parse
> >> dev_read_u32_default.
> >>
> >> I believe dev_read_u32_default incorrectly requests an int as last
> >> argument while it's going to fill it with u32 data on success.
> >> dev_read_u8/u16 get this correctly so that might just be an oversight.
> >>
> >> Please use dev_read_u32 instead:
> >>
> >> ret = dev_read_u32(dev, "linux,code", >linux_code);
> >> debug("linux code value: %d, ret: %d", linux_code, ret);
> >> return ret;
> >>
> >> (no need to check the value of ret since it's the same as
> >> if (ret)
> >>   return ret;
> >>
> >> return 0;
> >> )
> >>
> >> Cheers,
> >> Quentin


Re: [PATCH 2/3] dm: button: add support for linux_code in button-gpio.c driver

2023-01-14 Thread Dzmitry Sankouski
dev_read_u32 will fail, if linux,code is not found.
We shouldn't fail here, as linux,code is optional, so maybe dev_read_u32_default
with 0 default value, instead of negative error code?

ср, 11 янв. 2023 г. в 18:48, Quentin Schulz
:
>
> Hi Dzmitry,
>
> On 1/11/23 11:19, Dzmitry Sankouski wrote:
> > Linux event code may be used in input devices, using buttons.
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >   drivers/button/button-gpio.c   | 20 
> >   drivers/button/button-uclass.c | 10 ++
> >   include/button.h   | 16 
> >   3 files changed, 46 insertions(+)
> >
> > diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
> > index dbb000622c..e6eff5c1da 100644
> > --- a/drivers/button/button-gpio.c
> > +++ b/drivers/button/button-gpio.c
> > @@ -13,6 +13,7 @@
> >
> >   struct button_gpio_priv {
> >   struct gpio_desc gpio;
> > + u32 linux_code;
> >   };
> >
> >   static enum button_state_t button_gpio_get_state(struct udevice *dev)
> > @@ -29,10 +30,22 @@ static enum button_state_t button_gpio_get_state(struct 
> > udevice *dev)
> >   return ret ? BUTTON_ON : BUTTON_OFF;
> >   }
> >
> > +static u32 button_gpio_get_code(struct udevice *dev)
> > +{
> > + struct button_gpio_priv *priv = dev_get_priv(dev);
> > + u32 code = priv->linux_code;
> > +
> > + if (!code)
> > + return 0;
> > +
> > + return code;
> > +}
> > +
> >   static int button_gpio_probe(struct udevice *dev)
> >   {
> >   struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
> >   struct button_gpio_priv *priv = dev_get_priv(dev);
> > + u32 linux_code;
> >   int ret;
> >
> >   /* Ignore the top-level button node */
> > @@ -43,6 +56,12 @@ static int button_gpio_probe(struct udevice *dev)
> >   if (ret)
> >   return ret;
> >
> > + linux_code = dev_read_u32_default(dev, "linux,code", -ENODATA);
> > + debug("linux code value: %d, ret: %d", linux_code, ret);
> > + if (ret)
> > + return ret;
>
> ret is not modified here so it'll always pass even if it fails to parse
> dev_read_u32_default.
>
> I believe dev_read_u32_default incorrectly requests an int as last
> argument while it's going to fill it with u32 data on success.
> dev_read_u8/u16 get this correctly so that might just be an oversight.
>
> Please use dev_read_u32 instead:
>
> ret = dev_read_u32(dev, "linux,code", >linux_code);
> debug("linux code value: %d, ret: %d", linux_code, ret);
> return ret;
>
> (no need to check the value of ret since it's the same as
> if (ret)
>  return ret;
>
> return 0;
> )
>
> Cheers,
> Quentin


Re: [PATCH 1/5] video console: unite normal and rotated files

2023-01-11 Thread Dzmitry Sankouski
I'll reword the commit description. Files contain similar logic, and
common code may be extracted after putting it together.

пт, 30 дек. 2022 г. в 01:41, Simon Glass :
>
> Hi Dzmitry,
>
> On Mon, 26 Dec 2022 at 13:49, Dzmitry Sankouski  wrote:
> >
> > Put video console driver code in one file.
>
> This isn't quite true as we still have TrueType.
>
> Also, what combine them?
>
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >  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%)
>
> Regards,
> Simon


Re: [PATCH 5/5] video console: remove unused 4x6 font

2023-01-11 Thread Dzmitry Sankouski
ok

пт, 30 дек. 2022 г. в 01:40, Simon Glass :
>
> Hi Dzmitry,
>
> On Mon, 26 Dec 2022 at 13:50, Dzmitry Sankouski  wrote:
> >
> > Remove video_font_4x6.h file because it's unused.
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >  drivers/video/Kconfig|6 -
> >  include/video_font.h |4 +-
> >  include/video_font_4x6.h | 2155 --
> >  3 files changed, 1 insertion(+), 2164 deletions(-)
> >  delete mode 100644 include/video_font_4x6.h
> >
>
> I do think this is useful, e.g. on small displays. How about adding a
> Kconfig for it instead?
>
> Regards,
> Simon


Re: [PATCH 4/5] video console: add 16x32 ter font from linux

2023-01-11 Thread Dzmitry Sankouski
I tested on qemu q35 with RUFSCRIPT, CANTORAONE font, it uses
RUFSCRIPT, and works fine.
Not sure how to switch it on runtime, though.



пт, 30 дек. 2022 г. в 01:41, Simon Glass :
>
> Hi Dzmitry,
>
> On Tue, 27 Dec 2022 at 07:44, Dzmitry Sankouski  wrote:
> >
> > Modern mobile phones typically have high pixel density.
> > Bootmenu is hardly readable on those with 8x16 font.
> >
> > Add 16x32 ter font from linux, and allow font size configuration.
>
> That second bit should really be in a separate (previous) commit.
>
> > Set 16x32 font for starqltechn board.
>
> This should be in the next commit.
>
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >  configs/starqltechn_defconfig |1 +
> >  drivers/video/Kconfig |   23 +
> >  include/video_font.h  |6 +-
> >  include/video_font_ter16x32.h | 2068 +
> >  4 files changed, 2096 insertions(+), 2 deletions(-)
> >  create mode 100644 include/video_font_ter16x32.h
>
> Can we test this? With truetype we actually allow multiple fonts to be
> built, so we can select one at runtime.
>
> Regards,
> Simon


Re: [PATCH 0/5] vidconsole: refactoring and support for wider fonts

2023-01-11 Thread Dzmitry Sankouski
This patchset adds wider fonts only for normal console.

пт, 30 дек. 2022 г. в 02:02, Mark Kettenis :
>
> > From: Dzmitry Sankouski 
> > Date: Mon, 26 Dec 2022 22:49:24 +0300
> >
> > Modern mobile phones typically have high pixel density.
> > Bootmenu is hardly readable on those with 8x16 font.
> >
> > This patch series aims to add wider fonts for devices with high ppi.
> >
> > Add 16x32 ter font from linux, and allow font size configuration.
> > Use new font in starqltechn board.
>
> There was a patchset related to this earlier this year that is still
> in limbo:
>
>   https://patchwork.ozlabs.org/project/uboot/list/?series=280178
>
> No idea which is the better approach.


Re: [PATCH] SoC: sdm845: find and save KASLR to env variables

2023-01-11 Thread Dzmitry Sankouski
Right.

ср, 11 янв. 2023 г. в 05:36, Peter Robinson :
>
> On Tue, Dec 27, 2022 at 7:47 PM Dzmitry Sankouski  
> wrote:
> >
> > KASLR address is needed to boot fully functional Android.
> > KASLR is set by primary bootloader, and since u-boot is used
> > as a secondary bootloader(replacing kernel) on sdm845 platform,
> > KASLR may be found by comparing memory chunks at relocaddr over
> > supposed KASLR range.
>
> By KASLR I presume  you mean the random seed? KASLR is a technology
> used in the kernel, but it's actually a random seed that's passed to
> the kernel to generate the random layout.
>
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >  arch/arm/mach-snapdragon/init_sdm845.c | 18 ++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/arch/arm/mach-snapdragon/init_sdm845.c 
> > b/arch/arm/mach-snapdragon/init_sdm845.c
> > index 5f53c21947..1f88502394 100644
> > --- a/arch/arm/mach-snapdragon/init_sdm845.c
> > +++ b/arch/arm/mach-snapdragon/init_sdm845.c
> > @@ -78,5 +78,23 @@ __weak int misc_init_r(void)
> > env_set("key_power", "0");
> > }
> >
> > +   /*
> > +* search for kaslr address, set by primary bootloader by searching 
> > first
> > +* 0x100 relocated bytes at u-boot's initial load address range
> > +*/
> > +   uintptr_t start = gd->ram_base;
> > +   uintptr_t end = start + 0x80;
> > +   u8 *addr = (u8 *)start;
> > +   phys_addr_t *relocaddr = (phys_addr_t *)gd->relocaddr;
> > +   u32 block_size = 0x1000;
> > +
> > +   while (memcmp(addr, relocaddr, 0x100) && (uintptr_t)addr < end)
> > +   addr += block_size;
> > +
> > +   if ((uintptr_t)addr >= end)
> > +   printf("KASLR not found in range 0x%lx - 0x%lx", start, 
> > end);
> > +   else
> > +   env_set_addr("KASLR", addr);
> > +
> > return 0;
> >  }
> > --
> > 2.30.2
> >


[PATCH 3/3] dm: input: add button_kbd driver

2023-01-11 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.
To use driver, add 'button-kbd' to stdin.

Signed-off-by: Dzmitry Sankouski 
---
 drivers/input/Kconfig  |   9 +++
 drivers/input/Makefile |   1 +
 drivers/input/button_kbd.c | 123 +
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/input/button_kbd.c

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 1c534be005..b9a4e443a3 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -46,6 +46,15 @@ config APPLE_SPI_KEYB
  laptops based on Apple SoCs. These keyboards use an
  Apple-specific HID-over-SPI protocol.
 
+config BUTTON_KEYBOARD
+   bool "Buttons as keyboard"
+   depends on BUTTON_GPIO
+   depends on DM_KEYBOARD
+   help
+ Enable support for mapping buttons to keycode events. Use linux,code 
button driver
+ dt node to define button-event mapping.
+ For example, an arrows and enter may be implemented to navigate boot 
menu.
+
 config CROS_EC_KEYB
bool "Enable Chrome OS EC keyboard support"
depends on INPUT
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index ded76bddb2..14c0ea7325 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_$(SPL_TPL_)CROS_EC_KEYB) += cros_ec_keyb.o
 obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += key_matrix.o
 obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += input.o keyboard-uclass.o
+obj-$(CONFIG_BUTTON_KEYBOARD) += button_kbd.o
 
 ifndef CONFIG_SPL_BUILD
 
diff --git a/drivers/input/button_kbd.c b/drivers/input/button_kbd.c
new file mode 100644
index 00..cacec5f699
--- /dev/null
+++ b/drivers/input/button_kbd.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2023 Dzmitry Sankouski 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct button_kbd_priv {
+   struct input_config *input;
+   u32 *keys;
+   u32 keysize;
+   u32 button_size;
+   u32 *old_state;
+};
+
+static int button_kbd_start(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   int i = 0;
+   struct udevice *button_gpio_devp;
+
+   uclass_foreach_dev_probe(UCLASS_BUTTON, button_gpio_devp) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   debug("Found button %s #%d - %s, probing...\n",
+ uc_plat->label, i, button_gpio_devp->name);
+   i++;
+   }
+
+   priv->button_size = i;
+   priv->old_state = malloc(sizeof(int) * i);
+   priv->keysize = 0;
+   priv->keys = malloc(sizeof(int) * i);
+
+   return 0;
+}
+
+int button_read_keys(struct input_config *input)
+{
+   struct button_kbd_priv *priv = dev_get_priv(input->dev);
+   struct udevice *button_gpio_devp;
+   struct uclass *uc;
+   int i = 0;
+   u32 code, state, state_changed = 0;
+
+   uclass_id_foreach_dev(UCLASS_BUTTON, button_gpio_devp, uc) {
+   struct button_uc_plat *uc_plat = 
dev_get_uclass_plat(button_gpio_devp);
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   continue;
+   code = button_get_code(button_gpio_devp);
+   if (code == -ENODATA)
+   continue;
+
+   state = button_get_state(button_gpio_devp);
+   state_changed = state != priv->old_state[i];
+
+   if (state_changed) {
+   debug("%s: %d\n", uc_plat->label, code);
+   priv->old_state[i] = state;
+   input_add_keycode(input, code, state);
+   }
+   i++;
+   }
+   return 0;
+}
+
+static const struct keyboard_ops button_kbd_ops = {
+   .start  = button_kbd_start,
+};
+
+static int button_kbd_probe(struct udevice *dev)
+{
+   struct button_kbd_priv *priv = dev_get_priv(dev);
+   struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct stdio_dev *sdev = _priv->sdev;
+   struct input_config *input = _priv->input;
+   int ret = 0;
+
+   input_init(input, false);
+   input_add_tables(input, false);
+
+   /* Register the device. */
+   priv->input = input;
+   input->dev = dev;
+   input->read_keys = button_read_keys;
+   strcpy(sdev->name, "button-kbd");
+   ret = input_stdio_register(sdev);
+   if (ret) {
+   debug("%s: input_stdio_registe

[PATCH 2/3] dm: button: add support for linux_code in button-gpio.c driver

2023-01-11 Thread Dzmitry Sankouski
Linux event code may be used in input devices, using buttons.

Signed-off-by: Dzmitry Sankouski 
---
 drivers/button/button-gpio.c   | 20 
 drivers/button/button-uclass.c | 10 ++
 include/button.h   | 16 
 3 files changed, 46 insertions(+)

diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index dbb000622c..e6eff5c1da 100644
--- a/drivers/button/button-gpio.c
+++ b/drivers/button/button-gpio.c
@@ -13,6 +13,7 @@
 
 struct button_gpio_priv {
struct gpio_desc gpio;
+   u32 linux_code;
 };
 
 static enum button_state_t button_gpio_get_state(struct udevice *dev)
@@ -29,10 +30,22 @@ static enum button_state_t button_gpio_get_state(struct 
udevice *dev)
return ret ? BUTTON_ON : BUTTON_OFF;
 }
 
+static u32 button_gpio_get_code(struct udevice *dev)
+{
+   struct button_gpio_priv *priv = dev_get_priv(dev);
+   u32 code = priv->linux_code;
+
+   if (!code)
+   return 0;
+
+   return code;
+}
+
 static int button_gpio_probe(struct udevice *dev)
 {
struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
struct button_gpio_priv *priv = dev_get_priv(dev);
+   u32 linux_code;
int ret;
 
/* Ignore the top-level button node */
@@ -43,6 +56,12 @@ static int button_gpio_probe(struct udevice *dev)
if (ret)
return ret;
 
+   linux_code = dev_read_u32_default(dev, "linux,code", -ENODATA);
+   debug("linux code value: %d, ret: %d", linux_code, ret);
+   if (ret)
+   return ret;
+   priv->linux_code = linux_code;
+
return 0;
 }
 
@@ -92,6 +111,7 @@ static int button_gpio_bind(struct udevice *parent)
 
 static const struct button_ops button_gpio_ops = {
.get_state  = button_gpio_get_state,
+   .get_code   = button_gpio_get_code,
 };
 
 static const struct udevice_id button_gpio_ids[] = {
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
index e33ed7d01d..6d0c6f69c5 100644
--- a/drivers/button/button-uclass.c
+++ b/drivers/button/button-uclass.c
@@ -38,6 +38,16 @@ enum button_state_t button_get_state(struct udevice *dev)
return ops->get_state(dev);
 }
 
+u32 button_get_code(struct udevice *dev)
+{
+   struct button_ops *ops = button_get_ops(dev);
+
+   if (!ops->get_code)
+   return -ENOSYS;
+
+   return ops->get_code(dev);
+}
+
 UCLASS_DRIVER(button) = {
.id = UCLASS_BUTTON,
.name   = "button",
diff --git a/include/button.h b/include/button.h
index 96e6b1901f..27af4a6a1a 100644
--- a/include/button.h
+++ b/include/button.h
@@ -37,6 +37,14 @@ struct button_ops {
 * @return button state button_state_t, or -ve on error
 */
enum button_state_t (*get_state)(struct udevice *dev);
+
+   /**
+* get_code() - get linux event code of a button
+*
+* @dev:button device to change
+* @return button code, or -ve on error
+*/
+   u32 (*get_code)(struct udevice *dev);
 };
 
 #define button_get_ops(dev)((struct button_ops *)(dev)->driver->ops)
@@ -58,4 +66,12 @@ int button_get_by_label(const char *label, struct udevice 
**devp);
  */
 enum button_state_t button_get_state(struct udevice *dev);
 
+/**
+ * button_get_code() - get linux event code of a button
+ *
+ * @dev:   button device to change
+ * @return button code, or -ve on error
+ */
+u32 button_get_code(struct udevice *dev);
+
 #endif
-- 
2.30.2



[PATCH 1/3] gpio: qcom: add direction functions for pwrkey

2023-01-11 Thread Dzmitry Sankouski
GPIO button driver requires direction functions to probe
button gpio. Those functions are blank, since pwrkey gpio
configured earlier not by u-boot.

Signed-off-by: Dzmitry Sankouski 
---
 drivers/gpio/qcom_pmic_gpio.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpio/qcom_pmic_gpio.c b/drivers/gpio/qcom_pmic_gpio.c
index 3be1be8692..e46377ce3b 100644
--- a/drivers/gpio/qcom_pmic_gpio.c
+++ b/drivers/gpio/qcom_pmic_gpio.c
@@ -303,9 +303,24 @@ static int qcom_pwrkey_get_value(struct udevice *dev, 
unsigned offset)
}
 }
 
+/*
+ * Power button already configured as input by previous bootloader.
+ */
+static int qcom_pwrkey_direction_input(struct udevice *dev, unsigned int 
offset)
+{
+   return 0;
+}
+
+static int qcom_pwrkey_direction_output(struct udevice *dev, unsigned int 
offset, int value)
+{
+   return -EOPNOTSUPP;
+}
+
 static const struct dm_gpio_ops qcom_pwrkey_ops = {
.get_value  = qcom_pwrkey_get_value,
.get_function   = qcom_pwrkey_get_function,
+   .direction_input= qcom_pwrkey_direction_input,
+   .direction_output   = qcom_pwrkey_direction_output,
 };
 
 static int qcom_pwrkey_probe(struct udevice *dev)
-- 
2.30.2



[PATCH 0/3] dm: input: driver for buttons with linux, code declaration

2023-01-11 Thread Dzmitry Sankouski
Bootmenu requires an input device with arrows and enter key.
A common smartphone luckily has power, volume up/down buttons,
which may be used for controlling bootmenu.

Button keyboard driver relies on button driver - iterates over
all button with linux,code, checks state and sends events.
Add support for linux,code in button driver.
Fix qcom pwr-key gpio driver to work with button driver.

Dzmitry Sankouski (3):
  gpio: qcom: add direction functions for pwrkey
  dm: button: add support for linux_code in button-gpio.c driver
  dm: input: add button_kbd driver

 drivers/button/button-gpio.c   |  20 ++
 drivers/button/button-uclass.c |  10 +++
 drivers/gpio/qcom_pmic_gpio.c  |  15 
 drivers/input/Kconfig  |   9 +++
 drivers/input/Makefile |   1 +
 drivers/input/button_kbd.c | 123 +
 include/button.h   |  16 +
 7 files changed, 194 insertions(+)
 create mode 100644 drivers/input/button_kbd.c

-- 
2.30.2



Re: [PATCH 2/5] video console: refactoring and optimization

2023-01-04 Thread Dzmitry Sankouski
Regarding code-size there's a gain with CONFIG_CONSOLE_ROTATION
enabled, and penalty with disabled:

New:
CONFIG_VIDEO_CONSOLE=y
CONFIG_CONSOLE_ROTATION=y
dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_simple.o
108208  drivers/video/console_simple.o

CONFIG_VIDEO_CONSOLE=y
# CONFIG_CONSOLE_ROTATION is not set
dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_simple.o
53848   drivers/video/console_simple.o

Old:
dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_normal.o
44728   drivers/video/console_normal.o
dzmitry@debian:~/side/u-boot$ du --bytes drivers/video/console_rotate.o
85424   drivers/video/console_rotate.o

In theory, there should be a small performance penalty for the `if
(direction)` statement -
for every row, and for each pixel. For an 8x16 font, it'll be 144 if statements.

I'll comment on functions in the next patch versions.

пт, 30 дек. 2022 г. в 01:41, Simon Glass :
>
> Hi Dzmitry,
>
> On Mon, 26 Dec 2022 at 13:50, Dzmitry Sankouski  wrote:
> >
> > - get rid of code duplications in switch across bpp values
> > - extract common pixel fill logic in two functions one per
> > horizontal and vertical filling
> > - rearrange statements in put_xy* methods in unified way
> > - replace types - uint*_t to u*
> >
> > Signed-off-by: Dzmitry Sankouski 
> > ---
> >  drivers/video/console_simple.c | 508 -
> >  1 file changed, 184 insertions(+), 324 deletions(-)
>
> This looks like a nice tidy up.
>
> Is there a code-size or performance penalty with this? E.g. with
> CONFIG_CONSOLE_ROTATION disabled
>
> Please can you comment the functions property so we know what they do?
>
> Regards,
> Simon


[PATCH] SoC: sdm845: find and save KASLR to env variables

2022-12-27 Thread Dzmitry Sankouski
KASLR address is needed to boot fully functional Android.
KASLR is set by primary bootloader, and since u-boot is used
as a secondary bootloader(replacing kernel) on sdm845 platform,
KASLR may be found by comparing memory chunks at relocaddr over
supposed KASLR range.

Signed-off-by: Dzmitry Sankouski 
---
 arch/arm/mach-snapdragon/init_sdm845.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/mach-snapdragon/init_sdm845.c 
b/arch/arm/mach-snapdragon/init_sdm845.c
index 5f53c21947..1f88502394 100644
--- a/arch/arm/mach-snapdragon/init_sdm845.c
+++ b/arch/arm/mach-snapdragon/init_sdm845.c
@@ -78,5 +78,23 @@ __weak int misc_init_r(void)
env_set("key_power", "0");
}
 
+   /*
+* search for kaslr address, set by primary bootloader by searching 
first
+* 0x100 relocated bytes at u-boot's initial load address range
+*/
+   uintptr_t start = gd->ram_base;
+   uintptr_t end = start + 0x80;
+   u8 *addr = (u8 *)start;
+   phys_addr_t *relocaddr = (phys_addr_t *)gd->relocaddr;
+   u32 block_size = 0x1000;
+
+   while (memcmp(addr, relocaddr, 0x100) && (uintptr_t)addr < end)
+   addr += block_size;
+
+   if ((uintptr_t)addr >= end)
+   printf("KASLR not found in range 0x%lx - 0x%lx", start, end);
+   else
+   env_set_addr("KASLR", addr);
+
return 0;
 }
-- 
2.30.2



[PATCH] board: starqltechn: enable serial console

2022-12-27 Thread Dzmitry Sankouski
It was temporary disabled due to problem with boot.
Issue was fixed in
commit f5ed6c9ccf3e ("uart: sdm845: Fix debug UART pinmux")

Signed-off-by: Dzmitry Sankouski 
---
 configs/starqltechn_defconfig | 4 ++--
 include/configs/sdm845.h  | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/configs/starqltechn_defconfig b/configs/starqltechn_defconfig
index 7955076d61..7a64f2a7a0 100644
--- a/configs/starqltechn_defconfig
+++ b/configs/starqltechn_defconfig
@@ -20,14 +20,14 @@ CONFIG_SYS_PBSIZE=532
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_BMP=y
 # CONFIG_NET is not set
-# CONFIG_DM_STDIO is not set
 CONFIG_CLK=y
 CONFIG_MSM_GPIO=y
 CONFIG_QCOM_PMIC_GPIO=y
 CONFIG_PINCTRL=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_QCOM=y
-# CONFIG_REQUIRE_SERIAL_CONSOLE is not set
+CONFIG_REQUIRE_SERIAL_CONSOLE=y
+CONFIG_MSM_GENI_SERIAL=y
 CONFIG_SPMI_MSM=y
 CONFIG_VIDEO=y
 CONFIG_SYS_WHITE_ON_BLACK=y
diff --git a/include/configs/sdm845.h b/include/configs/sdm845.h
index af5fe27e68..ec6cb3a13c 100644
--- a/include/configs/sdm845.h
+++ b/include/configs/sdm845.h
@@ -16,8 +16,9 @@
 #define CONFIG_EXTRA_ENV_SETTINGS \
"bootm_size=0x400\0"\
"bootm_low=0x8000\0"\
-   "stdout=vidconsole\0"   \
-   "stderr=vidconsole\0"   \
+   "stdin=serial\0"\
+   "stdout=serial,vidconsole\0"\
+   "stderr=serial,vidconsole\0"\
"preboot=source $prevbl_initrd_start_addr:prebootscript\0" \
"bootcmd=source $prevbl_initrd_start_addr:bootscript\0"
 
-- 
2.30.2



[PATCH 4/5] video console: add 16x32 ter font from linux

2022-12-27 Thread Dzmitry Sankouski
Modern mobile phones typically have high pixel density.
Bootmenu is hardly readable on those with 8x16 font.

Add 16x32 ter font from linux, and allow font size configuration.
Set 16x32 font for starqltechn board.

Signed-off-by: Dzmitry Sankouski 
---
 configs/starqltechn_defconfig |1 +
 drivers/video/Kconfig |   23 +
 include/video_font.h  |6 +-
 include/video_font_ter16x32.h | 2068 +
 4 files changed, 2096 insertions(+), 2 deletions(-)
 create mode 100644 include/video_font_ter16x32.h

diff --git a/configs/starqltechn_defconfig b/configs/starqltechn_defconfig
index 59fc9ab151..9e9ca33089 100644
--- a/configs/starqltechn_defconfig
+++ b/configs/starqltechn_defconfig
@@ -12,6 +12,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_BOOTDELAY=5
 CONFIG_CMD_BOOTMENU=y
 CONFIG_DM_KEYBOARD=y
+CONFIG_VIDEO_FONT_16x32=y
 CONFIG_USE_PREBOOT=y
 CONFIG_SAVE_PREV_BL_FDT_ADDR=n
 CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR=n
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index bc7f20cf64..3d531e69dc 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -15,6 +15,29 @@ config VIDEO
  through this.
 
 if VIDEO
+choice
+   prompt "Video font size"
+   default VIDEO_FONT_8x16
+
+config VIDEO_FONT_4X6
+   bool "4 x 6 font size"
+   help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+
+config VIDEO_FONT_8x16
+   bool "8 x 16 font size"
+   help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+
+config VIDEO_FONT_16x32
+   bool "16 x 32 font size"
+   help
+ Font for video console driver, 16 x 32 pixels
+ Provides character bitmap data in header file.
+
+endchoice
 
 config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
diff --git a/include/video_font.h b/include/video_font.h
index 5e23f70f85..86685bfaf1 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -7,10 +7,12 @@
 #ifndef _VIDEO_FONT_
 #define _VIDEO_FONT_
 
-#ifdef CONFIG_VIDEO_FONT_4X6
+#if defined(CONFIG_VIDEO_FONT_4X6)
 #include 
-#else
+#elif defined(CONFIG_VIDEO_FONT_8x16)
 #include 
+#elif defined(CONFIG_VIDEO_FONT_16x32)
+#include 
 #endif
 
 #endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_ter16x32.h b/include/video_font_ter16x32.h
new file mode 100644
index 00..7c9c1b489a
--- /dev/null
+++ b/include/video_font_ter16x32.h
@@ -0,0 +1,2068 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copied from linux.
+ */
+
+#ifndef _VIDEO_FONT_DATA_
+#define _VIDEO_FONT_DATA_
+
+#define VIDEO_FONT_CHARS   256
+#define VIDEO_FONT_WIDTH   16
+#define VIDEO_FONT_BYTE_WIDTH  VIDEO_FONT_WIDTH / 8 + (VIDEO_FONT_WIDTH % 8 > 
0)
+#define VIDEO_FONT_HEIGHT  32
+#define VIDEO_FONT_CHAR_PIXEL_DATA_SIZEVIDEO_FONT_HEIGHT * 
VIDEO_FONT_BYTE_WIDTH
+#define VIDEO_FONT_SIZE(VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT \
+   * VIDEO_FONT_BYTE_WIDTH)
+
+static unsigned char __maybe_unused video_fontdata[VIDEO_FONT_SIZE] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x7f, 0xfc,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c, 0x70, 0x1c,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xf0, 0x1e, 0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xee, 0xee, 0xee, 0xee, 0xe0, 0x0e, 0xe0, 0x0e,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xef, 0xee, 0xe7, 0xce,
+   0xe0, 0x0e, 0xe0, 0x0e, 0xe0, 0x0e, 0xf0, 0x1e,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x3f, 0xf8, 0x7f, 0xfc,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0xe3, 0x8e, 0xe3, 0x8e, 0xff, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xe0, 0x0e, 0xf0, 0x1e,
+   0xf8, 0x3e, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x3f, 0xf8, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 2 */
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x78, 0x3c, 0xfc, 0x7e, 0xfe, 0xfe, 0xff, 0xfe,
+   0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe,
+   0x7f, 0xfc, 0x7f, 0xfc, 0x3f, 0xf8, 0x1f, 0xf0,
+   0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  

  1   2   >