pmag-ba-fb.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 <asm/system.h>
  35. #include <video/pmag-ba-fb.h>
  36. struct pmagbafb_par {
  37. volatile void __iomem *mmio;
  38. volatile u32 __iomem *dac;
  39. };
  40. static struct fb_var_screeninfo pmagbafb_defined __devinitdata = {
  41. .xres = 1024,
  42. .yres = 864,
  43. .xres_virtual = 1024,
  44. .yres_virtual = 864,
  45. .bits_per_pixel = 8,
  46. .red.length = 8,
  47. .green.length = 8,
  48. .blue.length = 8,
  49. .activate = FB_ACTIVATE_NOW,
  50. .height = -1,
  51. .width = -1,
  52. .accel_flags = FB_ACCEL_NONE,
  53. .pixclock = 14452,
  54. .left_margin = 116,
  55. .right_margin = 12,
  56. .upper_margin = 34,
  57. .lower_margin = 12,
  58. .hsync_len = 128,
  59. .vsync_len = 3,
  60. .sync = FB_SYNC_ON_GREEN,
  61. .vmode = FB_VMODE_NONINTERLACED,
  62. };
  63. static struct fb_fix_screeninfo pmagbafb_fix __devinitdata = {
  64. .id = "PMAG-BA",
  65. .smem_len = (1024 * 1024),
  66. .type = FB_TYPE_PACKED_PIXELS,
  67. .visual = FB_VISUAL_PSEUDOCOLOR,
  68. .line_length = 1024,
  69. .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
  70. };
  71. static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
  72. {
  73. writeb(v, par->dac + reg / 4);
  74. }
  75. static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
  76. {
  77. return readb(par->dac + reg / 4);
  78. }
  79. /*
  80. * Set the palette.
  81. */
  82. static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
  83. unsigned int green, unsigned int blue,
  84. unsigned int transp, struct fb_info *info)
  85. {
  86. struct pmagbafb_par *par = info->par;
  87. if (regno >= info->cmap.len)
  88. return 1;
  89. red >>= 8; /* The cmap fields are 16 bits */
  90. green >>= 8; /* wide, but the hardware colormap */
  91. blue >>= 8; /* registers are only 8 bits wide */
  92. mb();
  93. dac_write(par, BT459_ADDR_LO, regno);
  94. dac_write(par, BT459_ADDR_HI, 0x00);
  95. wmb();
  96. dac_write(par, BT459_CMAP, red);
  97. wmb();
  98. dac_write(par, BT459_CMAP, green);
  99. wmb();
  100. dac_write(par, BT459_CMAP, blue);
  101. return 0;
  102. }
  103. static struct fb_ops pmagbafb_ops = {
  104. .owner = THIS_MODULE,
  105. .fb_setcolreg = pmagbafb_setcolreg,
  106. .fb_fillrect = cfb_fillrect,
  107. .fb_copyarea = cfb_copyarea,
  108. .fb_imageblit = cfb_imageblit,
  109. };
  110. /*
  111. * Turn the hardware cursor off.
  112. */
  113. static void __init pmagbafb_erase_cursor(struct fb_info *info)
  114. {
  115. struct pmagbafb_par *par = info->par;
  116. mb();
  117. dac_write(par, BT459_ADDR_LO, 0x00);
  118. dac_write(par, BT459_ADDR_HI, 0x03);
  119. wmb();
  120. dac_write(par, BT459_DATA, 0x00);
  121. }
  122. static int __devinit pmagbafb_probe(struct device *dev)
  123. {
  124. struct tc_dev *tdev = to_tc_dev(dev);
  125. resource_size_t start, len;
  126. struct fb_info *info;
  127. struct pmagbafb_par *par;
  128. int err;
  129. info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
  130. if (!info) {
  131. printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
  132. return -ENOMEM;
  133. }
  134. par = info->par;
  135. dev_set_drvdata(dev, info);
  136. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  137. printk(KERN_ERR "%s: Cannot allocate color map\n",
  138. dev_name(dev));
  139. err = -ENOMEM;
  140. goto err_alloc;
  141. }
  142. info->fbops = &pmagbafb_ops;
  143. info->fix = pmagbafb_fix;
  144. info->var = pmagbafb_defined;
  145. info->flags = FBINFO_DEFAULT;
  146. /* Request the I/O MEM resource. */
  147. start = tdev->resource.start;
  148. len = tdev->resource.end - start + 1;
  149. if (!request_mem_region(start, len, dev_name(dev))) {
  150. printk(KERN_ERR "%s: Cannot reserve FB region\n",
  151. dev_name(dev));
  152. err = -EBUSY;
  153. goto err_cmap;
  154. }
  155. /* MMIO mapping setup. */
  156. info->fix.mmio_start = start;
  157. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  158. if (!par->mmio) {
  159. printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
  160. err = -ENOMEM;
  161. goto err_resource;
  162. }
  163. par->dac = par->mmio + PMAG_BA_BT459;
  164. /* Frame buffer mapping setup. */
  165. info->fix.smem_start = start + PMAG_BA_FBMEM;
  166. info->screen_base = ioremap_nocache(info->fix.smem_start,
  167. info->fix.smem_len);
  168. if (!info->screen_base) {
  169. printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
  170. err = -ENOMEM;
  171. goto err_mmio_map;
  172. }
  173. info->screen_size = info->fix.smem_len;
  174. pmagbafb_erase_cursor(info);
  175. err = register_framebuffer(info);
  176. if (err < 0) {
  177. printk(KERN_ERR "%s: Cannot register framebuffer\n",
  178. dev_name(dev));
  179. goto err_smem_map;
  180. }
  181. get_device(dev);
  182. pr_info("fb%d: %s frame buffer device at %s\n",
  183. info->node, info->fix.id, dev_name(dev));
  184. return 0;
  185. err_smem_map:
  186. iounmap(info->screen_base);
  187. err_mmio_map:
  188. iounmap(par->mmio);
  189. err_resource:
  190. release_mem_region(start, len);
  191. err_cmap:
  192. fb_dealloc_cmap(&info->cmap);
  193. err_alloc:
  194. framebuffer_release(info);
  195. return err;
  196. }
  197. static int __exit pmagbafb_remove(struct device *dev)
  198. {
  199. struct tc_dev *tdev = to_tc_dev(dev);
  200. struct fb_info *info = dev_get_drvdata(dev);
  201. struct pmagbafb_par *par = info->par;
  202. resource_size_t start, len;
  203. put_device(dev);
  204. unregister_framebuffer(info);
  205. iounmap(info->screen_base);
  206. iounmap(par->mmio);
  207. start = tdev->resource.start;
  208. len = tdev->resource.end - start + 1;
  209. release_mem_region(start, len);
  210. fb_dealloc_cmap(&info->cmap);
  211. framebuffer_release(info);
  212. return 0;
  213. }
  214. /*
  215. * Initialize the framebuffer.
  216. */
  217. static const struct tc_device_id pmagbafb_tc_table[] = {
  218. { "DEC ", "PMAG-BA " },
  219. { }
  220. };
  221. MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
  222. static struct tc_driver pmagbafb_driver = {
  223. .id_table = pmagbafb_tc_table,
  224. .driver = {
  225. .name = "pmagbafb",
  226. .bus = &tc_bus_type,
  227. .probe = pmagbafb_probe,
  228. .remove = __exit_p(pmagbafb_remove),
  229. },
  230. };
  231. static int __init pmagbafb_init(void)
  232. {
  233. #ifndef MODULE
  234. if (fb_get_options("pmagbafb", NULL))
  235. return -ENXIO;
  236. #endif
  237. return tc_register_driver(&pmagbafb_driver);
  238. }
  239. static void __exit pmagbafb_exit(void)
  240. {
  241. tc_unregister_driver(&pmagbafb_driver);
  242. }
  243. module_init(pmagbafb_init);
  244. module_exit(pmagbafb_exit);
  245. MODULE_LICENSE("GPL");