xref: /netbsd-src/sys/arch/arc/jazz/pccons_jazzio.c (revision cf10107d5d3746e98e37d403b996f1965f67f255)
1 /* $NetBSD: pccons_jazzio.c,v 1.11 2011/07/01 19:25:42 dyoung 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.11 2011/07/01 19:25:42 dyoung 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 <sys/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 static int	pccons_jazzio_match(device_t, cfdata_t, void *);
53 static void	pccons_jazzio_attach(device_t, device_t, void *);
54 
55 CFATTACH_DECL_NEW(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 static 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 static void
pccons_jazzio_init(void)72 pccons_jazzio_init(void)
73 {
74 
75 	/* nothing to do */
76 }
77 
78 static int pccons_jazzio_init_tag(const char *, bus_space_tag_t *,
79     bus_space_tag_t *);
80 
81 int
pccons_jazzio_init_tag(const char * name,bus_space_tag_t * iotp,bus_space_tag_t * memtp)82 pccons_jazzio_init_tag(const char *name, bus_space_tag_t *iotp,
83     bus_space_tag_t *memtp)
84 {
85 	static int initialized = 0;
86 	static struct arc_bus_space vga_io, vga_mem;
87 
88 	if (strcmp(name, "ALI_S3") != 0)
89 		return ENXIO;
90 
91 	if (!initialized) {
92 		initialized = 1;
93 
94 		arc_bus_space_init(&vga_io, "vga_jazzio_io",
95 		    PICA_P_LOCAL_VIDEO_CTRL, PICA_V_LOCAL_VIDEO_CTRL,
96 		    0, PICA_S_LOCAL_VIDEO_CTRL);
97 		arc_bus_space_init(&vga_mem, "vga_jazzio_mem",
98 		    PICA_P_LOCAL_VIDEO, PICA_V_LOCAL_VIDEO,
99 		    0, PICA_S_LOCAL_VIDEO);
100 
101 		arc_wired_enter_page(
102 		    PICA_V_LOCAL_VIDEO_CTRL,
103 		    PICA_P_LOCAL_VIDEO_CTRL,
104 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
105 		arc_wired_enter_page(
106 		    PICA_V_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL / 2,
107 		    PICA_P_LOCAL_VIDEO_CTRL + PICA_S_LOCAL_VIDEO_CTRL / 2,
108 		    PICA_S_LOCAL_VIDEO_CTRL / 2);
109 
110 		arc_wired_enter_page(PICA_V_LOCAL_VIDEO,
111 		    PICA_P_LOCAL_VIDEO,
112 		    PICA_S_LOCAL_VIDEO / 2);
113 		arc_wired_enter_page(
114 		    PICA_V_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
115 		    PICA_P_LOCAL_VIDEO + PICA_S_LOCAL_VIDEO / 2,
116 		    PICA_S_LOCAL_VIDEO / 2);
117 #if 0
118 		arc_wired_enter_page(PICA_V_EXTND_VIDEO_CTRL,
119 		    PICA_P_EXTND_VIDEO_CTRL,
120 		    PICA_S_EXTND_VIDEO_CTRL / 2);
121 		arc_wired_enter_page(
122 		    PICA_V_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
123 		    PICA_P_EXTND_VIDEO_CTRL + PICA_S_EXTND_VIDEO_CTRL / 2,
124 		    PICA_S_EXTND_VIDEO_CTRL / 2);
125 #endif
126 	}
127 	*iotp = &vga_io;
128 	*memtp = &vga_mem;
129 	return 0;
130 }
131 
132 static int
pccons_jazzio_match(device_t parent,cfdata_t cf,void * aux)133 pccons_jazzio_match(device_t parent, cfdata_t cf, void *aux)
134 {
135 	struct jazzio_attach_args *ja = aux;
136 	bus_space_tag_t crt_iot, crt_memt;
137 
138 	if (pccons_jazzio_init_tag(ja->ja_name, &crt_iot, &crt_memt))
139 		return 0;
140 
141 	if (!pccons_common_match(crt_iot, crt_memt, ja->ja_bust,
142 	    &pccons_jazzio_conf))
143 		return 0;
144 
145 	return 1;
146 }
147 
148 static void
pccons_jazzio_attach(device_t parent,device_t self,void * aux)149 pccons_jazzio_attach(device_t parent, device_t self, void *aux)
150 {
151 	struct pc_softc *sc = device_private(self);
152 	struct jazzio_attach_args *ja = aux;
153 	bus_space_tag_t crt_iot, crt_memt;
154 
155 	pccons_jazzio_init_tag(ja->ja_name, &crt_iot, &crt_memt);
156 	jazzio_intr_establish(PCKBD_INTR, pcintr, sc);
157 	pccons_common_attach(sc, crt_iot, crt_memt, ja->ja_bust,
158 	    &pccons_jazzio_conf);
159 }
160 
161 int
pccons_jazzio_cnattach(char * name,bus_space_tag_t kbd_iot)162 pccons_jazzio_cnattach(char *name, bus_space_tag_t kbd_iot)
163 {
164 	bus_space_tag_t crt_iot, crt_memt;
165 
166 	if (pccons_jazzio_init_tag(name, &crt_iot, &crt_memt))
167 		return ENXIO;
168 	pccons_common_cnattach(crt_iot, crt_memt, kbd_iot,
169 	    &pccons_jazzio_conf);
170 	return 0;
171 }
172