2006-03-29 21:23:56 +04:00
|
|
|
/* $NetBSD: ppbus_conf.c,v 1.11 2006/03/29 17:23:56 thorpej Exp $ */
|
2004-01-21 03:33:37 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998, 1999 Nicolas Souchu
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
2004-01-25 03:28:01 +03:00
|
|
|
* FreeBSD: src/sys/dev/ppbus/ppbconf.c,v 1.17.2.1 2000/05/24 00:20:57 n_hibma Exp
|
2004-01-20 02:22:23 +03:00
|
|
|
*
|
|
|
|
*/
|
2004-01-25 03:28:01 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2006-03-29 21:23:56 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ppbus_conf.c,v 1.11 2006/03/29 17:23:56 thorpej Exp $");
|
2004-01-25 03:28:01 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
#include "opt_ppbus.h"
|
2004-02-01 20:28:48 +03:00
|
|
|
#include "opt_ppbus_1284.h"
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbus_1284.h>
|
|
|
|
#include <dev/ppbus/ppbus_base.h>
|
|
|
|
#include <dev/ppbus/ppbus_conf.h>
|
|
|
|
#include <dev/ppbus/ppbus_device.h>
|
|
|
|
#include <dev/ppbus/ppbus_var.h>
|
|
|
|
|
|
|
|
/* Probe, attach, and detach functions for ppbus. */
|
2004-09-09 00:12:20 +04:00
|
|
|
static int ppbus_probe(struct device *, struct cfdata *, void *);
|
|
|
|
static void ppbus_attach(struct device *, struct device *, void *);
|
|
|
|
static int ppbus_detach(struct device *, int);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
/* Utility function prototypes */
|
2004-09-09 00:12:20 +04:00
|
|
|
static int ppbus_search_children(struct device *, struct cfdata *,
|
2005-08-26 16:42:11 +04:00
|
|
|
const int *, void *);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
CFATTACH_DECL(ppbus, sizeof(struct ppbus_softc), ppbus_probe, ppbus_attach,
|
|
|
|
ppbus_detach, NULL);
|
|
|
|
|
|
|
|
/* Probe function for ppbus. */
|
|
|
|
static int
|
2004-09-09 00:12:20 +04:00
|
|
|
ppbus_probe(struct device *parent, struct cfdata *cf, void *aux)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-09-09 00:12:20 +04:00
|
|
|
struct parport_adapter *sc_link = aux;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/* Check adapter for consistency */
|
2004-09-09 00:12:20 +04:00
|
|
|
if (
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Required methods for all parports */
|
2005-02-27 03:26:58 +03:00
|
|
|
sc_link->parport_io == NULL ||
|
2004-01-20 02:22:23 +03:00
|
|
|
sc_link->parport_exec_microseq == NULL ||
|
|
|
|
sc_link->parport_setmode == NULL ||
|
|
|
|
sc_link->parport_getmode == NULL ||
|
|
|
|
sc_link->parport_read == NULL ||
|
|
|
|
sc_link->parport_write == NULL ||
|
|
|
|
sc_link->parport_read_ivar == NULL ||
|
|
|
|
sc_link->parport_write_ivar == NULL ||
|
|
|
|
/* Methods which conditional exist based on capabilities */
|
2005-02-27 03:26:58 +03:00
|
|
|
((sc_link->capabilities & PPBUS_HAS_EPP) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
(sc_link->parport_reset_epp_timeout == NULL)) ||
|
2005-02-27 03:26:58 +03:00
|
|
|
((sc_link->capabilities & PPBUS_HAS_ECP) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
(sc_link->parport_ecp_sync == NULL)) ||
|
2005-02-27 03:26:58 +03:00
|
|
|
((sc_link->capabilities & PPBUS_HAS_DMA) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
(sc_link->parport_dma_malloc == NULL ||
|
2005-02-27 03:26:58 +03:00
|
|
|
sc_link->parport_dma_free == NULL)) ||
|
|
|
|
((sc_link->capabilities & PPBUS_HAS_INTR) &&
|
2004-01-20 02:22:23 +03:00
|
|
|
(sc_link->parport_add_handler == NULL ||
|
|
|
|
sc_link->parport_remove_handler == NULL))
|
|
|
|
) {
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
#ifdef PPBUS_DEBUG
|
|
|
|
printf("%s(%s): parport_adaptor is incomplete. Child device "
|
|
|
|
"probe failed.\n", __func__, parent->dv_xname);
|
|
|
|
#endif
|
|
|
|
return 0;
|
2004-09-09 00:12:20 +04:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach function for ppbus. */
|
|
|
|
static void
|
2004-09-09 00:12:20 +04:00
|
|
|
ppbus_attach(struct device *parent, struct device *self, void *aux)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2006-03-29 21:23:56 +04:00
|
|
|
struct ppbus_softc *ppbus = device_private(self);
|
2004-09-09 00:12:20 +04:00
|
|
|
struct parport_adapter *sc_link = aux;
|
2004-01-20 02:22:23 +03:00
|
|
|
struct ppbus_attach_args args;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Initialize config data from adapter (bus + device methods) */
|
2005-02-27 03:26:58 +03:00
|
|
|
args.capabilities = ppbus->sc_capabilities = sc_link->capabilities;
|
2004-01-20 02:22:23 +03:00
|
|
|
ppbus->ppbus_io = sc_link->parport_io;
|
|
|
|
ppbus->ppbus_exec_microseq = sc_link->parport_exec_microseq;
|
|
|
|
ppbus->ppbus_reset_epp_timeout = sc_link->
|
|
|
|
parport_reset_epp_timeout;
|
|
|
|
ppbus->ppbus_setmode = sc_link->parport_setmode;
|
|
|
|
ppbus->ppbus_getmode = sc_link->parport_getmode;
|
|
|
|
ppbus->ppbus_ecp_sync = sc_link->parport_ecp_sync;
|
|
|
|
ppbus->ppbus_read = sc_link->parport_read;
|
|
|
|
ppbus->ppbus_write = sc_link->parport_write;
|
|
|
|
ppbus->ppbus_read_ivar = sc_link->parport_read_ivar;
|
|
|
|
ppbus->ppbus_write_ivar = sc_link->parport_write_ivar;
|
|
|
|
ppbus->ppbus_dma_malloc = sc_link->parport_dma_malloc;
|
|
|
|
ppbus->ppbus_dma_free = sc_link->parport_dma_free;
|
|
|
|
ppbus->ppbus_add_handler = sc_link->parport_add_handler;
|
|
|
|
ppbus->ppbus_remove_handler = sc_link->parport_remove_handler;
|
|
|
|
|
|
|
|
/* Initially there is no device owning the bus */
|
|
|
|
ppbus->ppbus_owner = NULL;
|
|
|
|
|
|
|
|
/* Initialize locking structures */
|
2005-02-27 03:26:58 +03:00
|
|
|
lockinit(&(ppbus->sc_lock), PPBUSPRI | PCATCH, "ppbuslock", 0,
|
2004-01-20 02:22:23 +03:00
|
|
|
LK_NOWAIT);
|
|
|
|
|
|
|
|
/* Set up bus mode and ieee state */
|
2006-03-25 06:44:35 +03:00
|
|
|
ppbus->sc_mode = ppbus->ppbus_getmode(device_parent(self));
|
2004-01-20 02:22:23 +03:00
|
|
|
ppbus->sc_use_ieee = 1;
|
|
|
|
ppbus->sc_1284_state = PPBUS_FORWARD_IDLE;
|
|
|
|
ppbus->sc_1284_error = PPBUS_NO_ERROR;
|
|
|
|
|
|
|
|
/* Record device's sucessful attachment */
|
|
|
|
ppbus->sc_dev_ok = PPBUS_OK;
|
|
|
|
|
|
|
|
#ifndef DONTPROBE_1284
|
|
|
|
/* detect IEEE1284 compliant devices */
|
2004-09-09 00:12:20 +04:00
|
|
|
if (ppbus_scan_bus(self)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: No IEEE1284 device found.\n", self->dv_xname);
|
2004-09-09 00:12:20 +04:00
|
|
|
} else {
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: IEEE1284 device found.\n", self->dv_xname);
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
|
|
|
* Detect device ID (interrupts must be disabled because we
|
|
|
|
* cannot do a ltsleep() to wait for it - no context)
|
2004-01-20 02:22:23 +03:00
|
|
|
*/
|
2004-09-09 00:12:20 +04:00
|
|
|
if (args.capabilities & PPBUS_HAS_INTR) {
|
2004-01-20 02:22:23 +03:00
|
|
|
int val = 0;
|
|
|
|
if(ppbus_write_ivar(self, PPBUS_IVAR_INTR, &val) != 0) {
|
|
|
|
printf(" <problem initializing interrupt "
|
|
|
|
"usage>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ppbus_pnp_detect(self);
|
|
|
|
}
|
|
|
|
#endif /* !DONTPROBE_1284 */
|
|
|
|
|
|
|
|
/* Configure child devices */
|
|
|
|
SLIST_INIT(&(ppbus->sc_childlist_head));
|
2004-09-09 00:12:20 +04:00
|
|
|
config_search_ia(ppbus_search_children, self, "ppbus", &args);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach function for ppbus. */
|
|
|
|
static int
|
2004-09-09 00:12:20 +04:00
|
|
|
ppbus_detach(struct device *self, int flag)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2006-03-29 21:23:56 +04:00
|
|
|
struct ppbus_softc * ppbus = device_private(self);
|
2004-01-20 02:22:23 +03:00
|
|
|
struct ppbus_device_softc * child;
|
|
|
|
|
2004-09-09 00:12:20 +04:00
|
|
|
if (ppbus->sc_dev_ok != PPBUS_OK) {
|
|
|
|
if (!(flag & DETACH_QUIET))
|
2005-02-27 03:26:58 +03:00
|
|
|
printf("%s: detach called on unattached device.\n",
|
2004-01-20 02:22:23 +03:00
|
|
|
ppbus->sc_dev.dv_xname);
|
2004-09-09 00:12:20 +04:00
|
|
|
if (!(flag & DETACH_FORCE))
|
2004-01-20 02:22:23 +03:00
|
|
|
return 0;
|
2004-09-09 00:12:20 +04:00
|
|
|
if (!(flag & DETACH_QUIET))
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: continuing detach (DETACH_FORCE).\n",
|
|
|
|
ppbus->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
|
2004-09-09 00:12:20 +04:00
|
|
|
if (lockmgr(&(ppbus->sc_lock), LK_DRAIN, NULL)) {
|
|
|
|
if (!(flag & DETACH_QUIET))
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: error while waiting for lock activity to "
|
|
|
|
"end.\n", ppbus->sc_dev.dv_xname);
|
2004-09-09 00:12:20 +04:00
|
|
|
if (!(flag & DETACH_FORCE))
|
2004-01-20 02:22:23 +03:00
|
|
|
return 0;
|
2004-09-09 00:12:20 +04:00
|
|
|
if (!(flag & DETACH_QUIET))
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: continuing detach (DETACH_FORCE).\n",
|
|
|
|
ppbus->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detach children devices */
|
2004-09-09 00:12:20 +04:00
|
|
|
while (!SLIST_EMPTY(&(ppbus->sc_childlist_head))) {
|
2004-01-20 02:22:23 +03:00
|
|
|
child = SLIST_FIRST(&(ppbus->sc_childlist_head));
|
|
|
|
config_deactivate((struct device *)child);
|
2004-09-09 00:12:20 +04:00
|
|
|
if (config_detach((struct device *)child, flag)) {
|
2004-01-20 02:22:23 +03:00
|
|
|
if(!(flag & DETACH_QUIET))
|
2005-02-27 03:26:58 +03:00
|
|
|
printf("%s: error detaching %s.",
|
|
|
|
ppbus->sc_dev.dv_xname,
|
2004-01-20 02:22:23 +03:00
|
|
|
child->sc_dev.dv_xname);
|
|
|
|
if(!(flag & DETACH_FORCE))
|
|
|
|
return 0;
|
|
|
|
if(!(flag & DETACH_QUIET))
|
|
|
|
printf("%s: continuing (DETACH_FORCE).\n",
|
|
|
|
ppbus->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
SLIST_REMOVE_HEAD(&(ppbus->sc_childlist_head), entries);
|
|
|
|
}
|
|
|
|
|
2004-09-09 00:12:20 +04:00
|
|
|
if (!(flag & DETACH_QUIET))
|
2004-01-20 02:22:23 +03:00
|
|
|
printf("%s: detached.\n", ppbus->sc_dev.dv_xname);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for children device and add to list */
|
|
|
|
static int
|
2004-09-09 00:12:20 +04:00
|
|
|
ppbus_search_children(struct device *parent, struct cfdata *cf,
|
2005-08-26 16:42:11 +04:00
|
|
|
const int *ldesc, void *aux)
|
2004-01-20 02:22:23 +03:00
|
|
|
{
|
2004-09-09 00:12:20 +04:00
|
|
|
struct ppbus_softc *ppbus = (struct ppbus_softc *)parent;
|
|
|
|
struct ppbus_device_softc *child;
|
2004-01-20 02:22:23 +03:00
|
|
|
int rval = 0;
|
|
|
|
|
2004-09-09 00:12:20 +04:00
|
|
|
if (config_match(parent, cf, aux) > 0) {
|
2005-02-27 03:26:58 +03:00
|
|
|
child = (struct ppbus_device_softc *) config_attach(parent,
|
2004-09-13 16:49:58 +04:00
|
|
|
cf, aux, NULL);
|
2004-09-09 00:12:20 +04:00
|
|
|
if (child) {
|
2005-02-27 03:26:58 +03:00
|
|
|
SLIST_INSERT_HEAD(&(ppbus->sc_childlist_head), child,
|
2004-01-20 02:22:23 +03:00
|
|
|
entries);
|
|
|
|
rval = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|