2 * HP300 Topcat framebuffer support (derived from macfb of all things)
3 * Phil Blundell <philb@gnu.org> 1998
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>
12 #include <linux/tty.h>
13 #include <linux/slab.h>
14 #include <linux/delay.h>
15 #include <linux/init.h>
17 #include <linux/dio.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;
29 #define TC_FBEN 0x4090
30 #define TC_NBLANK 0x4080
35 #define SOURCE_X 0x40f2
36 #define SOURCE_Y 0x40f6
39 #define WHEIGHT 0x4106
43 static struct fb_fix_screeninfo hpfb_fix __initdata = {
46 .type = FB_TYPE_PACKED_PIXELS,
47 .visual = FB_VISUAL_PSEUDOCOLOR,
49 .accel = FB_ACCEL_NONE,
52 static struct fb_var_screeninfo hpfb_defined = {
58 .red = {0,2,0}, /* R */
59 .green = {0,2,0}, /* G */
60 .blue = {0,2,0}, /* B */
61 .activate = FB_ACTIVATE_NOW,
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
71 * XXX Doesn't work at all.
73 static int hpfb_setcolreg(unsigned regno, unsigned red, unsigned green,
74 unsigned blue, unsigned transp,
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);
85 out_be16(fb_regs + 0x60ba, 0xffff);
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)
118 if (fb_get_options("hpfb", NULL))
121 fboff = (in_8(base + TOPCAT_FBOMSB) << 8) | in_8(base + TOPCAT_FBOLSB);
123 hpfb_fix.smem_start = 0xf0000000 | (in_8(base + fboff) << 16);
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);
136 * Give the hardware a bit of a prod and work out how many bits per
137 * pixel are supported.
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);
146 * Enable reading/writing of all the planes.
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);
154 * Let there be consoles..
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
162 fb_alloc_cmap(&fb_info.cmap, 256, 0);
164 if (register_framebuffer(&fb_info) < 0)
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.
174 #define topcat_sid_ok(x) (((x) == DIO_ID2_LRCATSEYE) || ((x) == DIO_ID2_HRCCATSEYE) \
175 || ((x) == DIO_ID2_HRMCATSEYE) || ((x) == DIO_ID2_TOPCAT))
178 * Initialise the framebuffer
181 int __init hpfb_init(void)
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.
190 * Perhaps this #define should be in a global header file:
191 * I believe it's common to all internal fbs, not just topcat.
193 #define INTFBADDR 0xf0560000
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);
201 int sc = dio_find(DIO_ID_FBUFFER);
204 unsigned long addr = (unsigned long)dio_scodetoviraddr(sc);
205 unsigned int sid = DIO_SECID(addr);
207 if (topcat_sid_ok(sid)) {
208 printk("Topcat found at DIO select code %02x "
209 "(secondary id %02x)\n", sc, sid);
217 module_init(hpfb_init);
218 MODULE_LICENSE("GPL");