wmt_ge_rops.c 5.3 KB

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