9
0
Fork 0

fbconsole: register fonts dynamically

Instead of having a fixed array of fonts register the fonts dynamically.
This allows easier adding of fonts to the tree since only one file per
font has to be added and no other files modified.

Currently we have to register the fonts very early before the first
framebuffer is registered. This is because of our limited
dev_add_param_enum() which wants to know the number of elements when
called, so we can't add elements once after we've called
dev_add_param_enum(). Maybe a dev_add_param_array() has to be created
whithout this limitation, but that's left for a future exercise.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2015-11-13 09:13:12 +01:00
parent 3eeac4d2ab
commit 314b5402d9
5 changed files with 59 additions and 37 deletions

View File

@ -17,12 +17,9 @@ struct font_desc {
const char *name;
int width, height;
const void *data;
struct list_head list;
};
extern const struct font_desc font_vga_8x16,
font_7x14,
font_mini_4x6;
/* Max. length for the name of a predefined font */
#define MAX_FONT_NAME 32
@ -32,4 +29,6 @@ extern struct param_d *add_param_font(struct device_d *dev,
int (*get)(struct param_d *p, void *priv),
int *value, void *priv);
int font_register(struct font_desc *font);
#endif /* _VIDEO_FONT_H */

View File

@ -3,6 +3,7 @@
/* by Jurriaan Kalkman 05-2005 */
/**************************************/
#include <init.h>
#include <linux/font.h>
#define FONTDATAMAX 3584
@ -4108,9 +4109,15 @@ static const unsigned char fontdata_7x14[FONTDATAMAX] = {
};
const struct font_desc font_7x14 = {
static struct font_desc font_7x14 = {
.name = "7x14",
.width = 7,
.height = 14,
.data = fontdata_7x14,
};
static int font_7x14_register(void)
{
return font_register(&font_7x14);
}
postcore_initcall(font_7x14_register);

View File

@ -4,6 +4,7 @@
/* */
/**********************************************/
#include <init.h>
#include <module.h>
#include <linux/font.h>
@ -4621,10 +4622,15 @@ static const unsigned char fontdata_8x16[FONTDATAMAX] = {
};
const struct font_desc font_vga_8x16 = {
static struct font_desc font_vga_8x16 = {
.name = "VGA8x16",
.width = 8,
.height = 16,
.data = fontdata_8x16,
};
EXPORT_SYMBOL(font_vga_8x16);
static int font_vga_8x16_register(void)
{
return font_register(&font_vga_8x16);
}
postcore_initcall(font_vga_8x16_register);

View File

@ -39,6 +39,7 @@ __END__;
MSBit to LSBit = left to right.
*/
#include <init.h>
#include <linux/font.h>
#define FONTDATAMAX 1536
@ -2147,9 +2148,15 @@ static const unsigned char fontdata_mini_4x6[FONTDATAMAX] = {
/*}*/
};
const struct font_desc font_mini_4x6 = {
static struct font_desc font_mini_4x6 = {
.name = "MINI4x6",
.width = 4,
.height = 6,
.data = fontdata_mini_4x6,
};
static int font_mini_4x6_register(void)
{
return font_register(&font_mini_4x6);
}
postcore_initcall(font_mini_4x6_register);

View File

@ -18,37 +18,32 @@
#include <linux/string.h>
#include <linux/font.h>
#define NO_FONTS
static const struct font_desc *fonts[] = {
#ifdef CONFIG_FONT_8x16
#undef NO_FONTS
&font_vga_8x16,
#endif
#ifdef CONFIG_FONT_7x14
#undef NO_FONTS
&font_7x14,
#endif
#ifdef CONFIG_FONT_MINI_4x6
#undef NO_FONTS
&font_mini_4x6,
#endif
};
#define num_fonts ARRAY_SIZE(fonts)
#ifdef NO_FONTS
#error No fonts configured.
#endif
static char *font_names;
static LIST_HEAD(fonts_list);
int font_register(struct font_desc *font)
{
if (font_names)
return -EBUSY;
list_add_tail(&font->list, &fonts_list);
return 0;
}
const struct font_desc *find_font_enum(int n)
{
if (n > num_fonts)
return NULL;
struct font_desc *f;
int i = 0;
return fonts[n];
list_for_each_entry(f, &fonts_list, list) {
if (i == n)
return f;
i++;
}
return NULL;
}
struct param_d *add_param_font(struct device_d *dev,
@ -56,13 +51,21 @@ struct param_d *add_param_font(struct device_d *dev,
int (*get)(struct param_d *p, void *priv),
int *value, void *priv)
{
unsigned int i;
struct font_desc *f;
int num_fonts = 0;
list_for_each_entry(f, &fonts_list, list)
num_fonts++;
if (!font_names) {
int i = 0;
font_names = xmalloc(sizeof(char *) * num_fonts);
for (i = 0; i < num_fonts; i++)
((const char **)font_names)[i] = fonts[i]->name;
list_for_each_entry(f, &fonts_list, list) {
((const char **)font_names)[i] = f->name;
i++;
}
}
return dev_add_param_enum(dev, "font",