2008-03-14 18:09:09 +03:00
|
|
|
/* $NetBSD: com_vrip.c,v 1.20 2008/03/14 15:09:10 cube Exp $ */
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 SASAKI Takesi. All rights reserved.
|
2002-02-02 13:50:08 +03:00
|
|
|
* Copyright (c) 1999, 2002 PocketBSD Project. All rights reserved.
|
1999-09-16 16:23:18 +04:00
|
|
|
*
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the PocketBSD project
|
|
|
|
* and its contributors.
|
|
|
|
* 4. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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-07-15 06:29:24 +04:00
|
|
|
#include <sys/cdefs.h>
|
2008-03-14 18:09:09 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: com_vrip.c,v 1.20 2008/03/14 15:09:10 cube Exp $");
|
2003-07-15 06:29:24 +04:00
|
|
|
|
2001-05-30 19:24:23 +04:00
|
|
|
#include "opt_kgdb.h"
|
|
|
|
|
1999-09-16 16:23:18 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
|
2001-03-11 19:45:13 +03:00
|
|
|
#include <sys/termios.h>
|
|
|
|
|
1999-09-16 16:23:18 +04:00
|
|
|
#include <machine/intr.h>
|
|
|
|
#include <machine/bus.h>
|
2001-03-11 19:45:13 +03:00
|
|
|
|
1999-09-16 16:23:18 +04:00
|
|
|
#include <machine/platid.h>
|
|
|
|
#include <machine/platid_mask.h>
|
1999-12-23 09:26:08 +03:00
|
|
|
#include <machine/config_hook.h>
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
#include <hpcmips/vr/vr.h>
|
2001-09-28 14:25:15 +04:00
|
|
|
#include <hpcmips/vr/vrcpudef.h>
|
2002-01-27 17:18:11 +03:00
|
|
|
#include <hpcmips/vr/vripif.h>
|
1999-09-16 16:23:18 +04:00
|
|
|
#include <hpcmips/vr/vripvar.h>
|
|
|
|
#include <hpcmips/vr/cmureg.h>
|
|
|
|
#include <hpcmips/vr/siureg.h>
|
|
|
|
|
|
|
|
#include <dev/ic/comvar.h>
|
|
|
|
#include <dev/ic/comreg.h>
|
|
|
|
|
2001-04-30 15:42:17 +04:00
|
|
|
#include "opt_vr41xx.h"
|
1999-09-16 16:23:18 +04:00
|
|
|
#include <hpcmips/vr/com_vripvar.h>
|
|
|
|
|
|
|
|
#include "locators.h"
|
|
|
|
|
2000-02-11 06:20:17 +03:00
|
|
|
#define COMVRIPDEBUG
|
1999-09-16 16:23:18 +04:00
|
|
|
#ifdef COMVRIPDEBUG
|
|
|
|
int com_vrip_debug = 0;
|
|
|
|
#define DPRINTF(arg) if (com_vrip_debug) printf arg;
|
2000-10-27 12:12:18 +04:00
|
|
|
#define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
|
1999-09-16 16:23:18 +04:00
|
|
|
#else
|
|
|
|
#define DPRINTF(arg)
|
2000-10-27 12:12:18 +04:00
|
|
|
#define VPRINTF(arg) if (bootverbose) printf arg;
|
1999-09-16 16:23:18 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct com_vrip_softc {
|
|
|
|
struct com_softc sc_com;
|
1999-12-23 09:26:08 +03:00
|
|
|
int sc_pwctl;
|
1999-09-16 16:23:18 +04:00
|
|
|
};
|
|
|
|
|
2008-03-14 18:09:09 +03:00
|
|
|
static int com_vrip_probe(device_t, cfdata_t , void *);
|
|
|
|
static void com_vrip_attach(device_t, device_t, void *);
|
2001-09-16 09:32:18 +04:00
|
|
|
static int com_vrip_common_probe(bus_space_tag_t, int);
|
1999-09-16 16:23:18 +04:00
|
|
|
|
2001-09-16 09:32:18 +04:00
|
|
|
void vrcmu_init(void);
|
|
|
|
void vrcmu_supply(int);
|
|
|
|
void vrcmu_mask(int);
|
1999-09-16 16:23:18 +04:00
|
|
|
|
2008-03-14 18:09:09 +03:00
|
|
|
CFATTACH_DECL_NEW(com_vrip, sizeof(struct com_vrip_softc),
|
2002-10-02 08:55:47 +04:00
|
|
|
com_vrip_probe, com_vrip_attach, NULL, NULL);
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
int
|
2001-09-16 09:32:18 +04:00
|
|
|
com_vrip_cndb_attach(bus_space_tag_t iot, int iobase, int rate, int frequency,
|
|
|
|
tcflag_t cflag, int kgdb)
|
1999-09-16 16:23:18 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (!com_vrip_common_probe(iot, iobase))
|
|
|
|
return (EIO); /* I can't find appropriate error number. */
|
2000-07-21 01:03:36 +04:00
|
|
|
#ifdef KGDB
|
|
|
|
if (kgdb)
|
2003-06-14 21:01:06 +04:00
|
|
|
return (com_kgdb_attach(iot, iobase, rate, frequency,
|
|
|
|
COM_TYPE_NORMAL, cflag));
|
2000-07-21 01:03:36 +04:00
|
|
|
else
|
|
|
|
#endif
|
2003-06-14 21:01:06 +04:00
|
|
|
return (comcnattach(iot, iobase, rate, frequency,
|
|
|
|
COM_TYPE_NORMAL, cflag));
|
1999-09-16 16:23:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-16 09:32:18 +04:00
|
|
|
com_vrip_common_probe(bus_space_tag_t iot, int iobase)
|
1999-09-16 16:23:18 +04:00
|
|
|
{
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
|
2008-03-14 18:09:09 +03:00
|
|
|
aprint_error(": can't map i/o space\n");
|
1999-09-16 16:23:18 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = comprobe1(iot, ioh);
|
|
|
|
bus_space_unmap(iot, ioh, 1);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-03-14 18:09:09 +03:00
|
|
|
com_vrip_probe(device_t parent, cfdata_t cf, void *aux)
|
1999-09-16 16:23:18 +04:00
|
|
|
{
|
|
|
|
struct vrip_attach_args *va = aux;
|
|
|
|
bus_space_tag_t iot = va->va_iot;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
DPRINTF(("==com_vrip_probe"));
|
|
|
|
|
2002-01-27 17:18:11 +03:00
|
|
|
if (va->va_addr == VRIPIFCF_ADDR_DEFAULT ||
|
|
|
|
va->va_unit == VRIPIFCF_UNIT_DEFAULT) {
|
2008-03-14 18:09:09 +03:00
|
|
|
aprint_error(": need addr and intr.\n");
|
1999-09-16 16:23:18 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-01-27 17:18:11 +03:00
|
|
|
vrip_power(va->va_vc, va->va_unit, 1);
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
if (com_is_console(iot, va->va_addr, 0)) {
|
|
|
|
/*
|
|
|
|
* We have alredy probed.
|
|
|
|
*/
|
|
|
|
rv = 1;
|
|
|
|
} else {
|
|
|
|
rv = com_vrip_common_probe(iot, va->va_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
|
|
|
|
|
|
|
|
if (rv) {
|
|
|
|
va->va_size = COM_NPORTS;
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-03-14 18:09:09 +03:00
|
|
|
com_vrip_attach(device_t parent, device_t self, void *aux)
|
1999-09-16 16:23:18 +04:00
|
|
|
{
|
2008-03-14 18:09:09 +03:00
|
|
|
struct com_vrip_softc *vsc = device_private(self);
|
1999-09-16 16:23:18 +04:00
|
|
|
struct com_softc *sc = &vsc->sc_com;
|
|
|
|
struct vrip_attach_args *va = aux;
|
|
|
|
|
|
|
|
bus_space_tag_t iot = va->va_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
|
2008-03-14 18:09:09 +03:00
|
|
|
sc->sc_dev = self;
|
|
|
|
vsc->sc_pwctl = device_cfdata(sc->sc_dev)->cf_loc[VRIPIFCF_PWCTL];
|
1999-12-23 09:26:08 +03:00
|
|
|
|
1999-09-16 16:23:18 +04:00
|
|
|
DPRINTF(("==com_vrip_attach"));
|
|
|
|
|
|
|
|
if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
|
2008-03-14 18:09:09 +03:00
|
|
|
aprint_error(": can't map bus space\n");
|
1999-09-16 16:23:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-07-14 02:56:00 +04:00
|
|
|
|
|
|
|
COM_INIT_REGS(sc->sc_regs, iot, ioh, va->va_addr);
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
sc->enable = NULL; /* XXX: CMU control */
|
|
|
|
sc->disable = NULL;
|
|
|
|
|
|
|
|
sc->sc_frequency = VRCOM_FREQ;
|
|
|
|
/* Power management */
|
2002-01-27 17:18:11 +03:00
|
|
|
vrip_power(va->va_vc, va->va_unit, 1);
|
1999-12-23 09:26:08 +03:00
|
|
|
/* XXX, locale 'ID' must be need */
|
|
|
|
config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
|
|
|
|
|
1999-09-16 16:23:18 +04:00
|
|
|
DPRINTF(("Try to attach com.\n"));
|
|
|
|
com_attach_subr(sc);
|
|
|
|
|
|
|
|
DPRINTF(("Establish intr"));
|
2002-01-27 17:18:11 +03:00
|
|
|
if (!vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
|
|
|
|
comintr, self)) {
|
2008-03-14 18:09:09 +03:00
|
|
|
aprint_error_dev(self, "can't map interrupt line.\n");
|
2002-01-27 17:18:11 +03:00
|
|
|
}
|
1999-09-16 16:23:18 +04:00
|
|
|
|
|
|
|
DPRINTF((":return()"));
|
2008-03-14 18:09:09 +03:00
|
|
|
VPRINTF(("%s: pwctl %d\n", device_xname(self), vsc->sc_pwctl));
|
1999-09-16 16:23:18 +04:00
|
|
|
}
|