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 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/tty.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/init.h>
26 #include <asm/machvec.h>
27 #include <asm/uaccess.h>
28 #include <asm/pgtable.h>
30 #include <asm/hd64461/hd64461.h>
33 #include <asm/cpu/dac.h>
34 #include <asm/hp6xx/hp6xx.h>
39 static struct fb_var_screeninfo hitfb_var __initdata = {
40 .activate = FB_ACTIVATE_NOW,
43 .vmode = FB_VMODE_NONINTERLACED,
46 static struct fb_fix_screeninfo hitfb_fix __initdata = {
47 .id = "Hitachi HD64461",
48 .type = FB_TYPE_PACKED_PIXELS,
50 .accel = FB_ACCEL_NONE,
53 static u32 pseudo_palette[16];
54 static struct fb_info fb_info;
56 static inline void hitfb_accel_wait(void)
58 while (fb_readw(HD64461_GRCFGR) & HD64461_GRCFGR_ACCSTATUS) ;
61 static inline void hitfb_accel_start(int truecolor)
64 fb_writew(6, HD64461_GRCFGR);
66 fb_writew(7, HD64461_GRCFGR);
70 static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
71 u16 width, u16 height)
73 u32 saddr = WIDTH * dy + dx;
77 fb_writew(width, HD64461_BBTDWR);
78 fb_writew(height, HD64461_BBTDHR);
80 fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
81 fb_writew(saddr >> 16, HD64461_BBTDSARH);
85 static inline void hitfb_accel_solidfill(int truecolor, u16 dx, u16 dy,
86 u16 width, u16 height, u16 color)
88 hitfb_accel_set_dest(truecolor, dx, dy, width, height);
90 fb_writew(0x00f0, HD64461_BBTROPR);
91 fb_writew(16, HD64461_BBTMDR);
92 fb_writew(color, HD64461_GRSCR);
94 hitfb_accel_start(truecolor);
97 static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
98 u16 dy, u16 width, u16 height, u16 rop,
104 fb_writew(rop, HD64461_BBTROPR);
105 if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
106 saddr = WIDTH * (sy + height) + sx + width;
107 daddr = WIDTH * (dy + height) + dx + width;
110 maddr = ((width >> 3) + 1) * (height + 1) - 1;
113 (((width >> 4) + 1) * (height + 1) - 1) * 2;
115 fb_writew((1 << 5) | 1, HD64461_BBTMDR);
117 fb_writew(1, HD64461_BBTMDR);
119 saddr = WIDTH * sy + sx;
120 daddr = WIDTH * dy + dx;
122 fb_writew((1 << 5), HD64461_BBTMDR);
124 fb_writew(0, HD64461_BBTMDR);
131 fb_writew(width, HD64461_BBTDWR);
132 fb_writew(height, HD64461_BBTDHR);
133 fb_writew(saddr & 0xffff, HD64461_BBTSSARL);
134 fb_writew(saddr >> 16, HD64461_BBTSSARH);
135 fb_writew(daddr & 0xffff, HD64461_BBTDSARL);
136 fb_writew(daddr >> 16, HD64461_BBTDSARH);
139 fb_writew(maddr & 0xffff, HD64461_BBTMARL);
140 fb_writew(maddr >> 16, HD64461_BBTMARH);
142 hitfb_accel_start(truecolor);
145 static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
147 if (rect->rop != ROP_COPY)
148 cfb_fillrect(p, rect);
150 fb_writew(0x00f0, HD64461_BBTROPR);
151 fb_writew(16, HD64461_BBTMDR);
153 if (p->var.bits_per_pixel == 16) {
154 fb_writew(((u32 *) (p->pseudo_palette))[rect->color],
156 hitfb_accel_set_dest(1, rect->dx, rect->dy, rect->width,
158 hitfb_accel_start(1);
160 fb_writew(rect->color, HD64461_GRSCR);
161 hitfb_accel_set_dest(0, rect->dx, rect->dy, rect->width,
163 hitfb_accel_start(0);
169 static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
171 hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
172 area->dx, area->dy, area->width, area->height,
177 static int hitfb_pan_display(struct fb_var_screeninfo *var,
178 struct fb_info *info)
180 int xoffset = var->xoffset;
181 int yoffset = var->yoffset;
186 fb_writew(yoffset, HD64461_LCDCBAR);
191 int hitfb_blank(int blank_mode, struct fb_info *info)
197 sh_dac_disable(DAC_LCD_BRIGHTNESS);
198 v = fb_readw(HD64461_GPBDR);
199 v |= HD64461_GPBDR_LCDOFF;
200 fb_writew(v, HD64461_GPBDR);
202 v = fb_readw(HD64461_LDR1);
203 v &= ~HD64461_LDR1_DON;
204 fb_writew(v, HD64461_LDR1);
206 v = fb_readw(HD64461_LCDCCR);
207 v |= HD64461_LCDCCR_MOFF;
208 fb_writew(v, HD64461_LCDCCR);
210 v = fb_readw(HD64461_STBCR);
211 v |= HD64461_STBCR_SLCDST;
212 fb_writew(v, HD64461_STBCR);
214 v = fb_readw(HD64461_STBCR);
215 v &= ~HD64461_STBCR_SLCDST;
216 fb_writew(v, HD64461_STBCR);
218 sh_dac_enable(DAC_LCD_BRIGHTNESS);
219 v = fb_readw(HD64461_GPBDR);
220 v &= ~HD64461_GPBDR_LCDOFF;
221 fb_writew(v, HD64461_GPBDR);
223 v = fb_readw(HD64461_LDR1);
224 v |= HD64461_LDR1_DON;
225 fb_writew(v, HD64461_LDR1);
227 v = fb_readw(HD64461_LCDCCR);
228 v &= ~HD64461_LCDCCR_MOFF;
229 fb_writew(v, HD64461_LCDCCR);
234 static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
235 unsigned blue, unsigned transp, struct fb_info *info)
237 if (regno >= info->cmap.len)
240 switch (info->var.bits_per_pixel) {
242 fb_writew(regno << 8, HD64461_CPTWAR);
243 fb_writew(red >> 10, HD64461_CPTWDR);
244 fb_writew(green >> 10, HD64461_CPTWDR);
245 fb_writew(blue >> 10, HD64461_CPTWDR);
248 ((u32 *) (info->pseudo_palette))[regno] =
250 ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
256 static struct fb_ops hitfb_ops = {
257 .owner = THIS_MODULE,
258 .fb_setcolreg = hitfb_setcolreg,
259 .fb_blank = hitfb_blank,
260 .fb_pan_display = hitfb_pan_display,
261 .fb_fillrect = hitfb_fillrect,
262 .fb_copyarea = hitfb_copyarea,
263 .fb_imageblit = cfb_imageblit,
266 int __init hitfb_init(void)
268 unsigned short lcdclor, ldr3, ldvndr;
271 if (fb_get_options("hitfb", NULL))
274 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000;
275 hitfb_fix.smem_len = (MACH_HP690) ? 1024 * 1024 : 512 * 1024;
277 lcdclor = fb_readw(HD64461_LCDCLOR);
278 ldvndr = fb_readw(HD64461_LDVNDR);
279 ldr3 = fb_readw(HD64461_LDR3);
284 hitfb_var.bits_per_pixel = 8;
285 hitfb_var.xres = lcdclor;
288 hitfb_var.bits_per_pixel = 16;
289 hitfb_var.xres = lcdclor / 2;
292 hitfb_fix.line_length = lcdclor;
293 hitfb_fix.visual = (hitfb_var.bits_per_pixel == 8) ?
294 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
295 hitfb_var.yres = ldvndr + 1;
296 hitfb_var.xres_virtual = hitfb_var.xres;
297 hitfb_var.yres_virtual = hitfb_fix.smem_len / lcdclor;
298 switch (hitfb_var.bits_per_pixel) {
300 hitfb_var.red.offset = 0;
301 hitfb_var.red.length = 8;
302 hitfb_var.green.offset = 0;
303 hitfb_var.green.length = 8;
304 hitfb_var.blue.offset = 0;
305 hitfb_var.blue.length = 8;
306 hitfb_var.transp.offset = 0;
307 hitfb_var.transp.length = 0;
309 case 16: /* RGB 565 */
310 hitfb_var.red.offset = 11;
311 hitfb_var.red.length = 5;
312 hitfb_var.green.offset = 5;
313 hitfb_var.green.length = 6;
314 hitfb_var.blue.offset = 0;
315 hitfb_var.blue.length = 5;
316 hitfb_var.transp.offset = 0;
317 hitfb_var.transp.length = 0;
321 fb_info.fbops = &hitfb_ops;
322 fb_info.var = hitfb_var;
323 fb_info.fix = hitfb_fix;
324 fb_info.pseudo_palette = pseudo_palette;
325 fb_info.flags = FBINFO_DEFAULT;
327 fb_info.screen_base = (void *)hitfb_fix.smem_start;
329 size = (fb_info.var.bits_per_pixel == 8) ? 256 : 16;
330 fb_alloc_cmap(&fb_info.cmap, size, 0);
332 if (register_framebuffer(&fb_info) < 0)
335 printk(KERN_INFO "fb%d: %s frame buffer device\n",
336 fb_info.node, fb_info.fix.id);
340 static void __exit hitfb_exit(void)
342 unregister_framebuffer(&fb_info);
345 module_init(hitfb_init);
346 module_exit(hitfb_exit);
348 MODULE_LICENSE("GPL");