167646539SMike Smith /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4ddd22fb7SNicolas Souchu * Copyright (c) 1997-2000 Nicolas Souchu
5c264e80fSNicolas Souchu * Copyright (c) 2001 Alcove - Nicolas Souchu
667646539SMike Smith * All rights reserved.
767646539SMike Smith *
867646539SMike Smith * Redistribution and use in source and binary forms, with or without
967646539SMike Smith * modification, are permitted provided that the following conditions
1067646539SMike Smith * are met:
1167646539SMike Smith * 1. Redistributions of source code must retain the above copyright
1267646539SMike Smith * notice, this list of conditions and the following disclaimer.
1367646539SMike Smith * 2. Redistributions in binary form must reproduce the above copyright
1467646539SMike Smith * notice, this list of conditions and the following disclaimer in the
1567646539SMike Smith * documentation and/or other materials provided with the distribution.
1667646539SMike Smith *
1767646539SMike Smith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1867646539SMike Smith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1967646539SMike Smith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2067646539SMike Smith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2167646539SMike Smith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2267646539SMike Smith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2367646539SMike Smith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2467646539SMike Smith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2567646539SMike Smith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2667646539SMike Smith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2767646539SMike Smith * SUCH DAMAGE.
2867646539SMike Smith */
2967646539SMike Smith
308c9bbf48SDavid E. O'Brien #include <sys/cdefs.h>
310f210c92SNicolas Souchu #include "opt_ppc.h"
320f210c92SNicolas Souchu
3367646539SMike Smith #include <sys/param.h>
3467646539SMike Smith #include <sys/systm.h>
350f210c92SNicolas Souchu #include <sys/bus.h>
36ca3d3795SJohn Baldwin #include <sys/kernel.h>
372067d312SJohn Baldwin #include <sys/lock.h>
38ca3d3795SJohn Baldwin #include <sys/interrupt.h>
39ca3d3795SJohn Baldwin #include <sys/module.h>
400f210c92SNicolas Souchu #include <sys/malloc.h>
412067d312SJohn Baldwin #include <sys/mutex.h>
42ca3d3795SJohn Baldwin #include <sys/proc.h>
4367646539SMike Smith
440f210c92SNicolas Souchu #include <machine/bus.h>
450f210c92SNicolas Souchu #include <machine/resource.h>
460f210c92SNicolas Souchu #include <sys/rman.h>
4767646539SMike Smith
48cea4d875SMarcel Moolenaar #ifdef __i386__
49cea4d875SMarcel Moolenaar #include <vm/vm.h>
50cea4d875SMarcel Moolenaar #include <vm/pmap.h>
51cea4d875SMarcel Moolenaar #include <machine/vmparam.h>
52d86c1f0dSKonstantin Belousov #include <machine/pc/bios.h>
53cea4d875SMarcel Moolenaar #endif
5467646539SMike Smith
5567646539SMike Smith #include <dev/ppbus/ppbconf.h>
5646f3ff79SMike Smith #include <dev/ppbus/ppb_msq.h>
5746f3ff79SMike Smith
58a3732274SDoug Ambrisko #include <dev/ppc/ppcvar.h>
59a3732274SDoug Ambrisko #include <dev/ppc/ppcreg.h>
6067646539SMike Smith
610f210c92SNicolas Souchu #include "ppbus_if.h"
62bc35c174SNicolas Souchu
63a3732274SDoug Ambrisko static void ppcintr(void *arg);
64a3732274SDoug Ambrisko
65cea4d875SMarcel Moolenaar #define IO_LPTSIZE_EXTENDED 8 /* "Extended" LPT controllers */
66cea4d875SMarcel Moolenaar #define IO_LPTSIZE_NORMAL 4 /* "Normal" LPT controllers */
67cea4d875SMarcel Moolenaar
68bc35c174SNicolas Souchu #define LOG_PPC(function, ppc, string) \
69bc35c174SNicolas Souchu if (bootverbose) printf("%s: %s\n", function, string)
70bc35c174SNicolas Souchu
710f210c92SNicolas Souchu #define DEVTOSOFTC(dev) ((struct ppc_data *)device_get_softc(dev))
720f210c92SNicolas Souchu
731eb7e5feSWarner Losh /*
74d0741ed4SGleb Smirnoff * We use critical enter/exit for the simple config locking needed to
751eb7e5feSWarner Losh * detect the devices. We just want to make sure that both of our writes
761eb7e5feSWarner Losh * happen without someone else also writing to those config registers. Since
771eb7e5feSWarner Losh * we just do this at startup, Giant keeps multiple threads from executing,
781eb7e5feSWarner Losh * and critical_enter() then is all that's needed to keep us from being preempted
791eb7e5feSWarner Losh * during the critical sequences with the hardware.
801eb7e5feSWarner Losh *
811eb7e5feSWarner Losh * Note: this doesn't prevent multiple threads from putting the chips into
821eb7e5feSWarner Losh * config mode, but since we only do that to detect the type at startup the
831eb7e5feSWarner Losh * extra overhead isn't needed since Giant protects us from multiple entry
841eb7e5feSWarner Losh * and no other code changes these registers.
851eb7e5feSWarner Losh */
861eb7e5feSWarner Losh #define PPC_CONFIG_LOCK(ppc) critical_enter()
87d0741ed4SGleb Smirnoff #define PPC_CONFIG_UNLOCK(ppc) critical_exit()
881eb7e5feSWarner Losh
89cea4d875SMarcel Moolenaar const char ppc_driver_name[] = "ppc";
9067646539SMike Smith
910f210c92SNicolas Souchu static char *ppc_models[] = {
9246f3ff79SMike Smith "SMC-like", "SMC FDC37C665GT", "SMC FDC37C666GT", "PC87332", "PC87306",
936a5be862SDoug Rabson "82091AA", "Generic", "W83877F", "W83877AF", "Winbond", "PC87334",
94ac7ba926SDoug Rabson "SMC FDC37C935", "PC87303", 0
9567646539SMike Smith };
9667646539SMike Smith
9746f3ff79SMike Smith /* list of available modes */
9846f3ff79SMike Smith static char *ppc_avms[] = {
9946f3ff79SMike Smith "COMPATIBLE", "NIBBLE-only", "PS2-only", "PS2/NIBBLE", "EPP-only",
10046f3ff79SMike Smith "EPP/NIBBLE", "EPP/PS2", "EPP/PS2/NIBBLE", "ECP-only",
10146f3ff79SMike Smith "ECP/NIBBLE", "ECP/PS2", "ECP/PS2/NIBBLE", "ECP/EPP",
10246f3ff79SMike Smith "ECP/EPP/NIBBLE", "ECP/EPP/PS2", "ECP/EPP/PS2/NIBBLE", 0
10346f3ff79SMike Smith };
10446f3ff79SMike Smith
10546f3ff79SMike Smith /* list of current executing modes
10646f3ff79SMike Smith * Note that few modes do not actually exist.
10746f3ff79SMike Smith */
10867646539SMike Smith static char *ppc_modes[] = {
10946f3ff79SMike Smith "COMPATIBLE", "NIBBLE", "PS/2", "PS/2", "EPP",
11046f3ff79SMike Smith "EPP", "EPP", "EPP", "ECP",
11146f3ff79SMike Smith "ECP", "ECP+PS2", "ECP+PS2", "ECP+EPP",
11246f3ff79SMike Smith "ECP+EPP", "ECP+EPP", "ECP+EPP", 0
11367646539SMike Smith };
11467646539SMike Smith
11567646539SMike Smith static char *ppc_epp_protocol[] = { " (EPP 1.9)", " (EPP 1.7)", 0 };
11667646539SMike Smith
117d64d73c9SDoug Rabson #ifdef __i386__
11867646539SMike Smith /*
11967646539SMike Smith * BIOS printer list - used by BIOS probe.
12067646539SMike Smith */
12167646539SMike Smith #define BIOS_PPC_PORTS 0x408
122d86c1f0dSKonstantin Belousov #define BIOS_PORTS ((short *)BIOS_PADDRTOVADDR(BIOS_PPC_PORTS))
12367646539SMike Smith #define BIOS_MAX_PPC 4
124d64d73c9SDoug Rabson #endif
12567646539SMike Smith
12667646539SMike Smith /*
12767646539SMike Smith * ppc_ecp_sync() XXX
12867646539SMike Smith */
1293fd85273SWarner Losh int
ppc_ecp_sync(device_t dev)130284c87f6SJohn Baldwin ppc_ecp_sync(device_t dev)
131284c87f6SJohn Baldwin {
13267646539SMike Smith int i, r;
1330f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(dev);
13467646539SMike Smith
1352067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
136c264e80fSNicolas Souchu if (!(ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_dtm & PPB_ECP))
1373fd85273SWarner Losh return 0;
138bc35c174SNicolas Souchu
13967646539SMike Smith r = r_ecr(ppc);
140bc35c174SNicolas Souchu if ((r & 0xe0) != PPC_ECR_EPP)
1413fd85273SWarner Losh return 0;
14267646539SMike Smith
14367646539SMike Smith for (i = 0; i < 100; i++) {
14467646539SMike Smith r = r_ecr(ppc);
14567646539SMike Smith if (r & 0x1)
1463fd85273SWarner Losh return 0;
14767646539SMike Smith DELAY(100);
14867646539SMike Smith }
14967646539SMike Smith
150ae6b868aSJohn Baldwin device_printf(dev, "ECP sync failed as data still present in FIFO.\n");
15167646539SMike Smith
1523fd85273SWarner Losh return 0;
15367646539SMike Smith }
15467646539SMike Smith
155bc35c174SNicolas Souchu /*
156bc35c174SNicolas Souchu * ppc_detect_fifo()
157bc35c174SNicolas Souchu *
158bc35c174SNicolas Souchu * Detect parallel port FIFO
159bc35c174SNicolas Souchu */
160bc35c174SNicolas Souchu static int
ppc_detect_fifo(struct ppc_data * ppc)161bc35c174SNicolas Souchu ppc_detect_fifo(struct ppc_data *ppc)
16267646539SMike Smith {
163bc35c174SNicolas Souchu char ecr_sav;
16494885fbdSWarner Losh char ctr_sav, ctr;
165bc35c174SNicolas Souchu short i;
16667646539SMike Smith
167bc35c174SNicolas Souchu /* save registers */
168bc35c174SNicolas Souchu ecr_sav = r_ecr(ppc);
169bc35c174SNicolas Souchu ctr_sav = r_ctr(ppc);
170bc35c174SNicolas Souchu
171bc35c174SNicolas Souchu /* enter ECP configuration mode, no interrupt, no DMA */
172bc35c174SNicolas Souchu w_ecr(ppc, 0xf4);
173bc35c174SNicolas Souchu
174bc35c174SNicolas Souchu /* read PWord size - transfers in FIFO mode must be PWord aligned */
175bc35c174SNicolas Souchu ppc->ppc_pword = (r_cnfgA(ppc) & PPC_PWORD_MASK);
176bc35c174SNicolas Souchu
177bc35c174SNicolas Souchu /* XXX 16 and 32 bits implementations not supported */
178bc35c174SNicolas Souchu if (ppc->ppc_pword != PPC_PWORD_8) {
1796e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "PWord not supported");
180bc35c174SNicolas Souchu goto error;
181bc35c174SNicolas Souchu }
182bc35c174SNicolas Souchu
183bc35c174SNicolas Souchu w_ecr(ppc, 0x34); /* byte mode, no interrupt, no DMA */
184bc35c174SNicolas Souchu ctr = r_ctr(ppc);
185bc35c174SNicolas Souchu w_ctr(ppc, ctr | PCD); /* set direction to 1 */
186bc35c174SNicolas Souchu
187bc35c174SNicolas Souchu /* enter ECP test mode, no interrupt, no DMA */
188bc35c174SNicolas Souchu w_ecr(ppc, 0xd4);
189bc35c174SNicolas Souchu
190bc35c174SNicolas Souchu /* flush the FIFO */
191bc35c174SNicolas Souchu for (i=0; i<1024; i++) {
192bc35c174SNicolas Souchu if (r_ecr(ppc) & PPC_FIFO_EMPTY)
193bc35c174SNicolas Souchu break;
19494885fbdSWarner Losh r_fifo(ppc);
195bc35c174SNicolas Souchu }
196bc35c174SNicolas Souchu
197bc35c174SNicolas Souchu if (i >= 1024) {
1986e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "can't flush FIFO");
199bc35c174SNicolas Souchu goto error;
200bc35c174SNicolas Souchu }
201bc35c174SNicolas Souchu
202bc35c174SNicolas Souchu /* enable interrupts, no DMA */
203bc35c174SNicolas Souchu w_ecr(ppc, 0xd0);
204bc35c174SNicolas Souchu
205bc35c174SNicolas Souchu /* determine readIntrThreshold
206bc35c174SNicolas Souchu * fill the FIFO until serviceIntr is set
207bc35c174SNicolas Souchu */
208bc35c174SNicolas Souchu for (i=0; i<1024; i++) {
209bc35c174SNicolas Souchu w_fifo(ppc, (char)i);
210bc35c174SNicolas Souchu if (!ppc->ppc_rthr && (r_ecr(ppc) & PPC_SERVICE_INTR)) {
211bc35c174SNicolas Souchu /* readThreshold reached */
212bc35c174SNicolas Souchu ppc->ppc_rthr = i+1;
213bc35c174SNicolas Souchu }
214bc35c174SNicolas Souchu if (r_ecr(ppc) & PPC_FIFO_FULL) {
215bc35c174SNicolas Souchu ppc->ppc_fifo = i+1;
216bc35c174SNicolas Souchu break;
217bc35c174SNicolas Souchu }
218bc35c174SNicolas Souchu }
219bc35c174SNicolas Souchu
220bc35c174SNicolas Souchu if (i >= 1024) {
2216e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "can't fill FIFO");
222bc35c174SNicolas Souchu goto error;
223bc35c174SNicolas Souchu }
224bc35c174SNicolas Souchu
225bc35c174SNicolas Souchu w_ecr(ppc, 0xd4); /* test mode, no interrupt, no DMA */
226bc35c174SNicolas Souchu w_ctr(ppc, ctr & ~PCD); /* set direction to 0 */
227bc35c174SNicolas Souchu w_ecr(ppc, 0xd0); /* enable interrupts */
228bc35c174SNicolas Souchu
229bc35c174SNicolas Souchu /* determine writeIntrThreshold
230bc35c174SNicolas Souchu * empty the FIFO until serviceIntr is set
231bc35c174SNicolas Souchu */
232bc35c174SNicolas Souchu for (i=ppc->ppc_fifo; i>0; i--) {
233bc35c174SNicolas Souchu if (r_fifo(ppc) != (char)(ppc->ppc_fifo-i)) {
2346e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "invalid data in FIFO");
235bc35c174SNicolas Souchu goto error;
236bc35c174SNicolas Souchu }
237bc35c174SNicolas Souchu if (r_ecr(ppc) & PPC_SERVICE_INTR) {
238bc35c174SNicolas Souchu /* writeIntrThreshold reached */
239bc35c174SNicolas Souchu ppc->ppc_wthr = ppc->ppc_fifo - i+1;
240bc35c174SNicolas Souchu }
241bc35c174SNicolas Souchu /* if FIFO empty before the last byte, error */
242bc35c174SNicolas Souchu if (i>1 && (r_ecr(ppc) & PPC_FIFO_EMPTY)) {
2436e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "data lost in FIFO");
244bc35c174SNicolas Souchu goto error;
245bc35c174SNicolas Souchu }
246bc35c174SNicolas Souchu }
247bc35c174SNicolas Souchu
248bc35c174SNicolas Souchu /* FIFO must be empty after the last byte */
249bc35c174SNicolas Souchu if (!(r_ecr(ppc) & PPC_FIFO_EMPTY)) {
2506e551fb6SDavid E. O'Brien LOG_PPC(__func__, ppc, "can't empty the FIFO");
251bc35c174SNicolas Souchu goto error;
252bc35c174SNicolas Souchu }
253bc35c174SNicolas Souchu
254bc35c174SNicolas Souchu w_ctr(ppc, ctr_sav);
255bc35c174SNicolas Souchu w_ecr(ppc, ecr_sav);
256bc35c174SNicolas Souchu
257bc35c174SNicolas Souchu return (0);
258bc35c174SNicolas Souchu
259bc35c174SNicolas Souchu error:
260bc35c174SNicolas Souchu w_ctr(ppc, ctr_sav);
261bc35c174SNicolas Souchu w_ecr(ppc, ecr_sav);
262bc35c174SNicolas Souchu
263bc35c174SNicolas Souchu return (EINVAL);
26467646539SMike Smith }
26567646539SMike Smith
26646f3ff79SMike Smith static int
ppc_detect_port(struct ppc_data * ppc)26746f3ff79SMike Smith ppc_detect_port(struct ppc_data *ppc)
26846f3ff79SMike Smith {
26946f3ff79SMike Smith
27046f3ff79SMike Smith w_ctr(ppc, 0x0c); /* To avoid missing PS2 ports */
27146f3ff79SMike Smith w_dtr(ppc, 0xaa);
272a7006f89SNicolas Souchu if (r_dtr(ppc) != 0xaa)
27346f3ff79SMike Smith return (0);
27446f3ff79SMike Smith
27546f3ff79SMike Smith return (1);
27646f3ff79SMike Smith }
27746f3ff79SMike Smith
27867646539SMike Smith /*
2790f210c92SNicolas Souchu * EPP timeout, according to the PC87332 manual
2800f210c92SNicolas Souchu * Semantics of clearing EPP timeout bit.
2810f210c92SNicolas Souchu * PC87332 - reading SPP_STR does it...
2820f210c92SNicolas Souchu * SMC - write 1 to EPP timeout bit XXX
2830f210c92SNicolas Souchu * Others - (?) write 0 to EPP timeout bit
2840f210c92SNicolas Souchu */
2850f210c92SNicolas Souchu static void
ppc_reset_epp_timeout(struct ppc_data * ppc)2860f210c92SNicolas Souchu ppc_reset_epp_timeout(struct ppc_data *ppc)
2870f210c92SNicolas Souchu {
2883e85b721SEd Maste char r;
2890f210c92SNicolas Souchu
2900f210c92SNicolas Souchu r = r_str(ppc);
2910f210c92SNicolas Souchu w_str(ppc, r | 0x1);
2920f210c92SNicolas Souchu w_str(ppc, r & 0xfe);
2930f210c92SNicolas Souchu
2940f210c92SNicolas Souchu return;
2950f210c92SNicolas Souchu }
2960f210c92SNicolas Souchu
2970f210c92SNicolas Souchu static int
ppc_check_epp_timeout(struct ppc_data * ppc)2980f210c92SNicolas Souchu ppc_check_epp_timeout(struct ppc_data *ppc)
2990f210c92SNicolas Souchu {
3000f210c92SNicolas Souchu ppc_reset_epp_timeout(ppc);
3010f210c92SNicolas Souchu
3020f210c92SNicolas Souchu return (!(r_str(ppc) & TIMEOUT));
3030f210c92SNicolas Souchu }
3040f210c92SNicolas Souchu
3050f210c92SNicolas Souchu /*
3060f210c92SNicolas Souchu * Configure current operating mode
3070f210c92SNicolas Souchu */
3080f210c92SNicolas Souchu static int
ppc_generic_setmode(struct ppc_data * ppc,int mode)3090f210c92SNicolas Souchu ppc_generic_setmode(struct ppc_data *ppc, int mode)
3100f210c92SNicolas Souchu {
3110f210c92SNicolas Souchu u_char ecr = 0;
3120f210c92SNicolas Souchu
3130f210c92SNicolas Souchu /* check if mode is available */
3140f210c92SNicolas Souchu if (mode && !(ppc->ppc_avm & mode))
3150f210c92SNicolas Souchu return (EINVAL);
3160f210c92SNicolas Souchu
3170f210c92SNicolas Souchu /* if ECP mode, configure ecr register */
318c264e80fSNicolas Souchu if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
3190f210c92SNicolas Souchu /* return to byte mode (keeping direction bit),
3200f210c92SNicolas Souchu * no interrupt, no DMA to be able to change to
3210f210c92SNicolas Souchu * ECP
3220f210c92SNicolas Souchu */
3230f210c92SNicolas Souchu w_ecr(ppc, PPC_ECR_RESET);
3240f210c92SNicolas Souchu ecr = PPC_DISABLE_INTR;
3250f210c92SNicolas Souchu
3260f210c92SNicolas Souchu if (mode & PPB_EPP)
3270f210c92SNicolas Souchu return (EINVAL);
3280f210c92SNicolas Souchu else if (mode & PPB_ECP)
3290f210c92SNicolas Souchu /* select ECP mode */
3300f210c92SNicolas Souchu ecr |= PPC_ECR_ECP;
3310f210c92SNicolas Souchu else if (mode & PPB_PS2)
3320f210c92SNicolas Souchu /* select PS2 mode with ECP */
3330f210c92SNicolas Souchu ecr |= PPC_ECR_PS2;
3340f210c92SNicolas Souchu else
3350f210c92SNicolas Souchu /* select COMPATIBLE/NIBBLE mode */
3360f210c92SNicolas Souchu ecr |= PPC_ECR_STD;
3370f210c92SNicolas Souchu
3380f210c92SNicolas Souchu w_ecr(ppc, ecr);
3390f210c92SNicolas Souchu }
3400f210c92SNicolas Souchu
3410f210c92SNicolas Souchu ppc->ppc_mode = mode;
3420f210c92SNicolas Souchu
3430f210c92SNicolas Souchu return (0);
3440f210c92SNicolas Souchu }
3450f210c92SNicolas Souchu
3460f210c92SNicolas Souchu /*
3470f210c92SNicolas Souchu * The ppc driver is free to choose options like FIFO or DMA
3480f210c92SNicolas Souchu * if ECP mode is available.
3490f210c92SNicolas Souchu *
3500f210c92SNicolas Souchu * The 'RAW' option allows the upper drivers to force the ppc mode
3510f210c92SNicolas Souchu * even with FIFO, DMA available.
3520f210c92SNicolas Souchu */
3530f210c92SNicolas Souchu static int
ppc_smclike_setmode(struct ppc_data * ppc,int mode)3540f210c92SNicolas Souchu ppc_smclike_setmode(struct ppc_data *ppc, int mode)
3550f210c92SNicolas Souchu {
3560f210c92SNicolas Souchu u_char ecr = 0;
3570f210c92SNicolas Souchu
3580f210c92SNicolas Souchu /* check if mode is available */
3590f210c92SNicolas Souchu if (mode && !(ppc->ppc_avm & mode))
3600f210c92SNicolas Souchu return (EINVAL);
3610f210c92SNicolas Souchu
3620f210c92SNicolas Souchu /* if ECP mode, configure ecr register */
363c264e80fSNicolas Souchu if ((ppc->ppc_avm & PPB_ECP) || (ppc->ppc_dtm & PPB_ECP)) {
3640f210c92SNicolas Souchu /* return to byte mode (keeping direction bit),
3650f210c92SNicolas Souchu * no interrupt, no DMA to be able to change to
3660f210c92SNicolas Souchu * ECP or EPP mode
3670f210c92SNicolas Souchu */
3680f210c92SNicolas Souchu w_ecr(ppc, PPC_ECR_RESET);
3690f210c92SNicolas Souchu ecr = PPC_DISABLE_INTR;
3700f210c92SNicolas Souchu
3710f210c92SNicolas Souchu if (mode & PPB_EPP)
3720f210c92SNicolas Souchu /* select EPP mode */
3730f210c92SNicolas Souchu ecr |= PPC_ECR_EPP;
3740f210c92SNicolas Souchu else if (mode & PPB_ECP)
3750f210c92SNicolas Souchu /* select ECP mode */
3760f210c92SNicolas Souchu ecr |= PPC_ECR_ECP;
3770f210c92SNicolas Souchu else if (mode & PPB_PS2)
3780f210c92SNicolas Souchu /* select PS2 mode with ECP */
3790f210c92SNicolas Souchu ecr |= PPC_ECR_PS2;
3800f210c92SNicolas Souchu else
3810f210c92SNicolas Souchu /* select COMPATIBLE/NIBBLE mode */
3820f210c92SNicolas Souchu ecr |= PPC_ECR_STD;
3830f210c92SNicolas Souchu
3840f210c92SNicolas Souchu w_ecr(ppc, ecr);
3850f210c92SNicolas Souchu }
3860f210c92SNicolas Souchu
3870f210c92SNicolas Souchu ppc->ppc_mode = mode;
3880f210c92SNicolas Souchu
3890f210c92SNicolas Souchu return (0);
3900f210c92SNicolas Souchu }
3910f210c92SNicolas Souchu
3920f210c92SNicolas Souchu #ifdef PPC_PROBE_CHIPSET
3930f210c92SNicolas Souchu /*
39467646539SMike Smith * ppc_pc873xx_detect
39567646539SMike Smith *
39667646539SMike Smith * Probe for a Natsemi PC873xx-family part.
39767646539SMike Smith *
39867646539SMike Smith * References in this function are to the National Semiconductor
39967646539SMike Smith * PC87332 datasheet TL/C/11930, May 1995 revision.
40067646539SMike Smith */
40167646539SMike Smith static int pc873xx_basetab[] = {0x0398, 0x026e, 0x015c, 0x002e, 0};
40267646539SMike Smith static int pc873xx_porttab[] = {0x0378, 0x03bc, 0x0278, 0};
403af548787SNicolas Souchu static int pc873xx_irqtab[] = {5, 7, 5, 0};
404af548787SNicolas Souchu
405af548787SNicolas Souchu static int pc873xx_regstab[] = {
406af548787SNicolas Souchu PC873_FER, PC873_FAR, PC873_PTR,
407af548787SNicolas Souchu PC873_FCR, PC873_PCR, PC873_PMC,
408af548787SNicolas Souchu PC873_TUP, PC873_SID, PC873_PNP0,
409af548787SNicolas Souchu PC873_PNP1, PC873_LPTBA, -1
410af548787SNicolas Souchu };
411af548787SNicolas Souchu
412af548787SNicolas Souchu static char *pc873xx_rnametab[] = {
413af548787SNicolas Souchu "FER", "FAR", "PTR", "FCR", "PCR",
414af548787SNicolas Souchu "PMC", "TUP", "SID", "PNP0", "PNP1",
415af548787SNicolas Souchu "LPTBA", NULL
416af548787SNicolas Souchu };
41767646539SMike Smith
41867646539SMike Smith static int
ppc_pc873xx_detect(struct ppc_data * ppc,int chipset_mode)41946f3ff79SMike Smith ppc_pc873xx_detect(struct ppc_data *ppc, int chipset_mode) /* XXX mode never forced */
42067646539SMike Smith {
42167646539SMike Smith static int index = 0;
422f1d19042SArchie Cobbs int idport, irq;
423af548787SNicolas Souchu int ptr, pcr, val, i;
42467646539SMike Smith
42567646539SMike Smith while ((idport = pc873xx_basetab[index++])) {
42667646539SMike Smith /* XXX should check first to see if this location is already claimed */
42767646539SMike Smith
42867646539SMike Smith /*
429af548787SNicolas Souchu * Pull the 873xx through the power-on ID cycle (2.2,1.).
430af548787SNicolas Souchu * We can't use this to locate the chip as it may already have
431af548787SNicolas Souchu * been used by the BIOS.
43267646539SMike Smith */
433af548787SNicolas Souchu (void)inb(idport); (void)inb(idport);
434af548787SNicolas Souchu (void)inb(idport); (void)inb(idport);
43567646539SMike Smith
43667646539SMike Smith /*
43767646539SMike Smith * Read the SID byte. Possible values are :
43867646539SMike Smith *
439af548787SNicolas Souchu * 01010xxx PC87334
44067646539SMike Smith * 0001xxxx PC87332
44167646539SMike Smith * 01110xxx PC87306
442ac7ba926SDoug Rabson * 00110xxx PC87303
44367646539SMike Smith */
44467646539SMike Smith outb(idport, PC873_SID);
44567646539SMike Smith val = inb(idport + 1);
44667646539SMike Smith if ((val & 0xf0) == 0x10) {
4470f210c92SNicolas Souchu ppc->ppc_model = NS_PC87332;
44867646539SMike Smith } else if ((val & 0xf8) == 0x70) {
4490f210c92SNicolas Souchu ppc->ppc_model = NS_PC87306;
450af548787SNicolas Souchu } else if ((val & 0xf8) == 0x50) {
4510f210c92SNicolas Souchu ppc->ppc_model = NS_PC87334;
452ac7ba926SDoug Rabson } else if ((val & 0xf8) == 0x40) { /* Should be 0x30 by the
453ac7ba926SDoug Rabson documentation, but probing
454ac7ba926SDoug Rabson yielded 0x40... */
455ac7ba926SDoug Rabson ppc->ppc_model = NS_PC87303;
45667646539SMike Smith } else {
45767646539SMike Smith if (bootverbose && (val != 0xff))
45867646539SMike Smith printf("PC873xx probe at 0x%x got unknown ID 0x%x\n", idport, val);
45967646539SMike Smith continue ; /* not recognised */
46067646539SMike Smith }
46167646539SMike Smith
462af548787SNicolas Souchu /* print registers */
463af548787SNicolas Souchu if (bootverbose) {
464af548787SNicolas Souchu printf("PC873xx");
465af548787SNicolas Souchu for (i=0; pc873xx_regstab[i] != -1; i++) {
466af548787SNicolas Souchu outb(idport, pc873xx_regstab[i]);
467af548787SNicolas Souchu printf(" %s=0x%x", pc873xx_rnametab[i],
468af548787SNicolas Souchu inb(idport + 1) & 0xff);
469af548787SNicolas Souchu }
470af548787SNicolas Souchu printf("\n");
471af548787SNicolas Souchu }
472af548787SNicolas Souchu
47367646539SMike Smith /*
47467646539SMike Smith * We think we have one. Is it enabled and where we want it to be?
47567646539SMike Smith */
47667646539SMike Smith outb(idport, PC873_FER);
47767646539SMike Smith val = inb(idport + 1);
47867646539SMike Smith if (!(val & PC873_PPENABLE)) {
47967646539SMike Smith if (bootverbose)
48067646539SMike Smith printf("PC873xx parallel port disabled\n");
48167646539SMike Smith continue;
48267646539SMike Smith }
48367646539SMike Smith outb(idport, PC873_FAR);
484ac7ba926SDoug Rabson val = inb(idport + 1);
48567646539SMike Smith /* XXX we should create a driver instance for every port found */
486ac7ba926SDoug Rabson if (pc873xx_porttab[val & 0x3] != ppc->ppc_base) {
487ac7ba926SDoug Rabson /* First try to change the port address to that requested... */
488ac7ba926SDoug Rabson
489ac7ba926SDoug Rabson switch (ppc->ppc_base) {
490ac7ba926SDoug Rabson case 0x378:
491ac7ba926SDoug Rabson val &= 0xfc;
492ac7ba926SDoug Rabson break;
493ac7ba926SDoug Rabson
494ac7ba926SDoug Rabson case 0x3bc:
495ac7ba926SDoug Rabson val &= 0xfd;
496ac7ba926SDoug Rabson break;
497ac7ba926SDoug Rabson
498ac7ba926SDoug Rabson case 0x278:
499ac7ba926SDoug Rabson val &= 0xfe;
500ac7ba926SDoug Rabson break;
501ac7ba926SDoug Rabson
502ac7ba926SDoug Rabson default:
503ac7ba926SDoug Rabson val &= 0xfd;
504ac7ba926SDoug Rabson break;
505ac7ba926SDoug Rabson }
506ac7ba926SDoug Rabson
507ac7ba926SDoug Rabson outb(idport, PC873_FAR);
508ac7ba926SDoug Rabson outb(idport + 1, val);
509ac7ba926SDoug Rabson outb(idport + 1, val);
510ac7ba926SDoug Rabson
511ac7ba926SDoug Rabson /* Check for success by reading back the value we supposedly
512ac7ba926SDoug Rabson wrote and comparing...*/
513ac7ba926SDoug Rabson
514ac7ba926SDoug Rabson outb(idport, PC873_FAR);
515ac7ba926SDoug Rabson val = inb(idport + 1) & 0x3;
516ac7ba926SDoug Rabson
517ac7ba926SDoug Rabson /* If we fail, report the failure... */
518ac7ba926SDoug Rabson
51967646539SMike Smith if (pc873xx_porttab[val] != ppc->ppc_base) {
52067646539SMike Smith if (bootverbose)
52167646539SMike Smith printf("PC873xx at 0x%x not for driver at port 0x%x\n",
52267646539SMike Smith pc873xx_porttab[val], ppc->ppc_base);
523ac7ba926SDoug Rabson }
52467646539SMike Smith continue;
52567646539SMike Smith }
52667646539SMike Smith
52767646539SMike Smith outb(idport, PC873_PTR);
528af548787SNicolas Souchu ptr = inb(idport + 1);
529af548787SNicolas Souchu
530af548787SNicolas Souchu /* get irq settings */
531af548787SNicolas Souchu if (ppc->ppc_base == 0x378)
532af548787SNicolas Souchu irq = (ptr & PC873_LPTBIRQ7) ? 7 : 5;
533af548787SNicolas Souchu else
534af548787SNicolas Souchu irq = pc873xx_irqtab[val];
535af548787SNicolas Souchu
53667646539SMike Smith if (bootverbose)
537af548787SNicolas Souchu printf("PC873xx irq %d at 0x%x\n", irq, ppc->ppc_base);
53867646539SMike Smith
539af548787SNicolas Souchu /*
540af548787SNicolas Souchu * Check if irq settings are correct
541af548787SNicolas Souchu */
542af548787SNicolas Souchu if (irq != ppc->ppc_irq) {
543af548787SNicolas Souchu /*
544af548787SNicolas Souchu * If the chipset is not locked and base address is 0x378,
545af548787SNicolas Souchu * we have another chance
546af548787SNicolas Souchu */
547af548787SNicolas Souchu if (ppc->ppc_base == 0x378 && !(ptr & PC873_CFGLOCK)) {
548af548787SNicolas Souchu if (ppc->ppc_irq == 7) {
549af548787SNicolas Souchu outb(idport + 1, (ptr | PC873_LPTBIRQ7));
550af548787SNicolas Souchu outb(idport + 1, (ptr | PC873_LPTBIRQ7));
551af548787SNicolas Souchu } else {
552af548787SNicolas Souchu outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
553af548787SNicolas Souchu outb(idport + 1, (ptr & ~PC873_LPTBIRQ7));
55467646539SMike Smith }
555af548787SNicolas Souchu if (bootverbose)
556af548787SNicolas Souchu printf("PC873xx irq set to %d\n", ppc->ppc_irq);
557af548787SNicolas Souchu } else {
558af548787SNicolas Souchu if (bootverbose)
559af548787SNicolas Souchu printf("PC873xx sorry, can't change irq setting\n");
56067646539SMike Smith }
56167646539SMike Smith } else {
56267646539SMike Smith if (bootverbose)
563af548787SNicolas Souchu printf("PC873xx irq settings are correct\n");
56467646539SMike Smith }
56567646539SMike Smith
56667646539SMike Smith outb(idport, PC873_PCR);
567af548787SNicolas Souchu pcr = inb(idport + 1);
568af548787SNicolas Souchu
569af548787SNicolas Souchu if ((ptr & PC873_CFGLOCK) || !chipset_mode) {
570af548787SNicolas Souchu if (bootverbose)
571af548787SNicolas Souchu printf("PC873xx %s", (ptr & PC873_CFGLOCK)?"locked":"unlocked");
572af548787SNicolas Souchu
573af548787SNicolas Souchu ppc->ppc_avm |= PPB_NIBBLE;
574af548787SNicolas Souchu if (bootverbose)
575af548787SNicolas Souchu printf(", NIBBLE");
576af548787SNicolas Souchu
577af548787SNicolas Souchu if (pcr & PC873_EPPEN) {
578af548787SNicolas Souchu ppc->ppc_avm |= PPB_EPP;
579af548787SNicolas Souchu
580af548787SNicolas Souchu if (bootverbose)
581af548787SNicolas Souchu printf(", EPP");
582af548787SNicolas Souchu
583af548787SNicolas Souchu if (pcr & PC873_EPP19)
584af548787SNicolas Souchu ppc->ppc_epp = EPP_1_9;
585af548787SNicolas Souchu else
586af548787SNicolas Souchu ppc->ppc_epp = EPP_1_7;
587af548787SNicolas Souchu
5880f210c92SNicolas Souchu if ((ppc->ppc_model == NS_PC87332) && bootverbose) {
589af548787SNicolas Souchu outb(idport, PC873_PTR);
590af548787SNicolas Souchu ptr = inb(idport + 1);
591af548787SNicolas Souchu if (ptr & PC873_EPPRDIR)
592af548787SNicolas Souchu printf(", Regular mode");
593af548787SNicolas Souchu else
594af548787SNicolas Souchu printf(", Automatic mode");
595af548787SNicolas Souchu }
596af548787SNicolas Souchu } else if (pcr & PC873_ECPEN) {
597af548787SNicolas Souchu ppc->ppc_avm |= PPB_ECP;
598af548787SNicolas Souchu if (bootverbose)
599af548787SNicolas Souchu printf(", ECP");
600af548787SNicolas Souchu
601af548787SNicolas Souchu if (pcr & PC873_ECPCLK) { /* XXX */
602af548787SNicolas Souchu ppc->ppc_avm |= PPB_PS2;
603af548787SNicolas Souchu if (bootverbose)
604af548787SNicolas Souchu printf(", PS/2");
605af548787SNicolas Souchu }
606af548787SNicolas Souchu } else {
607af548787SNicolas Souchu outb(idport, PC873_PTR);
608af548787SNicolas Souchu ptr = inb(idport + 1);
609af548787SNicolas Souchu if (ptr & PC873_EXTENDED) {
610af548787SNicolas Souchu ppc->ppc_avm |= PPB_SPP;
611af548787SNicolas Souchu if (bootverbose)
612af548787SNicolas Souchu printf(", SPP");
613af548787SNicolas Souchu }
614af548787SNicolas Souchu }
615af548787SNicolas Souchu } else {
616af548787SNicolas Souchu if (bootverbose)
617af548787SNicolas Souchu printf("PC873xx unlocked");
618af548787SNicolas Souchu
619af548787SNicolas Souchu if (chipset_mode & PPB_ECP) {
620af548787SNicolas Souchu if ((chipset_mode & PPB_EPP) && bootverbose)
621af548787SNicolas Souchu printf(", ECP+EPP not supported");
622af548787SNicolas Souchu
623af548787SNicolas Souchu pcr &= ~PC873_EPPEN;
624af548787SNicolas Souchu pcr |= (PC873_ECPEN | PC873_ECPCLK); /* XXX */
625af548787SNicolas Souchu outb(idport + 1, pcr);
626af548787SNicolas Souchu outb(idport + 1, pcr);
627af548787SNicolas Souchu
628af548787SNicolas Souchu if (bootverbose)
629af548787SNicolas Souchu printf(", ECP");
630af548787SNicolas Souchu
631af548787SNicolas Souchu } else if (chipset_mode & PPB_EPP) {
632af548787SNicolas Souchu pcr &= ~(PC873_ECPEN | PC873_ECPCLK);
633af548787SNicolas Souchu pcr |= (PC873_EPPEN | PC873_EPP19);
634af548787SNicolas Souchu outb(idport + 1, pcr);
635af548787SNicolas Souchu outb(idport + 1, pcr);
636af548787SNicolas Souchu
637af548787SNicolas Souchu ppc->ppc_epp = EPP_1_9; /* XXX */
638af548787SNicolas Souchu
639af548787SNicolas Souchu if (bootverbose)
640af548787SNicolas Souchu printf(", EPP1.9");
64167646539SMike Smith
64267646539SMike Smith /* enable automatic direction turnover */
6430f210c92SNicolas Souchu if (ppc->ppc_model == NS_PC87332) {
64467646539SMike Smith outb(idport, PC873_PTR);
645af548787SNicolas Souchu ptr = inb(idport + 1);
646af548787SNicolas Souchu ptr &= ~PC873_EPPRDIR;
647af548787SNicolas Souchu outb(idport + 1, ptr);
648af548787SNicolas Souchu outb(idport + 1, ptr);
64967646539SMike Smith
65067646539SMike Smith if (bootverbose)
651af548787SNicolas Souchu printf(", Automatic mode");
65267646539SMike Smith }
653af548787SNicolas Souchu } else {
654af548787SNicolas Souchu pcr &= ~(PC873_ECPEN | PC873_ECPCLK | PC873_EPPEN);
655af548787SNicolas Souchu outb(idport + 1, pcr);
656af548787SNicolas Souchu outb(idport + 1, pcr);
657af548787SNicolas Souchu
658af548787SNicolas Souchu /* configure extended bit in PTR */
659af548787SNicolas Souchu outb(idport, PC873_PTR);
660af548787SNicolas Souchu ptr = inb(idport + 1);
661af548787SNicolas Souchu
662af548787SNicolas Souchu if (chipset_mode & PPB_PS2) {
663af548787SNicolas Souchu ptr |= PC873_EXTENDED;
664af548787SNicolas Souchu
665af548787SNicolas Souchu if (bootverbose)
666af548787SNicolas Souchu printf(", PS/2");
667af548787SNicolas Souchu
668af548787SNicolas Souchu } else {
669af548787SNicolas Souchu /* default to NIBBLE mode */
670af548787SNicolas Souchu ptr &= ~PC873_EXTENDED;
671af548787SNicolas Souchu
672af548787SNicolas Souchu if (bootverbose)
673af548787SNicolas Souchu printf(", NIBBLE");
67467646539SMike Smith }
675af548787SNicolas Souchu outb(idport + 1, ptr);
676af548787SNicolas Souchu outb(idport + 1, ptr);
677af548787SNicolas Souchu }
678af548787SNicolas Souchu
679af548787SNicolas Souchu ppc->ppc_avm = chipset_mode;
680af548787SNicolas Souchu }
681af548787SNicolas Souchu
682af548787SNicolas Souchu if (bootverbose)
683af548787SNicolas Souchu printf("\n");
684af548787SNicolas Souchu
6850f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_GENERIC;
6860f210c92SNicolas Souchu ppc_generic_setmode(ppc, chipset_mode);
68746f3ff79SMike Smith
68846f3ff79SMike Smith return(chipset_mode);
68967646539SMike Smith }
69046f3ff79SMike Smith return(-1);
69167646539SMike Smith }
69267646539SMike Smith
69367646539SMike Smith /*
69467646539SMike Smith * ppc_smc37c66xgt_detect
69567646539SMike Smith *
69667646539SMike Smith * SMC FDC37C66xGT configuration.
69767646539SMike Smith */
69867646539SMike Smith static int
ppc_smc37c66xgt_detect(struct ppc_data * ppc,int chipset_mode)69946f3ff79SMike Smith ppc_smc37c66xgt_detect(struct ppc_data *ppc, int chipset_mode)
70067646539SMike Smith {
7011eb7e5feSWarner Losh int i;
702c9ab0738SNicolas Souchu u_char r;
70367646539SMike Smith int type = -1;
70467646539SMike Smith int csr = SMC66x_CSR; /* initial value is 0x3F0 */
70567646539SMike Smith
70667646539SMike Smith int port_address[] = { -1 /* disabled */ , 0x3bc, 0x378, 0x278 };
70767646539SMike Smith
70867646539SMike Smith #define cio csr+1 /* config IO port is either 0x3F1 or 0x371 */
70967646539SMike Smith
71067646539SMike Smith /*
71167646539SMike Smith * Detection: enter configuration mode and read CRD register.
71267646539SMike Smith */
7131eb7e5feSWarner Losh PPC_CONFIG_LOCK(ppc);
71467646539SMike Smith outb(csr, SMC665_iCODE);
71567646539SMike Smith outb(csr, SMC665_iCODE);
7161eb7e5feSWarner Losh PPC_CONFIG_UNLOCK(ppc);
71767646539SMike Smith
71867646539SMike Smith outb(csr, 0xd);
71967646539SMike Smith if (inb(cio) == 0x65) {
72067646539SMike Smith type = SMC_37C665GT;
72167646539SMike Smith goto config;
72267646539SMike Smith }
72367646539SMike Smith
72467646539SMike Smith for (i = 0; i < 2; i++) {
7251eb7e5feSWarner Losh PPC_CONFIG_LOCK(ppc);
72667646539SMike Smith outb(csr, SMC666_iCODE);
72767646539SMike Smith outb(csr, SMC666_iCODE);
7281eb7e5feSWarner Losh PPC_CONFIG_UNLOCK(ppc);
72967646539SMike Smith
73067646539SMike Smith outb(csr, 0xd);
73167646539SMike Smith if (inb(cio) == 0x66) {
73267646539SMike Smith type = SMC_37C666GT;
73367646539SMike Smith break;
73467646539SMike Smith }
73567646539SMike Smith
73667646539SMike Smith /* Another chance, CSR may be hard-configured to be at 0x370 */
73767646539SMike Smith csr = SMC666_CSR;
73867646539SMike Smith }
73967646539SMike Smith
74067646539SMike Smith config:
74167646539SMike Smith /*
74267646539SMike Smith * If chipset not found, do not continue.
74367646539SMike Smith */
7441eb7e5feSWarner Losh if (type == -1) {
7451eb7e5feSWarner Losh outb(csr, 0xaa); /* end config mode */
74646f3ff79SMike Smith return (-1);
7471eb7e5feSWarner Losh }
74867646539SMike Smith
74967646539SMike Smith /* select CR1 */
75067646539SMike Smith outb(csr, 0x1);
75167646539SMike Smith
75267646539SMike Smith /* read the port's address: bits 0 and 1 of CR1 */
75367646539SMike Smith r = inb(cio) & SMC_CR1_ADDR;
7541eb7e5feSWarner Losh if (port_address[(int)r] != ppc->ppc_base) {
7551eb7e5feSWarner Losh outb(csr, 0xaa); /* end config mode */
75646f3ff79SMike Smith return (-1);
7571eb7e5feSWarner Losh }
75867646539SMike Smith
7590f210c92SNicolas Souchu ppc->ppc_model = type;
76067646539SMike Smith
76167646539SMike Smith /*
76267646539SMike Smith * CR1 and CR4 registers bits 3 and 0/1 for mode configuration
76346f3ff79SMike Smith * If SPP mode is detected, try to set ECP+EPP mode
76467646539SMike Smith */
76567646539SMike Smith
76646f3ff79SMike Smith if (bootverbose) {
76746f3ff79SMike Smith outb(csr, 0x1);
768ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "SMC registers CR1=0x%x",
769ff809674SJohn Baldwin inb(cio) & 0xff);
77046f3ff79SMike Smith
77146f3ff79SMike Smith outb(csr, 0x4);
77246f3ff79SMike Smith printf(" CR4=0x%x", inb(cio) & 0xff);
77346f3ff79SMike Smith }
77446f3ff79SMike Smith
77546f3ff79SMike Smith /* select CR1 */
77667646539SMike Smith outb(csr, 0x1);
77767646539SMike Smith
77846f3ff79SMike Smith if (!chipset_mode) {
77967646539SMike Smith /* autodetect mode */
78067646539SMike Smith
78146f3ff79SMike Smith /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
78246f3ff79SMike Smith if (type == SMC_37C666GT) {
78346f3ff79SMike Smith ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
784edcfcf27SNicolas Souchu if (bootverbose)
785edcfcf27SNicolas Souchu printf(" configuration hardwired, supposing " \
786edcfcf27SNicolas Souchu "ECP+EPP SPP");
78767646539SMike Smith
78846f3ff79SMike Smith } else
78946f3ff79SMike Smith if ((inb(cio) & SMC_CR1_MODE) == 0) {
79067646539SMike Smith /* already in extended parallel port mode, read CR4 */
79167646539SMike Smith outb(csr, 0x4);
79267646539SMike Smith r = (inb(cio) & SMC_CR4_EMODE);
79367646539SMike Smith
79467646539SMike Smith switch (r) {
79567646539SMike Smith case SMC_SPP:
79646f3ff79SMike Smith ppc->ppc_avm |= PPB_SPP;
797edcfcf27SNicolas Souchu if (bootverbose)
798edcfcf27SNicolas Souchu printf(" SPP");
79967646539SMike Smith break;
80067646539SMike Smith
80167646539SMike Smith case SMC_EPPSPP:
80246f3ff79SMike Smith ppc->ppc_avm |= PPB_EPP | PPB_SPP;
803edcfcf27SNicolas Souchu if (bootverbose)
804edcfcf27SNicolas Souchu printf(" EPP SPP");
80567646539SMike Smith break;
80667646539SMike Smith
80767646539SMike Smith case SMC_ECP:
80846f3ff79SMike Smith ppc->ppc_avm |= PPB_ECP | PPB_SPP;
809edcfcf27SNicolas Souchu if (bootverbose)
810edcfcf27SNicolas Souchu printf(" ECP SPP");
81167646539SMike Smith break;
81267646539SMike Smith
81367646539SMike Smith case SMC_ECPEPP:
81446f3ff79SMike Smith ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
815edcfcf27SNicolas Souchu if (bootverbose)
816edcfcf27SNicolas Souchu printf(" ECP+EPP SPP");
81767646539SMike Smith break;
81867646539SMike Smith }
81946f3ff79SMike Smith } else {
82046f3ff79SMike Smith /* not an extended port mode */
82146f3ff79SMike Smith ppc->ppc_avm |= PPB_SPP;
822edcfcf27SNicolas Souchu if (bootverbose)
823edcfcf27SNicolas Souchu printf(" SPP");
82467646539SMike Smith }
82546f3ff79SMike Smith
82667646539SMike Smith } else {
82767646539SMike Smith /* mode forced */
82854ad6085SNicolas Souchu ppc->ppc_avm = chipset_mode;
82967646539SMike Smith
83046f3ff79SMike Smith /* 666GT is ~certainly~ hardwired to an extended ECP+EPP mode */
83167646539SMike Smith if (type == SMC_37C666GT)
83267646539SMike Smith goto end_detect;
83367646539SMike Smith
83467646539SMike Smith r = inb(cio);
83546f3ff79SMike Smith if ((chipset_mode & (PPB_ECP | PPB_EPP)) == 0) {
83646f3ff79SMike Smith /* do not use ECP when the mode is not forced to */
83767646539SMike Smith outb(cio, r | SMC_CR1_MODE);
838edcfcf27SNicolas Souchu if (bootverbose)
839edcfcf27SNicolas Souchu printf(" SPP");
84067646539SMike Smith } else {
84167646539SMike Smith /* an extended mode is selected */
84267646539SMike Smith outb(cio, r & ~SMC_CR1_MODE);
84367646539SMike Smith
84467646539SMike Smith /* read CR4 register and reset mode field */
84567646539SMike Smith outb(csr, 0x4);
84667646539SMike Smith r = inb(cio) & ~SMC_CR4_EMODE;
84767646539SMike Smith
84846f3ff79SMike Smith if (chipset_mode & PPB_ECP) {
84946f3ff79SMike Smith if (chipset_mode & PPB_EPP) {
85067646539SMike Smith outb(cio, r | SMC_ECPEPP);
851edcfcf27SNicolas Souchu if (bootverbose)
852edcfcf27SNicolas Souchu printf(" ECP+EPP");
85346f3ff79SMike Smith } else {
85446f3ff79SMike Smith outb(cio, r | SMC_ECP);
855edcfcf27SNicolas Souchu if (bootverbose)
856edcfcf27SNicolas Souchu printf(" ECP");
85746f3ff79SMike Smith }
85846f3ff79SMike Smith } else {
85946f3ff79SMike Smith /* PPB_EPP is set */
86046f3ff79SMike Smith outb(cio, r | SMC_EPPSPP);
861edcfcf27SNicolas Souchu if (bootverbose)
862edcfcf27SNicolas Souchu printf(" EPP SPP");
86367646539SMike Smith }
86467646539SMike Smith }
86546f3ff79SMike Smith ppc->ppc_avm = chipset_mode;
86667646539SMike Smith }
86767646539SMike Smith
868bc35c174SNicolas Souchu /* set FIFO threshold to 16 */
869bc35c174SNicolas Souchu if (ppc->ppc_avm & PPB_ECP) {
870bc35c174SNicolas Souchu /* select CRA */
871bc35c174SNicolas Souchu outb(csr, 0xa);
872bc35c174SNicolas Souchu outb(cio, 16);
873bc35c174SNicolas Souchu }
874bc35c174SNicolas Souchu
87567646539SMike Smith end_detect:
87646f3ff79SMike Smith
87746f3ff79SMike Smith if (bootverbose)
87846f3ff79SMike Smith printf ("\n");
87946f3ff79SMike Smith
88054ad6085SNicolas Souchu if (ppc->ppc_avm & PPB_EPP) {
88167646539SMike Smith /* select CR4 */
88267646539SMike Smith outb(csr, 0x4);
88367646539SMike Smith r = inb(cio);
88467646539SMike Smith
88567646539SMike Smith /*
88667646539SMike Smith * Set the EPP protocol...
88767646539SMike Smith * Low=EPP 1.9 (1284 standard) and High=EPP 1.7
88867646539SMike Smith */
88967646539SMike Smith if (ppc->ppc_epp == EPP_1_9)
89067646539SMike Smith outb(cio, (r & ~SMC_CR4_EPPTYPE));
89167646539SMike Smith else
89267646539SMike Smith outb(cio, (r | SMC_CR4_EPPTYPE));
89367646539SMike Smith }
89467646539SMike Smith
8951eb7e5feSWarner Losh outb(csr, 0xaa); /* end config mode */
89667646539SMike Smith
8970f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_SMCLIKE;
8980f210c92SNicolas Souchu ppc_smclike_setmode(ppc, chipset_mode);
89967646539SMike Smith
90046f3ff79SMike Smith return (chipset_mode);
90167646539SMike Smith }
90267646539SMike Smith
90346f3ff79SMike Smith /*
9046a5be862SDoug Rabson * SMC FDC37C935 configuration
9056a5be862SDoug Rabson * Found on many Alpha machines
9066a5be862SDoug Rabson */
9076a5be862SDoug Rabson static int
ppc_smc37c935_detect(struct ppc_data * ppc,int chipset_mode)9086a5be862SDoug Rabson ppc_smc37c935_detect(struct ppc_data *ppc, int chipset_mode)
9096a5be862SDoug Rabson {
9106a5be862SDoug Rabson int type = -1;
9116a5be862SDoug Rabson
9121eb7e5feSWarner Losh PPC_CONFIG_LOCK(ppc);
9136a5be862SDoug Rabson outb(SMC935_CFG, 0x55); /* enter config mode */
9146a5be862SDoug Rabson outb(SMC935_CFG, 0x55);
9151eb7e5feSWarner Losh PPC_CONFIG_UNLOCK(ppc);
9166a5be862SDoug Rabson
9176a5be862SDoug Rabson outb(SMC935_IND, SMC935_ID); /* check device id */
9186a5be862SDoug Rabson if (inb(SMC935_DAT) == 0x2)
9196a5be862SDoug Rabson type = SMC_37C935;
9206a5be862SDoug Rabson
9216a5be862SDoug Rabson if (type == -1) {
9226a5be862SDoug Rabson outb(SMC935_CFG, 0xaa); /* exit config mode */
9236a5be862SDoug Rabson return (-1);
9246a5be862SDoug Rabson }
9256a5be862SDoug Rabson
9266a5be862SDoug Rabson ppc->ppc_model = type;
9276a5be862SDoug Rabson
9286a5be862SDoug Rabson outb(SMC935_IND, SMC935_LOGDEV); /* select parallel port, */
9296a5be862SDoug Rabson outb(SMC935_DAT, 3); /* which is logical device 3 */
9306a5be862SDoug Rabson
9316a5be862SDoug Rabson /* set io port base */
9326a5be862SDoug Rabson outb(SMC935_IND, SMC935_PORTHI);
9336a5be862SDoug Rabson outb(SMC935_DAT, (u_char)((ppc->ppc_base & 0xff00) >> 8));
9346a5be862SDoug Rabson outb(SMC935_IND, SMC935_PORTLO);
9356a5be862SDoug Rabson outb(SMC935_DAT, (u_char)(ppc->ppc_base & 0xff));
9366a5be862SDoug Rabson
9376a5be862SDoug Rabson if (!chipset_mode)
9386a5be862SDoug Rabson ppc->ppc_avm = PPB_COMPATIBLE; /* default mode */
9396a5be862SDoug Rabson else {
9406a5be862SDoug Rabson ppc->ppc_avm = chipset_mode;
9416a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9426a5be862SDoug Rabson outb(SMC935_DAT, SMC935_CENT); /* start in compatible mode */
9436a5be862SDoug Rabson
9446a5be862SDoug Rabson /* SPP + EPP or just plain SPP */
9456a5be862SDoug Rabson if (chipset_mode & (PPB_SPP)) {
9466a5be862SDoug Rabson if (chipset_mode & PPB_EPP) {
9476a5be862SDoug Rabson if (ppc->ppc_epp == EPP_1_9) {
9486a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9496a5be862SDoug Rabson outb(SMC935_DAT, SMC935_EPP19SPP);
9506a5be862SDoug Rabson }
9516a5be862SDoug Rabson if (ppc->ppc_epp == EPP_1_7) {
9526a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9536a5be862SDoug Rabson outb(SMC935_DAT, SMC935_EPP17SPP);
9546a5be862SDoug Rabson }
9556a5be862SDoug Rabson } else {
9566a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9576a5be862SDoug Rabson outb(SMC935_DAT, SMC935_SPP);
9586a5be862SDoug Rabson }
9596a5be862SDoug Rabson }
9606a5be862SDoug Rabson
9616a5be862SDoug Rabson /* ECP + EPP or just plain ECP */
9626a5be862SDoug Rabson if (chipset_mode & PPB_ECP) {
9636a5be862SDoug Rabson if (chipset_mode & PPB_EPP) {
9646a5be862SDoug Rabson if (ppc->ppc_epp == EPP_1_9) {
9656a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9666a5be862SDoug Rabson outb(SMC935_DAT, SMC935_ECPEPP19);
9676a5be862SDoug Rabson }
9686a5be862SDoug Rabson if (ppc->ppc_epp == EPP_1_7) {
9696a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9706a5be862SDoug Rabson outb(SMC935_DAT, SMC935_ECPEPP17);
9716a5be862SDoug Rabson }
9726a5be862SDoug Rabson } else {
9736a5be862SDoug Rabson outb(SMC935_IND, SMC935_PPMODE);
9746a5be862SDoug Rabson outb(SMC935_DAT, SMC935_ECP);
9756a5be862SDoug Rabson }
9766a5be862SDoug Rabson }
9776a5be862SDoug Rabson }
9786a5be862SDoug Rabson
9796a5be862SDoug Rabson outb(SMC935_CFG, 0xaa); /* exit config mode */
9806a5be862SDoug Rabson
9816a5be862SDoug Rabson ppc->ppc_type = PPC_TYPE_SMCLIKE;
9826a5be862SDoug Rabson ppc_smclike_setmode(ppc, chipset_mode);
9836a5be862SDoug Rabson
9846a5be862SDoug Rabson return (chipset_mode);
9856a5be862SDoug Rabson }
9866a5be862SDoug Rabson
9876a5be862SDoug Rabson /*
98846f3ff79SMike Smith * Winbond W83877F stuff
98946f3ff79SMike Smith *
99046f3ff79SMike Smith * EFER: extended function enable register
99146f3ff79SMike Smith * EFIR: extended function index register
99246f3ff79SMike Smith * EFDR: extended function data register
99346f3ff79SMike Smith */
99446f3ff79SMike Smith #define efir ((efer == 0x250) ? 0x251 : 0x3f0)
99546f3ff79SMike Smith #define efdr ((efer == 0x250) ? 0x252 : 0x3f1)
99646f3ff79SMike Smith
99746f3ff79SMike Smith static int w83877f_efers[] = { 0x250, 0x3f0, 0x3f0, 0x250 };
99846f3ff79SMike Smith static int w83877f_keys[] = { 0x89, 0x86, 0x87, 0x88 };
99946f3ff79SMike Smith static int w83877f_keyiter[] = { 1, 2, 2, 1 };
100046f3ff79SMike Smith static int w83877f_hefs[] = { WINB_HEFERE, WINB_HEFRAS, WINB_HEFERE | WINB_HEFRAS, 0 };
100167646539SMike Smith
100267646539SMike Smith static int
ppc_w83877f_detect(struct ppc_data * ppc,int chipset_mode)100346f3ff79SMike Smith ppc_w83877f_detect(struct ppc_data *ppc, int chipset_mode)
100467646539SMike Smith {
1005f1d19042SArchie Cobbs int i, j, efer;
100646f3ff79SMike Smith unsigned char r, hefere, hefras;
100767646539SMike Smith
100846f3ff79SMike Smith for (i = 0; i < 4; i ++) {
100946f3ff79SMike Smith /* first try to enable configuration registers */
101046f3ff79SMike Smith efer = w83877f_efers[i];
101167646539SMike Smith
101246f3ff79SMike Smith /* write the key to the EFER */
101346f3ff79SMike Smith for (j = 0; j < w83877f_keyiter[i]; j ++)
101446f3ff79SMike Smith outb (efer, w83877f_keys[i]);
101546f3ff79SMike Smith
101646f3ff79SMike Smith /* then check HEFERE and HEFRAS bits */
101746f3ff79SMike Smith outb (efir, 0x0c);
101846f3ff79SMike Smith hefere = inb(efdr) & WINB_HEFERE;
101946f3ff79SMike Smith
102046f3ff79SMike Smith outb (efir, 0x16);
102146f3ff79SMike Smith hefras = inb(efdr) & WINB_HEFRAS;
102246f3ff79SMike Smith
102346f3ff79SMike Smith /*
102446f3ff79SMike Smith * HEFRAS HEFERE
102546f3ff79SMike Smith * 0 1 write 89h to 250h (power-on default)
102646f3ff79SMike Smith * 1 0 write 86h twice to 3f0h
102746f3ff79SMike Smith * 1 1 write 87h twice to 3f0h
102846f3ff79SMike Smith * 0 0 write 88h to 250h
102946f3ff79SMike Smith */
103046f3ff79SMike Smith if ((hefere | hefras) == w83877f_hefs[i])
103146f3ff79SMike Smith goto found;
103267646539SMike Smith }
103367646539SMike Smith
103446f3ff79SMike Smith return (-1); /* failed */
103567646539SMike Smith
103646f3ff79SMike Smith found:
103746f3ff79SMike Smith /* check base port address - read from CR23 */
103846f3ff79SMike Smith outb(efir, 0x23);
103946f3ff79SMike Smith if (ppc->ppc_base != inb(efdr) * 4) /* 4 bytes boundaries */
104046f3ff79SMike Smith return (-1);
104146f3ff79SMike Smith
104246f3ff79SMike Smith /* read CHIP ID from CR9/bits0-3 */
104346f3ff79SMike Smith outb(efir, 0x9);
104446f3ff79SMike Smith
104546f3ff79SMike Smith switch (inb(efdr) & WINB_CHIPID) {
104646f3ff79SMike Smith case WINB_W83877F_ID:
10470f210c92SNicolas Souchu ppc->ppc_model = WINB_W83877F;
104846f3ff79SMike Smith break;
104946f3ff79SMike Smith
105046f3ff79SMike Smith case WINB_W83877AF_ID:
10510f210c92SNicolas Souchu ppc->ppc_model = WINB_W83877AF;
105246f3ff79SMike Smith break;
105346f3ff79SMike Smith
105446f3ff79SMike Smith default:
10550f210c92SNicolas Souchu ppc->ppc_model = WINB_UNKNOWN;
105646f3ff79SMike Smith }
105746f3ff79SMike Smith
105846f3ff79SMike Smith if (bootverbose) {
105946f3ff79SMike Smith /* dump of registers */
1060ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "0x%x - ", w83877f_keys[i]);
106146f3ff79SMike Smith for (i = 0; i <= 0xd; i ++) {
106246f3ff79SMike Smith outb(efir, i);
106346f3ff79SMike Smith printf("0x%x ", inb(efdr));
106446f3ff79SMike Smith }
106546f3ff79SMike Smith for (i = 0x10; i <= 0x17; i ++) {
106646f3ff79SMike Smith outb(efir, i);
106746f3ff79SMike Smith printf("0x%x ", inb(efdr));
106846f3ff79SMike Smith }
106946f3ff79SMike Smith outb(efir, 0x1e);
107046f3ff79SMike Smith printf("0x%x ", inb(efdr));
107146f3ff79SMike Smith for (i = 0x20; i <= 0x29; i ++) {
107246f3ff79SMike Smith outb(efir, i);
107346f3ff79SMike Smith printf("0x%x ", inb(efdr));
107446f3ff79SMike Smith }
107546f3ff79SMike Smith printf("\n");
107646f3ff79SMike Smith }
107746f3ff79SMike Smith
10780f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_GENERIC;
1079edcfcf27SNicolas Souchu
108046f3ff79SMike Smith if (!chipset_mode) {
108146f3ff79SMike Smith /* autodetect mode */
108246f3ff79SMike Smith
108346f3ff79SMike Smith /* select CR0 */
108446f3ff79SMike Smith outb(efir, 0x0);
108546f3ff79SMike Smith r = inb(efdr) & (WINB_PRTMODS0 | WINB_PRTMODS1);
108646f3ff79SMike Smith
108746f3ff79SMike Smith /* select CR9 */
108846f3ff79SMike Smith outb(efir, 0x9);
108946f3ff79SMike Smith r |= (inb(efdr) & WINB_PRTMODS2);
109046f3ff79SMike Smith
109146f3ff79SMike Smith switch (r) {
109246f3ff79SMike Smith case WINB_W83757:
109346f3ff79SMike Smith if (bootverbose)
1094ff809674SJohn Baldwin device_printf(ppc->ppc_dev,
1095ff809674SJohn Baldwin "W83757 compatible mode\n");
109646f3ff79SMike Smith return (-1); /* generic or SMC-like */
109746f3ff79SMike Smith
109846f3ff79SMike Smith case WINB_EXTFDC:
109946f3ff79SMike Smith case WINB_EXTADP:
110046f3ff79SMike Smith case WINB_EXT2FDD:
110146f3ff79SMike Smith case WINB_JOYSTICK:
110246f3ff79SMike Smith if (bootverbose)
1103ff809674SJohn Baldwin device_printf(ppc->ppc_dev,
1104ae6b868aSJohn Baldwin "not in parallel port mode\n");
110546f3ff79SMike Smith return (-1);
110646f3ff79SMike Smith
110746f3ff79SMike Smith case (WINB_PARALLEL | WINB_EPP_SPP):
110846f3ff79SMike Smith ppc->ppc_avm |= PPB_EPP | PPB_SPP;
1109edcfcf27SNicolas Souchu if (bootverbose)
1110ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "EPP SPP\n");
111146f3ff79SMike Smith break;
111246f3ff79SMike Smith
111346f3ff79SMike Smith case (WINB_PARALLEL | WINB_ECP):
111446f3ff79SMike Smith ppc->ppc_avm |= PPB_ECP | PPB_SPP;
1115edcfcf27SNicolas Souchu if (bootverbose)
1116ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "ECP SPP\n");
111746f3ff79SMike Smith break;
111846f3ff79SMike Smith
111946f3ff79SMike Smith case (WINB_PARALLEL | WINB_ECP_EPP):
112046f3ff79SMike Smith ppc->ppc_avm |= PPB_ECP | PPB_EPP | PPB_SPP;
11210f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_SMCLIKE;
1122edcfcf27SNicolas Souchu
1123edcfcf27SNicolas Souchu if (bootverbose)
1124ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "ECP+EPP SPP\n");
112546f3ff79SMike Smith break;
112646f3ff79SMike Smith default:
11276e551fb6SDavid E. O'Brien printf("%s: unknown case (0x%x)!\n", __func__, r);
112846f3ff79SMike Smith }
112946f3ff79SMike Smith
113046f3ff79SMike Smith } else {
113146f3ff79SMike Smith /* mode forced */
113246f3ff79SMike Smith
113346f3ff79SMike Smith /* select CR9 and set PRTMODS2 bit */
113446f3ff79SMike Smith outb(efir, 0x9);
113546f3ff79SMike Smith outb(efdr, inb(efdr) & ~WINB_PRTMODS2);
113646f3ff79SMike Smith
113746f3ff79SMike Smith /* select CR0 and reset PRTMODSx bits */
113846f3ff79SMike Smith outb(efir, 0x0);
113946f3ff79SMike Smith outb(efdr, inb(efdr) & ~(WINB_PRTMODS0 | WINB_PRTMODS1));
114046f3ff79SMike Smith
114146f3ff79SMike Smith if (chipset_mode & PPB_ECP) {
1142edcfcf27SNicolas Souchu if (chipset_mode & PPB_EPP) {
114346f3ff79SMike Smith outb(efdr, inb(efdr) | WINB_ECP_EPP);
1144edcfcf27SNicolas Souchu if (bootverbose)
1145ff809674SJohn Baldwin device_printf(ppc->ppc_dev,
1146ff809674SJohn Baldwin "ECP+EPP\n");
1147edcfcf27SNicolas Souchu
11480f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_SMCLIKE;
1149edcfcf27SNicolas Souchu
1150edcfcf27SNicolas Souchu } else {
115146f3ff79SMike Smith outb(efdr, inb(efdr) | WINB_ECP);
1152edcfcf27SNicolas Souchu if (bootverbose)
1153ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "ECP\n");
1154edcfcf27SNicolas Souchu }
115546f3ff79SMike Smith } else {
115646f3ff79SMike Smith /* select EPP_SPP otherwise */
115746f3ff79SMike Smith outb(efdr, inb(efdr) | WINB_EPP_SPP);
1158edcfcf27SNicolas Souchu if (bootverbose)
1159ff809674SJohn Baldwin device_printf(ppc->ppc_dev, "EPP SPP\n");
116046f3ff79SMike Smith }
116146f3ff79SMike Smith ppc->ppc_avm = chipset_mode;
116246f3ff79SMike Smith }
116346f3ff79SMike Smith
116446f3ff79SMike Smith /* exit configuration mode */
116546f3ff79SMike Smith outb(efer, 0xaa);
116646f3ff79SMike Smith
11670f210c92SNicolas Souchu switch (ppc->ppc_type) {
11680f210c92SNicolas Souchu case PPC_TYPE_SMCLIKE:
11690f210c92SNicolas Souchu ppc_smclike_setmode(ppc, chipset_mode);
11700f210c92SNicolas Souchu break;
11710f210c92SNicolas Souchu default:
11720f210c92SNicolas Souchu ppc_generic_setmode(ppc, chipset_mode);
11730f210c92SNicolas Souchu break;
11740f210c92SNicolas Souchu }
117546f3ff79SMike Smith
117646f3ff79SMike Smith return (chipset_mode);
117767646539SMike Smith }
11780f210c92SNicolas Souchu #endif
117967646539SMike Smith
118067646539SMike Smith /*
118167646539SMike Smith * ppc_generic_detect
118267646539SMike Smith */
118367646539SMike Smith static int
ppc_generic_detect(struct ppc_data * ppc,int chipset_mode)118446f3ff79SMike Smith ppc_generic_detect(struct ppc_data *ppc, int chipset_mode)
118567646539SMike Smith {
1186edcfcf27SNicolas Souchu /* default to generic */
11870f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_GENERIC;
1188edcfcf27SNicolas Souchu
1189edcfcf27SNicolas Souchu if (bootverbose)
1190ae6b868aSJohn Baldwin device_printf(ppc->ppc_dev, "SPP");
1191edcfcf27SNicolas Souchu
119246f3ff79SMike Smith /* first, check for ECP */
1193bc35c174SNicolas Souchu w_ecr(ppc, PPC_ECR_PS2);
1194bc35c174SNicolas Souchu if ((r_ecr(ppc) & 0xe0) == PPC_ECR_PS2) {
1195c264e80fSNicolas Souchu ppc->ppc_dtm |= PPB_ECP | PPB_SPP;
1196edcfcf27SNicolas Souchu if (bootverbose)
1197ae6b868aSJohn Baldwin printf(" ECP ");
119846f3ff79SMike Smith
119946f3ff79SMike Smith /* search for SMC style ECP+EPP mode */
1200bc35c174SNicolas Souchu w_ecr(ppc, PPC_ECR_EPP);
120146f3ff79SMike Smith }
120267646539SMike Smith
120367646539SMike Smith /* try to reset EPP timeout bit */
120446f3ff79SMike Smith if (ppc_check_epp_timeout(ppc)) {
1205c264e80fSNicolas Souchu ppc->ppc_dtm |= PPB_EPP;
120667646539SMike Smith
1207c264e80fSNicolas Souchu if (ppc->ppc_dtm & PPB_ECP) {
120846f3ff79SMike Smith /* SMC like chipset found */
12090f210c92SNicolas Souchu ppc->ppc_model = SMC_LIKE;
12100f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_SMCLIKE;
1211edcfcf27SNicolas Souchu
1212edcfcf27SNicolas Souchu if (bootverbose)
1213edcfcf27SNicolas Souchu printf(" ECP+EPP");
1214edcfcf27SNicolas Souchu } else {
1215edcfcf27SNicolas Souchu if (bootverbose)
1216edcfcf27SNicolas Souchu printf(" EPP");
1217edcfcf27SNicolas Souchu }
1218edcfcf27SNicolas Souchu } else {
1219edcfcf27SNicolas Souchu /* restore to standard mode */
1220bc35c174SNicolas Souchu w_ecr(ppc, PPC_ECR_STD);
122167646539SMike Smith }
122267646539SMike Smith
1223edcfcf27SNicolas Souchu /* XXX try to detect NIBBLE and PS2 modes */
1224c264e80fSNicolas Souchu ppc->ppc_dtm |= PPB_NIBBLE;
122567646539SMike Smith
1226c264e80fSNicolas Souchu if (chipset_mode)
1227edcfcf27SNicolas Souchu ppc->ppc_avm = chipset_mode;
1228c264e80fSNicolas Souchu else
1229c264e80fSNicolas Souchu ppc->ppc_avm = ppc->ppc_dtm;
1230edcfcf27SNicolas Souchu
1231edcfcf27SNicolas Souchu if (bootverbose)
1232edcfcf27SNicolas Souchu printf("\n");
1233edcfcf27SNicolas Souchu
12340f210c92SNicolas Souchu switch (ppc->ppc_type) {
12350f210c92SNicolas Souchu case PPC_TYPE_SMCLIKE:
12360f210c92SNicolas Souchu ppc_smclike_setmode(ppc, chipset_mode);
12370f210c92SNicolas Souchu break;
12380f210c92SNicolas Souchu default:
12390f210c92SNicolas Souchu ppc_generic_setmode(ppc, chipset_mode);
12400f210c92SNicolas Souchu break;
12410f210c92SNicolas Souchu }
124246f3ff79SMike Smith
124346f3ff79SMike Smith return (chipset_mode);
124467646539SMike Smith }
124567646539SMike Smith
124667646539SMike Smith /*
124767646539SMike Smith * ppc_detect()
124867646539SMike Smith *
124967646539SMike Smith * mode is the mode suggested at boot
125067646539SMike Smith */
125167646539SMike Smith static int
ppc_detect(struct ppc_data * ppc,int chipset_mode)125246f3ff79SMike Smith ppc_detect(struct ppc_data *ppc, int chipset_mode) {
12530f210c92SNicolas Souchu #ifdef PPC_PROBE_CHIPSET
125446f3ff79SMike Smith int i, mode;
125567646539SMike Smith
125646f3ff79SMike Smith /* list of supported chipsets */
125746f3ff79SMike Smith int (*chipset_detect[])(struct ppc_data *, int) = {
125846f3ff79SMike Smith ppc_pc873xx_detect,
125946f3ff79SMike Smith ppc_smc37c66xgt_detect,
126046f3ff79SMike Smith ppc_w83877f_detect,
12616a5be862SDoug Rabson ppc_smc37c935_detect,
126246f3ff79SMike Smith ppc_generic_detect,
126346f3ff79SMike Smith NULL
126446f3ff79SMike Smith };
12650f210c92SNicolas Souchu #endif
126667646539SMike Smith
126746f3ff79SMike Smith /* if can't find the port and mode not forced return error */
126846f3ff79SMike Smith if (!ppc_detect_port(ppc) && chipset_mode == 0)
126946f3ff79SMike Smith return (EIO); /* failed, port not present */
127067646539SMike Smith
127146f3ff79SMike Smith /* assume centronics compatible mode is supported */
127246f3ff79SMike Smith ppc->ppc_avm = PPB_COMPATIBLE;
127367646539SMike Smith
12740f210c92SNicolas Souchu #ifdef PPC_PROBE_CHIPSET
127546f3ff79SMike Smith /* we have to differenciate available chipset modes,
127646f3ff79SMike Smith * chipset running modes and IEEE-1284 operating modes
127746f3ff79SMike Smith *
127846f3ff79SMike Smith * after detection, the port must support running in compatible mode
127946f3ff79SMike Smith */
1280af548787SNicolas Souchu if (ppc->ppc_flags & 0x40) {
1281af548787SNicolas Souchu if (bootverbose)
1282af548787SNicolas Souchu printf("ppc: chipset forced to generic\n");
12830f210c92SNicolas Souchu #endif
1284af548787SNicolas Souchu
1285af548787SNicolas Souchu ppc->ppc_mode = ppc_generic_detect(ppc, chipset_mode);
1286af548787SNicolas Souchu
12870f210c92SNicolas Souchu #ifdef PPC_PROBE_CHIPSET
1288af548787SNicolas Souchu } else {
128946f3ff79SMike Smith for (i=0; chipset_detect[i] != NULL; i++) {
129046f3ff79SMike Smith if ((mode = chipset_detect[i](ppc, chipset_mode)) != -1) {
129146f3ff79SMike Smith ppc->ppc_mode = mode;
129246f3ff79SMike Smith break;
129346f3ff79SMike Smith }
129446f3ff79SMike Smith }
1295af548787SNicolas Souchu }
12960f210c92SNicolas Souchu #endif
129746f3ff79SMike Smith
1298bc35c174SNicolas Souchu /* configure/detect ECP FIFO */
1299bc35c174SNicolas Souchu if ((ppc->ppc_avm & PPB_ECP) && !(ppc->ppc_flags & 0x80))
1300bc35c174SNicolas Souchu ppc_detect_fifo(ppc);
1301bc35c174SNicolas Souchu
130246f3ff79SMike Smith return (0);
130346f3ff79SMike Smith }
130446f3ff79SMike Smith
130546f3ff79SMike Smith /*
130646f3ff79SMike Smith * ppc_exec_microseq()
130746f3ff79SMike Smith *
130846f3ff79SMike Smith * Execute a microsequence.
130946f3ff79SMike Smith * Microsequence mechanism is supposed to handle fast I/O operations.
131046f3ff79SMike Smith */
1311a3732274SDoug Ambrisko int
ppc_exec_microseq(device_t dev,struct ppb_microseq ** p_msq)13120f210c92SNicolas Souchu ppc_exec_microseq(device_t dev, struct ppb_microseq **p_msq)
131346f3ff79SMike Smith {
13140f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(dev);
13150a40e22aSNicolas Souchu struct ppb_microseq *mi;
131646f3ff79SMike Smith char cc, *p;
131754ad6085SNicolas Souchu int i, iter, len;
131846f3ff79SMike Smith int error;
131946f3ff79SMike Smith
13203e85b721SEd Maste int reg;
13213e85b721SEd Maste char mask;
13223e85b721SEd Maste int accum = 0;
13233e85b721SEd Maste char *ptr = NULL;
132446f3ff79SMike Smith
13254d24901aSPedro F. Giffuni struct ppb_microseq *stack = NULL;
132646f3ff79SMike Smith
132746f3ff79SMike Smith /* microsequence registers are equivalent to PC-like port registers */
13283ae3f8b0SNicolas Souchu
13298fd40d8aSJohn Baldwin #define r_reg(reg,ppc) (bus_read_1((ppc)->res_ioport, reg))
13308fd40d8aSJohn Baldwin #define w_reg(reg, ppc, byte) (bus_write_1((ppc)->res_ioport, reg, byte))
133146f3ff79SMike Smith
13320a40e22aSNicolas Souchu #define INCR_PC (mi ++) /* increment program counter */
133346f3ff79SMike Smith
13342067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
13350a40e22aSNicolas Souchu mi = *p_msq;
133646f3ff79SMike Smith for (;;) {
133746f3ff79SMike Smith switch (mi->opcode) {
133846f3ff79SMike Smith case MS_OP_RSET:
133946f3ff79SMike Smith cc = r_reg(mi->arg[0].i, ppc);
134054ad6085SNicolas Souchu cc &= (char)mi->arg[2].i; /* clear mask */
134154ad6085SNicolas Souchu cc |= (char)mi->arg[1].i; /* assert mask */
134246f3ff79SMike Smith w_reg(mi->arg[0].i, ppc, cc);
134346f3ff79SMike Smith INCR_PC;
134446f3ff79SMike Smith break;
134546f3ff79SMike Smith
134646f3ff79SMike Smith case MS_OP_RASSERT_P:
134754ad6085SNicolas Souchu reg = mi->arg[1].i;
134854ad6085SNicolas Souchu ptr = ppc->ppc_ptr;
134954ad6085SNicolas Souchu
135054ad6085SNicolas Souchu if ((len = mi->arg[0].i) == MS_ACCUM) {
135154ad6085SNicolas Souchu accum = ppc->ppc_accum;
135254ad6085SNicolas Souchu for (; accum; accum--)
135354ad6085SNicolas Souchu w_reg(reg, ppc, *ptr++);
135454ad6085SNicolas Souchu ppc->ppc_accum = accum;
135554ad6085SNicolas Souchu } else
135654ad6085SNicolas Souchu for (i=0; i<len; i++)
135754ad6085SNicolas Souchu w_reg(reg, ppc, *ptr++);
135854ad6085SNicolas Souchu ppc->ppc_ptr = ptr;
135954ad6085SNicolas Souchu
136046f3ff79SMike Smith INCR_PC;
136146f3ff79SMike Smith break;
136246f3ff79SMike Smith
136346f3ff79SMike Smith case MS_OP_RFETCH_P:
136454ad6085SNicolas Souchu reg = mi->arg[1].i;
136554ad6085SNicolas Souchu mask = (char)mi->arg[2].i;
136654ad6085SNicolas Souchu ptr = ppc->ppc_ptr;
136754ad6085SNicolas Souchu
136854ad6085SNicolas Souchu if ((len = mi->arg[0].i) == MS_ACCUM) {
136954ad6085SNicolas Souchu accum = ppc->ppc_accum;
137054ad6085SNicolas Souchu for (; accum; accum--)
137154ad6085SNicolas Souchu *ptr++ = r_reg(reg, ppc) & mask;
137254ad6085SNicolas Souchu ppc->ppc_accum = accum;
137354ad6085SNicolas Souchu } else
137454ad6085SNicolas Souchu for (i=0; i<len; i++)
137554ad6085SNicolas Souchu *ptr++ = r_reg(reg, ppc) & mask;
137654ad6085SNicolas Souchu ppc->ppc_ptr = ptr;
137754ad6085SNicolas Souchu
137846f3ff79SMike Smith INCR_PC;
137946f3ff79SMike Smith break;
138046f3ff79SMike Smith
138146f3ff79SMike Smith case MS_OP_RFETCH:
138246f3ff79SMike Smith *((char *) mi->arg[2].p) = r_reg(mi->arg[0].i, ppc) &
138354ad6085SNicolas Souchu (char)mi->arg[1].i;
138446f3ff79SMike Smith INCR_PC;
138546f3ff79SMike Smith break;
138646f3ff79SMike Smith
138746f3ff79SMike Smith case MS_OP_RASSERT:
138854ad6085SNicolas Souchu case MS_OP_DELAY:
138946f3ff79SMike Smith
139046f3ff79SMike Smith /* let's suppose the next instr. is the same */
139146f3ff79SMike Smith prefetch:
139246f3ff79SMike Smith for (;mi->opcode == MS_OP_RASSERT; INCR_PC)
139354ad6085SNicolas Souchu w_reg(mi->arg[0].i, ppc, (char)mi->arg[1].i);
139446f3ff79SMike Smith
139546f3ff79SMike Smith if (mi->opcode == MS_OP_DELAY) {
139646f3ff79SMike Smith DELAY(mi->arg[0].i);
139746f3ff79SMike Smith INCR_PC;
139846f3ff79SMike Smith goto prefetch;
139946f3ff79SMike Smith }
140046f3ff79SMike Smith break;
140146f3ff79SMike Smith
140254ad6085SNicolas Souchu case MS_OP_ADELAY:
14032067d312SJohn Baldwin if (mi->arg[0].i) {
14042067d312SJohn Baldwin PPC_UNLOCK(ppc);
1405a96255b6SJohn Baldwin pause("ppbdelay", mi->arg[0].i * (hz/1000));
14062067d312SJohn Baldwin PPC_LOCK(ppc);
14072067d312SJohn Baldwin }
140846f3ff79SMike Smith INCR_PC;
140946f3ff79SMike Smith break;
141046f3ff79SMike Smith
141146f3ff79SMike Smith case MS_OP_TRIG:
141246f3ff79SMike Smith reg = mi->arg[0].i;
141346f3ff79SMike Smith iter = mi->arg[1].i;
141446f3ff79SMike Smith p = (char *)mi->arg[2].p;
141546f3ff79SMike Smith
141654ad6085SNicolas Souchu /* XXX delay limited to 255 us */
141746f3ff79SMike Smith for (i=0; i<iter; i++) {
141846f3ff79SMike Smith w_reg(reg, ppc, *p++);
141946f3ff79SMike Smith DELAY((unsigned char)*p++);
142046f3ff79SMike Smith }
142146f3ff79SMike Smith INCR_PC;
142246f3ff79SMike Smith break;
142346f3ff79SMike Smith
142446f3ff79SMike Smith case MS_OP_SET:
142554ad6085SNicolas Souchu ppc->ppc_accum = mi->arg[0].i;
142646f3ff79SMike Smith INCR_PC;
142746f3ff79SMike Smith break;
142846f3ff79SMike Smith
142946f3ff79SMike Smith case MS_OP_DBRA:
143054ad6085SNicolas Souchu if (--ppc->ppc_accum > 0)
14310a40e22aSNicolas Souchu mi += mi->arg[0].i;
143246f3ff79SMike Smith INCR_PC;
143346f3ff79SMike Smith break;
143446f3ff79SMike Smith
143546f3ff79SMike Smith case MS_OP_BRSET:
143646f3ff79SMike Smith cc = r_str(ppc);
143754ad6085SNicolas Souchu if ((cc & (char)mi->arg[0].i) == (char)mi->arg[0].i)
14380a40e22aSNicolas Souchu mi += mi->arg[1].i;
143946f3ff79SMike Smith INCR_PC;
144046f3ff79SMike Smith break;
144146f3ff79SMike Smith
144246f3ff79SMike Smith case MS_OP_BRCLEAR:
144346f3ff79SMike Smith cc = r_str(ppc);
144454ad6085SNicolas Souchu if ((cc & (char)mi->arg[0].i) == 0)
14450a40e22aSNicolas Souchu mi += mi->arg[1].i;
144646f3ff79SMike Smith INCR_PC;
144746f3ff79SMike Smith break;
144846f3ff79SMike Smith
144954ad6085SNicolas Souchu case MS_OP_BRSTAT:
145054ad6085SNicolas Souchu cc = r_str(ppc);
145154ad6085SNicolas Souchu if ((cc & ((char)mi->arg[0].i | (char)mi->arg[1].i)) ==
145254ad6085SNicolas Souchu (char)mi->arg[0].i)
14530a40e22aSNicolas Souchu mi += mi->arg[2].i;
145454ad6085SNicolas Souchu INCR_PC;
145554ad6085SNicolas Souchu break;
145654ad6085SNicolas Souchu
145746f3ff79SMike Smith case MS_OP_C_CALL:
145846f3ff79SMike Smith /*
145946f3ff79SMike Smith * If the C call returns !0 then end the microseq.
146046f3ff79SMike Smith * The current state of ptr is passed to the C function
146146f3ff79SMike Smith */
146254ad6085SNicolas Souchu if ((error = mi->arg[0].f(mi->arg[1].p, ppc->ppc_ptr)))
146346f3ff79SMike Smith return (error);
146446f3ff79SMike Smith
146546f3ff79SMike Smith INCR_PC;
146646f3ff79SMike Smith break;
146746f3ff79SMike Smith
146846f3ff79SMike Smith case MS_OP_PTR:
146954ad6085SNicolas Souchu ppc->ppc_ptr = (char *)mi->arg[0].p;
147046f3ff79SMike Smith INCR_PC;
147146f3ff79SMike Smith break;
147246f3ff79SMike Smith
147346f3ff79SMike Smith case MS_OP_CALL:
14740a40e22aSNicolas Souchu if (stack)
14756e551fb6SDavid E. O'Brien panic("%s: too much calls", __func__);
147646f3ff79SMike Smith
147746f3ff79SMike Smith if (mi->arg[0].p) {
147846f3ff79SMike Smith /* store the state of the actual
147946f3ff79SMike Smith * microsequence
148046f3ff79SMike Smith */
14810a40e22aSNicolas Souchu stack = mi;
148246f3ff79SMike Smith
148346f3ff79SMike Smith /* jump to the new microsequence */
14840a40e22aSNicolas Souchu mi = (struct ppb_microseq *)mi->arg[0].p;
148546f3ff79SMike Smith } else
148646f3ff79SMike Smith INCR_PC;
148746f3ff79SMike Smith
148846f3ff79SMike Smith break;
148946f3ff79SMike Smith
149046f3ff79SMike Smith case MS_OP_SUBRET:
149146f3ff79SMike Smith /* retrieve microseq and pc state before the call */
14920a40e22aSNicolas Souchu mi = stack;
149346f3ff79SMike Smith
149446f3ff79SMike Smith /* reset the stack */
14954d24901aSPedro F. Giffuni stack = NULL;
149646f3ff79SMike Smith
149746f3ff79SMike Smith /* XXX return code */
149846f3ff79SMike Smith
149946f3ff79SMike Smith INCR_PC;
150046f3ff79SMike Smith break;
150146f3ff79SMike Smith
150246f3ff79SMike Smith case MS_OP_PUT:
150346f3ff79SMike Smith case MS_OP_GET:
150446f3ff79SMike Smith case MS_OP_RET:
150546f3ff79SMike Smith /* can't return to ppb level during the execution
150646f3ff79SMike Smith * of a submicrosequence */
15070a40e22aSNicolas Souchu if (stack)
150846f3ff79SMike Smith panic("%s: can't return to ppb level",
15096e551fb6SDavid E. O'Brien __func__);
151046f3ff79SMike Smith
151146f3ff79SMike Smith /* update pc for ppb level of execution */
15120a40e22aSNicolas Souchu *p_msq = mi;
151346f3ff79SMike Smith
151446f3ff79SMike Smith /* return to ppb level of execution */
151546f3ff79SMike Smith return (0);
151646f3ff79SMike Smith
151746f3ff79SMike Smith default:
151846f3ff79SMike Smith panic("%s: unknown microsequence opcode 0x%x",
15196e551fb6SDavid E. O'Brien __func__, mi->opcode);
152046f3ff79SMike Smith }
152146f3ff79SMike Smith }
152246f3ff79SMike Smith
152346f3ff79SMike Smith /* unreached */
152446f3ff79SMike Smith }
152546f3ff79SMike Smith
1526bc35c174SNicolas Souchu static void
ppcintr(void * arg)15270f210c92SNicolas Souchu ppcintr(void *arg)
1528bc35c174SNicolas Souchu {
1529ca3d3795SJohn Baldwin struct ppc_data *ppc = arg;
15303ab971c1SNicolas Souchu u_char ctr, ecr, str;
1531bc35c174SNicolas Souchu
1532ca3d3795SJohn Baldwin /*
1533ca3d3795SJohn Baldwin * If we have any child interrupt handlers registered, let
1534ca3d3795SJohn Baldwin * them handle this interrupt.
1535ca3d3795SJohn Baldwin *
1536ca3d3795SJohn Baldwin * XXX: If DMA is in progress should we just complete that w/o
1537ca3d3795SJohn Baldwin * doing this?
1538ca3d3795SJohn Baldwin */
15392067d312SJohn Baldwin PPC_LOCK(ppc);
15402067d312SJohn Baldwin if (ppc->ppc_intr_hook != NULL &&
15412067d312SJohn Baldwin ppc->ppc_intr_hook(ppc->ppc_intr_arg) == 0) {
15422067d312SJohn Baldwin PPC_UNLOCK(ppc);
1543ca3d3795SJohn Baldwin return;
1544ca3d3795SJohn Baldwin }
1545ca3d3795SJohn Baldwin
15463ab971c1SNicolas Souchu str = r_str(ppc);
1547bc35c174SNicolas Souchu ctr = r_ctr(ppc);
1548bc35c174SNicolas Souchu ecr = r_ecr(ppc);
1549bc35c174SNicolas Souchu
1550f4e98881SRuslan Ermilov #if defined(PPC_DEBUG) && PPC_DEBUG > 1
15513ab971c1SNicolas Souchu printf("![%x/%x/%x]", ctr, ecr, str);
1552bc35c174SNicolas Souchu #endif
1553bc35c174SNicolas Souchu
1554bc35c174SNicolas Souchu /* don't use ecp mode with IRQENABLE set */
1555bc35c174SNicolas Souchu if (ctr & IRQENABLE) {
15562067d312SJohn Baldwin PPC_UNLOCK(ppc);
1557bc35c174SNicolas Souchu return;
1558bc35c174SNicolas Souchu }
1559bc35c174SNicolas Souchu
15603ab971c1SNicolas Souchu /* interrupts are generated by nFault signal
15613ab971c1SNicolas Souchu * only in ECP mode */
15623ab971c1SNicolas Souchu if ((str & nFAULT) && (ppc->ppc_mode & PPB_ECP)) {
15633ab971c1SNicolas Souchu /* check if ppc driver has programmed the
15643ab971c1SNicolas Souchu * nFault interrupt */
1565bc35c174SNicolas Souchu if (ppc->ppc_irqstat & PPC_IRQ_nFAULT) {
1566bc35c174SNicolas Souchu w_ecr(ppc, ecr | PPC_nFAULT_INTR);
1567bc35c174SNicolas Souchu ppc->ppc_irqstat &= ~PPC_IRQ_nFAULT;
1568bc35c174SNicolas Souchu } else {
15690f210c92SNicolas Souchu /* shall be handled by underlying layers XXX */
15702067d312SJohn Baldwin PPC_UNLOCK(ppc);
1571bc35c174SNicolas Souchu return;
1572bc35c174SNicolas Souchu }
1573bc35c174SNicolas Souchu }
1574bc35c174SNicolas Souchu
1575bc35c174SNicolas Souchu if (ppc->ppc_irqstat & PPC_IRQ_DMA) {
1576bc35c174SNicolas Souchu /* disable interrupts (should be done by hardware though) */
1577bc35c174SNicolas Souchu w_ecr(ppc, ecr | PPC_SERVICE_INTR);
1578bc35c174SNicolas Souchu ppc->ppc_irqstat &= ~PPC_IRQ_DMA;
1579bc35c174SNicolas Souchu ecr = r_ecr(ppc);
1580bc35c174SNicolas Souchu
1581bc35c174SNicolas Souchu /* check if DMA completed */
1582bc35c174SNicolas Souchu if ((ppc->ppc_avm & PPB_ECP) && (ecr & PPC_ENABLE_DMA)) {
1583bc35c174SNicolas Souchu #ifdef PPC_DEBUG
1584bc35c174SNicolas Souchu printf("a");
1585bc35c174SNicolas Souchu #endif
1586bc35c174SNicolas Souchu /* stop DMA */
1587bc35c174SNicolas Souchu w_ecr(ppc, ecr & ~PPC_ENABLE_DMA);
1588bc35c174SNicolas Souchu ecr = r_ecr(ppc);
1589bc35c174SNicolas Souchu
1590bc35c174SNicolas Souchu if (ppc->ppc_dmastat == PPC_DMA_STARTED) {
1591bc35c174SNicolas Souchu #ifdef PPC_DEBUG
1592bc35c174SNicolas Souchu printf("d");
1593bc35c174SNicolas Souchu #endif
1594cea4d875SMarcel Moolenaar ppc->ppc_dmadone(ppc);
1595bc35c174SNicolas Souchu ppc->ppc_dmastat = PPC_DMA_COMPLETE;
1596bc35c174SNicolas Souchu
1597bc35c174SNicolas Souchu /* wakeup the waiting process */
1598521f364bSDag-Erling Smørgrav wakeup(ppc);
1599bc35c174SNicolas Souchu }
1600bc35c174SNicolas Souchu }
1601bc35c174SNicolas Souchu } else if (ppc->ppc_irqstat & PPC_IRQ_FIFO) {
1602bc35c174SNicolas Souchu /* classic interrupt I/O */
1603bc35c174SNicolas Souchu ppc->ppc_irqstat &= ~PPC_IRQ_FIFO;
1604bc35c174SNicolas Souchu }
16052067d312SJohn Baldwin PPC_UNLOCK(ppc);
1606bc35c174SNicolas Souchu
1607bc35c174SNicolas Souchu return;
1608bc35c174SNicolas Souchu }
1609bc35c174SNicolas Souchu
1610a3732274SDoug Ambrisko int
ppc_read(device_t dev,char * buf,int len,int mode)16110f210c92SNicolas Souchu ppc_read(device_t dev, char *buf, int len, int mode)
1612bc35c174SNicolas Souchu {
1613bc35c174SNicolas Souchu return (EINVAL);
1614bc35c174SNicolas Souchu }
1615bc35c174SNicolas Souchu
1616a3732274SDoug Ambrisko int
ppc_write(device_t dev,char * buf,int len,int how)16170f210c92SNicolas Souchu ppc_write(device_t dev, char *buf, int len, int how)
1618bc35c174SNicolas Souchu {
1619cea4d875SMarcel Moolenaar return (EINVAL);
1620bc35c174SNicolas Souchu }
1621bc35c174SNicolas Souchu
16223fd85273SWarner Losh int
ppc_reset_epp(device_t dev)16230f210c92SNicolas Souchu ppc_reset_epp(device_t dev)
162467646539SMike Smith {
16250f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(dev);
162667646539SMike Smith
16272067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
16280f210c92SNicolas Souchu ppc_reset_epp_timeout(ppc);
162967646539SMike Smith
16303fd85273SWarner Losh return 0;
163167646539SMike Smith }
163267646539SMike Smith
1633a3732274SDoug Ambrisko int
ppc_setmode(device_t dev,int mode)16340f210c92SNicolas Souchu ppc_setmode(device_t dev, int mode)
16350f210c92SNicolas Souchu {
16360f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(dev);
16370f210c92SNicolas Souchu
16382067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
16390f210c92SNicolas Souchu switch (ppc->ppc_type) {
16400f210c92SNicolas Souchu case PPC_TYPE_SMCLIKE:
16410f210c92SNicolas Souchu return (ppc_smclike_setmode(ppc, mode));
16420f210c92SNicolas Souchu break;
16430f210c92SNicolas Souchu
16440f210c92SNicolas Souchu case PPC_TYPE_GENERIC:
16450f210c92SNicolas Souchu default:
16460f210c92SNicolas Souchu return (ppc_generic_setmode(ppc, mode));
16470f210c92SNicolas Souchu break;
16480f210c92SNicolas Souchu }
16490f210c92SNicolas Souchu
16500f210c92SNicolas Souchu /* not reached */
16510f210c92SNicolas Souchu return (ENXIO);
16520f210c92SNicolas Souchu }
16530f210c92SNicolas Souchu
1654a3732274SDoug Ambrisko int
ppc_probe(device_t dev,int rid)1655cea4d875SMarcel Moolenaar ppc_probe(device_t dev, int rid)
1656a3732274SDoug Ambrisko {
165730cac8e3SJohn Baldwin struct ppc_data *ppc;
1658a3732274SDoug Ambrisko #ifdef __i386__
1659a3732274SDoug Ambrisko static short next_bios_ppc = 0;
1660a3732274SDoug Ambrisko int error;
16612dd1bdf1SJustin Hibbits rman_res_t port;
166230cac8e3SJohn Baldwin #endif
1663a3732274SDoug Ambrisko
166467646539SMike Smith /*
166567646539SMike Smith * Allocate the ppc_data structure.
166667646539SMike Smith */
16670f210c92SNicolas Souchu ppc = DEVTOSOFTC(dev);
166867646539SMike Smith bzero(ppc, sizeof(struct ppc_data));
166967646539SMike Smith
1670cea4d875SMarcel Moolenaar ppc->rid_ioport = rid;
167167646539SMike Smith
167230cac8e3SJohn Baldwin #ifdef __i386__
16730f210c92SNicolas Souchu /* retrieve ISA parameters */
1674cea4d875SMarcel Moolenaar error = bus_get_resource(dev, SYS_RES_IOPORT, rid, &port, NULL);
16750f210c92SNicolas Souchu
16760f210c92SNicolas Souchu /*
16770f210c92SNicolas Souchu * If port not specified, use bios list.
16780f210c92SNicolas Souchu */
1679d64d73c9SDoug Rabson if (error) {
16800f210c92SNicolas Souchu if ((next_bios_ppc < BIOS_MAX_PPC) &&
16810f210c92SNicolas Souchu (*(BIOS_PORTS + next_bios_ppc) != 0)) {
16820f210c92SNicolas Souchu port = *(BIOS_PORTS + next_bios_ppc++);
16830f210c92SNicolas Souchu if (bootverbose)
1684284c87f6SJohn Baldwin device_printf(dev,
1685da1b038aSJustin Hibbits "parallel port found at 0x%jx\n", port);
16860f210c92SNicolas Souchu } else {
16870f210c92SNicolas Souchu device_printf(dev, "parallel port not found.\n");
1688284c87f6SJohn Baldwin return (ENXIO);
16890f210c92SNicolas Souchu }
1690cea4d875SMarcel Moolenaar bus_set_resource(dev, SYS_RES_IOPORT, rid, port,
16916a5be862SDoug Rabson IO_LPTSIZE_EXTENDED);
16920f210c92SNicolas Souchu }
1693d64d73c9SDoug Rabson #endif
16940f210c92SNicolas Souchu
16950f210c92SNicolas Souchu /* IO port is mandatory */
16966a5be862SDoug Rabson
16976a5be862SDoug Rabson /* Try "extended" IO port range...*/
1698c47476d7SJustin Hibbits ppc->res_ioport = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT,
1699c47476d7SJustin Hibbits &ppc->rid_ioport,
1700c47476d7SJustin Hibbits IO_LPTSIZE_EXTENDED,
1701c47476d7SJustin Hibbits RF_ACTIVE);
17026a5be862SDoug Rabson
17036a5be862SDoug Rabson if (ppc->res_ioport != 0) {
17046a5be862SDoug Rabson if (bootverbose)
17056a5be862SDoug Rabson device_printf(dev, "using extended I/O port range\n");
17066a5be862SDoug Rabson } else {
17076a5be862SDoug Rabson /* Failed? If so, then try the "normal" IO port range... */
1708c47476d7SJustin Hibbits ppc->res_ioport = bus_alloc_resource_anywhere(dev,
1709c47476d7SJustin Hibbits SYS_RES_IOPORT,
1710c47476d7SJustin Hibbits &ppc->rid_ioport,
17116a5be862SDoug Rabson IO_LPTSIZE_NORMAL,
17126a5be862SDoug Rabson RF_ACTIVE);
17136a5be862SDoug Rabson if (ppc->res_ioport != 0) {
17146a5be862SDoug Rabson if (bootverbose)
17156a5be862SDoug Rabson device_printf(dev, "using normal I/O port range\n");
17166a5be862SDoug Rabson } else {
17171ab9094cSScott Long if (bootverbose)
17180f210c92SNicolas Souchu device_printf(dev, "cannot reserve I/O port range\n");
17190f210c92SNicolas Souchu goto error;
17200f210c92SNicolas Souchu }
17215c885c3fSDoug Rabson }
17225c885c3fSDoug Rabson
1723d64d73c9SDoug Rabson ppc->ppc_base = rman_get_start(ppc->res_ioport);
17240f210c92SNicolas Souchu
17250f210c92SNicolas Souchu ppc->ppc_flags = device_get_flags(dev);
17260f210c92SNicolas Souchu
17270f210c92SNicolas Souchu if (!(ppc->ppc_flags & 0x20)) {
17285f96beb9SNate Lawson ppc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
17295f96beb9SNate Lawson &ppc->rid_irq,
17305f96beb9SNate Lawson RF_SHAREABLE);
17315f96beb9SNate Lawson ppc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
17325f96beb9SNate Lawson &ppc->rid_drq,
17335f96beb9SNate Lawson RF_ACTIVE);
17340f210c92SNicolas Souchu }
17350f210c92SNicolas Souchu
17360f210c92SNicolas Souchu if (ppc->res_irq)
1737d64d73c9SDoug Rabson ppc->ppc_irq = rman_get_start(ppc->res_irq);
17380f210c92SNicolas Souchu if (ppc->res_drq)
1739d64d73c9SDoug Rabson ppc->ppc_dmachan = rman_get_start(ppc->res_drq);
17400f210c92SNicolas Souchu
1741ae6b868aSJohn Baldwin ppc->ppc_dev = dev;
17420f210c92SNicolas Souchu ppc->ppc_model = GENERIC;
1743af548787SNicolas Souchu
174446f3ff79SMike Smith ppc->ppc_mode = PPB_COMPATIBLE;
17450f210c92SNicolas Souchu ppc->ppc_epp = (ppc->ppc_flags & 0x10) >> 4;
174667646539SMike Smith
17470f210c92SNicolas Souchu ppc->ppc_type = PPC_TYPE_GENERIC;
1748edcfcf27SNicolas Souchu
1749edcfcf27SNicolas Souchu /*
1750dc733423SDag-Erling Smørgrav * Try to detect the chipset and its mode.
175167646539SMike Smith */
17520f210c92SNicolas Souchu if (ppc_detect(ppc, ppc->ppc_flags & 0xf))
175367646539SMike Smith goto error;
175467646539SMike Smith
17550f210c92SNicolas Souchu return (0);
175667646539SMike Smith
175767646539SMike Smith error:
17580f210c92SNicolas Souchu if (ppc->res_irq != 0) {
17590f210c92SNicolas Souchu bus_release_resource(dev, SYS_RES_IRQ, ppc->rid_irq,
17600f210c92SNicolas Souchu ppc->res_irq);
17610f210c92SNicolas Souchu }
17620f210c92SNicolas Souchu if (ppc->res_ioport != 0) {
17630f210c92SNicolas Souchu bus_release_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
17640f210c92SNicolas Souchu ppc->res_ioport);
17650f210c92SNicolas Souchu }
17660f210c92SNicolas Souchu if (ppc->res_drq != 0) {
17670f210c92SNicolas Souchu bus_release_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
17680f210c92SNicolas Souchu ppc->res_drq);
17690f210c92SNicolas Souchu }
17700f210c92SNicolas Souchu return (ENXIO);
177167646539SMike Smith }
177267646539SMike Smith
1773a3732274SDoug Ambrisko int
ppc_attach(device_t dev)17740f210c92SNicolas Souchu ppc_attach(device_t dev)
177567646539SMike Smith {
17760f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(dev);
1777ca3d3795SJohn Baldwin int error;
17780f210c92SNicolas Souchu
17792067d312SJohn Baldwin mtx_init(&ppc->ppc_lock, device_get_nameunit(dev), "ppc", MTX_DEF);
17802067d312SJohn Baldwin
17810f210c92SNicolas Souchu device_printf(dev, "%s chipset (%s) in %s mode%s\n",
17820f210c92SNicolas Souchu ppc_models[ppc->ppc_model], ppc_avms[ppc->ppc_avm],
178346f3ff79SMike Smith ppc_modes[ppc->ppc_mode], (PPB_IS_EPP(ppc->ppc_mode)) ?
178467646539SMike Smith ppc_epp_protocol[ppc->ppc_epp] : "");
178567646539SMike Smith
1786bc35c174SNicolas Souchu if (ppc->ppc_fifo)
17870f210c92SNicolas Souchu device_printf(dev, "FIFO with %d/%d/%d bytes threshold\n",
17880f210c92SNicolas Souchu ppc->ppc_fifo, ppc->ppc_wthr, ppc->ppc_rthr);
178967646539SMike Smith
1790ca3d3795SJohn Baldwin if (ppc->res_irq) {
1791ca3d3795SJohn Baldwin /* default to the tty mask for registration */ /* XXX */
17922067d312SJohn Baldwin error = bus_setup_intr(dev, ppc->res_irq, INTR_TYPE_TTY |
17932067d312SJohn Baldwin INTR_MPSAFE, NULL, ppcintr, ppc, &ppc->intr_cookie);
1794ca3d3795SJohn Baldwin if (error) {
1795ca3d3795SJohn Baldwin device_printf(dev,
1796ca3d3795SJohn Baldwin "failed to register interrupt handler: %d\n",
1797ca3d3795SJohn Baldwin error);
17982067d312SJohn Baldwin mtx_destroy(&ppc->ppc_lock);
1799ca3d3795SJohn Baldwin return (error);
1800ca3d3795SJohn Baldwin }
1801ca3d3795SJohn Baldwin }
1802ca3d3795SJohn Baldwin
18030f210c92SNicolas Souchu /* add ppbus as a child of this isa to parallel bridge */
18045b56413dSWarner Losh ppc->ppbus = device_add_child(dev, "ppbus", DEVICE_UNIT_ANY);
18050f210c92SNicolas Souchu
180667646539SMike Smith /*
180767646539SMike Smith * Probe the ppbus and attach devices found.
180867646539SMike Smith */
18092067d312SJohn Baldwin device_probe_and_attach(ppc->ppbus);
181067646539SMike Smith
18110f210c92SNicolas Souchu return (0);
18120f210c92SNicolas Souchu }
18130f210c92SNicolas Souchu
1814858a52f4SMitsuru IWASAKI int
ppc_detach(device_t dev)1815858a52f4SMitsuru IWASAKI ppc_detach(device_t dev)
1816858a52f4SMitsuru IWASAKI {
1817858a52f4SMitsuru IWASAKI struct ppc_data *ppc = DEVTOSOFTC(dev);
1818*3ddaf820SJohn Baldwin int error;
1819858a52f4SMitsuru IWASAKI
1820858a52f4SMitsuru IWASAKI if (ppc->res_irq == 0) {
1821858a52f4SMitsuru IWASAKI return (ENXIO);
1822858a52f4SMitsuru IWASAKI }
1823858a52f4SMitsuru IWASAKI
1824858a52f4SMitsuru IWASAKI /* detach & delete all children */
1825*3ddaf820SJohn Baldwin error = bus_generic_detach(dev);
1826*3ddaf820SJohn Baldwin if (error != 0)
1827*3ddaf820SJohn Baldwin return (error);
1828858a52f4SMitsuru IWASAKI
1829858a52f4SMitsuru IWASAKI if (ppc->res_irq != 0) {
1830858a52f4SMitsuru IWASAKI bus_teardown_intr(dev, ppc->res_irq, ppc->intr_cookie);
1831858a52f4SMitsuru IWASAKI bus_release_resource(dev, SYS_RES_IRQ, ppc->rid_irq,
1832858a52f4SMitsuru IWASAKI ppc->res_irq);
1833858a52f4SMitsuru IWASAKI }
1834858a52f4SMitsuru IWASAKI if (ppc->res_ioport != 0) {
1835858a52f4SMitsuru IWASAKI bus_release_resource(dev, SYS_RES_IOPORT, ppc->rid_ioport,
1836858a52f4SMitsuru IWASAKI ppc->res_ioport);
1837858a52f4SMitsuru IWASAKI }
1838858a52f4SMitsuru IWASAKI if (ppc->res_drq != 0) {
1839858a52f4SMitsuru IWASAKI bus_release_resource(dev, SYS_RES_DRQ, ppc->rid_drq,
1840858a52f4SMitsuru IWASAKI ppc->res_drq);
1841858a52f4SMitsuru IWASAKI }
1842858a52f4SMitsuru IWASAKI
18432067d312SJohn Baldwin mtx_destroy(&ppc->ppc_lock);
18442067d312SJohn Baldwin
1845858a52f4SMitsuru IWASAKI return (0);
1846858a52f4SMitsuru IWASAKI }
1847858a52f4SMitsuru IWASAKI
1848a3732274SDoug Ambrisko u_char
ppc_io(device_t ppcdev,int iop,u_char * addr,int cnt,u_char byte)18490f210c92SNicolas Souchu ppc_io(device_t ppcdev, int iop, u_char *addr, int cnt, u_char byte)
18500f210c92SNicolas Souchu {
18510f210c92SNicolas Souchu struct ppc_data *ppc = DEVTOSOFTC(ppcdev);
1852284c87f6SJohn Baldwin
18532067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
18540f210c92SNicolas Souchu switch (iop) {
18550f210c92SNicolas Souchu case PPB_OUTSB_EPP:
18568fd40d8aSJohn Baldwin bus_write_multi_1(ppc->res_ioport, PPC_EPP_DATA, addr, cnt);
18570f210c92SNicolas Souchu break;
18580f210c92SNicolas Souchu case PPB_OUTSW_EPP:
18598fd40d8aSJohn Baldwin bus_write_multi_2(ppc->res_ioport, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
18600f210c92SNicolas Souchu break;
18610f210c92SNicolas Souchu case PPB_OUTSL_EPP:
18628fd40d8aSJohn Baldwin bus_write_multi_4(ppc->res_ioport, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
18630f210c92SNicolas Souchu break;
18640f210c92SNicolas Souchu case PPB_INSB_EPP:
18658fd40d8aSJohn Baldwin bus_read_multi_1(ppc->res_ioport, PPC_EPP_DATA, addr, cnt);
18660f210c92SNicolas Souchu break;
18670f210c92SNicolas Souchu case PPB_INSW_EPP:
18688fd40d8aSJohn Baldwin bus_read_multi_2(ppc->res_ioport, PPC_EPP_DATA, (u_int16_t *)addr, cnt);
18690f210c92SNicolas Souchu break;
18700f210c92SNicolas Souchu case PPB_INSL_EPP:
18718fd40d8aSJohn Baldwin bus_read_multi_4(ppc->res_ioport, PPC_EPP_DATA, (u_int32_t *)addr, cnt);
18720f210c92SNicolas Souchu break;
18730f210c92SNicolas Souchu case PPB_RDTR:
18740f210c92SNicolas Souchu return (r_dtr(ppc));
18750f210c92SNicolas Souchu case PPB_RSTR:
18760f210c92SNicolas Souchu return (r_str(ppc));
18770f210c92SNicolas Souchu case PPB_RCTR:
18780f210c92SNicolas Souchu return (r_ctr(ppc));
18790f210c92SNicolas Souchu case PPB_REPP_A:
18800f210c92SNicolas Souchu return (r_epp_A(ppc));
18810f210c92SNicolas Souchu case PPB_REPP_D:
18820f210c92SNicolas Souchu return (r_epp_D(ppc));
18830f210c92SNicolas Souchu case PPB_RECR:
18840f210c92SNicolas Souchu return (r_ecr(ppc));
18850f210c92SNicolas Souchu case PPB_RFIFO:
18860f210c92SNicolas Souchu return (r_fifo(ppc));
18870f210c92SNicolas Souchu case PPB_WDTR:
18880f210c92SNicolas Souchu w_dtr(ppc, byte);
18890f210c92SNicolas Souchu break;
18900f210c92SNicolas Souchu case PPB_WSTR:
18910f210c92SNicolas Souchu w_str(ppc, byte);
18920f210c92SNicolas Souchu break;
18930f210c92SNicolas Souchu case PPB_WCTR:
18940f210c92SNicolas Souchu w_ctr(ppc, byte);
18950f210c92SNicolas Souchu break;
18960f210c92SNicolas Souchu case PPB_WEPP_A:
18970f210c92SNicolas Souchu w_epp_A(ppc, byte);
18980f210c92SNicolas Souchu break;
18990f210c92SNicolas Souchu case PPB_WEPP_D:
19000f210c92SNicolas Souchu w_epp_D(ppc, byte);
19010f210c92SNicolas Souchu break;
19020f210c92SNicolas Souchu case PPB_WECR:
19030f210c92SNicolas Souchu w_ecr(ppc, byte);
19040f210c92SNicolas Souchu break;
19050f210c92SNicolas Souchu case PPB_WFIFO:
19060f210c92SNicolas Souchu w_fifo(ppc, byte);
19070f210c92SNicolas Souchu break;
19080f210c92SNicolas Souchu default:
19096e551fb6SDavid E. O'Brien panic("%s: unknown I/O operation", __func__);
19100f210c92SNicolas Souchu break;
19110f210c92SNicolas Souchu }
19120f210c92SNicolas Souchu
19130f210c92SNicolas Souchu return (0); /* not significative */
19140f210c92SNicolas Souchu }
19150f210c92SNicolas Souchu
1916a3732274SDoug Ambrisko int
ppc_read_ivar(device_t bus,device_t dev,int index,uintptr_t * val)19170f210c92SNicolas Souchu ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
19180f210c92SNicolas Souchu {
19190f210c92SNicolas Souchu struct ppc_data *ppc = (struct ppc_data *)device_get_softc(bus);
19200f210c92SNicolas Souchu
19210f210c92SNicolas Souchu switch (index) {
19220f210c92SNicolas Souchu case PPC_IVAR_EPP_PROTO:
19232067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
19240f210c92SNicolas Souchu *val = (u_long)ppc->ppc_epp;
19250f210c92SNicolas Souchu break;
19262067d312SJohn Baldwin case PPC_IVAR_LOCK:
19272067d312SJohn Baldwin *val = (uintptr_t)&ppc->ppc_lock;
19282067d312SJohn Baldwin break;
19292067d312SJohn Baldwin default:
19302067d312SJohn Baldwin return (ENOENT);
19312067d312SJohn Baldwin }
19322067d312SJohn Baldwin
19332067d312SJohn Baldwin return (0);
19342067d312SJohn Baldwin }
19352067d312SJohn Baldwin
19362067d312SJohn Baldwin int
ppc_write_ivar(device_t bus,device_t dev,int index,uintptr_t val)19372067d312SJohn Baldwin ppc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
19382067d312SJohn Baldwin {
19392067d312SJohn Baldwin struct ppc_data *ppc = (struct ppc_data *)device_get_softc(bus);
19402067d312SJohn Baldwin
19412067d312SJohn Baldwin switch (index) {
19422067d312SJohn Baldwin case PPC_IVAR_INTR_HANDLER:
19432067d312SJohn Baldwin PPC_ASSERT_LOCKED(ppc);
19442067d312SJohn Baldwin if (dev != ppc->ppbus)
19452067d312SJohn Baldwin return (EINVAL);
19462067d312SJohn Baldwin if (val == 0) {
19472067d312SJohn Baldwin ppc->ppc_intr_hook = NULL;
19482067d312SJohn Baldwin break;
19492067d312SJohn Baldwin }
19502067d312SJohn Baldwin if (ppc->ppc_intr_hook != NULL)
19512067d312SJohn Baldwin return (EBUSY);
19522067d312SJohn Baldwin ppc->ppc_intr_hook = (void *)val;
19532067d312SJohn Baldwin ppc->ppc_intr_arg = device_get_softc(dev);
19542067d312SJohn Baldwin break;
19550f210c92SNicolas Souchu default:
19560f210c92SNicolas Souchu return (ENOENT);
19570f210c92SNicolas Souchu }
19580f210c92SNicolas Souchu
19590f210c92SNicolas Souchu return (0);
19600f210c92SNicolas Souchu }
19610f210c92SNicolas Souchu
19620f210c92SNicolas Souchu /*
1963ca3d3795SJohn Baldwin * We allow child devices to allocate an IRQ resource at rid 0 for their
1964ca3d3795SJohn Baldwin * interrupt handlers.
1965ca3d3795SJohn Baldwin */
1966ca3d3795SJohn Baldwin struct resource *
ppc_alloc_resource(device_t bus,device_t child,int type,int * rid,rman_res_t start,rman_res_t end,rman_res_t count,u_int flags)1967ca3d3795SJohn Baldwin ppc_alloc_resource(device_t bus, device_t child, int type, int *rid,
19682dd1bdf1SJustin Hibbits rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
1969ca3d3795SJohn Baldwin {
1970ca3d3795SJohn Baldwin struct ppc_data *ppc = DEVTOSOFTC(bus);
1971ca3d3795SJohn Baldwin
1972ca3d3795SJohn Baldwin switch (type) {
1973ca3d3795SJohn Baldwin case SYS_RES_IRQ:
1974ca3d3795SJohn Baldwin if (*rid == 0)
1975ca3d3795SJohn Baldwin return (ppc->res_irq);
1976ca3d3795SJohn Baldwin break;
1977ca3d3795SJohn Baldwin }
1978ca3d3795SJohn Baldwin return (NULL);
1979ca3d3795SJohn Baldwin }
1980ca3d3795SJohn Baldwin
1981ca3d3795SJohn Baldwin int
ppc_release_resource(device_t bus,device_t child,struct resource * r)19829dbf5b0eSJohn Baldwin ppc_release_resource(device_t bus, device_t child, struct resource *r)
1983ca3d3795SJohn Baldwin {
1984ca3d3795SJohn Baldwin struct ppc_data *ppc = DEVTOSOFTC(bus);
1985ca3d3795SJohn Baldwin
19869dbf5b0eSJohn Baldwin if (r == ppc->res_irq)
1987ca3d3795SJohn Baldwin return (0);
1988ca3d3795SJohn Baldwin return (EINVAL);
1989ca3d3795SJohn Baldwin }
1990ca3d3795SJohn Baldwin
1991f5fd5611SRuslan Ermilov MODULE_DEPEND(ppc, ppbus, 1, 1, 1);
1992