vserver 1.9.3
[linux-2.6.git] / drivers / video / hpfb.c
1 /*
2  *      HP300 Topcat framebuffer support (derived from macfb of all things)
3  *      Phil Blundell <philb@gnu.org> 1998
4  */
5
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/errno.h>
10 #include <linux/string.h>
11 #include <linux/mm.h>
12 #include <linux/tty.h>
13 #include <linux/slab.h>
14 #include <linux/delay.h>
15 #include <linux/init.h>
16 #include <linux/fb.h>
17 #include <linux/dio.h>
18 #include <asm/io.h>
19 #include <asm/blinken.h>
20 #include <asm/hwtest.h>
21
22 static struct fb_info fb_info;
23
24 unsigned long fb_regs;
25 unsigned char fb_bitmask;
26
27 #define TC_WEN          0x4088
28 #define TC_REN          0x408c
29 #define TC_FBEN         0x4090
30 #define TC_NBLANK       0x4080
31
32 /* blitter regs */
33 #define BUSY            0x4044
34 #define WMRR            0x40ef
35 #define SOURCE_X        0x40f2
36 #define SOURCE_Y        0x40f6
37 #define DEST_X          0x40fa
38 #define DEST_Y          0x40fe
39 #define WHEIGHT         0x4106
40 #define WWIDTH          0x4102
41 #define WMOVE           0x409c
42
43 static struct fb_fix_screeninfo hpfb_fix __initdata = {
44         .id             = "HP300 Topcat",
45         .smem_len       = 1024*768,
46         .type           = FB_TYPE_PACKED_PIXELS,
47         .visual         = FB_VISUAL_PSEUDOCOLOR,
48         .line_length    = 1024,
49         .accel          = FB_ACCEL_NONE,
50 };
51
52 static struct fb_var_screeninfo hpfb_defined = {
53         .xres           = 1024,
54         .yres           = 768,
55         .xres_virtual   = 1024,
56         .yres_virtual   = 786,
57         .bits_per_pixel = 1,
58         .red            = {0,2,0},      /* R */
59         .green          = {0,2,0},      /* G */
60         .blue           = {0,2,0},      /* B */
61         .activate       = FB_ACTIVATE_NOW,
62         .height         = 274,
63         .width          = 195,  /* 14" monitor */
64         .accel_flags    = FB_ACCEL_NONE,
65         .vmode          = FB_VMODE_NONINTERLACED,
66 };
67
68 /*
69  * Set the palette.  This may not work on all boards but only experimentation 
70  * will tell.
71  * XXX Doesn't work at all.
72  */
73 static int hpfb_setcolreg(unsigned regno, unsigned red, unsigned green,
74                            unsigned blue, unsigned transp,
75                            struct fb_info *info)
76 {
77         while (in_be16(fb_regs + 0x6002) & 0x4) udelay(1);
78         out_be16(fb_regs + 0x60f0, 0);
79         out_be16(fb_regs + 0x60b8, regno);
80         out_be16(fb_regs + 0x60b2, red);
81         out_be16(fb_regs + 0x60b4, green);
82         out_be16(fb_regs + 0x60b6, blue);
83         out_be16(fb_regs + 0x60f0, 0xff);
84         udelay(100);
85         out_be16(fb_regs + 0x60ba, 0xffff);
86         return 0;
87 }
88
89 void hpfb_copyarea(struct fb_info *info, const struct fb_copyarea *area) 
90 {
91         while (in_8(fb_regs + BUSY) & fb_bitmask);
92         out_8(fb_regs + WMRR, 0x3);
93         out_be16(fb_regs + SOURCE_X, area->sx);
94         out_be16(fb_regs + SOURCE_Y, area->sy);
95         out_be16(fb_regs + DEST_X, area->dx);
96         out_be16(fb_regs + DEST_Y, area->dy);
97         out_be16(fb_regs + WHEIGHT, area->height);
98         out_be16(fb_regs + WWIDTH, area->width);
99         out_8(fb_regs + WMOVE, fb_bitmask);
100 }
101
102 static struct fb_ops hpfb_ops = {
103         .owner          = THIS_MODULE,
104         .fb_setcolreg   = hpfb_setcolreg,
105         .fb_fillrect    = cfb_fillrect,
106         .fb_copyarea    = hpfb_copyarea,
107         .fb_imageblit   = cfb_imageblit,
108         .fb_cursor      = soft_cursor,
109 };
110
111 #define TOPCAT_FBOMSB   0x5d
112 #define TOPCAT_FBOLSB   0x5f
113
114 int __init hpfb_init_one(unsigned long base)
115 {
116         unsigned long fboff;
117
118         if (fb_get_options("hpfb", NULL))
119                 return -ENODEV;
120
121         fboff = (in_8(base + TOPCAT_FBOMSB) << 8) | in_8(base + TOPCAT_FBOLSB);
122
123         hpfb_fix.smem_start = 0xf0000000 | (in_8(base + fboff) << 16);
124         fb_regs = base;
125
126 #if 0
127         /* This is the magic incantation NetBSD uses to make Catseye boards work. */
128         out_8(base+0x4800, 0);
129         out_8(base+0x4510, 0);
130         out_8(base+0x4512, 0);
131         out_8(base+0x4514, 0);
132         out_8(base+0x4516, 0);
133         out_8(base+0x4206, 0x90);
134 #endif
135         /* 
136          *      Give the hardware a bit of a prod and work out how many bits per
137          *      pixel are supported.
138          */
139         
140         out_8(base + TC_WEN, 0xff);
141         out_8(base + TC_FBEN, 0xff);
142         out_8(hpfb_fix.smem_start, 0xff);
143         fb_bitmask = in_8(hpfb_fix.smem_start);
144
145         /*
146          *      Enable reading/writing of all the planes.
147          */
148         out_8(base + TC_WEN, fb_bitmask);
149         out_8(base + TC_REN, fb_bitmask);
150         out_8(base + TC_FBEN, fb_bitmask);
151         out_8(base + TC_NBLANK, 0x1);
152
153         /*
154          *      Let there be consoles..
155          */
156         fb_info.fbops = &hpfb_ops;
157         fb_info.flags = FBINFO_DEFAULT;
158         fb_info.var   = hpfb_defined;
159         fb_info.fix   = hpfb_fix;
160         fb_info.screen_base = (char *)hpfb_fix.smem_start;      // FIXME
161
162         fb_alloc_cmap(&fb_info.cmap, 256, 0);
163
164         if (register_framebuffer(&fb_info) < 0)
165                 return 1;
166         return 0;
167 }
168
169 /* 
170  * Check that the secondary ID indicates that we have some hope of working with this
171  * framebuffer.  The catseye boards are pretty much like topcats and we can muddle through.
172  */
173
174 #define topcat_sid_ok(x)  (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE)    \
175                            || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
176
177 /* 
178  * Initialise the framebuffer
179  */
180
181 int __init hpfb_init(void)
182 {
183         unsigned int sid;
184
185         /* Topcats can be on the internal IO bus or real DIO devices.
186          * The internal variant sits at 0xf0560000; it has primary
187          * and secondary ID registers just like the DIO version.
188          * So we merge the two detection routines.
189          *
190          * Perhaps this #define should be in a global header file:
191          * I believe it's common to all internal fbs, not just topcat.
192          */
193 #define INTFBADDR 0xf0560000
194
195         if (hwreg_present((void *)INTFBADDR) && 
196            (DIO_ID(INTFBADDR) == DIO_ID_FBUFFER) &&
197             topcat_sid_ok(sid = DIO_SECID(INTFBADDR))) {
198                 printk("Internal Topcat found (secondary id %02x)\n", sid); 
199                 hpfb_init_one(INTFBADDR);
200         } else {
201                 int sc = dio_find(DIO_ID_FBUFFER);
202
203                 if (sc) {
204                         unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
205                         unsigned int sid = DIO_SECID(addr);
206
207                         if (topcat_sid_ok(sid)) {
208                                 printk("Topcat found at DIO select code %02x "
209                                         "(secondary id %02x)\n", sc, sid);
210                                 hpfb_init_one(addr);
211                         }
212                 }
213         }
214         return 0;
215 }
216
217 module_init(hpfb_init);
218 MODULE_LICENSE("GPL");