More cleaning ...
[linux-2.6/linux-mips.git] / drivers / video / hitfb.c
blob3de65cec9e962b0c291622115cdd3f22ac69c32d
1 /*
2 * $Id: hitfb.c,v 1.2 2000/07/04 06:24:46 yaegashi Exp $
3 * linux/drivers/video/hitfb.c -- Hitachi LCD frame buffer device
4 * (C) 1999 Mihai Spatar
5 * (C) 2000 YAEGASHI Takeshi
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/mm.h>
19 #include <linux/tty.h>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
22 #include <linux/nubus.h>
23 #include <linux/init.h>
24 #include <linux/fb.h>
26 #include <asm/machvec.h>
27 #include <asm/uaccess.h>
28 #include <asm/pgtable.h>
29 #include <asm/io.h>
30 #include <asm/hd64461.h>
32 static struct fb_var_screeninfo hitfb_var __initdata = {
33 .activate = FB_ACTIVATE_NOW,
34 .height = -1,
35 .width = -1,
36 .vmode = FB_VMODE_NONINTERLACED,
39 static struct fb_fix_screeninfo hitfb_fix __initdata = {
40 .id = "Hitachi HD64461",
41 .type = FB_TYPE_PACKED_PIXELS,
42 .visual = FB_VISUAL_TRUECOLOR,
43 .accel_flags = FB_ACCEL_NONE,
46 static u16 pseudo_palette[17];
47 struct fb_info fb_info;
49 static int hitfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
51 var->xres_virtual = var->xres;
52 var->yres_virtual = var->yres;
54 switch (var->bits_per_pixel) {
55 case 8:
56 var->red.offset = 0;
57 var->red.length = 8;
58 var->green.offset = 0;
59 var->green.length = 8;
60 var->blue.offset = 0;
61 var->blue.length = 8;
62 var->transp.offset = 0;
63 var->transp.length = 0;
64 break;
65 case 16: /* RGB 565 */
66 var->red.offset = 11;
67 var->red.length = 5;
68 var->green.offset = 5;
69 var->green.length = 6;
70 var->blue.offset = 0;
71 var->blue.length = 5;
72 var->transp.offset = 0;
73 var->transp.length = 0;
74 break;
76 return 0;
79 static int hitfb_set_par(struct fb_info *info)
81 info->fix.visual = (info->var.bits_per_pixel == 8) ?
82 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
84 switch(info->var.bits_per_pixel) {
85 default:
86 case 8:
87 info->fix.line_length = info->var.xres;
88 break;
89 case 16:
90 info->fix.line_length = info->var.xres*2;
91 break;
93 return 0;
96 static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
97 unsigned blue, unsigned transp,
98 struct fb_info *info)
100 if (regno > 255)
101 return 1;
103 outw(regno << 8, HD64461_CPTWAR);
104 outw(red >> 10, HD64461_CPTWDR);
105 outw(green >> 10, HD64461_CPTWDR);
106 outw(blue >> 10, HD64461_CPTWDR);
108 if (regno < 16) {
109 switch(info->var.bits_per_pixel) {
110 case 16:
111 ((u16 *)(info->pseudo_palette))[regno] =
112 ((red & 0xf800) ) |
113 ((green & 0xfc00) >> 5) |
114 ((blue & 0xf800) >> 11);
115 break;
118 return 0;
121 static struct fb_ops hitfb_ops = {
122 .owner = THIS_MODULE,
123 .fb_check_var = hitfb_check_var,
124 .fb_set_par = hitfb_set_par,
125 .fb_setcolreg = hitfb_setcolreg,
126 .fb_fillrect = cfb_fillrect,
127 .fb_copyarea = cfb_copyarea,
128 .fb_imageblit = cfb_imageblit,
129 .fb_cursor = soft_cursor,
132 int __init hitfb_init(void)
134 unsigned short lcdclor, ldr3, ldvntr;
136 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
137 hitfb_fix.smem_len = (MACH_HP680 || MACH_HP690) ? 1024*1024 : 512*1024;
139 lcdclor = inw(HD64461_LCDCLOR);
140 ldvntr = inw(HD64461_LDVNTR);
141 ldr3 = inw(HD64461_LDR3);
143 switch (ldr3&15) {
144 default:
145 case 4:
146 hitfb_var.bits_per_pixel = 8;
147 hitfb_var.xres = lcdclor;
148 break;
149 case 8:
150 hitfb_var.bits_per_pixel = 16;
151 hitfb_var.xres = lcdclor/2;
152 break;
154 hitfb_var.yres = ldvntr+1;
156 fb_info.fbops = &hitfb_ops;
157 fb_info.var = hitfb_var;
158 fb_info.fix = hitfb_fix;
159 fb_info.pseudo_palette = pseudo_palette;
160 fb_info.flags = FBINFO_FLAG_DEFAULT;
162 fb_info.screen_base = (void *) hitfb_fix.smem_start;
164 size = (fb_info.var.bits_per_pixel == 8) ? 256 : 16;
165 fb_alloc_cmap(&fb_info.cmap, size, 0);
167 if (register_framebuffer(&fb_info) < 0)
168 return -EINVAL;
170 printk(KERN_INFO "fb%d: %s frame buffer device\n",
171 fb_info.node, fb_info.fix.id);
172 return 0;
176 void hitfb_cleanup(struct fb_info *info)
178 unregister_framebuffer(info);
182 #ifdef MODULE
183 MODULE_LICENSE("GPL");
185 int init_module(void)
187 return hitfb_init();
190 void cleanup_module(void)
192 hitfb_cleanup(void);
194 #endif
197 * Local variables:
198 * c-basic-offset: 4
199 * End: