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