g364fb.c 6.2 KB

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