1 /* leo.c: LEO frame buffer driver
3 * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
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/of_device.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 vm_area_struct
*);
36 static int leo_ioctl(struct fb_info
*, unsigned int, unsigned long);
37 static int leo_pan_display(struct fb_var_screeninfo
*, struct fb_info
*);
40 * Frame buffer operations
43 static struct fb_ops leo_ops
= {
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
,
52 .fb_ioctl
= leo_ioctl
,
54 .fb_compat_ioctl
= sbusfb_compat_ioctl
,
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
72 #define LEO_CUR_ENABLE 0x00000080
73 #define LEO_CUR_UPDATE 0x00000030
74 #define LEO_CUR_PROGRESS 0x00000006
75 #define LEO_CUR_UPDATECMAP 0x00000003
77 #define LEO_CUR_TYPE_MASK 0x00000000
78 #define LEO_CUR_TYPE_IMAGE 0x00000020
79 #define LEO_CUR_TYPE_CMAP 0x00000050
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
107 struct leo_lc_ss0_krn
{
113 struct leo_lc_ss0_usr
{
125 struct leo_lc_ss1_krn
{
129 struct leo_lc_ss1_usr
{
141 u32 pickmin
; /* SS1 only */
142 u32 pickmax
; /* SS1 only */
145 u32 src
; /* Copy/Scroll (SS0 only) */
146 u32 dst
; /* Copy/Scroll/Fill (SS0 only) */
147 u32 extent
; /* Copy/Scroll/Fill size (SS0 only) */
149 u32 setsem
; /* SS1 only */
150 u32 clrsem
; /* SS1 only */
151 u32 clrpick
; /* SS1 only */
152 u32 clrdat
; /* SS1 only */
153 u32 alpha
; /* SS1 only */
159 u32 dczf
; /* SS1 only */
160 u32 dczb
; /* SS1 only */
161 u32 dcs
; /* SS1 only */
162 u32 dczs
; /* SS1 only */
163 u32 pickfb
; /* SS1 only */
164 u32 pickbb
; /* SS1 only */
165 u32 dcfc
; /* SS1 only */
166 u32 forcecol
; /* SS1 only */
167 u32 door
[8]; /* SS1 only */
168 u32 pick
[5]; /* SS1 only */
171 #define LEO_SS1_MISC_ENABLE 0x00000001
172 #define LEO_SS1_MISC_STEREO 0x00000002
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
;
193 #define LEO_FLAG_BLANKED 0x00000001
195 unsigned long physbase
;
196 unsigned long which_io
;
197 unsigned long fbsize
;
200 static void leo_wait(struct leo_lx_krn __iomem
*lx_krn
)
205 (sbus_readl(&lx_krn
->krn_csr
) & LEO_KRN_CSR_PROGRESS
) && i
< 300000;
207 udelay (1); /* Busy wait at most 0.3 sec */
212 * leo_setcolreg - Optional function. Sets a color register.
213 * @regno: boolean, 0 copy local, 1 get_user() function
214 * @red: frame buffer colormap structure
215 * @green: The green value which can be up to 16 bits wide
216 * @blue: The blue value which can be up to 16 bits wide.
217 * @transp: If supported the alpha value which can be up to 16 bits wide.
218 * @info: frame buffer info structure
220 static int leo_setcolreg(unsigned regno
,
221 unsigned red
, unsigned green
, unsigned blue
,
222 unsigned transp
, struct fb_info
*info
)
224 struct leo_par
*par
= (struct leo_par
*) info
->par
;
225 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
237 par
->clut_data
[regno
] = red
| (green
<< 8) | (blue
<< 16);
239 spin_lock_irqsave(&par
->lock
, flags
);
243 sbus_writel(LEO_KRN_TYPE_CLUTDATA
, &lx_krn
->krn_type
);
244 for (i
= 0; i
< 256; i
++)
245 sbus_writel(par
->clut_data
[i
], &lx_krn
->krn_value
);
246 sbus_writel(LEO_KRN_TYPE_CLUT0
, &lx_krn
->krn_type
);
248 val
= sbus_readl(&lx_krn
->krn_csr
);
249 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
250 sbus_writel(val
, &lx_krn
->krn_csr
);
252 spin_unlock_irqrestore(&par
->lock
, flags
);
258 * leo_blank - Optional function. Blanks the display.
259 * @blank_mode: the blank mode we want.
260 * @info: frame buffer structure that represents a single frame buffer
262 static int leo_blank(int blank
, struct fb_info
*info
)
264 struct leo_par
*par
= (struct leo_par
*) info
->par
;
265 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
269 spin_lock_irqsave(&par
->lock
, flags
);
272 case FB_BLANK_UNBLANK
: /* Unblanking */
273 val
= sbus_readl(&lx_krn
->krn_csr
);
274 val
|= LEO_KRN_CSR_ENABLE
;
275 sbus_writel(val
, &lx_krn
->krn_csr
);
276 par
->flags
&= ~LEO_FLAG_BLANKED
;
279 case FB_BLANK_NORMAL
: /* Normal blanking */
280 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
281 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
282 case FB_BLANK_POWERDOWN
: /* Poweroff */
283 val
= sbus_readl(&lx_krn
->krn_csr
);
284 val
&= ~LEO_KRN_CSR_ENABLE
;
285 sbus_writel(val
, &lx_krn
->krn_csr
);
286 par
->flags
|= LEO_FLAG_BLANKED
;
290 spin_unlock_irqrestore(&par
->lock
, flags
);
295 static struct sbus_mmap_map leo_mmap_map
[] = {
302 .voff
= LEO_LC_SS0_USR_MAP
,
303 .poff
= LEO_OFF_LC_SS0_USR
,
307 .voff
= LEO_LD_SS0_MAP
,
308 .poff
= LEO_OFF_LD_SS0
,
312 .voff
= LEO_LX_CURSOR_MAP
,
313 .poff
= LEO_OFF_LX_CURSOR
,
322 .voff
= LEO_LC_SS1_USR_MAP
,
323 .poff
= LEO_OFF_LC_SS1_USR
,
327 .voff
= LEO_LD_SS1_MAP
,
328 .poff
= LEO_OFF_LD_SS1
,
337 .voff
= LEO_LX_KRN_MAP
,
338 .poff
= LEO_OFF_LX_KRN
,
342 .voff
= LEO_LC_SS0_KRN_MAP
,
343 .poff
= LEO_OFF_LC_SS0_KRN
,
347 .voff
= LEO_LC_SS1_KRN_MAP
,
348 .poff
= LEO_OFF_LC_SS1_KRN
,
352 .voff
= LEO_LD_GBL_MAP
,
353 .poff
= LEO_OFF_LD_GBL
,
357 .voff
= LEO_UNK2_MAP
,
358 .poff
= LEO_OFF_UNK2
,
364 static int leo_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
366 struct leo_par
*par
= (struct leo_par
*)info
->par
;
368 return sbusfb_mmap_helper(leo_mmap_map
,
369 par
->physbase
, par
->fbsize
,
373 static int leo_ioctl(struct fb_info
*info
, unsigned int cmd
, unsigned long arg
)
375 struct leo_par
*par
= (struct leo_par
*) info
->par
;
377 return sbusfb_ioctl_helper(cmd
, arg
, info
,
378 FBTYPE_SUNLEO
, 32, par
->fbsize
);
386 leo_init_fix(struct fb_info
*info
, struct device_node
*dp
)
388 strlcpy(info
->fix
.id
, dp
->name
, sizeof(info
->fix
.id
));
390 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
391 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
393 info
->fix
.line_length
= 8192;
395 info
->fix
.accel
= FB_ACCEL_SUN_LEO
;
398 static void leo_wid_put(struct fb_info
*info
, struct fb_wid_list
*wl
)
400 struct leo_par
*par
= (struct leo_par
*) info
->par
;
401 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
402 struct fb_wid_item
*wi
;
407 spin_lock_irqsave(&par
->lock
, flags
);
411 for (i
= 0, wi
= wl
->wl_list
; i
< wl
->wl_count
; i
++, wi
++) {
412 switch(wi
->wi_type
) {
414 j
= (wi
->wi_index
& 0xf) + 0x40;
418 j
= wi
->wi_index
& 0x3f;
424 sbus_writel(0x5800 + j
, &lx_krn
->krn_type
);
425 sbus_writel(wi
->wi_values
[0], &lx_krn
->krn_value
);
427 sbus_writel(LEO_KRN_TYPE_WID
, &lx_krn
->krn_type
);
429 val
= sbus_readl(&lx_krn
->krn_csr
);
430 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
431 sbus_writel(val
, &lx_krn
->krn_csr
);
433 spin_unlock_irqrestore(&par
->lock
, flags
);
436 static void leo_init_wids(struct fb_info
*info
)
438 struct fb_wid_item wi
;
439 struct fb_wid_list wl
;
443 wi
.wi_type
= FB_WID_DBL_8
;
445 wi
.wi_values
[0] = 0x2c0;
446 leo_wid_put(info
, &wl
);
448 wi
.wi_values
[0] = 0x30;
449 leo_wid_put(info
, &wl
);
451 wi
.wi_values
[0] = 0x20;
452 leo_wid_put(info
, &wl
);
453 wi
.wi_type
= FB_WID_DBL_24
;
455 wi
.wi_values
[0] = 0x30;
456 leo_wid_put(info
, &wl
);
460 static void leo_switch_from_graph(struct fb_info
*info
)
462 struct leo_par
*par
= (struct leo_par
*) info
->par
;
463 struct leo_ld __iomem
*ss
= (struct leo_ld __iomem
*) par
->ld_ss0
;
467 spin_lock_irqsave(&par
->lock
, flags
);
469 par
->extent
= ((info
->var
.xres
- 1) |
470 ((info
->var
.yres
- 1) << 16));
472 sbus_writel(0xffffffff, &ss
->wid
);
473 sbus_writel(0xffff, &ss
->wmask
);
474 sbus_writel(0, &ss
->vclipmin
);
475 sbus_writel(par
->extent
, &ss
->vclipmax
);
476 sbus_writel(0, &ss
->fg
);
477 sbus_writel(0xff000000, &ss
->planemask
);
478 sbus_writel(0x310850, &ss
->rop
);
479 sbus_writel(0, &ss
->widclip
);
480 sbus_writel((info
->var
.xres
-1) | ((info
->var
.yres
-1) << 11),
481 &par
->lc_ss0_usr
->extent
);
482 sbus_writel(4, &par
->lc_ss0_usr
->addrspace
);
483 sbus_writel(0x80000000, &par
->lc_ss0_usr
->fill
);
484 sbus_writel(0, &par
->lc_ss0_usr
->fontt
);
486 val
= sbus_readl(&par
->lc_ss0_usr
->csr
);
487 } while (val
& 0x20000000);
489 spin_unlock_irqrestore(&par
->lock
, flags
);
492 static int leo_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
494 /* We just use this to catch switches out of
497 leo_switch_from_graph(info
);
499 if (var
->xoffset
|| var
->yoffset
|| var
->vmode
)
504 static void leo_init_hw(struct fb_info
*info
)
506 struct leo_par
*par
= (struct leo_par
*) info
->par
;
509 val
= sbus_readl(&par
->ld_ss1
->ss1_misc
);
510 val
|= LEO_SS1_MISC_ENABLE
;
511 sbus_writel(val
, &par
->ld_ss1
->ss1_misc
);
513 leo_switch_from_graph(info
);
516 static void leo_fixup_var_rgb(struct fb_var_screeninfo
*var
)
520 var
->green
.offset
= 8;
521 var
->green
.length
= 8;
522 var
->blue
.offset
= 16;
523 var
->blue
.length
= 8;
524 var
->transp
.offset
= 0;
525 var
->transp
.length
= 0;
533 static void leo_unmap_regs(struct all_info
*all
)
535 if (all
->par
.lc_ss0_usr
)
536 of_iounmap(all
->par
.lc_ss0_usr
, 0x1000);
538 of_iounmap(all
->par
.ld_ss0
, 0x1000);
540 of_iounmap(all
->par
.ld_ss1
, 0x1000);
542 of_iounmap(all
->par
.lx_krn
, 0x1000);
544 of_iounmap(all
->par
.cursor
, sizeof(struct leo_cursor
));
545 if (all
->info
.screen_base
)
546 of_iounmap(all
->info
.screen_base
, 0x800000);
549 static int __devinit
leo_init_one(struct of_device
*op
)
551 struct device_node
*dp
= op
->node
;
552 struct all_info
*all
;
555 all
= kzalloc(sizeof(*all
), GFP_KERNEL
);
559 spin_lock_init(&all
->par
.lock
);
561 all
->par
.physbase
= op
->resource
[0].start
;
562 all
->par
.which_io
= op
->resource
[0].flags
& IORESOURCE_BITS
;
564 sbusfb_fill_var(&all
->info
.var
, dp
->node
, 32);
565 leo_fixup_var_rgb(&all
->info
.var
);
567 linebytes
= of_getintprop_default(dp
, "linebytes",
569 all
->par
.fbsize
= PAGE_ALIGN(linebytes
* all
->info
.var
.yres
);
571 all
->par
.lc_ss0_usr
=
572 of_ioremap(&op
->resource
[0], LEO_OFF_LC_SS0_USR
,
573 0x1000, "leolc ss0usr");
575 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS0
,
576 0x1000, "leold ss0");
578 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS1
,
579 0x1000, "leold ss1");
581 of_ioremap(&op
->resource
[0], LEO_OFF_LX_KRN
,
582 0x1000, "leolx krn");
584 of_ioremap(&op
->resource
[0], LEO_OFF_LX_CURSOR
,
585 sizeof(struct leo_cursor
), "leolx cursor");
586 all
->info
.screen_base
=
587 of_ioremap(&op
->resource
[0], LEO_OFF_SS0
,
588 0x800000, "leo ram");
589 if (!all
->par
.lc_ss0_usr
||
594 !all
->info
.screen_base
) {
600 all
->info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
601 all
->info
.fbops
= &leo_ops
;
602 all
->info
.par
= &all
->par
;
604 leo_init_wids(&all
->info
);
605 leo_init_hw(&all
->info
);
607 leo_blank(0, &all
->info
);
609 if (fb_alloc_cmap(&all
->info
.cmap
, 256, 0)) {
615 leo_init_fix(&all
->info
, dp
);
617 err
= register_framebuffer(&all
->info
);
619 fb_dealloc_cmap(&all
->info
.cmap
);
625 dev_set_drvdata(&op
->dev
, all
);
627 printk("%s: leo at %lx:%lx\n",
629 all
->par
.which_io
, all
->par
.physbase
);
634 static int __devinit
leo_probe(struct of_device
*dev
, const struct of_device_id
*match
)
636 struct of_device
*op
= to_of_device(&dev
->dev
);
638 return leo_init_one(op
);
641 static int __devexit
leo_remove(struct of_device
*dev
)
643 struct all_info
*all
= dev_get_drvdata(&dev
->dev
);
645 unregister_framebuffer(&all
->info
);
646 fb_dealloc_cmap(&all
->info
.cmap
);
652 dev_set_drvdata(&dev
->dev
, NULL
);
657 static struct of_device_id leo_match
[] = {
663 MODULE_DEVICE_TABLE(of
, leo_match
);
665 static struct of_platform_driver leo_driver
= {
667 .match_table
= leo_match
,
669 .remove
= __devexit_p(leo_remove
),
672 static int __init
leo_init(void)
674 if (fb_get_options("leofb", NULL
))
677 return of_register_driver(&leo_driver
, &of_bus_type
);
680 static void __exit
leo_exit(void)
682 of_unregister_driver(&leo_driver
);
685 module_init(leo_init
);
686 module_exit(leo_exit
);
688 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
689 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
690 MODULE_VERSION("2.0");
691 MODULE_LICENSE("GPL");