Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / video / hitfb.c
blob5ba95497a749506893899430f13d03ed6c8d09d4
1 /*
2 * linux/drivers/video/hitfb.c -- Hitachi LCD frame buffer device
4 * (C) 1999 Mihai Spatar
5 * (C) 2000 YAEGASHI Takeshi
6 * (C) 2003, 2004 Paul Mundt
7 * (C) 2003, 2004, 2006 Andriy Skulysh
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.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/mm.h>
19 #include <linux/slab.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/fb.h>
25 #include <asm/machvec.h>
26 #include <asm/uaccess.h>
27 #include <asm/pgtable.h>
28 #include <asm/io.h>
29 #include <asm/hd64461.h>
30 #include <asm/cpu/dac.h>
32 #define WIDTH 640
34 static struct fb_var_screeninfo hitfb_var __initdata = {
35 .activate = FB_ACTIVATE_NOW,
36 .height = -1,
37 .width = -1,
38 .vmode = FB_VMODE_NONINTERLACED,
41 static struct fb_fix_screeninfo hitfb_fix __initdata = {
42 .id = "Hitachi HD64461",
43 .type = FB_TYPE_PACKED_PIXELS,
44 .accel = FB_ACCEL_NONE,
47 static u32 pseudo_palette[16];
48 static struct fb_info fb_info;
50 static inline void hitfb_accel_wait(void)
52 while (fb_readw(HD64461_GRCFGR) & HD64461_GRCFGR_ACCSTATUS) ;
55 static inline void hitfb_accel_start(int truecolor)
57 if (truecolor) {
58 fb_writew(6, HD64461_GRCFGR);
59 } else {
60 fb_writew(7, HD64461_GRCFGR);
64 static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
65 u16 width, u16 height)
67 u32 saddr = WIDTH * dy + dx;
68 if (truecolor)
69 saddr <<= 1;
71 fb_writew(width-1, HD64461_BBTDWR);
72 fb_writew(height-1, HD64461_BBTDHR);
74 fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
75 fb_writew(saddr >> 16, HD64461_BBTDSARH);
79 static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
80 u16 dy, u16 width, u16 height, u16 rop,
81 u32 mask_addr)
83 u32 saddr, daddr;
84 u32 maddr = 0;
86 height--;
87 width--;
88 fb_writew(rop, HD64461_BBTROPR);
89 if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
90 saddr = WIDTH * (sy + height) + sx + width;
91 daddr = WIDTH * (dy + height) + dx + width;
92 if (mask_addr) {
93 if (truecolor)
94 maddr = ((width >> 3) + 1) * (height + 1) - 1;
95 else
96 maddr =
97 (((width >> 4) + 1) * (height + 1) - 1) * 2;
99 fb_writew((1 << 5) | 1, HD64461_BBTMDR);
100 } else
101 fb_writew(1, HD64461_BBTMDR);
102 } else {
103 saddr = WIDTH * sy + sx;
104 daddr = WIDTH * dy + dx;
105 if (mask_addr) {
106 fb_writew((1 << 5), HD64461_BBTMDR);
107 } else {
108 fb_writew(0, HD64461_BBTMDR);
111 if (truecolor) {
112 saddr <<= 1;
113 daddr <<= 1;
115 fb_writew(width, HD64461_BBTDWR);
116 fb_writew(height, HD64461_BBTDHR);
117 fb_writew(saddr & 0xffff, HD64461_BBTSSARL);
118 fb_writew(saddr >> 16, HD64461_BBTSSARH);
119 fb_writew(daddr & 0xffff, HD64461_BBTDSARL);
120 fb_writew(daddr >> 16, HD64461_BBTDSARH);
121 if (mask_addr) {
122 maddr += mask_addr;
123 fb_writew(maddr & 0xffff, HD64461_BBTMARL);
124 fb_writew(maddr >> 16, HD64461_BBTMARH);
126 hitfb_accel_start(truecolor);
129 static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
131 if (rect->rop != ROP_COPY)
132 cfb_fillrect(p, rect);
133 else {
134 hitfb_accel_wait();
135 fb_writew(0x00f0, HD64461_BBTROPR);
136 fb_writew(16, HD64461_BBTMDR);
138 if (p->var.bits_per_pixel == 16) {
139 fb_writew(((u32 *) (p->pseudo_palette))[rect->color],
140 HD64461_GRSCR);
141 hitfb_accel_set_dest(1, rect->dx, rect->dy, rect->width,
142 rect->height);
143 hitfb_accel_start(1);
144 } else {
145 fb_writew(rect->color, HD64461_GRSCR);
146 hitfb_accel_set_dest(0, rect->dx, rect->dy, rect->width,
147 rect->height);
148 hitfb_accel_start(0);
153 static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
155 hitfb_accel_wait();
156 hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
157 area->dx, area->dy, area->width, area->height,
158 0x00cc, 0);
161 static int hitfb_pan_display(struct fb_var_screeninfo *var,
162 struct fb_info *info)
164 int xoffset = var->xoffset;
165 int yoffset = var->yoffset;
167 if (xoffset != 0)
168 return -EINVAL;
170 fb_writew((yoffset*info->fix.line_length)>>10, HD64461_LCDCBAR);
172 return 0;
175 int hitfb_blank(int blank_mode, struct fb_info *info)
177 unsigned short v;
179 if (blank_mode) {
180 v = fb_readw(HD64461_LDR1);
181 v &= ~HD64461_LDR1_DON;
182 fb_writew(v, HD64461_LDR1);
184 v = fb_readw(HD64461_LCDCCR);
185 v |= HD64461_LCDCCR_MOFF;
186 fb_writew(v, HD64461_LCDCCR);
188 v = fb_readw(HD64461_STBCR);
189 v |= HD64461_STBCR_SLCDST;
190 fb_writew(v, HD64461_STBCR);
191 } else {
192 v = fb_readw(HD64461_STBCR);
193 v &= ~HD64461_STBCR_SLCDST;
194 fb_writew(v, HD64461_STBCR);
196 v = fb_readw(HD64461_LCDCCR);
197 v &= ~(HD64461_LCDCCR_MOFF | HD64461_LCDCCR_STREQ);
198 fb_writew(v, HD64461_LCDCCR);
200 do {
201 v = fb_readw(HD64461_LCDCCR);
202 } while(v&HD64461_LCDCCR_STBACK);
204 v = fb_readw(HD64461_LDR1);
205 v |= HD64461_LDR1_DON;
206 fb_writew(v, HD64461_LDR1);
208 return 0;
211 static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
212 unsigned blue, unsigned transp, struct fb_info *info)
214 if (regno >= 256)
215 return 1;
217 switch (info->var.bits_per_pixel) {
218 case 8:
219 fb_writew(regno << 8, HD64461_CPTWAR);
220 fb_writew(red >> 10, HD64461_CPTWDR);
221 fb_writew(green >> 10, HD64461_CPTWDR);
222 fb_writew(blue >> 10, HD64461_CPTWDR);
223 break;
224 case 16:
225 if (regno >= 16)
226 return 1;
227 ((u32 *) (info->pseudo_palette))[regno] =
228 ((red & 0xf800)) |
229 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
230 break;
232 return 0;
235 static int hitfb_sync(struct fb_info *info)
237 hitfb_accel_wait();
239 return 0;
242 static int hitfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
244 int maxy;
246 var->xres = info->var.xres;
247 var->xres_virtual = info->var.xres;
248 var->yres = info->var.yres;
250 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16))
251 var->bits_per_pixel = info->var.bits_per_pixel;
253 if (var->yres_virtual < var->yres)
254 var->yres_virtual = var->yres;
256 maxy = info->fix.smem_len / var->xres;
258 if (var->bits_per_pixel == 16)
259 maxy /= 2;
261 if (var->yres_virtual > maxy)
262 var->yres_virtual = maxy;
264 var->xoffset = 0;
265 var->yoffset = 0;
267 switch (var->bits_per_pixel) {
268 case 8:
269 var->red.offset = 0;
270 var->red.length = 8;
271 var->green.offset = 0;
272 var->green.length = 8;
273 var->blue.offset = 0;
274 var->blue.length = 8;
275 var->transp.offset = 0;
276 var->transp.length = 0;
277 break;
278 case 16: /* RGB 565 */
279 var->red.offset = 11;
280 var->red.length = 5;
281 var->green.offset = 5;
282 var->green.length = 6;
283 var->blue.offset = 0;
284 var->blue.length = 5;
285 var->transp.offset = 0;
286 var->transp.length = 0;
287 break;
290 return 0;
293 static int hitfb_set_par(struct fb_info *info)
295 unsigned short ldr3;
297 switch (info->var.bits_per_pixel) {
298 case 8:
299 info->fix.line_length = info->var.xres;
300 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
301 info->fix.ypanstep = 16;
302 break;
303 case 16:
304 info->fix.line_length = info->var.xres*2;
305 info->fix.visual = FB_VISUAL_TRUECOLOR;
306 info->fix.ypanstep = 8;
307 break;
310 fb_writew(info->fix.line_length, HD64461_LCDCLOR);
311 ldr3 = fb_readw(HD64461_LDR3);
312 ldr3 &= ~15;
313 ldr3 |= (info->var.bits_per_pixel == 8) ? 4 : 8;
314 fb_writew(ldr3, HD64461_LDR3);
315 return 0;
318 static struct fb_ops hitfb_ops = {
319 .owner = THIS_MODULE,
320 .fb_check_var = hitfb_check_var,
321 .fb_set_par = hitfb_set_par,
322 .fb_setcolreg = hitfb_setcolreg,
323 .fb_blank = hitfb_blank,
324 .fb_sync = hitfb_sync,
325 .fb_pan_display = hitfb_pan_display,
326 .fb_fillrect = hitfb_fillrect,
327 .fb_copyarea = hitfb_copyarea,
328 .fb_imageblit = cfb_imageblit,
331 static int __init hitfb_probe(struct platform_device *dev)
333 unsigned short lcdclor, ldr3, ldvndr;
335 if (fb_get_options("hitfb", NULL))
336 return -ENODEV;
338 hitfb_fix.mmio_start = CONFIG_HD64461_IOBASE+0x1000;
339 hitfb_fix.mmio_len = 0x1000;
340 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
341 hitfb_fix.smem_len = 512 * 1024;
343 lcdclor = fb_readw(HD64461_LCDCLOR);
344 ldvndr = fb_readw(HD64461_LDVNDR);
345 ldr3 = fb_readw(HD64461_LDR3);
347 switch (ldr3 & 15) {
348 default:
349 case 4:
350 hitfb_var.bits_per_pixel = 8;
351 hitfb_var.xres = lcdclor;
352 break;
353 case 8:
354 hitfb_var.bits_per_pixel = 16;
355 hitfb_var.xres = lcdclor / 2;
356 break;
358 hitfb_fix.line_length = lcdclor;
359 hitfb_fix.visual = (hitfb_var.bits_per_pixel == 8) ?
360 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
361 hitfb_var.yres = ldvndr + 1;
362 hitfb_var.xres_virtual = hitfb_var.xres;
363 hitfb_var.yres_virtual = hitfb_fix.smem_len / lcdclor;
364 switch (hitfb_var.bits_per_pixel) {
365 case 8:
366 hitfb_var.red.offset = 0;
367 hitfb_var.red.length = 8;
368 hitfb_var.green.offset = 0;
369 hitfb_var.green.length = 8;
370 hitfb_var.blue.offset = 0;
371 hitfb_var.blue.length = 8;
372 hitfb_var.transp.offset = 0;
373 hitfb_var.transp.length = 0;
374 break;
375 case 16: /* RGB 565 */
376 hitfb_var.red.offset = 11;
377 hitfb_var.red.length = 5;
378 hitfb_var.green.offset = 5;
379 hitfb_var.green.length = 6;
380 hitfb_var.blue.offset = 0;
381 hitfb_var.blue.length = 5;
382 hitfb_var.transp.offset = 0;
383 hitfb_var.transp.length = 0;
384 break;
387 fb_info.fbops = &hitfb_ops;
388 fb_info.var = hitfb_var;
389 fb_info.fix = hitfb_fix;
390 fb_info.pseudo_palette = pseudo_palette;
391 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
392 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
394 fb_info.screen_base = (void *)hitfb_fix.smem_start;
396 fb_alloc_cmap(&fb_info.cmap, 256, 0);
398 if (register_framebuffer(&fb_info) < 0)
399 return -EINVAL;
401 printk(KERN_INFO "fb%d: %s frame buffer device\n",
402 fb_info.node, fb_info.fix.id);
403 return 0;
406 <<<<<<< HEAD:drivers/video/hitfb.c
407 static int __devexit hitfb_remove(struct platform_device *dev)
408 =======
409 static int __exit hitfb_remove(struct platform_device *dev)
410 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/video/hitfb.c
412 return unregister_framebuffer(&fb_info);
415 #ifdef CONFIG_PM
416 static int hitfb_suspend(struct platform_device *dev, pm_message_t state)
418 u16 v;
420 hitfb_blank(1,0);
421 v = fb_readw(HD64461_STBCR);
422 v |= HD64461_STBCR_SLCKE_IST;
423 fb_writew(v, HD64461_STBCR);
425 return 0;
428 static int hitfb_resume(struct platform_device *dev)
430 u16 v;
432 v = fb_readw(HD64461_STBCR);
433 v &= ~HD64461_STBCR_SLCKE_OST;
434 msleep(100);
435 v = fb_readw(HD64461_STBCR);
436 v &= ~HD64461_STBCR_SLCKE_IST;
437 fb_writew(v, HD64461_STBCR);
438 hitfb_blank(0,0);
440 return 0;
442 #endif
444 static struct platform_driver hitfb_driver = {
445 .probe = hitfb_probe,
446 <<<<<<< HEAD:drivers/video/hitfb.c
447 .remove = __devexit_p(hitfb_remove),
448 =======
449 .remove = __exit_p(hitfb_remove),
450 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/video/hitfb.c
451 #ifdef CONFIG_PM
452 .suspend = hitfb_suspend,
453 .resume = hitfb_resume,
454 #endif
455 .driver = {
456 .name = "hitfb",
460 static struct platform_device hitfb_device = {
461 .name = "hitfb",
462 .id = -1,
465 static int __init hitfb_init(void)
467 int ret;
469 ret = platform_driver_register(&hitfb_driver);
470 if (!ret) {
471 ret = platform_device_register(&hitfb_device);
472 if (ret)
473 platform_driver_unregister(&hitfb_driver);
475 return ret;
479 static void __exit hitfb_exit(void)
481 platform_device_unregister(&hitfb_device);
482 platform_driver_unregister(&hitfb_driver);
485 module_init(hitfb_init);
486 module_exit(hitfb_exit);
488 MODULE_LICENSE("GPL");