pmag-ba-fb.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 __initdata = {
  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 __initdata = {
  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. BUG_ON(regno >= info->cmap.len);
  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 __init 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. info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
  128. if (!info)
  129. return -ENOMEM;
  130. par = info->par;
  131. dev_set_drvdata(dev, info);
  132. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  133. goto err_alloc;
  134. info->fbops = &pmagbafb_ops;
  135. info->fix = pmagbafb_fix;
  136. info->var = pmagbafb_defined;
  137. info->flags = FBINFO_DEFAULT;
  138. /* Request the I/O MEM resource. */
  139. start = tdev->resource.start;
  140. len = tdev->resource.end - start + 1;
  141. if (!request_mem_region(start, len, dev->bus_id))
  142. goto err_cmap;
  143. /* MMIO mapping setup. */
  144. info->fix.mmio_start = start;
  145. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  146. if (!par->mmio)
  147. goto err_resource;
  148. par->dac = par->mmio + PMAG_BA_BT459;
  149. /* Frame buffer mapping setup. */
  150. info->fix.smem_start = start + PMAG_BA_FBMEM;
  151. info->screen_base = ioremap_nocache(info->fix.smem_start,
  152. info->fix.smem_len);
  153. if (!info->screen_base)
  154. goto err_mmio_map;
  155. info->screen_size = info->fix.smem_len;
  156. pmagbafb_erase_cursor(info);
  157. if (register_framebuffer(info) < 0)
  158. goto err_smem_map;
  159. get_device(dev);
  160. pr_info("fb%d: %s frame buffer device at %s\n",
  161. info->node, info->fix.id, dev->bus_id);
  162. return 0;
  163. err_smem_map:
  164. iounmap(info->screen_base);
  165. err_mmio_map:
  166. iounmap(par->mmio);
  167. err_resource:
  168. release_mem_region(start, len);
  169. err_cmap:
  170. fb_dealloc_cmap(&info->cmap);
  171. err_alloc:
  172. framebuffer_release(info);
  173. return -ENXIO;
  174. }
  175. static int __exit pmagbafb_remove(struct device *dev)
  176. {
  177. struct tc_dev *tdev = to_tc_dev(dev);
  178. struct fb_info *info = dev_get_drvdata(dev);
  179. struct pmagbafb_par *par = info->par;
  180. resource_size_t start, len;
  181. put_device(dev);
  182. unregister_framebuffer(info);
  183. iounmap(info->screen_base);
  184. iounmap(par->mmio);
  185. start = tdev->resource.start;
  186. len = tdev->resource.end - start + 1;
  187. release_mem_region(start, len);
  188. fb_dealloc_cmap(&info->cmap);
  189. framebuffer_release(info);
  190. return 0;
  191. }
  192. /*
  193. * Initialize the framebuffer.
  194. */
  195. static const struct tc_device_id pmagbafb_tc_table[] = {
  196. { "DEC ", "PMAG-BA " },
  197. { }
  198. };
  199. MODULE_DEVICE_TABLE(tc, pmagbafb_tc_table);
  200. static struct tc_driver pmagbafb_driver = {
  201. .id_table = pmagbafb_tc_table,
  202. .driver = {
  203. .name = "pmagbafb",
  204. .bus = &tc_bus_type,
  205. .probe = pmagbafb_probe,
  206. .remove = __exit_p(pmagbafb_remove),
  207. },
  208. };
  209. static int __init pmagbafb_init(void)
  210. {
  211. #ifndef MODULE
  212. if (fb_get_options("pmagbafb", NULL))
  213. return -ENXIO;
  214. #endif
  215. return tc_register_driver(&pmagbafb_driver);
  216. }
  217. static void __exit pmagbafb_exit(void)
  218. {
  219. tc_unregister_driver(&pmagbafb_driver);
  220. }
  221. module_init(pmagbafb_init);
  222. module_exit(pmagbafb_exit);
  223. MODULE_LICENSE("GPL");