1*9af887f0Smrg /* $NetBSD: igsfbvar.h,v 1.20 2011/07/26 08:59:37 mrg Exp $ */
2782296b5Suwe
3782296b5Suwe /*
42866542aSuwe * Copyright (c) 2002, 2003 Valeriy E. Ushakov
5782296b5Suwe * All rights reserved.
6782296b5Suwe *
7782296b5Suwe * Redistribution and use in source and binary forms, with or without
8782296b5Suwe * modification, are permitted provided that the following conditions
9782296b5Suwe * are met:
10782296b5Suwe * 1. Redistributions of source code must retain the above copyright
11782296b5Suwe * notice, this list of conditions and the following disclaimer.
12782296b5Suwe * 2. Redistributions in binary form must reproduce the above copyright
13782296b5Suwe * notice, this list of conditions and the following disclaimer in the
14782296b5Suwe * documentation and/or other materials provided with the distribution.
15782296b5Suwe * 3. The name of the author may not be used to endorse or promote products
16782296b5Suwe * derived from this software without specific prior written permission
17782296b5Suwe *
18782296b5Suwe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19782296b5Suwe * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20782296b5Suwe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21782296b5Suwe * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22782296b5Suwe * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23782296b5Suwe * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24782296b5Suwe * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25782296b5Suwe * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26782296b5Suwe * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27782296b5Suwe * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28782296b5Suwe */
29782296b5Suwe
30782296b5Suwe /*
31fee27e72Suwe * Integraphics Systems IGA 168x and CyberPro series.
32782296b5Suwe */
33782296b5Suwe #ifndef _DEV_IC_IGSFBVAR_H_
34782296b5Suwe #define _DEV_IC_IGSFBVAR_H_
35782296b5Suwe
36d0b2c368Smacallan #include <dev/videomode/videomode.h>
37d0b2c368Smacallan
38782296b5Suwe #define IGS_CMAP_SIZE 256 /* 256 R/G/B entries */
39782296b5Suwe struct igs_hwcmap {
40520a24eaSuwe uint8_t r[IGS_CMAP_SIZE];
41520a24eaSuwe uint8_t g[IGS_CMAP_SIZE];
42520a24eaSuwe uint8_t b[IGS_CMAP_SIZE];
43782296b5Suwe };
44782296b5Suwe
45782296b5Suwe
46782296b5Suwe #define IGS_CURSOR_MAX_SIZE 64 /* 64x64 sprite */
47782296b5Suwe struct igs_hwcursor {
48782296b5Suwe struct wsdisplay_curpos cc_pos;
49782296b5Suwe struct wsdisplay_curpos cc_hot;
50782296b5Suwe struct wsdisplay_curpos cc_size;
51520a24eaSuwe uint8_t cc_image[512]; /* save copy of image for GCURSOR */
52520a24eaSuwe uint8_t cc_mask[512]; /* save copy of mask for GCURSOR */
53520a24eaSuwe uint16_t cc_sprite[512]; /* sprite in device 2bpp format */
54520a24eaSuwe uint8_t cc_color[6]; /* 2 colors, 3 rgb components */
55782296b5Suwe };
56782296b5Suwe
57782296b5Suwe
582866542aSuwe struct igsfb_devconfig {
592866542aSuwe /* io space, may be memory mapped */
602866542aSuwe bus_space_tag_t dc_iot;
612866542aSuwe bus_addr_t dc_iobase;
622866542aSuwe int dc_ioflags;
63782296b5Suwe
64782296b5Suwe /* io registers */
652866542aSuwe bus_space_handle_t dc_ioh;
66782296b5Suwe
6797e817d0Suwe /* graphic coprocessor */
6897e817d0Suwe bus_space_handle_t dc_coph;
6997e817d0Suwe
70782296b5Suwe /* linear memory */
712866542aSuwe bus_space_tag_t dc_memt;
722866542aSuwe bus_addr_t dc_memaddr;
732866542aSuwe bus_size_t dc_memsz; /* size of linear address space including mmio */
742866542aSuwe int dc_memflags;
75782296b5Suwe
7697e817d0Suwe /* video memory size */
772866542aSuwe bus_size_t dc_vmemsz;
78fee27e72Suwe
792866542aSuwe /* resolution */
800eaa91efSuwe int dc_width, dc_height, dc_depth, dc_stride;
8191061211Smacallan int dc_maxdepth;
8291061211Smacallan const struct videomode *dc_mode;
83782296b5Suwe
84d0b2c368Smacallan char dc_modestring[128];
85d0b2c368Smacallan
862866542aSuwe /* part of video memory mapped for wsscreen */
872866542aSuwe bus_space_handle_t dc_fbh;
882866542aSuwe bus_size_t dc_fbsz;
89782296b5Suwe
902866542aSuwe /* 1KB of cursor sprite data */
912866542aSuwe bus_space_handle_t dc_crh;
922866542aSuwe
932866542aSuwe /* product id: IGA 168x, CyberPro 2k &c */
942866542aSuwe int dc_id;
95782296b5Suwe
96782296b5Suwe /* flags that control driver operation */
972866542aSuwe int dc_hwflags;
98fee27e72Suwe #define IGSFB_HW_BSWAP 0x1 /* endianness mismatch */
992866542aSuwe #define IGSFB_HW_BE_SELECT 0x2 /* big endian magic (cyberpro) */
100a3e1bfb0Suwe #define IGSFB_HW_TEXT_CURSOR 0x4 /* do text cursor in hardware */
101782296b5Suwe
1022866542aSuwe /* do we need to do bswap in software? */
1032866542aSuwe #define IGSFB_HW_SOFT_BSWAP(dc) \
1042866542aSuwe ((((dc)->dc_hwflags) & (IGSFB_HW_BSWAP | IGSFB_HW_BE_SELECT)) \
1052866542aSuwe == IGSFB_HW_BSWAP)
106782296b5Suwe
107a3e1bfb0Suwe int dc_blanked; /* screen is currently blanked */
108a3e1bfb0Suwe int dc_curenb; /* cursor sprite enabled */
109a3e1bfb0Suwe int dc_mapped; /* currently in mapped mode */
110a3e1bfb0Suwe
11197e817d0Suwe /* saved dc_ri.ri_ops.putchar */
11297e817d0Suwe void (*dc_ri_putchar)(void *, int, int, u_int, long);
11397e817d0Suwe
114293ac096Smacallan /* optional MD mmap() method */
115293ac096Smacallan paddr_t (*dc_mmap)(void *, void *, off_t, int);
116293ac096Smacallan
1172866542aSuwe struct igs_hwcmap dc_cmap; /* software copy of colormap */
1182866542aSuwe struct igs_hwcursor dc_cursor; /* software copy of cursor sprite */
119782296b5Suwe
1206311425dSuwe /* precomputed bit table for cursor sprite 1bpp -> 2bpp conversion */
121520a24eaSuwe uint16_t dc_bexpand[256];
12231038cb7Smacallan
12331038cb7Smacallan /* virtual console support */
12431038cb7Smacallan struct vcons_data dc_vd;
12531038cb7Smacallan struct vcons_screen dc_console;
126782296b5Suwe };
127782296b5Suwe
128fee27e72Suwe
1292866542aSuwe struct igsfb_softc {
130*9af887f0Smrg device_t sc_dev;
1312866542aSuwe struct igsfb_devconfig *sc_dc;
1322866542aSuwe };
1332866542aSuwe
1342866542aSuwe
1352866542aSuwe
136fee27e72Suwe /*
137fee27e72Suwe * Access sugar for indexed registers
138fee27e72Suwe */
139fee27e72Suwe
140fbae48b9Sperry static __inline uint8_t
141520a24eaSuwe igs_idx_read(bus_space_tag_t, bus_space_handle_t, u_int, uint8_t);
142fbae48b9Sperry static __inline void
143520a24eaSuwe igs_idx_write(bus_space_tag_t, bus_space_handle_t, u_int, uint8_t, uint8_t);
144fee27e72Suwe
145fbae48b9Sperry static __inline uint8_t
igs_idx_read(bus_space_tag_t t,bus_space_handle_t h,u_int idxport,uint8_t idx)146a31a2f7dSuwe igs_idx_read(bus_space_tag_t t, bus_space_handle_t h,
147a31a2f7dSuwe u_int idxport, uint8_t idx)
148fee27e72Suwe {
149fee27e72Suwe bus_space_write_1(t, h, idxport, idx);
150fee27e72Suwe return (bus_space_read_1(t, h, idxport + 1));
151fee27e72Suwe }
152fee27e72Suwe
153fbae48b9Sperry static __inline void
igs_idx_write(bus_space_tag_t t,bus_space_handle_t h,u_int idxport,uint8_t idx,uint8_t val)154a31a2f7dSuwe igs_idx_write(bus_space_tag_t t, bus_space_handle_t h,
155a31a2f7dSuwe u_int idxport, uint8_t idx, uint8_t val)
156fee27e72Suwe {
157fee27e72Suwe bus_space_write_1(t, h, idxport, idx);
158fee27e72Suwe bus_space_write_1(t, h, idxport + 1, val);
159fee27e72Suwe }
160fee27e72Suwe
161be3f67caSuwe
162be3f67caSuwe /* sugar for sequencer controller */
163be3f67caSuwe #define igs_seq_read(t,h,x) \
164be3f67caSuwe (igs_idx_read((t),(h),IGS_SEQ_IDX,(x)))
165be3f67caSuwe #define igs_seq_write(t,h,x,v) \
166be3f67caSuwe (igs_idx_write((t),(h),IGS_SEQ_IDX,(x),(v)))
167be3f67caSuwe
168be3f67caSuwe
169be3f67caSuwe /* sugar for CRT controller */
170be3f67caSuwe #define igs_crtc_read(t,h,x) \
171be3f67caSuwe (igs_idx_read((t),(h),IGS_CRTC_IDX,(x)))
172be3f67caSuwe #define igs_crtc_write(t,h,x,v) \
173be3f67caSuwe (igs_idx_write((t),(h),IGS_CRTC_IDX,(x),(v)))
174be3f67caSuwe
175be3f67caSuwe
176be3f67caSuwe /* sugar for attribute controller */
177be3f67caSuwe #define igs_attr_flip_flop(t,h) \
178be3f67caSuwe ((void)bus_space_read_1((t),(h),IGS_INPUT_STATUS1));
179be3f67caSuwe #define igs_attr_read(t,h,x) \
180be3f67caSuwe (igs_idx_read((t),(h),IGS_ATTR_IDX,(x)))
181be3f67caSuwe
182fbae48b9Sperry static __inline void
183520a24eaSuwe igs_attr_write(bus_space_tag_t, bus_space_handle_t, uint8_t, uint8_t);
184be3f67caSuwe
185fbae48b9Sperry static __inline void
igs_attr_write(bus_space_tag_t t,bus_space_handle_t h,uint8_t idx,uint8_t val)186a31a2f7dSuwe igs_attr_write(bus_space_tag_t t, bus_space_handle_t h,
187a31a2f7dSuwe uint8_t idx, uint8_t val)
188be3f67caSuwe {
189be3f67caSuwe bus_space_write_1(t, h, IGS_ATTR_IDX, idx);
190be3f67caSuwe bus_space_write_1(t, h, IGS_ATTR_IDX, val); /* sic, same register */
191be3f67caSuwe }
192be3f67caSuwe
193be3f67caSuwe
194be3f67caSuwe /* sugar for graphics controller registers */
195be3f67caSuwe #define igs_grfx_read(t,h,x) (igs_idx_read((t),(h),IGS_GRFX_IDX,(x)))
196be3f67caSuwe #define igs_grfx_write(t,h,x,v) (igs_idx_write((t),(h),IGS_GRFX_IDX,(x),(v)))
197be3f67caSuwe
198be3f67caSuwe
199be3f67caSuwe /* sugar for extended registers */
200fee27e72Suwe #define igs_ext_read(t,h,x) (igs_idx_read((t),(h),IGS_EXT_IDX,(x)))
201fee27e72Suwe #define igs_ext_write(t,h,x,v) (igs_idx_write((t),(h),IGS_EXT_IDX,(x),(v)))
202782296b5Suwe
203782296b5Suwe
204be3f67caSuwe /* igsfb_subr.c */
2052866542aSuwe int igsfb_enable(bus_space_tag_t, bus_addr_t, int);
2062866542aSuwe void igsfb_hw_setup(struct igsfb_devconfig *);
2072866542aSuwe void igsfb_1024x768_8bpp_60Hz(struct igsfb_devconfig *);
208d0b2c368Smacallan void igsfb_set_mode(struct igsfb_devconfig *, const struct videomode *, int);
209be3f67caSuwe
210be3f67caSuwe /* igsfb.c */
2112866542aSuwe int igsfb_cnattach_subr(struct igsfb_devconfig *);
2122866542aSuwe void igsfb_attach_subr(struct igsfb_softc *, int);
2132866542aSuwe
2142866542aSuwe
2152866542aSuwe extern struct igsfb_devconfig igsfb_console_dc;
216782296b5Suwe
217782296b5Suwe #endif /* _DEV_IC_IGSFBVAR_H_ */
218