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
,
54 .fb_cursor
= soft_cursor
,
57 #define LEO_OFF_LC_SS0_KRN 0x00200000UL
58 #define LEO_OFF_LC_SS0_USR 0x00201000UL
59 #define LEO_OFF_LC_SS1_KRN 0x01200000UL
60 #define LEO_OFF_LC_SS1_USR 0x01201000UL
61 #define LEO_OFF_LD_SS0 0x00400000UL
62 #define LEO_OFF_LD_SS1 0x01400000UL
63 #define LEO_OFF_LD_GBL 0x00401000UL
64 #define LEO_OFF_LX_KRN 0x00600000UL
65 #define LEO_OFF_LX_CURSOR 0x00601000UL
66 #define LEO_OFF_SS0 0x00800000UL
67 #define LEO_OFF_SS1 0x01800000UL
68 #define LEO_OFF_UNK 0x00602000UL
69 #define LEO_OFF_UNK2 0x00000000UL
71 #define LEO_CUR_ENABLE 0x00000080
72 #define LEO_CUR_UPDATE 0x00000030
73 #define LEO_CUR_PROGRESS 0x00000006
74 #define LEO_CUR_UPDATECMAP 0x00000003
76 #define LEO_CUR_TYPE_MASK 0x00000000
77 #define LEO_CUR_TYPE_IMAGE 0x00000020
78 #define LEO_CUR_TYPE_CMAP 0x00000050
82 volatile u32 cur_type
;
83 volatile u32 cur_misc
;
84 volatile u32 cur_cursxy
;
85 volatile u32 cur_data
;
88 #define LEO_KRN_TYPE_CLUT0 0x00001000
89 #define LEO_KRN_TYPE_CLUT1 0x00001001
90 #define LEO_KRN_TYPE_CLUT2 0x00001002
91 #define LEO_KRN_TYPE_WID 0x00001003
92 #define LEO_KRN_TYPE_UNK 0x00001006
93 #define LEO_KRN_TYPE_VIDEO 0x00002003
94 #define LEO_KRN_TYPE_CLUTDATA 0x00004000
95 #define LEO_KRN_CSR_ENABLE 0x00000008
96 #define LEO_KRN_CSR_PROGRESS 0x00000004
97 #define LEO_KRN_CSR_UNK 0x00000002
98 #define LEO_KRN_CSR_UNK2 0x00000001
101 volatile u32 krn_type
;
102 volatile u32 krn_csr
;
103 volatile u32 krn_value
;
106 struct leo_lc_ss0_krn
{
112 struct leo_lc_ss0_usr
{
114 volatile u32 addrspace
;
115 volatile u32 fontmsk
;
124 struct leo_lc_ss1_krn
{
128 struct leo_lc_ss1_usr
{
137 volatile u32 widclip
;
138 volatile u32 vclipmin
;
139 volatile u32 vclipmax
;
140 volatile u32 pickmin
; /* SS1 only */
141 volatile u32 pickmax
; /* SS1 only */
144 volatile u32 src
; /* Copy/Scroll (SS0 only) */
145 volatile u32 dst
; /* Copy/Scroll/Fill (SS0 only) */
146 volatile u32 extent
; /* Copy/Scroll/Fill size (SS0 only) */
148 volatile u32 setsem
; /* SS1 only */
149 volatile u32 clrsem
; /* SS1 only */
150 volatile u32 clrpick
; /* SS1 only */
151 volatile u32 clrdat
; /* SS1 only */
152 volatile u32 alpha
; /* SS1 only */
155 volatile u32 planemask
;
158 volatile u32 dczf
; /* SS1 only */
159 volatile u32 dczb
; /* SS1 only */
160 volatile u32 dcs
; /* SS1 only */
161 volatile u32 dczs
; /* SS1 only */
162 volatile u32 pickfb
; /* SS1 only */
163 volatile u32 pickbb
; /* SS1 only */
164 volatile u32 dcfc
; /* SS1 only */
165 volatile u32 forcecol
; /* SS1 only */
166 volatile u32 door
[8]; /* SS1 only */
167 volatile u32 pick
[5]; /* SS1 only */
170 #define LEO_SS1_MISC_ENABLE 0x00000001
171 #define LEO_SS1_MISC_STEREO 0x00000002
174 volatile u32 ss1_misc
;
183 struct leo_lx_krn __iomem
*lx_krn
;
184 struct leo_lc_ss0_usr __iomem
*lc_ss0_usr
;
185 struct leo_ld_ss0 __iomem
*ld_ss0
;
186 struct leo_ld_ss1 __iomem
*ld_ss1
;
187 struct leo_cursor __iomem
*cursor
;
192 #define LEO_FLAG_BLANKED 0x00000001
194 unsigned long physbase
;
195 unsigned long fbsize
;
197 struct sbus_dev
*sdev
;
198 struct list_head list
;
201 static void leo_wait(struct leo_lx_krn __iomem
*lx_krn
)
206 (sbus_readl(&lx_krn
->krn_csr
) & LEO_KRN_CSR_PROGRESS
) && i
< 300000;
208 udelay (1); /* Busy wait at most 0.3 sec */
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
221 static int leo_setcolreg(unsigned regno
,
222 unsigned red
, unsigned green
, unsigned blue
,
223 unsigned transp
, struct fb_info
*info
)
225 struct leo_par
*par
= (struct leo_par
*) info
->par
;
226 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
238 par
->clut_data
[regno
] = red
| (green
<< 8) | (blue
<< 16);
240 spin_lock_irqsave(&par
->lock
, flags
);
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
);
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
);
253 spin_unlock_irqrestore(&par
->lock
, flags
);
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
263 static int leo_blank(int blank
, struct fb_info
*info
)
265 struct leo_par
*par
= (struct leo_par
*) info
->par
;
266 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
270 spin_lock_irqsave(&par
->lock
, flags
);
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
;
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
;
291 spin_unlock_irqrestore(&par
->lock
, flags
);
296 static struct sbus_mmap_map leo_mmap_map
[] = {
303 .voff
= LEO_LC_SS0_USR_MAP
,
304 .poff
= LEO_OFF_LC_SS0_USR
,
308 .voff
= LEO_LD_SS0_MAP
,
309 .poff
= LEO_OFF_LD_SS0
,
313 .voff
= LEO_LX_CURSOR_MAP
,
314 .poff
= LEO_OFF_LX_CURSOR
,
323 .voff
= LEO_LC_SS1_USR_MAP
,
324 .poff
= LEO_OFF_LC_SS1_USR
,
328 .voff
= LEO_LD_SS1_MAP
,
329 .poff
= LEO_OFF_LD_SS1
,
338 .voff
= LEO_LX_KRN_MAP
,
339 .poff
= LEO_OFF_LX_KRN
,
343 .voff
= LEO_LC_SS0_KRN_MAP
,
344 .poff
= LEO_OFF_LC_SS0_KRN
,
348 .voff
= LEO_LC_SS1_KRN_MAP
,
349 .poff
= LEO_OFF_LC_SS1_KRN
,
353 .voff
= LEO_LD_GBL_MAP
,
354 .poff
= LEO_OFF_LD_GBL
,
358 .voff
= LEO_UNK2_MAP
,
359 .poff
= LEO_OFF_UNK2
,
365 static int leo_mmap(struct fb_info
*info
, struct file
*file
, struct vm_area_struct
*vma
)
367 struct leo_par
*par
= (struct leo_par
*)info
->par
;
369 return sbusfb_mmap_helper(leo_mmap_map
,
370 par
->physbase
, par
->fbsize
,
371 par
->sdev
->reg_addrs
[0].which_io
,
375 static int leo_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
376 unsigned long arg
, struct fb_info
*info
)
378 struct leo_par
*par
= (struct leo_par
*) info
->par
;
380 return sbusfb_ioctl_helper(cmd
, arg
, info
,
381 FBTYPE_SUNLEO
, 32, par
->fbsize
);
389 leo_init_fix(struct fb_info
*info
)
391 struct leo_par
*par
= (struct leo_par
*)info
->par
;
393 strlcpy(info
->fix
.id
, par
->sdev
->prom_name
, sizeof(info
->fix
.id
));
395 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
396 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
398 info
->fix
.line_length
= 8192;
400 info
->fix
.accel
= FB_ACCEL_SUN_LEO
;
403 static void leo_wid_put(struct fb_info
*info
, struct fb_wid_list
*wl
)
405 struct leo_par
*par
= (struct leo_par
*) info
->par
;
406 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
407 struct fb_wid_item
*wi
;
412 spin_lock_irqsave(&par
->lock
, flags
);
416 for (i
= 0, wi
= wl
->wl_list
; i
< wl
->wl_count
; i
++, wi
++) {
417 switch(wi
->wi_type
) {
419 j
= (wi
->wi_index
& 0xf) + 0x40;
423 j
= wi
->wi_index
& 0x3f;
429 sbus_writel(0x5800 + j
, &lx_krn
->krn_type
);
430 sbus_writel(wi
->wi_values
[0], &lx_krn
->krn_value
);
432 sbus_writel(LEO_KRN_TYPE_WID
, &lx_krn
->krn_type
);
434 val
= sbus_readl(&lx_krn
->krn_csr
);
435 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
436 sbus_writel(val
, &lx_krn
->krn_csr
);
438 spin_unlock_irqrestore(&par
->lock
, flags
);
441 static void leo_init_wids(struct fb_info
*info
)
443 struct fb_wid_item wi
;
444 struct fb_wid_list wl
;
448 wi
.wi_type
= FB_WID_DBL_8
;
450 wi
.wi_values
[0] = 0x2c0;
451 leo_wid_put(info
, &wl
);
453 wi
.wi_values
[0] = 0x30;
454 leo_wid_put(info
, &wl
);
456 wi
.wi_values
[0] = 0x20;
457 leo_wid_put(info
, &wl
);
458 wi
.wi_type
= FB_WID_DBL_24
;
460 wi
.wi_values
[0] = 0x30;
461 leo_wid_put(info
, &wl
);
465 static void leo_switch_from_graph(struct fb_info
*info
)
467 struct leo_par
*par
= (struct leo_par
*) info
->par
;
468 struct leo_ld __iomem
*ss
= (struct leo_ld __iomem
*) par
->ld_ss0
;
472 spin_lock_irqsave(&par
->lock
, flags
);
474 par
->extent
= ((info
->var
.xres
- 1) |
475 ((info
->var
.yres
- 1) << 16));
477 sbus_writel(0xffffffff, &ss
->wid
);
478 sbus_writel(0xffff, &ss
->wmask
);
479 sbus_writel(0, &ss
->vclipmin
);
480 sbus_writel(par
->extent
, &ss
->vclipmax
);
481 sbus_writel(0, &ss
->fg
);
482 sbus_writel(0xff000000, &ss
->planemask
);
483 sbus_writel(0x310850, &ss
->rop
);
484 sbus_writel(0, &ss
->widclip
);
485 sbus_writel((info
->var
.xres
-1) | ((info
->var
.yres
-1) << 11),
486 &par
->lc_ss0_usr
->extent
);
487 sbus_writel(4, &par
->lc_ss0_usr
->addrspace
);
488 sbus_writel(0x80000000, &par
->lc_ss0_usr
->fill
);
489 sbus_writel(0, &par
->lc_ss0_usr
->fontt
);
491 val
= sbus_readl(&par
->lc_ss0_usr
->csr
);
492 } while (val
& 0x20000000);
494 spin_unlock_irqrestore(&par
->lock
, flags
);
497 static int leo_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
499 /* We just use this to catch switches out of
502 leo_switch_from_graph(info
);
504 if (var
->xoffset
|| var
->yoffset
|| var
->vmode
)
509 static void leo_init_hw(struct fb_info
*info
)
511 struct leo_par
*par
= (struct leo_par
*) info
->par
;
514 val
= sbus_readl(&par
->ld_ss1
->ss1_misc
);
515 val
|= LEO_SS1_MISC_ENABLE
;
516 sbus_writel(val
, &par
->ld_ss1
->ss1_misc
);
518 leo_switch_from_graph(info
);
521 static void leo_fixup_var_rgb(struct fb_var_screeninfo
*var
)
525 var
->green
.offset
= 8;
526 var
->green
.length
= 8;
527 var
->blue
.offset
= 16;
528 var
->blue
.length
= 8;
529 var
->transp
.offset
= 0;
530 var
->transp
.length
= 0;
536 struct list_head list
;
538 static LIST_HEAD(leo_list
);
540 static void leo_init_one(struct sbus_dev
*sdev
)
542 struct all_info
*all
;
545 all
= kmalloc(sizeof(*all
), GFP_KERNEL
);
547 printk(KERN_ERR
"leo: Cannot allocate memory.\n");
550 memset(all
, 0, sizeof(*all
));
552 INIT_LIST_HEAD(&all
->list
);
554 spin_lock_init(&all
->par
.lock
);
555 all
->par
.sdev
= sdev
;
557 all
->par
.physbase
= sdev
->reg_addrs
[0].phys_addr
;
559 sbusfb_fill_var(&all
->info
.var
, sdev
->prom_node
, 32);
560 leo_fixup_var_rgb(&all
->info
.var
);
562 linebytes
= prom_getintdefault(sdev
->prom_node
, "linebytes",
564 all
->par
.fbsize
= PAGE_ALIGN(linebytes
* all
->info
.var
.yres
);
566 #ifdef CONFIG_SPARC32
567 all
->info
.screen_base
= (char __iomem
*)
568 prom_getintdefault(sdev
->prom_node
, "address", 0);
570 if (!all
->info
.screen_base
)
571 all
->info
.screen_base
=
572 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_SS0
,
573 0x800000, "leo ram");
575 all
->par
.lc_ss0_usr
=
576 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_LC_SS0_USR
,
577 0x1000, "leolc ss0usr");
579 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_LD_SS0
,
580 0x1000, "leold ss0");
582 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_LD_SS1
,
583 0x1000, "leold ss1");
585 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_LX_KRN
,
586 0x1000, "leolx krn");
588 sbus_ioremap(&sdev
->resource
[0], LEO_OFF_LX_CURSOR
,
589 sizeof(struct leo_cursor
), "leolx cursor");
591 all
->info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
592 all
->info
.fbops
= &leo_ops
;
593 all
->info
.par
= &all
->par
;
595 leo_init_wids(&all
->info
);
596 leo_init_hw(&all
->info
);
598 leo_blank(0, &all
->info
);
600 if (fb_alloc_cmap(&all
->info
.cmap
, 256, 0)) {
601 printk(KERN_ERR
"leo: Could not allocate color map.\n");
606 leo_init_fix(&all
->info
);
608 if (register_framebuffer(&all
->info
) < 0) {
609 printk(KERN_ERR
"leo: Could not register framebuffer.\n");
610 fb_dealloc_cmap(&all
->info
.cmap
);
615 list_add(&all
->list
, &leo_list
);
617 printk("leo: %s at %lx:%lx\n",
619 (long) sdev
->reg_addrs
[0].which_io
,
620 (long) sdev
->reg_addrs
[0].phys_addr
);
623 int __init
leo_init(void)
625 struct sbus_bus
*sbus
;
626 struct sbus_dev
*sdev
;
628 if (fb_get_options("leofb", NULL
))
631 for_all_sbusdev(sdev
, sbus
) {
632 if (!strcmp(sdev
->prom_name
, "leo"))
639 void __exit
leo_exit(void)
641 struct list_head
*pos
, *tmp
;
643 list_for_each_safe(pos
, tmp
, &leo_list
) {
644 struct all_info
*all
= list_entry(pos
, typeof(*all
), list
);
646 unregister_framebuffer(&all
->info
);
647 fb_dealloc_cmap(&all
->info
.cmap
);
655 /* No cmdline options yet... */
659 module_init(leo_init
);
661 module_exit(leo_exit
);
664 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
665 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
666 MODULE_LICENSE("GPL");