pmag-ba-fb.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. };
  112. /*
  113. * Turn the hardware cursor off.
  114. */
  115. static void __init pmagbafb_erase_cursor(struct fb_info *info)
  116. {
  117. struct pmagbafb_par *par = info->par;
  118. mb();
  119. dac_write(par, BT459_ADDR_LO, 0x00);
  120. dac_write(par, BT459_ADDR_HI, 0x03);
  121. wmb();
  122. dac_write(par, BT459_DATA, 0x00);
  123. }
  124. static int __init pmagbafb_init_one(int slot)
  125. {
  126. struct fb_info *info;
  127. struct pmagbafb_par *par;
  128. unsigned long base_addr;
  129. info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
  130. if (!info)
  131. return -ENOMEM;
  132. par = info->par;
  133. par->slot = slot;
  134. claim_tc_card(par->slot);
  135. base_addr = get_tc_base_addr(par->slot);
  136. par->next = root_pmagbafb_dev;
  137. root_pmagbafb_dev = info;
  138. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
  139. goto err_alloc;
  140. info->fbops = &pmagbafb_ops;
  141. info->fix = pmagbafb_fix;
  142. info->var = pmagbafb_defined;
  143. info->flags = FBINFO_DEFAULT;
  144. /* MMIO mapping setup. */
  145. info->fix.mmio_start = base_addr;
  146. par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
  147. if (!par->mmio)
  148. goto err_cmap;
  149. par->dac = par->mmio + PMAG_BA_BT459;
  150. /* Frame buffer mapping setup. */
  151. info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
  152. info->screen_base = ioremap_nocache(info->fix.smem_start,
  153. info->fix.smem_len);
  154. if (!info->screen_base)
  155. goto err_mmio_map;
  156. info->screen_size = info->fix.smem_len;
  157. pmagbafb_erase_cursor(info);
  158. if (register_framebuffer(info) < 0)
  159. goto err_smem_map;
  160. pr_info("fb%d: %s frame buffer device in slot %d\n",
  161. info->node, info->fix.id, par->slot);
  162. return 0;
  163. err_smem_map:
  164. iounmap(info->screen_base);
  165. err_mmio_map:
  166. iounmap(par->mmio);
  167. err_cmap:
  168. fb_dealloc_cmap(&info->cmap);
  169. err_alloc:
  170. root_pmagbafb_dev = par->next;
  171. release_tc_card(par->slot);
  172. framebuffer_release(info);
  173. return -ENXIO;
  174. }
  175. static void __exit pmagbafb_exit_one(void)
  176. {
  177. struct fb_info *info = root_pmagbafb_dev;
  178. struct pmagbafb_par *par = info->par;
  179. unregister_framebuffer(info);
  180. iounmap(info->screen_base);
  181. iounmap(par->mmio);
  182. fb_dealloc_cmap(&info->cmap);
  183. root_pmagbafb_dev = par->next;
  184. release_tc_card(par->slot);
  185. framebuffer_release(info);
  186. }
  187. /*
  188. * Initialise the framebuffer.
  189. */
  190. static int __init pmagbafb_init(void)
  191. {
  192. int count = 0;
  193. int slot;
  194. if (fb_get_options("pmagbafb", NULL))
  195. return -ENXIO;
  196. while ((slot = search_tc_card("PMAG-BA")) >= 0) {
  197. if (pmagbafb_init_one(slot) < 0)
  198. break;
  199. count++;
  200. }
  201. return (count > 0) ? 0 : -ENXIO;
  202. }
  203. static void __exit pmagbafb_exit(void)
  204. {
  205. while (root_pmagbafb_dev)
  206. pmagbafb_exit_one();
  207. }
  208. module_init(pmagbafb_init);
  209. module_exit(pmagbafb_exit);
  210. MODULE_LICENSE("GPL");