2 * Copyright (c) 1996, David Greenman
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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
31 * Cyclades Y PCI serial interface driver
34 #include "opt_cy_pci_fastintr.h"
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
41 #include <machine/bus.h>
43 #include <machine/resource.h>
48 #include <dev/pci/pcivar.h>
50 #define CY_PCI_BASE_ADDR0 0x10
51 #define CY_PCI_BASE_ADDR1 0x14
52 #define CY_PCI_BASE_ADDR2 0x18
54 #define CY_PLX_9050_ICS 0x4c
55 #define CY_PLX_9060_ICS 0x68
56 #define CY_PLX_9050_ICS_IENABLE 0x040
57 #define CY_PLX_9050_ICS_LOCAL_IENABLE 0x001
58 #define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002
59 #define CY_PLX_9060_ICS_IENABLE 0x100
60 #define CY_PLX_9060_ICS_LOCAL_IENABLE 0x800
62 /* Cyclom-Y Custom Register for PLX ID. */
63 #define PLX_VER 0x3400
68 extern int cyattach_common(void *, int); /* Not exactly correct */
69 extern void cyintr(int);
71 static int cy_pci_attach(device_t dev);
72 static int cy_pci_probe(device_t dev);
74 static device_method_t cy_pci_methods[] = {
75 /* Device interface. */
76 DEVMETHOD(device_probe, cy_pci_probe),
77 DEVMETHOD(device_attach, cy_pci_attach),
82 static driver_t cy_pci_driver = {
88 static devclass_t cy_devclass;
90 DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
98 device_id = pci_get_devid(dev);
99 device_id &= ~0x00060000;
100 if (device_id != 0x0100120e && device_id != 0x0101120e)
102 device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
110 struct resource *ioport_res, *irq_res, *mem_res;
111 void *irq_cookie, *vaddr;
113 int adapter, irq_setup, ioport_rid, irq_rid, mem_rid;
120 ioport_rid = CY_PCI_BASE_ADDR1;
121 ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid,
122 0ul, ~0ul, 0ul, RF_ACTIVE);
123 if (ioport_res == NULL) {
124 device_printf(dev, "ioport resource allocation failed\n");
127 ioport = rman_get_start(ioport_res);
129 mem_rid = CY_PCI_BASE_ADDR2;
130 mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
131 0ul, ~0ul, 0ul, RF_ACTIVE);
132 if (mem_res == NULL) {
133 device_printf(dev, "memory resource allocation failed\n");
136 vaddr = rman_get_virtual(mem_res);
138 adapter = cyattach_common(vaddr, 1);
140 device_printf(dev, "no ports found!\n");
145 * Allocate our interrupt.
146 * XXX Using the ISA interrupt handler directly is a bit of a violation
147 * since it doesn't actually take the same argument. For PCI, the
148 * argument is a void * token, but for ISA it is a unit. Since
149 * there is no overlap in PCI/ISA unit numbers for this driver, and
150 * since the ISA driver must handle the interrupt anyway, we use
151 * the unit number as the token even for PCI.
154 irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
155 RF_SHAREABLE | RF_ACTIVE);
156 if (irq_res == NULL) {
157 device_printf(dev, "interrupt resource allocation failed\n");
160 #ifdef CY_PCI_FASTINTR
161 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST,
162 (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
167 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
168 (driver_intr_t *)cyintr, (void *)adapter, &irq_cookie);
169 if (irq_setup != 0) {
170 device_printf(dev, "interrupt setup failed\n");
175 * Enable the "local" interrupt input to generate a
178 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
181 outw(ioport + CY_PLX_9050_ICS,
182 CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
183 CY_PLX_9050_ICS_LOCAL_IPOLARITY);
187 default: /* Old board, use PLX_9060 values. */
188 outw(ioport + CY_PLX_9060_ICS,
189 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
190 CY_PLX_9060_ICS_LOCAL_IENABLE);
197 if (ioport_res != NULL)
198 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
201 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
203 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);