1 // SPDX-License-Identifier: GPL-2.0-only
2 /* leo.c: LEO frame buffer driver
4 * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
5 * Copyright (C) 1996-1999 Jakub Jelinek (jj@ultra.linux.cz)
6 * Copyright (C) 1997 Michal Rehacek (Michal.Rehacek@st.mff.cuni.cz)
8 * Driver layout based loosely on tgafb.c, see that file for credits.
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/init.h>
21 #include <linux/platform_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
*);
34 static int leo_pan_display(struct fb_var_screeninfo
*, struct fb_info
*);
36 static int leo_sbusfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
);
37 static int leo_sbusfb_ioctl(struct fb_info
*info
, unsigned int cmd
, unsigned long arg
);
40 * Frame buffer operations
43 static const struct fb_ops leo_ops
= {
45 FB_DEFAULT_SBUS_OPS(leo
),
46 .fb_setcolreg
= leo_setcolreg
,
47 .fb_blank
= leo_blank
,
48 .fb_pan_display
= leo_pan_display
,
51 #define LEO_OFF_LC_SS0_KRN 0x00200000UL
52 #define LEO_OFF_LC_SS0_USR 0x00201000UL
53 #define LEO_OFF_LC_SS1_KRN 0x01200000UL
54 #define LEO_OFF_LC_SS1_USR 0x01201000UL
55 #define LEO_OFF_LD_SS0 0x00400000UL
56 #define LEO_OFF_LD_SS1 0x01400000UL
57 #define LEO_OFF_LD_GBL 0x00401000UL
58 #define LEO_OFF_LX_KRN 0x00600000UL
59 #define LEO_OFF_LX_CURSOR 0x00601000UL
60 #define LEO_OFF_SS0 0x00800000UL
61 #define LEO_OFF_SS1 0x01800000UL
62 #define LEO_OFF_UNK 0x00602000UL
63 #define LEO_OFF_UNK2 0x00000000UL
65 #define LEO_CUR_ENABLE 0x00000080
66 #define LEO_CUR_UPDATE 0x00000030
67 #define LEO_CUR_PROGRESS 0x00000006
68 #define LEO_CUR_UPDATECMAP 0x00000003
70 #define LEO_CUR_TYPE_MASK 0x00000000
71 #define LEO_CUR_TYPE_IMAGE 0x00000020
72 #define LEO_CUR_TYPE_CMAP 0x00000050
82 #define LEO_KRN_TYPE_CLUT0 0x00001000
83 #define LEO_KRN_TYPE_CLUT1 0x00001001
84 #define LEO_KRN_TYPE_CLUT2 0x00001002
85 #define LEO_KRN_TYPE_WID 0x00001003
86 #define LEO_KRN_TYPE_UNK 0x00001006
87 #define LEO_KRN_TYPE_VIDEO 0x00002003
88 #define LEO_KRN_TYPE_CLUTDATA 0x00004000
89 #define LEO_KRN_CSR_ENABLE 0x00000008
90 #define LEO_KRN_CSR_PROGRESS 0x00000004
91 #define LEO_KRN_CSR_UNK 0x00000002
92 #define LEO_KRN_CSR_UNK2 0x00000001
100 struct leo_lc_ss0_krn
{
106 struct leo_lc_ss0_usr
{
118 struct leo_lc_ss1_krn
{
122 struct leo_lc_ss1_usr
{
134 u32 pickmin
; /* SS1 only */
135 u32 pickmax
; /* SS1 only */
138 u32 src
; /* Copy/Scroll (SS0 only) */
139 u32 dst
; /* Copy/Scroll/Fill (SS0 only) */
140 u32 extent
; /* Copy/Scroll/Fill size (SS0 only) */
142 u32 setsem
; /* SS1 only */
143 u32 clrsem
; /* SS1 only */
144 u32 clrpick
; /* SS1 only */
145 u32 clrdat
; /* SS1 only */
146 u32 alpha
; /* SS1 only */
152 u32 dczf
; /* SS1 only */
153 u32 dczb
; /* SS1 only */
154 u32 dcs
; /* SS1 only */
155 u32 dczs
; /* SS1 only */
156 u32 pickfb
; /* SS1 only */
157 u32 pickbb
; /* SS1 only */
158 u32 dcfc
; /* SS1 only */
159 u32 forcecol
; /* SS1 only */
160 u32 door
[8]; /* SS1 only */
161 u32 pick
[5]; /* SS1 only */
164 #define LEO_SS1_MISC_ENABLE 0x00000001
165 #define LEO_SS1_MISC_STEREO 0x00000002
177 struct leo_lx_krn __iomem
*lx_krn
;
178 struct leo_lc_ss0_usr __iomem
*lc_ss0_usr
;
179 struct leo_ld_ss0 __iomem
*ld_ss0
;
180 struct leo_ld_ss1 __iomem
*ld_ss1
;
181 struct leo_cursor __iomem
*cursor
;
186 #define LEO_FLAG_BLANKED 0x00000001
188 unsigned long which_io
;
191 static void leo_wait(struct leo_lx_krn __iomem
*lx_krn
)
196 (sbus_readl(&lx_krn
->krn_csr
) & LEO_KRN_CSR_PROGRESS
) &&
199 udelay(1); /* Busy wait at most 0.3 sec */
203 static void leo_switch_from_graph(struct fb_info
*info
)
205 struct leo_par
*par
= (struct leo_par
*) info
->par
;
206 struct leo_ld_ss0 __iomem
*ss
= par
->ld_ss0
;
207 struct leo_cursor __iomem
*cursor
= par
->cursor
;
211 spin_lock_irqsave(&par
->lock
, flags
);
213 par
->extent
= ((info
->var
.xres
- 1) |
214 ((info
->var
.yres
- 1) << 16));
216 sbus_writel(0xffffffff, &ss
->wid
);
217 sbus_writel(0xffff, &ss
->wmask
);
218 sbus_writel(0, &ss
->vclipmin
);
219 sbus_writel(par
->extent
, &ss
->vclipmax
);
220 sbus_writel(0, &ss
->fg
);
221 sbus_writel(0xff000000, &ss
->planemask
);
222 sbus_writel(0x310850, &ss
->rop
);
223 sbus_writel(0, &ss
->widclip
);
224 sbus_writel((info
->var
.xres
-1) | ((info
->var
.yres
-1) << 11),
225 &par
->lc_ss0_usr
->extent
);
226 sbus_writel(4, &par
->lc_ss0_usr
->addrspace
);
227 sbus_writel(0x80000000, &par
->lc_ss0_usr
->fill
);
228 sbus_writel(0, &par
->lc_ss0_usr
->fontt
);
230 val
= sbus_readl(&par
->lc_ss0_usr
->csr
);
231 } while (val
& 0x20000000);
233 /* setup screen buffer for cfb_* functions */
234 sbus_writel(1, &ss
->wid
);
235 sbus_writel(0x00ffffff, &ss
->planemask
);
236 sbus_writel(0x310b90, &ss
->rop
);
237 sbus_writel(0, &par
->lc_ss0_usr
->addrspace
);
240 sbus_writel(sbus_readl(&cursor
->cur_misc
) & ~LEO_CUR_ENABLE
, &cursor
->cur_misc
);
242 spin_unlock_irqrestore(&par
->lock
, flags
);
245 static int leo_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
247 /* We just use this to catch switches out of
250 leo_switch_from_graph(info
);
252 if (var
->xoffset
|| var
->yoffset
|| var
->vmode
)
258 * leo_setcolreg - Optional function. Sets a color register.
259 * @regno: boolean, 0 copy local, 1 get_user() function
260 * @red: frame buffer colormap structure
261 * @green: The green value which can be up to 16 bits wide
262 * @blue: The blue value which can be up to 16 bits wide.
263 * @transp: If supported the alpha value which can be up to 16 bits wide.
264 * @info: frame buffer info structure
266 static int leo_setcolreg(unsigned regno
,
267 unsigned red
, unsigned green
, unsigned blue
,
268 unsigned transp
, struct fb_info
*info
)
270 struct leo_par
*par
= (struct leo_par
*) info
->par
;
271 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
283 par
->clut_data
[regno
] = red
| (green
<< 8) | (blue
<< 16);
285 spin_lock_irqsave(&par
->lock
, flags
);
289 sbus_writel(LEO_KRN_TYPE_CLUTDATA
, &lx_krn
->krn_type
);
290 for (i
= 0; i
< 256; i
++)
291 sbus_writel(par
->clut_data
[i
], &lx_krn
->krn_value
);
292 sbus_writel(LEO_KRN_TYPE_CLUT0
, &lx_krn
->krn_type
);
294 val
= sbus_readl(&lx_krn
->krn_csr
);
295 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
296 sbus_writel(val
, &lx_krn
->krn_csr
);
298 spin_unlock_irqrestore(&par
->lock
, flags
);
304 * leo_blank - Optional function. Blanks the display.
305 * @blank: the blank mode we want.
306 * @info: frame buffer structure that represents a single frame buffer
308 static int leo_blank(int blank
, struct fb_info
*info
)
310 struct leo_par
*par
= (struct leo_par
*) info
->par
;
311 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
315 spin_lock_irqsave(&par
->lock
, flags
);
318 case FB_BLANK_UNBLANK
: /* Unblanking */
319 val
= sbus_readl(&lx_krn
->krn_csr
);
320 val
|= LEO_KRN_CSR_ENABLE
;
321 sbus_writel(val
, &lx_krn
->krn_csr
);
322 par
->flags
&= ~LEO_FLAG_BLANKED
;
325 case FB_BLANK_NORMAL
: /* Normal blanking */
326 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
327 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
328 case FB_BLANK_POWERDOWN
: /* Poweroff */
329 val
= sbus_readl(&lx_krn
->krn_csr
);
330 val
&= ~LEO_KRN_CSR_ENABLE
;
331 sbus_writel(val
, &lx_krn
->krn_csr
);
332 par
->flags
|= LEO_FLAG_BLANKED
;
336 spin_unlock_irqrestore(&par
->lock
, flags
);
341 static const struct sbus_mmap_map leo_mmap_map
[] = {
348 .voff
= LEO_LC_SS0_USR_MAP
,
349 .poff
= LEO_OFF_LC_SS0_USR
,
353 .voff
= LEO_LD_SS0_MAP
,
354 .poff
= LEO_OFF_LD_SS0
,
358 .voff
= LEO_LX_CURSOR_MAP
,
359 .poff
= LEO_OFF_LX_CURSOR
,
368 .voff
= LEO_LC_SS1_USR_MAP
,
369 .poff
= LEO_OFF_LC_SS1_USR
,
373 .voff
= LEO_LD_SS1_MAP
,
374 .poff
= LEO_OFF_LD_SS1
,
383 .voff
= LEO_LX_KRN_MAP
,
384 .poff
= LEO_OFF_LX_KRN
,
388 .voff
= LEO_LC_SS0_KRN_MAP
,
389 .poff
= LEO_OFF_LC_SS0_KRN
,
393 .voff
= LEO_LC_SS1_KRN_MAP
,
394 .poff
= LEO_OFF_LC_SS1_KRN
,
398 .voff
= LEO_LD_GBL_MAP
,
399 .poff
= LEO_OFF_LD_GBL
,
403 .voff
= LEO_UNK2_MAP
,
404 .poff
= LEO_OFF_UNK2
,
410 static int leo_sbusfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
412 struct leo_par
*par
= (struct leo_par
*)info
->par
;
414 return sbusfb_mmap_helper(leo_mmap_map
,
415 info
->fix
.smem_start
, info
->fix
.smem_len
,
419 static int leo_sbusfb_ioctl(struct fb_info
*info
, unsigned int cmd
, unsigned long arg
)
421 return sbusfb_ioctl_helper(cmd
, arg
, info
,
422 FBTYPE_SUNLEO
, 32, info
->fix
.smem_len
);
430 leo_init_fix(struct fb_info
*info
, struct device_node
*dp
)
432 snprintf(info
->fix
.id
, sizeof(info
->fix
.id
), "%pOFn", dp
);
434 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
435 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
437 info
->fix
.line_length
= 8192;
439 info
->fix
.accel
= FB_ACCEL_SUN_LEO
;
442 static void leo_wid_put(struct fb_info
*info
, struct fb_wid_list
*wl
)
444 struct leo_par
*par
= (struct leo_par
*) info
->par
;
445 struct leo_lx_krn __iomem
*lx_krn
= par
->lx_krn
;
446 struct fb_wid_item
*wi
;
451 spin_lock_irqsave(&par
->lock
, flags
);
455 for (i
= 0, wi
= wl
->wl_list
; i
< wl
->wl_count
; i
++, wi
++) {
456 switch (wi
->wi_type
) {
458 j
= (wi
->wi_index
& 0xf) + 0x40;
462 j
= wi
->wi_index
& 0x3f;
468 sbus_writel(0x5800 + j
, &lx_krn
->krn_type
);
469 sbus_writel(wi
->wi_values
[0], &lx_krn
->krn_value
);
471 sbus_writel(LEO_KRN_TYPE_WID
, &lx_krn
->krn_type
);
473 val
= sbus_readl(&lx_krn
->krn_csr
);
474 val
|= (LEO_KRN_CSR_UNK
| LEO_KRN_CSR_UNK2
);
475 sbus_writel(val
, &lx_krn
->krn_csr
);
477 spin_unlock_irqrestore(&par
->lock
, flags
);
480 static void leo_init_wids(struct fb_info
*info
)
482 struct fb_wid_item wi
;
483 struct fb_wid_list wl
;
487 wi
.wi_type
= FB_WID_DBL_8
;
489 wi
.wi_values
[0] = 0x2c0;
490 leo_wid_put(info
, &wl
);
492 wi
.wi_values
[0] = 0x30;
493 leo_wid_put(info
, &wl
);
495 wi
.wi_values
[0] = 0x20;
496 leo_wid_put(info
, &wl
);
497 wi
.wi_type
= FB_WID_DBL_24
;
499 wi
.wi_values
[0] = 0x30;
500 leo_wid_put(info
, &wl
);
503 static void leo_init_hw(struct fb_info
*info
)
505 struct leo_par
*par
= (struct leo_par
*) info
->par
;
508 val
= sbus_readl(&par
->ld_ss1
->ss1_misc
);
509 val
|= LEO_SS1_MISC_ENABLE
;
510 sbus_writel(val
, &par
->ld_ss1
->ss1_misc
);
512 leo_switch_from_graph(info
);
515 static void leo_fixup_var_rgb(struct fb_var_screeninfo
*var
)
519 var
->green
.offset
= 8;
520 var
->green
.length
= 8;
521 var
->blue
.offset
= 16;
522 var
->blue
.length
= 8;
523 var
->transp
.offset
= 0;
524 var
->transp
.length
= 0;
527 static void leo_unmap_regs(struct platform_device
*op
, struct fb_info
*info
,
531 of_iounmap(&op
->resource
[0], par
->lc_ss0_usr
, 0x1000);
533 of_iounmap(&op
->resource
[0], par
->ld_ss0
, 0x1000);
535 of_iounmap(&op
->resource
[0], par
->ld_ss1
, 0x1000);
537 of_iounmap(&op
->resource
[0], par
->lx_krn
, 0x1000);
539 of_iounmap(&op
->resource
[0],
540 par
->cursor
, sizeof(struct leo_cursor
));
541 if (info
->screen_base
)
542 of_iounmap(&op
->resource
[0], info
->screen_base
, 0x800000);
545 static int leo_probe(struct platform_device
*op
)
547 struct device_node
*dp
= op
->dev
.of_node
;
548 struct fb_info
*info
;
552 info
= framebuffer_alloc(sizeof(struct leo_par
), &op
->dev
);
559 spin_lock_init(&par
->lock
);
561 info
->fix
.smem_start
= op
->resource
[0].start
;
562 par
->which_io
= op
->resource
[0].flags
& IORESOURCE_BITS
;
564 sbusfb_fill_var(&info
->var
, dp
, 32);
565 leo_fixup_var_rgb(&info
->var
);
567 linebytes
= of_getintprop_default(dp
, "linebytes",
569 info
->fix
.smem_len
= PAGE_ALIGN(linebytes
* info
->var
.yres
);
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");
587 of_ioremap(&op
->resource
[0], LEO_OFF_SS0
,
588 0x800000, "leo ram");
589 if (!par
->lc_ss0_usr
||
597 info
->fbops
= &leo_ops
;
598 info
->pseudo_palette
= par
->clut_data
;
603 leo_blank(FB_BLANK_UNBLANK
, info
);
605 if (fb_alloc_cmap(&info
->cmap
, 256, 0))
608 leo_init_fix(info
, dp
);
610 err
= register_framebuffer(info
);
612 goto out_dealloc_cmap
;
614 dev_set_drvdata(&op
->dev
, info
);
616 printk(KERN_INFO
"%pOF: leo at %lx:%lx\n",
618 par
->which_io
, info
->fix
.smem_start
);
623 fb_dealloc_cmap(&info
->cmap
);
626 leo_unmap_regs(op
, info
, par
);
627 framebuffer_release(info
);
633 static void leo_remove(struct platform_device
*op
)
635 struct fb_info
*info
= dev_get_drvdata(&op
->dev
);
636 struct leo_par
*par
= info
->par
;
638 unregister_framebuffer(info
);
639 fb_dealloc_cmap(&info
->cmap
);
641 leo_unmap_regs(op
, info
, par
);
643 framebuffer_release(info
);
646 static const struct of_device_id leo_match
[] = {
652 MODULE_DEVICE_TABLE(of
, leo_match
);
654 static struct platform_driver leo_driver
= {
657 .of_match_table
= leo_match
,
660 .remove
= leo_remove
,
663 static int __init
leo_init(void)
665 if (fb_get_options("leofb", NULL
))
668 return platform_driver_register(&leo_driver
);
671 static void __exit
leo_exit(void)
673 platform_driver_unregister(&leo_driver
);
676 module_init(leo_init
);
677 module_exit(leo_exit
);
679 MODULE_DESCRIPTION("framebuffer driver for LEO chipsets");
680 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
681 MODULE_VERSION("2.0");
682 MODULE_LICENSE("GPL");