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, 2006 Maciej W. Rozycki
19 * Copyright (c) 2005 James Simmons
21 * This file is subject to the terms and conditions of the GNU General
22 * Public License. See the file COPYING in the main directory of this
23 * archive for more details.
26 #include <linux/compiler.h>
27 #include <linux/errno.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
33 #include <linux/types.h>
36 #include <asm/system.h>
38 #include <video/pmag-ba-fb.h>
42 volatile void __iomem
*mmio
;
43 volatile u32 __iomem
*dac
;
47 static struct fb_var_screeninfo pmagbafb_defined __devinitdata
= {
56 .activate
= FB_ACTIVATE_NOW
,
59 .accel_flags
= FB_ACCEL_NONE
,
67 .sync
= FB_SYNC_ON_GREEN
,
68 .vmode
= FB_VMODE_NONINTERLACED
,
71 static struct fb_fix_screeninfo pmagbafb_fix __devinitdata
= {
73 .smem_len
= (1024 * 1024),
74 .type
= FB_TYPE_PACKED_PIXELS
,
75 .visual
= FB_VISUAL_PSEUDOCOLOR
,
77 .mmio_len
= PMAG_BA_SIZE
- PMAG_BA_BT459
,
81 static inline void dac_write(struct pmagbafb_par
*par
, unsigned int reg
, u8 v
)
83 writeb(v
, par
->dac
+ reg
/ 4);
86 static inline u8
dac_read(struct pmagbafb_par
*par
, unsigned int reg
)
88 return readb(par
->dac
+ reg
/ 4);
95 static int pmagbafb_setcolreg(unsigned int regno
, unsigned int red
,
96 unsigned int green
, unsigned int blue
,
97 unsigned int transp
, struct fb_info
*info
)
99 struct pmagbafb_par
*par
= info
->par
;
101 if (regno
>= info
->cmap
.len
)
104 red
>>= 8; /* The cmap fields are 16 bits */
105 green
>>= 8; /* wide, but the hardware colormap */
106 blue
>>= 8; /* registers are only 8 bits wide */
109 dac_write(par
, BT459_ADDR_LO
, regno
);
110 dac_write(par
, BT459_ADDR_HI
, 0x00);
112 dac_write(par
, BT459_CMAP
, red
);
114 dac_write(par
, BT459_CMAP
, green
);
116 dac_write(par
, BT459_CMAP
, blue
);
121 static struct fb_ops pmagbafb_ops
= {
122 .owner
= THIS_MODULE
,
123 .fb_setcolreg
= pmagbafb_setcolreg
,
124 .fb_fillrect
= cfb_fillrect
,
125 .fb_copyarea
= cfb_copyarea
,
126 .fb_imageblit
= cfb_imageblit
,
131 * Turn the hardware cursor off.
133 static void __init
pmagbafb_erase_cursor(struct fb_info
*info
)
135 struct pmagbafb_par
*par
= info
->par
;
138 dac_write(par
, BT459_ADDR_LO
, 0x00);
139 dac_write(par
, BT459_ADDR_HI
, 0x03);
141 dac_write(par
, BT459_DATA
, 0x00);
145 static int __devinit
pmagbafb_probe(struct device
*dev
)
147 struct tc_dev
*tdev
= to_tc_dev(dev
);
148 resource_size_t start
, len
;
149 struct fb_info
*info
;
150 struct pmagbafb_par
*par
;
153 info
= framebuffer_alloc(sizeof(struct pmagbafb_par
), dev
);
155 printk(KERN_ERR
"%s: Cannot allocate memory\n", dev_name(dev
));
160 dev_set_drvdata(dev
, info
);
162 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
163 printk(KERN_ERR
"%s: Cannot allocate color map\n",
169 info
->fbops
= &pmagbafb_ops
;
170 info
->fix
= pmagbafb_fix
;
171 info
->var
= pmagbafb_defined
;
172 info
->flags
= FBINFO_DEFAULT
;
174 /* Request the I/O MEM resource. */
175 start
= tdev
->resource
.start
;
176 len
= tdev
->resource
.end
- start
+ 1;
177 if (!request_mem_region(start
, len
, dev_name(dev
))) {
178 printk(KERN_ERR
"%s: Cannot reserve FB region\n",
184 /* MMIO mapping setup. */
185 info
->fix
.mmio_start
= start
;
186 par
->mmio
= ioremap_nocache(info
->fix
.mmio_start
, info
->fix
.mmio_len
);
188 printk(KERN_ERR
"%s: Cannot map MMIO\n", dev_name(dev
));
192 par
->dac
= par
->mmio
+ PMAG_BA_BT459
;
194 /* Frame buffer mapping setup. */
195 info
->fix
.smem_start
= start
+ PMAG_BA_FBMEM
;
196 info
->screen_base
= ioremap_nocache(info
->fix
.smem_start
,
198 if (!info
->screen_base
) {
199 printk(KERN_ERR
"%s: Cannot map FB\n", dev_name(dev
));
203 info
->screen_size
= info
->fix
.smem_len
;
205 pmagbafb_erase_cursor(info
);
207 err
= register_framebuffer(info
);
209 printk(KERN_ERR
"%s: Cannot register framebuffer\n",
216 pr_info("fb%d: %s frame buffer device at %s\n",
217 info
->node
, info
->fix
.id
, dev_name(dev
));
223 iounmap(info
->screen_base
);
229 release_mem_region(start
, len
);
232 fb_dealloc_cmap(&info
->cmap
);
235 framebuffer_release(info
);
239 static int __exit
pmagbafb_remove(struct device
*dev
)
241 struct tc_dev
*tdev
= to_tc_dev(dev
);
242 struct fb_info
*info
= dev_get_drvdata(dev
);
243 struct pmagbafb_par
*par
= info
->par
;
244 resource_size_t start
, len
;
247 unregister_framebuffer(info
);
248 iounmap(info
->screen_base
);
250 start
= tdev
->resource
.start
;
251 len
= tdev
->resource
.end
- start
+ 1;
252 release_mem_region(start
, len
);
253 fb_dealloc_cmap(&info
->cmap
);
254 framebuffer_release(info
);
260 * Initialize the framebuffer.
262 static const struct tc_device_id pmagbafb_tc_table
[] = {
263 { "DEC ", "PMAG-BA " },
266 MODULE_DEVICE_TABLE(tc
, pmagbafb_tc_table
);
268 static struct tc_driver pmagbafb_driver
= {
269 .id_table
= pmagbafb_tc_table
,
273 .probe
= pmagbafb_probe
,
274 .remove
= __exit_p(pmagbafb_remove
),
278 static int __init
pmagbafb_init(void)
281 if (fb_get_options("pmagbafb", NULL
))
284 return tc_register_driver(&pmagbafb_driver
);
287 static void __exit
pmagbafb_exit(void)
289 tc_unregister_driver(&pmagbafb_driver
);
293 module_init(pmagbafb_init
);
294 module_exit(pmagbafb_exit
);
296 MODULE_LICENSE("GPL");