pmag-ba-fb.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * linux/drivers/video/pmag-ba-fb.c
  3. *
  4. * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
  5. * derived from:
  6. * "HP300 Topcat framebuffer support (derived from macfb of all things)
  7. * Phil Blundell <philb@gnu.org> 1998", the original code can be
  8. * found in the file hpfb.c in the same directory.
  9. *
  10. * Based on digital document:
  11. * "PMAG-BA TURBOchannel Color Frame Buffer
  12. * Functional Specification", Revision 1.2, August 27, 1990
  13. *
  14. * DECstation related code Copyright (C) 1999, 2000, 2001 by
  15. * Michael Engel <engel@unix-ag.org>,
  16. * Karsten Merker <merker@linuxtag.org> and
  17. * Harald Koerfgen.
  18. * Copyright (c) 2005, 2006 Maciej W. Rozycki
  19. * Copyright (c) 2005 James Simmons
  20. *
  21. * This file is subject to the terms and conditions of the GNU General
  22. * Public License. See the file COPYING in the main directory of this
  23. * archive for more details.
  24. */
  25. #include <linux/compiler.h>
  26. #include <linux/errno.h>
  27. #include <linux/fb.h>
  28. #include <linux/init.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/tc.h>
  32. #include <linux/types.h>
  33. #include <asm/io.h>
  34. #include <video/pmag-ba-fb.h>
  35. struct pmagbafb_par {
  36. volatile void __iomem *mmio;
  37. volatile u32 __iomem *dac;
  38. };
  39. static struct fb_var_screeninfo pmagbafb_defined = {
  40. .xres = 1024,
  41. .yres = 864,
  42. .xres_virtual = 1024,
  43. .yres_virtual = 864,
  44. .bits_per_pixel = 8,
  45. .red.length = 8,
  46. .green.length = 8,
  47. .blue.length = 8,
  48. .activate = FB_ACTIVATE_NOW,
  49. .height = -1,
  50. .width = -1,
  51. .accel_flags = FB_ACCEL_NONE,
  52. .pixclock = 14452,
  53. .left_margin = 116,
  54. .right_margin = 12,
  55. .upper_margin = 34,
  56. .lower_margin = 12,
  57. .hsync_len = 128,
  58. .vsync_len = 3,
  59. .sync = FB_SYNC_ON_GREEN,
  60. .vmode = FB_VMODE_NONINTERLACED,
  61. };
  62. static struct fb_fix_screeninfo pmagbafb_fix = {
  63. .id = "PMAG-BA",
  64. .smem_len = (1024 * 1024),
  65. .type = FB_TYPE_PACKED_PIXELS,
  66. .visual = FB_VISUAL_PSEUDOCOLOR,
  67. .line_length = 1024,
  68. .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
  69. };
  70. static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
  71. {
  72. writeb(v, par->dac + reg / 4);
  73. }
  74. static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
  75. {
  76. return readb(par->dac + reg / 4);
  77. }
  78. /*
  79. * Set the palette.
  80. */
  81. static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
  82. unsigned int green, unsigned int blue,
  83. unsigned int transp, struct fb_info *info)
  84. {
  85. struct pmagbafb_par *par = info->par;
  86. if (regno >= info->cmap.len)
  87. return 1;
  88. red >>= 8; /* The cmap fields are 16 bits */
  89. green >>= 8; /* wide, but the hardware colormap */
  90. blue >>= 8; /* registers are only 8 bits wide */
  91. mb();
  92. dac_write(par, BT459_ADDR_LO, regno);
  93. dac_write(par, BT459_ADDR_HI, 0x00);
  94. wmb();
  95. dac_write(par, BT459_CMAP, red);
  96. wmb();
  97. dac_write(par, BT459_CMAP, green);
  98. wmb();
  99. dac_write(par, BT459_CMAP, blue);
  100. return 0;
  101. }
  102. static struct fb_ops pmagbafb_ops = {
  103. .owner = THIS_MODULE,
  104. .fb_setcolreg = pmagbafb_setcolreg,
  105. .fb_fillrect = cfb_fillrect,
  106. .fb_copyarea = cfb_copyarea,
  107. .fb_imageblit = cfb_imageblit,
  108. };
  109. /*
  110. * Turn the hardware cursor off.
  111. */
  112. static void __init pmagbafb_erase_cursor(struct fb_info *info)
  113. {
  114. struct pmagbafb_par *par = info->par;
  115. mb();
  116. dac_write(par, BT459_ADDR_LO, 0x00);
  117. dac_write(par, BT459_ADDR_HI, 0x03);
  118. wmb();
  119. dac_write(par, BT459_DATA, 0x00);
  120. }
  121. static int pmagbafb_probe(struct device *dev)
  122. {
  123. struct tc_dev *tdev = to_tc_dev(dev);
  124. resource_size_t start, len;
  125. struct fb_info *info;
  126. struct pmagbafb_par *par;
  127. int err;
  128. info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
  129. if (!info) {
  130. printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
  131. return -ENOMEM;
  132. }
  133. par = info->par;
  134. dev_set_drvdata(dev, info);
  135. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  136. printk(KERN_ERR "%s: Cannot allocate color map\n",
  137. dev_name(dev));
  138. err = -ENOMEM;
  139. goto err_alloc;
  140. }
  141. info->fbops = &pmagbafb_ops;
  142. info->fix = pmagbafb_fix;
  143. info->var = pmagbafb_defined;
  144. info->flags = FBINFO_DEFAULT;
  145. /* Request the I/O MEM resource. */
  146. start = tdev->resource.start;
  147. len = tdev->resource.end - start + 1;
  148. if (!request_mem_region(start, len, dev_name(dev))) {
  149. printk(KERN_ERR "%s: Cannot reserve FB region\n",
  150. dev_name(dev));
  151. err = -EBUSY;
  152. goto err_cmap;
  153. }
  154. /* MMIO mapping setup. */
  155. info->fix.mmio_start = start;
  156. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  157. if (!par->mmio) {
  158. printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
  159. err = -ENOMEM;
  160. goto err_resource;
  161. }
  162. par->dac = par->mmio + PMAG_BA_BT459;
  163. /* Frame buffer mapping setup. */
  164. info->fix.smem_start = start + PMAG_BA_FBMEM;
  165. info->screen_base = ioremap_nocache(info->fix.smem_start,
  166. info->fix.smem_len);
  167. if (!info->screen_base) {
  168. printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
  169. err = -ENOMEM;
  170. goto err_mmio_map;
  171. }
  172. info->screen_size = info->fix.smem_len;
  173. pmagbafb_erase_cursor(info);
  174. err = register_framebuffer(info);
  175. if (err < 0) {
  176. printk(KERN_ERR "%s: Cannot register framebuffer\n",
  177. dev_name(dev));
  178. goto err_smem_map;
  179. }
  180. get_device(dev);
  181. fb_info(info, "%s frame buffer device at %s\n",
  182. info->fix.id, dev_name(dev));
  183. return 0;
  184. err_smem_map:
  185. iounmap(info->screen_base);
  186. err_mmio_map:
  187. iounmap(par->mmio);
  188. err_resource:
  189. release_mem_region(start, len);
  190. err_cmap:
  191. fb_dealloc_cmap(&info->cmap);
  192. err_alloc:
  193. framebuffer_release(info);
  194. return err;
  195. }
  196. static int __exit pmagbafb_remove(struct device *dev)
  197. {
  198. struct tc_dev *tdev = to_tc_dev(dev);
  199. struct fb_info *info = dev_get_drvdata(dev);
  200. struct pmagbafb_par *par = info->par;
  201. resource_size_t start, len;
  202. put_device(dev);
  203. unregister_framebuffer(info);
  204. iounmap(info->screen_base);
  205. iounmap(par->mmio);
  206. start = tdev->resource.start;
  207. len = tdev->resource.end - start + 1;
  208. release_mem_region(start, len);
  209. fb_dealloc_cmap(&info->cmap);
  210. framebuffer_release(info);
  211. return 0;
  212. }
  213. /*
  214. * Initialize the framebuffer.
  215. */
  216. static const struct tc_device_id pmagbafb_tc_table[] = {
  217. { "DEC ", "PMAG-BA " },
  218. { }
  219. };
  220. MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
  221. static struct tc_driver pmagbafb_driver = {
  222. .id_table = pmagbafb_tc_table,
  223. .driver = {
  224. .name = "pmagbafb",
  225. .bus = &tc_bus_type,
  226. .probe = pmagbafb_probe,
  227. .remove = __exit_p(pmagbafb_remove),
  228. },
  229. };
  230. static int __init pmagbafb_init(void)
  231. {
  232. #ifndef MODULE
  233. if (fb_get_options("pmagbafb", NULL))
  234. return -ENXIO;
  235. #endif
  236. return tc_register_driver(&pmagbafb_driver);
  237. }
  238. static void __exit pmagbafb_exit(void)
  239. {
  240. tc_unregister_driver(&pmagbafb_driver);
  241. }
  242. module_init(pmagbafb_init);
  243. module_exit(pmagbafb_exit);
  244. MODULE_LICENSE("GPL");