2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1996, David Greenman
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Cyclades Y PCI serial interface driver
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_cy_pci_fastintr.h"
39 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/module.h>
44 #include <machine/bus.h>
46 #include <machine/resource.h>
48 #include <dev/pci/pcivar.h>
50 #include <dev/cy/cyvar.h>
52 #define CY_PCI_BASE_ADDR0 0x10
53 #define CY_PCI_BASE_ADDR1 0x14
54 #define CY_PCI_BASE_ADDR2 0x18
56 #define CY_PLX_9050_ICS 0x4c
57 #define CY_PLX_9060_ICS 0x68
58 #define CY_PLX_9050_ICS_IENABLE 0x040
59 #define CY_PLX_9050_ICS_LOCAL_IENABLE 0x001
60 #define CY_PLX_9050_ICS_LOCAL_IPOLARITY 0x002
61 #define CY_PLX_9060_ICS_IENABLE 0x100
62 #define CY_PLX_9060_ICS_LOCAL_IENABLE 0x800
64 /* Cyclom-Y Custom Register for PLX ID. */
65 #define PLX_VER 0x3400
70 static int cy_pci_attach(device_t dev);
71 static int cy_pci_probe(device_t dev);
73 static device_method_t cy_pci_methods[] = {
74 /* Device interface. */
75 DEVMETHOD(device_probe, cy_pci_probe),
76 DEVMETHOD(device_attach, cy_pci_attach),
81 static driver_t cy_pci_driver = {
87 DRIVER_MODULE(cy, pci, cy_pci_driver, cy_devclass, 0, 0);
88 MODULE_DEPEND(cy, pci, 1, 1, 1);
96 device_id = pci_get_devid(dev);
97 device_id &= ~0x00060000;
98 if (device_id != 0x0100120e && device_id != 0x0101120e)
100 device_set_desc(dev, "Cyclades Cyclom-Y Serial Adapter");
101 return (BUS_PROBE_DEFAULT);
108 struct resource *ioport_res, *irq_res, *mem_res;
109 void *irq_cookie, *vaddr, *vsc;
111 int irq_setup, ioport_rid, irq_rid, mem_rid;
118 ioport_rid = CY_PCI_BASE_ADDR1;
119 ioport_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &ioport_rid,
121 if (ioport_res == NULL) {
122 device_printf(dev, "ioport resource allocation failed\n");
125 ioport = rman_get_start(ioport_res);
127 mem_rid = CY_PCI_BASE_ADDR2;
128 mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
130 if (mem_res == NULL) {
131 device_printf(dev, "memory resource allocation failed\n");
134 vaddr = rman_get_virtual(mem_res);
136 vsc = cyattach_common(vaddr, 1);
138 device_printf(dev, "no ports found!\n");
143 irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irq_rid,
144 RF_SHAREABLE | RF_ACTIVE);
145 if (irq_res == NULL) {
146 device_printf(dev, "interrupt resource allocation failed\n");
149 #ifdef CY_PCI_FASTINTR
150 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
151 cyintr, NULL, vsc, &irq_cookie);
156 irq_setup = bus_setup_intr(dev, irq_res, INTR_TYPE_TTY,
157 NULL, (driver_intr_t *)cyintr, vsc, &irq_cookie);
158 if (irq_setup != 0) {
159 device_printf(dev, "interrupt setup failed\n");
164 * Enable the "local" interrupt input to generate a
167 plx_ver = *((u_char *)vaddr + PLX_VER) & 0x0f;
170 outw(ioport + CY_PLX_9050_ICS,
171 CY_PLX_9050_ICS_IENABLE | CY_PLX_9050_ICS_LOCAL_IENABLE |
172 CY_PLX_9050_ICS_LOCAL_IPOLARITY);
176 default: /* Old board, use PLX_9060 values. */
177 outw(ioport + CY_PLX_9060_ICS,
178 inw(ioport + CY_PLX_9060_ICS) | CY_PLX_9060_ICS_IENABLE |
179 CY_PLX_9060_ICS_LOCAL_IENABLE);
186 if (ioport_res != NULL)
187 bus_release_resource(dev, SYS_RES_IOPORT, ioport_rid,
190 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
192 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);