linux/drivers/video/console/sticon.c
<<
>>
Prefs
   1/*
   2 *  linux/drivers/video/console/sticon.c - console driver using HP's STI firmware
   3 *
   4 *      Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
   5 *      Copyright (C) 2002 Helge Deller <deller@gmx.de>
   6 *
   7 *  Based on linux/drivers/video/vgacon.c and linux/drivers/video/fbcon.c,
   8 *  which were
   9 *
  10 *      Created 28 Sep 1997 by Geert Uytterhoeven
  11 *      Rewritten by Martin Mares <mj@ucw.cz>, July 1998
  12 *      Copyright (C) 1991, 1992  Linus Torvalds
  13 *                          1995  Jay Estabrook
  14 *      Copyright (C) 1995 Geert Uytterhoeven
  15 *      Copyright (C) 1993 Bjoern Brauel
  16 *                         Roman Hodek
  17 *      Copyright (C) 1993 Hamish Macdonald
  18 *                         Greg Harp
  19 *      Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  20 *
  21 *            with work by William Rucklidge (wjr@cs.cornell.edu)
  22 *                         Geert Uytterhoeven
  23 *                         Jes Sorensen (jds@kom.auc.dk)
  24 *                         Martin Apel
  25 *            with work by Guenther Kelleter
  26 *                         Martin Schaller
  27 *                         Andreas Schwab
  28 *                         Emmanuel Marty (core@ggi-project.org)
  29 *                         Jakub Jelinek (jj@ultra.linux.cz)
  30 *                         Martin Mares <mj@ucw.cz>
  31 *
  32 *  This file is subject to the terms and conditions of the GNU General Public
  33 *  License.  See the file COPYING in the main directory of this archive for
  34 *  more details.
  35 *
  36 */
  37
  38#include <linux/init.h>
  39#include <linux/kernel.h>
  40#include <linux/console.h>
  41#include <linux/errno.h>
  42#include <linux/vt_kern.h>
  43#include <linux/kd.h>
  44#include <linux/selection.h>
  45#include <linux/module.h>
  46
  47#include <asm/io.h>
  48
  49#include "../fbdev/sticore.h"
  50
  51/* switching to graphics mode */
  52#define BLANK 0
  53static int vga_is_gfx;
  54
  55/* this is the sti_struct used for this console */
  56static struct sti_struct *sticon_sti;
  57
  58/* Software scrollback */
  59static unsigned long softback_buf, softback_curr;
  60static unsigned long softback_in;
  61static unsigned long /* softback_top, */ softback_end;
  62static int softback_lines;
  63
  64/* software cursor */
  65static int cursor_drawn;
  66#define CURSOR_DRAW_DELAY               (1)
  67#define DEFAULT_CURSOR_BLINK_RATE       (20)
  68
  69static int vbl_cursor_cnt;
  70
  71static inline void cursor_undrawn(void)
  72{
  73    vbl_cursor_cnt = 0;
  74    cursor_drawn = 0;
  75}
  76
  77static const char *sticon_startup(void)
  78{
  79    return "STI console";
  80}
  81
  82static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
  83{
  84    int redraw_cursor = 0;
  85
  86    if (vga_is_gfx || console_blanked)
  87            return;
  88
  89    if (conp->vc_mode != KD_TEXT)
  90            return;
  91#if 0
  92    if ((p->cursor_x == xpos) && (p->cursor_y == ypos)) {
  93            cursor_undrawn();
  94            redraw_cursor = 1;
  95    }
  96#endif
  97
  98    sti_putc(sticon_sti, c, ypos, xpos);
  99
 100    if (redraw_cursor)
 101            vbl_cursor_cnt = CURSOR_DRAW_DELAY;
 102}
 103
 104static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
 105                         int count, int ypos, int xpos)
 106{
 107    int redraw_cursor = 0;
 108
 109    if (vga_is_gfx || console_blanked)
 110            return;
 111
 112    if (conp->vc_mode != KD_TEXT)
 113            return;
 114
 115#if 0
 116    if ((p->cursor_y == ypos) && (xpos <= p->cursor_x) &&
 117        (p->cursor_x < (xpos + count))) {
 118            cursor_undrawn();
 119            redraw_cursor = 1;
 120    }
 121#endif
 122
 123    while (count--) {
 124        sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++);
 125    }
 126
 127    if (redraw_cursor)
 128            vbl_cursor_cnt = CURSOR_DRAW_DELAY;
 129}
 130
 131static void sticon_cursor(struct vc_data *conp, int mode)
 132{
 133    unsigned short car1;
 134
 135    car1 = conp->vc_screenbuf[conp->vc_x + conp->vc_y * conp->vc_cols];
 136    switch (mode) {
 137    case CM_ERASE:
 138        sti_putc(sticon_sti, car1, conp->vc_y, conp->vc_x);
 139        break;
 140    case CM_MOVE:
 141    case CM_DRAW:
 142        switch (conp->vc_cursor_type & 0x0f) {
 143        case CUR_UNDERLINE:
 144        case CUR_LOWER_THIRD:
 145        case CUR_LOWER_HALF:
 146        case CUR_TWO_THIRDS:
 147        case CUR_BLOCK:
 148            sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
 149                     conp->vc_y, conp->vc_x);
 150            break;
 151        }
 152        break;
 153    }
 154}
 155
 156static int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
 157{
 158    struct sti_struct *sti = sticon_sti;
 159
 160    if (vga_is_gfx)
 161        return 0;
 162
 163    sticon_cursor(conp, CM_ERASE);
 164
 165    switch (dir) {
 166    case SM_UP:
 167        sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
 168        sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
 169        break;
 170
 171    case SM_DOWN:
 172        sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
 173        sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
 174        break;
 175    }
 176
 177    return 0;
 178}
 179
 180static void sticon_init(struct vc_data *c, int init)
 181{
 182    struct sti_struct *sti = sticon_sti;
 183    int vc_cols, vc_rows;
 184
 185    sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
 186    vc_cols = sti_onscreen_x(sti) / sti->font_width;
 187    vc_rows = sti_onscreen_y(sti) / sti->font_height;
 188    c->vc_can_do_color = 1;
 189    
 190    if (init) {
 191        c->vc_cols = vc_cols;
 192        c->vc_rows = vc_rows;
 193    } else {
 194        /* vc_rows = (c->vc_rows > vc_rows) ? vc_rows : c->vc_rows; */
 195        /* vc_cols = (c->vc_cols > vc_cols) ? vc_cols : c->vc_cols; */
 196        vc_resize(c, vc_cols, vc_rows);
 197/*      vc_resize_con(vc_rows, vc_cols, c->vc_num); */
 198    }
 199}
 200
 201static void sticon_deinit(struct vc_data *c)
 202{
 203}
 204
 205static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
 206                         int width)
 207{
 208    if (!height || !width)
 209        return;
 210
 211    sti_clear(sticon_sti, sy, sx, height, width, conp->vc_video_erase_char);
 212}
 213
 214static int sticon_switch(struct vc_data *conp)
 215{
 216    return 1;   /* needs refreshing */
 217}
 218
 219static int sticon_set_origin(struct vc_data *conp)
 220{
 221    return 0;
 222}
 223
 224static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
 225{
 226    if (blank == 0) {
 227        if (mode_switch)
 228            vga_is_gfx = 0;
 229        return 1;
 230    }
 231    sticon_set_origin(c);
 232    sti_clear(sticon_sti, 0,0, c->vc_rows, c->vc_cols, BLANK);
 233    if (mode_switch)
 234        vga_is_gfx = 1;
 235    return 1;
 236}
 237
 238static u16 *sticon_screen_pos(struct vc_data *conp, int offset)
 239{
 240    int line;
 241    unsigned long p;
 242
 243    if (conp->vc_num != fg_console || !softback_lines)
 244        return (u16 *)(conp->vc_origin + offset);
 245    line = offset / conp->vc_size_row;
 246    if (line >= softback_lines)
 247        return (u16 *)(conp->vc_origin + offset - softback_lines * conp->vc_size_row);
 248    p = softback_curr + offset;
 249    if (p >= softback_end)
 250        p += softback_buf - softback_end;
 251    return (u16 *)p;
 252}
 253
 254static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
 255                                  int *px, int *py)
 256{
 257    int x, y;
 258    unsigned long ret;
 259    if (pos >= conp->vc_origin && pos < conp->vc_scr_end) {
 260        unsigned long offset = (pos - conp->vc_origin) / 2;
 261        
 262        x = offset % conp->vc_cols;
 263        y = offset / conp->vc_cols;
 264        if (conp->vc_num == fg_console)
 265            y += softback_lines;
 266        ret = pos + (conp->vc_cols - x) * 2;
 267    } else if (conp->vc_num == fg_console && softback_lines) {
 268        unsigned long offset = pos - softback_curr;
 269        
 270        if (pos < softback_curr)
 271            offset += softback_end - softback_buf;
 272        offset /= 2;
 273        x = offset % conp->vc_cols;
 274        y = offset / conp->vc_cols;
 275        ret = pos + (conp->vc_cols - x) * 2;
 276        if (ret == softback_end)
 277            ret = softback_buf;
 278        if (ret == softback_in)
 279            ret = conp->vc_origin;
 280    } else {
 281        /* Should not happen */
 282        x = y = 0;
 283        ret = conp->vc_origin;
 284    }
 285    if (px) *px = x;
 286    if (py) *py = y;
 287    return ret;
 288}
 289
 290static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
 291                            u8 blink, u8 underline, u8 reverse, u8 italic)
 292{
 293    u8 attr = ((color & 0x70) >> 1) | ((color & 7));
 294
 295    if (reverse) {
 296        color = ((color >> 3) & 0x7) | ((color & 0x7) << 3);
 297    }
 298
 299    return attr;
 300}
 301
 302static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
 303{
 304    int col = 1; /* vga_can_do_color; */
 305
 306    while (count--) {
 307        u16 a = scr_readw(p);
 308
 309        if (col)
 310                a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
 311        else
 312                a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
 313
 314        scr_writew(a, p++);
 315    }
 316}
 317
 318static void sticon_save_screen(struct vc_data *conp)
 319{
 320}
 321
 322static const struct consw sti_con = {
 323        .owner                  = THIS_MODULE,
 324        .con_startup            = sticon_startup,
 325        .con_init               = sticon_init,
 326        .con_deinit             = sticon_deinit,
 327        .con_clear              = sticon_clear,
 328        .con_putc               = sticon_putc,
 329        .con_putcs              = sticon_putcs,
 330        .con_cursor             = sticon_cursor,
 331        .con_scroll             = sticon_scroll,
 332        .con_switch             = sticon_switch,
 333        .con_blank              = sticon_blank,
 334        .con_set_origin         = sticon_set_origin,
 335        .con_save_screen        = sticon_save_screen, 
 336        .con_build_attr         = sticon_build_attr,
 337        .con_invert_region      = sticon_invert_region, 
 338        .con_screen_pos         = sticon_screen_pos,
 339        .con_getxy              = sticon_getxy,
 340};
 341
 342
 343
 344static int __init sticonsole_init(void)
 345{
 346    int err;
 347    /* already initialized ? */
 348    if (sticon_sti)
 349         return 0;
 350
 351    sticon_sti = sti_get_rom(0);
 352    if (!sticon_sti)
 353        return -ENODEV;
 354
 355    if (conswitchp == &dummy_con) {
 356        printk(KERN_INFO "sticon: Initializing STI text console.\n");
 357        console_lock();
 358        err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1, 1);
 359        console_unlock();
 360        return err;
 361    }
 362    return 0;
 363}
 364
 365module_init(sticonsole_init);
 366MODULE_LICENSE("GPL");
 367