pmag-aa-fb.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * linux/drivers/video/pmag-aa-fb.c
  3. * Copyright 2002 Karsten Merker <merker@debian.org>
  4. *
  5. * PMAG-AA TurboChannel framebuffer card support ... derived from
  6. * pmag-ba-fb.c, which is Copyright (C) 1999, 2000, 2001 by
  7. * Michael Engel <engel@unix-ag.org>, Karsten Merker <merker@debian.org>
  8. * and Harald Koerfgen <hkoerfg@web.de>, which itself is derived from
  9. * "HP300 Topcat framebuffer support (derived from macfb of all things)
  10. * Phil Blundell <philb@gnu.org> 1998"
  11. * Copyright (c) 2016 Maciej W. Rozycki
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file COPYING in the main directory of this
  15. * archive for more details.
  16. *
  17. * 2002-09-28 Karsten Merker <merker@linuxtag.org>
  18. * Version 0.01: First try to get a PMAG-AA running.
  19. *
  20. * 2003-02-24 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
  21. * Version 0.02: Major code cleanup.
  22. *
  23. * 2003-09-21 Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
  24. * Hardware cursor support.
  25. *
  26. * 2016-02-21 Maciej W. Rozycki <macro@linux-mips.org>
  27. * Version 0.03: Rewritten for the new FB and TC APIs.
  28. */
  29. #include <linux/compiler.h>
  30. #include <linux/errno.h>
  31. #include <linux/fb.h>
  32. #include <linux/init.h>
  33. #include <linux/io.h>
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/tc.h>
  37. #include <linux/timer.h>
  38. #include "bt455.h"
  39. #include "bt431.h"
  40. /* Version information */
  41. #define DRIVER_VERSION "0.03"
  42. #define DRIVER_AUTHOR "Karsten Merker <merker@linuxtag.org>"
  43. #define DRIVER_DESCRIPTION "PMAG-AA Framebuffer Driver"
  44. /*
  45. * Bt455 RAM DAC register base offset (rel. to TC slot base address).
  46. */
  47. #define PMAG_AA_BT455_OFFSET 0x100000
  48. /*
  49. * Bt431 cursor generator offset (rel. to TC slot base address).
  50. */
  51. #define PMAG_AA_BT431_OFFSET 0x180000
  52. /*
  53. * Begin of PMAG-AA framebuffer memory relative to TC slot address,
  54. * resolution is 1280x1024x1 (8 bits deep, but only LSB is used).
  55. */
  56. #define PMAG_AA_ONBOARD_FBMEM_OFFSET 0x200000
  57. struct aafb_par {
  58. void __iomem *mmio;
  59. struct bt455_regs __iomem *bt455;
  60. struct bt431_regs __iomem *bt431;
  61. };
  62. static struct fb_var_screeninfo aafb_defined = {
  63. .xres = 1280,
  64. .yres = 1024,
  65. .xres_virtual = 2048,
  66. .yres_virtual = 1024,
  67. .bits_per_pixel = 8,
  68. .grayscale = 1,
  69. .red.length = 0,
  70. .green.length = 1,
  71. .blue.length = 0,
  72. .activate = FB_ACTIVATE_NOW,
  73. .accel_flags = FB_ACCEL_NONE,
  74. .pixclock = 7645,
  75. .left_margin = 224,
  76. .right_margin = 32,
  77. .upper_margin = 33,
  78. .lower_margin = 3,
  79. .hsync_len = 160,
  80. .vsync_len = 3,
  81. .sync = FB_SYNC_ON_GREEN,
  82. .vmode = FB_VMODE_NONINTERLACED,
  83. };
  84. static struct fb_fix_screeninfo aafb_fix = {
  85. .id = "PMAG-AA",
  86. .smem_len = (2048 * 1024),
  87. .type = FB_TYPE_PACKED_PIXELS,
  88. .visual = FB_VISUAL_MONO10,
  89. .ypanstep = 1,
  90. .ywrapstep = 1,
  91. .line_length = 2048,
  92. .mmio_len = PMAG_AA_ONBOARD_FBMEM_OFFSET - PMAG_AA_BT455_OFFSET,
  93. };
  94. static int aafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  95. {
  96. struct aafb_par *par = info->par;
  97. if (cursor->image.height > BT431_CURSOR_SIZE ||
  98. cursor->image.width > BT431_CURSOR_SIZE) {
  99. bt431_erase_cursor(par->bt431);
  100. return -EINVAL;
  101. }
  102. if (!cursor->enable)
  103. bt431_erase_cursor(par->bt431);
  104. if (cursor->set & FB_CUR_SETPOS)
  105. bt431_position_cursor(par->bt431,
  106. cursor->image.dx, cursor->image.dy);
  107. if (cursor->set & FB_CUR_SETCMAP) {
  108. u8 fg = cursor->image.fg_color ? 0xf : 0x0;
  109. u8 bg = cursor->image.bg_color ? 0xf : 0x0;
  110. bt455_write_cmap_entry(par->bt455, 8, bg);
  111. bt455_write_cmap_next(par->bt455, bg);
  112. bt455_write_ovly_next(par->bt455, fg);
  113. }
  114. if (cursor->set & (FB_CUR_SETSIZE | FB_CUR_SETSHAPE | FB_CUR_SETIMAGE))
  115. bt431_set_cursor(par->bt431,
  116. cursor->image.data, cursor->mask, cursor->rop,
  117. cursor->image.width, cursor->image.height);
  118. if (cursor->enable)
  119. bt431_enable_cursor(par->bt431);
  120. return 0;
  121. }
  122. /* 0 unblanks, any other blanks. */
  123. static int aafb_blank(int blank, struct fb_info *info)
  124. {
  125. struct aafb_par *par = info->par;
  126. u8 val = blank ? 0x00 : 0x0f;
  127. bt455_write_cmap_entry(par->bt455, 1, val);
  128. return 0;
  129. }
  130. static struct fb_ops aafb_ops = {
  131. .owner = THIS_MODULE,
  132. .fb_blank = aafb_blank,
  133. .fb_fillrect = cfb_fillrect,
  134. .fb_copyarea = cfb_copyarea,
  135. .fb_imageblit = cfb_imageblit,
  136. .fb_cursor = aafb_cursor,
  137. };
  138. static int pmagaafb_probe(struct device *dev)
  139. {
  140. struct tc_dev *tdev = to_tc_dev(dev);
  141. resource_size_t start, len;
  142. struct fb_info *info;
  143. struct aafb_par *par;
  144. int err;
  145. info = framebuffer_alloc(sizeof(struct aafb_par), dev);
  146. if (!info) {
  147. printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
  148. return -ENOMEM;
  149. }
  150. par = info->par;
  151. dev_set_drvdata(dev, info);
  152. info->fbops = &aafb_ops;
  153. info->fix = aafb_fix;
  154. info->var = aafb_defined;
  155. info->flags = FBINFO_DEFAULT;
  156. /* Request the I/O MEM resource. */
  157. start = tdev->resource.start;
  158. len = tdev->resource.end - start + 1;
  159. if (!request_mem_region(start, len, dev_name(dev))) {
  160. printk(KERN_ERR "%s: Cannot reserve FB region\n",
  161. dev_name(dev));
  162. err = -EBUSY;
  163. goto err_alloc;
  164. }
  165. /* MMIO mapping setup. */
  166. info->fix.mmio_start = start + PMAG_AA_BT455_OFFSET;
  167. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  168. if (!par->mmio) {
  169. printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
  170. err = -ENOMEM;
  171. goto err_resource;
  172. }
  173. par->bt455 = par->mmio - PMAG_AA_BT455_OFFSET + PMAG_AA_BT455_OFFSET;
  174. par->bt431 = par->mmio - PMAG_AA_BT455_OFFSET + PMAG_AA_BT431_OFFSET;
  175. /* Frame buffer mapping setup. */
  176. info->fix.smem_start = start + PMAG_AA_ONBOARD_FBMEM_OFFSET;
  177. info->screen_base = ioremap_nocache(info->fix.smem_start,
  178. info->fix.smem_len);
  179. if (!info->screen_base) {
  180. printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
  181. err = -ENOMEM;
  182. goto err_mmio_map;
  183. }
  184. info->screen_size = info->fix.smem_len;
  185. /* Init colormap. */
  186. bt455_write_cmap_entry(par->bt455, 0, 0x0);
  187. bt455_write_cmap_next(par->bt455, 0xf);
  188. /* Init hardware cursor. */
  189. bt431_erase_cursor(par->bt431);
  190. bt431_init_cursor(par->bt431);
  191. err = register_framebuffer(info);
  192. if (err < 0) {
  193. printk(KERN_ERR "%s: Cannot register framebuffer\n",
  194. dev_name(dev));
  195. goto err_smem_map;
  196. }
  197. get_device(dev);
  198. pr_info("fb%d: %s frame buffer device at %s\n",
  199. info->node, info->fix.id, dev_name(dev));
  200. return 0;
  201. err_smem_map:
  202. iounmap(info->screen_base);
  203. err_mmio_map:
  204. iounmap(par->mmio);
  205. err_resource:
  206. release_mem_region(start, len);
  207. err_alloc:
  208. framebuffer_release(info);
  209. return err;
  210. }
  211. static int __exit pmagaafb_remove(struct device *dev)
  212. {
  213. struct tc_dev *tdev = to_tc_dev(dev);
  214. struct fb_info *info = dev_get_drvdata(dev);
  215. struct aafb_par *par = info->par;
  216. resource_size_t start, len;
  217. put_device(dev);
  218. unregister_framebuffer(info);
  219. iounmap(info->screen_base);
  220. iounmap(par->mmio);
  221. start = tdev->resource.start;
  222. len = tdev->resource.end - start + 1;
  223. release_mem_region(start, len);
  224. framebuffer_release(info);
  225. return 0;
  226. }
  227. /*
  228. * Initialise the framebuffer.
  229. */
  230. static const struct tc_device_id pmagaafb_tc_table[] = {
  231. { "DEC ", "PMAG-AA " },
  232. { }
  233. };
  234. MODULE_DEVICE_TABLE(tc, pmagaafb_tc_table);
  235. static struct tc_driver pmagaafb_driver = {
  236. .id_table = pmagaafb_tc_table,
  237. .driver = {
  238. .name = "pmagaafb",
  239. .bus = &tc_bus_type,
  240. .probe = pmagaafb_probe,
  241. .remove = __exit_p(pmagaafb_remove),
  242. },
  243. };
  244. static int __init pmagaafb_init(void)
  245. {
  246. #ifndef MODULE
  247. if (fb_get_options("pmagaafb", NULL))
  248. return -ENXIO;
  249. #endif
  250. return tc_register_driver(&pmagaafb_driver);
  251. }
  252. static void __exit pmagaafb_exit(void)
  253. {
  254. tc_unregister_driver(&pmagaafb_driver);
  255. }
  256. module_init(pmagaafb_init);
  257. module_exit(pmagaafb_exit);
  258. MODULE_AUTHOR(DRIVER_AUTHOR);
  259. MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
  260. MODULE_LICENSE("GPL");