1 /* $NetBSD: clmpcc_pcctwo.c,v 1.21 2026/04/26 18:02:57 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Steve C. Woodford. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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. 18 * 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. 30 */ 31 32 /* 33 * Cirrus Logic CD2401 4-channel serial chip. PCCchip2 Front-end. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: clmpcc_pcctwo.c,v 1.21 2026/04/26 18:02:57 thorpej Exp $"); 38 39 /* XXX see below */ 40 #ifdef __m68k__ 41 #define _M68K_BUS_SPACE_PRIVATE 42 #endif 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/proc.h> 47 #include <sys/device.h> 48 #include <sys/conf.h> 49 #include <sys/file.h> 50 #include <sys/ioctl.h> 51 #include <sys/tty.h> 52 #include <sys/time.h> 53 #include <sys/kernel.h> 54 #include <sys/syslog.h> 55 56 #include <dev/cons.h> 57 58 #include <sys/cpu.h> 59 #include <sys/bus.h> 60 #include <sys/intr.h> 61 62 #include <dev/ic/clmpccvar.h> 63 64 #include <dev/mvme/pcctwovar.h> 65 #include <dev/mvme/pcctworeg.h> 66 67 /* XXXXSCW: Fixme */ 68 #ifdef MVME68K 69 #include <mvme68k/dev/mainbus.h> 70 #define cons_space_tag m68k_simple_bus_space 71 #else 72 #error Need consiack hook 73 #endif 74 75 /* Definition of the driver for autoconfig. */ 76 int clmpcc_pcctwo_match(device_t, cfdata_t, void *); 77 void clmpcc_pcctwo_attach(device_t, device_t, void *); 78 void clmpcc_pcctwo_iackhook(struct clmpcc_softc *, int); 79 void clmpcc_pcctwo_consiackhook(struct clmpcc_softc *, int); 80 81 CFATTACH_DECL_NEW(clmpcc_pcctwo, sizeof(struct clmpcc_softc), 82 clmpcc_pcctwo_match, clmpcc_pcctwo_attach, NULL, NULL); 83 84 extern struct cfdriver clmpcc_cd; 85 86 extern const struct cdevsw clmpcc_cdevsw; 87 88 /* 89 * For clmpcccn*() 90 */ 91 cons_decl(clmpcc); 92 93 94 /* 95 * Is the CD2401 chip present? 96 */ 97 int 98 clmpcc_pcctwo_match(device_t parent, cfdata_t cf, void *aux) 99 { 100 struct pcctwo_attach_args *pa; 101 102 pa = aux; 103 104 if (strcmp(pa->pa_name, clmpcc_cd.cd_name)) 105 return (0); 106 107 pa->pa_ipl = cf->pcctwocf_ipl; 108 109 return (1); 110 } 111 112 /* 113 * Attach a found CD2401. 114 */ 115 void 116 clmpcc_pcctwo_attach(device_t parent, device_t self, void *aux) 117 { 118 struct clmpcc_softc *sc; 119 struct pcctwo_attach_args *pa = aux; 120 int level = pa->pa_ipl; 121 122 sc = device_private(self); 123 sc->sc_dev = self; 124 level = pa->pa_ipl; 125 sc->sc_iot = pa->pa_bust; 126 bus_space_map(pa->pa_bust, pa->pa_offset, 0x100, 0, &sc->sc_ioh); 127 128 sc->sc_clk = 20000000; 129 sc->sc_byteswap = CLMPCC_BYTESWAP_LOW; 130 sc->sc_swaprtsdtr = 1; 131 sc->sc_iackhook = clmpcc_pcctwo_iackhook; 132 sc->sc_vector_base = PCCTWO_SCC_VECBASE; 133 sc->sc_rpilr = 0x03; 134 sc->sc_tpilr = 0x02; 135 sc->sc_mpilr = 0x01; 136 sc->sc_evcnt = pcctwointr_evcnt(level); 137 138 /* Do common parts of CD2401 configuration. */ 139 clmpcc_attach(sc); 140 141 /* Hook the interrupts */ 142 pcctwointr_establish(PCCTWOV_SCC_RX, clmpcc_rxintr, level, sc, NULL); 143 pcctwointr_establish(PCCTWOV_SCC_RX_EXCEP, clmpcc_rxintr, level, sc, 144 NULL); 145 pcctwointr_establish(PCCTWOV_SCC_TX, clmpcc_txintr, level, sc, NULL); 146 pcctwointr_establish(PCCTWOV_SCC_MODEM, clmpcc_mdintr, level, sc, NULL); 147 } 148 149 void 150 clmpcc_pcctwo_iackhook(struct clmpcc_softc *sc, int which) 151 { 152 bus_size_t offset; 153 volatile u_char foo; 154 155 switch (which) { 156 case CLMPCC_IACK_MODEM: 157 offset = PCC2REG_SCC_MODEM_PIACK; 158 break; 159 160 case CLMPCC_IACK_RX: 161 offset = PCC2REG_SCC_RX_PIACK; 162 break; 163 164 case CLMPCC_IACK_TX: 165 offset = PCC2REG_SCC_TX_PIACK; 166 break; 167 default: 168 #ifdef DEBUG 169 printf("%s: Invalid IACK number '%d'\n", 170 device_xname(sc->sc_dev), which); 171 #endif 172 panic("clmpcc_pcctwo_iackhook %d", which); 173 } 174 175 foo = pcc2_reg_read(sys_pcctwo, offset); 176 __USE(foo); 177 } 178 179 /* 180 * This routine is only used prior to clmpcc_attach() being called 181 */ 182 void 183 clmpcc_pcctwo_consiackhook(struct clmpcc_softc *sc, int which) 184 { 185 bus_space_handle_t bush; 186 bus_size_t offset; 187 volatile u_char foo; 188 189 switch (which) { 190 case CLMPCC_IACK_MODEM: 191 offset = PCC2REG_SCC_MODEM_PIACK; 192 break; 193 194 case CLMPCC_IACK_RX: 195 offset = PCC2REG_SCC_RX_PIACK; 196 break; 197 198 case CLMPCC_IACK_TX: 199 offset = PCC2REG_SCC_TX_PIACK; 200 break; 201 default: 202 #ifdef DEBUG 203 printf("%s: Invalid IACK number '%d'\n", 204 device_xname(sc->sc_dev), which); 205 panic("clmpcc_pcctwo_consiackhook"); 206 #endif 207 panic("clmpcc_pcctwo_iackhook %d", which); 208 } 209 210 #ifdef MVME68K 211 /* 212 * We need to fake the tag and handle since 'sys_pcctwo' will 213 * be NULL during early system startup... 214 */ 215 bush = (bus_space_handle_t) & (intiobase[MAINBUS_PCCTWO_OFFSET + 216 PCCTWO_REG_OFF]); 217 218 foo = bus_space_read_1(&cons_space_tag, bush, offset); 219 __USE(foo); 220 #else 221 #error Need consiack hook 222 #endif 223 } 224 225 226 /**************************************************************** 227 * Console support functions (MVME PCCchip2 specific!) 228 ****************************************************************/ 229 230 /* 231 * Check for CD2401 console. 232 */ 233 void 234 clmpcccnprobe(struct consdev *cp) 235 { 236 int maj; 237 238 #if defined(MVME68K) 239 if (machineid != MVME_167 && machineid != MVME_177) 240 #elif defined(MVME88K) 241 if (machineid != MVME_187) 242 #endif 243 { 244 cp->cn_pri = CN_DEAD; 245 return; 246 } 247 248 /* 249 * Locate the major number 250 */ 251 maj = cdevsw_lookup_major(&clmpcc_cdevsw); 252 253 /* Initialize required fields. */ 254 cp->cn_dev = makedev(maj, 0); 255 cp->cn_pri = CN_NORMAL; 256 } 257 258 void 259 clmpcccninit(struct consdev *cp) 260 { 261 static struct clmpcc_softc cons_sc; 262 263 cons_sc.sc_iot = &cons_space_tag; 264 bus_space_map(&cons_space_tag, 265 intiobase_phys + MAINBUS_PCCTWO_OFFSET + PCCTWO_SCC_OFF, 266 PCC2REG_SIZE, 0, &cons_sc.sc_ioh); 267 cons_sc.sc_clk = 20000000; 268 cons_sc.sc_byteswap = CLMPCC_BYTESWAP_LOW; 269 cons_sc.sc_swaprtsdtr = 1; 270 cons_sc.sc_iackhook = clmpcc_pcctwo_consiackhook; 271 cons_sc.sc_vector_base = PCCTWO_SCC_VECBASE; 272 cons_sc.sc_rpilr = 0x03; 273 cons_sc.sc_tpilr = 0x02; 274 cons_sc.sc_mpilr = 0x01; 275 276 clmpcc_cnattach(&cons_sc, 0, 9600); 277 } 278