xref: /netbsd-src/sys/dev/isa/slhci_isa.c (revision d21ffc75e5955757b0c877e5406c36483577800d)
1 /*	$NetBSD: slhci_isa.c,v 1.15 2016/07/14 04:00:45 msaitoh Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 Kiyoshi Ikehara. All rights reserved.
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  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Kiyoshi Ikehara.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * ISA-USB host board
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: slhci_isa.c,v 1.15 2016/07/14 04:00:45 msaitoh Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 
44 #include <sys/bus.h>
45 #include <sys/cpu.h>
46 
47 #include <dev/usb/usb.h>
48 #include <dev/usb/usbdi.h>
49 #include <dev/usb/usbdivar.h>
50 
51 #include <dev/ic/sl811hsreg.h>
52 #include <dev/ic/sl811hsvar.h>
53 
54 #include <dev/isa/isavar.h>
55 
56 struct slhci_isa_softc {
57 	struct slhci_softc sc;
58 	isa_chipset_tag_t sc_ic;
59 	void	*sc_ih;
60 };
61 
62 static int  slhci_isa_match(device_t, cfdata_t, void *);
63 static void slhci_isa_attach(device_t, device_t, void *);
64 
65 CFATTACH_DECL_NEW(slhci_isa, sizeof(struct slhci_isa_softc),
66     slhci_isa_match, slhci_isa_attach, NULL, slhci_activate);
67 
68 static int
slhci_isa_match(device_t parent,cfdata_t cf,void * aux)69 slhci_isa_match(device_t parent, cfdata_t cf, void *aux)
70 {
71 	struct isa_attach_args *ia = aux;
72 	bus_space_tag_t iot = ia->ia_iot;
73 	bus_space_handle_t ioh;
74 	int result = 0;
75 	uint8_t sltype;
76 
77 	if (ia->ia_nio < 1)
78 		goto out;
79 	if (ia->ia_nirq < 1)
80 		goto out;
81 
82 	if (ISA_DIRECT_CONFIG(ia))
83 		goto out;
84 
85 	/* Disallow wildcarded i/o address. */
86 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
87 		goto out;
88 
89 	/* Don't allow wildcarded IRQ. */
90 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
91 		goto out;
92 
93 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SL11_PORTSIZE, 0, &ioh))
94 		goto out;
95 
96 	bus_space_write_1(iot, ioh, SL11_IDX_ADDR, SL11_REV);
97 	sltype = SL11_GET_REV(bus_space_read_1(iot, ioh, SL11_IDX_DATA));
98 
99 	result = slhci_supported_rev(sltype);
100 
101 	bus_space_unmap(iot, ioh, SL11_PORTSIZE);
102 
103  out:
104 	if (result) {
105 		ia->ia_nio = 1;
106 		ia->ia_io[0].ir_size = SL11_PORTSIZE;
107 
108 		ia->ia_nirq = 1;
109 
110 		ia->ia_niomem = 0;
111 		ia->ia_ndrq = 0;
112 	}
113 	return (result);
114 }
115 
116 static void
slhci_isa_attach(device_t parent,device_t self,void * aux)117 slhci_isa_attach(device_t parent, device_t self, void *aux)
118 {
119 	struct slhci_isa_softc *isc = device_private(self);
120 	struct slhci_softc *sc = &isc->sc;
121 	struct isa_attach_args *ia = aux;
122 	bus_space_tag_t iot = ia->ia_iot;
123 	bus_space_handle_t ioh;
124 
125 	sc->sc_dev = self;
126 	sc->sc_bus.ub_hcpriv = sc;
127 
128 	printf("\n"); /* XXX still needed? */
129 
130 	/* Map I/O space */
131 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, SL11_PORTSIZE, 0, &ioh)) {
132 		aprint_error("%s: can't map I/O space\n", SC_NAME(sc));
133 		return;
134 	}
135 
136 	/* Initialize sc XXX power value unconfirmed */
137 	slhci_preinit(sc, NULL, iot, ioh, 500, SL11_IDX_DATA);
138 
139 	/* Establish the interrupt handler */
140 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
141 	    IST_EDGE, IPL_USB, slhci_intr, sc);
142 	if (isc->sc_ih == NULL) {
143 		aprint_error("%s: can't establish interrupt\n", SC_NAME(sc));
144 		return;
145 	}
146 
147 	/* Attach SL811HS/T */
148 	if (slhci_attach(sc))
149 		aprint_error("%s: slhci_attach failed\n", SC_NAME(sc));
150 }
151