dbau1550.c revision 1.7 1 1.7 gdamore /* $NetBSD: dbau1550.c,v 1.7 2006/10/02 08:13:53 gdamore Exp $ */
2 1.1 gdamore
3 1.1 gdamore /*-
4 1.1 gdamore * Copyright (c) 2006 Itronix Inc.
5 1.1 gdamore * All rights reserved.
6 1.1 gdamore *
7 1.1 gdamore * Written by Garrett D'Amore for Itronix Inc.
8 1.1 gdamore *
9 1.1 gdamore * Redistribution and use in source and binary forms, with or without
10 1.1 gdamore * modification, are permitted provided that the following conditions
11 1.1 gdamore * are met:
12 1.1 gdamore * 1. Redistributions of source code must retain the above copyright
13 1.1 gdamore * notice, this list of conditions and the following disclaimer.
14 1.1 gdamore * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 gdamore * notice, this list of conditions and the following disclaimer in the
16 1.1 gdamore * documentation and/or other materials provided with the distribution.
17 1.1 gdamore * 3. The name of Itronix Inc. may not be used to endorse
18 1.1 gdamore * or promote products derived from this software without specific
19 1.1 gdamore * prior written permission.
20 1.1 gdamore *
21 1.1 gdamore * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 1.1 gdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 gdamore * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 gdamore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 1.1 gdamore * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 1.1 gdamore * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.1 gdamore * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 1.1 gdamore * ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 gdamore * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 gdamore * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 gdamore * POSSIBILITY OF SUCH DAMAGE.
32 1.1 gdamore */
33 1.1 gdamore
34 1.1 gdamore #include <sys/cdefs.h>
35 1.7 gdamore __KERNEL_RCSID(0, "$NetBSD: dbau1550.c,v 1.7 2006/10/02 08:13:53 gdamore Exp $");
36 1.1 gdamore
37 1.1 gdamore #include <sys/param.h>
38 1.5 gdamore #include <sys/kernel.h>
39 1.5 gdamore #include <sys/param.h>
40 1.5 gdamore #include <sys/time.h>
41 1.5 gdamore #include <sys/proc.h>
42 1.1 gdamore #include <machine/bus.h>
43 1.1 gdamore #include <machine/locore.h>
44 1.5 gdamore #include <mips/alchemy/include/aureg.h>
45 1.5 gdamore #include <mips/alchemy/dev/aupcmciavar.h>
46 1.5 gdamore #include <mips/alchemy/dev/aupcmciareg.h>
47 1.5 gdamore #include <mips/alchemy/dev/augpioreg.h>
48 1.7 gdamore #include <mips/alchemy/dev/auspivar.h>
49 1.1 gdamore #include <evbmips/alchemy/obiovar.h>
50 1.1 gdamore #include <evbmips/alchemy/board.h>
51 1.1 gdamore #include <evbmips/alchemy/dbau1550reg.h>
52 1.1 gdamore
53 1.7 gdamore #include "auspi.h"
54 1.7 gdamore
55 1.5 gdamore /*
56 1.5 gdamore * This should be converted to use bus_space routines.
57 1.5 gdamore */
58 1.4 gdamore #define GET16(x) \
59 1.4 gdamore (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)))
60 1.3 gdamore #define PUT16(x, v) \
61 1.3 gdamore (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
62 1.5 gdamore #define GET32(x) \
63 1.5 gdamore (*((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(x)))
64 1.5 gdamore #define PUT32(x, v) \
65 1.5 gdamore (*((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(x)) = (v))
66 1.3 gdamore
67 1.1 gdamore static void dbau1550_init(void);
68 1.1 gdamore static int dbau1550_pci_intr_map(struct pci_attach_args *,
69 1.1 gdamore pci_intr_handle_t *);
70 1.3 gdamore static void dbau1550_poweroff(void);
71 1.3 gdamore static void dbau1550_reboot(void);
72 1.5 gdamore static bus_addr_t dbau1550_slot_offset(int);
73 1.5 gdamore static int dbau1550_slot_irq(int, int);
74 1.5 gdamore static void dbau1550_slot_enable(int);
75 1.5 gdamore static void dbau1550_slot_disable(int);
76 1.5 gdamore static int dbau1550_slot_status(int);
77 1.5 gdamore static const char *dbau1550_slot_name(int);
78 1.7 gdamore static const struct auspi_machdep *dbau1550_spi(bus_addr_t);
79 1.1 gdamore
80 1.1 gdamore static const struct obiodev dbau1550_devices[] = {
81 1.1 gdamore { NULL },
82 1.1 gdamore };
83 1.1 gdamore
84 1.5 gdamore static struct aupcmcia_machdep dbau1550_pcmcia = {
85 1.5 gdamore 2, /* nslots */
86 1.5 gdamore dbau1550_slot_offset,
87 1.5 gdamore dbau1550_slot_irq,
88 1.5 gdamore dbau1550_slot_enable,
89 1.5 gdamore dbau1550_slot_disable,
90 1.5 gdamore dbau1550_slot_status,
91 1.5 gdamore dbau1550_slot_name,
92 1.5 gdamore };
93 1.5 gdamore
94 1.1 gdamore static struct alchemy_board dbau1550_info = {
95 1.7 gdamore .ab_name = "AMD Alchemy DBAu1550",
96 1.7 gdamore .ab_devices = dbau1550_devices,
97 1.7 gdamore .ab_init = dbau1550_init,
98 1.7 gdamore .ab_pci_intr_map =dbau1550_pci_intr_map,
99 1.7 gdamore .ab_reboot = dbau1550_reboot,
100 1.7 gdamore .ab_poweroff = dbau1550_poweroff,
101 1.7 gdamore .ab_pcmcia = &dbau1550_pcmcia,
102 1.7 gdamore .ab_spi = dbau1550_spi,
103 1.1 gdamore };
104 1.1 gdamore
105 1.1 gdamore const struct alchemy_board *
106 1.1 gdamore board_info(void)
107 1.1 gdamore {
108 1.1 gdamore
109 1.1 gdamore return &dbau1550_info;
110 1.1 gdamore }
111 1.1 gdamore
112 1.1 gdamore void
113 1.1 gdamore dbau1550_init(void)
114 1.1 gdamore {
115 1.4 gdamore uint16_t whoami;
116 1.7 gdamore uint32_t sysclk;
117 1.7 gdamore uint32_t pinfunc;
118 1.1 gdamore
119 1.1 gdamore if (MIPS_PRID_COPTS(cpu_id) != MIPS_AU1550)
120 1.1 gdamore panic("dbau1550: CPU not Au1550");
121 1.1 gdamore
122 1.1 gdamore /* check the whoami register for a match */
123 1.4 gdamore whoami = GET16(DBAU1550_WHOAMI);
124 1.1 gdamore
125 1.1 gdamore if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1)
126 1.1 gdamore panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami);
127 1.1 gdamore
128 1.1 gdamore printf("DBAu1550 (cabernet), CPLDv%d, ",
129 1.1 gdamore DBAU1550_WHOAMI_CPLD(whoami));
130 1.1 gdamore
131 1.1 gdamore if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf)
132 1.1 gdamore printf("daughtercard 0x%x\n",
133 1.1 gdamore DBAU1550_WHOAMI_DAUGHTER(whoami));
134 1.1 gdamore else
135 1.1 gdamore printf("no daughtercard\n");
136 1.1 gdamore
137 1.1 gdamore /* leave console and clocks alone -- YAMON should have got it right! */
138 1.7 gdamore
139 1.7 gdamore /*
140 1.7 gdamore * Initialize PSC clocks.
141 1.7 gdamore *
142 1.7 gdamore * PSC0 is SPI. Use 48MHz FREQ1.
143 1.7 gdamore * PSC1 is AC97.
144 1.7 gdamore * PSC2 is SMBus, and must be 48MHz. (Configured by YAMON)
145 1.7 gdamore * PSC3 is I2S.
146 1.7 gdamore *
147 1.7 gdamore * FREQ2 is 48MHz for USBH/USBD.
148 1.7 gdamore */
149 1.7 gdamore sysclk = GET32(SYS_CLKSRC);
150 1.7 gdamore sysclk &= ~(SCS_MP0(7) | SCS_DP0 | SCS_CP0);
151 1.7 gdamore sysclk |= SCS_MP0(3);
152 1.7 gdamore PUT32(SYS_CLKSRC, sysclk);
153 1.7 gdamore
154 1.7 gdamore /*
155 1.7 gdamore * Configure pin function for PSC devices.
156 1.7 gdamore */
157 1.7 gdamore pinfunc = GET32(SYS_PINFUNC);
158 1.7 gdamore /* configure PSC0 SYNC1 */
159 1.7 gdamore pinfunc |= SPF_S0;
160 1.7 gdamore /* configure PSC2 for SMBus (YAMON default) */
161 1.7 gdamore pinfunc &= ~SPF_PSC2_MASK;
162 1.7 gdamore pinfunc |= SPF_PSC2_SMBUS;
163 1.7 gdamore /* configure PSC3 for I2S (YAMON default) */
164 1.7 gdamore pinfunc &= ~SPF_PSC3_MASK;
165 1.7 gdamore pinfunc |= SPF_PSC3_I2S;
166 1.7 gdamore PUT32(SYS_PINFUNC, pinfunc);
167 1.1 gdamore }
168 1.1 gdamore
169 1.1 gdamore int
170 1.1 gdamore dbau1550_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
171 1.1 gdamore {
172 1.1 gdamore /*
173 1.1 gdamore * This platform has one onboard PCI IDE controller, and two
174 1.1 gdamore * PCI expansion slots.
175 1.1 gdamore */
176 1.1 gdamore static const int irqmap[3/*device*/][4/*pin*/] = {
177 1.1 gdamore { 5, -1, -1, -1 }, /* 11: IDE */
178 1.1 gdamore { 2, 5, 6, 1 }, /* 12: PCI Slot 2 */
179 1.1 gdamore { 1, 2, 5, 6 }, /* 13: PCI Slot 3 */
180 1.1 gdamore };
181 1.1 gdamore int pin, dev, irq;
182 1.1 gdamore
183 1.1 gdamore /* if interrupt pin not used... */
184 1.1 gdamore if ((pin = pa->pa_intrpin) == 0)
185 1.1 gdamore return 1;
186 1.1 gdamore
187 1.1 gdamore if (pin > 4) {
188 1.1 gdamore printf("pci: bad interrupt pin %d\n", pin);
189 1.1 gdamore return 1;
190 1.1 gdamore }
191 1.1 gdamore
192 1.1 gdamore pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL);
193 1.1 gdamore if ((dev < 11) || (dev > 13)) {
194 1.1 gdamore printf("pci: bad device %d\n", dev);
195 1.1 gdamore return 1;
196 1.1 gdamore }
197 1.1 gdamore
198 1.1 gdamore if ((irq = irqmap[dev - 11][pin - 1]) == -1) {
199 1.1 gdamore printf("pci: no IRQ routing for device %d pin %d\n", dev, pin);
200 1.1 gdamore return 1;
201 1.1 gdamore }
202 1.1 gdamore
203 1.1 gdamore *ihp = irq;
204 1.1 gdamore return 0;
205 1.1 gdamore }
206 1.3 gdamore
207 1.3 gdamore void
208 1.3 gdamore dbau1550_reboot(void)
209 1.3 gdamore {
210 1.3 gdamore PUT16(DBAU1550_SOFTWARE_RESET, 0);
211 1.5 gdamore wbflush();
212 1.3 gdamore delay(100000); /* 100 msec */
213 1.3 gdamore }
214 1.3 gdamore
215 1.3 gdamore void
216 1.3 gdamore dbau1550_poweroff(void)
217 1.3 gdamore {
218 1.3 gdamore printf("\n- poweroff -\n");
219 1.3 gdamore PUT16(DBAU1550_SOFTWARE_RESET,
220 1.3 gdamore DBAU1550_SOFTWARE_RESET_PWROFF | DBAU1550_SOFTWARE_RESET_RESET);
221 1.5 gdamore wbflush();
222 1.3 gdamore delay(100000); /* 100 msec */
223 1.3 gdamore }
224 1.5 gdamore
225 1.5 gdamore int
226 1.5 gdamore dbau1550_slot_irq(int slot, int which)
227 1.5 gdamore {
228 1.5 gdamore static const int irqmap[2/*slot*/][2/*which*/] = {
229 1.5 gdamore { 35, 32 }, /* Slot 0: Bottom */
230 1.5 gdamore { 37, 33 }, /* Slot 1: Top */
231 1.5 gdamore };
232 1.5 gdamore
233 1.5 gdamore if ((slot >= 2) || (which >= 2))
234 1.5 gdamore return -1;
235 1.5 gdamore
236 1.5 gdamore return (irqmap[slot][which]);
237 1.5 gdamore }
238 1.5 gdamore
239 1.5 gdamore bus_addr_t
240 1.5 gdamore dbau1550_slot_offset(int slot)
241 1.5 gdamore {
242 1.5 gdamore switch (slot) {
243 1.5 gdamore case 0:
244 1.5 gdamore return (DBAU1550_PC0_ADDR);
245 1.5 gdamore case 1:
246 1.5 gdamore return (DBAU1550_PC1_ADDR);
247 1.5 gdamore }
248 1.5 gdamore
249 1.5 gdamore return (bus_addr_t)-1;
250 1.5 gdamore }
251 1.5 gdamore
252 1.5 gdamore void
253 1.5 gdamore dbau1550_slot_enable(int slot)
254 1.5 gdamore {
255 1.5 gdamore uint16_t status;
256 1.5 gdamore uint16_t vcc, vpp;
257 1.5 gdamore int shift;
258 1.5 gdamore
259 1.5 gdamore status = GET16(DBAU1550_STATUS);
260 1.5 gdamore switch (slot) {
261 1.5 gdamore case 0:
262 1.5 gdamore status >>= DBAU1550_STATUS_PCMCIA0_VS_SHIFT;
263 1.5 gdamore shift = DBAU1550_PCMCIA_PC0_SHIFT;
264 1.5 gdamore break;
265 1.5 gdamore case 1:
266 1.5 gdamore status >>= DBAU1550_STATUS_PCMCIA1_VS_SHIFT;
267 1.5 gdamore shift = DBAU1550_PCMCIA_PC1_SHIFT;
268 1.5 gdamore break;
269 1.5 gdamore default:
270 1.5 gdamore return;
271 1.5 gdamore }
272 1.5 gdamore
273 1.5 gdamore status &= DBAU1550_STATUS_PCMCIA_VS_MASK;
274 1.5 gdamore switch (status) {
275 1.5 gdamore case DBAU1550_STATUS_PCMCIA_VS_GND:
276 1.5 gdamore vcc = DBAU1550_PCMCIA_VCC_GND;
277 1.5 gdamore vpp = DBAU1550_PCMCIA_VPP_GND;
278 1.5 gdamore break;
279 1.5 gdamore case DBAU1550_STATUS_PCMCIA_VS_5V:
280 1.5 gdamore vcc = DBAU1550_PCMCIA_VCC_5V;
281 1.5 gdamore vpp = DBAU1550_PCMCIA_VPP_VCC;
282 1.5 gdamore break;
283 1.5 gdamore default: /* covers both 3.3v cases */
284 1.5 gdamore vcc = DBAU1550_PCMCIA_VCC_3V;
285 1.5 gdamore vpp = DBAU1550_PCMCIA_VPP_VCC;
286 1.5 gdamore break;
287 1.5 gdamore }
288 1.5 gdamore
289 1.5 gdamore status = GET16(DBAU1550_PCMCIA);
290 1.5 gdamore
291 1.5 gdamore /* this clears all bits for this slot */
292 1.5 gdamore status &= ~(DBAU1550_PCMCIA_MASK << shift);
293 1.5 gdamore
294 1.5 gdamore status |= vcc << shift;
295 1.5 gdamore status |= vpp << shift;
296 1.5 gdamore
297 1.5 gdamore PUT16(DBAU1550_PCMCIA, status);
298 1.5 gdamore wbflush();
299 1.5 gdamore tsleep(&status, PWAIT, "pcmcia_reset_0", mstohz(100));
300 1.5 gdamore
301 1.5 gdamore status |= (DBAU1550_PCMCIA_DRV_EN << shift);
302 1.5 gdamore PUT16(DBAU1550_PCMCIA, status);
303 1.5 gdamore wbflush();
304 1.5 gdamore tsleep(&status, PWAIT, "pcmcia_reset_start", mstohz(300));
305 1.5 gdamore
306 1.5 gdamore /* take it out of reset */
307 1.5 gdamore status |= (DBAU1550_PCMCIA_RST << shift);
308 1.5 gdamore PUT16(DBAU1550_PCMCIA, status);
309 1.5 gdamore wbflush();
310 1.6 gdamore
311 1.6 gdamore /* spec says 20 msec, but experience shows even 200 is not enough */
312 1.6 gdamore tsleep(&status, PWAIT, "pcmcia_reset_finish", mstohz(1000));
313 1.5 gdamore
314 1.5 gdamore /* NOTE: WE DO NOT SUPPORT DIFFERENT VCC/VPP LEVELS! */
315 1.5 gdamore /* This means that 12V cards are not supported! */
316 1.5 gdamore }
317 1.5 gdamore
318 1.5 gdamore void
319 1.5 gdamore dbau1550_slot_disable(int slot)
320 1.5 gdamore {
321 1.5 gdamore int shift;
322 1.5 gdamore uint16_t status;
323 1.5 gdamore
324 1.5 gdamore switch (slot) {
325 1.5 gdamore case 0:
326 1.5 gdamore shift = DBAU1550_PCMCIA_PC0_SHIFT;
327 1.5 gdamore break;
328 1.5 gdamore case 1:
329 1.5 gdamore shift = DBAU1550_PCMCIA_PC1_SHIFT;
330 1.5 gdamore break;
331 1.5 gdamore }
332 1.5 gdamore
333 1.5 gdamore status = GET16(DBAU1550_PCMCIA);
334 1.5 gdamore status &= ~(DBAU1550_PCMCIA_MASK);
335 1.5 gdamore PUT16(DBAU1550_PCMCIA, status);
336 1.5 gdamore wbflush();
337 1.5 gdamore }
338 1.5 gdamore
339 1.5 gdamore int
340 1.5 gdamore dbau1550_slot_status(int slot)
341 1.5 gdamore {
342 1.5 gdamore uint16_t status, mask;
343 1.5 gdamore status = GET16(DBAU1550_STATUS);
344 1.5 gdamore switch (slot) {
345 1.5 gdamore case 0:
346 1.5 gdamore mask = DBAU1550_STATUS_PCMCIA0_INSERTED;
347 1.5 gdamore break;
348 1.5 gdamore case 1:
349 1.5 gdamore mask = DBAU1550_STATUS_PCMCIA1_INSERTED;
350 1.5 gdamore break;
351 1.5 gdamore
352 1.5 gdamore default:
353 1.5 gdamore return 0;
354 1.5 gdamore }
355 1.5 gdamore
356 1.5 gdamore return ((mask & status) ? 0 : 1);
357 1.5 gdamore }
358 1.5 gdamore
359 1.5 gdamore const char *
360 1.5 gdamore dbau1550_slot_name(int slot)
361 1.5 gdamore {
362 1.5 gdamore switch (slot) {
363 1.5 gdamore case 0:
364 1.5 gdamore return "bottom slot";
365 1.5 gdamore case 1:
366 1.5 gdamore return "top slot";
367 1.5 gdamore default:
368 1.5 gdamore return "???";
369 1.5 gdamore }
370 1.5 gdamore }
371 1.7 gdamore
372 1.7 gdamore #if NAUSPI > 0
373 1.7 gdamore
374 1.7 gdamore static int
375 1.7 gdamore dbau1550_spi_select(void *arg, int slave)
376 1.7 gdamore {
377 1.7 gdamore uint16_t status;
378 1.7 gdamore if ((slave < 0) || (slave > 1))
379 1.7 gdamore return EINVAL;
380 1.7 gdamore status = GET16(DBAU1550_BOARD_SPECIFIC);
381 1.7 gdamore
382 1.7 gdamore if (slave) {
383 1.7 gdamore status |= DBAU1550_SPI_DEV_SEL;
384 1.7 gdamore } else {
385 1.7 gdamore status &= ~DBAU1550_SPI_DEV_SEL;
386 1.7 gdamore }
387 1.7 gdamore PUT16(DBAU1550_BOARD_SPECIFIC, status);
388 1.7 gdamore return 0;
389 1.7 gdamore }
390 1.7 gdamore
391 1.7 gdamore const struct auspi_machdep *
392 1.7 gdamore dbau1550_spi(bus_addr_t ba)
393 1.7 gdamore {
394 1.7 gdamore static const struct auspi_machdep md = {
395 1.7 gdamore .am_nslaves = 2,
396 1.7 gdamore .am_cookie = NULL,
397 1.7 gdamore .am_select = dbau1550_spi_select,
398 1.7 gdamore };
399 1.7 gdamore
400 1.7 gdamore /* DBAU1550 only has SPI on PSC0 */
401 1.7 gdamore if (ba != PSC0_BASE)
402 1.7 gdamore return NULL;
403 1.7 gdamore
404 1.7 gdamore return &md;
405 1.7 gdamore }
406 1.7 gdamore
407 1.7 gdamore #endif /* NAUSPI > 0 */
408