summaryrefslogtreecommitdiff
path: root/chips/ims332.c
blob: ebe6a6cbf651e422cf3d4f492521ceb59f1f093f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* 
 * Mach Operating System
 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
 * All Rights Reserved.
 * 
 * Permission to use, copy, modify and distribute this software and its
 * documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 * 
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 * 
 * Carnegie Mellon requests users of this software to return to
 * 
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 * 
 * any improvements or extensions that they make and grant Carnegie Mellon
 * the rights to redistribute these changes.
 */
/*
 *	File: ims332.c
 * 	Author: Alessandro Forin, Carnegie Mellon University
 *	Date:	1/92
 *
 *	Routines for the Inmos IMS-G332 Colour video controller
 */

#include <platforms.h>

#include <chips/ims332.h>
#include <chips/screen.h>

#include <chips/xcfb_monitor.h>

/*
 * Generic register access
 */
typedef volatile unsigned char *ims332_padded_regmap_t;

#ifdef	MAXINE

unsigned int
ims332_read_register(regs, regno)
	unsigned char	*regs;
{
	unsigned char		*rptr;
	register unsigned int	val, v1;

	/* spec sez: */
	rptr = regs + 0x80000 + (regno << 4);
	val = * ((volatile unsigned short *) rptr );
	v1  = * ((volatile unsigned short *) regs );

	return (val & 0xffff) | ((v1 & 0xff00) << 8);
}

ims332_write_register(regs, regno, val)
	unsigned char		*regs;
	register unsigned int	val;
{
	unsigned char		*wptr;

	/* spec sez: */
	wptr = regs + 0xa0000 + (regno << 4);
	* ((volatile unsigned int *)(regs))   = (val >> 8) & 0xff00;
	* ((volatile unsigned short *)(wptr)) = val;
}

#define	assert_ims332_reset_bit(r)	*r &= ~0x40
#define	deassert_ims332_reset_bit(r)	*r |=  0x40

#else	/*MAXINE*/

#define	ims332_read_register(p,r)			\
		((unsigned int *)(p)) [ (r) ]
#define	ims332_write_register(p,r,v)			\
		((unsigned int *)(p)) [ (r) ] = (v)

#endif	/*MAXINE*/


/*
 * Color map
 */
ims332_load_colormap( regs, map)
	ims332_padded_regmap_t	*regs;
	color_map_t	*map;
{
	register int    i;

	for (i = 0; i < 256; i++, map++)
		ims332_load_colormap_entry(regs, i, map);
}

ims332_load_colormap_entry( regs, entry, map)
	ims332_padded_regmap_t	*regs;
	color_map_t	*map;
{
	/* ?? stop VTG */
	ims332_write_register(regs, IMS332_REG_LUT_BASE + (entry & 0xff),
			      (map->blue << 16) |
			      (map->green << 8) |
			      (map->red));
}

ims332_init_colormap( regs)
	ims332_padded_regmap_t	*regs;
{
	color_map_t		m;

	m.red = m.green = m.blue = 0;
	ims332_load_colormap_entry( regs, 0, &m);

	m.red = m.green = m.blue = 0xff;
	ims332_load_colormap_entry( regs, 1, &m);
	ims332_load_colormap_entry( regs, 255, &m);

	/* since we are at it, also fix cursor LUT */
	ims332_load_colormap_entry( regs, IMS332_REG_CURSOR_LUT_0, &m);
	ims332_load_colormap_entry( regs, IMS332_REG_CURSOR_LUT_1, &m);
	/* *we* do not use this, but the prom does */
	ims332_load_colormap_entry( regs, IMS332_REG_CURSOR_LUT_2, &m);
}

#if	1/*debug*/
ims332_print_colormap( regs)
	ims332_padded_regmap_t	*regs;
{
	register int    i;

	for (i = 0; i < 256; i++) {
		register unsigned int	color;

		color = ims332_read_register( regs, IMS332_REG_LUT_BASE + i);
		printf("%x->[x%x x%x x%x]\n", i,
			(color >> 16) & 0xff,
			(color >> 8) & 0xff,
			color & 0xff);
	}
}
#endif

/*
 * Video on/off
 *
 * It is unfortunate that X11 goes backward with white@0
 * and black@1.  So we must stash away the zero-th entry
 * and fix it while screen is off.  Also must remember
 * it, sigh.
 */
struct vstate {
	ims332_padded_regmap_t	*regs;
	unsigned short	off;
};

ims332_video_off(vstate, up)
	struct vstate	*vstate;
	user_info_t	*up;
{
	register ims332_padded_regmap_t	*regs = vstate->regs;
	register unsigned		*save, csr;

	if (vstate->off)
		return;

	/* Yes, this is awful */
	save = (unsigned *)up->dev_dep_2.gx.colormap;

	*save = ims332_read_register(regs, IMS332_REG_LUT_BASE);

	ims332_write_register(regs, IMS332_REG_LUT_BASE, 0);

	ims332_write_register( regs, IMS332_REG_COLOR_MASK, 0);

	/* cursor now */
	csr = ims332_read_register(regs, IMS332_REG_CSR_A);
	csr |= IMS332_CSR_A_DISABLE_CURSOR;
	ims332_write_register(regs, IMS332_REG_CSR_A, csr);

	vstate->off = 1;
}

ims332_video_on(vstate, up)
	struct vstate	*vstate;
	user_info_t	*up;
{
	register ims332_padded_regmap_t	*regs = vstate->regs;
	register unsigned		*save, csr;

	if (!vstate->off)
		return;

	/* Like I said.. */
	save = (unsigned *)up->dev_dep_2.gx.colormap;

	ims332_write_register(regs, IMS332_REG_LUT_BASE, *save);

	ims332_write_register( regs, IMS332_REG_COLOR_MASK, 0xffffffff);

	/* cursor now */
	csr = ims332_read_register(regs, IMS332_REG_CSR_A);
	csr &= ~IMS332_CSR_A_DISABLE_CURSOR;
	ims332_write_register(regs, IMS332_REG_CSR_A, csr);

	vstate->off = 0;
}

/*
 * Cursor
 */
ims332_pos_cursor(regs,x,y)
	ims332_padded_regmap_t	*regs;
	register int	x,y;
{
	ims332_write_register( regs, IMS332_REG_CURSOR_LOC,
		((x & 0xfff) << 12) | (y & 0xfff) );
}


ims332_cursor_color( regs, color)
	ims332_padded_regmap_t	*regs;
	color_map_t	*color;
{
	/* Bg is color[0], Fg is color[1] */
	ims332_write_register(regs, IMS332_REG_CURSOR_LUT_0,
			      (color->blue << 16) |
			      (color->green << 8) |
			      (color->red));
	color++;
	ims332_write_register(regs, IMS332_REG_CURSOR_LUT_1,
			      (color->blue << 16) |
			      (color->green << 8) |
			      (color->red));
}

ims332_cursor_sprite( regs, cursor)
	ims332_padded_regmap_t	*regs;
	unsigned short		*cursor;
{
	register int i;

	/* We *could* cut this down a lot... */
	for (i = 0; i < 512; i++, cursor++)
		ims332_write_register( regs,
			IMS332_REG_CURSOR_RAM+i, *cursor);
}

/*
 * Initialization
 */
ims332_init(regs, reset, mon)
	ims332_padded_regmap_t	*regs;
	unsigned int		*reset;
	xcfb_monitor_type_t	mon;
{
	int shortdisplay, broadpulse, frontporch;

	assert_ims332_reset_bit(reset);
	delay(1);	/* specs sez 50ns.. */
	deassert_ims332_reset_bit(reset);

	/* CLOCKIN appears to receive a 6.25 Mhz clock --> PLL 12 for 75Mhz monitor */
	ims332_write_register(regs, IMS332_REG_BOOT, 12 | IMS332_BOOT_CLOCK_PLL);

	/* initialize VTG */
	ims332_write_register(regs, IMS332_REG_CSR_A,
				IMS332_BPP_8 | IMS332_CSR_A_DISABLE_CURSOR);
	delay(50);	/* spec does not say */

	/* datapath registers (values taken from prom's settings) */

	frontporch = mon->line_time - (mon->half_sync * 2 +
				       mon->back_porch +
				       mon->frame_visible_width / 4);

	shortdisplay = mon->line_time / 2 - (mon->half_sync * 2 +
					     mon->back_porch + frontporch);
	broadpulse = mon->line_time / 2 - frontporch;

	ims332_write_register( regs, IMS332_REG_HALF_SYNCH,     mon->half_sync);
	ims332_write_register( regs, IMS332_REG_BACK_PORCH,     mon->back_porch);
	ims332_write_register( regs, IMS332_REG_DISPLAY,
			      mon->frame_visible_width / 4);
	ims332_write_register( regs, IMS332_REG_SHORT_DIS,	shortdisplay);
	ims332_write_register( regs, IMS332_REG_BROAD_PULSE,	broadpulse);
	ims332_write_register( regs, IMS332_REG_V_SYNC,		mon->v_sync * 2);
	ims332_write_register( regs, IMS332_REG_V_PRE_EQUALIZE,
			      mon->v_pre_equalize);
	ims332_write_register( regs, IMS332_REG_V_POST_EQUALIZE,
			      mon->v_post_equalize);
	ims332_write_register( regs, IMS332_REG_V_BLANK,	mon->v_blank * 2);
	ims332_write_register( regs, IMS332_REG_V_DISPLAY,
			      mon->frame_visible_height * 2);
	ims332_write_register( regs, IMS332_REG_LINE_TIME,	mon->line_time);
	ims332_write_register( regs, IMS332_REG_LINE_START,	mon->line_start);
	ims332_write_register( regs, IMS332_REG_MEM_INIT, 	mon->mem_init);
	ims332_write_register( regs, IMS332_REG_XFER_DELAY,	mon->xfer_delay);

	ims332_write_register( regs, IMS332_REG_COLOR_MASK, 0xffffff);

	ims332_init_colormap( regs );

	ims332_write_register(regs, IMS332_REG_CSR_A,
		IMS332_BPP_8 | IMS332_CSR_A_DMA_DISABLE | IMS332_CSR_A_VTG_ENABLE);

}