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