MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / drivers / altfb.c
blobcebd65984f16796c9ffb713159fc10376ebd67fa
1 /*
2 * Altera VGA controller
3 *
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
12 * more details.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/mm.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>
29 #include <linux/fb.h>
30 #include <linux/init.h>
32 #define vgabase na_vga_controller_0
33 #define XRES 640
34 #define YRES 480
35 #define BPX 16
38 * RAM we reserve for the frame buffer. This defines the maximum screen
39 * size
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 = {
51 .xres = XRES,
52 .yres = YRES,
53 .xres_virtual = XRES,
54 .yres_virtual = YRES,
55 .bits_per_pixel = BPX,
56 #if (BPX == 16)
57 .red = { 11, 5, 0 },
58 .green = { 5, 6, 0 },
59 .blue = { 0, 5, 0 },
60 #else // BPX == 24
61 .red = { 16, 8, 0 },
62 .green = { 8, 8, 0 },
63 .blue = { 0, 8, 0 },
64 #endif
65 .activate = FB_ACTIVATE_NOW,
66 .height = -1,
67 .width = -1,
68 // timing useless ?
69 .pixclock = 20000,
70 .left_margin = 64,
71 .right_margin = 64,
72 .upper_margin = 32,
73 .lower_margin = 32,
74 .hsync_len = 64,
75 .vsync_len = 2,
76 .vmode = FB_VMODE_NONINTERLACED,
79 static struct fb_fix_screeninfo altfb_fix __initdata = {
80 .id = "Altera FB",
81 .type = FB_TYPE_PACKED_PIXELS,
82 .visual = FB_VISUAL_TRUECOLOR,
83 .line_length = (XRES * (BPX>>3)),
84 .xpanstep = 0,
85 .ypanstep = 0,
86 .ywrapstep = 0,
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;
111 return 0;
115 * Initialisation
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;
128 dma_addr_t handle;
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");
135 return retval;
137 altfb_fix.smem_start = handle;
138 altfb_fix.smem_len = videomemorysize;
140 info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev);
141 if (!info)
142 goto err;
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;
149 info->par = NULL;
150 info->flags = FBINFO_FLAG_DEFAULT;
152 retval = fb_alloc_cmap(&info->cmap, 256, 0);
153 if (retval < 0)
154 goto err1;
156 retval = register_framebuffer(info);
157 if (retval < 0)
158 goto err2;
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
166 printk(KERN_INFO
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);
170 return 0;
171 err2:
172 fb_dealloc_cmap(&info->cmap);
173 err1:
174 framebuffer_release(info);
175 err:
176 dma_free_noncoherent(&dev->dev, videomemorysize, videomemory, handle);
177 return retval;
180 static int altfb_remove(struct platform_device *dev)
182 struct fb_info *info = platform_get_drvdata(dev);
184 if (info) {
185 unregister_framebuffer(info);
186 dma_free_noncoherent(&dev->dev, videomemorysize, videomemory, altfb_fix.smem_start);
187 framebuffer_release(info);
189 return 0;
192 static struct platform_driver altfb_driver = {
193 .probe = altfb_probe,
194 .remove = altfb_remove,
195 .driver = {
196 .name = "altfb",
200 static struct platform_device altfb_device = {
201 .name = "altfb",
202 .id = 0,
203 .dev = {
204 .release = altfb_platform_release,
208 static int __init altfb_init(void)
210 int ret = 0;
212 ret = platform_driver_register(&altfb_driver);
214 if (!ret) {
215 ret = platform_device_register(&altfb_device);
216 if (ret)
217 platform_driver_unregister(&altfb_driver);
219 return ret;
222 module_init(altfb_init);
224 #ifdef MODULE
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");
234 #endif /* MODULE */