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
29 * Cyclades Y PCI serial interface driver
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_cy_pci_fastintr.h"
37 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
42 #include <machine/bus.h>
44 #include <machine/resource.h>
46 #include <dev/pci/pcivar.h>
48 #include <dev/cy/cyvar.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 static int cy_pci_attach(device_t dev);
69 static int cy_pci_probe(device_t dev);
71 static device_method_t cy_pci_methods[] = {
72 /* Device interface. */
73 DEVMETHOD(device_probe, cy_pci_probe),
74 DEVMETHOD(device_attach, cy_pci_attach),
79 static driver_t cy_pci_driver = {
85 DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
86 MODULE_DEPEND(cy, pci, 1, 1, 1);
94 device_id = pci_get_devid(dev);
95 device_id &= ~0x00060000;
96 if (device_id != 0x0100120e && device_id != 0x0101120e)
98 device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
99 return (BUS_PROBE_DEFAULT);
106 struct resource *ioport_res, *irq_res, *mem_res;
107 void *irq_cookie, *vaddr, *vsc;
109 int irq_setup, ioport_rid, irq_rid, mem_rid;
116 ioport_rid = CY_PCI_BASE_ADDR1;
117 ioport_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &ioport_rid,
118 0ul, ~0ul, 0ul, RF_ACTIVE);
119 if (ioport_res == NULL) {
120 device_printf(dev, "ioport resource allocation failed\n");
123 ioport = rman_get_start(ioport_res);
125 mem_rid = CY_PCI_BASE_ADDR2;
126 mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid,
127 0ul, ~0ul, 0ul, RF_ACTIVE);
128 if (mem_res == NULL) {
129 device_printf(dev, "memory resource allocation failed\n");
132 vaddr = rman_get_virtual(mem_res);
134 vsc = cyattach_common(vaddr, 1);
136 device_printf(dev, "no ports found!\n");
141 irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0ul, ~0ul, 0ul,
142 RF_SHAREABLE | RF_ACTIVE);
143 if (irq_res == NULL) {
144 device_printf(dev, "interrupt resource allocation failed\n");
147 #ifdef CY_PCI_FASTINTR
148 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY | INTR_FAST,
149 cyintr, vsc, &irq_cookie);
154 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
155 cyintr, vsc, &irq_cookie);
156 if (irq_setup != 0) {
157 device_printf(dev, "interrupt setup failed\n");
162 * Enable the "local" interrupt input to generate a
165 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
168 outw(ioport + CY_PLX_9050_ICS,
169 CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
170 CY_PLX_9050_ICS_LOCAL_IPOLARITY);
174 default: /* Old board, use PLX_9060 values. */
175 outw(ioport + CY_PLX_9060_ICS,
176 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
177 CY_PLX_9060_ICS_LOCAL_IENABLE);
184 if (ioport_res != NULL)
185 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
188 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
190 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);