1/* $NetBSD: omsal400.c,v 1.8 2011/07/01 18:44:45 dyoung Exp $ */ 2 3/*- 4 * Copyright (c) 2006 Itronix Inc. 5 * Copyright (c) 2006 Shigeyuki Fukushima. 6 * All rights reserved. 7 * 8 * Written by Garrett D'Amore for Itronix Inc 9 * Written by Shigeyuki Fukushima. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above 17 * copyright notice, this list of conditions and the following 18 * disclaimer in the documentation and/or other materials provided 19 * with the distribution. 20 * 3. The name of the author may not be used to endorse or promote 21 * products derived from this software without specific prior 22 * written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 30 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37 38#include <sys/cdefs.h> 39__KERNEL_RCSID(0, "$NetBSD: omsal400.c,v 1.8 2011/07/01 18:44:45 dyoung Exp $"); 40 41#include <sys/param.h> 42#include <sys/bus.h> 43 44#include <mips/locore.h> 45 46#include <mips/alchemy/dev/augpiovar.h> 47#include <mips/alchemy/dev/aupcmciavar.h> 48 49#include <evbmips/alchemy/obiovar.h> 50#include <evbmips/alchemy/board.h> 51#include <evbmips/alchemy/omsal400reg.h> 52 53#define GET16(x) \ 54 (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x))) 55#define PUT16(x, v) \ 56 (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v)) 57 58static void omsal400_init(void); 59static int omsal400_pci_intr_map(const struct pci_attach_args *, 60 pci_intr_handle_t *); 61static void omsal400_poweroff(void); 62static void omsal400_reboot(void); 63static bus_addr_t omsal400_slot_offset(int); 64static int omsal400_slot_irq(int, int); 65static void omsal400_slot_enable(int); 66static void omsal400_slot_disable(int); 67static int omsal400_slot_status(int); 68static const char *omsal400_slot_name(int); 69 70static const struct obiodev omsal400_devices[] = { 71 { NULL }, 72}; 73 74static struct aupcmcia_machdep omsal400_pcmcia = { 75 1, /* nslots */ 76 omsal400_slot_offset, 77 omsal400_slot_irq, 78 omsal400_slot_enable, 79 omsal400_slot_disable, 80 omsal400_slot_status, 81 omsal400_slot_name, 82}; 83 84static struct alchemy_board omsal400_info = { 85 "Plathome Open Micro Server AL400/AMD Alchemy Au1550", 86 omsal400_devices, 87 omsal400_init, 88 omsal400_pci_intr_map, 89 omsal400_reboot, 90 omsal400_poweroff, 91 &omsal400_pcmcia, 92}; 93 94const struct alchemy_board * 95board_info(void) 96{ 97 98 return &omsal400_info; 99} 100 101void 102omsal400_init(void) 103{ 104 /* uint16_t whoami; */ 105 106 if (MIPS_PRID_COPTS(mips_options.mips_cpu_id) != MIPS_AU1550) 107 panic("omsal400: CPU not Au1550"); 108 109#if 0 /* XXX: TODO borad identification */ 110 /* check the whoami register for a match */ 111 whoami = GET16(DBAU1550_WHOAMI); 112 113 if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1) 114 panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami); 115 116 printf("DBAu1550 (cabernet), CPLDv%d, ", 117 DBAU1550_WHOAMI_CPLD(whoami)); 118 119 if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf) 120 printf("daughtercard 0x%x\n", 121 DBAU1550_WHOAMI_DAUGHTER(whoami)); 122 else 123 printf("no daughtercard\n"); 124#endif 125 126 /* leave console and clocks alone -- YAMON should have got it right! */ 127} 128 129int 130omsal400_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 131{ 132 /* 133 * This platform has 4 PCI devices: 134 * dev 1 (PCI_INTD): PCI Connector 135 * dev 2 (PCI_INTC): NEC USB 2.0 uPD720101 136 * dev 3 (PCI_INTB): Intel GB Ether 82541PI 137 * dev 4 (PCI_INTA): Intel GB Ether 82541PI 138 */ 139 static const int irqmap[4/*device*/][4/*pin*/] = { 140 { 6, -1, -1, -1 }, /* 1: PCI Connecter (not used) */ 141 { 5, 5, 5, -1 }, /* 2: NEC USB 2.0 */ 142 { 2, -1, -1, -1 }, /* 3: Intel GbE */ 143 { 1, -1, -1, -1 }, /* 4: Intel GbE */ 144 }; 145 146 int pin, dev, irq; 147 148 /* if interrupt pin not used... */ 149 if ((pin = pa->pa_intrpin) == 0) 150 return 1; 151 152 if (pin > 4) { 153 printf("pci: bad interrupt pin %d\n", pin); 154 return 1; 155 } 156 157 pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL); 158 159 if ((dev < 1) || (dev > 4)) { 160 printf("pci: bad device %d\n", dev); 161 return 1; 162 } 163 164 if ((irq = irqmap[dev - 1][pin - 1]) == -1) { 165 printf("pci: no IRQ routing for device %d pin %d\n", dev, pin); 166 return 1; 167 } 168 169 *ihp = irq; 170 return 0; 171} 172 173void 174omsal400_reboot(void) 175{ 176 177 /* XXX */ 178} 179 180void 181omsal400_poweroff(void) 182{ 183 184 printf("\n- poweroff -\n"); 185 /* XXX */ 186} 187 188 189int 190omsal400_slot_irq(int slot, int which) 191{ 192 static const int irqmap[1/*slot*/][2/*which*/] = { 193 { 35, 37 }, /* Slot 0: CF connector Type2 */ 194 }; 195 196 if ((slot >= 1) || (which >= 2)) 197 return -1; 198 199 return irqmap[slot][which]; 200} 201 202bus_addr_t 203omsal400_slot_offset(int slot) 204{ 205 206 switch (slot) { 207 case 0: 208 return (0); /* offset 0 */ 209 } 210 return (bus_addr_t)-1; 211} 212 213void 214omsal400_slot_enable(int slot) 215{ 216 217 /* nothing todo */ 218} 219 220void 221omsal400_slot_disable(int slot) 222{ 223 224 /* nothing todo */ 225} 226 227int 228omsal400_slot_status(int slot) 229{ 230 uint16_t inserted = 0; 231 232 switch (slot) { 233 case 0: 234 inserted = !AUGPIO_READ(5); /* pin 5 */ 235 break; 236 } 237 238 return inserted; 239} 240 241const char * 242omsal400_slot_name(int slot) 243{ 244 switch (slot) { 245 case 0: 246 return "CF connector Type2 on Static BUS#3"; 247 default: 248 return "???"; 249 } 250} 251