Modify it to adjust Tizen IVI enviroment
[platform/upstream/kmscon.git] / fblog / 0003-fblog-register-framebuffer-objects.patch
1 From cbb97ae4af35277a5478383045a86438f2e97c71 Mon Sep 17 00:00:00 2001
2 From: David Herrmann <dh.herrmann@googlemail.com>
3 Date: Sat, 16 Jun 2012 22:56:55 +0200
4 Subject: [PATCH 03/10] fblog: register framebuffer objects
5
6 We register each available framebuffer in the system with the fblog driver
7 so we always know all active devices. We directly open the fb-driver,
8 initialize the buffer and load a font so we are ready for drawing
9 operations. If a device cannot be opened, we mark it as dead and ignore it
10 in all other functions.
11
12 Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
13 ---
14  drivers/video/console/fblog.c |  108 +++++++++++++++++++++++++++++++++++++++++
15  1 file changed, 108 insertions(+)
16
17 diff --git a/drivers/video/console/fblog.c b/drivers/video/console/fblog.c
18 index 1504ba9..8038dcc 100644
19 --- a/drivers/video/console/fblog.c
20 +++ b/drivers/video/console/fblog.c
21 @@ -39,6 +39,14 @@
22  #include <linux/font.h>
23  #include <linux/module.h>
24  
25 +#define FBLOG_STR(x) x, sizeof(x) - 1
26 +
27 +enum fblog_flags {
28 +       FBLOG_KILLED,
29 +       FBLOG_SUSPENDED,
30 +       FBLOG_BLANKED,
31 +};
32 +
33  /**
34   * struct fblog_buf: Console text buffer
35   *
36 @@ -61,6 +69,30 @@ struct fblog_buf {
37         size_t pos_y;
38  };
39  
40 +/**
41 + * struct fblog_fb: Framebuffer object
42 + *
43 + * For each framebuffer we register this object. It contains all data we need to
44 + * display the console log on it. The index of a framebuffer in registered_fb[]
45 + * is the same as in fblog_fbs[]. So the following must always be true if the
46 + * pointers are non-NULL:
47 + *     registered_fb[idx] == fblog_fbs[idx]->info
48 + *     fblog_fbs[idx]->info->node == idx
49 + *
50 + * flags: Framebuffer flags (see fblog_flags)
51 + * info: Pointer to the associated framebuffer device
52 + * font: Currently used font
53 + * buf: Console text buffer
54 + */
55 +struct fblog_fb {
56 +       unsigned long flags;
57 +       struct fb_info *info;
58 +       const struct font_desc *font;
59 +       struct fblog_buf buf;
60 +};
61 +
62 +static struct fblog_fb *fblog_fbs[FB_MAX];
63 +
64  static void fblog_buf_resize(struct fblog_buf *buf, size_t width,
65                              size_t height)
66  {
67 @@ -165,6 +197,82 @@ static void fblog_buf_write(struct fblog_buf *buf, const char *str, size_t len)
68         }
69  }
70  
71 +static struct fblog_fb *fblog_info2fb(struct fb_info *info)
72 +{
73 +       if (!info || info->node < 0 || info->node >= FB_MAX ||
74 +           !registered_fb[info->node])
75 +               return NULL;
76 +
77 +       return fblog_fbs[info->node];
78 +}
79 +
80 +static void fblog_register(struct fb_info *info)
81 +{
82 +       struct fblog_fb *fb;
83 +       struct fb_var_screeninfo var;
84 +       const struct fb_videomode *mode;
85 +       unsigned int width, height;
86 +
87 +       if (!info || info->node < 0 || info->node >= FB_MAX)
88 +               return;
89 +       if (!registered_fb[info->node] || fblog_fbs[info->node])
90 +               return;
91 +
92 +       fb = kzalloc(sizeof(*fb), GFP_KERNEL);
93 +       if (!fb)
94 +               return;
95 +
96 +       fblog_fbs[info->node] = fb;
97 +       fb->info = info;
98 +       fblog_buf_init(&fb->buf);
99 +       fblog_buf_write(&fb->buf, FBLOG_STR("Framebuffer log initialized\n"));
100 +
101 +       if (!try_module_get(info->fbops->owner))
102 +               goto out_killed;
103 +       if (info->fbops->fb_open && info->fbops->fb_open(info, 0))
104 +               goto out_unref;
105 +
106 +       var = info->var;
107 +       mode = fb_find_best_mode(&var, &info->modelist);
108 +       var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
109 +       fb_set_var(info, &var);
110 +
111 +       fb->font = get_default_font(info->var.xres, info->var.yres,
112 +                                   info->pixmap.blit_x,
113 +                                   info->pixmap.blit_y);
114 +       if (fb->font) {
115 +               width = info->var.xres / fb->font->width;
116 +               height = info->var.yres / fb->font->height;
117 +               fblog_buf_resize(&fb->buf, width, height);
118 +       }
119 +
120 +       return;
121 +
122 +out_unref:
123 +       module_put(info->fbops->owner);
124 +out_killed:
125 +       set_bit(FBLOG_KILLED, &fb->flags);
126 +}
127 +
128 +static void fblog_unregister(struct fblog_fb *fb)
129 +{
130 +       struct fb_info *info;
131 +
132 +       if (!fb)
133 +               return;
134 +
135 +       info = fb->info;
136 +       if (!test_bit(FBLOG_KILLED, &fb->flags)) {
137 +               if (info->fbops->fb_release)
138 +                       info->fbops->fb_release(info, 0);
139 +               module_put(info->fbops->owner);
140 +       }
141 +
142 +       fblog_buf_deinit(&fb->buf);
143 +       fblog_fbs[info->node] = NULL;
144 +       kfree(fb);
145 +}
146 +
147  static int __init fblog_init(void)
148  {
149         return 0;
150 -- 
151 1.7.10.4
152