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
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>
20 #include <linux/slab.h>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/platform_device.h>
26 #include <asm/machvec.h>
27 #include <asm/uaccess.h>
28 #include <asm/pgtable.h>
30 #include <asm/hd64461.h>
31 #include <asm/cpu/dac.h>
32 #include <asm/hp6xx/hp6xx.h>
36 static struct fb_var_screeninfo hitfb_var __initdata = {
37 .activate = FB_ACTIVATE_NOW,
40 .vmode = FB_VMODE_NONINTERLACED,
43 static struct fb_fix_screeninfo hitfb_fix __initdata = {
44 .id = "Hitachi HD64461",
45 .type = FB_TYPE_PACKED_PIXELS,
46 .accel = FB_ACCEL_NONE,
49 static u32 pseudo_palette[16];
50 static struct fb_info fb_info;
52 static inline void hitfb_accel_wait(void)
54 while (fb_readw(HD64461_GRCFGR) & HD64461_GRCFGR_ACCSTATUS) ;
57 static inline void hitfb_accel_start(int truecolor)
60 fb_writew(6, HD64461_GRCFGR);
62 fb_writew(7, HD64461_GRCFGR);
66 static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
67 u16 width, u16 height)
69 u32 saddr = WIDTH * dy + dx;
73 fb_writew(width-1, HD64461_BBTDWR);
74 fb_writew(height-1, HD64461_BBTDHR);
76 fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
77 fb_writew(saddr >> 16, HD64461_BBTDSARH);
81 static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
82 u16 dy, u16 width, u16 height, u16 rop,
90 fb_writew(rop, HD64461_BBTROPR);
91 if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
92 saddr = WIDTH * (sy + height) + sx + width;
93 daddr = WIDTH * (dy + height) + dx + width;
96 maddr = ((width >> 3) + 1) * (height + 1) - 1;
99 (((width >> 4) + 1) * (height + 1) - 1) * 2;
101 fb_writew((1 << 5) | 1, HD64461_BBTMDR);
103 fb_writew(1, HD64461_BBTMDR);
105 saddr = WIDTH * sy + sx;
106 daddr = WIDTH * dy + dx;
108 fb_writew((1 << 5), HD64461_BBTMDR);
110 fb_writew(0, HD64461_BBTMDR);
117 fb_writew(width, HD64461_BBTDWR);
118 fb_writew(height, HD64461_BBTDHR);
119 fb_writew(saddr & 0xffff, HD64461_BBTSSARL);
120 fb_writew(saddr >> 16, HD64461_BBTSSARH);
121 fb_writew(daddr & 0xffff, HD64461_BBTDSARL);
122 fb_writew(daddr >> 16, HD64461_BBTDSARH);
125 fb_writew(maddr & 0xffff, HD64461_BBTMARL);
126 fb_writew(maddr >> 16, HD64461_BBTMARH);
128 hitfb_accel_start(truecolor);
131 static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
133 if (rect->rop != ROP_COPY)
134 cfb_fillrect(p, rect);
137 fb_writew(0x00f0, HD64461_BBTROPR);
138 fb_writew(16, HD64461_BBTMDR);
140 if (p->var.bits_per_pixel == 16) {
141 fb_writew(((u32 *) (p->pseudo_palette))[rect->color],
143 hitfb_accel_set_dest(1, rect->dx, rect->dy, rect->width,
145 hitfb_accel_start(1);
147 fb_writew(rect->color, HD64461_GRSCR);
148 hitfb_accel_set_dest(0, rect->dx, rect->dy, rect->width,
150 hitfb_accel_start(0);
155 static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
158 hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
159 area->dx, area->dy, area->width, area->height,
163 static int hitfb_pan_display(struct fb_var_screeninfo *var,
164 struct fb_info *info)
166 int xoffset = var->xoffset;
167 int yoffset = var->yoffset;
172 fb_writew((yoffset*info->fix.line_length)>>10, HD64461_LCDCBAR);
177 int hitfb_blank(int blank_mode, struct fb_info *info)
182 v = fb_readw(HD64461_LDR1);
183 v &= ~HD64461_LDR1_DON;
184 fb_writew(v, HD64461_LDR1);
186 v = fb_readw(HD64461_LCDCCR);
187 v |= HD64461_LCDCCR_MOFF;
188 fb_writew(v, HD64461_LCDCCR);
190 v = fb_readw(HD64461_STBCR);
191 v |= HD64461_STBCR_SLCDST;
192 fb_writew(v, HD64461_STBCR);
194 v = fb_readw(HD64461_STBCR);
195 v &= ~HD64461_STBCR_SLCDST;
196 fb_writew(v, HD64461_STBCR);
198 v = fb_readw(HD64461_LCDCCR);
199 v &= ~(HD64461_LCDCCR_MOFF | HD64461_LCDCCR_STREQ);
200 fb_writew(v, HD64461_LCDCCR);
203 v = fb_readw(HD64461_LCDCCR);
204 } while(v&HD64461_LCDCCR_STBACK);
206 v = fb_readw(HD64461_LDR1);
207 v |= HD64461_LDR1_DON;
208 fb_writew(v, HD64461_LDR1);
213 static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
214 unsigned blue, unsigned transp, struct fb_info *info)
219 switch (info->var.bits_per_pixel) {
221 fb_writew(regno << 8, HD64461_CPTWAR);
222 fb_writew(red >> 10, HD64461_CPTWDR);
223 fb_writew(green >> 10, HD64461_CPTWDR);
224 fb_writew(blue >> 10, HD64461_CPTWDR);
229 ((u32 *) (info->pseudo_palette))[regno] =
231 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
237 static int hitfb_sync(struct fb_info *info)
244 static int hitfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
248 var->xres = info->var.xres;
249 var->xres_virtual = info->var.xres;
250 var->yres = info->var.yres;
252 if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16))
253 var->bits_per_pixel = info->var.bits_per_pixel;
255 if (var->yres_virtual < var->yres)
256 var->yres_virtual = var->yres;
258 maxy = info->fix.smem_len / var->xres;
260 if (var->bits_per_pixel == 16)
263 if (var->yres_virtual > maxy)
264 var->yres_virtual = maxy;
269 switch (var->bits_per_pixel) {
273 var->green.offset = 0;
274 var->green.length = 8;
275 var->blue.offset = 0;
276 var->blue.length = 8;
277 var->transp.offset = 0;
278 var->transp.length = 0;
280 case 16: /* RGB 565 */
281 var->red.offset = 11;
283 var->green.offset = 5;
284 var->green.length = 6;
285 var->blue.offset = 0;
286 var->blue.length = 5;
287 var->transp.offset = 0;
288 var->transp.length = 0;
295 static int hitfb_set_par(struct fb_info *info)
299 switch (info->var.bits_per_pixel) {
301 info->fix.line_length = info->var.xres;
302 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
303 info->fix.ypanstep = 16;
306 info->fix.line_length = info->var.xres*2;
307 info->fix.visual = FB_VISUAL_TRUECOLOR;
308 info->fix.ypanstep = 8;
312 fb_writew(info->fix.line_length, HD64461_LCDCLOR);
313 ldr3 = fb_readw(HD64461_LDR3);
315 ldr3 |= (info->var.bits_per_pixel == 8) ? 4 : 8;
316 fb_writew(ldr3, HD64461_LDR3);
320 static struct fb_ops hitfb_ops = {
321 .owner = THIS_MODULE,
322 .fb_check_var = hitfb_check_var,
323 .fb_set_par = hitfb_set_par,
324 .fb_setcolreg = hitfb_setcolreg,
325 .fb_blank = hitfb_blank,
326 .fb_sync = hitfb_sync,
327 .fb_pan_display = hitfb_pan_display,
328 .fb_fillrect = hitfb_fillrect,
329 .fb_copyarea = hitfb_copyarea,
330 .fb_imageblit = cfb_imageblit,
333 static int __init hitfb_probe(struct platform_device *dev)
335 unsigned short lcdclor, ldr3, ldvndr;
337 if (fb_get_options("hitfb", NULL))
340 hitfb_fix.mmio_start = CONFIG_HD64461_IOBASE+0x1000;
341 hitfb_fix.mmio_len = 0x1000;
342 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
343 hitfb_fix.smem_len = 512 * 1024;
345 lcdclor = fb_readw(HD64461_LCDCLOR);
346 ldvndr = fb_readw(HD64461_LDVNDR);
347 ldr3 = fb_readw(HD64461_LDR3);
352 hitfb_var.bits_per_pixel = 8;
353 hitfb_var.xres = lcdclor;
356 hitfb_var.bits_per_pixel = 16;
357 hitfb_var.xres = lcdclor / 2;
360 hitfb_fix.line_length = lcdclor;
361 hitfb_fix.visual = (hitfb_var.bits_per_pixel == 8) ?
362 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
363 hitfb_var.yres = ldvndr + 1;
364 hitfb_var.xres_virtual = hitfb_var.xres;
365 hitfb_var.yres_virtual = hitfb_fix.smem_len / lcdclor;
366 switch (hitfb_var.bits_per_pixel) {
368 hitfb_var.red.offset = 0;
369 hitfb_var.red.length = 8;
370 hitfb_var.green.offset = 0;
371 hitfb_var.green.length = 8;
372 hitfb_var.blue.offset = 0;
373 hitfb_var.blue.length = 8;
374 hitfb_var.transp.offset = 0;
375 hitfb_var.transp.length = 0;
377 case 16: /* RGB 565 */
378 hitfb_var.red.offset = 11;
379 hitfb_var.red.length = 5;
380 hitfb_var.green.offset = 5;
381 hitfb_var.green.length = 6;
382 hitfb_var.blue.offset = 0;
383 hitfb_var.blue.length = 5;
384 hitfb_var.transp.offset = 0;
385 hitfb_var.transp.length = 0;
389 fb_info.fbops = &hitfb_ops;
390 fb_info.var = hitfb_var;
391 fb_info.fix = hitfb_fix;
392 fb_info.pseudo_palette = pseudo_palette;
393 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
394 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
396 fb_info.screen_base = (void *)hitfb_fix.smem_start;
398 fb_alloc_cmap(&fb_info.cmap, 256, 0);
400 if (register_framebuffer(&fb_info) < 0)
403 printk(KERN_INFO "fb%d: %s frame buffer device\n",
404 fb_info.node, fb_info.fix.id);
408 static int __devexit hitfb_remove(struct platform_device *dev)
410 return unregister_framebuffer(&fb_info);
414 static int hitfb_suspend(struct platform_device *dev, pm_message_t state)
419 v = fb_readw(HD64461_STBCR);
420 v |= HD64461_STBCR_SLCKE_IST;
421 fb_writew(v, HD64461_STBCR);
426 static int hitfb_resume(struct platform_device *dev)
430 v = fb_readw(HD64461_STBCR);
431 v &= ~HD64461_STBCR_SLCKE_OST;
433 v = fb_readw(HD64461_STBCR);
434 v &= ~HD64461_STBCR_SLCKE_IST;
435 fb_writew(v, HD64461_STBCR);
442 static struct platform_driver hitfb_driver = {
443 .probe = hitfb_probe,
444 .remove = __devexit_p(hitfb_remove),
446 .suspend = hitfb_suspend,
447 .resume = hitfb_resume,
454 static struct platform_device hitfb_device = {
459 static int __init hitfb_init(void)
463 ret = platform_driver_register(&hitfb_driver);
465 ret = platform_device_register(&hitfb_device);
467 platform_driver_unregister(&hitfb_driver);
473 static void __exit hitfb_exit(void)
475 platform_device_unregister(&hitfb_device);
476 platform_driver_unregister(&hitfb_driver);
479 module_init(hitfb_init);
480 module_exit(hitfb_exit);
482 MODULE_LICENSE("GPL");