]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cy/cy_isa.c
Disable useless -Wformat-zero-length
[FreeBSD/FreeBSD.git] / sys / dev / cy / cy_isa.c
1 /*-
2  * cyclades cyclom-y serial driver
3  *      Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Copyright (c) 1993 Andrew Herbert.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name Andrew Herbert may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
24  * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 /*
34  * Cyclades Y ISA serial interface driver
35  */
36
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bus.h>
43 #include <sys/kernel.h>
44 #include <sys/module.h>
45
46 #include <machine/bus.h>
47 #include <sys/rman.h>
48 #include <machine/resource.h>
49
50 #include <isa/isavar.h>
51
52 #include <dev/cy/cyreg.h>
53 #include <dev/cy/cyvar.h>
54
55 static int      cy_isa_attach(device_t dev);
56 static int      cy_isa_probe(device_t dev);
57
58 static device_method_t cy_isa_methods[] = {
59         /* Device interface. */
60         DEVMETHOD(device_probe,         cy_isa_probe),
61         DEVMETHOD(device_attach,        cy_isa_attach),
62
63         { 0, 0 }
64 };
65
66 static driver_t cy_isa_driver = {
67         cy_driver_name,
68         cy_isa_methods,
69         0,
70 };
71
72 DRIVER_MODULE(cy, isa, cy_isa_driver, cy_devclass, 0, 0);
73
74 static int
75 cy_isa_probe(device_t dev)
76 {
77         struct resource *mem_res;
78         cy_addr iobase;
79         int error, mem_rid;
80
81         if (isa_get_logicalid(dev) != 0)        /* skip PnP probes */
82                 return (ENXIO);
83
84         mem_rid = 0;
85         mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
86             RF_ACTIVE);
87         if (mem_res == NULL) {
88                 device_printf(dev, "ioport resource allocation failed\n");
89                 return (ENXIO);
90         }
91         iobase = rman_get_virtual(mem_res);
92
93         /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
94         cy_inb(iobase, CY16_RESET, 0);  /* XXX? */
95         DELAY(500);             /* wait for the board to get its act together */
96
97         /* this is needed to get the board out of reset */
98         cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
99         DELAY(500);
100
101         error = (cy_units(iobase, 0) == 0 ? ENXIO : 0);
102         bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
103         return (error);
104 }
105
106 static int
107 cy_isa_attach(device_t dev)
108 {
109         struct resource *irq_res, *mem_res;
110         void *irq_cookie, *vaddr, *vsc;
111         int irq_rid, mem_rid;
112
113         irq_res = NULL;
114         mem_res = NULL;
115
116         mem_rid = 0;
117         mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &mem_rid,
118             RF_ACTIVE);
119         if (mem_res == NULL) {
120                 device_printf(dev, "memory resource allocation failed\n");
121                 goto fail;
122         }
123         vaddr = rman_get_virtual(mem_res);
124
125         vsc = cyattach_common(vaddr, 0);
126         if (vsc == NULL) {
127                 device_printf(dev, "no ports found!\n");
128                 goto fail;
129         }
130
131         irq_rid = 0;
132         irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irq_rid,
133             RF_SHAREABLE | RF_ACTIVE);
134         if (irq_res == NULL) {
135                 device_printf(dev, "interrupt resource allocation failed\n");
136                 goto fail;
137         }
138         if (bus_setup_intr(dev, irq_res, INTR_TYPE_TTY, 
139             cyintr, NULL, vsc, &irq_cookie) != 0) {         
140                 device_printf(dev, "interrupt setup failed\n");
141                 goto fail;
142         }
143
144         return (0);
145
146 fail:
147         if (irq_res != NULL)
148                 bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
149         if (mem_res != NULL)
150                 bus_release_resource(dev, SYS_RES_MEMORY, mem_rid, mem_res);
151         return (ENXIO);
152 }