xref: /netbsd-src/sys/arch/arc/jazz/pccons_jazzio.c (revision f3b496ec9be495acbb17756f05d342b6b7b495e9)
1 /* $NetBSD: pccons_jazzio.c,v 1.7 2005/11/15 12:12:21 tsutsui Exp $ */
2 /* NetBSD: vga_isa.c,v 1.4 2000/08/14 20:14:51 thorpej Exp  */
3 
4 /*
5  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
6  * All rights reserved.
7  *
8  * Author: Chris G. Demetriou
9  *
10  * Permission to use, copy, modify and distribute this software and
11  * its documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: pccons_jazzio.c,v 1.7 2005/11/15 12:12:21 tsutsui Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37 #include <uvm/uvm_extern.h>
38 
39 #include <machine/autoconf.h>
40 #include <machine/bus.h>
41 #include <machine/wired_map.h>
42 
43 #include <mips/pte.h>
44 
45 #include <arc/dev/pcconsvar.h>
46 #include <arc/jazz/jazziovar.h>
47 #include <arc/jazz/pica.h>
48 #include <arc/jazz/pccons_jazziovar.h>
49 
50 #define PCKBD_INTR 6	/* XXX - should be obtained from firmware */
51 
52 int	pccons_jazzio_match(struct device *, struct cfdata *, void *);
53 void	pccons_jazzio_attach(struct device *, struct device *, void *);
54 
55 CFATTACH_DECL(pc_jazzio, sizeof(struct pc_softc),
56     pccons_jazzio_match, pccons_jazzio_attach, NULL, NULL);
57 
58 /*
59  * chipset-dependent pccons configuration
60  */
61 
62 void pccons_jazzio_init(void);
63 
64 struct pccons_config pccons_jazzio_conf = {
65 	0x3b4, 0xb0000,	/* mono: iobase, memaddr */
66 	0x3d4, 0xb8000,	/* cga:  iobase, memaddr */
67 	PICA_SYS_KBD + 0x61, PICA_SYS_KBD + 0x60, /* kbdc: cmdport, dataport */
68 	pccons_jazzio_init
69 };
70 
71 void
72 pccons_jazzio_init(void)
73 {
74 
75 	/* nothing to do */
76 }
77 
78 int	pccons_jazzio_init_tag(const char *, bus_space_tag_t*,bus_space_tag_t*);
79 
80 int
81 pccons_jazzio_init_tag(const char *name, bus_space_tag_t *iotp,
82     bus_space_tag_t *memtp)
83 {
84 	static int initialized = 0;
85 	static struct arc_bus_space vga_io, vga_mem;
86 
87 	if (strcmp(name, "ALI_S3") != 0)
88 		return ENXIO;
89 
90 	if (!initialized) {
91 		initialized = 1;
92 
93 		arc_bus_space_init(&vga_io, "vga_jazzio_io",
94 		    PICA_P_LOCAL_VIDEO_CTRL, PICA_V_LOCAL_VIDEO_CTRL,
95 		    0, PICA_S_LOCAL_VIDEO_CTRL);
96 		arc_bus_space_init(&vga_mem, "vga_jazzio_mem",
97 		    PICA_P_LOCAL_VIDEO, PICA_V_LOCAL_VIDEO,
98 		    0, PICA_S_LOCAL_VIDEO);
99 
100 		arc_wired_enter_page(
101 		    PICA_V_LOCAL_VIDEO_CTRL,
102 		    PICA_P_LOCAL_VIDEO_CTRL,
103 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
104 		arc_wired_enter_page(
105 		    PICA_V_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL / 2,
106 		    PICA_P_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL / 2,
107 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
108 
109 		arc_wired_enter_page(PICA_V_LOCAL_VIDEO,
110 		    PICA_P_LOCAL_VIDEO,
111 		    PICA_S_LOCAL_VIDEO / 2);
112 		arc_wired_enter_page(
113 		    PICA_V_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
114 		    PICA_P_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
115 		    PICA_S_LOCAL_VIDEO / 2);
116 #if 0
117 		arc_wired_enter_page(PICA_V_EXTND_VIDEO_CTRL,
118 		    PICA_P_EXTND_VIDEO_CTRL,
119 		    PICA_S_EXTND_VIDEO_CTRL / 2);
120 		arc_wired_enter_page(
121 		    PICA_V_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
122 		    PICA_P_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
123 		    PICA_S_EXTND_VIDEO_CTRL / 2);
124 #endif
125 	}
126 	*iotp = &vga_io;
127 	*memtp = &vga_mem;
128 	return 0;
129 }
130 
131 int
132 pccons_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
133 {
134 	struct jazzio_attach_args *ja = aux;
135 	bus_space_tag_t crt_iot, crt_memt;
136 
137 	if (pccons_jazzio_init_tag(ja->ja_name, &crt_iot, &crt_memt))
138 		return 0;
139 
140 	if (!pccons_common_match(crt_iot, crt_memt, ja->ja_bust,
141 	    &pccons_jazzio_conf))
142 		return 0;
143 
144 	return 1;
145 }
146 
147 void
148 pccons_jazzio_attach(struct device *parent, struct device *self, void *aux)
149 {
150 	struct pc_softc *sc = (struct pc_softc *)self;
151 	struct jazzio_attach_args *ja = aux;
152 	bus_space_tag_t crt_iot, crt_memt;
153 
154 	pccons_jazzio_init_tag(ja->ja_name, &crt_iot, &crt_memt);
155 	jazzio_intr_establish(PCKBD_INTR, pcintr, self);
156 	pccons_common_attach(sc, crt_iot, crt_memt, ja->ja_bust,
157 	    &pccons_jazzio_conf);
158 }
159 
160 int
161 pccons_jazzio_cnattach(char *name, bus_space_tag_t kbd_iot)
162 {
163 	bus_space_tag_t crt_iot, crt_memt;
164 
165 	if (pccons_jazzio_init_tag(name, &crt_iot, &crt_memt))
166 		return ENXIO;
167 	pccons_common_cnattach(crt_iot, crt_memt, kbd_iot,
168 	    &pccons_jazzio_conf);
169 	return 0;
170 }
171