2 * linux/drivers/video/wmt_ge_rops.c
4 * Accelerators for raster operations using WonderMedia Graphics Engine
6 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/module.h>
20 #include <linux/platform_device.h>
23 #define GE_COMMAND_OFF 0x00
24 #define GE_DEPTH_OFF 0x04
25 #define GE_HIGHCOLOR_OFF 0x08
26 #define GE_ROPCODE_OFF 0x14
27 #define GE_FIRE_OFF 0x18
28 #define GE_SRCBASE_OFF 0x20
29 #define GE_SRCDISPW_OFF 0x24
30 #define GE_SRCDISPH_OFF 0x28
31 #define GE_SRCAREAX_OFF 0x2c
32 #define GE_SRCAREAY_OFF 0x30
33 #define GE_SRCAREAW_OFF 0x34
34 #define GE_SRCAREAH_OFF 0x38
35 #define GE_DESTBASE_OFF 0x3c
36 #define GE_DESTDISPW_OFF 0x40
37 #define GE_DESTDISPH_OFF 0x44
38 #define GE_DESTAREAX_OFF 0x48
39 #define GE_DESTAREAY_OFF 0x4c
40 #define GE_DESTAREAW_OFF 0x50
41 #define GE_DESTAREAH_OFF 0x54
42 #define GE_PAT0C_OFF 0x88 /* Pattern 0 color */
43 #define GE_ENABLE_OFF 0xec
44 #define GE_INTEN_OFF 0xf0
45 #define GE_STATUS_OFF 0xf8
47 static void __iomem
*regbase
;
49 void wmt_ge_fillrect(struct fb_info
*p
, const struct fb_fillrect
*rect
)
51 unsigned long fg
, pat
;
53 if (p
->state
!= FBINFO_STATE_RUNNING
)
56 if (p
->fix
.visual
== FB_VISUAL_TRUECOLOR
||
57 p
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
)
58 fg
= ((u32
*) (p
->pseudo_palette
))[rect
->color
];
62 pat
= pixel_to_pat(p
->var
.bits_per_pixel
, fg
);
64 if (p
->fbops
->fb_sync
)
67 writel(p
->var
.bits_per_pixel
== 32 ? 3 :
68 (p
->var
.bits_per_pixel
== 8 ? 0 : 1), regbase
+ GE_DEPTH_OFF
);
69 writel(p
->var
.bits_per_pixel
== 15 ? 1 : 0, regbase
+ GE_HIGHCOLOR_OFF
);
70 writel(p
->fix
.smem_start
, regbase
+ GE_DESTBASE_OFF
);
71 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_DESTDISPW_OFF
);
72 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_DESTDISPH_OFF
);
73 writel(rect
->dx
, regbase
+ GE_DESTAREAX_OFF
);
74 writel(rect
->dy
, regbase
+ GE_DESTAREAY_OFF
);
75 writel(rect
->width
- 1, regbase
+ GE_DESTAREAW_OFF
);
76 writel(rect
->height
- 1, regbase
+ GE_DESTAREAH_OFF
);
78 writel(pat
, regbase
+ GE_PAT0C_OFF
);
79 writel(1, regbase
+ GE_COMMAND_OFF
);
80 writel(rect
->rop
== ROP_XOR
? 0x5a : 0xf0, regbase
+ GE_ROPCODE_OFF
);
81 writel(1, regbase
+ GE_FIRE_OFF
);
83 EXPORT_SYMBOL_GPL(wmt_ge_fillrect
);
85 void wmt_ge_copyarea(struct fb_info
*p
, const struct fb_copyarea
*area
)
87 if (p
->state
!= FBINFO_STATE_RUNNING
)
90 if (p
->fbops
->fb_sync
)
93 writel(p
->var
.bits_per_pixel
> 16 ? 3 :
94 (p
->var
.bits_per_pixel
> 8 ? 1 : 0), regbase
+ GE_DEPTH_OFF
);
96 writel(p
->fix
.smem_start
, regbase
+ GE_SRCBASE_OFF
);
97 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_SRCDISPW_OFF
);
98 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_SRCDISPH_OFF
);
99 writel(area
->sx
, regbase
+ GE_SRCAREAX_OFF
);
100 writel(area
->sy
, regbase
+ GE_SRCAREAY_OFF
);
101 writel(area
->width
- 1, regbase
+ GE_SRCAREAW_OFF
);
102 writel(area
->height
- 1, regbase
+ GE_SRCAREAH_OFF
);
104 writel(p
->fix
.smem_start
, regbase
+ GE_DESTBASE_OFF
);
105 writel(p
->var
.xres_virtual
- 1, regbase
+ GE_DESTDISPW_OFF
);
106 writel(p
->var
.yres_virtual
- 1, regbase
+ GE_DESTDISPH_OFF
);
107 writel(area
->dx
, regbase
+ GE_DESTAREAX_OFF
);
108 writel(area
->dy
, regbase
+ GE_DESTAREAY_OFF
);
109 writel(area
->width
- 1, regbase
+ GE_DESTAREAW_OFF
);
110 writel(area
->height
- 1, regbase
+ GE_DESTAREAH_OFF
);
112 writel(0xcc, regbase
+ GE_ROPCODE_OFF
);
113 writel(1, regbase
+ GE_COMMAND_OFF
);
114 writel(1, regbase
+ GE_FIRE_OFF
);
116 EXPORT_SYMBOL_GPL(wmt_ge_copyarea
);
118 int wmt_ge_sync(struct fb_info
*p
)
121 while ((readl(regbase
+ GE_STATUS_OFF
) & 4) && --loops
)
123 return loops
> 0 ? 0 : -EBUSY
;
125 EXPORT_SYMBOL_GPL(wmt_ge_sync
);
127 static int __devinit
wmt_ge_rops_probe(struct platform_device
*pdev
)
129 struct resource
*res
;
131 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
133 dev_err(&pdev
->dev
, "no I/O memory resource defined\n");
137 /* Only one ROP engine is presently supported. */
138 if (unlikely(regbase
)) {
143 regbase
= ioremap(res
->start
, resource_size(res
));
144 if (regbase
== NULL
) {
145 dev_err(&pdev
->dev
, "failed to map I/O memory\n");
149 writel(1, regbase
+ GE_ENABLE_OFF
);
150 printk(KERN_INFO
"Enabled support for WMT GE raster acceleration\n");
155 static int __devexit
wmt_ge_rops_remove(struct platform_device
*pdev
)
161 static struct platform_driver wmt_ge_rops_driver
= {
162 .probe
= wmt_ge_rops_probe
,
163 .remove
= __devexit_p(wmt_ge_rops_remove
),
165 .owner
= THIS_MODULE
,
166 .name
= "wmt_ge_rops",
170 static int __init
wmt_ge_rops_init(void)
172 return platform_driver_register(&wmt_ge_rops_driver
);
175 static void __exit
wmt_ge_rops_exit(void)
177 platform_driver_unregister(&wmt_ge_rops_driver
);
180 module_init(wmt_ge_rops_init
);
181 module_exit(wmt_ge_rops_exit
);
183 MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com");
184 MODULE_DESCRIPTION("Accelerators for raster operations using "
185 "WonderMedia Graphics Engine");
186 MODULE_LICENSE("GPL");