ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / video / pmag-ba-fb.c
1 /*
2  *      linux/drivers/video/pmag-ba-fb.c
3  *
4  *      PMAG-BA TurboChannel framebuffer card support ... derived from:
5  *      "HP300 Topcat framebuffer support (derived from macfb of all things)
6  *      Phil Blundell <philb@gnu.org> 1998", the original code can be
7  *      found in the file hpfb.c in the same directory.
8  *
9  *      Based on digital document:
10  *      "PMAG-BA TURBOchannel Color Frame Buffer
11  *       Functional Specification", Revision 1.2, August 27, 1990
12  *
13  *      DECstation related code Copyright (C) 1999, 2000, 2001 by
14  *      Michael Engel <engel@unix-ag.org>, 
15  *      Karsten Merker <merker@linuxtag.org> and
16  *      Harald Koerfgen.
17  *      This file is subject to the terms and conditions of the GNU General
18  *      Public License.  See the file COPYING in the main directory of this
19  *      archive for more details.
20  *
21  */
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/errno.h>
26 #include <linux/string.h>
27 #include <linux/timer.h>
28 #include <linux/mm.h>
29 #include <linux/tty.h>
30 #include <linux/slab.h>
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/fb.h>
34 #include <asm/bootinfo.h>
35 #include <asm/dec/machtype.h>
36 #include <asm/dec/tc.h>
37 #include <video/pmag-ba-fb.h>
38
39 struct pmag_ba_ramdac_regs {
40         unsigned char addr_low;
41         unsigned char pad0[3];
42         unsigned char addr_hi;
43         unsigned char pad1[3];
44         unsigned char data;
45         unsigned char pad2[3];
46         unsigned char cmap;
47 };
48
49 /*
50  * Max 3 TURBOchannel slots -> max 3 PMAG-BA :)
51  */
52 static struct fb_info pmagba_fb_info[3];
53
54 static struct fb_var_screeninfo pmagbafb_defined = {
55         .xres           = 1024,
56         .yres           = 864,
57         .xres_virtual   = 1024,
58         .yres_virtual   = 864,
59         .bits_per_pixel = 8,
60         .red.length     = 8,
61         .green.length   = 8,
62         .blue.length    = 8,
63         .activate       = FB_ACTIVATE_NOW, 
64         .height         = 274,  
65         .width          = 195,
66         .accel          = FB_ACCEL_NONE,
67         .vmode          = FB_VMODE_NONINTERLACED,
68 };
69
70 static struct fb_fix_screeninfo pmagbafb_fix = {
71         .id             = "PMAG-BA",
72         .smem_len       = (1024 * 864),
73         .type           = FB_TYPE_PACKED_PIXELS,
74         .visual         = FB_VISUAL_PSEUDOCOLOR,
75         .line_length    = 1024,
76 };
77
78 /*
79  * Turn hardware cursor off
80  */
81 void pmagbafb_erase_cursor(struct pmag_ba_ramdac_regs *bt459_regs)
82 {
83         bt459_regs->addr_low = 0;
84         bt459_regs->addr_hi = 3;
85         bt459_regs->data = 0;
86 }
87
88 /*
89  * Set the palette. 
90  */
91 static int pmagbafb_setcolreg(unsigned regno, unsigned red, unsigned green,
92                               unsigned blue, unsigned transp,
93                               struct fb_info *info)
94 {
95         struct pmag_ba_ramdac_regs *bt459_regs = (struct pmag_ba_ramdac_regs *) info->par; 
96
97         if (regno >= info->cmap.len)
98                 return 1;
99
100         red   >>= 8;    /* The cmap fields are 16 bits    */
101         green >>= 8;    /* wide, but the harware colormap */
102         blue  >>= 8;    /* registers are only 8 bits wide */
103
104         bt459_regs->addr_low = (__u8) regno;
105         bt459_regs->addr_hi = 0;
106         bt459_regs->cmap = red;
107         bt459_regs->cmap = green;
108         bt459_regs->cmap = blue;
109         return 0;
110 }
111
112 static struct fb_ops pmagbafb_ops = {
113         .owner          = THIS_MODULE,
114         .fb_setcolreg   = pmagbafb_setcolreg,
115         .fb_fillrect    = cfb_fillrect,
116         .fb_copyarea    = cfb_copyarea,
117         .fb_imageblit   = cfb_imageblit,
118         .fb_cursor      = soft_cursor,
119 };
120
121 int __init pmagbafb_init_one(int slot)
122 {
123         unsigned long base_addr = get_tc_base_addr(slot);
124         struct fb_info *info = &pmagba_fb_info[slot]; 
125
126         printk("PMAG-BA framebuffer in slot %d\n", slot);
127         /*
128          * Framebuffer display memory base address and friends
129          */
130         pmagbafb_fix.smem_start = base_addr + PMAG_BA_ONBOARD_FBMEM_OFFSET;
131         info->par = (base_addr + PMAG_BA_BT459_OFFSET);
132
133         /*
134          * Configure the Bt459 RAM DAC
135          */
136         pmagbafb_erase_cursor((struct pmag_ba_ramdac_regs *) info->par);
137
138         /*
139          *      Let there be consoles..
140          */
141         info->fbops = &pmagbafb_ops;
142         info->var = pmagbafb_defined;
143         info->fix = pmagbafb_fix; 
144         info->screen_base = pmagbafb_fix.smem_start;
145         info->flags = FBINFO_FLAG_DEFAULT;
146
147         fb_alloc_cmap(&fb_info.cmap, 256, 0);
148         
149         if (register_framebuffer(info) < 0)
150                 return 1;
151         return 0;
152 }
153
154 /* 
155  * Initialise the framebuffer
156  */
157
158 int __init pmagbafb_init(void)
159 {
160         int sid;
161         int found = 0;
162
163         if (TURBOCHANNEL) {
164                 while ((sid = search_tc_card("PMAG-BA")) >= 0) {
165                         found = 1;
166                         claim_tc_card(sid);
167                         pmagbafb_init_one(sid);
168                 }
169                 return found ? 0 : -ENODEV;
170         } else {
171                 return -ENODEV;
172         }
173 }
174
175 MODULE_LICENSE("GPL");