2007-03-07 20:32:47 +03:00
|
|
|
/* $NetBSD: lm_isa.c,v 1.16 2007/03/07 17:32:47 xtraeme Exp $ */
|
2000-02-25 05:17:43 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Bill Squier.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 11:01:09 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-07 20:32:47 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: lm_isa.c,v 1.16 2007/03/07 17:32:47 xtraeme Exp $");
|
2001-11-13 11:01:09 +03:00
|
|
|
|
2000-02-25 05:17:43 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
2000-06-24 04:37:19 +04:00
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
|
|
|
|
2000-02-25 05:17:43 +03:00
|
|
|
#include <dev/ic/nslm7xvar.h>
|
|
|
|
|
|
|
|
#if defined(LMDEBUG)
|
|
|
|
#define DPRINTF(x) do { printf x; } while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-11-15 17:55:41 +03:00
|
|
|
int lm_isa_match(struct device *, struct cfdata *, void *);
|
|
|
|
void lm_isa_attach(struct device *, struct device *, void *);
|
2007-03-07 20:32:47 +03:00
|
|
|
uint8_t lm_isa_readreg(struct lm_softc *, int);
|
2002-11-15 17:55:41 +03:00
|
|
|
void lm_isa_writereg(struct lm_softc *, int, int);
|
2000-02-25 05:17:43 +03:00
|
|
|
|
2002-10-02 07:10:45 +04:00
|
|
|
CFATTACH_DECL(lm_isa, sizeof(struct lm_softc),
|
|
|
|
lm_isa_match, lm_isa_attach, NULL, NULL);
|
2000-02-25 05:17:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2007-03-07 20:32:47 +03:00
|
|
|
lm_isa_match(struct device *parent, struct cfdata *match, void *aux)
|
2000-02-25 05:17:43 +03:00
|
|
|
{
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
/* Must supply an address */
|
2002-01-08 00:46:56 +03:00
|
|
|
if (ia->ia_nio < 1)
|
2007-03-07 20:32:47 +03:00
|
|
|
return 0;
|
2002-01-08 00:46:56 +03:00
|
|
|
|
|
|
|
if (ISA_DIRECT_CONFIG(ia))
|
2007-03-07 20:32:47 +03:00
|
|
|
return 0;
|
2002-01-08 00:46:56 +03:00
|
|
|
|
2004-09-15 00:20:46 +04:00
|
|
|
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
|
2007-03-07 20:32:47 +03:00
|
|
|
return 0;
|
2000-02-25 05:17:43 +03:00
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0, &ioh))
|
|
|
|
return 0;
|
2000-02-25 05:17:43 +03:00
|
|
|
|
|
|
|
|
2000-03-09 07:19:03 +03:00
|
|
|
/* Bus independent probe */
|
2007-03-07 20:32:47 +03:00
|
|
|
rv = lm_probe(ia->ia_iot, ioh);
|
2000-02-25 05:17:43 +03:00
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
bus_space_unmap(ia->ia_iot, ioh, 8);
|
2000-02-25 05:17:43 +03:00
|
|
|
|
|
|
|
if (rv) {
|
2002-01-08 00:46:56 +03:00
|
|
|
ia->ia_nio = 1;
|
|
|
|
ia->ia_io[0].ir_size = 8;
|
|
|
|
|
|
|
|
ia->ia_niomem = 0;
|
|
|
|
ia->ia_nirq = 0;
|
|
|
|
ia->ia_ndrq = 0;
|
2000-02-25 05:17:43 +03:00
|
|
|
}
|
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
return rv;
|
2000-02-25 05:17:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
lm_isa_attach(struct device *parent, struct device *self, void *aux)
|
2000-02-25 05:17:43 +03:00
|
|
|
{
|
|
|
|
struct lm_softc *lmsc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
lmsc->lm_iot = ia->ia_iot;
|
2000-02-25 05:17:43 +03:00
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 8, 0,
|
|
|
|
&lmsc->lm_ioh)) {
|
|
|
|
aprint_error(": can't map i/o space\n");
|
2000-02-25 05:17:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-25 01:04:21 +03:00
|
|
|
/* Bus-independent attachment */
|
2002-11-15 17:55:41 +03:00
|
|
|
lmsc->lm_writereg = lm_isa_writereg;
|
|
|
|
lmsc->lm_readreg = lm_isa_readreg;
|
|
|
|
|
2000-02-25 05:17:43 +03:00
|
|
|
lm_attach(lmsc);
|
|
|
|
}
|
2002-11-15 17:55:41 +03:00
|
|
|
|
|
|
|
|
2007-03-07 20:32:47 +03:00
|
|
|
uint8_t
|
|
|
|
lm_isa_readreg(struct lm_softc *sc, int reg)
|
2002-11-15 17:55:41 +03:00
|
|
|
{
|
|
|
|
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
|
2007-03-07 20:32:47 +03:00
|
|
|
return bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA);
|
2002-11-15 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-03-07 20:32:47 +03:00
|
|
|
lm_isa_writereg(struct lm_softc *sc, int reg, int val)
|
2002-11-15 17:55:41 +03:00
|
|
|
{
|
|
|
|
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
|
|
|
|
bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
|
|
|
|
}
|