pmag-ba-fb.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 Maciej W. Rozycki
  19. *
  20. * This file is subject to the terms and conditions of the GNU General
  21. * Public License. See the file COPYING in the main directory of this
  22. * archive for more details.
  23. */
  24. #include <linux/compiler.h>
  25. #include <linux/errno.h>
  26. #include <linux/fb.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/types.h>
  31. #include <asm/bug.h>
  32. #include <asm/io.h>
  33. #include <asm/system.h>
  34. #include <asm/dec/tc.h>
  35. #include <video/pmag-ba-fb.h>
  36. struct pmagbafb_par {
  37. struct fb_info *next;
  38. volatile void __iomem *mmio;
  39. volatile u32 __iomem *dac;
  40. int slot;
  41. };
  42. static struct fb_info *root_pmagbafb_dev;
  43. static struct fb_var_screeninfo pmagbafb_defined __initdata = {
  44. .xres = 1024,
  45. .yres = 864,
  46. .xres_virtual = 1024,
  47. .yres_virtual = 864,
  48. .bits_per_pixel = 8,
  49. .red.length = 8,
  50. .green.length = 8,
  51. .blue.length = 8,
  52. .activate = FB_ACTIVATE_NOW,
  53. .height = -1,
  54. .width = -1,
  55. .accel_flags = FB_ACCEL_NONE,
  56. .pixclock = 14452,
  57. .left_margin = 116,
  58. .right_margin = 12,
  59. .upper_margin = 34,
  60. .lower_margin = 12,
  61. .hsync_len = 128,
  62. .vsync_len = 3,
  63. .sync = FB_SYNC_ON_GREEN,
  64. .vmode = FB_VMODE_NONINTERLACED,
  65. };
  66. static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
  67. .id = "PMAG-BA",
  68. .smem_len = (1024 * 1024),
  69. .type = FB_TYPE_PACKED_PIXELS,
  70. .visual = FB_VISUAL_PSEUDOCOLOR,
  71. .line_length = 1024,
  72. .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
  73. };
  74. static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
  75. {
  76. writeb(v, par->dac + reg / 4);
  77. }
  78. static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
  79. {
  80. return readb(par->dac + reg / 4);
  81. }
  82. /*
  83. * Set the palette.
  84. */
  85. static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
  86. unsigned int green, unsigned int blue,
  87. unsigned int transp, struct fb_info *info)
  88. {
  89. struct pmagbafb_par *par = info->par;
  90. BUG_ON(regno >= info->cmap.len);
  91. red >>= 8; /* The cmap fields are 16 bits */
  92. green >>= 8; /* wide, but the hardware colormap */
  93. blue >>= 8; /* registers are only 8 bits wide */
  94. mb();
  95. dac_write(par, BT459_ADDR_LO, regno);
  96. dac_write(par, BT459_ADDR_HI, 0x00);
  97. wmb();
  98. dac_write(par, BT459_CMAP, red);
  99. wmb();
  100. dac_write(par, BT459_CMAP, green);
  101. wmb();
  102. dac_write(par, BT459_CMAP, blue);
  103. return 0;
  104. }
  105. static struct fb_ops pmagbafb_ops = {
  106. .owner = THIS_MODULE,
  107. .fb_setcolreg = pmagbafb_setcolreg,
  108. .fb_fillrect = cfb_fillrect,
  109. .fb_copyarea = cfb_copyarea,
  110. .fb_imageblit = cfb_imageblit,
  111. .fb_cursor = soft_cursor,
  112. };
  113. /*
  114. * Turn the hardware cursor off.
  115. */
  116. static void __init pmagbafb_erase_cursor(struct fb_info *info)
  117. {
  118. struct pmagbafb_par *par = info->par;
  119. mb();
  120. dac_write(par, BT459_ADDR_LO, 0x00);
  121. dac_write(par, BT459_ADDR_HI, 0x03);
  122. wmb();
  123. dac_write(par, BT459_DATA, 0x00);
  124. }
  125. static int __init pmagbafb_init_one(int slot)
  126. {
  127. struct fb_info *info;
  128. struct pmagbafb_par *par;
  129. unsigned long base_addr;
  130. info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
  131. if (!info)
  132. return -ENOMEM;
  133. par = info->par;
  134. par->slot = slot;
  135. claim_tc_card(par->slot);
  136. base_addr = get_tc_base_addr(par->slot);
  137. par->next = root_pmagbafb_dev;
  138. root_pmagbafb_dev = info;
  139. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  140. goto err_alloc;
  141. info->fbops = &pmagbafb_ops;
  142. info->fix = pmagbafb_fix;
  143. info->var = pmagbafb_defined;
  144. info->flags = FBINFO_DEFAULT;
  145. /* MMIO mapping setup. */
  146. info->fix.mmio_start = base_addr;
  147. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  148. if (!par->mmio)
  149. goto err_cmap;
  150. par->dac = par->mmio + PMAG_BA_BT459;
  151. /* Frame buffer mapping setup. */
  152. info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
  153. info->screen_base = ioremap_nocache(info->fix.smem_start,
  154. info->fix.smem_len);
  155. if (!info->screen_base)
  156. goto err_mmio_map;
  157. info->screen_size = info->fix.smem_len;
  158. pmagbafb_erase_cursor(info);
  159. if (register_framebuffer(info) < 0)
  160. goto err_smem_map;
  161. pr_info("fb%d: %s frame buffer device in slot %d\n",
  162. info->node, info->fix.id, par->slot);
  163. return 0;
  164. err_smem_map:
  165. iounmap(info->screen_base);
  166. err_mmio_map:
  167. iounmap(par->mmio);
  168. err_cmap:
  169. fb_dealloc_cmap(&info->cmap);
  170. err_alloc:
  171. root_pmagbafb_dev = par->next;
  172. release_tc_card(par->slot);
  173. framebuffer_release(info);
  174. return -ENXIO;
  175. }
  176. static void __exit pmagbafb_exit_one(void)
  177. {
  178. struct fb_info *info = root_pmagbafb_dev;
  179. struct pmagbafb_par *par = info->par;
  180. unregister_framebuffer(info);
  181. iounmap(info->screen_base);
  182. iounmap(par->mmio);
  183. fb_dealloc_cmap(&info->cmap);
  184. root_pmagbafb_dev = par->next;
  185. release_tc_card(par->slot);
  186. framebuffer_release(info);
  187. }
  188. /*
  189. * Initialise the framebuffer.
  190. */
  191. static int __init pmagbafb_init(void)
  192. {
  193. int count = 0;
  194. int slot;
  195. if (fb_get_options("pmagbafb", NULL))
  196. return -ENXIO;
  197. while ((slot = search_tc_card("PMAG-BA")) >= 0) {
  198. if (pmagbafb_init_one(slot) < 0)
  199. break;
  200. count++;
  201. }
  202. return (count > 0) ? 0 : -ENXIO;
  203. }
  204. static void __exit pmagbafb_exit(void)
  205. {
  206. while (root_pmagbafb_dev)
  207. pmagbafb_exit_one();
  208. }
  209. module_init(pmagbafb_init);
  210. module_exit(pmagbafb_exit);
  211. MODULE_LICENSE("GPL");