/* $NetBSD: et4000.c,v 1.29 2023/12/20 00:40:43 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Julian Coleman.
*
* 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.
*/
/*
* Thanks to:
* Leo Weppelman
* 'Maximum Entropy'
* Thomas Gerner
* Juergen Orscheidt
* for their help and for code that I could refer to when writing this driver.
*
* Defining DEBUG_ET4000 will cause the driver to *always* attach. Use for
* debugging register settings.
*/
/*
* Allow a 8Kb io-region and a 1MB frame buffer to be mapped. This
* is more or less required by the XFree server. The X server also
* requires that the frame buffer be mapped above 0x3fffff.
*/
#define REG_MAPPABLE (8 * 1024) /* 0x2000 */
#define FRAME_MAPPABLE (1 * 1024 * 1024) /* 0x100000 */
#define FRAME_BASE (4 * 1024 * 1024) /* 0x400000 */
#define VGA_MAPPABLE (128 * 1024) /* 0x20000 */
#define VGA_BASE 0xa0000
static int et4k_vme_match(device_t, cfdata_t, void *);
static void et4k_vme_attach(device_t, device_t, void *);
static int et4k_probe_addresses(struct vme_attach_args *);
static void et4k_start(bus_space_tag_t *, bus_space_handle_t *, int *,
u_char *);
static void et4k_stop(bus_space_tag_t *, bus_space_handle_t *, int *,
u_char *);
static int et4k_detect(bus_space_tag_t *, bus_space_tag_t *,
bus_space_handle_t *, bus_space_handle_t *, u_int);
struct grfabs_et4k_priv {
volatile void * regkva;
volatile void * memkva;
int regsz;
int memsz;
} et4k_priv;
struct et4k_softc {
device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_ioh;
bus_space_handle_t sc_memh;
int sc_flags;
int sc_iobase;
int sc_maddr;
int sc_iosize;
int sc_msize;
};
/*
* Look for a ET4000 (Crazy Dots) card on the VME bus. We might
* match Spektrum cards too (untested).
*/
int
et4k_vme_match(device_t parent, cfdata_t cf, void *aux)
{
struct vme_attach_args *va = aux;
return et4k_probe_addresses(va);
}
static int
et4k_probe_addresses(struct vme_attach_args *va)
{
int i, found = 0;
bus_space_tag_t iot;
bus_space_tag_t memt;
bus_space_handle_t ioh;
bus_space_handle_t memh;
iot = va->va_iot;
memt = va->va_memt;
/* Loop around our possible addresses looking for a match */
for (i = 0; i < NET4KSTD; i++) {
struct et4k_addresses *et4k_ap = &et4kstd[i];
struct vme_attach_args vat = *va;
static int
et4k_detect(bus_space_tag_t *iot, bus_space_tag_t *memt, bus_space_handle_t *ioh, bus_space_handle_t *memh, u_int memsize)
{
u_char orig, new, saved;
int vgabase;
/* Test accessibility of registers and memory */
if (!bus_space_peek_1(*iot, *ioh, GREG_STATUS1_R))
return 0;
if (!bus_space_peek_1(*memt, *memh, 0))
return 0;