g364fb.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* $Id: g364fb.c,v 1.3 1998/08/28 22:43:00 tsbogend Exp $
  2. *
  3. * linux/drivers/video/g364fb.c -- Mips Magnum frame buffer device
  4. *
  5. * (C) 1998 Thomas Bogendoerfer
  6. *
  7. * This driver is based on tgafb.c
  8. *
  9. * Copyright (C) 1997 Geert Uytterhoeven
  10. * Copyright (C) 1995 Jay Estabrook
  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/console.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/string.h>
  22. #include <linux/mm.h>
  23. #include <linux/tty.h>
  24. #include <linux/slab.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/delay.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/fb.h>
  29. #include <linux/init.h>
  30. #include <linux/pci.h>
  31. #include <asm/io.h>
  32. #include <asm/jazz.h>
  33. /*
  34. * Various defines for the G364
  35. */
  36. #define G364_MEM_BASE 0xe4400000
  37. #define G364_PORT_BASE 0xe4000000
  38. #define ID_REG 0xe4000000 /* Read only */
  39. #define BOOT_REG 0xe4080000
  40. #define TIMING_REG 0xe4080108 /* to 0x080170 - DON'T TOUCH! */
  41. #define DISPLAY_REG 0xe4080118
  42. #define VDISPLAY_REG 0xe4080150
  43. #define MASK_REG 0xe4080200
  44. #define CTLA_REG 0xe4080300
  45. #define CURS_TOGGLE 0x800000
  46. #define BIT_PER_PIX 0x700000 /* bits 22 to 20 of Control A */
  47. #define DELAY_SAMPLE 0x080000
  48. #define PORT_INTER 0x040000
  49. #define PIX_PIPE_DEL 0x030000 /* bits 17 and 16 of Control A */
  50. #define PIX_PIPE_DEL2 0x008000 /* same as above - don't ask me why */
  51. #define TR_CYCLE_TOG 0x004000
  52. #define VRAM_ADR_INC 0x003000 /* bits 13 and 12 of Control A */
  53. #define BLANK_OFF 0x000800
  54. #define FORCE_BLANK 0x000400
  55. #define BLK_FUN_SWTCH 0x000200
  56. #define BLANK_IO 0x000100
  57. #define BLANK_LEVEL 0x000080
  58. #define A_VID_FORM 0x000040
  59. #define D_SYNC_FORM 0x000020
  60. #define FRAME_FLY_PAT 0x000010
  61. #define OP_MODE 0x000008
  62. #define INTL_STAND 0x000004
  63. #define SCRN_FORM 0x000002
  64. #define ENABLE_VTG 0x000001
  65. #define TOP_REG 0xe4080400
  66. #define CURS_PAL_REG 0xe4080508 /* to 0x080518 */
  67. #define CHKSUM_REG 0xe4080600 /* to 0x080610 - unused */
  68. #define CURS_POS_REG 0xe4080638
  69. #define CLR_PAL_REG 0xe4080800 /* to 0x080ff8 */
  70. #define CURS_PAT_REG 0xe4081000 /* to 0x081ff8 */
  71. #define MON_ID_REG 0xe4100000 /* unused */
  72. #define RESET_REG 0xe4180000 /* Write only */
  73. static struct fb_info fb_info;
  74. static struct fb_fix_screeninfo fb_fix __initdata = {
  75. .id = "G364 8plane",
  76. .smem_start = 0x40000000, /* physical address */
  77. .type = FB_TYPE_PACKED_PIXELS,
  78. .visual = FB_VISUAL_PSEUDOCOLOR,
  79. .ypanstep = 1,
  80. .accel = FB_ACCEL_NONE,
  81. };
  82. static struct fb_var_screeninfo fb_var __initdata = {
  83. .bits_per_pixel = 8,
  84. .red = { 0, 8, 0 },
  85. .green = { 0, 8, 0 },
  86. .blue = { 0, 8, 0 },
  87. .activate = FB_ACTIVATE_NOW,
  88. .height = -1,
  89. .width = -1,
  90. .pixclock = 39722,
  91. .left_margin = 40,
  92. .right_margin = 24,
  93. .upper_margin = 32,
  94. .lower_margin = 11,
  95. .hsync_len = 96,
  96. .vsync_len = 2,
  97. .vmode = FB_VMODE_NONINTERLACED,
  98. };
  99. /*
  100. * Interface used by the world
  101. */
  102. int g364fb_init(void);
  103. static int g364fb_pan_display(struct fb_var_screeninfo *var,
  104. struct fb_info *info);
  105. static int g364fb_setcolreg(u_int regno, u_int red, u_int green,
  106. u_int blue, u_int transp,
  107. struct fb_info *info);
  108. static int g364fb_cursor(struct fb_info *info, struct fb_cursor *cursor);
  109. static int g364fb_blank(int blank, struct fb_info *info);
  110. static struct fb_ops g364fb_ops = {
  111. .owner = THIS_MODULE,
  112. .fb_setcolreg = g364fb_setcolreg,
  113. .fb_pan_display = g364fb_pan_display,
  114. .fb_blank = g364fb_blank,
  115. .fb_fillrect = cfb_fillrect,
  116. .fb_copyarea = cfb_copyarea,
  117. .fb_imageblit = cfb_imageblit,
  118. .fb_cursor = g364fb_cursor,
  119. };
  120. int g364fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  121. {
  122. switch (cursor->enable) {
  123. case CM_ERASE:
  124. *(unsigned int *) CTLA_REG |= CURS_TOGGLE;
  125. break;
  126. case CM_MOVE:
  127. case CM_DRAW:
  128. *(unsigned int *) CTLA_REG &= ~CURS_TOGGLE;
  129. *(unsigned int *) CURS_POS_REG =
  130. ((x * fontwidth(p)) << 12) | ((y * fontheight(p)) -
  131. info->var.yoffset);
  132. break;
  133. }
  134. return 0;
  135. }
  136. /*
  137. * Pan or Wrap the Display
  138. *
  139. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  140. */
  141. static int g364fb_pan_display(struct fb_var_screeninfo *var,
  142. struct fb_info *info)
  143. {
  144. if (var->xoffset || var->yoffset + var->yres > var->yres_virtual)
  145. return -EINVAL;
  146. *(unsigned int *) TOP_REG = var->yoffset * var->xres;
  147. return 0;
  148. }
  149. /*
  150. * Blank the display.
  151. */
  152. static int g364fb_blank(int blank, struct fb_info *info)
  153. {
  154. if (blank)
  155. *(unsigned int *) CTLA_REG |= FORCE_BLANK;
  156. else
  157. *(unsigned int *) CTLA_REG &= ~FORCE_BLANK;
  158. return 0;
  159. }
  160. /*
  161. * Set a single color register. Return != 0 for invalid regno.
  162. */
  163. static int g364fb_setcolreg(u_int regno, u_int red, u_int green,
  164. u_int blue, u_int transp, struct fb_info *info)
  165. {
  166. volatile unsigned int *ptr = (volatile unsigned int *) CLR_PAL_REG;
  167. if (regno > 255)
  168. return 1;
  169. red >>= 8;
  170. green >>= 8;
  171. blue >>= 8;
  172. ptr[regno << 1] = (red << 16) | (green << 8) | blue;
  173. return 0;
  174. }
  175. /*
  176. * Initialisation
  177. */
  178. int __init g364fb_init(void)
  179. {
  180. volatile unsigned int *pal_ptr =
  181. (volatile unsigned int *) CLR_PAL_REG;
  182. volatile unsigned int *curs_pal_ptr =
  183. (volatile unsigned int *) CURS_PAL_REG;
  184. int mem, i, j;
  185. if (fb_get_options("g364fb", NULL))
  186. return -ENODEV;
  187. /* TBD: G364 detection */
  188. /* get the resolution set by ARC console */
  189. *(volatile unsigned int *) CTLA_REG &= ~ENABLE_VTG;
  190. fb_var.xres =
  191. (*((volatile unsigned int *) DISPLAY_REG) & 0x00ffffff) * 4;
  192. fb_var.yres =
  193. (*((volatile unsigned int *) VDISPLAY_REG) & 0x00ffffff) / 2;
  194. *(volatile unsigned int *) CTLA_REG |= ENABLE_VTG;
  195. /* setup cursor */
  196. curs_pal_ptr[0] |= 0x00ffffff;
  197. curs_pal_ptr[2] |= 0x00ffffff;
  198. curs_pal_ptr[4] |= 0x00ffffff;
  199. /*
  200. * first set the whole cursor to transparent
  201. */
  202. for (i = 0; i < 512; i++)
  203. *(unsigned short *) (CURS_PAT_REG + i * 8) = 0;
  204. /*
  205. * switch the last two lines to cursor palette 3
  206. * we assume here, that FONTSIZE_X is 8
  207. */
  208. *(unsigned short *) (CURS_PAT_REG + 14 * 64) = 0xffff;
  209. *(unsigned short *) (CURS_PAT_REG + 15 * 64) = 0xffff;
  210. fb_var.xres_virtual = fbvar.xres;
  211. fb_fix.line_length = (xres / 8) * fb_var.bits_per_pixel;
  212. fb_fix.smem_start = 0x40000000; /* physical address */
  213. /* get size of video memory; this is special for the JAZZ hardware */
  214. mem = (r4030_read_reg32(JAZZ_R4030_CONFIG) >> 8) & 3;
  215. fb_fix.smem_len = (1 << (mem * 2)) * 512 * 1024;
  216. fb_var.yres_virtual = fb_fix.smem_len / fb_var.xres;
  217. fb_info.fbops = &g364fb_ops;
  218. fb_info.screen_base = (char *) G364_MEM_BASE; /* virtual kernel address */
  219. fb_info.var = fb_var;
  220. fb_info.fix = fb_fix;
  221. fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  222. fb_alloc_cmap(&fb_info.cmap, 255, 0);
  223. if (register_framebuffer(&fb_info) < 0)
  224. return -EINVAL;
  225. return 0;
  226. }
  227. module_init(g364fb_init);
  228. MODULE_LICENSE("GPL");