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