]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/dev/sx/sx_pci.c
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / sys / dev / sx / sx_pci.c
1 /*-
2  * Device driver for Specialix I/O8+ multiport serial card.
3  *
4  * Copyright 2003 Frank Mayhar <frank@exit.com>
5  *
6  * Derived from the "si" driver by Peter Wemm <peter@netplex.com.au>, using
7  * lots of information from the Linux "specialix" driver by Roger Wolff
8  * <R.E.Wolff@BitWizard.nl> and from the Intel CD1865 "Intelligent Eight-
9  * Channel Communications Controller" datasheet.  Roger was also nice
10  * enough to answer numerous questions about stuff specific to the I/O8+
11  * not covered by the CD1865 datasheet.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notices, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notices, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
25  * NO EVENT SHALL THE AUTHORS BE LIABLE.
26  *
27  * $FreeBSD$
28  */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/bus.h>
35 #include <sys/tty.h>
36 #include <machine/resource.h>   
37 #include <machine/bus.h>
38 #include <machine/clock.h>
39 #include <sys/rman.h>
40
41 #include <dev/sx/cd1865.h>
42 #include <dev/sx/sxvar.h>
43 #include <dev/sx/sx.h>
44 #include <dev/sx/sx_util.h>
45
46 #include <dev/pci/pcivar.h>
47
48 static int
49 sx_pci_probe(
50         device_t dev)
51 {
52         const char *desc = NULL;
53
54         switch (pci_get_devid(dev)) {
55                 case 0x200011cb:
56                         if (pci_get_subdevice(dev) == (uint16_t)0xb008) {
57                                 desc = "Specialix I/O8+ Multiport Serial Card";
58                         }
59                         break;
60         }
61         if (desc) {
62                 device_set_desc(dev, desc);
63                 return BUS_PROBE_DEFAULT;
64         }
65         return ENXIO;
66 }
67
68 static int
69 sx_pci_attach(device_t dev)
70 {
71         struct sx_softc *sc;
72         void *ih;
73         int error;
74
75         error = 0;
76         ih = NULL;
77         sc = device_get_softc(dev);
78
79         sc->sc_io_rid = 0x18;
80         sc->sc_io_res = bus_alloc_resource(dev,
81                                            SYS_RES_IOPORT,
82                                            &sc->sc_io_rid,
83                                            0, ~0, 1,
84                                            RF_ACTIVE);
85         if (!sc->sc_io_res) {
86                 device_printf(dev, "can't map I/O\n");
87                 goto fail;
88         }
89         sc->sc_st = rman_get_bustag(sc->sc_io_res);
90         sc->sc_sh = rman_get_bushandle(sc->sc_io_res);
91
92         /*
93          * Now that we have the bus handle, we can make certain that this
94          * is an I/O8+.
95          */
96         if (sx_probe_io8(dev)) {
97                 device_printf(dev, "Oops!  Device is not an I/O8+ board!\n");
98                 goto fail;
99         }
100
101         /*sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_io_res);*/
102         /*sc->sc_maddr = rman_get_virtual(sc->sc_io_res);*/
103
104         sc->sc_irq_rid = 0;
105         sc->sc_irq_res = bus_alloc_resource(dev,
106                                             SYS_RES_IRQ,
107                                             &sc->sc_irq_rid,
108                                             0, ~0, 1,
109                                             RF_ACTIVE | RF_SHAREABLE);
110         if (!sc->sc_irq_res) {
111                 device_printf(dev, "Can't map interrupt\n");
112                 goto fail;
113         }
114         sc->sc_irq = rman_get_start(sc->sc_irq_res);
115         error = bus_setup_intr(dev,
116                                sc->sc_irq_res,
117                                INTR_TYPE_TTY,
118                                sx_intr,
119                                sc, &ih);
120         if (error) {
121                 device_printf(dev, "Can't activate interrupt\n");
122                 goto fail;
123         }
124
125         error = sxattach(dev);
126         if (error)
127                 goto fail;
128         return (0);             /* success */
129
130 fail:
131         if (error == 0)
132                 error = ENXIO;
133         if (sc->sc_irq_res) {
134                 if (ih)
135                         bus_teardown_intr(dev, sc->sc_irq_res, ih);
136                 bus_release_resource(dev,
137                                      SYS_RES_IRQ,
138                                      sc->sc_irq_rid,
139                                      sc->sc_irq_res);
140                 sc->sc_irq_res = 0;
141         }
142         if (sc->sc_io_res) {
143                 bus_release_resource(dev,
144                                      SYS_RES_IOPORT,
145                                      sc->sc_io_rid,
146                                      sc->sc_io_res);
147                 sc->sc_io_res = 0;
148         }
149         return(error);
150 }
151
152 static device_method_t sx_pci_methods[] = {
153         /* Device interface */
154         DEVMETHOD(device_probe,         sx_pci_probe),
155         DEVMETHOD(device_attach,        sx_pci_attach),
156 /*      DEVMETHOD(device_detach,        sx_pci_detach),*/
157
158         { 0, 0 }
159 };
160
161 static driver_t sx_pci_driver = {
162         "sx",
163         sx_pci_methods,
164         sizeof(struct sx_softc),
165 };
166
167 DRIVER_MODULE(sx, pci, sx_pci_driver, sx_devclass, 0, 0);