pmag-ba-fb.c 5.6 KB

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