2 * Altera VGA controller
4 * linux/drivers/video/vfb.c -- Virtual frame buffer device
6 * Copyright (C) 2002 James Simmons
8 * Copyright (C) 1997 Geert Uytterhoeven
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
20 #include <linux/tty.h>
21 #include <linux/slab.h>
22 #include <linux/vmalloc.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/platform_device.h>
28 #include <asm/uaccess.h>
30 #include <linux/init.h>
32 #define vgabase na_vga_controller_0
38 * RAM we reserve for the frame buffer. This defines the maximum screen
41 * The default can be overridden if the driver is compiled as a module
44 #define VIDEOMEMSIZE (XRES * YRES * (BPX>>3))
46 static void *videomemory
;
47 static u_long videomemorysize
= VIDEOMEMSIZE
;
48 module_param(videomemorysize
, ulong
, 0);
50 static struct fb_var_screeninfo altfb_default __initdata
= {
55 .bits_per_pixel
= BPX
,
65 .activate
= FB_ACTIVATE_NOW
,
76 .vmode
= FB_VMODE_NONINTERLACED
,
79 static struct fb_fix_screeninfo altfb_fix __initdata
= {
81 .type
= FB_TYPE_PACKED_PIXELS
,
82 .visual
= FB_VISUAL_TRUECOLOR
,
83 .line_length
= (XRES
* (BPX
>>3)),
87 .accel
= FB_ACCEL_NONE
,
90 static int altfb_mmap(struct fb_info
*info
,
91 struct vm_area_struct
*vma
);
93 static struct fb_ops altfb_ops
= {
94 .fb_fillrect
= cfb_fillrect
,
95 .fb_copyarea
= cfb_copyarea
,
96 .fb_imageblit
= cfb_imageblit
,
97 .fb_mmap
= altfb_mmap
,
102 * Most drivers don't need their own mmap function
105 static int altfb_mmap(struct fb_info
*info
,
106 struct vm_area_struct
*vma
)
108 /* this is uClinux (no MMU) specific code */
109 vma
->vm_flags
|= (VM_RESERVED
| VM_MAYSHARE
);
110 vma
->vm_start
= (unsigned) videomemory
;
118 static void altfb_platform_release(struct device
*device
)
120 // This is called when the reference count goes to zero.
121 dev_err(device
, "This driver is broken, please bug the authors so they will fix it.\n");
124 static int __init
altfb_probe(struct platform_device
*dev
)
126 struct fb_info
*info
;
127 int retval
= -ENOMEM
;
131 * For real video cards we use ioremap.
133 if (!(videomemory
= dma_alloc_coherent(&dev
->dev
, PAGE_ALIGN(videomemorysize
), &handle
, GFP_KERNEL
))) {
134 printk(KERN_ERR
"altfb: unable to allocate screen memory\n");
137 altfb_fix
.smem_start
= handle
;
138 altfb_fix
.smem_len
= videomemorysize
;
140 info
= framebuffer_alloc(sizeof(u32
) * 256, &dev
->dev
);
144 info
->screen_base
= (char __iomem
*)videomemory
;
145 info
->fbops
= &altfb_ops
;
146 info
->var
= altfb_default
;
147 info
->fix
= altfb_fix
;
148 info
->pseudo_palette
= info
->par
;
150 info
->flags
= FBINFO_FLAG_DEFAULT
;
152 retval
= fb_alloc_cmap(&info
->cmap
, 256, 0);
156 retval
= register_framebuffer(info
);
159 platform_set_drvdata(dev
, info
);
161 outl(0x0,vgabase
+0); // Reset the VGA controller
162 outl(videomemory
,vgabase
+4); // Where our frame buffer starts
163 outl(videomemorysize
,vgabase
+8); // amount of memory needed
164 outl(0x1,vgabase
+0); // Set the go bit
167 "fb%d: Altera frame buffer device, using %ldK of video memory\n",
168 info
->node
, videomemorysize
>> 10);
169 // printk("vga %08x, video %08x+%08x\n",vgabase,videomemory,videomemorysize);
172 fb_dealloc_cmap(&info
->cmap
);
174 framebuffer_release(info
);
176 dma_free_noncoherent(&dev
->dev
, videomemorysize
, videomemory
, handle
);
180 static int altfb_remove(struct platform_device
*dev
)
182 struct fb_info
*info
= platform_get_drvdata(dev
);
185 unregister_framebuffer(info
);
186 dma_free_noncoherent(&dev
->dev
, videomemorysize
, videomemory
, altfb_fix
.smem_start
);
187 framebuffer_release(info
);
192 static struct platform_driver altfb_driver
= {
193 .probe
= altfb_probe
,
194 .remove
= altfb_remove
,
200 static struct platform_device altfb_device
= {
204 .release
= altfb_platform_release
,
208 static int __init
altfb_init(void)
212 ret
= platform_driver_register(&altfb_driver
);
215 ret
= platform_device_register(&altfb_device
);
217 platform_driver_unregister(&altfb_driver
);
222 module_init(altfb_init
);
225 static void __exit
altfb_exit(void)
227 platform_device_unregister(&altfb_device
);
228 platform_driver_unregister(&altfb_driver
);
231 module_exit(altfb_exit
);
233 MODULE_LICENSE("GPL");