1 /* $NetBSD: clmpcc_pcctwo.c,v 1.17 2009/05/12 13:16:45 cegger Exp $ */
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.17 2009/05/12 13:16:45 cegger Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/device.h>
45 #include <sys/ioctl.h>
48 #include <sys/kernel.h>
49 #include <sys/syslog.h>
57 #include <dev/ic/clmpccvar.h>
59 #include <dev/mvme/pcctwovar.h>
60 #include <dev/mvme/pcctworeg.h>
64 #include <mvme68k/dev/mainbus.h>
66 #error Need consiack hook
70 /* Definition of the driver for autoconfig. */
71 int clmpcc_pcctwo_match(device_t
, cfdata_t
, void *);
72 void clmpcc_pcctwo_attach(device_t
, device_t
, void *);
73 void clmpcc_pcctwo_iackhook(struct clmpcc_softc
*, int);
74 void clmpcc_pcctwo_consiackhook(struct clmpcc_softc
*, int);
76 CFATTACH_DECL(clmpcc_pcctwo
, sizeof(struct clmpcc_softc
),
77 clmpcc_pcctwo_match
, clmpcc_pcctwo_attach
, NULL
, NULL
);
79 extern struct cfdriver clmpcc_cd
;
81 extern const struct cdevsw clmpcc_cdevsw
;
90 * Is the CD2401 chip present?
93 clmpcc_pcctwo_match(device_t parent
, cfdata_t cf
, void *aux
)
95 struct pcctwo_attach_args
*pa
;
99 if (strcmp(pa
->pa_name
, clmpcc_cd
.cd_name
))
102 pa
->pa_ipl
= cf
->pcctwocf_ipl
;
108 * Attach a found CD2401.
111 clmpcc_pcctwo_attach(device_t parent
, device_t self
, void *aux
)
113 struct clmpcc_softc
*sc
;
114 struct pcctwo_attach_args
*pa
= aux
;
115 int level
= pa
->pa_ipl
;
117 sc
= device_private(self
);
119 sc
->sc_iot
= pa
->pa_bust
;
120 bus_space_map(pa
->pa_bust
, pa
->pa_offset
, 0x100, 0, &sc
->sc_ioh
);
122 sc
->sc_clk
= 20000000;
123 sc
->sc_byteswap
= CLMPCC_BYTESWAP_LOW
;
124 sc
->sc_swaprtsdtr
= 1;
125 sc
->sc_iackhook
= clmpcc_pcctwo_iackhook
;
126 sc
->sc_vector_base
= PCCTWO_SCC_VECBASE
;
130 sc
->sc_evcnt
= pcctwointr_evcnt(level
);
132 /* Do common parts of CD2401 configuration. */
135 /* Hook the interrupts */
136 pcctwointr_establish(PCCTWOV_SCC_RX
, clmpcc_rxintr
, level
, sc
, NULL
);
137 pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP
, clmpcc_rxintr
, level
, sc
,
139 pcctwointr_establish(PCCTWOV_SCC_TX
, clmpcc_txintr
, level
, sc
, NULL
);
140 pcctwointr_establish(PCCTWOV_SCC_MODEM
, clmpcc_mdintr
, level
, sc
, NULL
);
144 clmpcc_pcctwo_iackhook(struct clmpcc_softc
*sc
, int which
)
150 case CLMPCC_IACK_MODEM
:
151 offset
= PCC2REG_SCC_MODEM_PIACK
;
155 offset
= PCC2REG_SCC_RX_PIACK
;
159 offset
= PCC2REG_SCC_TX_PIACK
;
163 printf("%s: Invalid IACK number '%d'\n",
164 device_xname(&sc
->sc_dev
), which
);
166 panic("clmpcc_pcctwo_iackhook %d", which
);
169 foo
= pcc2_reg_read(sys_pcctwo
, offset
);
173 * This routine is only used prior to clmpcc_attach() being called
176 clmpcc_pcctwo_consiackhook(struct clmpcc_softc
*sc
, int which
)
178 bus_space_handle_t bush
;
183 case CLMPCC_IACK_MODEM
:
184 offset
= PCC2REG_SCC_MODEM_PIACK
;
188 offset
= PCC2REG_SCC_RX_PIACK
;
192 offset
= PCC2REG_SCC_TX_PIACK
;
196 printf("%s: Invalid IACK number '%d'\n",
197 device_xname(&sc
->sc_dev
), which
);
198 panic("clmpcc_pcctwo_consiackhook");
200 panic("clmpcc_pcctwo_iackhook %d", which
);
205 * We need to fake the tag and handle since 'sys_pcctwo' will
206 * be NULL during early system startup...
208 bush
= (bus_space_handle_t
) & (intiobase
[MAINBUS_PCCTWO_OFFSET
+
211 foo
= bus_space_read_1(&_mainbus_space_tag
, bush
, offset
);
213 #error Need consiack hook
218 /****************************************************************
219 * Console support functions (MVME PCCchip2 specific!)
220 ****************************************************************/
223 * Check for CD2401 console.
226 clmpcccnprobe(struct consdev
*cp
)
231 if (machineid
!= MVME_167
&& machineid
!= MVME_177
)
232 #elif defined(MVME88K)
233 if (machineid
!= MVME_187
)
236 cp
->cn_pri
= CN_DEAD
;
241 * Locate the major number
243 maj
= cdevsw_lookup_major(&clmpcc_cdevsw
);
245 /* Initialize required fields. */
246 cp
->cn_dev
= makedev(maj
, 0);
247 cp
->cn_pri
= CN_NORMAL
;
251 clmpcccninit(struct consdev
*cp
)
253 static struct clmpcc_softc cons_sc
;
255 cons_sc
.sc_iot
= &_mainbus_space_tag
;
256 bus_space_map(&_mainbus_space_tag
,
257 intiobase_phys
+ MAINBUS_PCCTWO_OFFSET
+ PCCTWO_SCC_OFF
,
258 PCC2REG_SIZE
, 0, &cons_sc
.sc_ioh
);
259 cons_sc
.sc_clk
= 20000000;
260 cons_sc
.sc_byteswap
= CLMPCC_BYTESWAP_LOW
;
261 cons_sc
.sc_swaprtsdtr
= 1;
262 cons_sc
.sc_iackhook
= clmpcc_pcctwo_consiackhook
;
263 cons_sc
.sc_vector_base
= PCCTWO_SCC_VECBASE
;
264 cons_sc
.sc_rpilr
= 0x03;
265 cons_sc
.sc_tpilr
= 0x02;
266 cons_sc
.sc_mpilr
= 0x01;
268 clmpcc_cnattach(&cons_sc
, 0, 9600);