dbau1550.c revision 1.3 1 /* $NetBSD: dbau1550.c,v 1.3 2006/02/13 02:37:05 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.3 2006/02/13 02:37:05 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 GET32(x) \
45 (*((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(x)))
46 #define PUT32(x, v) \
47 (*((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
48 #define PUT16(x, v) \
49 (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
50
51 static void dbau1550_init(void);
52 static int dbau1550_pci_intr_map(struct pci_attach_args *,
53 pci_intr_handle_t *);
54 static void dbau1550_poweroff(void);
55 static void dbau1550_reboot(void);
56
57 static const struct obiodev dbau1550_devices[] = {
58 #if 0
59 { "aupcmcia", -1, -1 },
60 { "aupsc", -1, -1 },
61 { "aupsc", -1, -1 },
62 { "aupsc", -1, -1 },
63 #endif
64 { NULL },
65 };
66
67 static struct alchemy_board dbau1550_info = {
68 "AMD Alchemy DBAu1550",
69 dbau1550_devices,
70 dbau1550_init,
71 dbau1550_pci_intr_map,
72 dbau1550_reboot,
73 dbau1550_poweroff,
74 };
75
76 const struct alchemy_board *
77 board_info(void)
78 {
79
80 return &dbau1550_info;
81 }
82
83 void
84 dbau1550_init(void)
85 {
86 uint32_t whoami;
87
88 if (MIPS_PRID_COPTS(cpu_id) != MIPS_AU1550)
89 panic("dbau1550: CPU not Au1550");
90
91 /* check the whoami register for a match */
92 whoami = *((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(DBAU1550_WHOAMI));
93
94 if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1)
95 panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami);
96
97 printf("DBAu1550 (cabernet), CPLDv%d, ",
98 DBAU1550_WHOAMI_CPLD(whoami));
99
100 if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf)
101 printf("daughtercard 0x%x\n",
102 DBAU1550_WHOAMI_DAUGHTER(whoami));
103 else
104 printf("no daughtercard\n");
105
106 /* leave console and clocks alone -- YAMON should have got it right! */
107 }
108
109 int
110 dbau1550_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
111 {
112 /*
113 * This platform has one onboard PCI IDE controller, and two
114 * PCI expansion slots.
115 */
116 static const int irqmap[3/*device*/][4/*pin*/] = {
117 { 5, -1, -1, -1 }, /* 11: IDE */
118 { 2, 5, 6, 1 }, /* 12: PCI Slot 2 */
119 { 1, 2, 5, 6 }, /* 13: PCI Slot 3 */
120 };
121 int pin, dev, irq;
122
123 /* if interrupt pin not used... */
124 if ((pin = pa->pa_intrpin) == 0)
125 return 1;
126
127 if (pin > 4) {
128 printf("pci: bad interrupt pin %d\n", pin);
129 return 1;
130 }
131
132 pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
133 if ((dev < 11) || (dev > 13)) {
134 printf("pci: bad device %d\n", dev);
135 return 1;
136 }
137
138 if ((irq = irqmap[dev - 11][pin - 1]) == -1) {
139 printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
140 return 1;
141 }
142
143 *ihp = irq;
144 return 0;
145 }
146
147 void
148 dbau1550_reboot(void)
149 {
150 PUT16(DBAU1550_SOFTWARE_RESET, 0);
151 delay(100000); /* 100 msec */
152 }
153
154 void
155 dbau1550_poweroff(void)
156 {
157 printf("\n- poweroff -\n");
158 PUT16(DBAU1550_SOFTWARE_RESET,
159 DBAU1550_SOFTWARE_RESET_PWROFF | DBAU1550_SOFTWARE_RESET_RESET);
160 delay(100000); /* 100 msec */
161 }
162