kernel: Use DEVMETHOD_END in the drivers.
[dragonfly.git] / sys / dev / serial / si / si_pci.c
1 /*
2  * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
3  *
4  * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notices, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notices, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18  * NO EVENT SHALL THE AUTHORS BE LIABLE.
19  *
20  * $FreeBSD: src/sys/dev/si/si_pci.c,v 1.2 2000/01/24 08:11:10 peter Exp $
21  */
22
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/kernel.h>
26 #include <sys/bus.h>
27 #include <sys/rman.h>
28
29 #include "sireg.h"
30 #include "sivar.h"
31
32 #include <bus/pci/pcivar.h>
33
34 static int
35 si_pci_probe(device_t dev)
36 {
37         const char *desc = NULL;
38
39         switch (pci_get_devid(dev)) {
40         case 0x400011cb:
41                 desc = "Specialix SI/XIO PCI host card";
42                 break;
43         case 0x200011cb:
44                 if (pci_read_config(dev, SIJETSSIDREG, 4) == 0x020011cb)
45                         desc = "Specialix SX PCI host card";
46                 break;
47         }
48         if (desc) {
49                 device_set_desc(dev, desc);
50                 return 0;
51         }
52         return ENXIO;
53 }
54
55 static int
56 si_pci_attach(device_t dev)
57 {
58         struct si_softc *sc;
59         void *ih;
60         int error;
61
62         error = 0;
63         ih = NULL;
64         sc = device_get_softc(dev);
65
66         switch (pci_get_devid(dev)) {
67         case 0x400011cb:
68                 sc->sc_type = SIPCI;
69                 sc->sc_mem_rid = SIPCIBADR;
70                 break;
71         case 0x200011cb:
72                 sc->sc_type = SIJETPCI;
73                 sc->sc_mem_rid = SIJETBADR;
74                 break;
75         }
76
77         sc->sc_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
78                                             &sc->sc_mem_rid,
79                                             0, ~0, 1, RF_ACTIVE);
80         if (!sc->sc_mem_res) {
81                 device_printf(dev, "couldn't map memory\n");
82                 goto fail;
83         }
84         sc->sc_paddr = (caddr_t)rman_get_start(sc->sc_mem_res);
85         sc->sc_maddr = rman_get_virtual(sc->sc_mem_res);
86
87         sc->sc_irq_rid = 0;
88         sc->sc_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irq_rid,
89                                             0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
90         if (!sc->sc_irq_res) {
91                 device_printf(dev, "couldn't map interrupt\n");
92                 goto fail;
93         }
94         sc->sc_irq = rman_get_start(sc->sc_irq_res);
95         error = bus_setup_intr(dev, sc->sc_irq_res, INTR_MPSAFE, si_intr, sc, &ih, NULL);
96         if (error) {
97                 device_printf(dev, "could not activate interrupt\n");
98                 goto fail;
99         }
100
101         error = siattach(dev);
102         if (error)
103                 goto fail;
104         return (0);             /* success */
105
106 fail:
107         if (error == 0)
108                 error = ENXIO;
109         if (sc->sc_irq_res) {
110                 if (ih)
111                         bus_teardown_intr(dev, sc->sc_irq_res, ih);
112                 bus_release_resource(dev, SYS_RES_IRQ,
113                                      sc->sc_irq_rid, sc->sc_irq_res);
114                 sc->sc_irq_res = 0;
115         }
116         if (sc->sc_mem_res) {
117                 bus_release_resource(dev, SYS_RES_MEMORY,
118                                      sc->sc_mem_rid, sc->sc_mem_res);
119                 sc->sc_mem_res = 0;
120         }
121         return (error);
122 }
123
124 static device_method_t si_pci_methods[] = {
125         /* Device interface */
126         DEVMETHOD(device_probe,         si_pci_probe),
127         DEVMETHOD(device_attach,        si_pci_attach),
128
129         DEVMETHOD_END
130 };
131
132 static driver_t si_pci_driver = {
133         "si",
134         si_pci_methods,
135         sizeof(struct si_softc),
136 };
137
138 DRIVER_MODULE(si, pci, si_pci_driver, si_devclass, NULL, NULL);