linux/drivers/video/pmag-aa-fb.c
<<
>>
Prefs
   1/*
   2 *      linux/drivers/video/pmag-aa-fb.c
   3 *      Copyright 2002 Karsten Merker <merker@debian.org>
   4 *
   5 *      PMAG-AA TurboChannel framebuffer card support ... derived from
   6 *      pmag-ba-fb.c, which is Copyright (C) 1999, 2000, 2001 by
   7 *      Michael Engel <engel@unix-ag.org>, Karsten Merker <merker@debian.org>
   8 *      and Harald Koerfgen <hkoerfg@web.de>, which itself is derived from
   9 *      "HP300 Topcat framebuffer support (derived from macfb of all things)
  10 *      Phil Blundell <philb@gnu.org> 1998"
  11 *
  12 *      This file is subject to the terms and conditions of the GNU General
  13 *      Public License.  See the file COPYING in the main directory of this
  14 *      archive for more details.
  15 *
  16 *      2002-09-28  Karsten Merker <merker@linuxtag.org>
  17 *              Version 0.01: First try to get a PMAG-AA running.
  18 *
  19 *      2003-02-24  Thiemo Seufer  <seufer@csv.ica.uni-stuttgart.de>
  20 *              Version 0.02: Major code cleanup.
  21 *
  22 *      2003-09-21  Thiemo Seufer  <seufer@csv.ica.uni-stuttgart.de>
  23 *              Hardware cursor support.
  24 */
  25#include <linux/module.h>
  26#include <linux/kernel.h>
  27#include <linux/errno.h>
  28#include <linux/string.h>
  29#include <linux/timer.h>
  30#include <linux/mm.h>
  31#include <linux/slab.h>
  32#include <linux/delay.h>
  33#include <linux/init.h>
  34#include <linux/fb.h>
  35#include <linux/console.h>
  36
  37#include <asm/bootinfo.h>
  38#include <asm/dec/machtype.h>
  39#include <asm/dec/tc.h>
  40
  41#include <video/fbcon.h>
  42#include <video/fbcon-cfb8.h>
  43
  44#include "bt455.h"
  45#include "bt431.h"
  46
  47/* Version information */
  48#define DRIVER_VERSION "0.02"
  49#define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>"
  50#define DRIVER_DESCRIPTION "PMAG-AA Framebuffer Driver"
  51
  52/* Prototypes */
  53static int aafb_set_var(struct fb_var_screeninfo *var, int con,
  54                        struct fb_info *info);
  55
  56/*
  57 * Bt455 RAM DAC register base offset (rel. to TC slot base address).
  58 */
  59#define PMAG_AA_BT455_OFFSET            0x100000
  60
  61/*
  62 * Bt431 cursor generator offset (rel. to TC slot base address).
  63 */
  64#define PMAG_AA_BT431_OFFSET            0x180000
  65
  66/*
  67 * Begin of PMAG-AA framebuffer memory relative to TC slot address,
  68 * resolution is 1280x1024x1 (8 bits deep, but only LSB is used).
  69 */
  70#define PMAG_AA_ONBOARD_FBMEM_OFFSET    0x200000
  71
  72struct aafb_cursor {
  73        struct timer_list timer;
  74        int enable;
  75        int on;
  76        int vbl_cnt;
  77        int blink_rate;
  78        u16 x, y, width, height;
  79};
  80
  81#define CURSOR_TIMER_FREQ       (HZ / 50)
  82#define CURSOR_BLINK_RATE       (20)
  83#define CURSOR_DRAW_DELAY       (2)
  84
  85struct aafb_info {
  86        struct fb_info info;
  87        struct display disp;
  88        struct aafb_cursor cursor;
  89        struct bt455_regs *bt455;
  90        struct bt431_regs *bt431;
  91        unsigned long fb_start;
  92        unsigned long fb_size;
  93        unsigned long fb_line_length;
  94};
  95
  96/*
  97 * Max 3 TURBOchannel slots -> max 3 PMAG-AA.
  98 */
  99static struct aafb_info my_fb_info[3];
 100
 101static struct aafb_par {
 102} current_par;
 103
 104static int currcon = -1;
 105
 106static void aafb_set_cursor(struct aafb_info *info, int on)
 107{
 108        struct aafb_cursor *c = &info->cursor;
 109
 110        if (on) {
 111                bt431_position_cursor(info->bt431, c->x, c->y);
 112                bt431_enable_cursor(info->bt431);
 113        } else
 114                bt431_erase_cursor(info->bt431);
 115}
 116
 117static void aafbcon_cursor(struct display *disp, int mode, int x, int y)
 118{
 119        struct aafb_info *info = (struct aafb_info *)disp->fb_info;
 120        struct aafb_cursor *c = &info->cursor;
 121
 122        x *= fontwidth(disp);
 123        y *= fontheight(disp);
 124
 125        if (c->x == x && c->y == y && (mode == CM_ERASE) == !c->enable)
 126                return;
 127
 128        c->enable = 0;
 129        if (c->on)
 130                aafb_set_cursor(info, 0);
 131        c->x = x - disp->var.xoffset;
 132        c->y = y - disp->var.yoffset;
 133
 134        switch (mode) {
 135                case CM_ERASE:
 136                        c->on = 0;
 137                        break;
 138                case CM_DRAW:
 139                case CM_MOVE:
 140                        if (c->on)
 141                                aafb_set_cursor(info, c->on);
 142                        else
 143                                c->vbl_cnt = CURSOR_DRAW_DELAY;
 144                        c->enable = 1;
 145                        break;
 146        }
 147}
 148
 149static int aafbcon_set_font(struct display *disp, int width, int height)
 150{
 151        struct aafb_info *info = (struct aafb_info *)disp->fb_info;
 152        struct aafb_cursor *c = &info->cursor;
 153        u8 fgc = ~attr_bgcol_ec(disp, disp->conp, &info->info);
 154
 155        if (width > 64 || height > 64 || width < 0 || height < 0)
 156                return -EINVAL;
 157
 158        c->height = height;
 159        c->width = width;
 160
 161        bt431_set_font(info->bt431, fgc, width, height);
 162
 163        return 1;
 164}
 165
 166static void aafb_cursor_timer_handler(unsigned long data)
 167{
 168        struct aafb_info *info = (struct aafb_info *)data;
 169        struct aafb_cursor *c = &info->cursor;
 170
 171        if (!c->enable)
 172                goto out;
 173
 174        if (c->vbl_cnt && --c->vbl_cnt == 0) {
 175                c->on ^= 1;
 176                aafb_set_cursor(info, c->on);
 177                c->vbl_cnt = c->blink_rate;
 178        }
 179
 180out:
 181        c->timer.expires = jiffies + CURSOR_TIMER_FREQ;
 182        add_timer(&c->timer);
 183}
 184
 185static void __init aafb_cursor_init(struct aafb_info *info)
 186{
 187        struct aafb_cursor *c = &info->cursor;
 188
 189        c->enable = 1;
 190        c->on = 1;
 191        c->x = c->y = 0;
 192        c->width = c->height = 0;
 193        c->vbl_cnt = CURSOR_DRAW_DELAY;
 194        c->blink_rate = CURSOR_BLINK_RATE;
 195
 196        init_timer(&c->timer);
 197        c->timer.data = (unsigned long)info;
 198        c->timer.function = aafb_cursor_timer_handler;
 199        mod_timer(&c->timer, jiffies + CURSOR_TIMER_FREQ);
 200}
 201
 202static void __exit aafb_cursor_exit(struct aafb_info *info)
 203{
 204        struct aafb_cursor *c = &info->cursor;
 205
 206        del_timer_sync(&c->timer);
 207}
 208
 209static struct display_switch aafb_switch8 = {
 210        .setup = fbcon_cfb8_setup,
 211        .bmove = fbcon_cfb8_bmove,
 212        .clear = fbcon_cfb8_clear,
 213        .putc = fbcon_cfb8_putc,
 214        .putcs = fbcon_cfb8_putcs,
 215        .revc = fbcon_cfb8_revc,
 216        .cursor = aafbcon_cursor,
 217        .set_font = aafbcon_set_font,
 218        .clear_margins = fbcon_cfb8_clear_margins,
 219        .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
 220};
 221
 222static void aafb_get_par(struct aafb_par *par)
 223{
 224        *par = current_par;
 225}
 226
 227static int aafb_get_fix(struct fb_fix_screeninfo *fix, int con,
 228                        struct fb_info *info)
 229{
 230        struct aafb_info *ip = (struct aafb_info *)info;
 231
 232        memset(fix, 0, sizeof(struct fb_fix_screeninfo));
 233        strcpy(fix->id, "PMAG-AA");
 234        fix->smem_start = ip->fb_start;
 235        fix->smem_len = ip->fb_size;
 236        fix->type = FB_TYPE_PACKED_PIXELS;
 237        fix->ypanstep = 1;
 238        fix->ywrapstep = 1;
 239        fix->visual = FB_VISUAL_MONO10;
 240        fix->line_length = 1280;
 241        fix->accel = FB_ACCEL_NONE;
 242
 243        return 0;
 244}
 245
 246static void aafb_set_disp(struct display *disp, int con,
 247                          struct aafb_info *info)
 248{
 249        struct fb_fix_screeninfo fix;
 250
 251        disp->fb_info = &info->info;
 252        aafb_set_var(&disp->var, con, &info->info);
 253        if (disp->conp && disp->conp->vc_sw && disp->conp->vc_sw->con_cursor)
 254                disp->conp->vc_sw->con_cursor(disp->conp, CM_ERASE);
 255        disp->dispsw = &aafb_switch8;
 256        disp->dispsw_data = 0;
 257
 258        aafb_get_fix(&fix, con, &info->info);
 259        disp->screen_base = (u8 *) fix.smem_start;
 260        disp->visual = fix.visual;
 261        disp->type = fix.type;
 262        disp->type_aux = fix.type_aux;
 263        disp->ypanstep = fix.ypanstep;
 264        disp->ywrapstep = fix.ywrapstep;
 265        disp->line_length = fix.line_length;
 266        disp->next_line = 2048;
 267        disp->can_soft_blank = 1;
 268        disp->inverse = 0;
 269        disp->scrollmode = SCROLL_YREDRAW;
 270
 271        aafbcon_set_font(disp, fontwidth(disp), fontheight(disp));
 272}
 273
 274static int aafb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
 275                         struct fb_info *info)
 276{
 277        static u16 color[2] = {0x0000, 0x000f};
 278        static struct fb_cmap aafb_cmap = {0, 2, color, color, color, NULL};
 279
 280        fb_copy_cmap(&aafb_cmap, cmap, kspc ? 0 : 2);
 281        return 0;
 282}
 283
 284static int aafb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
 285                         struct fb_info *info)
 286{
 287        u16 color[2] = {0x0000, 0x000f};
 288
 289        if (cmap->start == 0
 290            && cmap->len == 2
 291            && memcmp(cmap->red, color, sizeof(color)) == 0
 292            && memcmp(cmap->green, color, sizeof(color)) == 0
 293            && memcmp(cmap->blue, color, sizeof(color)) == 0
 294            && cmap->transp == NULL)
 295                return 0;
 296        else
 297                return -EINVAL;
 298}
 299
 300static int aafb_ioctl(struct fb_info *info, u32 cmd, unsigned long arg)
 301{
 302        /* TODO: Not yet implemented */
 303        return -ENOIOCTLCMD;
 304}
 305
 306static int aafb_switch(int con, struct fb_info *info)
 307{
 308        struct aafb_info *ip = (struct aafb_info *)info;
 309        struct display *old = (currcon < 0) ? &ip->disp : (fb_display + currcon);
 310        struct display *new = (con < 0) ? &ip->disp : (fb_display + con);
 311
 312        if (old->conp && old->conp->vc_sw && old->conp->vc_sw->con_cursor)
 313                old->conp->vc_sw->con_cursor(old->conp, CM_ERASE);
 314
 315        /* Set the current console. */
 316        currcon = con;
 317        aafb_set_disp(new, con, ip);
 318
 319        return 0;
 320}
 321
 322static void aafb_encode_var(struct fb_var_screeninfo *var,
 323                            struct aafb_par *par)
 324{
 325        var->xres = 1280;
 326        var->yres = 1024;
 327        var->xres_virtual = 2048;
 328        var->yres_virtual = 1024;
 329        var->xoffset = 0;
 330        var->yoffset = 0;
 331        var->bits_per_pixel = 8;
 332        var->grayscale = 1;
 333        var->red.offset = 0;
 334        var->red.length = 0;
 335        var->red.msb_right = 0;
 336        var->green.offset = 0;
 337        var->green.length = 1;
 338        var->green.msb_right = 0;
 339        var->blue.offset = 0;
 340        var->blue.length = 0;
 341        var->blue.msb_right = 0;
 342        var->transp.offset = 0;
 343        var->transp.length = 0;
 344        var->transp.msb_right = 0;
 345        var->nonstd = 0;
 346        var->activate &= ~FB_ACTIVATE_MASK & FB_ACTIVATE_NOW;
 347        var->accel_flags = 0;
 348        var->sync = FB_SYNC_ON_GREEN;
 349        var->vmode &= ~FB_VMODE_MASK & FB_VMODE_NONINTERLACED;
 350}
 351
 352static int aafb_get_var(struct fb_var_screeninfo *var, int con,
 353                        struct fb_info *info)
 354{
 355        if (con < 0) {
 356                struct aafb_par par;
 357
 358                memset(var, 0, sizeof(struct fb_var_screeninfo));
 359                aafb_get_par(&par);
 360                aafb_encode_var(var, &par);
 361        } else
 362                *var = info->var;
 363
 364        return 0;
 365}
 366
 367static int aafb_set_var(struct fb_var_screeninfo *var, int con,
 368                        struct fb_info *info)
 369{
 370        struct aafb_par par;
 371
 372        aafb_get_par(&par);
 373        aafb_encode_var(var, &par);
 374        info->var = *var;
 375
 376        return 0;
 377}
 378
 379static int aafb_update_var(int con, struct fb_info *info)
 380{
 381        struct aafb_info *ip = (struct aafb_info *)info;
 382        struct display *disp = (con < 0) ? &ip->disp : (fb_display + con);
 383
 384        if (con == currcon)
 385                aafbcon_cursor(disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
 386
 387        return 0;
 388}
 389
 390/* 0 unblanks, any other blanks. */
 391
 392static void aafb_blank(int blank, struct fb_info *info)
 393{
 394        struct aafb_info *ip = (struct aafb_info *)info;
 395        u8 val = blank ? 0x00 : 0x0f;
 396
 397        bt455_write_cmap_entry(ip->bt455, 1, val, val, val);
 398        aafbcon_cursor(&ip->disp, CM_ERASE, ip->cursor.x, ip->cursor.y);
 399}
 400
 401static struct fb_ops aafb_ops = {
 402        .owner = THIS_MODULE,
 403        .fb_get_fix = aafb_get_fix,
 404        .fb_get_var = aafb_get_var,
 405        .fb_set_var = aafb_set_var,
 406        .fb_get_cmap = aafb_get_cmap,
 407        .fb_set_cmap = aafb_set_cmap,
 408        .fb_ioctl = aafb_ioctl
 409};
 410
 411static int __init init_one(int slot)
 412{
 413        unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot));
 414        struct aafb_info *ip = &my_fb_info[slot];
 415
 416        memset(ip, 0, sizeof(struct aafb_info));
 417
 418        /*
 419         * Framebuffer display memory base address and friends.
 420         */
 421        ip->bt455 = (struct bt455_regs *) (base_addr + PMAG_AA_BT455_OFFSET);
 422        ip->bt431 = (struct bt431_regs *) (base_addr + PMAG_AA_BT431_OFFSET);
 423        ip->fb_start = base_addr + PMAG_AA_ONBOARD_FBMEM_OFFSET;
 424        ip->fb_size = 2048 * 1024; /* fb_fix_screeninfo.smem_length
 425                                      seems to be physical */
 426        ip->fb_line_length = 2048;
 427
 428        /*
 429         * Let there be consoles..
 430         */
 431        strcpy(ip->info.modename, "PMAG-AA");
 432        ip->info.node = -1;
 433        ip->info.flags = FBINFO_FLAG_DEFAULT;
 434        ip->info.fbops = &aafb_ops;
 435        ip->info.disp = &ip->disp;
 436        ip->info.changevar = NULL;
 437        ip->info.switch_con = &aafb_switch;
 438        ip->info.updatevar = &aafb_update_var;
 439        ip->info.blank = &aafb_blank;
 440
 441        aafb_set_disp(&ip->disp, currcon, ip);
 442
 443        /*
 444         * Configure the RAM DACs.
 445         */
 446        bt455_erase_cursor(ip->bt455);
 447
 448        /* Init colormap. */
 449        bt455_write_cmap_entry(ip->bt455, 0, 0x00, 0x00, 0x00);
 450        bt455_write_cmap_entry(ip->bt455, 1, 0x0f, 0x0f, 0x0f);
 451
 452        /* Init hardware cursor. */
 453        bt431_init_cursor(ip->bt431);
 454        aafb_cursor_init(ip);
 455
 456        /* Clear the screen. */
 457        memset ((void *)ip->fb_start, 0, ip->fb_size);
 458
 459        if (register_framebuffer(&ip->info) < 0)
 460                return -EINVAL;
 461
 462        printk(KERN_INFO "fb%d: %s frame buffer in TC slot %d\n",
 463               GET_FB_IDX(ip->info.node), ip->info.modename, slot);
 464
 465        return 0;
 466}
 467
 468static int __exit exit_one(int slot)
 469{
 470        struct aafb_info *ip = &my_fb_info[slot];
 471
 472        if (unregister_framebuffer(&ip->info) < 0)
 473                return -EINVAL;
 474
 475        return 0;
 476}
 477
 478/*
 479 * Initialise the framebuffer.
 480 */
 481int __init pmagaafb_init(void)
 482{
 483        int sid;
 484        int found = 0;
 485
 486        while ((sid = search_tc_card("PMAG-AA")) >= 0) {
 487                found = 1;
 488                claim_tc_card(sid);
 489                init_one(sid);
 490        }
 491
 492        return found ? 0 : -ENXIO;
 493}
 494
 495static void __exit pmagaafb_exit(void)
 496{
 497        int sid;
 498
 499        while ((sid = search_tc_card("PMAG-AA")) >= 0) {
 500                exit_one(sid);
 501                release_tc_card(sid);
 502        }
 503}
 504
 505MODULE_AUTHOR(DRIVER_AUTHOR);
 506MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
 507MODULE_LICENSE("GPL");
 508#ifdef MODULE
 509module_init(pmagaafb_init);
 510module_exit(pmagaafb_exit);
 511#endif
 512