omsal400.c revision 1.1
1/* $NetBSD: omsal400.c,v 1.1 2006/02/23 17:14:01 shige Exp $ */
2
3/*-
4 * Copyright (c) 2006 Shigeyuki Fukushima.
5 * All rights reserved.
6 *
7 * Written by Shigeyuki Fukushima.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following
16 *    disclaimer in the documentation and/or other materials provided
17 *    with the distribution.
18 * 3. The name of the author may not be used to endorse or promote
19 *    products derived from this software without specific prior
20 *    written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35
36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: omsal400.c,v 1.1 2006/02/23 17:14:01 shige Exp $");
38
39#include <sys/param.h>
40#include <machine/bus.h>
41#include <machine/locore.h>
42#include <evbmips/alchemy/obiovar.h>
43#include <evbmips/alchemy/board.h>
44#include <evbmips/alchemy/omsal400reg.h>
45
46#define	GET16(x)	\
47	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)))
48#define	PUT16(x, v)	\
49	(*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
50
51static void	omsal400_init(void);
52static int	omsal400_pci_intr_map(struct pci_attach_args *,
53					 pci_intr_handle_t *);
54static void	omsal400_poweroff(void);
55static void	omsal400_reboot(void);
56
57static const struct obiodev omsal400_devices[] = {
58	{ NULL },
59};
60
61static struct alchemy_board omsal400_info = {
62	"Plathome Open Micro Sever AL400/AMD Alchemy Au1550",
63	omsal400_devices,
64	omsal400_init,
65	omsal400_pci_intr_map,
66	omsal400_reboot,
67	omsal400_poweroff,
68};
69
70const struct alchemy_board *
71board_info(void)
72{
73
74	return &omsal400_info;
75}
76
77void
78omsal400_init(void)
79{
80	/* uint16_t whoami; */
81
82	if (MIPS_PRID_COPTS(cpu_id) != MIPS_AU1550)
83		panic("omsal400: CPU not Au1550");
84
85#if 0 /* XXX: TODO borad identification */
86	/* check the whoami register for a match */
87	whoami = GET16(DBAU1550_WHOAMI);
88
89	if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1)
90		panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami);
91
92	printf("DBAu1550 (cabernet), CPLDv%d, ",
93	    DBAU1550_WHOAMI_CPLD(whoami));
94
95	if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf)
96		printf("daughtercard 0x%x\n",
97		    DBAU1550_WHOAMI_DAUGHTER(whoami));
98	else
99		printf("no daughtercard\n");
100#endif
101
102	/* leave console and clocks alone -- YAMON should have got it right! */
103}
104
105int
106omsal400_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
107{
108	/*
109	 * This platform has 4 PCI devices:
110	 *  dev 1 (PCI_INTD):	PCI Connector
111	 *  dev 2 (PCI_INTC):	NEC USB 2.0 uPD720101
112	 *  dev 3 (PCI_INTB):	Intel GB Ether 82541PI
113	 *  dev 4 (PCI_INTA):	Intel GB Ether 82541PI
114	 */
115	static const int irqmap[5/*device*/][4/*pin*/] = {
116		{  6, -1, -1, -1 },	/* 1: PCI Connecter (not used) */
117		{  5,  5,  5, -1 },	/* 2: NEC USB 2.0 */
118		{  2, -1, -1, -1 },	/* 3: Intel GbE */
119		{  1, -1, -1, -1 },	/* 4: Intel GbE */
120	};
121
122	int pin, dev, irq;
123
124	/* if interrupt pin not used... */
125	if ((pin = pa->pa_intrpin) == 0)
126		return 1;
127
128	if (pin > 4) {
129		printf("pci: bad interrupt pin %d\n", pin);
130		return 1;
131	}
132
133	pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
134
135	if ((dev < 1) || (dev > 4)) {
136		printf("pci: bad device %d\n", dev);
137		return 1;
138	}
139
140	if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
141		printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
142		return 1;
143	}
144
145	*ihp = irq;
146	return 0;
147}
148
149void
150omsal400_reboot(void)
151{
152
153	/* XXX */
154}
155
156void
157omsal400_poweroff(void)
158{
159
160	printf("\n- poweroff -\n");
161	/* XXX */
162}
163