]> err.no Git - linux-2.6/blobdiff - drivers/video/console/fbcon.c
[PATCH] fbcon: Initialize new driver when old driver is released
[linux-2.6] / drivers / video / console / fbcon.c
index 88bd8ef56fde3c8575e8df67a9ad7ef91053ab35..5ff51cd0a2a98c23484a17719ecc1ebe2f19d32a 100644 (file)
@@ -247,9 +247,26 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
        case 2:
                /*
                 * Scale down 16-colors to 4 colors. Default 4-color palette
-                * is grayscale.
+                * is grayscale. However, simply dividing the values by 4
+                * will not work, as colors 1, 2 and 3 will be scaled-down
+                * to zero rendering them invisible.  So empirically convert
+                * colors to a sane 4-level grayscale.
                 */
-               color /= 4;
+               switch (color) {
+               case 0:
+                       color = 0; /* black */
+                       break;
+               case 1 ... 6:
+                       color = 2; /* white */
+                       break;
+               case 7 ... 8:
+                       color = 1; /* gray */
+                       break;
+               default:
+                       color = 3; /* intense white */
+                       break;
+               }
+               break;
        case 3:
                /*
                 * Last 8 entries of default 16-color palette is a more intense
@@ -264,6 +281,18 @@ static inline int get_color(struct vc_data *vc, struct fb_info *info,
        return color;
 }
 
+static void fbcon_update_softback(struct vc_data *vc)
+{
+       int l = fbcon_softback_size / vc->vc_size_row;
+
+       if (l > 5)
+               softback_end = softback_buf + l * vc->vc_size_row;
+       else
+               /* Smaller scrollback makes no sense, and 0 would screw
+                  the operation totally */
+               softback_top = 0;
+}
+
 static void fb_flashcursor(void *private)
 {
        struct fb_info *info = private;
@@ -314,6 +343,35 @@ static void cursor_timer_handler(unsigned long dev_addr)
        mod_timer(&ops->cursor_timer, jiffies + HZ/5);
 }
 
+static void fbcon_add_cursor_timer(struct fb_info *info)
+{
+       struct fbcon_ops *ops = info->fbcon_par;
+
+       if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
+           !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
+               if (!info->queue.func)
+                       INIT_WORK(&info->queue, fb_flashcursor, info);
+
+               init_timer(&ops->cursor_timer);
+               ops->cursor_timer.function = cursor_timer_handler;
+               ops->cursor_timer.expires = jiffies + HZ / 5;
+               ops->cursor_timer.data = (unsigned long ) info;
+               add_timer(&ops->cursor_timer);
+               ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
+       }
+}
+
+static void fbcon_del_cursor_timer(struct fb_info *info)
+{
+       struct fbcon_ops *ops = info->fbcon_par;
+
+       if (info->queue.func == fb_flashcursor &&
+           ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
+               del_timer_sync(&ops->cursor_timer);
+               ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
+       }
+}
+
 #ifndef MODULE
 static int __init fb_console_setup(char *this_opt)
 {
@@ -566,35 +624,26 @@ static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
        }
 
        if (!err) {
-               if (oldinfo->queue.func == fb_flashcursor)
-                       del_timer_sync(&ops->cursor_timer);
-
+               fbcon_del_cursor_timer(oldinfo);
                kfree(ops->cursor_state.mask);
                kfree(ops->cursor_data);
                kfree(oldinfo->fbcon_par);
                oldinfo->fbcon_par = NULL;
                module_put(oldinfo->fbops->owner);
+               /*
+                 If oldinfo and newinfo are driving the same hardware,
+                 the fb_release() method of oldinfo may attempt to
+                 restore the hardware state.  This will leave the
+                 newinfo in an undefined state. Thus, a call to
+                 fb_set_par() may be needed for the newinfo.
+               */
+               if (newinfo->fbops->fb_set_par)
+                       newinfo->fbops->fb_set_par(newinfo);
        }
 
        return err;
 }
 
-static void con2fb_init_newinfo(struct fb_info *info)
-{
-       if (!info->queue.func || info->queue.func == fb_flashcursor) {
-               struct fbcon_ops *ops = info->fbcon_par;
-
-               if (!info->queue.func)
-                       INIT_WORK(&info->queue, fb_flashcursor, info);
-
-               init_timer(&ops->cursor_timer);
-               ops->cursor_timer.function = cursor_timer_handler;
-               ops->cursor_timer.expires = jiffies + HZ / 5;
-               ops->cursor_timer.data = (unsigned long ) info;
-               add_timer(&ops->cursor_timer);
-       }
-}
-
 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
                                int unit, int show_logo)
 {
@@ -678,7 +727,7 @@ static int set_con2fb_map(int unit, int newidx, int user)
                                 logo_shown != FBCON_LOGO_DONTSHOW);
 
                if (!found)
-                       con2fb_init_newinfo(info);
+                       fbcon_add_cursor_timer(info);
                con2fb_map_boot[unit] = newidx;
                con2fb_init_display(vc, info, unit, show_logo);
        }
@@ -739,7 +788,7 @@ static const char *fbcon_startup(void)
        const char *display_desc = "frame buffer device";
        struct display *p = &fb_display[fg_console];
        struct vc_data *vc = vc_cons[fg_console].d;
-       struct font_desc *font = NULL;
+       const struct font_desc *font = NULL;
        struct module *owner;
        struct fb_info *info = NULL;
        struct fbcon_ops *ops;
@@ -813,7 +862,7 @@ static const char *fbcon_startup(void)
                                                info->var.yres);
                vc->vc_font.width = font->width;
                vc->vc_font.height = font->height;
-               vc->vc_font.data = p->fontdata = font->data;
+               vc->vc_font.data = (void *)(p->fontdata = font->data);
                vc->vc_font.charcount = 256; /* FIXME  Need to support more fonts */
        }
 
@@ -881,18 +930,7 @@ static const char *fbcon_startup(void)
        }
 #endif                         /* CONFIG_MAC */
 
-       /* Initialize the work queue. If the driver provides its
-        * own work queue this means it will use something besides 
-        * default timer to flash the cursor. */
-       if (!info->queue.func) {
-               INIT_WORK(&info->queue, fb_flashcursor, info);
-
-               init_timer(&ops->cursor_timer);
-               ops->cursor_timer.function = cursor_timer_handler;
-               ops->cursor_timer.expires = jiffies + HZ / 5;
-               ops->cursor_timer.data = (unsigned long ) info;
-               add_timer(&ops->cursor_timer);
-       }
+       fbcon_add_cursor_timer(info);
        return display_desc;
 }
 
@@ -924,7 +962,7 @@ static void fbcon_init(struct vc_data *vc, int init)
           fb, copy the font from that console */
        t = &fb_display[svc->vc_num];
        if (!vc->vc_font.data) {
-               vc->vc_font.data = p->fontdata = t->fontdata;
+               vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
                vc->vc_font.width = (*default_mode)->vc_font.width;
                vc->vc_font.height = (*default_mode)->vc_font.height;
                p->userfont = t->userfont;
@@ -990,16 +1028,8 @@ static void fbcon_init(struct vc_data *vc, int init)
        if (logo)
                fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
 
-       if (vc == svc && softback_buf) {
-               int l = fbcon_softback_size / vc->vc_size_row;
-               if (l > 5)
-                       softback_end = softback_buf + l * vc->vc_size_row;
-               else {
-                       /* Smaller scrollback makes no sense, and 0 would screw
-                          the operation totally */
-                       softback_top = 0;
-               }
-       }
+       if (vc == svc && softback_buf)
+               fbcon_update_softback(vc);
 }
 
 static void fbcon_deinit(struct vc_data *vc)
@@ -1171,7 +1201,7 @@ static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
                return;
        t = &fb_display[svc->vc_num];
        if (!vc->vc_font.data) {
-               vc->vc_font.data = p->fontdata = t->fontdata;
+               vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
                vc->vc_font.width = (*default_mode)->vc_font.width;
                vc->vc_font.height = (*default_mode)->vc_font.height;
                p->userfont = t->userfont;
@@ -1206,18 +1236,8 @@ static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
        vc_resize(vc, cols, rows);
        if (CON_IS_VISIBLE(vc)) {
                update_screen(vc);
-               if (softback_buf) {
-                       int l = fbcon_softback_size / vc->vc_size_row;
-
-                       if (l > 5)
-                               softback_end = softback_buf + l *
-                                       vc->vc_size_row;
-                       else {
-                               /* Smaller scrollback makes no sense, and 0
-                                  would screw the operation totally */
-                               softback_top = 0;
-                       }
-               }
+               if (softback_buf)
+                       fbcon_update_softback(vc);
        }
 }
 
@@ -1670,6 +1690,8 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
        case SM_DOWN:
                if (count > vc->vc_rows)        /* Maximum realistic size */
                        count = vc->vc_rows;
+               if (logo_shown >= 0)
+                       goto redraw_down;
                switch (p->scrollmode) {
                case SCROLL_MOVE:
                        ops->bmove(vc, info, t, 0, t + count, 0,
@@ -1873,24 +1895,11 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
                mode = fb_find_best_mode(&var, &info->modelist);
                if (mode == NULL)
                        return -EINVAL;
+               display_to_var(&var, p);
                fb_videomode_to_var(&var, mode);
+
                if (width > var.xres/fw || height > var.yres/fh)
                        return -EINVAL;
-               /*
-                * The following can probably have any value... Do we need to
-                * set all of them?
-                */
-               var.bits_per_pixel = p->bits_per_pixel;
-               var.xres_virtual = p->xres_virtual;
-               var.yres_virtual = p->yres_virtual;
-               var.accel_flags = p->accel_flags;
-               var.width = p->width;
-               var.height = p->height;
-               var.red = p->red;
-               var.green = p->green;
-               var.blue = p->blue;
-               var.transp = p->transp;
-               var.nonstd = p->nonstd;
 
                DPRINTK("resize now %ix%i\n", var.xres, var.yres);
                if (CON_IS_VISIBLE(vc)) {
@@ -1906,7 +1915,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
 
 static int fbcon_switch(struct vc_data *vc)
 {
-       struct fb_info *info;
+       struct fb_info *info, *old_info = NULL;
        struct display *p = &fb_display[vc->vc_num];
        struct fb_var_screeninfo var;
        int i, prev_console;
@@ -1914,19 +1923,11 @@ static int fbcon_switch(struct vc_data *vc)
        info = registered_fb[con2fb_map[vc->vc_num]];
 
        if (softback_top) {
-               int l = fbcon_softback_size / vc->vc_size_row;
                if (softback_lines)
                        fbcon_set_origin(vc);
                softback_top = softback_curr = softback_in = softback_buf;
                softback_lines = 0;
-
-               if (l > 5)
-                       softback_end = softback_buf + l * vc->vc_size_row;
-               else {
-                       /* Smaller scrollback makes no sense, and 0 would screw
-                          the operation totally */
-                       softback_top = 0;
-               }
+               fbcon_update_softback(vc);
        }
 
        if (logo_shown >= 0) {
@@ -1939,7 +1940,8 @@ static int fbcon_switch(struct vc_data *vc)
        }
 
        prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon;
-
+       if (prev_console != -1)
+               old_info = registered_fb[con2fb_map[prev_console]];
        /*
         * FIXME: If we have multiple fbdev's loaded, we need to
         * update all info->currcon.  Perhaps, we can place this
@@ -1967,10 +1969,12 @@ static int fbcon_switch(struct vc_data *vc)
        info->var.yoffset = info->var.xoffset = p->yscroll = 0;
        fb_set_var(info, &var);
 
-       if (prev_console != -1 &&
-           registered_fb[con2fb_map[prev_console]] != info &&
-           info->fbops->fb_set_par)
-               info->fbops->fb_set_par(info);
+       if (old_info != NULL && old_info != info) {
+               if (info->fbops->fb_set_par)
+                       info->fbops->fb_set_par(info);
+               fbcon_del_cursor_timer(old_info);
+               fbcon_add_cursor_timer(info);
+       }
 
        set_blitting_type(vc, info, p);
        ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1;
@@ -2056,11 +2060,16 @@ static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
                                fbcon_generic_blank(vc, info, blank);
                }
 
-               if (!blank)
-                       update_screen(vc);
-       }
+               if (!blank)
+                       update_screen(vc);
+       }
+
+       if (!blank)
+               fbcon_add_cursor_timer(info);
+       else
+               fbcon_del_cursor_timer(info);
 
-       return 0;
+       return 0;
 }
 
 static void fbcon_free_font(struct display *p)
@@ -2123,7 +2132,7 @@ static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
 }
 
 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
-                            u8 * data, int userfont)
+                            const u8 * data, int userfont)
 {
        struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
        struct display *p = &fb_display[vc->vc_num];
@@ -2141,7 +2150,7 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
                cnt = FNTCHARCNT(data);
        else
                cnt = 256;
-       vc->vc_font.data = p->fontdata = data;
+       vc->vc_font.data = (void *)(p->fontdata = data);
        if ((p->userfont = userfont))
                REFCOUNT(data)++;
        vc->vc_font.width = w;
@@ -2208,17 +2217,8 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
                /* reset wrap/pan */
                info->var.xoffset = info->var.yoffset = p->yscroll = 0;
                vc_resize(vc, info->var.xres / w, info->var.yres / h);
-               if (CON_IS_VISIBLE(vc) && softback_buf) {
-                       int l = fbcon_softback_size / vc->vc_size_row;
-                       if (l > 5)
-                               softback_end =
-                                   softback_buf + l * vc->vc_size_row;
-                       else {
-                               /* Smaller scrollback makes no sense, and 0 would screw
-                                  the operation totally */
-                               softback_top = 0;
-                       }
-               }
+               if (CON_IS_VISIBLE(vc) && softback_buf)
+                       fbcon_update_softback(vc);
        } else if (CON_IS_VISIBLE(vc)
                   && vc->vc_mode == KD_TEXT) {
                fbcon_clear_margins(vc, 0);
@@ -2298,7 +2298,7 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigne
                    tmp->vc_font.width == w &&
                    !memcmp(fb_display[i].fontdata, new_data, size)) {
                        kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
-                       new_data = fb_display[i].fontdata;
+                       new_data = (u8 *)fb_display[i].fontdata;
                        break;
                }
        }
@@ -2308,7 +2308,7 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigne
 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
 {
        struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
-       struct font_desc *f;
+       const struct font_desc *f;
 
        if (!name)
                f = get_default_font(info->var.xres, info->var.yres);
@@ -2588,16 +2588,8 @@ static void fbcon_modechanged(struct fb_info *info)
                update_var(vc->vc_num, info);
                fbcon_set_palette(vc, color_table);
                update_screen(vc);
-               if (softback_buf) {
-                       int l = fbcon_softback_size / vc->vc_size_row;
-                       if (l > 5)
-                               softback_end = softback_buf + l * vc->vc_size_row;
-                       else {
-                               /* Smaller scrollback makes no sense, and 0
-                                  would screw the operation totally */
-                               softback_top = 0;
-                       }
-               }
+               if (softback_buf)
+                       fbcon_update_softback(vc);
        }
 }
 
@@ -2632,16 +2624,8 @@ static void fbcon_set_all_vcs(struct fb_info *info)
                        update_var(vc->vc_num, info);
                        fbcon_set_palette(vc, color_table);
                        update_screen(vc);
-                       if (softback_buf) {
-                               int l = fbcon_softback_size / vc->vc_size_row;
-                               if (l > 5)
-                                       softback_end = softback_buf + l * vc->vc_size_row;
-                               else {
-                                       /* Smaller scrollback makes no sense, and 0
-                                          would screw the operation totally */
-                                       softback_top = 0;
-                               }
-                       }
+                       if (softback_buf)
+                               fbcon_update_softback(vc);
                }
        }
 }