Split device_t/softc for joy(4) and all its attachments. Also

use device_lookup_private() and related cosmetic changes.

Reviewed by cube@.
This commit is contained in:
xtraeme 2008-03-26 18:27:07 +00:00
parent 51a43e5da8
commit 701c2ae0a3
11 changed files with 170 additions and 183 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_pnpbios.c,v 1.10 2006/11/16 01:32:39 christos Exp $ */
/* $NetBSD: joy_pnpbios.c,v 1.11 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_pnpbios.c,v 1.10 2006/11/16 01:32:39 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_pnpbios.c,v 1.11 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -53,37 +53,36 @@ __KERNEL_RCSID(0, "$NetBSD: joy_pnpbios.c,v 1.10 2006/11/16 01:32:39 christos Ex
#include <dev/ic/joyvar.h>
int joy_pnpbios_match(struct device *, struct cfdata *, void *);
void joy_pnpbios_attach(struct device *, struct device *, void *);
static int joy_pnpbios_match(device_t, cfdata_t, void *);
static void joy_pnpbios_attach(device_t, device_t, void *);
CFATTACH_DECL(joy_pnpbios, sizeof(struct joy_softc),
CFATTACH_DECL_NEW(joy_pnpbios, sizeof(struct joy_softc),
joy_pnpbios_match, joy_pnpbios_attach, NULL, NULL);
int
joy_pnpbios_match(struct device *parent, struct cfdata *match,
void *aux)
static int
joy_pnpbios_match(device_t parent, cfdata_t match, void *aux)
{
struct pnpbiosdev_attach_args *aa = aux;
if (strcmp(aa->idstr, "PNPB02F"))
return (0);
return 0;
return (1);
return 1;
}
void
joy_pnpbios_attach(struct device *parent, struct device *self,
void *aux)
static void
joy_pnpbios_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = (struct joy_softc *)self;
struct joy_softc *sc = device_private(self);
struct pnpbiosdev_attach_args *aa = aux;
if (pnpbios_io_map(aa->pbt, aa->resc, 0, &sc->sc_iot, &sc->sc_ioh)) {
printf(": can't map i/o space\n");
aprint_error(": can't map i/o space\n");
return;
}
printf("\n");
aprint_normal("\n");
sc->sc_dev = self;
pnpbios_print_devres(self, aa);
joyattach(sc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_acpi.c,v 1.7 2007/10/19 11:59:35 ad Exp $ */
/* $NetBSD: joy_acpi.c,v 1.8 2008/03/26 18:27:07 xtraeme Exp $ */
/*
* Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_acpi.c,v 1.7 2007/10/19 11:59:35 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_acpi.c,v 1.8 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -47,14 +47,14 @@ __KERNEL_RCSID(0, "$NetBSD: joy_acpi.c,v 1.7 2007/10/19 11:59:35 ad Exp $");
#include <dev/ic/joyvar.h>
static int joy_acpi_match(struct device *, struct cfdata *, void *);
static void joy_acpi_attach(struct device *, struct device *, void *);
static int joy_acpi_match(device_t, cfdata_t, void *);
static void joy_acpi_attach(device_t, device_t, void *);
struct joy_acpi_softc {
struct joy_softc sc_joy;
};
CFATTACH_DECL(joy_acpi, sizeof(struct joy_acpi_softc), joy_acpi_match,
CFATTACH_DECL_NEW(joy_acpi, sizeof(struct joy_acpi_softc), joy_acpi_match,
joy_acpi_attach, NULL, NULL);
/*
@ -70,8 +70,7 @@ static const char * const joy_acpi_ids[] = {
* joy_acpi_match: autoconf(9) match routine
*/
static int
joy_acpi_match(struct device *parent, struct cfdata *match,
void *aux)
joy_acpi_match(device_t parent, cfdata_t match, void *aux)
{
struct acpi_attach_args *aa = aux;
@ -85,9 +84,9 @@ joy_acpi_match(struct device *parent, struct cfdata *match,
* joy_acpi_attach: autoconf(9) attach routine
*/
static void
joy_acpi_attach(struct device *parent, struct device *self, void *aux)
joy_acpi_attach(device_t parent, device_t self, void *aux)
{
struct joy_acpi_softc *asc = (struct joy_acpi_softc *)self;
struct joy_acpi_softc *asc = device_private(self);
struct joy_softc *sc = &asc->sc_joy;
struct acpi_attach_args *aa = aux;
struct acpi_resources res;
@ -97,8 +96,10 @@ joy_acpi_attach(struct device *parent, struct device *self, void *aux)
aprint_naive("\n");
aprint_normal("\n");
sc->sc_dev = self;
/* parse resources */
rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
&res, &acpi_resource_parse_ops_default);
if (ACPI_FAILURE(rv))
return;
@ -106,15 +107,15 @@ joy_acpi_attach(struct device *parent, struct device *self, void *aux)
/* find our i/o registers */
io = acpi_res_io(&res, 0);
if (io == NULL) {
aprint_error("%s: unable to find i/o register resource\n",
sc->sc_dev.dv_xname);
aprint_error_dev(self,
"unable to find i/o register resource\n");
goto out;
}
sc->sc_iot = aa->aa_iot;
if (bus_space_map(sc->sc_iot, io->ar_base, io->ar_length,
0, &sc->sc_ioh)) {
aprint_error("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
aprint_error_dev(self, "can't map i/o space\n");
goto out;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy.c,v 1.16 2007/12/01 23:40:28 jmcneill Exp $ */
/* $NetBSD: joy.c,v 1.17 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 1995 Jean-Marc Zucconi
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.16 2007/12/01 23:40:28 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy.c,v 1.17 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -78,14 +78,12 @@ const struct cdevsw joy_cdevsw = {
};
void
joyattach(sc)
struct joy_softc *sc;
joyattach(struct joy_softc *sc)
{
sc->timeout[0] = sc->timeout[1] = 0;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, 0xff);
DELAY(10000); /* 10 ms delay */
aprint_normal_dev(&sc->sc_dev, "joystick %sconnected\n",
aprint_normal_dev(sc->sc_dev, "joystick %sconnected\n",
(bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0) & 0x0f) == 0x0f ?
"not " : "");
}
@ -96,11 +94,11 @@ joydetach(struct joy_softc *sc, int flags)
int maj, mn;
maj = cdevsw_lookup_major(&joy_cdevsw);
mn = device_unit(&sc->sc_dev) << 1;
mn = device_unit(sc->sc_dev) << 1;
vdevgone(maj, mn, mn, VCHR);
vdevgone(maj, mn + 1, mn + 1, VCHR);
return (0);
return 0;
}
int
@ -110,37 +108,34 @@ joyopen(dev_t dev, int flag, int mode, struct lwp *l)
int i = JOYPART(dev);
struct joy_softc *sc;
if (unit >= joy_cd.cd_ndevs)
return (ENXIO);
sc = joy_cd.cd_devs[unit];
if (sc == 0)
return (ENXIO);
sc = device_lookup_private(&joy_cd, unit);
if (sc == NULL)
return ENXIO;
if (sc->timeout[i])
return (EBUSY);
return EBUSY;
sc->x_off[i] = sc->y_off[i] = 0;
sc->timeout[i] = JOY_TIMEOUT;
return (0);
return 0;
}
int
joyclose(dev_t dev, int flag, int mode,
struct lwp *l)
joyclose(dev_t dev, int flag, int mode, struct lwp *l)
{
int unit = JOYUNIT(dev);
int i = JOYPART(dev);
struct joy_softc *sc = joy_cd.cd_devs[unit];
struct joy_softc *sc = device_lookup_private(&joy_cd, unit);
sc->timeout[i] = 0;
return (0);
return 0;
}
int
joyread(dev_t dev, struct uio *uio, int flag)
{
int unit = JOYUNIT(dev);
struct joy_softc *sc = joy_cd.cd_devs[unit];
struct joy_softc *sc = device_lookup_private(&joy_cd, unit);
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh = sc->sc_ioh;
struct joystick c;
@ -175,42 +170,41 @@ joyread(dev_t dev, struct uio *uio, int flag)
state >>= 4;
c.b1 = ~state & 1;
c.b2 = ~(state >> 1) & 1;
return (uiomove(&c, sizeof(struct joystick), uio));
return uiomove(&c, sizeof(struct joystick), uio);
}
int
joyioctl(dev_t dev, u_long cmd, void *data, int flag,
struct lwp *l)
joyioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
int unit = JOYUNIT(dev);
struct joy_softc *sc = joy_cd.cd_devs[unit];
struct joy_softc *sc = device_lookup_private(&joy_cd, unit);
int i = JOYPART(dev);
int x;
switch (cmd) {
case JOY_SETTIMEOUT:
x = *(int *) data;
x = *(int *)data;
if (x < 1 || x > 10000) /* 10ms maximum! */
return (EINVAL);
return EINVAL;
sc->timeout[i] = x;
break;
case JOY_GETTIMEOUT:
*(int *) data = sc->timeout[i];
*(int *)data = sc->timeout[i];
break;
case JOY_SET_X_OFFSET:
sc->x_off[i] = *(int *) data;
sc->x_off[i] = *(int *)data;
break;
case JOY_SET_Y_OFFSET:
sc->y_off[i] = *(int *) data;
sc->y_off[i] = *(int *)data;
break;
case JOY_GET_X_OFFSET:
*(int *) data = sc->x_off[i];
*(int *)data = sc->x_off[i];
break;
case JOY_GET_Y_OFFSET:
*(int *) data = sc->y_off[i];
*(int *)data = sc->y_off[i];
break;
default:
return (ENXIO);
return ENXIO;
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: joyvar.h,v 1.5 2005/12/11 12:21:27 christos Exp $ */
/* $NetBSD: joyvar.h,v 1.6 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 1995 Jean-Marc Zucconi
@ -39,7 +39,7 @@
*/
struct joy_softc {
struct device sc_dev;
device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
int x_off[2], y_off[2];

View File

@ -1,7 +1,7 @@
/* $NetBSD: joy_ess.c,v 1.4 2007/12/11 11:56:46 lukem Exp $ */
/* $NetBSD: joy_ess.c,v 1.5 2008/03/26 18:27:07 xtraeme Exp $ */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_ess.c,v 1.4 2007/12/11 11:56:46 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_ess.c,v 1.5 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -15,32 +15,33 @@ __KERNEL_RCSID(0, "$NetBSD: joy_ess.c,v 1.4 2007/12/11 11:56:46 lukem Exp $");
#include <dev/isa/essvar.h>
#include <dev/ic/joyvar.h>
int joy_ess_match(struct device *, struct cfdata *, void *);
void joy_ess_attach(struct device *, struct device *, void *);
static int joy_ess_match(device_t, cfdata_t, void *);
static void joy_ess_attach(device_t, device_t, void *);
CFATTACH_DECL(joy_ess, sizeof (struct joy_softc),
CFATTACH_DECL_NEW(joy_ess, sizeof (struct joy_softc),
joy_ess_match, joy_ess_attach, NULL, NULL);
int
joy_ess_match(struct device *parent, struct cfdata *match, void *aux)
static int
joy_ess_match(device_t parent, cfdata_t match, void *aux)
{
struct audio_attach_args *aa = aux;
if (aa->type != AUDIODEV_TYPE_AUX)
return (0);
return (1);
return 0;
return 1;
}
void
joy_ess_attach(struct device *parent, struct device *self, void *aux)
static void
joy_ess_attach(device_t parent, device_t self, void *aux)
{
struct ess_softc *esc = (struct ess_softc *)parent;
struct joy_softc *sc = (struct joy_softc *)self;
struct ess_softc *esc = device_private(parent);
struct joy_softc *sc = device_private(self);
printf("\n");
aprint_normal("\n");
sc->sc_iot = esc->sc_joy_iot;
sc->sc_ioh = esc->sc_joy_ioh;
sc->sc_dev = self;
joyattach(sc);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_isa.c,v 1.11 2007/10/19 12:00:20 ad Exp $ */
/* $NetBSD: joy_isa.c,v 1.12 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 1995 Jean-Marc Zucconi
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_isa.c,v 1.11 2007/10/19 12:00:20 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_isa.c,v 1.12 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -48,15 +48,14 @@ __KERNEL_RCSID(0, "$NetBSD: joy_isa.c,v 1.11 2007/10/19 12:00:20 ad Exp $");
#define JOY_NPORTS 1
int joy_isa_probe(struct device *, struct cfdata *, void *);
void joy_isa_attach(struct device *, struct device *, void *);
static int joy_isa_probe(device_t, cfdata_t, void *);
static void joy_isa_attach(device_t, device_t, void *);
CFATTACH_DECL(joy_isa, sizeof(struct joy_softc),
CFATTACH_DECL_NEW(joy_isa, sizeof(struct joy_softc),
joy_isa_probe, joy_isa_attach, NULL, NULL);
int
joy_isa_probe(struct device *parent, struct cfdata *match,
void *aux)
static int
joy_isa_probe(device_t parent, cfdata_t match, void *aux)
{
struct isa_attach_args *ia = aux;
bus_space_tag_t iot = ia->ia_iot;
@ -64,13 +63,13 @@ joy_isa_probe(struct device *parent, struct cfdata *match,
int rval = 0;
if (ia->ia_nio < 1)
return (0);
return 0;
if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
return (0);
return 0;
if (bus_space_map(iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0, &ioh))
return (0);
return 0;
#ifdef WANT_JOYSTICK_CONNECTED
bus_space_write_1(iot, ioh, 0, 0xff);
@ -91,22 +90,23 @@ joy_isa_probe(struct device *parent, struct cfdata *match,
ia->ia_nirq = 0;
ia->ia_ndrq = 0;
}
return (rval);
return rval;
}
void
joy_isa_attach(struct device *parent, struct device *self, void *aux)
static void
joy_isa_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = (struct joy_softc *) self;
struct joy_softc *sc = device_private(self);
struct isa_attach_args *ia = aux;
printf("\n");
aprint_normal("\n");
sc->sc_iot = ia->ia_iot;
sc->sc_dev = self;
if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, JOY_NPORTS, 0,
&sc->sc_ioh)) {
printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
aprint_error_dev(self, "can't map i/o space\n");
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_isapnp.c,v 1.10 2007/10/19 12:00:32 ad Exp $ */
/* $NetBSD: joy_isapnp.c,v 1.11 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_isapnp.c,v 1.10 2007/10/19 12:00:32 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_isapnp.c,v 1.11 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -53,45 +53,41 @@ __KERNEL_RCSID(0, "$NetBSD: joy_isapnp.c,v 1.10 2007/10/19 12:00:32 ad Exp $");
#include <dev/ic/joyvar.h>
int joy_isapnp_match(struct device *, struct cfdata *, void *);
void joy_isapnp_attach(struct device *, struct device *, void *);
static int joy_isapnp_match(device_t, cfdata_t, void *);
static void joy_isapnp_attach(device_t, device_t, void *);
CFATTACH_DECL(joy_isapnp, sizeof(struct joy_softc),
CFATTACH_DECL_NEW(joy_isapnp, sizeof(struct joy_softc),
joy_isapnp_match, joy_isapnp_attach, NULL, NULL);
int
joy_isapnp_match(struct device *parent, struct cfdata *match,
void *aux)
static int
joy_isapnp_match(device_t parent, cfdata_t match, void *aux)
{
int pri, variant;
pri = isapnp_devmatch(aux, &isapnp_joy_devinfo, &variant);
if (pri && variant > 0)
pri = 0;
return (pri);
return pri;
}
void
joy_isapnp_attach(struct device *parent, struct device *self,
void *aux)
static void
joy_isapnp_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = device_private(self);
struct isapnp_attach_args *ipa = aux;
bus_space_handle_t ioh;
printf("\n");
aprint_normal("\n");
if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
printf("%s: error in region allocation\n",
sc->sc_dev.dv_xname);
aprint_error_dev(self, "error in region allocation\n");
return;
}
if (ipa->ipa_io[0].length == 8) {
if (bus_space_subregion(ipa->ipa_iot, ipa->ipa_io[0].h, 1, 1,
&ioh) < 0) {
printf("%s: error in region allocation\n",
sc->sc_dev.dv_xname);
aprint_error_dev(self, "error in region allocation\n");
return;
}
} else
@ -99,8 +95,9 @@ joy_isapnp_attach(struct device *parent, struct device *self,
sc->sc_iot = ipa->ipa_iot;
sc->sc_ioh = ioh;
sc->sc_dev = self;
printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
aprint_normal_dev(self, "%s %s\n", ipa->ipa_devident,
ipa->ipa_devclass);
joyattach(sc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_ofisa.c,v 1.12 2007/10/19 12:00:37 ad Exp $ */
/* $NetBSD: joy_ofisa.c,v 1.13 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.12 2007/10/19 12:00:37 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.13 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -54,17 +54,14 @@ __KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.12 2007/10/19 12:00:37 ad Exp $");
#define JOY_NPORTS 1 /* XXX should be in a header file */
int joy_ofisa_match(struct device *, struct cfdata *, void *);
void joy_ofisa_attach(struct device *, struct device *, void *);
static int joy_ofisa_match(device_t, cfdata_t, void *);
static void joy_ofisa_attach(device_t, device_t, void *);
CFATTACH_DECL(joy_ofisa, sizeof(struct joy_softc),
CFATTACH_DECL_NEW(joy_ofisa, sizeof(struct joy_softc),
joy_ofisa_match, joy_ofisa_attach, NULL, NULL);
int
joy_ofisa_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
static int
joy_ofisa_match(device_t parent, cfdata_t match, void *aux)
{
struct ofisa_attach_args *aa = aux;
static const char *const compatible_strings[] = {
@ -75,13 +72,11 @@ joy_ofisa_match(parent, match, aux)
if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
rv = 1;
return (rv);
return rv;
}
void
joy_ofisa_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
static void
joy_ofisa_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = device_private(self);
struct ofisa_attach_args *aa = aux;
@ -100,23 +95,24 @@ joy_ofisa_attach(parent, self, aux)
n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
if (n != 1) {
printf(": error getting register data\n");
aprint_error(": error getting register data\n");
return;
}
if (reg.type != OFISA_REG_TYPE_IO) {
printf(": register type not i/o\n");
aprint_error(": register type not i/o\n");
return;
}
if (reg.len != JOY_NPORTS) {
printf(": weird register size (%lu, expected %d)\n",
aprint_error(": weird register size (%lu, expected %d)\n",
(unsigned long)reg.len, JOY_NPORTS);
return;
}
sc->sc_iot = aa->iot;
sc->sc_dev = self;
if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
printf(": unable to map register space\n");
aprint_error(": unable to map register space\n");
return;
}
@ -127,8 +123,8 @@ joy_ofisa_attach(parent, self, aux)
model = NULL; /* safe; alloca */
}
if (model != NULL)
printf(": %s", model);
printf("\n");
aprint_normal(": %s", model);
aprint_normal("\n");
joyattach(sc);
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: joy_eap.c,v 1.8 2007/12/11 11:25:53 lukem Exp $ */
/* $NetBSD: joy_eap.c,v 1.9 2008/03/26 18:27:07 xtraeme Exp $ */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_eap.c,v 1.8 2007/12/11 11:25:53 lukem Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_eap.c,v 1.9 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -21,14 +21,14 @@ struct joy_eap_aa {
bus_space_handle_t aa_ioh;
};
struct device *
eap_joy_attach(struct device *eapdev, struct eap_gameport_args *gpa)
device_t
eap_joy_attach(device_t eapdev, struct eap_gameport_args *gpa)
{
int i;
bus_space_handle_t ioh;
u_int32_t icsc;
struct joy_eap_aa aa;
struct device *joydev;
device_t joydev;
/*
* There are 4 possible locations. Just try to map one of them.
@ -43,7 +43,7 @@ eap_joy_attach(struct device *eapdev, struct eap_gameport_args *gpa)
break;
}
if (i == 4)
return (0);
return 0;
printf("%s: enabling gameport at legacy io port 0x%x\n",
eapdev->dv_xname, 0x200 + i * 8);
@ -61,11 +61,11 @@ eap_joy_attach(struct device *eapdev, struct eap_gameport_args *gpa)
/* this cannot fail */
KASSERT(joydev != NULL);
return (joydev);
return joydev;
}
int
eap_joy_detach(struct device *joydev, struct eap_gameport_args *gpa)
eap_joy_detach(device_t joydev, struct eap_gameport_args *gpa)
{
int res;
struct joy_softc *sc = (struct joy_softc *)joydev;
@ -73,7 +73,7 @@ eap_joy_detach(struct device *joydev, struct eap_gameport_args *gpa)
res = config_detach(joydev, 0);
if (res)
return (res);
return res;
/* disable gameport on eap */
icsc = bus_space_read_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC);
@ -81,40 +81,40 @@ eap_joy_detach(struct device *joydev, struct eap_gameport_args *gpa)
bus_space_write_4(gpa->gpa_iot, gpa->gpa_ioh, EAP_ICSC, icsc);
bus_space_unmap(sc->sc_iot, sc->sc_ioh, 1);
return (0);
return 0;
}
static int
joy_eap_match(struct device *parent, struct cfdata *match,
void *aux)
joy_eap_match(device_t parent, cfdata_t match, void *aux)
{
struct joy_eap_aa *eaa = aux;
if (eaa->aa_aaa.type != AUDIODEV_TYPE_AUX)
return (0);
return (1);
return 0;
return 1;
}
static void
joy_eap_attach(struct device *parent, struct device *self, void *aux)
joy_eap_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = (struct joy_softc *)self;
struct joy_softc *sc = device_private(self);
struct joy_eap_aa *eaa = aux;
printf("\n");
aprint_normal("\n");
sc->sc_iot = eaa->aa_iot;
sc->sc_ioh = eaa->aa_ioh;
sc->sc_dev = self;
joyattach(sc);
}
static int
joy_eap_detach(struct device *self, int flags)
joy_eap_detach(device_t self, int flags)
{
return (joydetach((struct joy_softc *)self, flags));
return joydetach((struct joy_softc *)self, flags);
}
CFATTACH_DECL(joy_eap, sizeof (struct joy_softc),
CFATTACH_DECL_NEW(joy_eap, sizeof (struct joy_softc),
joy_eap_match, joy_eap_attach, joy_eap_detach, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_eso.c,v 1.12 2007/10/19 12:00:51 ad Exp $ */
/* $NetBSD: joy_eso.c,v 1.13 2008/03/26 18:27:07 xtraeme Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_eso.c,v 1.12 2007/10/19 12:00:51 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_eso.c,v 1.13 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -62,29 +62,29 @@ __KERNEL_RCSID(0, "$NetBSD: joy_eso.c,v 1.12 2007/10/19 12:00:51 ad Exp $");
#include <dev/ic/joyvar.h>
static int
joy_eso_match(struct device *parent, struct cfdata *match,
void *aux)
joy_eso_match(device_t parent, cfdata_t match, void *aux)
{
struct audio_attach_args *aa = (struct audio_attach_args *)aux;
struct audio_attach_args *aa = aux;
if (aa->type != AUDIODEV_TYPE_AUX)
return (0);
return (1);
return 0;
return 1;
}
static void
joy_eso_attach(struct device *parent, struct device *self, void *aux)
joy_eso_attach(device_t parent, device_t self, void *aux)
{
struct eso_softc *esc = (struct eso_softc *)parent;
struct joy_softc *sc = (struct joy_softc *)self;
struct eso_softc *esc = device_private(parent);
struct joy_softc *sc = device_private(self);
printf("\n");
aprint_normal("\n");
sc->sc_ioh = esc->sc_game_ioh;
sc->sc_iot = esc->sc_game_iot;
sc->sc_dev = self;
joyattach(sc);
}
CFATTACH_DECL(joy_eso, sizeof (struct joy_softc),
CFATTACH_DECL_NEW(joy_eso, sizeof (struct joy_softc),
joy_eso_match, joy_eso_attach, NULL, NULL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: joy_pci.c,v 1.15 2007/10/19 12:00:51 ad Exp $ */
/* $NetBSD: joy_pci.c,v 1.16 2008/03/26 18:27:07 xtraeme Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: joy_pci.c,v 1.15 2007/10/19 12:00:51 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: joy_pci.c,v 1.16 2008/03/26 18:27:07 xtraeme Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -55,24 +55,21 @@ __KERNEL_RCSID(0, "$NetBSD: joy_pci.c,v 1.15 2007/10/19 12:00:51 ad Exp $");
static int bar_is_io(pci_chipset_tag_t pc, pcitag_t tag, int reg);
static int
joy_pci_match(struct device *parent, struct cfdata *match,
void *aux)
joy_pci_match(device_t parent, cfdata_t match, void *aux)
{
struct pci_attach_args *pa = aux;
if (PCI_CLASS(pa->pa_class) == PCI_CLASS_INPUT &&
PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_INPUT_GAMEPORT &&
PCI_INTERFACE(pa->pa_class) == 0x10)
return (1);
return 1;
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CREATIVELABS &&
(PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CREATIVELABS_SBJOY ||
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CREATIVELABS_SBJOY2))
{
return (1);
}
return 1;
return (0);
return 0;
}
/* check if this BAR assigns/requests IO space */
@ -97,42 +94,44 @@ bar_is_io(pci_chipset_tag_t pc, pcitag_t tag, int reg)
}
static void
joy_pci_attach(struct device *parent, struct device *self, void *aux)
joy_pci_attach(device_t parent, device_t self, void *aux)
{
struct joy_softc *sc = (struct joy_softc *)self;
struct joy_softc *sc = device_private(self);
struct pci_attach_args *pa = aux;
char devinfo[256];
bus_size_t mapsize;
int reg;
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
printf(": %s (rev 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
aprint_normal(": %s (rev 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
for (reg = PCI_MAPREG_START; reg < PCI_MAPREG_END;
reg += sizeof(pcireg_t))
if (bar_is_io(pa->pa_pc, pa->pa_tag, reg))
break;
if (reg >= PCI_MAPREG_END) {
printf("%s: violates PCI spec, no IO region found\n",
sc->sc_dev.dv_xname);
aprint_error_dev(self,
"violates PCI spec, no IO region found\n");
return;
}
if (pci_mapreg_map(pa, reg, PCI_MAPREG_TYPE_IO, 0,
&sc->sc_iot, &sc->sc_ioh, NULL, &mapsize)) {
printf("%s: could not map IO space\n", sc->sc_dev.dv_xname);
aprint_error_dev(self, "could not map IO space\n");
return;
}
if (mapsize != 2) {
if (!bus_space_subregion(sc->sc_iot, sc->sc_ioh, 1, 1, &sc->sc_ioh) < 0) {
printf("%s: error mapping subregion\n", sc->sc_dev.dv_xname);
aprint_error_dev(self, "error mapping subregion\n");
return;
}
}
sc->sc_dev = self;
joyattach(sc);
}
CFATTACH_DECL(joy_pci, sizeof(struct joy_softc),
CFATTACH_DECL_NEW(joy_pci, sizeof(struct joy_softc),
joy_pci_match, joy_pci_attach, NULL, NULL);