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/errno.h>
17 #include <linux/string.h>
19 #include <linux/slab.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
25 #include <asm/machvec.h>
26 #include <asm/uaccess.h>
27 #include <asm/pgtable.h>
29 #include <asm/hd64461.h>
30 #include <asm/cpu/dac.h>
34 static struct fb_var_screeninfo hitfb_var __initdata
= {
35 .activate
= FB_ACTIVATE_NOW
,
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
)
58 fb_writew(6, HD64461_GRCFGR
);
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
;
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
,
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
;
94 maddr
= ((width
>> 3) + 1) * (height
+ 1) - 1;
97 (((width
>> 4) + 1) * (height
+ 1) - 1) * 2;
99 fb_writew((1 << 5) | 1, HD64461_BBTMDR
);
101 fb_writew(1, HD64461_BBTMDR
);
103 saddr
= WIDTH
* sy
+ sx
;
104 daddr
= WIDTH
* dy
+ dx
;
106 fb_writew((1 << 5), HD64461_BBTMDR
);
108 fb_writew(0, HD64461_BBTMDR
);
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
);
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
);
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
],
141 hitfb_accel_set_dest(1, rect
->dx
, rect
->dy
, rect
->width
,
143 hitfb_accel_start(1);
145 fb_writew(rect
->color
, HD64461_GRSCR
);
146 hitfb_accel_set_dest(0, rect
->dx
, rect
->dy
, rect
->width
,
148 hitfb_accel_start(0);
153 static void hitfb_copyarea(struct fb_info
*p
, const struct fb_copyarea
*area
)
156 hitfb_accel_bitblt(p
->var
.bits_per_pixel
== 16, area
->sx
, area
->sy
,
157 area
->dx
, area
->dy
, area
->width
, area
->height
,
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
;
170 fb_writew((yoffset
*info
->fix
.line_length
)>>10, HD64461_LCDCBAR
);
175 int hitfb_blank(int blank_mode
, struct fb_info
*info
)
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
);
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
);
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
);
211 static int hitfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
212 unsigned blue
, unsigned transp
, struct fb_info
*info
)
217 switch (info
->var
.bits_per_pixel
) {
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
);
227 ((u32
*) (info
->pseudo_palette
))[regno
] =
229 ((green
& 0xfc00) >> 5) | ((blue
& 0xf800) >> 11);
235 static int hitfb_sync(struct fb_info
*info
)
242 static int hitfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
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)
261 if (var
->yres_virtual
> maxy
)
262 var
->yres_virtual
= maxy
;
267 switch (var
->bits_per_pixel
) {
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;
278 case 16: /* RGB 565 */
279 var
->red
.offset
= 11;
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;
293 static int hitfb_set_par(struct fb_info
*info
)
297 switch (info
->var
.bits_per_pixel
) {
299 info
->fix
.line_length
= info
->var
.xres
;
300 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
301 info
->fix
.ypanstep
= 16;
304 info
->fix
.line_length
= info
->var
.xres
*2;
305 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
306 info
->fix
.ypanstep
= 8;
310 fb_writew(info
->fix
.line_length
, HD64461_LCDCLOR
);
311 ldr3
= fb_readw(HD64461_LDR3
);
313 ldr3
|= (info
->var
.bits_per_pixel
== 8) ? 4 : 8;
314 fb_writew(ldr3
, HD64461_LDR3
);
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
))
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
);
350 hitfb_var
.bits_per_pixel
= 8;
351 hitfb_var
.xres
= lcdclor
;
354 hitfb_var
.bits_per_pixel
= 16;
355 hitfb_var
.xres
= lcdclor
/ 2;
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
) {
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;
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;
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)
401 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
402 fb_info
.node
, fb_info
.fix
.id
);
406 static int __devexit
hitfb_remove(struct platform_device
*dev
)
408 return unregister_framebuffer(&fb_info
);
412 static int hitfb_suspend(struct platform_device
*dev
, pm_message_t state
)
417 v
= fb_readw(HD64461_STBCR
);
418 v
|= HD64461_STBCR_SLCKE_IST
;
419 fb_writew(v
, HD64461_STBCR
);
424 static int hitfb_resume(struct platform_device
*dev
)
428 v
= fb_readw(HD64461_STBCR
);
429 v
&= ~HD64461_STBCR_SLCKE_OST
;
431 v
= fb_readw(HD64461_STBCR
);
432 v
&= ~HD64461_STBCR_SLCKE_IST
;
433 fb_writew(v
, HD64461_STBCR
);
440 static struct platform_driver hitfb_driver
= {
441 .probe
= hitfb_probe
,
442 .remove
= __devexit_p(hitfb_remove
),
444 .suspend
= hitfb_suspend
,
445 .resume
= hitfb_resume
,
452 static struct platform_device hitfb_device
= {
457 static int __init
hitfb_init(void)
461 ret
= platform_driver_register(&hitfb_driver
);
463 ret
= platform_device_register(&hitfb_device
);
465 platform_driver_unregister(&hitfb_driver
);
471 static void __exit
hitfb_exit(void)
473 platform_device_unregister(&hitfb_device
);
474 platform_driver_unregister(&hitfb_driver
);
477 module_init(hitfb_init
);
478 module_exit(hitfb_exit
);
480 MODULE_LICENSE("GPL");