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