/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* 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 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.
*/
/*
* Try to give (mc) to the controller. Returns 1 if successful, 0 on
* failure (the controller is not ready to take a command).
*
* Must be called at splbio or in a fashion that prevents reentry.
*/
static int
mlx_v1_submit(struct mlx_softc *mlx, struct mlx_ccb *mc)
{
/* Ready for our command? */
if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_FULL) == 0) {
/* Copy mailbox data to window. */
bus_space_write_region_1(mlx->mlx_iot, mlx->mlx_ioh,
MLX_V1REG_MAILBOX, mc->mc_mbox, 13);
/* Post command. */
mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_FULL);
return (1);
}
return (0);
}
/*
* See if a command has been completed, if so acknowledge its completion and
* recover the slot number and status code.
*
* Must be called at splbio or in a fashion that prevents reentry.
*/
static int
mlx_v1_findcomplete(struct mlx_softc *mlx, u_int *slot, u_int *status)
{
/*
* Enable/disable interrupts as requested. (No acknowledge required)
*
* Must be called at splbio or in a fashion that prevents reentry.
*/
static void
mlx_v1_intaction(struct mlx_softc *mlx, int action)
{
mlx_outb(mlx, MLX_V1REG_IE, action ? 1 : 0);
}
/*
* Poll for firmware error codes during controller initialisation.
*
* Returns 0 if initialisation is complete, 1 if still in progress but no
* error has been fetched, 2 if an error has been retrieved.
*/
static int
mlx_v1_fw_handshake(struct mlx_softc *mlx, int *error, int *param1, int *param2)
{
u_int8_t fwerror;
/*
* First time around, enable the IDB interrupt and clear any
* hardware completion status.
*/
if ((mlx->mlx_flags & MLXF_FW_INITTED) == 0) {
mlx_outb(mlx, MLX_V1REG_ODB_EN, 1);
DELAY(1000);
mlx_outb(mlx, MLX_V1REG_ODB, 1);
DELAY(1000);
mlx_outb(mlx, MLX_V1REG_IDB, MLX_V1_IDB_SACK);
DELAY(1000);
mlx->mlx_flags |= MLXF_FW_INITTED;
}
/* Init in progress? */
if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_INIT_BUSY) == 0)
return (0);
/* Test error value. */
fwerror = mlx_inb(mlx, MLX_V1REG_ODB);
if ((fwerror & MLX_V1_FWERROR_PEND) == 0)
return (1);
/* Wait up to 2 minutes for the bit to clear. */
for (i = 120; i != 0; i--) {
delay(1000000);
if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_SACK) == 0)
break;
}
if (i == 0)
return (-1);
/* Wait up to 5 seconds for the bit to clear... */
for (i = 5; i != 0; i--) {
delay(1000000);
if ((mlx_inb(mlx, MLX_V1REG_IDB) & MLX_V1_IDB_RESET) == 0)
break;
}
if (i == 0)
return (-1);
/* Wait up to 3 seconds for the other bit to clear... */
for (i = 5; i != 0; i--) {
delay(1000000);
if ((mlx_inb(mlx, MLX_V1REG_ODB) & MLX_V1_ODB_RESET) == 0)
break;
}
if (i == 0)
return (-1);
return (0);
}
#endif /* MLX_RESET */
MODULE(MODULE_CLASS_DRIVER, mlx_eisa, "mlx"); /* No eisa module yet! */
#ifdef _MODULE
/*
* XXX Don't allow ioconf.c to redefine the "struct cfdriver cac_cd"
* XXX it will be defined in the common-code module
*/
#undef CFDRIVER_DECL
#define CFDRIVER_DECL(name, class, attr)
#include "ioconf.c"
#endif
static int
mlx_eisa_modcmd(modcmd_t cmd, void *opaque)
{
int error = 0;
#ifdef _MODULE
switch (cmd) {
case MODULE_CMD_INIT:
/*
* We skip over the first entry in cfdriver[] array
* since the cfdriver is attached by the common
* (non-attachment-specific) code.
*/
error = config_init_component(&cfdriver_ioconf_mlx_eisa[1],
cfattach_ioconf_mlx_eisa, cfdata_ioconf_mlx_eisa);
break;
case MODULE_CMD_FINI:
error = config_fini_component(&cfdriver_ioconf_mlx_eisa[1],
cfattach_ioconf_mlx_eisa, cfdata_ioconf_mlx_eisa);
break;
default:
error = ENOTTY;
break;
}
#endif