summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-11-13 09:13:12 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-11-13 09:14:48 +0100
commit314b5402d9f90e4be4be2bbe7c0072876f70281c (patch)
tree5e8623d40257191df7b6f9e7467e15ab067d1338 /lib
parent3eeac4d2abf64452e0aec723704f1566e020a60e (diff)
downloadbarebox-314b5402d9f90e4be4be2bbe7c0072876f70281c.tar.gz
barebox-314b5402d9f90e4be4be2bbe7c0072876f70281c.tar.xz
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/fonts/font_7x14.c9
-rw-r--r--lib/fonts/font_8x16.c10
-rw-r--r--lib/fonts/font_mini_4x6.c9
-rw-r--r--lib/fonts/fonts.c61
4 files changed, 56 insertions, 33 deletions
diff --git a/lib/fonts/font_7x14.c b/lib/fonts/font_7x14.c
index fe99871556..384ba39f17 100644
--- a/lib/fonts/font_7x14.c
+++ b/lib/fonts/font_7x14.c
@@ -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);
diff --git a/lib/fonts/font_8x16.c b/lib/fonts/font_8x16.c
index 4717ead699..c5c14fc427 100644
--- a/lib/fonts/font_8x16.c
+++ b/lib/fonts/font_8x16.c
@@ -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);
diff --git a/lib/fonts/font_mini_4x6.c b/lib/fonts/font_mini_4x6.c
index 3ecb4fbc2c..4a1de138a9 100644
--- a/lib/fonts/font_mini_4x6.c
+++ b/lib/fonts/font_mini_4x6.c
@@ -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);
diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
index 39efb612a3..d59d688950 100644
--- a/lib/fonts/fonts.c
+++ b/lib/fonts/fonts.c
@@ -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;
+
+ list_for_each_entry(f, &fonts_list, list) {
+ if (i == n)
+ return f;
+ i++;
+ }
- return fonts[n];
+ 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",