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