]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/dev/pccbb/pccbb_isa.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / dev / pccbb / pccbb_isa.c
1 /*-
2  * Copyright (c) 2002-2004 M. Warner Losh.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 /*
28  * Driver for ISA to PCMCIA bridges compliant with the Intel ExCA
29  * specification.
30  */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/proc.h>
38 #include <sys/condvar.h>
39 #include <sys/errno.h>
40 #include <sys/kernel.h>
41 #include <sys/lock.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/mutex.h>
45 #include <sys/sysctl.h>
46 #include <sys/kthread.h>
47 #include <sys/bus.h>
48 #include <machine/bus.h>
49 #include <sys/rman.h>
50 #include <machine/resource.h>
51
52 #include <isa/isavar.h>
53
54 #include <dev/pci/pcivar.h>
55 #include <dev/pci/pcib_private.h>
56
57 #include <dev/pccard/pccardreg.h>
58 #include <dev/pccard/pccardvar.h>
59
60 #include <dev/exca/excareg.h>
61 #include <dev/exca/excavar.h>
62
63 #include <dev/pccbb/pccbbreg.h>
64 #include <dev/pccbb/pccbbvar.h>
65
66 #include "power_if.h"
67 #include "card_if.h"
68
69 /*****************************************************************************
70  * Configurable parameters.
71  *****************************************************************************/
72
73 /* sysctl vars */
74 static SYSCTL_NODE(_hw, OID_AUTO, pcic, CTLFLAG_RD, 0, "PCIC parameters");
75
76 static int isa_intr_mask = EXCA_INT_MASK_ALLOWED;
77 TUNABLE_INT("hw.cbb.intr_mask", &isa_intr_mask);
78 SYSCTL_INT(_hw_pcic, OID_AUTO, intr_mask, CTLFLAG_RD, &isa_intr_mask, 0,
79     "Mask of allowable interrupts for this laptop.  The default is generally\n\
80 correct, but some laptops do not route all the IRQ pins to the bridge to\n\
81 save wires.  Sometimes you need a more restrictive mask because some of the\n\
82 hardware in your laptop may not have a driver so its IRQ might not be\n\
83 allocated.");
84
85 /*
86  * CL-PD6722's VSENSE method
87  *     0: NO VSENSE (assume a 5.0V card always)
88  *     1: 6710's method (default)
89  *     2: 6729's method
90  */
91 int pcic_pd6722_vsense = 1;
92 TUNABLE_INT("hw.pcic.pd6722_vsense", &pcic_pd6722_vsense);
93 SYSCTL_INT(_hw_pcic, OID_AUTO, pd6722_vsense, CTLFLAG_RDTUN,
94     &pcic_pd6722_vsense, 1,
95     "Select CL-PD6722's VSENSE method.  VSENSE is used to determine the\n\
96 volatage of inserted cards.  The CL-PD6722 has two methods to determine the\n\
97 voltage of the card.  0 means assume a 5.0V card and do not check.  1 means\n\
98 use the same method that the CL-PD6710 uses (default).  2 means use the\n\
99 same method as the CL-PD6729.  2 is documented in the datasheet as being\n\
100 the correct way, but 1 seems to give better results on more laptops.");
101
102 /*****************************************************************************
103  * End of configurable parameters.
104  *****************************************************************************/
105
106 #define DPRINTF(x) do { if (cbb_debug) printf x; } while (0)
107 #define DEVPRINTF(x) do { if (cbb_debug) device_printf x; } while (0)
108
109 /* XXX Not sure that PNP0E03 should be claimed, except maybe on pc98 */
110 static struct isa_pnp_id pcic_ids[] = {
111         {EXCA_PNP_ACTIONTEC,            NULL},          /* AEI0218 */
112         {EXCA_PNP_IBM3765,              NULL},          /* IBM3765 */
113         {EXCA_PNP_82365,                NULL},          /* PNP0E00 */
114         {EXCA_PNP_CL_PD6720,            NULL},          /* PNP0E01 */
115         {EXCA_PNP_VLSI_82C146,          NULL},          /* PNP0E02 */
116         {EXCA_PNP_82365_CARDBUS,        NULL},          /* PNP0E03 */
117         {EXCA_PNP_SCM_SWAPBOX,          NULL},          /* SCM0469 */
118         {EXCA_NEC_PC9801_102,           NULL},          /* NEC8091 */
119         {EXCA_NEC_PC9821RA_E01,         NULL},          /* NEC8121 */
120         {0}
121 };
122
123 /************************************************************************/
124 /* Probe/Attach                                                         */
125 /************************************************************************/
126
127 static int
128 cbb_isa_activate(device_t dev)
129 {
130         struct cbb_softc *sc = device_get_softc(dev);
131         struct resource *res;
132         int rid;
133         int i;
134
135         /* A little bogus, but go ahead and get the irq for CSC events */
136         rid = 0;
137         res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
138         if (res == NULL) {
139                 /*
140                  * No IRQ specified, find one.  This can be due to the PnP
141                  * data not specifying any IRQ, or the default kernel not
142                  * assinging an IRQ.
143                  */
144                 for (i = 0; i < 16 && res == NULL; i++) {
145                         if (((1 << i) & isa_intr_mask) == 0)
146                                 continue;
147                         res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, i, i,
148                             1, RF_ACTIVE);
149                 }
150         }
151         if (res == NULL)
152                 return (ENXIO);
153         sc->irq_res = res;
154         rid = 0;
155         res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
156         if (res == NULL) {
157                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
158                 sc->irq_res = NULL;
159                 device_printf(dev, "Cannot allocate I/O\n");
160                 return (ENOMEM);
161         }
162         sc->bst = rman_get_bustag(res);
163         sc->bsh = rman_get_bushandle(res);
164         sc->base_res = res;
165         return (0);
166 }
167
168 static void
169 cbb_isa_deactivate(device_t dev)
170 {
171         struct cbb_softc *sc = device_get_softc(dev);
172
173         if (sc->irq_res)
174                 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res);
175         sc->irq_res = NULL;
176         if (sc->base_res)
177                 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->base_res);
178         sc->base_res = NULL;
179 }
180
181 static int
182 cbb_isa_probe(device_t dev)
183 {
184         int error;
185         struct cbb_softc *sc = device_get_softc(dev);
186
187         /* Check isapnp ids */
188         error = ISA_PNP_PROBE(device_get_parent(dev), dev, pcic_ids);
189         if (error != 0 && error != ENOENT)
190                 return (error);
191
192         error = cbb_isa_activate(dev);
193         if (error != 0)
194                 return (error);
195
196         /* Check to make sure that we have actual hardware */
197         error = exca_probe_slots(dev, &sc->exca[0], sc->bst, sc->bsh);
198         cbb_isa_deactivate(dev);
199         return (error);
200 }
201
202 static int
203 cbb_isa_attach(device_t dev)
204 {
205         return (ENOMEM);
206 }
207
208 static int
209 cbb_isa_suspend(device_t dev)
210 {
211         return (0);
212 }
213
214 static int
215 cbb_isa_resume(device_t dev)
216 {
217         return (0);
218 }
219
220 static device_method_t cbb_methods[] = {
221         /* Device interface */
222         DEVMETHOD(device_probe,                 cbb_isa_probe),
223         DEVMETHOD(device_attach,                cbb_isa_attach),
224         DEVMETHOD(device_detach,                cbb_detach),
225         DEVMETHOD(device_suspend,               cbb_isa_suspend),
226         DEVMETHOD(device_resume,                cbb_isa_resume),
227
228         /* bus methods */
229         DEVMETHOD(bus_read_ivar,                cbb_read_ivar),
230         DEVMETHOD(bus_write_ivar,               cbb_write_ivar),
231         DEVMETHOD(bus_alloc_resource,           cbb_alloc_resource),
232         DEVMETHOD(bus_release_resource,         cbb_release_resource),
233         DEVMETHOD(bus_activate_resource,        cbb_activate_resource),
234         DEVMETHOD(bus_deactivate_resource,      cbb_deactivate_resource),
235         DEVMETHOD(bus_driver_added,             cbb_driver_added),
236         DEVMETHOD(bus_child_detached,           cbb_child_detached),
237         DEVMETHOD(bus_setup_intr,               cbb_setup_intr),
238         DEVMETHOD(bus_teardown_intr,            cbb_teardown_intr),
239         DEVMETHOD(bus_child_present,            cbb_child_present),
240
241         /* 16-bit card interface */
242         DEVMETHOD(card_set_res_flags,           cbb_pcic_set_res_flags),
243         DEVMETHOD(card_set_memory_offset,       cbb_pcic_set_memory_offset),
244
245         /* power interface */
246         DEVMETHOD(power_enable_socket,          cbb_power_enable_socket),
247         DEVMETHOD(power_disable_socket,         cbb_power_disable_socket),
248
249         DEVMETHOD_END
250 };
251
252 static driver_t cbb_isa_driver = {
253         "cbb",
254         cbb_methods,
255         sizeof(struct cbb_softc)
256 };
257
258 DRIVER_MODULE(cbb, isa, cbb_isa_driver, cbb_devclass, 0, 0);
259 MODULE_DEPEND(cbb, exca, 1, 1, 1);