1 /* leo.c: LEO frame buffer driver
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)
7 * Driver layout based loosely on tgafb.c, see that file for credits.
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>
22 #include <asm/oplib.h>
31 static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
32 unsigned, struct fb_info *);
33 static int leo_blank(int, struct fb_info *);
35 static int leo_mmap(struct fb_info *, struct file *, struct vm_area_struct *);
36 static int leo_ioctl(struct inode *, struct file *, unsigned int,
37 unsigned long, struct fb_info *);
38 static int leo_pan_display(struct fb_var_screeninfo *, struct fb_info *);
41 * Frame buffer operations
44 static struct fb_ops leo_ops = {
46 .fb_setcolreg = leo_setcolreg,
47 .fb_blank = leo_blank,
48 .fb_pan_display = leo_pan_display,
49 .fb_fillrect = cfb_fillrect,
50 .fb_copyarea = cfb_copyarea,
51 .fb_imageblit = cfb_imageblit,
53 .fb_ioctl = leo_ioctl,
55 .fb_compat_ioctl = sbusfb_compat_ioctl,
59 #define LEO_OFF_LC_SS0_KRN 0x00200000UL
60 #define LEO_OFF_LC_SS0_USR 0x00201000UL
61 #define LEO_OFF_LC_SS1_KRN 0x01200000UL
62 #define LEO_OFF_LC_SS1_USR 0x01201000UL
63 #define LEO_OFF_LD_SS0 0x00400000UL
64 #define LEO_OFF_LD_SS1 0x01400000UL
65 #define LEO_OFF_LD_GBL 0x00401000UL
66 #define LEO_OFF_LX_KRN 0x00600000UL
67 #define LEO_OFF_LX_CURSOR 0x00601000UL
68 #define LEO_OFF_SS0 0x00800000UL
69 #define LEO_OFF_SS1 0x01800000UL
70 #define LEO_OFF_UNK 0x00602000UL
71 #define LEO_OFF_UNK2 0x00000000UL
73 #define LEO_CUR_ENABLE 0x00000080
74 #define LEO_CUR_UPDATE 0x00000030
75 #define LEO_CUR_PROGRESS 0x00000006
76 #define LEO_CUR_UPDATECMAP 0x00000003
78 #define LEO_CUR_TYPE_MASK 0x00000000
79 #define LEO_CUR_TYPE_IMAGE 0x00000020
80 #define LEO_CUR_TYPE_CMAP 0x00000050
84 volatile u32 cur_type;
85 volatile u32 cur_misc;
86 volatile u32 cur_cursxy;
87 volatile u32 cur_data;
90 #define LEO_KRN_TYPE_CLUT0 0x00001000
91 #define LEO_KRN_TYPE_CLUT1 0x00001001
92 #define LEO_KRN_TYPE_CLUT2 0x00001002
93 #define LEO_KRN_TYPE_WID 0x00001003
94 #define LEO_KRN_TYPE_UNK 0x00001006
95 #define LEO_KRN_TYPE_VIDEO 0x00002003
96 #define LEO_KRN_TYPE_CLUTDATA 0x00004000
97 #define LEO_KRN_CSR_ENABLE 0x00000008
98 #define LEO_KRN_CSR_PROGRESS 0x00000004
99 #define LEO_KRN_CSR_UNK 0x00000002
100 #define LEO_KRN_CSR_UNK2 0x00000001
103 volatile u32 krn_type;
104 volatile u32 krn_csr;
105 volatile u32 krn_value;
108 struct leo_lc_ss0_krn {
114 struct leo_lc_ss0_usr {
116 volatile u32 addrspace;
117 volatile u32 fontmsk;
126 struct leo_lc_ss1_krn {
130 struct leo_lc_ss1_usr {
139 volatile u32 widclip;
140 volatile u32 vclipmin;
141 volatile u32 vclipmax;
142 volatile u32 pickmin; /* SS1 only */
143 volatile u32 pickmax; /* SS1 only */
146 volatile u32 src; /* Copy/Scroll (SS0 only) */
147 volatile u32 dst; /* Copy/Scroll/Fill (SS0 only) */
148 volatile u32 extent; /* Copy/Scroll/Fill size (SS0 only) */
150 volatile u32 setsem; /* SS1 only */
151 volatile u32 clrsem; /* SS1 only */
152 volatile u32 clrpick; /* SS1 only */
153 volatile u32 clrdat; /* SS1 only */
154 volatile u32 alpha; /* SS1 only */
157 volatile u32 planemask;
160 volatile u32 dczf; /* SS1 only */
161 volatile u32 dczb; /* SS1 only */
162 volatile u32 dcs; /* SS1 only */
163 volatile u32 dczs; /* SS1 only */
164 volatile u32 pickfb; /* SS1 only */
165 volatile u32 pickbb; /* SS1 only */
166 volatile u32 dcfc; /* SS1 only */
167 volatile u32 forcecol; /* SS1 only */
168 volatile u32 door[8]; /* SS1 only */
169 volatile u32 pick[5]; /* SS1 only */
172 #define LEO_SS1_MISC_ENABLE 0x00000001
173 #define LEO_SS1_MISC_STEREO 0x00000002
176 volatile u32 ss1_misc;
185 struct leo_lx_krn __iomem *lx_krn;
186 struct leo_lc_ss0_usr __iomem *lc_ss0_usr;
187 struct leo_ld_ss0 __iomem *ld_ss0;
188 struct leo_ld_ss1 __iomem *ld_ss1;
189 struct leo_cursor __iomem *cursor;
194 #define LEO_FLAG_BLANKED 0x00000001
196 unsigned long physbase;
197 unsigned long fbsize;
199 struct sbus_dev *sdev;
200 struct list_head list;
203 static void leo_wait(struct leo_lx_krn __iomem *lx_krn)
208 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000;
210 udelay (1); /* Busy wait at most 0.3 sec */
215 * leo_setcolreg - Optional function. Sets a color register.
216 * @regno: boolean, 0 copy local, 1 get_user() function
217 * @red: frame buffer colormap structure
218 * @green: The green value which can be up to 16 bits wide
219 * @blue: The blue value which can be up to 16 bits wide.
220 * @transp: If supported the alpha value which can be up to 16 bits wide.
221 * @info: frame buffer info structure
223 static int leo_setcolreg(unsigned regno,
224 unsigned red, unsigned green, unsigned blue,
225 unsigned transp, struct fb_info *info)
227 struct leo_par *par = (struct leo_par *) info->par;
228 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
240 par->clut_data[regno] = red | (green << 8) | (blue << 16);
242 spin_lock_irqsave(&par->lock, flags);
246 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
247 for (i = 0; i < 256; i++)
248 sbus_writel(par->clut_data[i], &lx_krn->krn_value);
249 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
251 val = sbus_readl(&lx_krn->krn_csr);
252 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
253 sbus_writel(val, &lx_krn->krn_csr);
255 spin_unlock_irqrestore(&par->lock, flags);
261 * leo_blank - Optional function. Blanks the display.
262 * @blank_mode: the blank mode we want.
263 * @info: frame buffer structure that represents a single frame buffer
265 static int leo_blank(int blank, struct fb_info *info)
267 struct leo_par *par = (struct leo_par *) info->par;
268 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
272 spin_lock_irqsave(&par->lock, flags);
275 case FB_BLANK_UNBLANK: /* Unblanking */
276 val = sbus_readl(&lx_krn->krn_csr);
277 val |= LEO_KRN_CSR_ENABLE;
278 sbus_writel(val, &lx_krn->krn_csr);
279 par->flags &= ~LEO_FLAG_BLANKED;
282 case FB_BLANK_NORMAL: /* Normal blanking */
283 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
284 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
285 case FB_BLANK_POWERDOWN: /* Poweroff */
286 val = sbus_readl(&lx_krn->krn_csr);
287 val &= ~LEO_KRN_CSR_ENABLE;
288 sbus_writel(val, &lx_krn->krn_csr);
289 par->flags |= LEO_FLAG_BLANKED;
293 spin_unlock_irqrestore(&par->lock, flags);
298 static struct sbus_mmap_map leo_mmap_map[] = {
305 .voff = LEO_LC_SS0_USR_MAP,
306 .poff = LEO_OFF_LC_SS0_USR,
310 .voff = LEO_LD_SS0_MAP,
311 .poff = LEO_OFF_LD_SS0,
315 .voff = LEO_LX_CURSOR_MAP,
316 .poff = LEO_OFF_LX_CURSOR,
325 .voff = LEO_LC_SS1_USR_MAP,
326 .poff = LEO_OFF_LC_SS1_USR,
330 .voff = LEO_LD_SS1_MAP,
331 .poff = LEO_OFF_LD_SS1,
340 .voff = LEO_LX_KRN_MAP,
341 .poff = LEO_OFF_LX_KRN,
345 .voff = LEO_LC_SS0_KRN_MAP,
346 .poff = LEO_OFF_LC_SS0_KRN,
350 .voff = LEO_LC_SS1_KRN_MAP,
351 .poff = LEO_OFF_LC_SS1_KRN,
355 .voff = LEO_LD_GBL_MAP,
356 .poff = LEO_OFF_LD_GBL,
360 .voff = LEO_UNK2_MAP,
361 .poff = LEO_OFF_UNK2,
367 static int leo_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
369 struct leo_par *par = (struct leo_par *)info->par;
371 return sbusfb_mmap_helper(leo_mmap_map,
372 par->physbase, par->fbsize,
373 par->sdev->reg_addrs[0].which_io,
377 static int leo_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
378 unsigned long arg, struct fb_info *info)
380 struct leo_par *par = (struct leo_par *) info->par;
382 return sbusfb_ioctl_helper(cmd, arg, info,
383 FBTYPE_SUNLEO, 32, par->fbsize);
391 leo_init_fix(struct fb_info *info)
393 struct leo_par *par = (struct leo_par *)info->par;
395 strlcpy(info->fix.id, par->sdev->prom_name, sizeof(info->fix.id));
397 info->fix.type = FB_TYPE_PACKED_PIXELS;
398 info->fix.visual = FB_VISUAL_TRUECOLOR;
400 info->fix.line_length = 8192;
402 info->fix.accel = FB_ACCEL_SUN_LEO;
405 static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
407 struct leo_par *par = (struct leo_par *) info->par;
408 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
409 struct fb_wid_item *wi;
414 spin_lock_irqsave(&par->lock, flags);
418 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
419 switch(wi->wi_type) {
421 j = (wi->wi_index & 0xf) + 0x40;
425 j = wi->wi_index & 0x3f;
431 sbus_writel(0x5800 + j, &lx_krn->krn_type);
432 sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
434 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
436 val = sbus_readl(&lx_krn->krn_csr);
437 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
438 sbus_writel(val, &lx_krn->krn_csr);
440 spin_unlock_irqrestore(&par->lock, flags);
443 static void leo_init_wids(struct fb_info *info)
445 struct fb_wid_item wi;
446 struct fb_wid_list wl;
450 wi.wi_type = FB_WID_DBL_8;
452 wi.wi_values [0] = 0x2c0;
453 leo_wid_put(info, &wl);
455 wi.wi_values [0] = 0x30;
456 leo_wid_put(info, &wl);
458 wi.wi_values [0] = 0x20;
459 leo_wid_put(info, &wl);
460 wi.wi_type = FB_WID_DBL_24;
462 wi.wi_values [0] = 0x30;
463 leo_wid_put(info, &wl);
467 static void leo_switch_from_graph(struct fb_info *info)
469 struct leo_par *par = (struct leo_par *) info->par;
470 struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0;
474 spin_lock_irqsave(&par->lock, flags);
476 par->extent = ((info->var.xres - 1) |
477 ((info->var.yres - 1) << 16));
479 sbus_writel(0xffffffff, &ss->wid);
480 sbus_writel(0xffff, &ss->wmask);
481 sbus_writel(0, &ss->vclipmin);
482 sbus_writel(par->extent, &ss->vclipmax);
483 sbus_writel(0, &ss->fg);
484 sbus_writel(0xff000000, &ss->planemask);
485 sbus_writel(0x310850, &ss->rop);
486 sbus_writel(0, &ss->widclip);
487 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
488 &par->lc_ss0_usr->extent);
489 sbus_writel(4, &par->lc_ss0_usr->addrspace);
490 sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
491 sbus_writel(0, &par->lc_ss0_usr->fontt);
493 val = sbus_readl(&par->lc_ss0_usr->csr);
494 } while (val & 0x20000000);
496 spin_unlock_irqrestore(&par->lock, flags);
499 static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
501 /* We just use this to catch switches out of
504 leo_switch_from_graph(info);
506 if (var->xoffset || var->yoffset || var->vmode)
511 static void leo_init_hw(struct fb_info *info)
513 struct leo_par *par = (struct leo_par *) info->par;
516 val = sbus_readl(&par->ld_ss1->ss1_misc);
517 val |= LEO_SS1_MISC_ENABLE;
518 sbus_writel(val, &par->ld_ss1->ss1_misc);
520 leo_switch_from_graph(info);
523 static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
527 var->green.offset = 8;
528 var->green.length = 8;
529 var->blue.offset = 16;
530 var->blue.length = 8;
531 var->transp.offset = 0;
532 var->transp.length = 0;
538 struct list_head list;
540 static LIST_HEAD(leo_list);
542 static void leo_init_one(struct sbus_dev *sdev)
544 struct all_info *all;
547 all = kmalloc(sizeof(*all), GFP_KERNEL);
549 printk(KERN_ERR "leo: Cannot allocate memory.\n");
552 memset(all, 0, sizeof(*all));
554 INIT_LIST_HEAD(&all->list);
556 spin_lock_init(&all->par.lock);
557 all->par.sdev = sdev;
559 all->par.physbase = sdev->reg_addrs[0].phys_addr;
561 sbusfb_fill_var(&all->info.var, sdev->prom_node, 32);
562 leo_fixup_var_rgb(&all->info.var);
564 linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
566 all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
568 #ifdef CONFIG_SPARC32
569 all->info.screen_base = (char __iomem *)
570 prom_getintdefault(sdev->prom_node, "address", 0);
572 if (!all->info.screen_base)
573 all->info.screen_base =
574 sbus_ioremap(&sdev->resource[0], LEO_OFF_SS0,
575 0x800000, "leo ram");
577 all->par.lc_ss0_usr =
578 sbus_ioremap(&sdev->resource[0], LEO_OFF_LC_SS0_USR,
579 0x1000, "leolc ss0usr");
581 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS0,
582 0x1000, "leold ss0");
584 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS1,
585 0x1000, "leold ss1");
587 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_KRN,
588 0x1000, "leolx krn");
590 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_CURSOR,
591 sizeof(struct leo_cursor), "leolx cursor");
593 all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
594 all->info.fbops = &leo_ops;
595 all->info.par = &all->par;
597 leo_init_wids(&all->info);
598 leo_init_hw(&all->info);
600 leo_blank(0, &all->info);
602 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
603 printk(KERN_ERR "leo: Could not allocate color map.\n");
608 leo_init_fix(&all->info);
610 if (register_framebuffer(&all->info) < 0) {
611 printk(KERN_ERR "leo: Could not register framebuffer.\n");
612 fb_dealloc_cmap(&all->info.cmap);
617 list_add(&all->list, &leo_list);
619 printk("leo: %s at %lx:%lx\n",
621 (long) sdev->reg_addrs[0].which_io,
622 (long) sdev->reg_addrs[0].phys_addr);
625 int __init leo_init(void)
627 struct sbus_bus *sbus;
628 struct sbus_dev *sdev;
630 if (fb_get_options("leofb", NULL))
633 for_all_sbusdev(sdev, sbus) {
634 if (!strcmp(sdev->prom_name, "leo"))
641 void __exit leo_exit(void)
643 struct list_head *pos, *tmp;
645 list_for_each_safe(pos, tmp, &leo_list) {
646 struct all_info *all = list_entry(pos, typeof(*all), list);
648 unregister_framebuffer(&all->info);
649 fb_dealloc_cmap(&all->info.cmap);
657 /* No cmdline options yet... */
661 module_init(leo_init);
663 module_exit(leo_exit);
666 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
667 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
668 MODULE_LICENSE("GPL");