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;
202 static void leo_wait(struct leo_lx_krn __iomem *lx_krn)
207 (sbus_readl(&lx_krn->krn_csr) & LEO_KRN_CSR_PROGRESS) && i < 300000;
209 udelay (1); /* Busy wait at most 0.3 sec */
214 * leo_setcolreg - Optional function. Sets a color register.
215 * @regno: boolean, 0 copy local, 1 get_user() function
216 * @red: frame buffer colormap structure
217 * @green: The green value which can be up to 16 bits wide
218 * @blue: The blue value which can be up to 16 bits wide.
219 * @transp: If supported the alpha value which can be up to 16 bits wide.
220 * @info: frame buffer info structure
222 static int leo_setcolreg(unsigned regno,
223 unsigned red, unsigned green, unsigned blue,
224 unsigned transp, struct fb_info *info)
226 struct leo_par *par = (struct leo_par *) info->par;
227 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
239 par->clut_data[regno] = red | (green << 8) | (blue << 16);
241 spin_lock_irqsave(&par->lock, flags);
245 sbus_writel(LEO_KRN_TYPE_CLUTDATA, &lx_krn->krn_type);
246 for (i = 0; i < 256; i++)
247 sbus_writel(par->clut_data[i], &lx_krn->krn_value);
248 sbus_writel(LEO_KRN_TYPE_CLUT0, &lx_krn->krn_type);
250 val = sbus_readl(&lx_krn->krn_csr);
251 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
252 sbus_writel(val, &lx_krn->krn_csr);
254 spin_unlock_irqrestore(&par->lock, flags);
260 * leo_blank - Optional function. Blanks the display.
261 * @blank_mode: the blank mode we want.
262 * @info: frame buffer structure that represents a single frame buffer
264 static int leo_blank(int blank, struct fb_info *info)
266 struct leo_par *par = (struct leo_par *) info->par;
267 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
271 spin_lock_irqsave(&par->lock, flags);
274 case FB_BLANK_UNBLANK: /* Unblanking */
275 val = sbus_readl(&lx_krn->krn_csr);
276 val |= LEO_KRN_CSR_ENABLE;
277 sbus_writel(val, &lx_krn->krn_csr);
278 par->flags &= ~LEO_FLAG_BLANKED;
281 case FB_BLANK_NORMAL: /* Normal blanking */
282 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
283 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
284 case FB_BLANK_POWERDOWN: /* Poweroff */
285 val = sbus_readl(&lx_krn->krn_csr);
286 val &= ~LEO_KRN_CSR_ENABLE;
287 sbus_writel(val, &lx_krn->krn_csr);
288 par->flags |= LEO_FLAG_BLANKED;
292 spin_unlock_irqrestore(&par->lock, flags);
297 static struct sbus_mmap_map leo_mmap_map[] = {
304 .voff = LEO_LC_SS0_USR_MAP,
305 .poff = LEO_OFF_LC_SS0_USR,
309 .voff = LEO_LD_SS0_MAP,
310 .poff = LEO_OFF_LD_SS0,
314 .voff = LEO_LX_CURSOR_MAP,
315 .poff = LEO_OFF_LX_CURSOR,
324 .voff = LEO_LC_SS1_USR_MAP,
325 .poff = LEO_OFF_LC_SS1_USR,
329 .voff = LEO_LD_SS1_MAP,
330 .poff = LEO_OFF_LD_SS1,
339 .voff = LEO_LX_KRN_MAP,
340 .poff = LEO_OFF_LX_KRN,
344 .voff = LEO_LC_SS0_KRN_MAP,
345 .poff = LEO_OFF_LC_SS0_KRN,
349 .voff = LEO_LC_SS1_KRN_MAP,
350 .poff = LEO_OFF_LC_SS1_KRN,
354 .voff = LEO_LD_GBL_MAP,
355 .poff = LEO_OFF_LD_GBL,
359 .voff = LEO_UNK2_MAP,
360 .poff = LEO_OFF_UNK2,
366 static int leo_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma)
368 struct leo_par *par = (struct leo_par *)info->par;
370 return sbusfb_mmap_helper(leo_mmap_map,
371 par->physbase, par->fbsize,
372 par->sdev->reg_addrs[0].which_io,
376 static int leo_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
377 unsigned long arg, struct fb_info *info)
379 struct leo_par *par = (struct leo_par *) info->par;
381 return sbusfb_ioctl_helper(cmd, arg, info,
382 FBTYPE_SUNLEO, 32, par->fbsize);
390 leo_init_fix(struct fb_info *info)
392 struct leo_par *par = (struct leo_par *)info->par;
394 strlcpy(info->fix.id, par->sdev->prom_name, sizeof(info->fix.id));
396 info->fix.type = FB_TYPE_PACKED_PIXELS;
397 info->fix.visual = FB_VISUAL_TRUECOLOR;
399 info->fix.line_length = 8192;
401 info->fix.accel = FB_ACCEL_SUN_LEO;
404 static void leo_wid_put(struct fb_info *info, struct fb_wid_list *wl)
406 struct leo_par *par = (struct leo_par *) info->par;
407 struct leo_lx_krn __iomem *lx_krn = par->lx_krn;
408 struct fb_wid_item *wi;
413 spin_lock_irqsave(&par->lock, flags);
417 for (i = 0, wi = wl->wl_list; i < wl->wl_count; i++, wi++) {
418 switch(wi->wi_type) {
420 j = (wi->wi_index & 0xf) + 0x40;
424 j = wi->wi_index & 0x3f;
430 sbus_writel(0x5800 + j, &lx_krn->krn_type);
431 sbus_writel(wi->wi_values[0], &lx_krn->krn_value);
433 sbus_writel(LEO_KRN_TYPE_WID, &lx_krn->krn_type);
435 val = sbus_readl(&lx_krn->krn_csr);
436 val |= (LEO_KRN_CSR_UNK | LEO_KRN_CSR_UNK2);
437 sbus_writel(val, &lx_krn->krn_csr);
439 spin_unlock_irqrestore(&par->lock, flags);
442 static void leo_init_wids(struct fb_info *info)
444 struct fb_wid_item wi;
445 struct fb_wid_list wl;
449 wi.wi_type = FB_WID_DBL_8;
451 wi.wi_values [0] = 0x2c0;
452 leo_wid_put(info, &wl);
454 wi.wi_values [0] = 0x30;
455 leo_wid_put(info, &wl);
457 wi.wi_values [0] = 0x20;
458 leo_wid_put(info, &wl);
459 wi.wi_type = FB_WID_DBL_24;
461 wi.wi_values [0] = 0x30;
462 leo_wid_put(info, &wl);
466 static void leo_switch_from_graph(struct fb_info *info)
468 struct leo_par *par = (struct leo_par *) info->par;
469 struct leo_ld __iomem *ss = (struct leo_ld __iomem *) par->ld_ss0;
473 spin_lock_irqsave(&par->lock, flags);
475 par->extent = ((info->var.xres - 1) |
476 ((info->var.yres - 1) << 16));
478 sbus_writel(0xffffffff, &ss->wid);
479 sbus_writel(0xffff, &ss->wmask);
480 sbus_writel(0, &ss->vclipmin);
481 sbus_writel(par->extent, &ss->vclipmax);
482 sbus_writel(0, &ss->fg);
483 sbus_writel(0xff000000, &ss->planemask);
484 sbus_writel(0x310850, &ss->rop);
485 sbus_writel(0, &ss->widclip);
486 sbus_writel((info->var.xres-1) | ((info->var.yres-1) << 11),
487 &par->lc_ss0_usr->extent);
488 sbus_writel(4, &par->lc_ss0_usr->addrspace);
489 sbus_writel(0x80000000, &par->lc_ss0_usr->fill);
490 sbus_writel(0, &par->lc_ss0_usr->fontt);
492 val = sbus_readl(&par->lc_ss0_usr->csr);
493 } while (val & 0x20000000);
495 spin_unlock_irqrestore(&par->lock, flags);
498 static int leo_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
500 /* We just use this to catch switches out of
503 leo_switch_from_graph(info);
505 if (var->xoffset || var->yoffset || var->vmode)
510 static void leo_init_hw(struct fb_info *info)
512 struct leo_par *par = (struct leo_par *) info->par;
515 val = sbus_readl(&par->ld_ss1->ss1_misc);
516 val |= LEO_SS1_MISC_ENABLE;
517 sbus_writel(val, &par->ld_ss1->ss1_misc);
519 leo_switch_from_graph(info);
522 static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
526 var->green.offset = 8;
527 var->green.length = 8;
528 var->blue.offset = 16;
529 var->blue.length = 8;
530 var->transp.offset = 0;
531 var->transp.length = 0;
537 struct list_head list;
539 static LIST_HEAD(leo_list);
541 static void leo_init_one(struct sbus_dev *sdev)
543 struct all_info *all;
546 all = kmalloc(sizeof(*all), GFP_KERNEL);
548 printk(KERN_ERR "leo: Cannot allocate memory.\n");
551 memset(all, 0, sizeof(*all));
553 INIT_LIST_HEAD(&all->list);
555 spin_lock_init(&all->par.lock);
556 all->par.sdev = sdev;
558 all->par.physbase = sdev->reg_addrs[0].phys_addr;
560 sbusfb_fill_var(&all->info.var, sdev->prom_node, 32);
561 leo_fixup_var_rgb(&all->info.var);
563 linebytes = prom_getintdefault(sdev->prom_node, "linebytes",
565 all->par.fbsize = PAGE_ALIGN(linebytes * all->info.var.yres);
567 #ifdef CONFIG_SPARC32
568 all->info.screen_base = (char __iomem *)
569 prom_getintdefault(sdev->prom_node, "address", 0);
571 if (!all->info.screen_base)
572 all->info.screen_base =
573 sbus_ioremap(&sdev->resource[0], LEO_OFF_SS0,
574 0x800000, "leo ram");
576 all->par.lc_ss0_usr =
577 sbus_ioremap(&sdev->resource[0], LEO_OFF_LC_SS0_USR,
578 0x1000, "leolc ss0usr");
580 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS0,
581 0x1000, "leold ss0");
583 sbus_ioremap(&sdev->resource[0], LEO_OFF_LD_SS1,
584 0x1000, "leold ss1");
586 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_KRN,
587 0x1000, "leolx krn");
589 sbus_ioremap(&sdev->resource[0], LEO_OFF_LX_CURSOR,
590 sizeof(struct leo_cursor), "leolx cursor");
592 all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
593 all->info.fbops = &leo_ops;
594 all->info.par = &all->par;
596 leo_init_wids(&all->info);
597 leo_init_hw(&all->info);
599 leo_blank(0, &all->info);
601 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
602 printk(KERN_ERR "leo: Could not allocate color map.\n");
607 leo_init_fix(&all->info);
609 if (register_framebuffer(&all->info) < 0) {
610 printk(KERN_ERR "leo: Could not register framebuffer.\n");
611 fb_dealloc_cmap(&all->info.cmap);
616 list_add(&all->list, &leo_list);
618 printk("leo: %s at %lx:%lx\n",
620 (long) sdev->reg_addrs[0].which_io,
621 (long) sdev->reg_addrs[0].phys_addr);
624 int __init leo_init(void)
626 struct sbus_bus *sbus;
627 struct sbus_dev *sdev;
629 if (fb_get_options("leofb", NULL))
632 for_all_sbusdev(sdev, sbus) {
633 if (!strcmp(sdev->prom_name, "leo"))
640 void __exit leo_exit(void)
642 struct list_head *pos, *tmp;
644 list_for_each_safe(pos, tmp, &leo_list) {
645 struct all_info *all = list_entry(pos, typeof(*all), list);
647 unregister_framebuffer(&all->info);
648 fb_dealloc_cmap(&all->info.cmap);
656 /* No cmdline options yet... */
660 module_init(leo_init);
662 module_exit(leo_exit);
665 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
666 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
667 MODULE_LICENSE("GPL");