omsal400.c revision 1.11
11.11Ssimonb/* $NetBSD: omsal400.c,v 1.11 2020/08/17 07:50:41 simonb Exp $ */ 21.1Sshige 31.1Sshige/*- 41.2Sshige * Copyright (c) 2006 Itronix Inc. 51.1Sshige * Copyright (c) 2006 Shigeyuki Fukushima. 61.1Sshige * All rights reserved. 71.1Sshige * 81.2Sshige * Written by Garrett D'Amore for Itronix Inc 91.1Sshige * Written by Shigeyuki Fukushima. 101.1Sshige * 111.1Sshige * Redistribution and use in source and binary forms, with or without 121.1Sshige * modification, are permitted provided that the following conditions 131.1Sshige * are met: 141.1Sshige * 1. Redistributions of source code must retain the above copyright 151.1Sshige * notice, this list of conditions and the following disclaimer. 161.1Sshige * 2. Redistributions in binary form must reproduce the above 171.1Sshige * copyright notice, this list of conditions and the following 181.1Sshige * disclaimer in the documentation and/or other materials provided 191.1Sshige * with the distribution. 201.1Sshige * 3. The name of the author may not be used to endorse or promote 211.1Sshige * products derived from this software without specific prior 221.1Sshige * written permission. 231.1Sshige * 241.1Sshige * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 251.1Sshige * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 261.1Sshige * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271.1Sshige * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 281.1Sshige * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291.1Sshige * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 301.1Sshige * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 311.1Sshige * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 321.1Sshige * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 331.1Sshige * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 341.1Sshige * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 351.1Sshige */ 361.1Sshige 371.1Sshige 381.1Sshige#include <sys/cdefs.h> 391.11Ssimonb__KERNEL_RCSID(0, "$NetBSD: omsal400.c,v 1.11 2020/08/17 07:50:41 simonb Exp $"); 401.1Sshige 411.1Sshige#include <sys/param.h> 421.8Sdyoung#include <sys/bus.h> 431.10Smatt#include <sys/cpu.h> 441.9Smatt 451.9Smatt#include <mips/locore.h> 461.10Smatt#include <mips/cpuregs.h> 471.9Smatt 481.4Skiyohara#include <mips/alchemy/dev/augpiovar.h> 491.4Skiyohara#include <mips/alchemy/dev/aupcmciavar.h> 501.9Smatt 511.1Sshige#include <evbmips/alchemy/obiovar.h> 521.1Sshige#include <evbmips/alchemy/board.h> 531.1Sshige#include <evbmips/alchemy/omsal400reg.h> 541.1Sshige 551.1Sshige#define GET16(x) \ 561.1Sshige (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x))) 571.1Sshige#define PUT16(x, v) \ 581.1Sshige (*((volatile uint16_t *)MIPS_PHYS_TO_KSEG1(x)) = (v)) 591.1Sshige 601.1Sshigestatic void omsal400_init(void); 611.7Sdyoungstatic int omsal400_pci_intr_map(const struct pci_attach_args *, 621.1Sshige pci_intr_handle_t *); 631.1Sshigestatic void omsal400_poweroff(void); 641.1Sshigestatic void omsal400_reboot(void); 651.4Skiyoharastatic bus_addr_t omsal400_slot_offset(int); 661.4Skiyoharastatic int omsal400_slot_irq(int, int); 671.4Skiyoharastatic void omsal400_slot_enable(int); 681.4Skiyoharastatic void omsal400_slot_disable(int); 691.4Skiyoharastatic int omsal400_slot_status(int); 701.4Skiyoharastatic const char *omsal400_slot_name(int); 711.1Sshige 721.1Sshigestatic const struct obiodev omsal400_devices[] = { 731.1Sshige { NULL }, 741.1Sshige}; 751.1Sshige 761.4Skiyoharastatic struct aupcmcia_machdep omsal400_pcmcia = { 771.4Skiyohara 1, /* nslots */ 781.4Skiyohara omsal400_slot_offset, 791.4Skiyohara omsal400_slot_irq, 801.4Skiyohara omsal400_slot_enable, 811.4Skiyohara omsal400_slot_disable, 821.4Skiyohara omsal400_slot_status, 831.4Skiyohara omsal400_slot_name, 841.4Skiyohara}; 851.4Skiyohara 861.1Sshigestatic struct alchemy_board omsal400_info = { 871.5Skiyohara "Plathome Open Micro Server AL400/AMD Alchemy Au1550", 881.1Sshige omsal400_devices, 891.1Sshige omsal400_init, 901.1Sshige omsal400_pci_intr_map, 911.1Sshige omsal400_reboot, 921.1Sshige omsal400_poweroff, 931.4Skiyohara &omsal400_pcmcia, 941.1Sshige}; 951.1Sshige 961.11Ssimonb/* The OMS AL400 kernels only support little endian */ 971.11SsimonbCTASSERT(_BYTE_ORDER == _LITTLE_ENDIAN); 981.11Ssimonb 991.1Sshigeconst struct alchemy_board * 1001.1Sshigeboard_info(void) 1011.1Sshige{ 1021.1Sshige 1031.1Sshige return &omsal400_info; 1041.1Sshige} 1051.1Sshige 1061.1Sshigevoid 1071.1Sshigeomsal400_init(void) 1081.1Sshige{ 1091.1Sshige /* uint16_t whoami; */ 1101.1Sshige 1111.6Smatt if (MIPS_PRID_COPTS(mips_options.mips_cpu_id) != MIPS_AU1550) 1121.1Sshige panic("omsal400: CPU not Au1550"); 1131.1Sshige 1141.1Sshige#if 0 /* XXX: TODO borad identification */ 1151.1Sshige /* check the whoami register for a match */ 1161.1Sshige whoami = GET16(DBAU1550_WHOAMI); 1171.1Sshige 1181.1Sshige if (DBAU1550_WHOAMI_BOARD(whoami) != DBAU1550_WHOAMI_DBAU1550_REV1) 1191.1Sshige panic("dbau1550: WHOAMI (%x) not DBAu1550!", whoami); 1201.1Sshige 1211.1Sshige printf("DBAu1550 (cabernet), CPLDv%d, ", 1221.1Sshige DBAU1550_WHOAMI_CPLD(whoami)); 1231.1Sshige 1241.1Sshige if (DBAU1550_WHOAMI_DAUGHTER(whoami) != 0xf) 1251.1Sshige printf("daughtercard 0x%x\n", 1261.1Sshige DBAU1550_WHOAMI_DAUGHTER(whoami)); 1271.1Sshige else 1281.1Sshige printf("no daughtercard\n"); 1291.1Sshige#endif 1301.1Sshige 1311.1Sshige /* leave console and clocks alone -- YAMON should have got it right! */ 1321.1Sshige} 1331.1Sshige 1341.1Sshigeint 1351.7Sdyoungomsal400_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp) 1361.1Sshige{ 1371.1Sshige /* 1381.1Sshige * This platform has 4 PCI devices: 1391.1Sshige * dev 1 (PCI_INTD): PCI Connector 1401.1Sshige * dev 2 (PCI_INTC): NEC USB 2.0 uPD720101 1411.1Sshige * dev 3 (PCI_INTB): Intel GB Ether 82541PI 1421.1Sshige * dev 4 (PCI_INTA): Intel GB Ether 82541PI 1431.1Sshige */ 1441.3Sshige static const int irqmap[4/*device*/][4/*pin*/] = { 1451.1Sshige { 6, -1, -1, -1 }, /* 1: PCI Connecter (not used) */ 1461.1Sshige { 5, 5, 5, -1 }, /* 2: NEC USB 2.0 */ 1471.1Sshige { 2, -1, -1, -1 }, /* 3: Intel GbE */ 1481.1Sshige { 1, -1, -1, -1 }, /* 4: Intel GbE */ 1491.1Sshige }; 1501.1Sshige 1511.1Sshige int pin, dev, irq; 1521.1Sshige 1531.1Sshige /* if interrupt pin not used... */ 1541.1Sshige if ((pin = pa->pa_intrpin) == 0) 1551.1Sshige return 1; 1561.1Sshige 1571.1Sshige if (pin > 4) { 1581.1Sshige printf("pci: bad interrupt pin %d\n", pin); 1591.1Sshige return 1; 1601.1Sshige } 1611.1Sshige 1621.1Sshige pci_decompose_tag(pa->pa_pc, pa->pa_intrtag, NULL, &dev, NULL); 1631.1Sshige 1641.1Sshige if ((dev < 1) || (dev > 4)) { 1651.1Sshige printf("pci: bad device %d\n", dev); 1661.1Sshige return 1; 1671.1Sshige } 1681.1Sshige 1691.1Sshige if ((irq = irqmap[dev - 1][pin - 1]) == -1) { 1701.1Sshige printf("pci: no IRQ routing for device %d pin %d\n", dev, pin); 1711.1Sshige return 1; 1721.1Sshige } 1731.1Sshige 1741.1Sshige *ihp = irq; 1751.1Sshige return 0; 1761.1Sshige} 1771.1Sshige 1781.1Sshigevoid 1791.1Sshigeomsal400_reboot(void) 1801.1Sshige{ 1811.1Sshige 1821.1Sshige /* XXX */ 1831.1Sshige} 1841.1Sshige 1851.1Sshigevoid 1861.1Sshigeomsal400_poweroff(void) 1871.1Sshige{ 1881.1Sshige 1891.1Sshige printf("\n- poweroff -\n"); 1901.1Sshige /* XXX */ 1911.1Sshige} 1921.4Skiyohara 1931.4Skiyohara 1941.4Skiyoharaint 1951.4Skiyoharaomsal400_slot_irq(int slot, int which) 1961.4Skiyohara{ 1971.4Skiyohara static const int irqmap[1/*slot*/][2/*which*/] = { 1981.4Skiyohara { 35, 37 }, /* Slot 0: CF connector Type2 */ 1991.4Skiyohara }; 2001.4Skiyohara 2011.4Skiyohara if ((slot >= 1) || (which >= 2)) 2021.4Skiyohara return -1; 2031.4Skiyohara 2041.4Skiyohara return irqmap[slot][which]; 2051.4Skiyohara} 2061.4Skiyohara 2071.4Skiyoharabus_addr_t 2081.4Skiyoharaomsal400_slot_offset(int slot) 2091.4Skiyohara{ 2101.4Skiyohara 2111.4Skiyohara switch (slot) { 2121.4Skiyohara case 0: 2131.4Skiyohara return (0); /* offset 0 */ 2141.4Skiyohara } 2151.4Skiyohara return (bus_addr_t)-1; 2161.4Skiyohara} 2171.4Skiyohara 2181.4Skiyoharavoid 2191.4Skiyoharaomsal400_slot_enable(int slot) 2201.4Skiyohara{ 2211.4Skiyohara 2221.4Skiyohara /* nothing todo */ 2231.4Skiyohara} 2241.4Skiyohara 2251.4Skiyoharavoid 2261.4Skiyoharaomsal400_slot_disable(int slot) 2271.4Skiyohara{ 2281.4Skiyohara 2291.4Skiyohara /* nothing todo */ 2301.4Skiyohara} 2311.4Skiyohara 2321.4Skiyoharaint 2331.4Skiyoharaomsal400_slot_status(int slot) 2341.4Skiyohara{ 2351.4Skiyohara uint16_t inserted = 0; 2361.4Skiyohara 2371.4Skiyohara switch (slot) { 2381.4Skiyohara case 0: 2391.4Skiyohara inserted = !AUGPIO_READ(5); /* pin 5 */ 2401.4Skiyohara break; 2411.4Skiyohara } 2421.4Skiyohara 2431.4Skiyohara return inserted; 2441.4Skiyohara} 2451.4Skiyohara 2461.4Skiyoharaconst char * 2471.4Skiyoharaomsal400_slot_name(int slot) 2481.4Skiyohara{ 2491.4Skiyohara switch (slot) { 2501.4Skiyohara case 0: 2511.4Skiyohara return "CF connector Type2 on Static BUS#3"; 2521.4Skiyohara default: 2531.4Skiyohara return "???"; 2541.4Skiyohara } 2551.4Skiyohara} 256