2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Marcel Moolenaar
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
36 #include <sys/sysctl.h>
38 #include <dev/puc/puc_bus.h>
39 #include <dev/puc/puc_cfg.h>
40 #include <dev/puc/puc_bfe.h>
43 puc_config(struct puc_softc *sc, enum puc_cfg_cmd cmd, int port, intptr_t *r)
45 const struct puc_cfg *cfg = sc->sc_cfg;
48 if (cfg->config_function != NULL) {
49 error = cfg->config_function(sc, cmd, port, r);
56 case PUC_CFG_GET_CLOCK:
61 case PUC_CFG_GET_DESC:
62 if (cfg->desc == NULL)
64 *r = (intptr_t)cfg->desc;
70 /* The length of bus space needed by the port. */
73 case PUC_CFG_GET_NPORTS:
74 /* The number of ports on this card. */
76 case PUC_PORT_NONSTANDARD:
112 case PUC_CFG_GET_OFS:
113 /* The offset relative to the RID. */
116 *r = port * cfg->d_ofs;
118 case PUC_CFG_GET_RID:
119 /* The RID for this port. */
129 error = puc_config(sc, PUC_CFG_GET_RID, 0, r);
134 *r += port * cfg->d_rid;
136 case PUC_CFG_GET_TYPE:
137 /* The type of this port. */
138 if (cfg->ports == PUC_PORT_NONSTANDARD)
142 if (cfg->ports == PUC_PORT_1P ||
143 cfg->ports == PUC_PORT_2P)
144 *r = PUC_TYPE_PARALLEL;
146 *r = PUC_TYPE_SERIAL;
149 if (cfg->ports == PUC_PORT_1S1P ||
150 cfg->ports == PUC_PORT_1S2P ||
151 cfg->ports == PUC_PORT_2P)
152 *r = PUC_TYPE_PARALLEL;
154 *r = PUC_TYPE_SERIAL;
157 if (cfg->ports == PUC_PORT_1S2P ||
158 cfg->ports == PUC_PORT_2S1P)
159 *r = PUC_TYPE_PARALLEL;
161 *r = PUC_TYPE_SERIAL;
164 if (cfg->ports == PUC_PORT_4S1P)
165 *r = PUC_TYPE_PARALLEL;
167 *r = PUC_TYPE_SERIAL;
170 *r = PUC_TYPE_SERIAL;