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