2 * linux/drivers/video/pmag-ba-fb.c
4 * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
6 * "HP300 Topcat framebuffer support (derived from macfb of all things)
7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
8 * found in the file hpfb.c in the same directory.
10 * Based on digital document:
11 * "PMAG-BA TURBOchannel Color Frame Buffer
12 * Functional Specification", Revision 1.2, August 27, 1990
14 * DECstation related code Copyright (C) 1999, 2000, 2001 by
15 * Michael Engel <engel@unix-ag.org>,
16 * Karsten Merker <merker@linuxtag.org> and
18 * Copyright (c) 2005 Maciej W. Rozycki
20 * This file is subject to the terms and conditions of the GNU General
21 * Public License. See the file COPYING in the main directory of this
22 * archive for more details.
25 #include <linux/compiler.h>
26 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/types.h>
34 #include <asm/system.h>
36 #include <asm/dec/tc.h>
38 #include <video/pmag-ba-fb.h>
43 volatile void __iomem *mmio;
44 volatile u32 __iomem *dac;
49 static struct fb_info *root_pmagbafb_dev;
51 static struct fb_var_screeninfo pmagbafb_defined __initdata = {
60 .activate = FB_ACTIVATE_NOW,
63 .accel_flags = FB_ACCEL_NONE,
71 .sync = FB_SYNC_ON_GREEN,
72 .vmode = FB_VMODE_NONINTERLACED,
75 static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
77 .smem_len = (1024 * 1024),
78 .type = FB_TYPE_PACKED_PIXELS,
79 .visual = FB_VISUAL_PSEUDOCOLOR,
81 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
85 static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
87 writeb(v, par->dac + reg / 4);
90 static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
92 return readb(par->dac + reg / 4);
99 static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
100 unsigned int green, unsigned int blue,
101 unsigned int transp, struct fb_info *info)
103 struct pmagbafb_par *par = info->par;
105 BUG_ON(regno >= info->cmap.len);
107 red >>= 8; /* The cmap fields are 16 bits */
108 green >>= 8; /* wide, but the hardware colormap */
109 blue >>= 8; /* registers are only 8 bits wide */
112 dac_write(par, BT459_ADDR_LO, regno);
113 dac_write(par, BT459_ADDR_HI, 0x00);
115 dac_write(par, BT459_CMAP, red);
117 dac_write(par, BT459_CMAP, green);
119 dac_write(par, BT459_CMAP, blue);
124 static struct fb_ops pmagbafb_ops = {
125 .owner = THIS_MODULE,
126 .fb_setcolreg = pmagbafb_setcolreg,
127 .fb_fillrect = cfb_fillrect,
128 .fb_copyarea = cfb_copyarea,
129 .fb_imageblit = cfb_imageblit,
134 * Turn the hardware cursor off.
136 static void __init pmagbafb_erase_cursor(struct fb_info *info)
138 struct pmagbafb_par *par = info->par;
141 dac_write(par, BT459_ADDR_LO, 0x00);
142 dac_write(par, BT459_ADDR_HI, 0x03);
144 dac_write(par, BT459_DATA, 0x00);
148 static int __init pmagbafb_init_one(int slot)
150 struct fb_info *info;
151 struct pmagbafb_par *par;
152 unsigned long base_addr;
154 info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
160 claim_tc_card(par->slot);
162 base_addr = get_tc_base_addr(par->slot);
164 par->next = root_pmagbafb_dev;
165 root_pmagbafb_dev = info;
167 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
170 info->fbops = &pmagbafb_ops;
171 info->fix = pmagbafb_fix;
172 info->var = pmagbafb_defined;
173 info->flags = FBINFO_DEFAULT;
175 /* MMIO mapping setup. */
176 info->fix.mmio_start = base_addr;
177 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
180 par->dac = par->mmio + PMAG_BA_BT459;
182 /* Frame buffer mapping setup. */
183 info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
184 info->screen_base = ioremap_nocache(info->fix.smem_start,
186 if (!info->screen_base)
188 info->screen_size = info->fix.smem_len;
190 pmagbafb_erase_cursor(info);
192 if (register_framebuffer(info) < 0)
195 pr_info("fb%d: %s frame buffer device in slot %d\n",
196 info->node, info->fix.id, par->slot);
202 iounmap(info->screen_base);
208 fb_dealloc_cmap(&info->cmap);
211 root_pmagbafb_dev = par->next;
212 release_tc_card(par->slot);
213 framebuffer_release(info);
217 static void __exit pmagbafb_exit_one(void)
219 struct fb_info *info = root_pmagbafb_dev;
220 struct pmagbafb_par *par = info->par;
222 unregister_framebuffer(info);
223 iounmap(info->screen_base);
225 fb_dealloc_cmap(&info->cmap);
226 root_pmagbafb_dev = par->next;
227 release_tc_card(par->slot);
228 framebuffer_release(info);
233 * Initialise the framebuffer.
235 static int __init pmagbafb_init(void)
240 if (fb_get_options("pmagbafb", NULL))
243 while ((slot = search_tc_card("PMAG-BA")) >= 0) {
244 if (pmagbafb_init_one(slot) < 0)
248 return (count > 0) ? 0 : -ENXIO;
251 static void __exit pmagbafb_exit(void)
253 while (root_pmagbafb_dev)
258 module_init(pmagbafb_init);
259 module_exit(pmagbafb_exit);
261 MODULE_LICENSE("GPL");