pmag-aa-fb.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 const 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 const 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 const struct fb_ops aafb_ops = {
  131. .owner = THIS_MODULE,
  132. FB_DEFAULT_IOMEM_OPS,
  133. .fb_blank = aafb_blank,
  134. .fb_cursor = aafb_cursor,
  135. };
  136. static int pmagaafb_probe(struct device *dev)
  137. {
  138. struct tc_dev *tdev = to_tc_dev(dev);
  139. resource_size_t start, len;
  140. struct fb_info *info;
  141. struct aafb_par *par;
  142. int err;
  143. info = framebuffer_alloc(sizeof(struct aafb_par), dev);
  144. if (!info)
  145. return -ENOMEM;
  146. par = info->par;
  147. dev_set_drvdata(dev, info);
  148. info->fbops = &aafb_ops;
  149. info->fix = aafb_fix;
  150. info->var = aafb_defined;
  151. /* Request the I/O MEM resource. */
  152. start = tdev->resource.start;
  153. len = tdev->resource.end - start + 1;
  154. if (!request_mem_region(start, len, dev_name(dev))) {
  155. printk(KERN_ERR "%s: Cannot reserve FB region\n",
  156. dev_name(dev));
  157. err = -EBUSY;
  158. goto err_alloc;
  159. }
  160. /* MMIO mapping setup. */
  161. info->fix.mmio_start = start + PMAG_AA_BT455_OFFSET;
  162. par->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  163. if (!par->mmio) {
  164. printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
  165. err = -ENOMEM;
  166. goto err_resource;
  167. }
  168. par->bt455 = par->mmio - PMAG_AA_BT455_OFFSET + PMAG_AA_BT455_OFFSET;
  169. par->bt431 = par->mmio - PMAG_AA_BT455_OFFSET + PMAG_AA_BT431_OFFSET;
  170. /* Frame buffer mapping setup. */
  171. info->fix.smem_start = start + PMAG_AA_ONBOARD_FBMEM_OFFSET;
  172. info->screen_base = ioremap(info->fix.smem_start,
  173. info->fix.smem_len);
  174. if (!info->screen_base) {
  175. printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
  176. err = -ENOMEM;
  177. goto err_mmio_map;
  178. }
  179. info->screen_size = info->fix.smem_len;
  180. /* Init colormap. */
  181. bt455_write_cmap_entry(par->bt455, 0, 0x0);
  182. bt455_write_cmap_next(par->bt455, 0xf);
  183. /* Init hardware cursor. */
  184. bt431_erase_cursor(par->bt431);
  185. bt431_init_cursor(par->bt431);
  186. err = register_framebuffer(info);
  187. if (err < 0) {
  188. printk(KERN_ERR "%s: Cannot register framebuffer\n",
  189. dev_name(dev));
  190. goto err_smem_map;
  191. }
  192. get_device(dev);
  193. pr_info("fb%d: %s frame buffer device at %s\n",
  194. info->node, info->fix.id, dev_name(dev));
  195. return 0;
  196. err_smem_map:
  197. iounmap(info->screen_base);
  198. err_mmio_map:
  199. iounmap(par->mmio);
  200. err_resource:
  201. release_mem_region(start, len);
  202. err_alloc:
  203. framebuffer_release(info);
  204. return err;
  205. }
  206. static int pmagaafb_remove(struct device *dev)
  207. {
  208. struct tc_dev *tdev = to_tc_dev(dev);
  209. struct fb_info *info = dev_get_drvdata(dev);
  210. struct aafb_par *par = info->par;
  211. resource_size_t start, len;
  212. put_device(dev);
  213. unregister_framebuffer(info);
  214. iounmap(info->screen_base);
  215. iounmap(par->mmio);
  216. start = tdev->resource.start;
  217. len = tdev->resource.end - start + 1;
  218. release_mem_region(start, len);
  219. framebuffer_release(info);
  220. return 0;
  221. }
  222. /*
  223. * Initialise the framebuffer.
  224. */
  225. static const struct tc_device_id pmagaafb_tc_table[] = {
  226. { "DEC ", "PMAG-AA " },
  227. { }
  228. };
  229. MODULE_DEVICE_TABLE(tc, pmagaafb_tc_table);
  230. static struct tc_driver pmagaafb_driver = {
  231. .id_table = pmagaafb_tc_table,
  232. .driver = {
  233. .name = "pmagaafb",
  234. .bus = &tc_bus_type,
  235. .probe = pmagaafb_probe,
  236. .remove = pmagaafb_remove,
  237. },
  238. };
  239. static int __init pmagaafb_init(void)
  240. {
  241. #ifndef MODULE
  242. if (fb_get_options("pmagaafb", NULL))
  243. return -ENXIO;
  244. #endif
  245. return tc_register_driver(&pmagaafb_driver);
  246. }
  247. static void __exit pmagaafb_exit(void)
  248. {
  249. tc_unregister_driver(&pmagaafb_driver);
  250. }
  251. module_init(pmagaafb_init);
  252. module_exit(pmagaafb_exit);
  253. MODULE_AUTHOR(DRIVER_AUTHOR);
  254. MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
  255. MODULE_LICENSE("GPL");