#include <sys/cdefs.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <amiga/dev/zbusvar.h>
#include <amiga/dev/p5busvar.h>
#define ZORRO_MANID_P5 8512
#define ZORRO_PRODID_CSPPC 100
#define ZORRO_PRODID_BPPC 110
#define P5_ROM_OFF 0xF00010
#define P5_SN_LEN 7
static int p5bus_match(device_t, cfdata_t, void *);
static void p5bus_attach(device_t, device_t, void *);
static char* p5bus_cardsn(void);
static int p5bus_print(void *aux, const char *str);
static void p5bus_callback(device_t self);
struct p5bus_softc {
device_t sc_dev;
uint8_t sc_cardtype;
uint8_t sc_has_scsi;
#define P5BUS_SCSI_NONE 0
#define P5BUS_SCSI_710 1
#define P5BUS_SCSI_770 2
uint8_t sc_has_ppc;
#define P5BUS_PPC_NONE 0
#define P5BUS_PPC_OK 1
};
CFATTACH_DECL_NEW(p5bus, sizeof(struct p5bus_softc),
p5bus_match, p5bus_attach, NULL, NULL);
static int
p5bus_match(device_t parent, cfdata_t cf, void *aux)
{
struct zbus_args *zap;
zap = aux;
if (zap->manid != ZORRO_MANID_P5)
return 0;
if ((zap->prodid != ZORRO_PRODID_BPPC) &&
(zap->prodid != ZORRO_PRODID_CSPPC))
return 0;
return 1;
}
static void
p5bus_attach(device_t parent, device_t self, void *aux)
{
struct p5bus_softc *sc;
struct zbus_args *zap;
struct p5bus_attach_args p5baa;
char *sn;
zap = aux;
sc = device_private(self);
sc->sc_dev = self;
sn = p5bus_cardsn();
aprint_normal(": Phase5 PowerUP on-board bus\n");
if (zap->prodid == ZORRO_PRODID_CSPPC) {
if (sn[0] == 'F') {
aprint_normal_dev(sc->sc_dev,
"CyberStorm Mk-III (sn %s)\n", sn);
sc->sc_has_ppc = P5BUS_PPC_NONE;
} else {
aprint_normal_dev(sc->sc_dev,
"CyberStorm PPC 604e (sn %s)\n", sn);
sc->sc_has_ppc = P5BUS_PPC_OK;
}
sc->sc_cardtype = P5_CARDTYPE_CS;
sc->sc_has_scsi = P5BUS_SCSI_770;
} else if (zap->prodid == ZORRO_PRODID_BPPC) {
if (sn[0] != 'I') {
aprint_normal_dev(sc->sc_dev,
"BlizzardPPC 603e (sn %s)\n", sn);
sc->sc_has_scsi = P5BUS_SCSI_NONE;
} else {
aprint_normal_dev(sc->sc_dev,
"BlizzardPPC 603e+ (sn %s)\n", sn);
sc->sc_has_scsi = P5BUS_SCSI_710;
}
sc->sc_cardtype = P5_CARDTYPE_BPPC;
sc->sc_has_ppc = P5BUS_PPC_OK;
}
p5baa.p5baa_cardtype = sc->sc_cardtype;
switch (sc->sc_has_scsi) {
case P5BUS_SCSI_710:
strcpy(p5baa.p5baa_name, "bppcsc");
config_found(sc->sc_dev, &p5baa, p5bus_print, CFARGS_NONE);
break;
case P5BUS_SCSI_770:
strcpy(p5baa.p5baa_name, "cbiiisc");
config_found(sc->sc_dev, &p5baa, p5bus_print, CFARGS_NONE);
break;
default:
break;
}
config_defer(self, p5bus_callback);
}
static void
p5bus_callback(device_t self) {
struct p5bus_attach_args p5baa;
struct p5bus_softc *sc;
sc = device_private(self);
p5baa.p5baa_cardtype = sc->sc_cardtype;
strcpy(p5baa.p5baa_name, "p5pb");
config_found(sc->sc_dev, &p5baa, p5bus_print, CFARGS_NONE);
}
static char *
p5bus_cardsn(void)
{
char *snr, *sn;
sn = kmem_zalloc(P5_SN_LEN + 1, KM_SLEEP);
snr = (char *)__UNVOLATILE(ztwomap(P5_ROM_OFF));
memcpy(sn, snr, P5_SN_LEN);
return sn;
}
static int
p5bus_print(void *aux, const char *str)
{
if (str == NULL)
return 0;
printf("%s ", str);
return 0;
}