#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa_machdep.c,v 1.14 2020/11/22 03:57:19 thorpej Exp $");
#include "opt_compat_old_ofw.h"
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/kmem.h>
#include <sys/socket.h>
#include <sys/bus.h>
#include <sys/rndsource.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>
#include <machine/intr.h>
#include <dev/ofw/openfirm.h>
#include <dev/isa/isavar.h>
#include <dev/ofisa/ofisavar.h>
#include <dev/ic/cs89x0reg.h>
#include <dev/ic/cs89x0var.h>
#ifdef COMPAT_OLD_OFW
int
cs_ofisa_md_match(device_t parent, cfdata_t cf, void *aux)
{
struct ofisa_attach_args *aa = aux;
char type[64];
char name[64];
char model[64];
char compatible[64];
int rv;
rv = 0;
if (1) {
if (OF_getprop(aa->oba.oba_phandle, "device_type", type,
sizeof(type)) < 0 || strcmp(type, "network") != 0 ||
OF_getprop(aa->oba.oba_phandle, "name", name,
sizeof(name)) < 0 || strcmp(name, "ethernet") != 0)
return (0);
if (OF_getprop(aa->oba.oba_phandle, "model", model,
sizeof(model)) > 0 && strcmp(model, "CS8900") == 0)
rv = 3;
if (OF_getprop(aa->oba.oba_phandle, "compatible", compatible,
sizeof(compatible)) > 0 && pmatch(compatible, "*CS8900*",
NULL) > 0)
rv = 2;
}
return (rv);
}
int
cs_ofisa_md_reg_fixup(device_t parent, device_t self, void *aux,
struct ofisa_reg_desc *descp, int ndescs, int ndescsfilled)
{
if (1) {
if (ndescs != 2)
return (ndescsfilled);
if (ndescsfilled == 2)
return (ndescsfilled);
descp[0].type = OFISA_REG_TYPE_IO;
descp[0].addr = 0x300;
descp[0].len = CS8900_IOSIZE;
descp[1].type = OFISA_REG_TYPE_MEM;
descp[1].addr = 0xd0000;
descp[1].len = 4096;
}
return (ndescsfilled);
}
int
cs_ofisa_md_intr_fixup(device_t parent, device_t self, void *aux,
struct ofisa_intr_desc *descp, int ndescs, int ndescsfilled)
{
if (1)
if (ndescs > 0 && ndescsfilled > 0)
descp[0].share = IST_LEVEL;
return (ndescsfilled);
}
int *
cs_ofisa_md_media_fixup(device_t parent, device_t self, void *aux, int *media,
int *nmediap, int *defmediap)
{
if (1) {
if (media == NULL) {
media = kmem_alloc(2 * sizeof(int), KM_SLEEP);
media[0] = IFM_ETHER | IFM_10_T;
media[1] = IFM_ETHER | IFM_10_T | IFM_FDX;
*nmediap = 2;
*defmediap = media[0];
}
}
return (media);
}
int
cs_ofisa_md_dma_fixup(device_t parent, device_t self, void *aux,
struct ofisa_dma_desc *descp, int ndescs, int ndescsfilled)
{
struct ofisa_attach_args *aa = aux;
if (ndescs > 0 && ndescsfilled > 0) {
if (OF_getproplen(aa->oba.oba_phandle, "no-dma") >= 0)
descp[0].drq = -1;
}
return (ndescsfilled);
}
#endif
int
cs_ofisa_md_cfgflags_fixup(device_t parent, device_t self, void *aux)
{
return (CFGFLG_USE_SA | CFGFLG_IOCHRDY | CFGFLG_NOT_EEPROM);
}