fm2fb.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * linux/drivers/video/fm2fb.c -- BSC FrameMaster II/Rainbow II frame buffer
  3. * device
  4. *
  5. * Copyright (C) 1998 Steffen A. Mork (linux-dev@morknet.de)
  6. * Copyright (C) 1999 Geert Uytterhoeven
  7. *
  8. * Written for 2.0.x by Steffen A. Mork
  9. * Ported to 2.1.x by Geert Uytterhoeven
  10. * Ported to new api by James Simmons
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file COPYING in the main directory of this archive for
  14. * more details.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/mm.h>
  18. #include <linux/fb.h>
  19. #include <linux/init.h>
  20. #include <linux/zorro.h>
  21. #include <asm/io.h>
  22. /*
  23. * Some technical notes:
  24. *
  25. * The BSC FrameMaster II (or Rainbow II) is a simple very dumb
  26. * frame buffer which allows to display 24 bit true color images.
  27. * Each pixel is 32 bit width so it's very easy to maintain the
  28. * frame buffer. One long word has the following layout:
  29. * AARRGGBB which means: AA the alpha channel byte, RR the red
  30. * channel, GG the green channel and BB the blue channel.
  31. *
  32. * The FrameMaster II supports the following video modes.
  33. * - PAL/NTSC
  34. * - interlaced/non interlaced
  35. * - composite sync/sync/sync over green
  36. *
  37. * The resolution is to the following both ones:
  38. * - 768x576 (PAL)
  39. * - 768x480 (NTSC)
  40. *
  41. * This means that pixel access per line is fixed due to the
  42. * fixed line width. In case of maximal resolution the frame
  43. * buffer needs an amount of memory of 1.769.472 bytes which
  44. * is near to 2 MByte (the allocated address space of Zorro2).
  45. * The memory is channel interleaved. That means every channel
  46. * owns four VRAMs. Unfortunatly most FrameMasters II are
  47. * not assembled with memory for the alpha channel. In this
  48. * case it could be possible to add the frame buffer into the
  49. * normal memory pool.
  50. *
  51. * At relative address 0x1ffff8 of the frame buffers base address
  52. * there exists a control register with the number of
  53. * four control bits. They have the following meaning:
  54. * bit value meaning
  55. *
  56. * 0 1 0=interlaced/1=non interlaced
  57. * 1 2 0=video out disabled/1=video out enabled
  58. * 2 4 0=normal mode as jumpered via JP8/1=complement mode
  59. * 3 8 0=read onboard ROM/1 normal operation (required)
  60. *
  61. * As mentioned above there are several jumper. I think there
  62. * is not very much information about the FrameMaster II in
  63. * the world so I add these information for completeness.
  64. *
  65. * JP1 interlace selection (1-2 non interlaced/2-3 interlaced)
  66. * JP2 wait state creation (leave as is!)
  67. * JP3 wait state creation (leave as is!)
  68. * JP4 modulate composite sync on green output (1-2 composite
  69. * sync on green channel/2-3 normal composite sync)
  70. * JP5 create test signal, shorting this jumper will create
  71. * a white screen
  72. * JP6 sync creation (1-2 composite sync/2-3 H-sync output)
  73. * JP8 video mode (1-2 PAL/2-3 NTSC)
  74. *
  75. * With the following jumpering table you can connect the
  76. * FrameMaster II to a normal TV via SCART connector:
  77. * JP1: 2-3
  78. * JP4: 2-3
  79. * JP6: 2-3
  80. * JP8: 1-2 (means PAL for Europe)
  81. *
  82. * NOTE:
  83. * There is no other possibility to change the video timings
  84. * except the interlaced/non interlaced, sync control and the
  85. * video mode PAL (50 Hz)/NTSC (60 Hz). Inside this
  86. * FrameMaster II driver are assumed values to avoid anomalies
  87. * to a future X server. Except the pixel clock is really
  88. * constant at 30 MHz.
  89. *
  90. * 9 pin female video connector:
  91. *
  92. * 1 analog red 0.7 Vss
  93. * 2 analog green 0.7 Vss
  94. * 3 analog blue 0.7 Vss
  95. * 4 H-sync TTL
  96. * 5 V-sync TTL
  97. * 6 ground
  98. * 7 ground
  99. * 8 ground
  100. * 9 ground
  101. *
  102. * Some performance notes:
  103. * The FrameMaster II was not designed to display a console
  104. * this driver would do! It was designed to display still true
  105. * color images. Imagine: When scroll up a text line there
  106. * must copied ca. 1.7 MBytes to another place inside this
  107. * frame buffer. This means 1.7 MByte read and 1.7 MByte write
  108. * over the slow 16 bit wide Zorro2 bus! A scroll of one
  109. * line needs 1 second so do not expect to much from this
  110. * driver - he is at the limit!
  111. *
  112. */
  113. /*
  114. * definitions
  115. */
  116. #define FRAMEMASTER_SIZE 0x200000
  117. #define FRAMEMASTER_REG 0x1ffff8
  118. #define FRAMEMASTER_NOLACE 1
  119. #define FRAMEMASTER_ENABLE 2
  120. #define FRAMEMASTER_COMPL 4
  121. #define FRAMEMASTER_ROM 8
  122. static volatile unsigned char *fm2fb_reg;
  123. static struct fb_fix_screeninfo fb_fix __devinitdata = {
  124. .smem_len = FRAMEMASTER_REG,
  125. .type = FB_TYPE_PACKED_PIXELS,
  126. .visual = FB_VISUAL_TRUECOLOR,
  127. .line_length = (768 << 2),
  128. .mmio_len = (8),
  129. .accel = FB_ACCEL_NONE,
  130. };
  131. static int fm2fb_mode __devinitdata = -1;
  132. #define FM2FB_MODE_PAL 0
  133. #define FM2FB_MODE_NTSC 1
  134. static struct fb_var_screeninfo fb_var_modes[] __devinitdata = {
  135. {
  136. /* 768 x 576, 32 bpp (PAL) */
  137. 768, 576, 768, 576, 0, 0, 32, 0,
  138. { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
  139. 0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
  140. 33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
  141. }, {
  142. /* 768 x 480, 32 bpp (NTSC - not supported yet */
  143. 768, 480, 768, 480, 0, 0, 32, 0,
  144. { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 8, 0 },
  145. 0, FB_ACTIVATE_NOW, -1, -1, FB_ACCEL_NONE,
  146. 33333, 10, 102, 10, 5, 80, 34, FB_SYNC_COMP_HIGH_ACT, 0
  147. }
  148. };
  149. /*
  150. * Interface used by the world
  151. */
  152. static int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  153. u_int transp, struct fb_info *info);
  154. static int fm2fb_blank(int blank, struct fb_info *info);
  155. static struct fb_ops fm2fb_ops = {
  156. .owner = THIS_MODULE,
  157. .fb_setcolreg = fm2fb_setcolreg,
  158. .fb_blank = fm2fb_blank,
  159. .fb_fillrect = cfb_fillrect,
  160. .fb_copyarea = cfb_copyarea,
  161. .fb_imageblit = cfb_imageblit,
  162. };
  163. /*
  164. * Blank the display.
  165. */
  166. static int fm2fb_blank(int blank, struct fb_info *info)
  167. {
  168. unsigned char t = FRAMEMASTER_ROM;
  169. if (!blank)
  170. t |= FRAMEMASTER_ENABLE | FRAMEMASTER_NOLACE;
  171. fm2fb_reg[0] = t;
  172. return 0;
  173. }
  174. /*
  175. * Set a single color register. The values supplied are already
  176. * rounded down to the hardware's capabilities (according to the
  177. * entries in the var structure). Return != 0 for invalid regno.
  178. */
  179. static int fm2fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  180. u_int transp, struct fb_info *info)
  181. {
  182. if (regno > info->cmap.len)
  183. return 1;
  184. red >>= 8;
  185. green >>= 8;
  186. blue >>= 8;
  187. ((u32*)(info->pseudo_palette))[regno] = (red << 16) | (green << 8) | blue;
  188. return 0;
  189. }
  190. /*
  191. * Initialisation
  192. */
  193. static int __devinit fm2fb_probe(struct zorro_dev *z,
  194. const struct zorro_device_id *id);
  195. static struct zorro_device_id fm2fb_devices[] __devinitdata = {
  196. { ZORRO_PROD_BSC_FRAMEMASTER_II },
  197. { ZORRO_PROD_HELFRICH_RAINBOW_II },
  198. { 0 }
  199. };
  200. static struct zorro_driver fm2fb_driver = {
  201. .name = "fm2fb",
  202. .id_table = fm2fb_devices,
  203. .probe = fm2fb_probe,
  204. };
  205. static int __devinit fm2fb_probe(struct zorro_dev *z,
  206. const struct zorro_device_id *id)
  207. {
  208. struct fb_info *info;
  209. unsigned long *ptr;
  210. int is_fm;
  211. int x, y;
  212. is_fm = z->id == ZORRO_PROD_BSC_FRAMEMASTER_II;
  213. if (!zorro_request_device(z,"fm2fb"))
  214. return -ENXIO;
  215. info = framebuffer_alloc(256 * sizeof(u32), &z->dev);
  216. if (!info) {
  217. zorro_release_device(z);
  218. return -ENOMEM;
  219. }
  220. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  221. framebuffer_release(info);
  222. zorro_release_device(z);
  223. return -ENOMEM;
  224. }
  225. /* assigning memory to kernel space */
  226. fb_fix.smem_start = zorro_resource_start(z);
  227. info->screen_base = ioremap(fb_fix.smem_start, FRAMEMASTER_SIZE);
  228. fb_fix.mmio_start = fb_fix.smem_start + FRAMEMASTER_REG;
  229. fm2fb_reg = (unsigned char *)(info->screen_base+FRAMEMASTER_REG);
  230. strcpy(fb_fix.id, is_fm ? "FrameMaster II" : "Rainbow II");
  231. /* make EBU color bars on display */
  232. ptr = (unsigned long *)fb_fix.smem_start;
  233. for (y = 0; y < 576; y++) {
  234. for (x = 0; x < 96; x++) *ptr++ = 0xffffff;/* white */
  235. for (x = 0; x < 96; x++) *ptr++ = 0xffff00;/* yellow */
  236. for (x = 0; x < 96; x++) *ptr++ = 0x00ffff;/* cyan */
  237. for (x = 0; x < 96; x++) *ptr++ = 0x00ff00;/* green */
  238. for (x = 0; x < 96; x++) *ptr++ = 0xff00ff;/* magenta */
  239. for (x = 0; x < 96; x++) *ptr++ = 0xff0000;/* red */
  240. for (x = 0; x < 96; x++) *ptr++ = 0x0000ff;/* blue */
  241. for (x = 0; x < 96; x++) *ptr++ = 0x000000;/* black */
  242. }
  243. fm2fb_blank(0, info);
  244. if (fm2fb_mode == -1)
  245. fm2fb_mode = FM2FB_MODE_PAL;
  246. info->fbops = &fm2fb_ops;
  247. info->var = fb_var_modes[fm2fb_mode];
  248. info->pseudo_palette = info->par;
  249. info->par = NULL;
  250. info->fix = fb_fix;
  251. info->flags = FBINFO_DEFAULT;
  252. if (register_framebuffer(info) < 0) {
  253. fb_dealloc_cmap(&info->cmap);
  254. iounmap(info->screen_base);
  255. framebuffer_release(info);
  256. zorro_release_device(z);
  257. return -EINVAL;
  258. }
  259. printk("fb%d: %s frame buffer device\n", info->node, fb_fix.id);
  260. return 0;
  261. }
  262. int __init fm2fb_setup(char *options)
  263. {
  264. char *this_opt;
  265. if (!options || !*options)
  266. return 0;
  267. while ((this_opt = strsep(&options, ",")) != NULL) {
  268. if (!strncmp(this_opt, "pal", 3))
  269. fm2fb_mode = FM2FB_MODE_PAL;
  270. else if (!strncmp(this_opt, "ntsc", 4))
  271. fm2fb_mode = FM2FB_MODE_NTSC;
  272. }
  273. return 0;
  274. }
  275. int __init fm2fb_init(void)
  276. {
  277. char *option = NULL;
  278. if (fb_get_options("fm2fb", &option))
  279. return -ENODEV;
  280. fm2fb_setup(option);
  281. return zorro_register_driver(&fm2fb_driver);
  282. }
  283. module_init(fm2fb_init);
  284. MODULE_LICENSE("GPL");