omsal400.c revision 1.7
11.7Sdyoung/* $NetBSD: omsal400.c,v 1.7 2011/04/04 20:37:49 dyoung Exp $ */
21.1Sshige
31.1Sshige/*-
41.2Sshige * Copyright (c) 2006 Itronix Inc.
51.1Sshige * Copyright (c) 2006 Shigeyuki Fukushima.
61.1Sshige * All rights reserved.
71.1Sshige *
81.2Sshige * Written by Garrett D'Amore for Itronix Inc
91.1Sshige * Written by Shigeyuki Fukushima.
101.1Sshige *
111.1Sshige * Redistribution and use in source and binary forms, with or without
121.1Sshige * modification, are permitted provided that the following conditions
131.1Sshige * are met:
141.1Sshige * 1. Redistributions of source code must retain the above copyright
151.1Sshige *    notice, this list of conditions and the following disclaimer.
161.1Sshige * 2. Redistributions in binary form must reproduce the above
171.1Sshige *    copyright notice, this list of conditions and the following
181.1Sshige *    disclaimer in the documentation and/or other materials provided
191.1Sshige *    with the distribution.
201.1Sshige * 3. The name of the author may not be used to endorse or promote
211.1Sshige *    products derived from this software without specific prior
221.1Sshige *    written permission.
231.1Sshige *
241.1Sshige * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
251.1Sshige * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
261.1Sshige * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271.1Sshige * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
281.1Sshige * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291.1Sshige * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
301.1Sshige * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
311.1Sshige * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
321.1Sshige * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
331.1Sshige * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
341.1Sshige * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351.1Sshige */
361.1Sshige
371.1Sshige
381.1Sshige#include <sys/cdefs.h>
391.7Sdyoung__KERNEL_RCSID(0, "$NetBSD: omsal400.c,v 1.7 2011/04/04 20:37:49 dyoung Exp $");
401.1Sshige
411.1Sshige#include <sys/param.h>
421.1Sshige#include <machine/bus.h>
431.1Sshige#include <machine/locore.h>
441.4Skiyohara#include <mips/alchemy/dev/augpiovar.h>
451.4Skiyohara#include <mips/alchemy/dev/aupcmciavar.h>
461.1Sshige#include <evbmips/alchemy/obiovar.h>
471.1Sshige#include <evbmips/alchemy/board.h>
481.1Sshige#include <evbmips/alchemy/omsal400reg.h>
491.1Sshige
501.1Sshige#define	GET16(x)	\
511.1Sshige	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)))
521.1Sshige#define	PUT16(x, v)	\
531.1Sshige	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
541.1Sshige
551.1Sshigestatic void	omsal400_init(void);
561.7Sdyoungstatic int	omsal400_pci_intr_map(const struct pci_attach_args *,
571.1Sshige					 pci_intr_handle_t *);
581.1Sshigestatic void	omsal400_poweroff(void);
591.1Sshigestatic void	omsal400_reboot(void);
601.4Skiyoharastatic bus_addr_t omsal400_slot_offset(int);
611.4Skiyoharastatic int omsal400_slot_irq(int, int);
621.4Skiyoharastatic void omsal400_slot_enable(int);
631.4Skiyoharastatic void omsal400_slot_disable(int);
641.4Skiyoharastatic int omsal400_slot_status(int);
651.4Skiyoharastatic const char *omsal400_slot_name(int);
661.1Sshige
671.1Sshigestatic const struct obiodev omsal400_devices[] = {
681.1Sshige	{ NULL },
691.1Sshige};
701.1Sshige
711.4Skiyoharastatic struct aupcmcia_machdep omsal400_pcmcia = {
721.4Skiyohara	1,      /* nslots */
731.4Skiyohara	omsal400_slot_offset,
741.4Skiyohara	omsal400_slot_irq,
751.4Skiyohara	omsal400_slot_enable,
761.4Skiyohara	omsal400_slot_disable,
771.4Skiyohara	omsal400_slot_status,
781.4Skiyohara	omsal400_slot_name,
791.4Skiyohara};
801.4Skiyohara
811.1Sshigestatic struct alchemy_board omsal400_info = {
821.5Skiyohara	"Plathome Open Micro Server AL400/AMD Alchemy Au1550",
831.1Sshige	omsal400_devices,
841.1Sshige	omsal400_init,
851.1Sshige	omsal400_pci_intr_map,
861.1Sshige	omsal400_reboot,
871.1Sshige	omsal400_poweroff,
881.4Skiyohara	&omsal400_pcmcia,
891.1Sshige};
901.1Sshige
911.1Sshigeconst struct alchemy_board *
921.1Sshigeboard_info(void)
931.1Sshige{
941.1Sshige
951.1Sshige	return &omsal400_info;
961.1Sshige}
971.1Sshige
981.1Sshigevoid
991.1Sshigeomsal400_init(void)
1001.1Sshige{
1011.1Sshige	/* uint16_t whoami; */
1021.1Sshige
1031.6Smatt	if (MIPS_PRID_COPTS(mips_options.mips_cpu_id) != MIPS_AU1550)
1041.1Sshige		panic("omsal400: CPU not Au1550");
1051.1Sshige
1061.1Sshige#if 0 /* XXX: TODO borad identification */
1071.1Sshige	/* check the whoami register for a match */
1081.1Sshige	whoami = GET16(DBAU1550_WHOAMI);
1091.1Sshige
1101.1Sshige	if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1)
1111.1Sshige		panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami);
1121.1Sshige
1131.1Sshige	printf("DBAu1550 (cabernet), CPLDv%d, ",
1141.1Sshige	    DBAU1550_WHOAMI_CPLD(whoami));
1151.1Sshige
1161.1Sshige	if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf)
1171.1Sshige		printf("daughtercard 0x%x\n",
1181.1Sshige		    DBAU1550_WHOAMI_DAUGHTER(whoami));
1191.1Sshige	else
1201.1Sshige		printf("no daughtercard\n");
1211.1Sshige#endif
1221.1Sshige
1231.1Sshige	/* leave console and clocks alone -- YAMON should have got it right! */
1241.1Sshige}
1251.1Sshige
1261.1Sshigeint
1271.7Sdyoungomsal400_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
1281.1Sshige{
1291.1Sshige	/*
1301.1Sshige	 * This platform has 4 PCI devices:
1311.1Sshige	 *  dev 1 (PCI_INTD):	PCI Connector
1321.1Sshige	 *  dev 2 (PCI_INTC):	NEC USB 2.0 uPD720101
1331.1Sshige	 *  dev 3 (PCI_INTB):	Intel GB Ether 82541PI
1341.1Sshige	 *  dev 4 (PCI_INTA):	Intel GB Ether 82541PI
1351.1Sshige	 */
1361.3Sshige	static const int irqmap[4/*device*/][4/*pin*/] = {
1371.1Sshige		{  6, -1, -1, -1 },	/* 1: PCI Connecter (not used) */
1381.1Sshige		{  5,  5,  5, -1 },	/* 2: NEC USB 2.0 */
1391.1Sshige		{  2, -1, -1, -1 },	/* 3: Intel GbE */
1401.1Sshige		{  1, -1, -1, -1 },	/* 4: Intel GbE */
1411.1Sshige	};
1421.1Sshige
1431.1Sshige	int pin, dev, irq;
1441.1Sshige
1451.1Sshige	/* if interrupt pin not used... */
1461.1Sshige	if ((pin = pa->pa_intrpin) == 0)
1471.1Sshige		return 1;
1481.1Sshige
1491.1Sshige	if (pin > 4) {
1501.1Sshige		printf("pci: bad interrupt pin %d\n", pin);
1511.1Sshige		return 1;
1521.1Sshige	}
1531.1Sshige
1541.1Sshige	pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
1551.1Sshige
1561.1Sshige	if ((dev < 1) || (dev > 4)) {
1571.1Sshige		printf("pci: bad device %d\n", dev);
1581.1Sshige		return 1;
1591.1Sshige	}
1601.1Sshige
1611.1Sshige	if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
1621.1Sshige		printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
1631.1Sshige		return 1;
1641.1Sshige	}
1651.1Sshige
1661.1Sshige	*ihp = irq;
1671.1Sshige	return 0;
1681.1Sshige}
1691.1Sshige
1701.1Sshigevoid
1711.1Sshigeomsal400_reboot(void)
1721.1Sshige{
1731.1Sshige
1741.1Sshige	/* XXX */
1751.1Sshige}
1761.1Sshige
1771.1Sshigevoid
1781.1Sshigeomsal400_poweroff(void)
1791.1Sshige{
1801.1Sshige
1811.1Sshige	printf("\n- poweroff -\n");
1821.1Sshige	/* XXX */
1831.1Sshige}
1841.4Skiyohara
1851.4Skiyohara
1861.4Skiyoharaint
1871.4Skiyoharaomsal400_slot_irq(int slot, int which)
1881.4Skiyohara{
1891.4Skiyohara	static const int irqmap[1/*slot*/][2/*which*/] = {
1901.4Skiyohara		{ 35, 37 },		/* Slot 0: CF connector Type2 */
1911.4Skiyohara	};
1921.4Skiyohara
1931.4Skiyohara	if ((slot >= 1) || (which >= 2))
1941.4Skiyohara		return -1;
1951.4Skiyohara
1961.4Skiyohara	return irqmap[slot][which];
1971.4Skiyohara}
1981.4Skiyohara
1991.4Skiyoharabus_addr_t
2001.4Skiyoharaomsal400_slot_offset(int slot)
2011.4Skiyohara{
2021.4Skiyohara
2031.4Skiyohara	switch (slot) {
2041.4Skiyohara	case 0:
2051.4Skiyohara		return (0);	/* offset 0 */
2061.4Skiyohara	}
2071.4Skiyohara	return (bus_addr_t)-1;
2081.4Skiyohara}
2091.4Skiyohara
2101.4Skiyoharavoid
2111.4Skiyoharaomsal400_slot_enable(int slot)
2121.4Skiyohara{
2131.4Skiyohara
2141.4Skiyohara	/* nothing todo */
2151.4Skiyohara}
2161.4Skiyohara
2171.4Skiyoharavoid
2181.4Skiyoharaomsal400_slot_disable(int slot)
2191.4Skiyohara{
2201.4Skiyohara
2211.4Skiyohara	/* nothing todo */
2221.4Skiyohara}
2231.4Skiyohara
2241.4Skiyoharaint
2251.4Skiyoharaomsal400_slot_status(int slot)
2261.4Skiyohara{
2271.4Skiyohara	uint16_t	inserted = 0;
2281.4Skiyohara
2291.4Skiyohara	switch (slot) {
2301.4Skiyohara	case 0:
2311.4Skiyohara		inserted = !AUGPIO_READ(5);	/* pin 5 */
2321.4Skiyohara		break;
2331.4Skiyohara	}
2341.4Skiyohara
2351.4Skiyohara	return inserted;
2361.4Skiyohara}
2371.4Skiyohara
2381.4Skiyoharaconst char *
2391.4Skiyoharaomsal400_slot_name(int slot)
2401.4Skiyohara{
2411.4Skiyohara	switch (slot) {
2421.4Skiyohara	case 0:
2431.4Skiyohara		return "CF connector Type2 on Static BUS#3";
2441.4Skiyohara	default:
2451.4Skiyohara		return "???";
2461.4Skiyohara	}
2471.4Skiyohara}
248