mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum
@ 2015-07-14  9:56 Antony Pavlov
  2015-07-15  5:45 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Antony Pavlov @ 2015-07-14  9:56 UTC (permalink / raw)
  To: barebox

Alas I can't find any tab-complition for param_enum,
so addition 'fonts' command is introduced.

Usage example:
==============

    barebox@barebox sandbox:/ fonts
    VGA8x16
    MINI4x6
    barebox@barebox sandbox:/ fbconsole0.font=MINI4x6
    barebox@barebox sandbox:/ fbconsole0.active=o
    fb0: framebuffer console 160x80 activated
    barebox@barebox sandbox:/ fbconsole0.font=VGA8x16

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
 include/linux/font.h      | 11 ++++++---
 lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
 3 files changed, 80 insertions(+), 30 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 36fd138..7df89ab 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -20,6 +20,10 @@ struct fbc_priv {
 	struct fb_info *fb;
 
 	struct screen *sc;
+
+	struct param_d *par_font;
+	int par_font_val;
+
 /* FIXME */
 #define VIDEO_FONT_CHARS 256
 	struct image *chars[VIDEO_FONT_CHARS];
@@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
 	return 0;
 }
 
+static void cls(struct fbc_priv *priv)
+{
+	void *buf = gui_screen_render_buffer(priv->sc);
+
+	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
+
+	priv->x = 0;
+	priv->y = 0;
+}
+
 static void drawchar(struct fbc_priv *priv, int x, int y, char c)
 {
 	void *buf;
@@ -173,12 +187,7 @@ static void fbc_parse_csi(struct fbc_priv *priv)
 	}
 
 	if (*end == 'J' && a == 2 && b == -1) {
-		void *buf = gui_screen_render_buffer(priv->sc);
-
-		memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-
-		priv->x = 0;
-		priv->y = 0;
+		cls(priv);
 		video_invertchar(priv, priv->x, priv->y);
 	}
 
@@ -263,14 +272,13 @@ static void fbc_putc(struct console_device *cdev, char c)
 	}
 }
 
-static int fbc_set_active(struct console_device *cdev, unsigned flags)
+/* FIXME: name */
+static int setup_font(struct fbc_priv *priv)
 {
-	struct fbc_priv *priv = container_of(cdev,
-					struct fbc_priv, cdev);
 	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
 
-	font = find_font("MINI4x6");
+	font = find_font_enum(priv->par_font_val);
 	if (!font) {
 		return -ENOENT;
 	}
@@ -282,6 +290,20 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	priv->rows = fb->yres / priv->font_height - 1;
 	priv->cols = fb->xres / priv->font_width - 1;
 
+	return 0;
+}
+
+static int fbc_set_active(struct console_device *cdev, unsigned flags)
+{
+	struct fbc_priv *priv = container_of(cdev,
+					struct fbc_priv, cdev);
+	struct fb_info *fb = priv->fb;
+	int ret;
+
+	ret = setup_font(priv);
+	if (ret)
+		return ret;
+
 	priv->sc = fb_create_screen(fb, 0);
 	if (IS_ERR(priv->sc))
 		return PTR_ERR(priv->sc);
@@ -296,6 +318,19 @@ static int fbc_set_active(struct console_device *cdev, unsigned flags)
 	return 0;
 }
 
+static int set_font(struct param_d *p, void *vpriv)
+{
+	struct fbc_priv *priv = vpriv;
+	struct console_device *cdev = &priv->cdev;
+
+	if (cdev->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR)) {
+		cls(priv);
+		setup_font(priv);
+	}
+
+	return 0;
+}
+
 int register_fbconsole(struct fb_info *fb)
 {
 	struct fbc_priv *priv;
@@ -325,6 +360,11 @@ int register_fbconsole(struct fb_info *fb)
 		return ret;
 	}
 
+	priv->par_font_val = 0;
+	priv->par_font = add_param_font(&cdev->class_dev,
+			set_font, NULL,
+			&priv->par_font_val, priv);
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
diff --git a/include/linux/font.h b/include/linux/font.h
index 24d6355..17693a0 100644
--- a/include/linux/font.h
+++ b/include/linux/font.h
@@ -11,6 +11,8 @@
 #ifndef _VIDEO_FONT_H
 #define _VIDEO_FONT_H
 
+#include <param.h>
+
 struct font_desc {
 	const char *name;
 	int width, height;
@@ -20,10 +22,13 @@ struct font_desc {
 extern const struct font_desc	font_vga_8x16,
 			font_mini_4x6;
 
-/* Find a font with a specific name */
-extern const struct font_desc *find_font(const char *name);
-
 /* Max. length for the name of a predefined font */
 #define MAX_FONT_NAME	32
 
+extern const struct font_desc *find_font_enum(int n);
+extern struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv);
+
 #endif /* _VIDEO_FONT_H */
diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
index dbd1813..234885b 100644
--- a/lib/fonts/fonts.c
+++ b/lib/fonts/fonts.c
@@ -37,30 +37,35 @@ static const struct font_desc *fonts[] = {
 #error No fonts configured.
 #endif
 
+static char *font_names;
 
-/**
- *	find_font - find a font
- *	@name: string name of a font
- *
- *	Find a specified font with string name @name.
- *
- *	Returns %NULL if no font found, or a pointer to the
- *	specified font.
- *
- */
-const struct font_desc *find_font(const char *name)
+const struct font_desc *find_font_enum(int n)
+{
+	if (n > num_fonts)
+		return NULL;
+
+	return fonts[n];
+}
+
+struct param_d *add_param_font(struct device_d *dev,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		int *value, void *priv)
 {
 	unsigned int i;
 
-	for (i = 0; i < num_fonts; i++)
-		if (!strncmp(fonts[i]->name, name, MAX_FONT_NAME))
-			  return fonts[i];
+	if (!font_names) {
+		font_names = xmalloc(sizeof(char *) * num_fonts);
 
-	return NULL;
+		for (i = 0; i < num_fonts; i++)
+			((const char **)font_names)[i] = fonts[i]->name;
+	}
+
+	return dev_add_param_enum(dev, "font",
+			set, get, value,
+			(const char **)font_names, num_fonts, priv);
 }
 
-EXPORT_SYMBOL(find_font);
-
 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
 MODULE_DESCRIPTION("Console Fonts");
 MODULE_LICENSE("GPL");
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum
  2015-07-14  9:56 [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum Antony Pavlov
@ 2015-07-15  5:45 ` Sascha Hauer
  2015-07-15  8:45   ` Antony Pavlov
  0 siblings, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2015-07-15  5:45 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

Hi Antony,

On Tue, Jul 14, 2015 at 12:56:34PM +0300, Antony Pavlov wrote:
> Alas I can't find any tab-complition for param_enum,
> so addition 'fonts' command is introduced.
> 
> Usage example:
> ==============
> 
>     barebox@barebox sandbox:/ fonts
>     VGA8x16
>     MINI4x6
>     barebox@barebox sandbox:/ fbconsole0.font=MINI4x6
>     barebox@barebox sandbox:/ fbconsole0.active=o
>     fb0: framebuffer console 160x80 activated
>     barebox@barebox sandbox:/ fbconsole0.font=VGA8x16
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
>  include/linux/font.h      | 11 ++++++---
>  lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
>  3 files changed, 80 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 36fd138..7df89ab 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -20,6 +20,10 @@ struct fbc_priv {
>  	struct fb_info *fb;
>  
>  	struct screen *sc;
> +
> +	struct param_d *par_font;
> +	int par_font_val;
> +
>  /* FIXME */
>  #define VIDEO_FONT_CHARS 256
>  	struct image *chars[VIDEO_FONT_CHARS];
> @@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
>  	return 0;
>  }
>  
> +static void cls(struct fbc_priv *priv)
> +{
> +	void *buf = gui_screen_render_buffer(priv->sc);
> +
> +	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
> +
> +	priv->x = 0;
> +	priv->y = 0;

I found out this is not entirely correct. Clearing the screen (\e[2J)
and putting the cursor top left (\e[;H) are two different things.

I integrated the changes from this patch, but changed cls() not to put
the cursor in home position.

Also I integrated some other changes:

- Fix fbc_set_active, no longer lose memory when called multiple times
- Add 7x14 font
- properly export get_pixel
- Add fb_enable/fb_disable function so that we do not have to call into
  the fb_info ops directly
- Make splash screen work again, was broken by "graphics_utils: Let
  fb_open allocate the screen"

Checkout the result on -next.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum
  2015-07-15  5:45 ` Sascha Hauer
@ 2015-07-15  8:45   ` Antony Pavlov
  2015-07-15 10:27     ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Antony Pavlov @ 2015-07-15  8:45 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Wed, 15 Jul 2015 07:45:32 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:

> Hi Antony,
> 
> On Tue, Jul 14, 2015 at 12:56:34PM +0300, Antony Pavlov wrote:
> > Alas I can't find any tab-complition for param_enum,
> > so addition 'fonts' command is introduced.
> > 
> > Usage example:
> > ==============
> > 
> >     barebox@barebox sandbox:/ fonts
> >     VGA8x16
> >     MINI4x6
> >     barebox@barebox sandbox:/ fbconsole0.font=MINI4x6
> >     barebox@barebox sandbox:/ fbconsole0.active=o
> >     fb0: framebuffer console 160x80 activated
> >     barebox@barebox sandbox:/ fbconsole0.font=VGA8x16
> > 
> > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> > ---
> >  drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
> >  include/linux/font.h      | 11 ++++++---
> >  lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
> >  3 files changed, 80 insertions(+), 30 deletions(-)
> > 
> > diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> > index 36fd138..7df89ab 100644
> > --- a/drivers/video/fbconsole.c
> > +++ b/drivers/video/fbconsole.c
> > @@ -20,6 +20,10 @@ struct fbc_priv {
> >  	struct fb_info *fb;
> >  
> >  	struct screen *sc;
> > +
> > +	struct param_d *par_font;
> > +	int par_font_val;
> > +
> >  /* FIXME */
> >  #define VIDEO_FONT_CHARS 256
> >  	struct image *chars[VIDEO_FONT_CHARS];
> > @@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
> >  	return 0;
> >  }
> >  
> > +static void cls(struct fbc_priv *priv)
> > +{
> > +	void *buf = gui_screen_render_buffer(priv->sc);
> > +
> > +	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
> > +
> > +	priv->x = 0;
> > +	priv->y = 0;
> 
> I found out this is not entirely correct. Clearing the screen (\e[2J)
> and putting the cursor top left (\e[;H) are two different things.
> 
> I integrated the changes from this patch, but changed cls() not to put
> the cursor in home position.
> 
> Also I integrated some other changes:
> 
> - Fix fbc_set_active, no longer lose memory when called multiple times
> - Add 7x14 font
> - properly export get_pixel
> - Add fb_enable/fb_disable function so that we do not have to call into
>   the fb_info ops directly
> - Make splash screen work again, was broken by "graphics_utils: Let
>   fb_open allocate the screen"
> 
> Checkout the result on -next.

So my fbconsole TODO list contain only one position:

  - add Documentation.

Have you any fbconsole TODOs?




-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum
  2015-07-15  8:45   ` Antony Pavlov
@ 2015-07-15 10:27     ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2015-07-15 10:27 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Wed, Jul 15, 2015 at 11:45:47AM +0300, Antony Pavlov wrote:
> On Wed, 15 Jul 2015 07:45:32 +0200
> Sascha Hauer <s.hauer@pengutronix.de> wrote:
> 
> > Hi Antony,
> > 
> > On Tue, Jul 14, 2015 at 12:56:34PM +0300, Antony Pavlov wrote:
> > > Alas I can't find any tab-complition for param_enum,
> > > so addition 'fonts' command is introduced.
> > > 
> > > Usage example:
> > > ==============
> > > 
> > >     barebox@barebox sandbox:/ fonts
> > >     VGA8x16
> > >     MINI4x6
> > >     barebox@barebox sandbox:/ fbconsole0.font=MINI4x6
> > >     barebox@barebox sandbox:/ fbconsole0.active=o
> > >     fb0: framebuffer console 160x80 activated
> > >     barebox@barebox sandbox:/ fbconsole0.font=VGA8x16
> > > 
> > > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> > > ---
> > >  drivers/video/fbconsole.c | 60 +++++++++++++++++++++++++++++++++++++++--------
> > >  include/linux/font.h      | 11 ++++++---
> > >  lib/fonts/fonts.c         | 39 ++++++++++++++++--------------
> > >  3 files changed, 80 insertions(+), 30 deletions(-)
> > > 
> > > diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> > > index 36fd138..7df89ab 100644
> > > --- a/drivers/video/fbconsole.c
> > > +++ b/drivers/video/fbconsole.c
> > > @@ -20,6 +20,10 @@ struct fbc_priv {
> > >  	struct fb_info *fb;
> > >  
> > >  	struct screen *sc;
> > > +
> > > +	struct param_d *par_font;
> > > +	int par_font_val;
> > > +
> > >  /* FIXME */
> > >  #define VIDEO_FONT_CHARS 256
> > >  	struct image *chars[VIDEO_FONT_CHARS];
> > > @@ -47,6 +51,16 @@ static int fbc_tstc(struct console_device *cdev)
> > >  	return 0;
> > >  }
> > >  
> > > +static void cls(struct fbc_priv *priv)
> > > +{
> > > +	void *buf = gui_screen_render_buffer(priv->sc);
> > > +
> > > +	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
> > > +
> > > +	priv->x = 0;
> > > +	priv->y = 0;
> > 
> > I found out this is not entirely correct. Clearing the screen (\e[2J)
> > and putting the cursor top left (\e[;H) are two different things.
> > 
> > I integrated the changes from this patch, but changed cls() not to put
> > the cursor in home position.
> > 
> > Also I integrated some other changes:
> > 
> > - Fix fbc_set_active, no longer lose memory when called multiple times
> > - Add 7x14 font
> > - properly export get_pixel
> > - Add fb_enable/fb_disable function so that we do not have to call into
> >   the fb_info ops directly
> > - Make splash screen work again, was broken by "graphics_utils: Let
> >   fb_open allocate the screen"
> > 
> > Checkout the result on -next.
> 
> So my fbconsole TODO list contain only one position:
> 
>   - add Documentation.
> 
> Have you any fbconsole TODOs?

One that should be fixed before merging into master:

- protect against u8 csi[20] overflows

Some items that can be done later, shouldn't prevent us from merging:

- support remaining colors
- implement dma_alloc_writecombine for faster scrolling
- implement more ANSI sequences (until edit works properly)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-15 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14  9:56 [RFC v2] WIP: fbconsole: not so dirty font selection via param_enum Antony Pavlov
2015-07-15  5:45 ` Sascha Hauer
2015-07-15  8:45   ` Antony Pavlov
2015-07-15 10:27     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox