]> err.no Git - linux-2.6/blob - drivers/video/hitfb.c
c6ac0dcd885405c904b8dcc08f53416a6f26f1ed
[linux-2.6] / drivers / video / hitfb.c
1 /*
2  * linux/drivers/video/hitfb.c -- Hitachi LCD frame buffer device
3  *
4  * (C) 1999 Mihai Spatar
5  * (C) 2000 YAEGASHI Takeshi
6  * (C) 2003, 2004 Paul Mundt
7  * (C) 2003, 2004 Andriy Skulysh
8  *
9  *  This file is subject to the terms and conditions of the GNU General Public
10  *  License. See the file COPYING in the main directory of this archive for
11  *  more details.
12  */
13
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/mm.h>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/fb.h>
24
25 #include <asm/machvec.h>
26 #include <asm/uaccess.h>
27 #include <asm/pgtable.h>
28 #include <asm/io.h>
29 #include <asm/hd64461/hd64461.h>
30
31 #include <asm/cpu/dac.h>
32 #include <asm/hp6xx/hp6xx.h>
33
34 #define WIDTH 640
35
36 static struct fb_var_screeninfo hitfb_var __initdata = {
37         .activate       = FB_ACTIVATE_NOW,
38         .height         = -1,
39         .width          = -1,
40         .vmode          = FB_VMODE_NONINTERLACED,
41 };
42
43 static struct fb_fix_screeninfo hitfb_fix __initdata = {
44         .id             = "Hitachi HD64461",
45         .type           = FB_TYPE_PACKED_PIXELS,
46         .ypanstep       = 8,
47         .accel          = FB_ACCEL_NONE,
48 };
49
50 static u32 pseudo_palette[16];
51 static struct fb_info fb_info;
52
53 static inline void hitfb_accel_wait(void)
54 {
55         while (fb_readw(HD64461_GRCFGR) & HD64461_GRCFGR_ACCSTATUS) ;
56 }
57
58 static inline void hitfb_accel_start(int truecolor)
59 {
60         if (truecolor) {
61                 fb_writew(6, HD64461_GRCFGR);
62         } else {
63                 fb_writew(7, HD64461_GRCFGR);
64         }
65 }
66
67 static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
68                                         u16 width, u16 height)
69 {
70         u32 saddr = WIDTH * dy + dx;
71         if (truecolor)
72                 saddr <<= 1;
73
74         fb_writew(width, HD64461_BBTDWR);
75         fb_writew(height, HD64461_BBTDHR);
76
77         fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
78         fb_writew(saddr >> 16, HD64461_BBTDSARH);
79
80 }
81
82 static inline void hitfb_accel_solidfill(int truecolor, u16 dx, u16 dy,
83                                          u16 width, u16 height, u16 color)
84 {
85         hitfb_accel_set_dest(truecolor, dx, dy, width, height);
86
87         fb_writew(0x00f0, HD64461_BBTROPR);
88         fb_writew(16, HD64461_BBTMDR);
89         fb_writew(color, HD64461_GRSCR);
90
91         hitfb_accel_start(truecolor);
92 }
93
94 static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
95                                       u16 dy, u16 width, u16 height, u16 rop,
96                                       u32 mask_addr)
97 {
98         u32 saddr, daddr;
99         u32 maddr = 0;
100
101         fb_writew(rop, HD64461_BBTROPR);
102         if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
103                 saddr = WIDTH * (sy + height) + sx + width;
104                 daddr = WIDTH * (dy + height) + dx + width;
105                 if (mask_addr) {
106                         if (truecolor)
107                                 maddr = ((width >> 3) + 1) * (height + 1) - 1;
108                         else
109                                 maddr =
110                                     (((width >> 4) + 1) * (height + 1) - 1) * 2;
111
112                         fb_writew((1 << 5) | 1, HD64461_BBTMDR);
113                 } else
114                         fb_writew(1, HD64461_BBTMDR);
115         } else {
116                 saddr = WIDTH * sy + sx;
117                 daddr = WIDTH * dy + dx;
118                 if (mask_addr) {
119                         fb_writew((1 << 5), HD64461_BBTMDR);
120                 } else {
121                         fb_writew(0, HD64461_BBTMDR);
122                 }
123         }
124         if (truecolor) {
125                 saddr <<= 1;
126                 daddr <<= 1;
127         }
128         fb_writew(width, HD64461_BBTDWR);
129         fb_writew(height, HD64461_BBTDHR);
130         fb_writew(saddr & 0xffff, HD64461_BBTSSARL);
131         fb_writew(saddr >> 16, HD64461_BBTSSARH);
132         fb_writew(daddr & 0xffff, HD64461_BBTDSARL);
133         fb_writew(daddr >> 16, HD64461_BBTDSARH);
134         if (mask_addr) {
135                 maddr += mask_addr;
136                 fb_writew(maddr & 0xffff, HD64461_BBTMARL);
137                 fb_writew(maddr >> 16, HD64461_BBTMARH);
138         }
139         hitfb_accel_start(truecolor);
140 }
141
142 static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
143 {
144         if (rect->rop != ROP_COPY)
145                 cfb_fillrect(p, rect);
146         else {
147                 fb_writew(0x00f0, HD64461_BBTROPR);
148                 fb_writew(16, HD64461_BBTMDR);
149
150                 if (p->var.bits_per_pixel == 16) {
151                         fb_writew(((u32 *) (p->pseudo_palette))[rect->color],
152                                   HD64461_GRSCR);
153                         hitfb_accel_set_dest(1, rect->dx, rect->dy, rect->width,
154                                              rect->height);
155                         hitfb_accel_start(1);
156                 } else {
157                         fb_writew(rect->color, HD64461_GRSCR);
158                         hitfb_accel_set_dest(0, rect->dx, rect->dy, rect->width,
159                                              rect->height);
160                         hitfb_accel_start(0);
161                 }
162                 hitfb_accel_wait();
163         }
164 }
165
166 static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
167 {
168         hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
169                            area->dx, area->dy, area->width, area->height,
170                            0x00cc, 0);
171         hitfb_accel_wait();
172 }
173
174 static int hitfb_pan_display(struct fb_var_screeninfo *var,
175                              struct fb_info *info)
176 {
177         int xoffset = var->xoffset;
178         int yoffset = var->yoffset;
179
180         if (xoffset != 0)
181                 return -EINVAL;
182
183         fb_writew(yoffset, HD64461_LCDCBAR);
184
185         return 0;
186 }
187
188 int hitfb_blank(int blank_mode, struct fb_info *info)
189 {
190         unsigned short v;
191
192         if (blank_mode) {
193                 v = fb_readw(HD64461_LDR1);
194                 v &= ~HD64461_LDR1_DON;
195                 fb_writew(v, HD64461_LDR1);
196
197                 v = fb_readw(HD64461_LCDCCR);
198                 v |= HD64461_LCDCCR_MOFF;
199                 fb_writew(v, HD64461_LCDCCR);
200
201                 v = fb_readw(HD64461_STBCR);
202                 v |= HD64461_STBCR_SLCDST;
203                 fb_writew(v, HD64461_STBCR);
204         } else {
205                 v = fb_readw(HD64461_STBCR);
206                 v &= ~HD64461_STBCR_SLCDST;
207                 fb_writew(v, HD64461_STBCR);
208
209                 v = fb_readw(HD64461_LDR1);
210                 v |= HD64461_LDR1_DON;
211                 fb_writew(v, HD64461_LDR1);
212
213                 v = fb_readw(HD64461_LCDCCR);
214                 v &= ~HD64461_LCDCCR_MOFF;
215                 fb_writew(v, HD64461_LCDCCR);
216         }
217         return 0;
218 }
219
220 static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
221                            unsigned blue, unsigned transp, struct fb_info *info)
222 {
223         if (regno >= info->cmap.len)
224                 return 1;
225
226         switch (info->var.bits_per_pixel) {
227         case 8:
228                 fb_writew(regno << 8, HD64461_CPTWAR);
229                 fb_writew(red >> 10, HD64461_CPTWDR);
230                 fb_writew(green >> 10, HD64461_CPTWDR);
231                 fb_writew(blue >> 10, HD64461_CPTWDR);
232                 break;
233         case 16:
234                 ((u32 *) (info->pseudo_palette))[regno] =
235                     ((red & 0xf800)) |
236                     ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
237                 break;
238         }
239         return 0;
240 }
241
242 static struct fb_ops hitfb_ops = {
243         .owner          = THIS_MODULE,
244         .fb_setcolreg   = hitfb_setcolreg,
245         .fb_blank       = hitfb_blank,
246         .fb_pan_display = hitfb_pan_display,
247         .fb_fillrect    = hitfb_fillrect,
248         .fb_copyarea    = hitfb_copyarea,
249         .fb_imageblit   = cfb_imageblit,
250 };
251
252 int __init hitfb_init(void)
253 {
254         unsigned short lcdclor, ldr3, ldvndr;
255         int size;
256
257         if (fb_get_options("hitfb", NULL))
258                 return -ENODEV;
259
260         hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
261         hitfb_fix.smem_len = (MACH_HP690) ? 1024 * 1024 : 512 * 1024;
262
263         lcdclor = fb_readw(HD64461_LCDCLOR);
264         ldvndr = fb_readw(HD64461_LDVNDR);
265         ldr3 = fb_readw(HD64461_LDR3);
266
267         switch (ldr3 & 15) {
268         default:
269         case 4:
270                 hitfb_var.bits_per_pixel = 8;
271                 hitfb_var.xres = lcdclor;
272                 break;
273         case 8:
274                 hitfb_var.bits_per_pixel = 16;
275                 hitfb_var.xres = lcdclor / 2;
276                 break;
277         }
278         hitfb_fix.line_length = lcdclor;
279         hitfb_fix.visual = (hitfb_var.bits_per_pixel == 8) ?
280             FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
281         hitfb_var.yres = ldvndr + 1;
282         hitfb_var.xres_virtual = hitfb_var.xres;
283         hitfb_var.yres_virtual = hitfb_fix.smem_len / lcdclor;
284         switch (hitfb_var.bits_per_pixel) {
285         case 8:
286                 hitfb_var.red.offset = 0;
287                 hitfb_var.red.length = 8;
288                 hitfb_var.green.offset = 0;
289                 hitfb_var.green.length = 8;
290                 hitfb_var.blue.offset = 0;
291                 hitfb_var.blue.length = 8;
292                 hitfb_var.transp.offset = 0;
293                 hitfb_var.transp.length = 0;
294                 break;
295         case 16:                /* RGB 565 */
296                 hitfb_var.red.offset = 11;
297                 hitfb_var.red.length = 5;
298                 hitfb_var.green.offset = 5;
299                 hitfb_var.green.length = 6;
300                 hitfb_var.blue.offset = 0;
301                 hitfb_var.blue.length = 5;
302                 hitfb_var.transp.offset = 0;
303                 hitfb_var.transp.length = 0;
304                 break;
305         }
306
307         fb_info.fbops = &hitfb_ops;
308         fb_info.var = hitfb_var;
309         fb_info.fix = hitfb_fix;
310         fb_info.pseudo_palette = pseudo_palette;
311         fb_info.flags = FBINFO_DEFAULT;
312
313         fb_info.screen_base = (void *)hitfb_fix.smem_start;
314
315         size = (fb_info.var.bits_per_pixel == 8) ? 256 : 16;
316         fb_alloc_cmap(&fb_info.cmap, size, 0);
317
318         if (register_framebuffer(&fb_info) < 0)
319                 return -EINVAL;
320
321         printk(KERN_INFO "fb%d: %s frame buffer device\n",
322                fb_info.node, fb_info.fix.id);
323         return 0;
324 }
325
326 static void __exit hitfb_exit(void)
327 {
328         unregister_framebuffer(&fb_info);
329 }
330
331 module_init(hitfb_init);
332 module_exit(hitfb_exit);
333
334 MODULE_LICENSE("GPL");