#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: omsal400.c,v 1.12 2024/05/24 20:06:55 andvar Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <mips/locore.h>
#include <mips/cpuregs.h>
#include <mips/alchemy/dev/augpiovar.h>
#include <mips/alchemy/dev/aupcmciavar.h>
#include <evbmips/alchemy/obiovar.h>
#include <evbmips/alchemy/board.h>
#include <evbmips/alchemy/omsal400reg.h>
#define GET16(x) \
(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)))
#define PUT16(x, v) \
(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
static void omsal400_init(void);
static int omsal400_pci_intr_map(const struct pci_attach_args *,
pci_intr_handle_t *);
static void omsal400_poweroff(void);
static void omsal400_reboot(void);
static bus_addr_t omsal400_slot_offset(int);
static int omsal400_slot_irq(int, int);
static void omsal400_slot_enable(int);
static void omsal400_slot_disable(int);
static int omsal400_slot_status(int);
static const char *omsal400_slot_name(int);
static const struct obiodev omsal400_devices[] = {
{ NULL },
};
static struct aupcmcia_machdep omsal400_pcmcia = {
1,
omsal400_slot_offset,
omsal400_slot_irq,
omsal400_slot_enable,
omsal400_slot_disable,
omsal400_slot_status,
omsal400_slot_name,
};
static struct alchemy_board omsal400_info = {
"Plathome Open Micro Server AL400/AMD Alchemy Au1550",
omsal400_devices,
omsal400_init,
omsal400_pci_intr_map,
omsal400_reboot,
omsal400_poweroff,
&omsal400_pcmcia,
};
CTASSERT(_BYTE_ORDER == _LITTLE_ENDIAN);
const struct alchemy_board *
board_info(void)
{
return &omsal400_info;
}
void
omsal400_init(void)
{
if (MIPS_PRID_COPTS(mips_options.mips_cpu_id) != MIPS_AU1550)
panic("omsal400: CPU not Au1550");
#if 0
whoami = GET16(DBAU1550_WHOAMI);
if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1)
panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami);
printf("DBAu1550 (cabernet), CPLDv%d, ",
DBAU1550_WHOAMI_CPLD(whoami));
if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf)
printf("daughtercard 0x%x\n",
DBAU1550_WHOAMI_DAUGHTER(whoami));
else
printf("no daughtercard\n");
#endif
}
int
omsal400_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
static const int irqmap[4][4] = {
{ 6, -1, -1, -1 },
{ 5, 5, 5, -1 },
{ 2, -1, -1, -1 },
{ 1, -1, -1, -1 },
};
int pin, dev, irq;
if ((pin = pa->pa_intrpin) == 0)
return 1;
if (pin > 4) {
printf("pci: bad interrupt pin %d\n", pin);
return 1;
}
pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
if ((dev < 1) || (dev > 4)) {
printf("pci: bad device %d\n", dev);
return 1;
}
if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
return 1;
}
*ihp = irq;
return 0;
}
void
omsal400_reboot(void)
{
}
void
omsal400_poweroff(void)
{
printf("\n- poweroff -\n");
}
int
omsal400_slot_irq(int slot, int which)
{
static const int irqmap[1][2] = {
{ 35, 37 },
};
if ((slot >= 1) || (which >= 2))
return -1;
return irqmap[slot][which];
}
bus_addr_t
omsal400_slot_offset(int slot)
{
switch (slot) {
case 0:
return (0);
}
return (bus_addr_t)-1;
}
void
omsal400_slot_enable(int slot)
{
}
void
omsal400_slot_disable(int slot)
{
}
int
omsal400_slot_status(int slot)
{
uint16_t inserted = 0;
switch (slot) {
case 0:
inserted = !AUGPIO_READ(5);
break;
}
return inserted;
}
const char *
omsal400_slot_name(int slot)
{
switch (slot) {
case 0:
return "CF connector Type2 on Static BUS#3";
default:
return "???";
}
}