blob: a23cfdb9d826391ff5d4007fb33f884da0d53f1c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* leo.c: LEO frame buffer driver
2 *
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
4 * Copyright (C) 1996-1999 Jakub Jelinek (jj@ultra.linux.cz)
5 * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz)
6 *
7 * Driver layout based loosely on tgafb.c, see that file for credits.
8 */
9
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/errno.h>
13#include <linux/string.h>
14#include <linux/slab.h>
15#include <linux/delay.h>
16#include <linux/init.h>
17#include <linux/fb.h>
18#include <linux/mm.h>
19
20#include <asm/io.h>
21#include <asm/sbus.h>
22#include <asm/oplib.h>
23#include <asm/fbio.h>
24
25#include "sbuslib.h"
26
27/*
28 * Local functions.
29 */
30
31static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
32 unsigned, struct fb_info *);
33static int leo_blank(int, struct fb_info *);
34
Christoph Hellwig216d5262006-01-14 13:21:25 -080035static int leo_mmap(struct fb_info *, struct vm_area_struct *);
Christoph Hellwig67a66802006-01-14 13:21:25 -080036static int leo_ioctl(struct fb_info *, unsigned int, unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *);
38
39/*
40 * Frame buffer operations
41 */
42
43static struct fb_ops leo_ops = {
44 .owner = THIS_MODULE,
45 .fb_setcolreg = leo_setcolreg,
46 .fb_blank = leo_blank,
47 .fb_pan_display = leo_pan_display,
48 .fb_fillrect = cfb_fillrect,
49 .fb_copyarea = cfb_copyarea,
50 .fb_imageblit = cfb_imageblit,
51 .fb_mmap = leo_mmap,
52 .fb_ioctl = leo_ioctl,
Christoph Hellwig9ffb83b2005-11-12 12:11:12 -080053#ifdef CONFIG_COMPAT
54 .fb_compat_ioctl = sbusfb_compat_ioctl,
55#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
58#define LEO_OFF_LC_SS0_KRN 0x00200000UL
59#define LEO_OFF_LC_SS0_USR 0x00201000UL
60#define LEO_OFF_LC_SS1_KRN 0x01200000UL
61#define LEO_OFF_LC_SS1_USR 0x01201000UL
62#define LEO_OFF_LD_SS0 0x00400000UL
63#define LEO_OFF_LD_SS1 0x01400000UL
64#define LEO_OFF_LD_GBL 0x00401000UL
65#define LEO_OFF_LX_KRN 0x00600000UL
66#define LEO_OFF_LX_CURSOR 0x00601000UL
67#define LEO_OFF_SS0 0x00800000UL
68#define LEO_OFF_SS1 0x01800000UL
69#define LEO_OFF_UNK 0x00602000UL
70#define LEO_OFF_UNK2 0x00000000UL
71
72#define LEO_CUR_ENABLE 0x00000080
73#define LEO_CUR_UPDATE 0x00000030
74#define LEO_CUR_PROGRESS 0x00000006
75#define LEO_CUR_UPDATECMAP 0x00000003
76
77#define LEO_CUR_TYPE_MASK 0x00000000
78#define LEO_CUR_TYPE_IMAGE 0x00000020
79#define LEO_CUR_TYPE_CMAP 0x00000050
80
81struct leo_cursor {
82 u8 xxx0[16];
83 volatile u32 cur_type;
84 volatile u32 cur_misc;
85 volatile u32 cur_cursxy;
86 volatile u32 cur_data;
87};
88
89#define LEO_KRN_TYPE_CLUT0 0x00001000
90#define LEO_KRN_TYPE_CLUT1 0x00001001
91#define LEO_KRN_TYPE_CLUT2 0x00001002
92#define LEO_KRN_TYPE_WID 0x00001003
93#define LEO_KRN_TYPE_UNK 0x00001006
94#define LEO_KRN_TYPE_VIDEO 0x00002003
95#define LEO_KRN_TYPE_CLUTDATA 0x00004000
96#define LEO_KRN_CSR_ENABLE 0x00000008
97#define LEO_KRN_CSR_PROGRESS 0x00000004
98#define LEO_KRN_CSR_UNK 0x00000002
99#define LEO_KRN_CSR_UNK2 0x00000001
100
101struct leo_lx_krn {
102 volatile u32 krn_type;
103 volatile u32 krn_csr;
104 volatile u32 krn_value;
105};
106
107struct leo_lc_ss0_krn {
108 volatile u32 misc;
109 u8 xxx0[0x800-4];
110 volatile u32 rev;
111};
112
113struct leo_lc_ss0_usr {
114 volatile u32 csr;
115 volatile u32 addrspace;
116 volatile u32 fontmsk;
117 volatile u32 fontt;
118 volatile u32 extent;
119 volatile u32 src;
120 u32 dst;
121 volatile u32 copy;
122 volatile u32 fill;
123};
124
125struct leo_lc_ss1_krn {
126 u8 unknown;
127};
128
129struct leo_lc_ss1_usr {
130 u8 unknown;
131};
132
133struct leo_ld {
134 u8 xxx0[0xe00];
135 volatile u32 csr;
136 volatile u32 wid;
137 volatile u32 wmask;
138 volatile u32 widclip;
139 volatile u32 vclipmin;
140 volatile u32 vclipmax;
141 volatile u32 pickmin; /* SS1 only */
142 volatile u32 pickmax; /* SS1 only */
143 volatile u32 fg;
144 volatile u32 bg;
145 volatile u32 src; /* Copy/Scroll (SS0 only) */
146 volatile u32 dst; /* Copy/Scroll/Fill (SS0 only) */
147 volatile u32 extent; /* Copy/Scroll/Fill size (SS0 only) */
148 u32 xxx1[3];
149 volatile u32 setsem; /* SS1 only */
150 volatile u32 clrsem; /* SS1 only */
151 volatile u32 clrpick; /* SS1 only */
152 volatile u32 clrdat; /* SS1 only */
153 volatile u32 alpha; /* SS1 only */
154 u8 xxx2[0x2c];
155 volatile u32 winbg;
156 volatile u32 planemask;
157 volatile u32 rop;
158 volatile u32 z;
159 volatile u32 dczf; /* SS1 only */
160 volatile u32 dczb; /* SS1 only */
161 volatile u32 dcs; /* SS1 only */
162 volatile u32 dczs; /* SS1 only */
163 volatile u32 pickfb; /* SS1 only */
164 volatile u32 pickbb; /* SS1 only */
165 volatile u32 dcfc; /* SS1 only */
166 volatile u32 forcecol; /* SS1 only */
167 volatile u32 door[8]; /* SS1 only */
168 volatile u32 pick[5]; /* SS1 only */
169};
170
171#define LEO_SS1_MISC_ENABLE 0x00000001
172#define LEO_SS1_MISC_STEREO 0x00000002
173struct leo_ld_ss1 {
174 u8 xxx0[0xef4];
175 volatile u32 ss1_misc;
176};
177
178struct leo_ld_gbl {
179 u8 unknown;
180};
181
182struct leo_par {
183 spinlock_t lock;
184 struct leo_lx_krn __iomem *lx_krn;
185 struct leo_lc_ss0_usr __iomem *lc_ss0_usr;
186 struct leo_ld_ss0 __iomem *ld_ss0;
187 struct leo_ld_ss1 __iomem *ld_ss1;
188 struct leo_cursor __iomem *cursor;
189 u32 extent;
190 u32 clut_data[256];
191
192 u32 flags;
193#define LEO_FLAG_BLANKED 0x00000001
194
195 unsigned long physbase;
196 unsigned long fbsize;
197
198 struct sbus_dev *sdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
201static void leo_wait(struct leo_lx_krn __iomem *lx_krn)
202{
203 int i;
204
205 for (i = 0;
206 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000;
207 i++)
208 udelay (1); /* Busy wait at most 0.3 sec */
209 return;
210}
211
212/**
213 * leo_setcolreg - Optional function. Sets a color register.
214 * @regno: boolean, 0 copy local, 1 get_user() function
215 * @red: frame buffer colormap structure
216 * @green: The green value which can be up to 16 bits wide
217 * @blue: The blue value which can be up to 16 bits wide.
218 * @transp: If supported the alpha value which can be up to 16 bits wide.
219 * @info: frame buffer info structure
220 */
221static int leo_setcolreg(unsigned regno,
222 unsigned red, unsigned green, unsigned blue,
223 unsigned transp, struct fb_info *info)
224{
225 struct leo_par *par = (struct leo_par *) info->par;
226 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
227 unsigned long flags;
228 u32 val;
229 int i;
230
231 if (regno >= 256)
232 return 1;
233
234 red >>= 8;
235 green >>= 8;
236 blue >>= 8;
237
238 par->clut_data[regno] = red | (green << 8) | (blue << 16);
239
240 spin_lock_irqsave(&par->lock, flags);
241
242 leo_wait(lx_krn);
243
244 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
245 for (i = 0; i < 256; i++)
246 sbus_writel(par->clut_data[i], &lx_krn->krn_value);
247 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
248
249 val = sbus_readl(&lx_krn->krn_csr);
250 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
251 sbus_writel(val, &lx_krn->krn_csr);
252
253 spin_unlock_irqrestore(&par->lock, flags);
254
255 return 0;
256}
257
258/**
259 * leo_blank - Optional function. Blanks the display.
260 * @blank_mode: the blank mode we want.
261 * @info: frame buffer structure that represents a single frame buffer
262 */
263static int leo_blank(int blank, struct fb_info *info)
264{
265 struct leo_par *par = (struct leo_par *) info->par;
266 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
267 unsigned long flags;
268 u32 val;
269
270 spin_lock_irqsave(&par->lock, flags);
271
272 switch (blank) {
273 case FB_BLANK_UNBLANK: /* Unblanking */
274 val = sbus_readl(&lx_krn->krn_csr);
275 val |= LEO_KRN_CSR_ENABLE;
276 sbus_writel(val, &lx_krn->krn_csr);
277 par->flags &= ~LEO_FLAG_BLANKED;
278 break;
279
280 case FB_BLANK_NORMAL: /* Normal blanking */
281 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
282 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
283 case FB_BLANK_POWERDOWN: /* Poweroff */
284 val = sbus_readl(&lx_krn->krn_csr);
285 val &= ~LEO_KRN_CSR_ENABLE;
286 sbus_writel(val, &lx_krn->krn_csr);
287 par->flags |= LEO_FLAG_BLANKED;
288 break;
289 }
290
291 spin_unlock_irqrestore(&par->lock, flags);
292
293 return 0;
294}
295
296static struct sbus_mmap_map leo_mmap_map[] = {
297 {
298 .voff = LEO_SS0_MAP,
299 .poff = LEO_OFF_SS0,
300 .size = 0x800000
301 },
302 {
303 .voff = LEO_LC_SS0_USR_MAP,
304 .poff = LEO_OFF_LC_SS0_USR,
305 .size = 0x1000
306 },
307 {
308 .voff = LEO_LD_SS0_MAP,
309 .poff = LEO_OFF_LD_SS0,
310 .size = 0x1000
311 },
312 {
313 .voff = LEO_LX_CURSOR_MAP,
314 .poff = LEO_OFF_LX_CURSOR,
315 .size = 0x1000
316 },
317 {
318 .voff = LEO_SS1_MAP,
319 .poff = LEO_OFF_SS1,
320 .size = 0x800000
321 },
322 {
323 .voff = LEO_LC_SS1_USR_MAP,
324 .poff = LEO_OFF_LC_SS1_USR,
325 .size = 0x1000
326 },
327 {
328 .voff = LEO_LD_SS1_MAP,
329 .poff = LEO_OFF_LD_SS1,
330 .size = 0x1000
331 },
332 {
333 .voff = LEO_UNK_MAP,
334 .poff = LEO_OFF_UNK,
335 .size = 0x1000
336 },
337 {
338 .voff = LEO_LX_KRN_MAP,
339 .poff = LEO_OFF_LX_KRN,
340 .size = 0x1000
341 },
342 {
343 .voff = LEO_LC_SS0_KRN_MAP,
344 .poff = LEO_OFF_LC_SS0_KRN,
345 .size = 0x1000
346 },
347 {
348 .voff = LEO_LC_SS1_KRN_MAP,
349 .poff = LEO_OFF_LC_SS1_KRN,
350 .size = 0x1000
351 },
352 {
353 .voff = LEO_LD_GBL_MAP,
354 .poff = LEO_OFF_LD_GBL,
355 .size = 0x1000
356 },
357 {
358 .voff = LEO_UNK2_MAP,
359 .poff = LEO_OFF_UNK2,
360 .size = 0x100000
361 },
362 { .size = 0 }
363};
364
Christoph Hellwig216d5262006-01-14 13:21:25 -0800365static int leo_mmap(struct fb_info *info, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 struct leo_par *par = (struct leo_par *)info->par;
368
369 return sbusfb_mmap_helper(leo_mmap_map,
370 par->physbase, par->fbsize,
371 par->sdev->reg_addrs[0].which_io,
372 vma);
373}
374
Christoph Hellwig67a66802006-01-14 13:21:25 -0800375static int leo_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 struct leo_par *par = (struct leo_par *) info->par;
378
379 return sbusfb_ioctl_helper(cmd, arg, info,
380 FBTYPE_SUNLEO, 32, par->fbsize);
381}
382
383/*
384 * Initialisation
385 */
386
387static void
388leo_init_fix(struct fb_info *info)
389{
390 struct leo_par *par = (struct leo_par *)info->par;
391
392 strlcpy(info->fix.id, par->sdev->prom_name, sizeof(info->fix.id));
393
394 info->fix.type = FB_TYPE_PACKED_PIXELS;
395 info->fix.visual = FB_VISUAL_TRUECOLOR;
396
397 info->fix.line_length = 8192;
398
399 info->fix.accel = FB_ACCEL_SUN_LEO;
400}
401
402static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
403{
404 struct leo_par *par = (struct leo_par *) info->par;
405 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
406 struct fb_wid_item *wi;
407 unsigned long flags;
408 u32 val;
409 int i, j;
410
411 spin_lock_irqsave(&par->lock, flags);
412
413 leo_wait(lx_krn);
414
415 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
416 switch(wi->wi_type) {
417 case FB_WID_DBL_8:
418 j = (wi->wi_index & 0xf) + 0x40;
419 break;
420
421 case FB_WID_DBL_24:
422 j = wi->wi_index & 0x3f;
423 break;
424
425 default:
426 continue;
427 };
428 sbus_writel(0x5800 + j, &lx_krn->krn_type);
429 sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
430 }
431 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
432
433 val = sbus_readl(&lx_krn->krn_csr);
434 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
435 sbus_writel(val, &lx_krn->krn_csr);
436
437 spin_unlock_irqrestore(&par->lock, flags);
438}
439
440static void leo_init_wids(struct fb_info *info)
441{
442 struct fb_wid_item wi;
443 struct fb_wid_list wl;
444
445 wl.wl_count = 1;
446 wl.wl_list = &wi;
447 wi.wi_type = FB_WID_DBL_8;
448 wi.wi_index = 0;
449 wi.wi_values [0] = 0x2c0;
450 leo_wid_put(info, &wl);
451 wi.wi_index = 1;
452 wi.wi_values [0] = 0x30;
453 leo_wid_put(info, &wl);
454 wi.wi_index = 2;
455 wi.wi_values [0] = 0x20;
456 leo_wid_put(info, &wl);
457 wi.wi_type = FB_WID_DBL_24;
458 wi.wi_index = 1;
459 wi.wi_values [0] = 0x30;
460 leo_wid_put(info, &wl);
461
462}
463
464static void leo_switch_from_graph(struct fb_info *info)
465{
466 struct leo_par *par = (struct leo_par *) info->par;
467 struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0;
468 unsigned long flags;
469 u32 val;
470
471 spin_lock_irqsave(&par->lock, flags);
472
473 par->extent = ((info->var.xres - 1) |
474 ((info->var.yres - 1) << 16));
475
476 sbus_writel(0xffffffff, &ss->wid);
477 sbus_writel(0xffff, &ss->wmask);
478 sbus_writel(0, &ss->vclipmin);
479 sbus_writel(par->extent, &ss->vclipmax);
480 sbus_writel(0, &ss->fg);
481 sbus_writel(0xff000000, &ss->planemask);
482 sbus_writel(0x310850, &ss->rop);
483 sbus_writel(0, &ss->widclip);
484 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
485 &par->lc_ss0_usr->extent);
486 sbus_writel(4, &par->lc_ss0_usr->addrspace);
487 sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
488 sbus_writel(0, &par->lc_ss0_usr->fontt);
489 do {
490 val = sbus_readl(&par->lc_ss0_usr->csr);
491 } while (val & 0x20000000);
492
493 spin_unlock_irqrestore(&par->lock, flags);
494}
495
496static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
497{
498 /* We just use this to catch switches out of
499 * graphics mode.
500 */
501 leo_switch_from_graph(info);
502
503 if (var->xoffset || var->yoffset || var->vmode)
504 return -EINVAL;
505 return 0;
506}
507
508static void leo_init_hw(struct fb_info *info)
509{
510 struct leo_par *par = (struct leo_par *) info->par;
511 u32 val;
512
513 val = sbus_readl(&par->ld_ss1->ss1_misc);
514 val |= LEO_SS1_MISC_ENABLE;
515 sbus_writel(val, &par->ld_ss1->ss1_misc);
516
517 leo_switch_from_graph(info);
518}
519
520static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
521{
522 var->red.offset = 0;
523 var->red.length = 8;
524 var->green.offset = 8;
525 var->green.length = 8;
526 var->blue.offset = 16;
527 var->blue.length = 8;
528 var->transp.offset = 0;
529 var->transp.length = 0;
530}
531
532struct all_info {
533 struct fb_info info;
534 struct leo_par par;
535 struct list_head list;
536};
537static LIST_HEAD(leo_list);
538
539static void leo_init_one(struct sbus_dev *sdev)
540{
541 struct all_info *all;
542 int linebytes;
543
544 all = kmalloc(sizeof(*all), GFP_KERNEL);
545 if (!all) {
546 printk(KERN_ERR "leo: Cannot allocate memory.\n");
547 return;
548 }
549 memset(all, 0, sizeof(*all));
550
551 INIT_LIST_HEAD(&all->list);
552
553 spin_lock_init(&all->par.lock);
554 all->par.sdev = sdev;
555
556 all->par.physbase = sdev->reg_addrs[0].phys_addr;
557
558 sbusfb_fill_var(&all->info.var, sdev->prom_node, 32);
559 leo_fixup_var_rgb(&all->info.var);
560
561 linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
562 all->info.var.xres);
563 all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
564
565#ifdef CONFIG_SPARC32
566 all->info.screen_base = (char __iomem *)
567 prom_getintdefault(sdev->prom_node, "address", 0);
568#endif
569 if (!all->info.screen_base)
570 all->info.screen_base =
571 sbus_ioremap(&sdev->resource[0], LEO_OFF_SS0,
572 0x800000, "leo ram");
573
574 all->par.lc_ss0_usr =
575 sbus_ioremap(&sdev->resource[0], LEO_OFF_LC_SS0_USR,
576 0x1000, "leolc ss0usr");
577 all->par.ld_ss0 =
578 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS0,
579 0x1000, "leold ss0");
580 all->par.ld_ss1 =
581 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS1,
582 0x1000, "leold ss1");
583 all->par.lx_krn =
584 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_KRN,
585 0x1000, "leolx krn");
586 all->par.cursor =
587 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_CURSOR,
588 sizeof(struct leo_cursor), "leolx cursor");
589
590 all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
591 all->info.fbops = &leo_ops;
592 all->info.par = &all->par;
593
594 leo_init_wids(&all->info);
595 leo_init_hw(&all->info);
596
597 leo_blank(0, &all->info);
598
599 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
600 printk(KERN_ERR "leo: Could not allocate color map.\n");
601 kfree(all);
602 return;
603 }
604
605 leo_init_fix(&all->info);
606
607 if (register_framebuffer(&all->info) < 0) {
608 printk(KERN_ERR "leo: Could not register framebuffer.\n");
609 fb_dealloc_cmap(&all->info.cmap);
610 kfree(all);
611 return;
612 }
613
614 list_add(&all->list, &leo_list);
615
616 printk("leo: %s at %lx:%lx\n",
617 sdev->prom_name,
618 (long) sdev->reg_addrs[0].which_io,
619 (long) sdev->reg_addrs[0].phys_addr);
620}
621
622int __init leo_init(void)
623{
624 struct sbus_bus *sbus;
625 struct sbus_dev *sdev;
626
627 if (fb_get_options("leofb", NULL))
628 return -ENODEV;
629
630 for_all_sbusdev(sdev, sbus) {
631 if (!strcmp(sdev->prom_name, "leo"))
632 leo_init_one(sdev);
633 }
634
635 return 0;
636}
637
638void __exit leo_exit(void)
639{
640 struct list_head *pos, *tmp;
641
642 list_for_each_safe(pos, tmp, &leo_list) {
643 struct all_info *all = list_entry(pos, typeof(*all), list);
644
645 unregister_framebuffer(&all->info);
646 fb_dealloc_cmap(&all->info.cmap);
647 kfree(all);
648 }
649}
650
651int __init
652leo_setup(char *arg)
653{
654 /* No cmdline options yet... */
655 return 0;
656}
657
658module_init(leo_init);
659#ifdef MODULE
660module_exit(leo_exit);
661#endif
662
663MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
664MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
665MODULE_LICENSE("GPL");