1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/wmt_ge_rops.c
5 * Accelerators for raster operations using WonderMedia Graphics Engine
7 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
10 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include "core/fb_draw.h"
16 #include "wmt_ge_rops.h"
18 #define GE_COMMAND_OFF 0x00
19 #define GE_DEPTH_OFF 0x04
20 #define GE_HIGHCOLOR_OFF 0x08
21 #define GE_ROPCODE_OFF 0x14
22 #define GE_FIRE_OFF 0x18
23 #define GE_SRCBASE_OFF 0x20
24 #define GE_SRCDISPW_OFF 0x24
25 #define GE_SRCDISPH_OFF 0x28
26 #define GE_SRCAREAX_OFF 0x2c
27 #define GE_SRCAREAY_OFF 0x30
28 #define GE_SRCAREAW_OFF 0x34
29 #define GE_SRCAREAH_OFF 0x38
30 #define GE_DESTBASE_OFF 0x3c
31 #define GE_DESTDISPW_OFF 0x40
32 #define GE_DESTDISPH_OFF 0x44
33 #define GE_DESTAREAX_OFF 0x48
34 #define GE_DESTAREAY_OFF 0x4c
35 #define GE_DESTAREAW_OFF 0x50
36 #define GE_DESTAREAH_OFF 0x54
37 #define GE_PAT0C_OFF 0x88 /* Pattern 0 color */
38 #define GE_ENABLE_OFF 0xec
39 #define GE_INTEN_OFF 0xf0
40 #define GE_STATUS_OFF 0xf8
42 static void __iomem
*regbase
;
44 void wmt_ge_fillrect(struct fb_info
*p
, const struct fb_fillrect
*rect
)
46 unsigned long fg
, pat
;
48 if (p
->state
!= FBINFO_STATE_RUNNING
)
51 if (p
->fix
.visual
== FB_VISUAL_TRUECOLOR
||
52 p
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
)
53 fg
= ((u32
*) (p
->pseudo_palette
))[rect
->color
];
57 pat
= pixel_to_pat(p
->var
.bits_per_pixel
, fg
);
59 if (p
->fbops
->fb_sync
)
62 writel(p
->var
.bits_per_pixel
== 32 ? 3 :
63 (p
->var
.bits_per_pixel
== 8 ? 0 : 1), regbase
+ GE_DEPTH_OFF
);
64 writel(p
->var
.bits_per_pixel
== 15 ? 1 : 0, regbase
+ GE_HIGHCOLOR_OFF
);
65 writel(p
->fix
.smem_start
, regbase
+ GE_DESTBASE_OFF
);
66 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_DESTDISPW_OFF
);
67 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_DESTDISPH_OFF
);
68 writel(rect
->dx
, regbase
+ GE_DESTAREAX_OFF
);
69 writel(rect
->dy
, regbase
+ GE_DESTAREAY_OFF
);
70 writel(rect
->width
- 1, regbase
+ GE_DESTAREAW_OFF
);
71 writel(rect
->height
- 1, regbase
+ GE_DESTAREAH_OFF
);
73 writel(pat
, regbase
+ GE_PAT0C_OFF
);
74 writel(1, regbase
+ GE_COMMAND_OFF
);
75 writel(rect
->rop
== ROP_XOR
? 0x5a : 0xf0, regbase
+ GE_ROPCODE_OFF
);
76 writel(1, regbase
+ GE_FIRE_OFF
);
78 EXPORT_SYMBOL_GPL(wmt_ge_fillrect
);
80 void wmt_ge_copyarea(struct fb_info
*p
, const struct fb_copyarea
*area
)
82 if (p
->state
!= FBINFO_STATE_RUNNING
)
85 if (p
->fbops
->fb_sync
)
88 writel(p
->var
.bits_per_pixel
> 16 ? 3 :
89 (p
->var
.bits_per_pixel
> 8 ? 1 : 0), regbase
+ GE_DEPTH_OFF
);
91 writel(p
->fix
.smem_start
, regbase
+ GE_SRCBASE_OFF
);
92 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_SRCDISPW_OFF
);
93 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_SRCDISPH_OFF
);
94 writel(area
->sx
, regbase
+ GE_SRCAREAX_OFF
);
95 writel(area
->sy
, regbase
+ GE_SRCAREAY_OFF
);
96 writel(area
->width
- 1, regbase
+ GE_SRCAREAW_OFF
);
97 writel(area
->height
- 1, regbase
+ GE_SRCAREAH_OFF
);
99 writel(p
->fix
.smem_start
, regbase
+ GE_DESTBASE_OFF
);
100 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_DESTDISPW_OFF
);
101 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_DESTDISPH_OFF
);
102 writel(area
->dx
, regbase
+ GE_DESTAREAX_OFF
);
103 writel(area
->dy
, regbase
+ GE_DESTAREAY_OFF
);
104 writel(area
->width
- 1, regbase
+ GE_DESTAREAW_OFF
);
105 writel(area
->height
- 1, regbase
+ GE_DESTAREAH_OFF
);
107 writel(0xcc, regbase
+ GE_ROPCODE_OFF
);
108 writel(1, regbase
+ GE_COMMAND_OFF
);
109 writel(1, regbase
+ GE_FIRE_OFF
);
111 EXPORT_SYMBOL_GPL(wmt_ge_copyarea
);
113 int wmt_ge_sync(struct fb_info
*p
)
116 while ((readl(regbase
+ GE_STATUS_OFF
) & 4) && --loops
)
118 return loops
> 0 ? 0 : -EBUSY
;
120 EXPORT_SYMBOL_GPL(wmt_ge_sync
);
122 static int wmt_ge_rops_probe(struct platform_device
*pdev
)
124 struct resource
*res
;
126 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
128 dev_err(&pdev
->dev
, "no I/O memory resource defined\n");
132 /* Only one ROP engine is presently supported. */
133 if (unlikely(regbase
)) {
138 regbase
= ioremap(res
->start
, resource_size(res
));
139 if (regbase
== NULL
) {
140 dev_err(&pdev
->dev
, "failed to map I/O memory\n");
144 writel(1, regbase
+ GE_ENABLE_OFF
);
145 printk(KERN_INFO
"Enabled support for WMT GE raster acceleration\n");
150 static void wmt_ge_rops_remove(struct platform_device
*pdev
)
155 static const struct of_device_id wmt_dt_ids
[] = {
156 { .compatible
= "wm,prizm-ge-rops", },
160 static struct platform_driver wmt_ge_rops_driver
= {
161 .probe
= wmt_ge_rops_probe
,
162 .remove
= wmt_ge_rops_remove
,
164 .name
= "wmt_ge_rops",
165 .of_match_table
= wmt_dt_ids
,
169 module_platform_driver(wmt_ge_rops_driver
);
171 MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com>");
172 MODULE_DESCRIPTION("Accelerators for raster operations using "
173 "WonderMedia Graphics Engine");
174 MODULE_DEVICE_TABLE(of
, wmt_dt_ids
);