2005-02-27 03:26:58 +03:00
|
|
|
/* $NetBSD: upc.c,v 1.9 2005/02/27 00:27:03 perry Exp $ */
|
2000-08-17 03:56:08 +04:00
|
|
|
/*-
|
2003-03-02 03:21:47 +03:00
|
|
|
* Copyright (c) 2000, 2003 Ben Harris
|
2000-08-17 03:56:08 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
2005-02-27 03:26:58 +03:00
|
|
|
*
|
2000-08-17 03:56:08 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2003-03-02 03:21:47 +03:00
|
|
|
/*
|
|
|
|
* upc - driver for C&T Universal Peripheral Controllers
|
|
|
|
*
|
|
|
|
* Supports:
|
|
|
|
* 82C710 Universal Peripheral Controller
|
|
|
|
* 82C711 Universal Peripheral Controller II
|
|
|
|
* 82C721 Universal Peripheral Controller III (untested)
|
|
|
|
*
|
|
|
|
* The 82C710 is substantially different from its successors.
|
|
|
|
* Functions that just handle the 82C710 are named upc1_*, which those
|
|
|
|
* that handle the 82C711 and 82C721 are named upc2_*.
|
|
|
|
*/
|
2000-08-17 03:56:08 +04:00
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: upc.c,v 1.9 2005/02/27 00:27:03 perry Exp $");
|
2000-08-17 03:56:08 +04:00
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/param.h>
|
2000-08-17 03:56:08 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/ata/atavar.h> /* XXX needed by wdcvar.h */
|
|
|
|
#include <dev/ic/comreg.h>
|
|
|
|
#include <dev/ic/lptreg.h>
|
|
|
|
#include <dev/ic/lptvar.h>
|
2003-11-29 22:33:34 +03:00
|
|
|
#include <dev/ic/wdcreg.h>
|
2000-08-17 03:56:08 +04:00
|
|
|
#include <dev/ic/wdcvar.h>
|
|
|
|
#include <dev/ic/upcreg.h>
|
|
|
|
#include <dev/ic/upcvar.h>
|
|
|
|
|
|
|
|
#include "locators.h"
|
|
|
|
|
2003-03-02 03:21:47 +03:00
|
|
|
/* Conventional port to use for 82C710 configuration */
|
|
|
|
#define UPC1_PORT_CRI 0x390
|
|
|
|
#define UPC1_PORT_CAP (UPC1_PORT_CRI + 1)
|
|
|
|
|
|
|
|
static int upc1_probe(struct upc_softc *);
|
|
|
|
static void upc1_attach(struct upc_softc *);
|
|
|
|
static void upc2_attach(struct upc_softc *);
|
2000-08-17 03:56:08 +04:00
|
|
|
static void upc_found(struct upc_softc *, char const *, int, int,
|
|
|
|
struct upc_irqhandle *);
|
|
|
|
static void upc_found2(struct upc_softc *, char const *, int, int, int, int,
|
|
|
|
struct upc_irqhandle *);
|
|
|
|
static int upc_print(void *, char const *);
|
2004-09-13 16:55:47 +04:00
|
|
|
static int upc_submatch(struct device *, struct cfdata *,
|
|
|
|
const locdesc_t *, void *);
|
2003-03-02 03:21:47 +03:00
|
|
|
static int upc2_com3_addr(int);
|
|
|
|
static int upc2_com4_addr(int);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
upc_attach(struct upc_softc *sc)
|
2003-03-02 03:21:47 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (upc1_probe(sc))
|
|
|
|
upc1_attach(sc);
|
|
|
|
else
|
|
|
|
upc2_attach(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upc1_probe(struct upc_softc *sc)
|
|
|
|
{
|
|
|
|
|
|
|
|
return upc1_read_config(sc, UPC1_CFGADDR_CONFBASE) ==
|
|
|
|
UPC1_PORT_CRI >> UPC1_CONFBASE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
upc1_attach(struct upc_softc *sc)
|
|
|
|
{
|
|
|
|
u_int8_t cr[16];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
aprint_normal(": 82C710\n");
|
|
|
|
/* Dump configuration */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
cr[i] = upc1_read_config(sc, i);
|
|
|
|
|
|
|
|
aprint_verbose("%s: config state", sc->sc_dev.dv_xname);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
aprint_verbose(" %02x", cr[i]);
|
|
|
|
aprint_verbose("\n");
|
|
|
|
|
|
|
|
/* FDC */
|
|
|
|
if (cr[UPC1_CFGADDR_CRC] & UPC1_CRC_FDCEN)
|
|
|
|
upc_found(sc, "fdc", UPC_PORT_FDCBASE, 2, &sc->sc_fintr);
|
|
|
|
/* IDE */
|
|
|
|
if (cr[UPC1_CFGADDR_CRC] & UPC1_CRC_IDEEN)
|
|
|
|
upc_found2(sc, "wdc", UPC_PORT_IDECMDBASE, 8,
|
|
|
|
UPC_PORT_IDECTLBASE, 2, &sc->sc_wintr);
|
|
|
|
/* Parallel */
|
|
|
|
if (cr[UPC1_CFGADDR_CR0] & UPC1_CR0_PEN)
|
|
|
|
upc_found(sc, "lpt",
|
|
|
|
cr[UPC1_CFGADDR_PARBASE] << UPC1_PARBASE_SHIFT,
|
|
|
|
LPT_NPORTS, &sc->sc_pintr);
|
|
|
|
/* UART */
|
|
|
|
if (cr[UPC1_CFGADDR_CR0] & UPC1_CR0_SEN)
|
|
|
|
upc_found(sc, "com",
|
|
|
|
cr[UPC1_CFGADDR_UARTBASE] << UPC1_UARTBASE_SHIFT,
|
|
|
|
COM_NPORTS, &sc->sc_irq4);
|
|
|
|
/* Mouse */
|
|
|
|
/* XXX not yet supported */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
upc2_attach(struct upc_softc *sc)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
u_int8_t cr[5];
|
|
|
|
int i;
|
|
|
|
|
2003-03-02 03:21:47 +03:00
|
|
|
aprint_normal(": 82C711/82C721");
|
2000-08-17 03:56:08 +04:00
|
|
|
/* Dump configuration */
|
|
|
|
for (i = 0; i < 5; i++)
|
2003-03-02 03:21:47 +03:00
|
|
|
cr[i] = upc2_read_config(sc, i);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
2003-03-02 03:21:47 +03:00
|
|
|
aprint_verbose(", config state %02x %02x %02x %02x %02x",
|
2000-08-17 03:56:08 +04:00
|
|
|
cr[0], cr[1], cr[2], cr[3], cr[4]);
|
2003-03-02 03:21:47 +03:00
|
|
|
aprint_normal("\n");
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
/* "Find" the attached devices */
|
|
|
|
/* FDC */
|
2003-03-02 03:21:47 +03:00
|
|
|
if (cr[0] & UPC2_CR0_FDC_ENABLE)
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "fdc", UPC_PORT_FDCBASE, 2, &sc->sc_fintr);
|
|
|
|
/* IDE */
|
2003-03-02 03:21:47 +03:00
|
|
|
if (cr[0] & UPC2_CR0_IDE_ENABLE)
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found2(sc, "wdc", UPC_PORT_IDECMDBASE, 8,
|
|
|
|
UPC_PORT_IDECTLBASE, 2, &sc->sc_wintr);
|
|
|
|
/* Parallel */
|
2003-03-02 03:21:47 +03:00
|
|
|
switch (cr[1] & UPC2_CR1_LPT_MASK) {
|
|
|
|
case UPC2_CR1_LPT_3BC:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "lpt", 0x3bc, LPT_NPORTS, &sc->sc_pintr);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_LPT_378:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "lpt", 0x378, LPT_NPORTS, &sc->sc_pintr);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_LPT_278:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "lpt", 0x278, LPT_NPORTS, &sc->sc_pintr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* UART1 */
|
2003-03-02 03:21:47 +03:00
|
|
|
if (cr[2] & UPC2_CR2_UART1_ENABLE) {
|
|
|
|
switch (cr[2] & UPC2_CR2_UART1_MASK) {
|
|
|
|
case UPC2_CR2_UART1_3F8:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "com", 0x3f8, COM_NPORTS, &sc->sc_irq4);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART1_2F8:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "com", 0x2f8, COM_NPORTS, &sc->sc_irq3);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART1_COM3:
|
|
|
|
upc_found(sc, "com", upc2_com3_addr(cr[1]), COM_NPORTS,
|
2000-08-17 03:56:08 +04:00
|
|
|
&sc->sc_irq4);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART1_COM4:
|
|
|
|
upc_found(sc, "com", upc2_com4_addr(cr[1]), COM_NPORTS,
|
2000-08-17 03:56:08 +04:00
|
|
|
&sc->sc_irq3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* UART2 */
|
2003-03-02 03:21:47 +03:00
|
|
|
if (cr[2] & UPC2_CR2_UART2_ENABLE) {
|
|
|
|
switch (cr[2] & UPC2_CR2_UART2_MASK) {
|
|
|
|
case UPC2_CR2_UART2_3F8:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "com", 0x3f8, COM_NPORTS, &sc->sc_irq4);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART2_2F8:
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found(sc, "com", 0x2f8, COM_NPORTS, &sc->sc_irq3);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART2_COM3:
|
|
|
|
upc_found(sc, "com", upc2_com3_addr(cr[1]), COM_NPORTS,
|
2000-08-17 03:56:08 +04:00
|
|
|
&sc->sc_irq4);
|
|
|
|
break;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR2_UART2_COM4:
|
|
|
|
upc_found(sc, "com", upc2_com4_addr(cr[1]), COM_NPORTS,
|
2000-08-17 03:56:08 +04:00
|
|
|
&sc->sc_irq3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
upc_found(struct upc_softc *sc, char const *devtype, int offset, int size,
|
|
|
|
struct upc_irqhandle *uih)
|
|
|
|
{
|
|
|
|
struct upc_attach_args ua;
|
2004-09-13 16:55:47 +04:00
|
|
|
int help[2];
|
|
|
|
locdesc_t *ldesc = (void *)help;
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
ua.ua_devtype = devtype;
|
|
|
|
ua.ua_offset = offset;
|
|
|
|
ua.ua_iot = sc->sc_iot;
|
|
|
|
bus_space_subregion(sc->sc_iot, sc->sc_ioh, offset, size, &ua.ua_ioh);
|
|
|
|
ua.ua_irqhandle = uih;
|
2004-09-13 16:55:47 +04:00
|
|
|
|
|
|
|
ldesc->len = 1;
|
|
|
|
ldesc->locs[UPCCF_OFFSET] = offset;
|
|
|
|
|
|
|
|
config_found_sm_loc(&sc->sc_dev, "upc", ldesc, &ua,
|
|
|
|
upc_print, upc_submatch);
|
2000-08-17 03:56:08 +04:00
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
static void
|
2000-08-17 03:56:08 +04:00
|
|
|
upc_found2(struct upc_softc *sc, char const *devtype, int offset, int size,
|
|
|
|
int offset2, int size2, struct upc_irqhandle *uih)
|
|
|
|
{
|
|
|
|
struct upc_attach_args ua;
|
2004-09-13 16:55:47 +04:00
|
|
|
int help[2];
|
|
|
|
locdesc_t *ldesc = (void *)help;
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
ua.ua_devtype = devtype;
|
|
|
|
ua.ua_offset = offset;
|
|
|
|
ua.ua_iot = sc->sc_iot;
|
|
|
|
bus_space_subregion(sc->sc_iot, sc->sc_ioh, offset, size, &ua.ua_ioh);
|
|
|
|
bus_space_subregion(sc->sc_iot, sc->sc_ioh, offset2, size2,
|
|
|
|
&ua.ua_ioh2);
|
|
|
|
ua.ua_irqhandle = uih;
|
2004-09-13 16:55:47 +04:00
|
|
|
|
|
|
|
ldesc->len = 1;
|
|
|
|
ldesc->locs[UPCCF_OFFSET] = offset;
|
|
|
|
|
|
|
|
config_found_sm_loc(&sc->sc_dev, "upc", ldesc, &ua,
|
|
|
|
upc_print, upc_submatch);
|
2000-08-17 03:56:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
upc_intr_establish(struct upc_irqhandle *uih, int level, int (*func)(void *),
|
|
|
|
void *arg) {
|
|
|
|
|
|
|
|
uih->uih_level = level;
|
|
|
|
uih->uih_func = func;
|
|
|
|
uih->uih_arg = arg;
|
|
|
|
/* Actual MD establishment will be handled later by bus attachment. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-02 03:21:47 +03:00
|
|
|
upc2_com3_addr(int cr1)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
|
2003-03-02 03:21:47 +03:00
|
|
|
switch (cr1 & UPC2_CR1_COM34_MASK) {
|
|
|
|
case UPC2_CR1_COM34_338_238:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x338;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_3E8_2E8:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x3e8;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_2E8_2E0:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x2e8;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_220_228:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x220;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-02 03:21:47 +03:00
|
|
|
upc2_com4_addr(int cr1)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
|
2003-03-02 03:21:47 +03:00
|
|
|
switch (cr1 & UPC2_CR1_COM34_MASK) {
|
|
|
|
case UPC2_CR1_COM34_338_238:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x238;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_3E8_2E8:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x2e8;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_2E8_2E0:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x2e0;
|
2003-03-02 03:21:47 +03:00
|
|
|
case UPC2_CR1_COM34_220_228:
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0x228;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
upc_print(void *aux, char const *pnp)
|
|
|
|
{
|
|
|
|
struct upc_attach_args *ua = aux;
|
|
|
|
|
|
|
|
if (pnp)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("%s at %s", ua->ua_devtype, pnp);
|
|
|
|
aprint_normal(" offset 0x%x", ua->ua_offset);
|
2000-08-17 03:56:08 +04:00
|
|
|
return UNCONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-09-13 16:55:47 +04:00
|
|
|
upc_submatch(struct device *parent, struct cfdata *cf,
|
|
|
|
const locdesc_t *ldesc, void *aux)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
struct upc_attach_args *ua = aux;
|
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
if (strcmp(cf->cf_name, ua->ua_devtype) == 0 &&
|
2000-08-17 03:56:08 +04:00
|
|
|
(cf->cf_loc[UPCCF_OFFSET] == UPCCF_OFFSET_DEFAULT ||
|
2004-09-13 16:55:47 +04:00
|
|
|
cf->cf_loc[UPCCF_OFFSET] == ldesc->locs[UPCCF_OFFSET]))
|
2002-09-27 07:17:40 +04:00
|
|
|
return config_match(parent, cf, aux);
|
2000-08-17 03:56:08 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-03-02 03:21:47 +03:00
|
|
|
upc1_read_config(struct upc_softc *sc, int reg)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Switch into configuration mode. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG1, UPC1_CFGMAGIC_1);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2, UPC1_CFGMAGIC_2);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2, UPC1_CFGMAGIC_3);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2,
|
|
|
|
UPC1_PORT_CRI >> UPC1_CONFBASE_SHIFT);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG1,
|
|
|
|
(UPC1_PORT_CRI >> UPC1_CONFBASE_SHIFT) ^ 0xff);
|
|
|
|
|
|
|
|
/* Read register. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CRI, reg);
|
|
|
|
retval = bus_space_read_1(iot, ioh, UPC1_PORT_CAP);
|
|
|
|
|
|
|
|
/* Leave configuration mode. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CRI, UPC1_CFGADDR_EXIT);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CAP, 0);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
upc1_write_config(struct upc_softc *sc, int reg, int val)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
/* Switch into configuration mode. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG1, UPC1_CFGMAGIC_1);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2, UPC1_CFGMAGIC_2);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2, UPC1_CFGMAGIC_3);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG2,
|
|
|
|
UPC1_PORT_CRI >> UPC1_CONFBASE_SHIFT);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CFG1,
|
|
|
|
(UPC1_PORT_CRI >> UPC1_CONFBASE_SHIFT) ^ 0xff);
|
|
|
|
|
|
|
|
/* Read register. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CRI, reg);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CAP, val);
|
|
|
|
|
|
|
|
/* Leave configuration mode. */
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CRI, UPC1_CFGADDR_EXIT);
|
|
|
|
bus_space_write_1(iot, ioh, UPC1_PORT_CAP, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
upc2_read_config(struct upc_softc *sc, int reg)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Switch into configuration mode. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_ENTER);
|
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_ENTER);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
/* Read register. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, reg);
|
|
|
|
retval = bus_space_read_1(iot, ioh, UPC2_PORT_CFGDATA);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
/* Leave configuration mode. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_EXIT);
|
2000-08-17 03:56:08 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-02 03:21:47 +03:00
|
|
|
upc2_write_config(struct upc_softc *sc, int reg, int val)
|
2000-08-17 03:56:08 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
/* Switch into configuration mode. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_ENTER);
|
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_ENTER);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
/* Write register. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, reg);
|
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGDATA, val);
|
2000-08-17 03:56:08 +04:00
|
|
|
|
|
|
|
/* Leave configuration mode. */
|
2003-03-02 03:21:47 +03:00
|
|
|
bus_space_write_1(iot, ioh, UPC2_PORT_CFGADDR, UPC2_CFGMAGIC_EXIT);
|
2000-08-17 03:56:08 +04:00
|
|
|
}
|