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>
19 #include <linux/of_device.h>
30 static int leo_setcolreg(unsigned, unsigned, unsigned, unsigned,
31 unsigned, struct fb_info
*);
32 static int leo_blank(int, struct fb_info
*);
34 static int leo_mmap(struct fb_info
*, struct vm_area_struct
*);
35 static int leo_ioctl(struct fb_info
*, unsigned int, unsigned long);
36 static int leo_pan_display(struct fb_var_screeninfo
*, struct fb_info
*);
39 * Frame buffer operations
42 static struct fb_ops leo_ops
= {
44 .fb_setcolreg
= leo_setcolreg
,
45 .fb_blank
= leo_blank
,
46 .fb_pan_display
= leo_pan_display
,
47 .fb_fillrect
= cfb_fillrect
,
48 .fb_copyarea
= cfb_copyarea
,
49 .fb_imageblit
= cfb_imageblit
,
51 .fb_ioctl
= leo_ioctl
,
53 .fb_compat_ioctl
= sbusfb_compat_ioctl
,
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
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
106 struct leo_lc_ss0_krn
{
112 struct leo_lc_ss0_usr
{
124 struct leo_lc_ss1_krn
{
128 struct leo_lc_ss1_usr
{
140 u32 pickmin
; /* SS1 only */
141 u32 pickmax
; /* SS1 only */
144 u32 src
; /* Copy/Scroll (SS0 only) */
145 u32 dst
; /* Copy/Scroll/Fill (SS0 only) */
146 u32 extent
; /* Copy/Scroll/Fill size (SS0 only) */
148 u32 setsem
; /* SS1 only */
149 u32 clrsem
; /* SS1 only */
150 u32 clrpick
; /* SS1 only */
151 u32 clrdat
; /* SS1 only */
152 u32 alpha
; /* SS1 only */
158 u32 dczf
; /* SS1 only */
159 u32 dczb
; /* SS1 only */
160 u32 dcs
; /* SS1 only */
161 u32 dczs
; /* SS1 only */
162 u32 pickfb
; /* SS1 only */
163 u32 pickbb
; /* SS1 only */
164 u32 dcfc
; /* SS1 only */
165 u32 forcecol
; /* SS1 only */
166 u32 door
[8]; /* SS1 only */
167 u32 pick
[5]; /* SS1 only */
170 #define LEO_SS1_MISC_ENABLE 0x00000001
171 #define LEO_SS1_MISC_STEREO 0x00000002
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 which_io
;
196 unsigned long fbsize
;
199 static void leo_wait(struct leo_lx_krn __iomem
*lx_krn
)
204 (sbus_readl(&lx_krn
->krn_csr
) & LEO_KRN_CSR_PROGRESS
) &&
207 udelay(1); /* Busy wait at most 0.3 sec */
211 static void leo_switch_from_graph(struct fb_info
*info
)
213 struct leo_par
*par
= (struct leo_par
*) info
->par
;
214 struct leo_ld_ss0 __iomem
*ss
= par
->ld_ss0
;
215 struct leo_cursor __iomem
*cursor
= par
->cursor
;
219 spin_lock_irqsave(&par
->lock
, flags
);
221 par
->extent
= ((info
->var
.xres
- 1) |
222 ((info
->var
.yres
- 1) << 16));
224 sbus_writel(0xffffffff, &ss
->wid
);
225 sbus_writel(0xffff, &ss
->wmask
);
226 sbus_writel(0, &ss
->vclipmin
);
227 sbus_writel(par
->extent
, &ss
->vclipmax
);
228 sbus_writel(0, &ss
->fg
);
229 sbus_writel(0xff000000, &ss
->planemask
);
230 sbus_writel(0x310850, &ss
->rop
);
231 sbus_writel(0, &ss
->widclip
);
232 sbus_writel((info
->var
.xres
-1) | ((info
->var
.yres
-1) << 11),
233 &par
->lc_ss0_usr
->extent
);
234 sbus_writel(4, &par
->lc_ss0_usr
->addrspace
);
235 sbus_writel(0x80000000, &par
->lc_ss0_usr
->fill
);
236 sbus_writel(0, &par
->lc_ss0_usr
->fontt
);
238 val
= sbus_readl(&par
->lc_ss0_usr
->csr
);
239 } while (val
& 0x20000000);
241 /* setup screen buffer for cfb_* functions */
242 sbus_writel(1, &ss
->wid
);
243 sbus_writel(0x00ffffff, &ss
->planemask
);
244 sbus_writel(0x310b90, &ss
->rop
);
245 sbus_writel(0, &par
->lc_ss0_usr
->addrspace
);
248 sbus_writel(sbus_readl(&cursor
->cur_misc
) & ~LEO_CUR_ENABLE
, &cursor
->cur_misc
);
250 spin_unlock_irqrestore(&par
->lock
, flags
);
253 static int leo_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
255 /* We just use this to catch switches out of
258 leo_switch_from_graph(info
);
260 if (var
->xoffset
|| var
->yoffset
|| var
->vmode
)
266 * leo_setcolreg - Optional function. Sets a color register.
267 * @regno: boolean, 0 copy local, 1 get_user() function
268 * @red: frame buffer colormap structure
269 * @green: The green value which can be up to 16 bits wide
270 * @blue: The blue value which can be up to 16 bits wide.
271 * @transp: If supported the alpha value which can be up to 16 bits wide.
272 * @info: frame buffer info structure
274 static int leo_setcolreg(unsigned regno
,
275 unsigned red
, unsigned green
, unsigned blue
,
276 unsigned transp
, struct fb_info
*info
)
278 struct leo_par
*par
= (struct leo_par
*) info
->par
;
279 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
291 par
->clut_data
[regno
] = red
| (green
<< 8) | (blue
<< 16);
293 spin_lock_irqsave(&par
->lock
, flags
);
297 sbus_writel(LEO_KRN_TYPE_CLUTDATA
, &lx_krn
->krn_type
);
298 for (i
= 0; i
< 256; i
++)
299 sbus_writel(par
->clut_data
[i
], &lx_krn
->krn_value
);
300 sbus_writel(LEO_KRN_TYPE_CLUT0
, &lx_krn
->krn_type
);
302 val
= sbus_readl(&lx_krn
->krn_csr
);
303 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
304 sbus_writel(val
, &lx_krn
->krn_csr
);
306 spin_unlock_irqrestore(&par
->lock
, flags
);
312 * leo_blank - Optional function. Blanks the display.
313 * @blank_mode: the blank mode we want.
314 * @info: frame buffer structure that represents a single frame buffer
316 static int leo_blank(int blank
, struct fb_info
*info
)
318 struct leo_par
*par
= (struct leo_par
*) info
->par
;
319 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
323 spin_lock_irqsave(&par
->lock
, flags
);
326 case FB_BLANK_UNBLANK
: /* Unblanking */
327 val
= sbus_readl(&lx_krn
->krn_csr
);
328 val
|= LEO_KRN_CSR_ENABLE
;
329 sbus_writel(val
, &lx_krn
->krn_csr
);
330 par
->flags
&= ~LEO_FLAG_BLANKED
;
333 case FB_BLANK_NORMAL
: /* Normal blanking */
334 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
335 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
336 case FB_BLANK_POWERDOWN
: /* Poweroff */
337 val
= sbus_readl(&lx_krn
->krn_csr
);
338 val
&= ~LEO_KRN_CSR_ENABLE
;
339 sbus_writel(val
, &lx_krn
->krn_csr
);
340 par
->flags
|= LEO_FLAG_BLANKED
;
344 spin_unlock_irqrestore(&par
->lock
, flags
);
349 static struct sbus_mmap_map leo_mmap_map
[] = {
356 .voff
= LEO_LC_SS0_USR_MAP
,
357 .poff
= LEO_OFF_LC_SS0_USR
,
361 .voff
= LEO_LD_SS0_MAP
,
362 .poff
= LEO_OFF_LD_SS0
,
366 .voff
= LEO_LX_CURSOR_MAP
,
367 .poff
= LEO_OFF_LX_CURSOR
,
376 .voff
= LEO_LC_SS1_USR_MAP
,
377 .poff
= LEO_OFF_LC_SS1_USR
,
381 .voff
= LEO_LD_SS1_MAP
,
382 .poff
= LEO_OFF_LD_SS1
,
391 .voff
= LEO_LX_KRN_MAP
,
392 .poff
= LEO_OFF_LX_KRN
,
396 .voff
= LEO_LC_SS0_KRN_MAP
,
397 .poff
= LEO_OFF_LC_SS0_KRN
,
401 .voff
= LEO_LC_SS1_KRN_MAP
,
402 .poff
= LEO_OFF_LC_SS1_KRN
,
406 .voff
= LEO_LD_GBL_MAP
,
407 .poff
= LEO_OFF_LD_GBL
,
411 .voff
= LEO_UNK2_MAP
,
412 .poff
= LEO_OFF_UNK2
,
418 static int leo_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
420 struct leo_par
*par
= (struct leo_par
*)info
->par
;
422 return sbusfb_mmap_helper(leo_mmap_map
,
423 par
->physbase
, par
->fbsize
,
427 static int leo_ioctl(struct fb_info
*info
, unsigned int cmd
, unsigned long arg
)
429 struct leo_par
*par
= (struct leo_par
*) info
->par
;
431 return sbusfb_ioctl_helper(cmd
, arg
, info
,
432 FBTYPE_SUNLEO
, 32, par
->fbsize
);
440 leo_init_fix(struct fb_info
*info
, struct device_node
*dp
)
442 strlcpy(info
->fix
.id
, dp
->name
, sizeof(info
->fix
.id
));
444 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
445 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
447 info
->fix
.line_length
= 8192;
449 info
->fix
.accel
= FB_ACCEL_SUN_LEO
;
452 static void leo_wid_put(struct fb_info
*info
, struct fb_wid_list
*wl
)
454 struct leo_par
*par
= (struct leo_par
*) info
->par
;
455 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
456 struct fb_wid_item
*wi
;
461 spin_lock_irqsave(&par
->lock
, flags
);
465 for (i
= 0, wi
= wl
->wl_list
; i
< wl
->wl_count
; i
++, wi
++) {
466 switch (wi
->wi_type
) {
468 j
= (wi
->wi_index
& 0xf) + 0x40;
472 j
= wi
->wi_index
& 0x3f;
478 sbus_writel(0x5800 + j
, &lx_krn
->krn_type
);
479 sbus_writel(wi
->wi_values
[0], &lx_krn
->krn_value
);
481 sbus_writel(LEO_KRN_TYPE_WID
, &lx_krn
->krn_type
);
483 val
= sbus_readl(&lx_krn
->krn_csr
);
484 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
485 sbus_writel(val
, &lx_krn
->krn_csr
);
487 spin_unlock_irqrestore(&par
->lock
, flags
);
490 static void leo_init_wids(struct fb_info
*info
)
492 struct fb_wid_item wi
;
493 struct fb_wid_list wl
;
497 wi
.wi_type
= FB_WID_DBL_8
;
499 wi
.wi_values
[0] = 0x2c0;
500 leo_wid_put(info
, &wl
);
502 wi
.wi_values
[0] = 0x30;
503 leo_wid_put(info
, &wl
);
505 wi
.wi_values
[0] = 0x20;
506 leo_wid_put(info
, &wl
);
507 wi
.wi_type
= FB_WID_DBL_24
;
509 wi
.wi_values
[0] = 0x30;
510 leo_wid_put(info
, &wl
);
513 static void leo_init_hw(struct fb_info
*info
)
515 struct leo_par
*par
= (struct leo_par
*) info
->par
;
518 val
= sbus_readl(&par
->ld_ss1
->ss1_misc
);
519 val
|= LEO_SS1_MISC_ENABLE
;
520 sbus_writel(val
, &par
->ld_ss1
->ss1_misc
);
522 leo_switch_from_graph(info
);
525 static void leo_fixup_var_rgb(struct fb_var_screeninfo
*var
)
529 var
->green
.offset
= 8;
530 var
->green
.length
= 8;
531 var
->blue
.offset
= 16;
532 var
->blue
.length
= 8;
533 var
->transp
.offset
= 0;
534 var
->transp
.length
= 0;
537 static void leo_unmap_regs(struct of_device
*op
, struct fb_info
*info
,
541 of_iounmap(&op
->resource
[0], par
->lc_ss0_usr
, 0x1000);
543 of_iounmap(&op
->resource
[0], par
->ld_ss0
, 0x1000);
545 of_iounmap(&op
->resource
[0], par
->ld_ss1
, 0x1000);
547 of_iounmap(&op
->resource
[0], par
->lx_krn
, 0x1000);
549 of_iounmap(&op
->resource
[0],
550 par
->cursor
, sizeof(struct leo_cursor
));
551 if (info
->screen_base
)
552 of_iounmap(&op
->resource
[0], info
->screen_base
, 0x800000);
555 static int __devinit
leo_probe(struct of_device
*op
,
556 const struct of_device_id
*match
)
558 struct device_node
*dp
= op
->node
;
559 struct fb_info
*info
;
563 info
= framebuffer_alloc(sizeof(struct leo_par
), &op
->dev
);
570 spin_lock_init(&par
->lock
);
572 par
->physbase
= op
->resource
[0].start
;
573 par
->which_io
= op
->resource
[0].flags
& IORESOURCE_BITS
;
575 sbusfb_fill_var(&info
->var
, dp
, 32);
576 leo_fixup_var_rgb(&info
->var
);
578 linebytes
= of_getintprop_default(dp
, "linebytes",
580 par
->fbsize
= PAGE_ALIGN(linebytes
* info
->var
.yres
);
583 of_ioremap(&op
->resource
[0], LEO_OFF_LC_SS0_USR
,
584 0x1000, "leolc ss0usr");
586 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS0
,
587 0x1000, "leold ss0");
589 of_ioremap(&op
->resource
[0], LEO_OFF_LD_SS1
,
590 0x1000, "leold ss1");
592 of_ioremap(&op
->resource
[0], LEO_OFF_LX_KRN
,
593 0x1000, "leolx krn");
595 of_ioremap(&op
->resource
[0], LEO_OFF_LX_CURSOR
,
596 sizeof(struct leo_cursor
), "leolx cursor");
598 of_ioremap(&op
->resource
[0], LEO_OFF_SS0
,
599 0x800000, "leo ram");
600 if (!par
->lc_ss0_usr
||
608 info
->flags
= FBINFO_DEFAULT
;
609 info
->fbops
= &leo_ops
;
610 info
->pseudo_palette
= par
->clut_data
;
615 leo_blank(FB_BLANK_UNBLANK
, info
);
617 if (fb_alloc_cmap(&info
->cmap
, 256, 0))
620 leo_init_fix(info
, dp
);
622 err
= register_framebuffer(info
);
624 goto out_dealloc_cmap
;
626 dev_set_drvdata(&op
->dev
, info
);
628 printk(KERN_INFO
"%s: leo at %lx:%lx\n",
630 par
->which_io
, par
->physbase
);
635 fb_dealloc_cmap(&info
->cmap
);
638 leo_unmap_regs(op
, info
, par
);
639 framebuffer_release(info
);
645 static int __devexit
leo_remove(struct of_device
*op
)
647 struct fb_info
*info
= dev_get_drvdata(&op
->dev
);
648 struct leo_par
*par
= info
->par
;
650 unregister_framebuffer(info
);
651 fb_dealloc_cmap(&info
->cmap
);
653 leo_unmap_regs(op
, info
, par
);
655 framebuffer_release(info
);
657 dev_set_drvdata(&op
->dev
, NULL
);
662 static const struct of_device_id leo_match
[] = {
668 MODULE_DEVICE_TABLE(of
, leo_match
);
670 static struct of_platform_driver leo_driver
= {
672 .match_table
= leo_match
,
674 .remove
= __devexit_p(leo_remove
),
677 static int __init
leo_init(void)
679 if (fb_get_options("leofb", NULL
))
682 return of_register_driver(&leo_driver
, &of_bus_type
);
685 static void __exit
leo_exit(void)
687 of_unregister_driver(&leo_driver
);
690 module_init(leo_init
);
691 module_exit(leo_exit
);
693 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
694 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
695 MODULE_VERSION("2.0");
696 MODULE_LICENSE("GPL");