cy_pci.c revision 128800
1/* 2 * Copyright (c) 1996, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28/* 29 * Cyclades Y PCI serial interface driver 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD: head/sys/dev/cy/cy_pci.c 128800 2004-05-01 18:09:16Z bde $"); 34 35#include "opt_cy_pci_fastintr.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <sys/bus.h> 41 42#include <machine/bus.h> 43#include <sys/rman.h> 44#include <machine/resource.h> 45 46#include <vm/vm.h> 47#include <vm/pmap.h> 48 49#include <dev/pci/pcivar.h> 50 51#include <dev/cy/cyvar.h> 52 53#define CY_PCI_BASE_ADDR0 0x10 54#define CY_PCI_BASE_ADDR1 0x14 55#define CY_PCI_BASE_ADDR2 0x18 56 57#define CY_PLX_9050_ICS 0x4c 58#define CY_PLX_9060_ICS 0x68 59#define CY_PLX_9050_ICS_IENABLE 0x040 60#define CY_PLX_9050_ICS_LOCAL_IENABLE 0x001 61#define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002 62#define CY_PLX_9060_ICS_IENABLE 0x100 63#define CY_PLX_9060_ICS_LOCAL_IENABLE 0x800 64 65/* Cyclom-Y Custom Register for PLX ID. */ 66#define PLX_VER 0x3400 67#define PLX_9050 0x0b 68#define PLX_9060 0x0c 69#define PLX_9080 0x0d 70 71static int cy_pci_attach(device_t dev); 72static int cy_pci_probe(device_t dev); 73 74static device_method_t cy_pci_methods[] = { 75 /* Device interface. */ 76 DEVMETHOD(device_probe, cy_pci_probe), 77 DEVMETHOD(device_attach, cy_pci_attach), 78 79 { 0, 0 } 80}; 81 82static driver_t cy_pci_driver = { 83 cy_driver_name, 84 cy_pci_methods, 85 0, 86}; 87 88DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0); 89MODULE_DEPEND(cy, pci, 1, 1, 1); 90 91static int 92cy_pci_probe(dev) 93 device_t dev; 94{ 95 u_int32_t device_id; 96 97 device_id = pci_get_devid(dev); 98 device_id &= ~0x00060000; 99 if (device_id != 0x0100120e && device_id != 0x0101120e) 100 return (ENXIO); 101 device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter"); 102 return (0); 103} 104 105static int 106cy_pci_attach(dev) 107 device_t dev; 108{ 109 struct resource *ioport_res, *irq_res, *mem_res; 110 void *irq_cookie, *vaddr, *vsc; 111 u_int32_t ioport; 112 int irq_setup, ioport_rid, irq_rid, mem_rid; 113 u_char plx_ver; 114 115 ioport_res = NULL; 116 irq_res = NULL; 117 mem_res = NULL; 118 119 ioport_rid = CY_PCI_BASE_ADDR1; 120 ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid, 121 0ul, ~0ul, 0ul, RF_ACTIVE); 122 if (ioport_res == NULL) { 123 device_printf(dev, "ioport resource allocation failed\n"); 124 goto fail; 125 } 126 ioport = rman_get_start(ioport_res); 127 128 mem_rid = CY_PCI_BASE_ADDR2; 129 mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid, 130 0ul, ~0ul, 0ul, RF_ACTIVE); 131 if (mem_res == NULL) { 132 device_printf(dev, "memory resource allocation failed\n"); 133 goto fail; 134 } 135 vaddr = rman_get_virtual(mem_res); 136 137 vsc = cyattach_common(vaddr, 1); 138 if (vsc == NULL) { 139 device_printf(dev, "no ports found!\n"); 140 goto fail; 141 } 142 143 irq_rid = 0; 144 irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul, 145 RF_SHAREABLE | RF_ACTIVE); 146 if (irq_res == NULL) { 147 device_printf(dev, "interrupt resource allocation failed\n"); 148 goto fail; 149 } 150#ifdef CY_PCI_FASTINTR 151 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST, 152 cyintr, vsc, &irq_cookie); 153#else 154 irq_setup = ENXIO; 155#endif 156 if (irq_setup != 0) 157 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY, 158 cyintr, vsc, &irq_cookie); 159 if (irq_setup != 0) { 160 device_printf(dev, "interrupt setup failed\n"); 161 goto fail; 162 } 163 164 /* 165 * Enable the "local" interrupt input to generate a 166 * PCI interrupt. 167 */ 168 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f; 169 switch (plx_ver) { 170 case PLX_9050: 171 outw(ioport + CY_PLX_9050_ICS, 172 CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE | 173 CY_PLX_9050_ICS_LOCAL_IPOLARITY); 174 break; 175 case PLX_9060: 176 case PLX_9080: 177 default: /* Old board, use PLX_9060 values. */ 178 outw(ioport + CY_PLX_9060_ICS, 179 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE | 180 CY_PLX_9060_ICS_LOCAL_IENABLE); 181 break; 182 } 183 184 return (0); 185 186fail: 187 if (ioport_res != NULL) 188 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid, 189 ioport_res); 190 if (irq_res != NULL) 191 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res); 192 if (mem_res != NULL) 193 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res); 194 return (ENXIO); 195} 196