Import 2.1.34
[davej-history.git] / drivers / sbus / char / bwtwo.c
blob91d77ad785f1bf6e7f17c7b6bbd6d5e57541dc00
1 /* $Id: bwtwo.c,v 1.12 1997/04/10 03:02:40 davem Exp $
2 * bwtwo.c: bwtwo console driver
4 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
5 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
6 */
8 #include <linux/kd.h>
9 #include <linux/tty.h>
10 #include <linux/malloc.h>
11 #include <linux/proc_fs.h>
13 #include <asm/sbus.h>
14 #include <asm/io.h>
15 #include <asm/fbio.h>
16 #include <asm/pgtable.h>
18 #include"../../char/vt_kern.h"
19 #include"../../char/selection.h"
20 #include"../../char/console_struct.h"
21 #include"fb.h"
22 #include"cg_common.h"
24 /* OBio addresses for the bwtwo registers */
25 #define BWTWO_REGISTER_OFFSET 0x400000
27 struct bwtwo_regs {
28 __volatile__ struct bt_regs bt;
29 __volatile__ __u8 control;
30 __volatile__ __u8 status;
31 __volatile__ __u8 cursor_start;
32 __volatile__ __u8 cursor_end;
33 __volatile__ __u8 h_blank_start;
34 __volatile__ __u8 h_blank_end;
35 __volatile__ __u8 h_sync_start;
36 __volatile__ __u8 h_sync_end;
37 __volatile__ __u8 comp_sync_end;
38 __volatile__ __u8 v_blank_start_high;
39 __volatile__ __u8 v_blank_start_low;
40 __volatile__ __u8 v_blank_end;
41 __volatile__ __u8 v_sync_start;
42 __volatile__ __u8 v_sync_end;
43 __volatile__ __u8 xfer_holdoff_start;
44 __volatile__ __u8 xfer_holdoff_end;
47 /* Status Register Constants */
48 #define BWTWO_SR_RES_MASK 0x70
49 #define BWTWO_SR_1600_1280 0x50
50 #define BWTWO_SR_1152_900_76_A 0x40
51 #define BWTWO_SR_1152_900_76_B 0x60
52 #define BWTWO_SR_ID_MASK 0x0f
53 #define BWTWO_SR_ID_MONO 0x02
54 #define BWTWO_SR_ID_MONO_ECL 0x03
55 #define BWTWO_SR_ID_MSYNC 0x04
57 /* Control Register Constants */
58 #define BWTWO_CTL_ENABLE_INTS 0x80
59 #define BWTWO_CTL_ENABLE_VIDEO 0x40
60 #define BWTWO_CTL_ENABLE_TIMING 0x20
61 #define BWTWO_CTL_ENABLE_CURCMP 0x10
62 #define BWTWO_CTL_XTAL_MASK 0x0C
63 #define BWTWO_CTL_DIVISOR_MASK 0x03
65 /* Status Register Constants */
66 #define BWTWO_STAT_PENDING_INT 0x80
67 #define BWTWO_STAT_MSENSE_MASK 0x70
68 #define BWTWO_STAT_ID_MASK 0x0f
71 static int
72 bwtwo_mmap(struct inode *inode,struct file *file,struct vm_area_struct *vma,
73 long base, fbinfo_t *fb)
75 uint size, map_offset, r;
76 int map_size;
78 map_size = size = vma->vm_end - vma->vm_start;
80 if(vma->vm_offset & ~PAGE_MASK)
81 return-ENXIO;
83 /* To stop the swapper from even considering these pages */
84 vma->vm_flags |= FB_MMAP_VM_FLAGS;
86 /* This routine should also map the register if asked for,
87 * but we don't do that yet.
89 map_offset =get_phys((uint) fb->base);
90 r =io_remap_page_range(vma->vm_start, map_offset, map_size,
91 vma->vm_page_prot, fb->space);
92 if(r)return-EAGAIN;
93 vma->vm_inode = inode;
94 inode->i_count++;
95 return0;
98 static void
99 bwtwo_blank(fbinfo_t *fb)
101 fb->info.bwtwo.regs->control &= ~BWTWO_CTL_ENABLE_VIDEO;
104 static void
105 bwtwo_unblank(fbinfo_t *fb)
107 fb->info.bwtwo.regs->control |= BWTWO_CTL_ENABLE_VIDEO;
111 static u8 bw2regs_1600[] __initdata = {
112 0x14,0x8b,0x15,0x28,0x16,0x03,0x17,0x13,
113 0x18,0x7b,0x19,0x05,0x1a,0x34,0x1b,0x2e,
114 0x1c,0x00,0x1d,0x0a,0x1e,0xff,0x1f,0x01,
115 0x10,0x21,0
118 static u8 bw2regs_ecl[] __initdata = {
119 0x14,0x65,0x15,0x1e,0x16,0x04,0x17,0x0c,
120 0x18,0x5e,0x19,0x03,0x1a,0xa7,0x1b,0x23,
121 0x1c,0x00,0x1d,0x08,0x1e,0xff,0x1f,0x01,
122 0x10,0x20,0
125 static u8 bw2regs_analog[] __initdata = {
126 0x14,0xbb,0x15,0x2b,0x16,0x03,0x17,0x13,
127 0x18,0xb0,0x19,0x03,0x1a,0xa6,0x1b,0x22,
128 0x1c,0x01,0x1d,0x05,0x1e,0xff,0x1f,0x01,
129 0x10,0x20,0
132 static u8 bw2regs_76hz[] __initdata = {
133 0x14,0xb7,0x15,0x27,0x16,0x03,0x17,0x0f,
134 0x18,0xae,0x19,0x03,0x1a,0xae,0x1b,0x2a,
135 0x1c,0x01,0x1d,0x09,0x1e,0xff,0x1f,0x01,
136 0x10,0x24,0
139 static u8 bw2regs_66hz[] __initdata = {
140 0x14,0xbb,0x15,0x2b,0x16,0x04,0x17,0x14,
141 0x18,0xae,0x19,0x03,0x1a,0xa8,0x1b,0x24,
142 0x1c,0x01,0x1d,0x05,0x1e,0xff,0x1f,0x01,
143 0x10,0x20,0
146 __initfunc(voidbwtwo_setup(fbinfo_t *fb,int slot,unsigned long bwtwo,int bw2_io,
147 struct linux_sbus_device *sbdp))
149 printk("bwtwo%d at 0x%8.8x\n", slot, (uint)bwtwo);
150 fb->type.fb_cmsize =0;
151 fb->mmap = bwtwo_mmap;
152 fb->loadcmap =0;
153 fb->ioctl =0;
154 fb->reset =0;
155 fb->blank = bwtwo_blank;
156 fb->unblank = bwtwo_unblank;
158 fb->info.bwtwo.regs =
159 sparc_alloc_io((u32)(bwtwo + BWTWO_REGISTER_OFFSET),
160 0,sizeof(struct bwtwo_regs),
161 "bwtwo_regs", bw2_io,0);
163 if(!prom_getbool(sbdp->prom_node,"width")) {
164 /* Ugh, broken PROM didn't initialize us.
165 * Let's deal with this ourselves.
167 u8 status, mon;
168 u8 *p;
170 status = fb->info.bwtwo.regs->status;
171 mon = status & BWTWO_SR_RES_MASK;
172 switch(status & BWTWO_SR_ID_MASK) {
173 case BWTWO_SR_ID_MONO_ECL:
174 if(mon == BWTWO_SR_1600_1280) {
175 p = bw2regs_1600;
176 fb->type.fb_width =1600;
177 fb->type.fb_height =1280;
178 }else{
179 p = bw2regs_ecl;
181 break;
182 case BWTWO_SR_ID_MONO:
183 p = bw2regs_analog;
184 break;
185 case BWTWO_SR_ID_MSYNC:
186 if(mon == BWTWO_SR_1152_900_76_A ||
187 mon == BWTWO_SR_1152_900_76_B) {
188 p = bw2regs_76hz;
189 }else{
190 p = bw2regs_66hz;
192 break;
193 default:
194 prom_printf("bwtwo: can't handle SR %02x\n",
195 status);
196 prom_halt();
197 return;/* fool gcc. */
199 for( ; *p; p +=2)
200 ((u8 *)fb->info.bwtwo.regs)[p[0]] = p[1];
203 if(!fb->base)
204 fb->base = (unsigned long)sparc_alloc_io((u32)bwtwo,0,
205 ((fb->type.fb_depth*fb->type.fb_height*fb->type.fb_width)/8),
206 "bwtwo_fbase", bw2_io,0);
208 if(slot && sun_prom_console_id != slot)
209 bwtwo_blank(fb);
close