ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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         fboff = (in_8(base + TOPCAT_FBOMSB) << 8) | in_8(base + TOPCAT_FBOLSB);
119
120         hpfb_fix.smem_start = 0xf0000000 | (in_8(base + fboff) << 16);
121         fb_regs = base;
122
123 #if 0
124         /* This is the magic incantation NetBSD uses to make Catseye boards work. */
125         out_8(base+0x4800, 0);
126         out_8(base+0x4510, 0);
127         out_8(base+0x4512, 0);
128         out_8(base+0x4514, 0);
129         out_8(base+0x4516, 0);
130         out_8(base+0x4206, 0x90);
131 #endif
132         /* 
133          *      Give the hardware a bit of a prod and work out how many bits per
134          *      pixel are supported.
135          */
136         
137         out_8(base + TC_WEN, 0xff);
138         out_8(base + TC_FBEN, 0xff);
139         out_8(hpfb_fix.smem_start, 0xff);
140         fb_bitmask = in_8(hpfb_fix.smem_start);
141
142         /*
143          *      Enable reading/writing of all the planes.
144          */
145         out_8(base + TC_WEN, fb_bitmask);
146         out_8(base + TC_REN, fb_bitmask);
147         out_8(base + TC_FBEN, fb_bitmask);
148         out_8(base + TC_NBLANK, 0x1);
149
150         /*
151          *      Let there be consoles..
152          */
153         fb_info.fbops = &hpfb_ops;
154         fb_info.flags = FBINFO_FLAG_DEFAULT;
155         fb_info.var   = hpfb_defined;
156         fb_info.fix   = hpfb_fix;
157         fb_info.screen_base = (char *)hpfb_fix.smem_start;      // FIXME
158
159         fb_alloc_cmap(&fb_info.cmap, 256, 0);
160
161         if (register_framebuffer(&fb_info) < 0)
162                 return 1;
163         return 0;
164 }
165
166 /* 
167  * Check that the secondary ID indicates that we have some hope of working with this
168  * framebuffer.  The catseye boards are pretty much like topcats and we can muddle through.
169  */
170
171 #define topcat_sid_ok(x)  (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE)    \
172                            || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
173
174 /* 
175  * Initialise the framebuffer
176  */
177
178 int __init hpfb_init(void)
179 {
180         unsigned int sid;
181
182         /* Topcats can be on the internal IO bus or real DIO devices.
183          * The internal variant sits at 0xf0560000; it has primary
184          * and secondary ID registers just like the DIO version.
185          * So we merge the two detection routines.
186          *
187          * Perhaps this #define should be in a global header file:
188          * I believe it's common to all internal fbs, not just topcat.
189          */
190 #define INTFBADDR 0xf0560000
191
192         if (hwreg_present((void *)INTFBADDR) && 
193            (DIO_ID(INTFBADDR) == DIO_ID_FBUFFER) &&
194             topcat_sid_ok(sid = DIO_SECID(INTFBADDR))) {
195                 printk("Internal Topcat found (secondary id %02x)\n", sid); 
196                 hpfb_init_one(INTFBADDR);
197         } else {
198                 int sc = dio_find(DIO_ID_FBUFFER);
199
200                 if (sc) {
201                         unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
202                         unsigned int sid = DIO_SECID(addr);
203
204                         if (topcat_sid_ok(sid)) {
205                                 printk("Topcat found at DIO select code %02x "
206                                         "(secondary id %02x)\n", sc, sid);
207                                 hpfb_init_one(addr);
208                         }
209                 }
210         }
211         return 0;
212 }
213
214 MODULE_LICENSE("GPL");