More cleaning ...
[linux-2.6/linux-mips.git] / drivers / video / hpfb.c
blobbfbdbabfd18833f899e126d54c71a7cc034fc68f
1 /*
2 * HP300 Topcat framebuffer support (derived from macfb of all things)
3 * Phil Blundell <philb@gnu.org> 1998
4 */
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>
22 static struct fb_info fb_info;
24 unsigned long fb_regs;
25 unsigned char fb_bitmask;
27 #define TC_WEN 0x4088
28 #define TC_REN 0x408c
29 #define TC_FBEN 0x4090
30 #define TC_NBLANK 0x4080
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
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,
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,
69 * Set the palette. This may not work on all boards but only experimentation
70 * will tell.
71 * XXX Doesn't work at all.
73 static int hpfb_setcolreg(unsigned regno, unsigned red, unsigned green,
74 unsigned blue, unsigned transp,
75 struct fb_info *info)
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;
89 void hpfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
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);
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,
111 #define TOPCAT_FBOMSB 0x5d
112 #define TOPCAT_FBOLSB 0x5f
114 int __init hpfb_init_one(unsigned long base)
116 unsigned long fboff;
118 fboff = (in_8(base + TOPCAT_FBOMSB) << 8) | in_8(base + TOPCAT_FBOLSB);
120 hpfb_fix.smem_start = 0xf0000000 | (in_8(base + fboff) << 16);
121 fb_regs = base;
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
133 * Give the hardware a bit of a prod and work out how many bits per
134 * pixel are supported.
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);
143 * Enable reading/writing of all the planes.
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);
151 * Let there be consoles..
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
159 fb_alloc_cmap(&fb_info.cmap, 256, 0);
161 if (register_framebuffer(&fb_info) < 0)
162 return 1;
163 return 0;
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.
171 #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
172 || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
175 * Initialise the framebuffer
178 int __init hpfb_init(void)
180 unsigned int sid;
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.
187 * Perhaps this #define should be in a global header file:
188 * I believe it's common to all internal fbs, not just topcat.
190 #define INTFBADDR 0xf0560000
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);
200 if (sc) {
201 unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
202 unsigned int sid = DIO_SECID(addr);
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);
211 return 0;
214 MODULE_LICENSE("GPL");