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/delay.h>
15 #include <linux/init.h>
18 #include <linux/of_device.h>
29 static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
30 unsigned, struct fb_info
*);
31 static int leo_blank(int, struct fb_info
*);
33 static int leo_mmap(struct fb_info
*, struct vm_area_struct
*);
34 static int leo_ioctl(struct fb_info
*, unsigned int, unsigned long);
35 static int leo_pan_display(struct fb_var_screeninfo
*, struct fb_info
*);
38 * Frame buffer operations
41 static struct fb_ops leo_ops
= {
43 .fb_setcolreg
= leo_setcolreg
,
44 .fb_blank
= leo_blank
,
45 .fb_pan_display
= leo_pan_display
,
46 .fb_fillrect
= cfb_fillrect
,
47 .fb_copyarea
= cfb_copyarea
,
48 .fb_imageblit
= cfb_imageblit
,
50 .fb_ioctl
= leo_ioctl
,
52 .fb_compat_ioctl
= sbusfb_compat_ioctl
,
56 #define LEO_OFF_LC_SS0_KRN 0x00200000UL
57 #define LEO_OFF_LC_SS0_USR 0x00201000UL
58 #define LEO_OFF_LC_SS1_KRN 0x01200000UL
59 #define LEO_OFF_LC_SS1_USR 0x01201000UL
60 #define LEO_OFF_LD_SS0 0x00400000UL
61 #define LEO_OFF_LD_SS1 0x01400000UL
62 #define LEO_OFF_LD_GBL 0x00401000UL
63 #define LEO_OFF_LX_KRN 0x00600000UL
64 #define LEO_OFF_LX_CURSOR 0x00601000UL
65 #define LEO_OFF_SS0 0x00800000UL
66 #define LEO_OFF_SS1 0x01800000UL
67 #define LEO_OFF_UNK 0x00602000UL
68 #define LEO_OFF_UNK2 0x00000000UL
70 #define LEO_CUR_ENABLE 0x00000080
71 #define LEO_CUR_UPDATE 0x00000030
72 #define LEO_CUR_PROGRESS 0x00000006
73 #define LEO_CUR_UPDATECMAP 0x00000003
75 #define LEO_CUR_TYPE_MASK 0x00000000
76 #define LEO_CUR_TYPE_IMAGE 0x00000020
77 #define LEO_CUR_TYPE_CMAP 0x00000050
87 #define LEO_KRN_TYPE_CLUT0 0x00001000
88 #define LEO_KRN_TYPE_CLUT1 0x00001001
89 #define LEO_KRN_TYPE_CLUT2 0x00001002
90 #define LEO_KRN_TYPE_WID 0x00001003
91 #define LEO_KRN_TYPE_UNK 0x00001006
92 #define LEO_KRN_TYPE_VIDEO 0x00002003
93 #define LEO_KRN_TYPE_CLUTDATA 0x00004000
94 #define LEO_KRN_CSR_ENABLE 0x00000008
95 #define LEO_KRN_CSR_PROGRESS 0x00000004
96 #define LEO_KRN_CSR_UNK 0x00000002
97 #define LEO_KRN_CSR_UNK2 0x00000001
105 struct leo_lc_ss0_krn
{
111 struct leo_lc_ss0_usr
{
123 struct leo_lc_ss1_krn
{
127 struct leo_lc_ss1_usr
{
139 u32 pickmin
; /* SS1 only */
140 u32 pickmax
; /* SS1 only */
143 u32 src
; /* Copy/Scroll (SS0 only) */
144 u32 dst
; /* Copy/Scroll/Fill (SS0 only) */
145 u32 extent
; /* Copy/Scroll/Fill size (SS0 only) */
147 u32 setsem
; /* SS1 only */
148 u32 clrsem
; /* SS1 only */
149 u32 clrpick
; /* SS1 only */
150 u32 clrdat
; /* SS1 only */
151 u32 alpha
; /* SS1 only */
157 u32 dczf
; /* SS1 only */
158 u32 dczb
; /* SS1 only */
159 u32 dcs
; /* SS1 only */
160 u32 dczs
; /* SS1 only */
161 u32 pickfb
; /* SS1 only */
162 u32 pickbb
; /* SS1 only */
163 u32 dcfc
; /* SS1 only */
164 u32 forcecol
; /* SS1 only */
165 u32 door
[8]; /* SS1 only */
166 u32 pick
[5]; /* SS1 only */
169 #define LEO_SS1_MISC_ENABLE 0x00000001
170 #define LEO_SS1_MISC_STEREO 0x00000002
182 struct leo_lx_krn __iomem
*lx_krn
;
183 struct leo_lc_ss0_usr __iomem
*lc_ss0_usr
;
184 struct leo_ld_ss0 __iomem
*ld_ss0
;
185 struct leo_ld_ss1 __iomem
*ld_ss1
;
186 struct leo_cursor __iomem
*cursor
;
191 #define LEO_FLAG_BLANKED 0x00000001
193 unsigned long which_io
;
196 static void leo_wait(struct leo_lx_krn __iomem
*lx_krn
)
201 (sbus_readl(&lx_krn
->krn_csr
) & LEO_KRN_CSR_PROGRESS
) &&
204 udelay(1); /* Busy wait at most 0.3 sec */
208 static void leo_switch_from_graph(struct fb_info
*info
)
210 struct leo_par
*par
= (struct leo_par
*) info
->par
;
211 struct leo_ld_ss0 __iomem
*ss
= par
->ld_ss0
;
212 struct leo_cursor __iomem
*cursor
= par
->cursor
;
216 spin_lock_irqsave(&par
->lock
, flags
);
218 par
->extent
= ((info
->var
.xres
- 1) |
219 ((info
->var
.yres
- 1) << 16));
221 sbus_writel(0xffffffff, &ss
->wid
);
222 sbus_writel(0xffff, &ss
->wmask
);
223 sbus_writel(0, &ss
->vclipmin
);
224 sbus_writel(par
->extent
, &ss
->vclipmax
);
225 sbus_writel(0, &ss
->fg
);
226 sbus_writel(0xff000000, &ss
->planemask
);
227 sbus_writel(0x310850, &ss
->rop
);
228 sbus_writel(0, &ss
->widclip
);
229 sbus_writel((info
->var
.xres
-1) | ((info
->var
.yres
-1) << 11),
230 &par
->lc_ss0_usr
->extent
);
231 sbus_writel(4, &par
->lc_ss0_usr
->addrspace
);
232 sbus_writel(0x80000000, &par
->lc_ss0_usr
->fill
);
233 sbus_writel(0, &par
->lc_ss0_usr
->fontt
);
235 val
= sbus_readl(&par
->lc_ss0_usr
->csr
);
236 } while (val
& 0x20000000);
238 /* setup screen buffer for cfb_* functions */
239 sbus_writel(1, &ss
->wid
);
240 sbus_writel(0x00ffffff, &ss
->planemask
);
241 sbus_writel(0x310b90, &ss
->rop
);
242 sbus_writel(0, &par
->lc_ss0_usr
->addrspace
);
245 sbus_writel(sbus_readl(&cursor
->cur_misc
) & ~LEO_CUR_ENABLE
, &cursor
->cur_misc
);
247 spin_unlock_irqrestore(&par
->lock
, flags
);
250 static int leo_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
252 /* We just use this to catch switches out of
255 leo_switch_from_graph(info
);
257 if (var
->xoffset
|| var
->yoffset
|| var
->vmode
)
263 * leo_setcolreg - Optional function. Sets a color register.
264 * @regno: boolean, 0 copy local, 1 get_user() function
265 * @red: frame buffer colormap structure
266 * @green: The green value which can be up to 16 bits wide
267 * @blue: The blue value which can be up to 16 bits wide.
268 * @transp: If supported the alpha value which can be up to 16 bits wide.
269 * @info: frame buffer info structure
271 static int leo_setcolreg(unsigned regno
,
272 unsigned red
, unsigned green
, unsigned blue
,
273 unsigned transp
, struct fb_info
*info
)
275 struct leo_par
*par
= (struct leo_par
*) info
->par
;
276 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
288 par
->clut_data
[regno
] = red
| (green
<< 8) | (blue
<< 16);
290 spin_lock_irqsave(&par
->lock
, flags
);
294 sbus_writel(LEO_KRN_TYPE_CLUTDATA
, &lx_krn
->krn_type
);
295 for (i
= 0; i
< 256; i
++)
296 sbus_writel(par
->clut_data
[i
], &lx_krn
->krn_value
);
297 sbus_writel(LEO_KRN_TYPE_CLUT0
, &lx_krn
->krn_type
);
299 val
= sbus_readl(&lx_krn
->krn_csr
);
300 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
301 sbus_writel(val
, &lx_krn
->krn_csr
);
303 spin_unlock_irqrestore(&par
->lock
, flags
);
309 * leo_blank - Optional function. Blanks the display.
310 * @blank_mode: the blank mode we want.
311 * @info: frame buffer structure that represents a single frame buffer
313 static int leo_blank(int blank
, struct fb_info
*info
)
315 struct leo_par
*par
= (struct leo_par
*) info
->par
;
316 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
320 spin_lock_irqsave(&par
->lock
, flags
);
323 case FB_BLANK_UNBLANK
: /* Unblanking */
324 val
= sbus_readl(&lx_krn
->krn_csr
);
325 val
|= LEO_KRN_CSR_ENABLE
;
326 sbus_writel(val
, &lx_krn
->krn_csr
);
327 par
->flags
&= ~LEO_FLAG_BLANKED
;
330 case FB_BLANK_NORMAL
: /* Normal blanking */
331 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
332 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
333 case FB_BLANK_POWERDOWN
: /* Poweroff */
334 val
= sbus_readl(&lx_krn
->krn_csr
);
335 val
&= ~LEO_KRN_CSR_ENABLE
;
336 sbus_writel(val
, &lx_krn
->krn_csr
);
337 par
->flags
|= LEO_FLAG_BLANKED
;
341 spin_unlock_irqrestore(&par
->lock
, flags
);
346 static struct sbus_mmap_map leo_mmap_map
[] = {
353 .voff
= LEO_LC_SS0_USR_MAP
,
354 .poff
= LEO_OFF_LC_SS0_USR
,
358 .voff
= LEO_LD_SS0_MAP
,
359 .poff
= LEO_OFF_LD_SS0
,
363 .voff
= LEO_LX_CURSOR_MAP
,
364 .poff
= LEO_OFF_LX_CURSOR
,
373 .voff
= LEO_LC_SS1_USR_MAP
,
374 .poff
= LEO_OFF_LC_SS1_USR
,
378 .voff
= LEO_LD_SS1_MAP
,
379 .poff
= LEO_OFF_LD_SS1
,
388 .voff
= LEO_LX_KRN_MAP
,
389 .poff
= LEO_OFF_LX_KRN
,
393 .voff
= LEO_LC_SS0_KRN_MAP
,
394 .poff
= LEO_OFF_LC_SS0_KRN
,
398 .voff
= LEO_LC_SS1_KRN_MAP
,
399 .poff
= LEO_OFF_LC_SS1_KRN
,
403 .voff
= LEO_LD_GBL_MAP
,
404 .poff
= LEO_OFF_LD_GBL
,
408 .voff
= LEO_UNK2_MAP
,
409 .poff
= LEO_OFF_UNK2
,
415 static int leo_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
417 struct leo_par
*par
= (struct leo_par
*)info
->par
;
419 return sbusfb_mmap_helper(leo_mmap_map
,
420 info
->fix
.smem_start
, info
->fix
.smem_len
,
424 static int leo_ioctl(struct fb_info
*info
, unsigned int cmd
, unsigned long arg
)
426 return sbusfb_ioctl_helper(cmd
, arg
, info
,
427 FBTYPE_SUNLEO
, 32, info
->fix
.smem_len
);
435 leo_init_fix(struct fb_info
*info
, struct device_node
*dp
)
437 strlcpy(info
->fix
.id
, dp
->name
, sizeof(info
->fix
.id
));
439 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
440 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
442 info
->fix
.line_length
= 8192;
444 info
->fix
.accel
= FB_ACCEL_SUN_LEO
;
447 static void leo_wid_put(struct fb_info
*info
, struct fb_wid_list
*wl
)
449 struct leo_par
*par
= (struct leo_par
*) info
->par
;
450 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
451 struct fb_wid_item
*wi
;
456 spin_lock_irqsave(&par
->lock
, flags
);
460 for (i
= 0, wi
= wl
->wl_list
; i
< wl
->wl_count
; i
++, wi
++) {
461 switch (wi
->wi_type
) {
463 j
= (wi
->wi_index
& 0xf) + 0x40;
467 j
= wi
->wi_index
& 0x3f;
473 sbus_writel(0x5800 + j
, &lx_krn
->krn_type
);
474 sbus_writel(wi
->wi_values
[0], &lx_krn
->krn_value
);
476 sbus_writel(LEO_KRN_TYPE_WID
, &lx_krn
->krn_type
);
478 val
= sbus_readl(&lx_krn
->krn_csr
);
479 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
480 sbus_writel(val
, &lx_krn
->krn_csr
);
482 spin_unlock_irqrestore(&par
->lock
, flags
);
485 static void leo_init_wids(struct fb_info
*info
)
487 struct fb_wid_item wi
;
488 struct fb_wid_list wl
;
492 wi
.wi_type
= FB_WID_DBL_8
;
494 wi
.wi_values
[0] = 0x2c0;
495 leo_wid_put(info
, &wl
);
497 wi
.wi_values
[0] = 0x30;
498 leo_wid_put(info
, &wl
);
500 wi
.wi_values
[0] = 0x20;
501 leo_wid_put(info
, &wl
);
502 wi
.wi_type
= FB_WID_DBL_24
;
504 wi
.wi_values
[0] = 0x30;
505 leo_wid_put(info
, &wl
);
508 static void leo_init_hw(struct fb_info
*info
)
510 struct leo_par
*par
= (struct leo_par
*) info
->par
;
513 val
= sbus_readl(&par
->ld_ss1
->ss1_misc
);
514 val
|= LEO_SS1_MISC_ENABLE
;
515 sbus_writel(val
, &par
->ld_ss1
->ss1_misc
);
517 leo_switch_from_graph(info
);
520 static void leo_fixup_var_rgb(struct fb_var_screeninfo
*var
)
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;
532 static void leo_unmap_regs(struct platform_device
*op
, struct fb_info
*info
,
536 of_iounmap(&op
->resource
[0], par
->lc_ss0_usr
, 0x1000);
538 of_iounmap(&op
->resource
[0], par
->ld_ss0
, 0x1000);
540 of_iounmap(&op
->resource
[0], par
->ld_ss1
, 0x1000);
542 of_iounmap(&op
->resource
[0], par
->lx_krn
, 0x1000);
544 of_iounmap(&op
->resource
[0],
545 par
->cursor
, sizeof(struct leo_cursor
));
546 if (info
->screen_base
)
547 of_iounmap(&op
->resource
[0], info
->screen_base
, 0x800000);
550 static int leo_probe(struct platform_device
*op
)
552 struct device_node
*dp
= op
->dev
.of_node
;
553 struct fb_info
*info
;
557 info
= framebuffer_alloc(sizeof(struct leo_par
), &op
->dev
);
564 spin_lock_init(&par
->lock
);
566 info
->fix
.smem_start
= op
->resource
[0].start
;
567 par
->which_io
= op
->resource
[0].flags
& IORESOURCE_BITS
;
569 sbusfb_fill_var(&info
->var
, dp
, 32);
570 leo_fixup_var_rgb(&info
->var
);
572 linebytes
= of_getintprop_default(dp
, "linebytes",
574 info
->fix
.smem_len
= PAGE_ALIGN(linebytes
* info
->var
.yres
);
577 of_ioremap(&op
->resource
[0], LEO_OFF_LC_SS0_USR
,
578 0x1000, "leolc ss0usr");
580 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS0
,
581 0x1000, "leold ss0");
583 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS1
,
584 0x1000, "leold ss1");
586 of_ioremap(&op
->resource
[0], LEO_OFF_LX_KRN
,
587 0x1000, "leolx krn");
589 of_ioremap(&op
->resource
[0], LEO_OFF_LX_CURSOR
,
590 sizeof(struct leo_cursor
), "leolx cursor");
592 of_ioremap(&op
->resource
[0], LEO_OFF_SS0
,
593 0x800000, "leo ram");
594 if (!par
->lc_ss0_usr
||
602 info
->flags
= FBINFO_DEFAULT
;
603 info
->fbops
= &leo_ops
;
604 info
->pseudo_palette
= par
->clut_data
;
609 leo_blank(FB_BLANK_UNBLANK
, info
);
611 if (fb_alloc_cmap(&info
->cmap
, 256, 0))
614 leo_init_fix(info
, dp
);
616 err
= register_framebuffer(info
);
618 goto out_dealloc_cmap
;
620 dev_set_drvdata(&op
->dev
, info
);
622 printk(KERN_INFO
"%s: leo at %lx:%lx\n",
624 par
->which_io
, info
->fix
.smem_start
);
629 fb_dealloc_cmap(&info
->cmap
);
632 leo_unmap_regs(op
, info
, par
);
633 framebuffer_release(info
);
639 static int leo_remove(struct platform_device
*op
)
641 struct fb_info
*info
= dev_get_drvdata(&op
->dev
);
642 struct leo_par
*par
= info
->par
;
644 unregister_framebuffer(info
);
645 fb_dealloc_cmap(&info
->cmap
);
647 leo_unmap_regs(op
, info
, par
);
649 framebuffer_release(info
);
654 static const struct of_device_id leo_match
[] = {
660 MODULE_DEVICE_TABLE(of
, leo_match
);
662 static struct platform_driver leo_driver
= {
665 .owner
= THIS_MODULE
,
666 .of_match_table
= leo_match
,
669 .remove
= leo_remove
,
672 static int __init
leo_init(void)
674 if (fb_get_options("leofb", NULL
))
677 return platform_driver_register(&leo_driver
);
680 static void __exit
leo_exit(void)
682 platform_driver_unregister(&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");