- Use IPL_BIO (instead of IPL_SERIAL) for SPI. - Convert simple_lock/ltsleep to mutex/condvar.diff -r1.3 -r1.4 src/sys/arch/mips/alchemy/dev/auspi.c
(rmind)
--- src/sys/arch/mips/alchemy/dev/auspi.c 2007/02/28 04:21:53 1.3
+++ src/sys/arch/mips/alchemy/dev/auspi.c 2011/06/08 23:05:48 1.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: auspi.c,v 1.3 2007/02/28 04:21:53 thorpej Exp $ */ | 1 | /* $NetBSD: auspi.c,v 1.4 2011/06/08 23:05:48 rmind Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | 4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | |
5 | * Copyright (c) 2006 Garrett D'Amore. | 5 | * Copyright (c) 2006 Garrett D'Amore. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Portions of this code were written by Garrett D'Amore for the | 8 | * Portions of this code were written by Garrett D'Amore for the | |
9 | * Champaign-Urbana Community Wireless Network Project. | 9 | * Champaign-Urbana Community Wireless Network Project. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or | 11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | 12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | 13 | * conditions are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | |
34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | 34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | |
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: auspi.c,v 1.3 2007/02/28 04:21:53 thorpej Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: auspi.c,v 1.4 2011/06/08 23:05:48 rmind Exp $"); | |
46 | 46 | |||
47 | #include "locators.h" | 47 | #include "locators.h" | |
48 | 48 | |||
49 | #include <sys/param.h> | 49 | #include <sys/param.h> | |
50 | #include <sys/systm.h> | 50 | #include <sys/systm.h> | |
51 | #include <sys/kernel.h> | 51 | #include <sys/kernel.h> | |
52 | #include <sys/device.h> | 52 | #include <sys/device.h> | |
53 | #include <sys/errno.h> | 53 | #include <sys/errno.h> | |
54 | #include <sys/proc.h> | 54 | #include <sys/proc.h> | |
55 | 55 | |||
56 | #include <machine/bus.h> | 56 | #include <machine/bus.h> | |
57 | #include <machine/cpu.h> | 57 | #include <machine/cpu.h> | |
58 | 58 | |||
@@ -148,27 +148,27 @@ auspi_attach(struct device *parent, stru | @@ -148,27 +148,27 @@ auspi_attach(struct device *parent, stru | |||
148 | 148 | |||
149 | sba.sba_controller = &sc->sc_spi; | 149 | sba.sba_controller = &sc->sc_spi; | |
150 | 150 | |||
151 | /* enable SPI mode */ | 151 | /* enable SPI mode */ | |
152 | sc->sc_psc.psc_enable(sc, AUPSC_SEL_SPI); | 152 | sc->sc_psc.psc_enable(sc, AUPSC_SEL_SPI); | |
153 | 153 | |||
154 | /* initialize the queue */ | 154 | /* initialize the queue */ | |
155 | SIMPLEQ_INIT(&sc->sc_q); | 155 | SIMPLEQ_INIT(&sc->sc_q); | |
156 | 156 | |||
157 | /* make sure interrupts disabled at the SPI */ | 157 | /* make sure interrupts disabled at the SPI */ | |
158 | PUTREG(sc, AUPSC_SPIMSK, SPIMSK_ALL); | 158 | PUTREG(sc, AUPSC_SPIMSK, SPIMSK_ALL); | |
159 | 159 | |||
160 | /* enable device interrupts */ | 160 | /* enable device interrupts */ | |
161 | sc->sc_ih = au_intr_establish(aa->aupsc_irq, 0, IPL_SERIAL, IST_LEVEL, | 161 | sc->sc_ih = au_intr_establish(aa->aupsc_irq, 0, IPL_BIO, IST_LEVEL, | |
162 | auspi_intr, sc); | 162 | auspi_intr, sc); | |
163 | 163 | |||
164 | (void) config_found_ia(&sc->sc_dev, "spibus", &sba, spibus_print); | 164 | (void) config_found_ia(&sc->sc_dev, "spibus", &sba, spibus_print); | |
165 | } | 165 | } | |
166 | 166 | |||
167 | int | 167 | int | |
168 | auspi_configure(void *arg, int slave, int mode, int speed) | 168 | auspi_configure(void *arg, int slave, int mode, int speed) | |
169 | { | 169 | { | |
170 | struct auspi_softc *sc = arg; | 170 | struct auspi_softc *sc = arg; | |
171 | int brg, i; | 171 | int brg, i; | |
172 | uint32_t reg; | 172 | uint32_t reg; | |
173 | 173 | |||
174 | /* setup interrupt registers */ | 174 | /* setup interrupt registers */ | |
@@ -418,22 +418,22 @@ auspi_intr(void *arg) | @@ -418,22 +418,22 @@ auspi_intr(void *arg) | |||
418 | ev & (SPIMSK_TR | SPIMSK_RR | SPIMSK_MD)); | 418 | ev & (SPIMSK_TR | SPIMSK_RR | SPIMSK_MD)); | |
419 | } | 419 | } | |
420 | 420 | |||
421 | return 1; | 421 | return 1; | |
422 | } | 422 | } | |
423 | 423 | |||
424 | int | 424 | int | |
425 | auspi_transfer(void *arg, struct spi_transfer *st) | 425 | auspi_transfer(void *arg, struct spi_transfer *st) | |
426 | { | 426 | { | |
427 | struct auspi_softc *sc = arg; | 427 | struct auspi_softc *sc = arg; | |
428 | int s; | 428 | int s; | |
429 | 429 | |||
430 | /* make sure we select the right chip */ | 430 | /* make sure we select the right chip */ | |
431 | s = splserial(); | 431 | s = splbio(); | |
432 | spi_transq_enqueue(&sc->sc_q, st); | 432 | spi_transq_enqueue(&sc->sc_q, st); | |
433 | if (sc->sc_running == 0) { | 433 | if (sc->sc_running == 0) { | |
434 | auspi_sched(sc); | 434 | auspi_sched(sc); | |
435 | } | 435 | } | |
436 | splx(s); | 436 | splx(s); | |
437 | return 0; | 437 | return 0; | |
438 | } | 438 | } | |
439 | 439 |
--- src/sys/arch/mips/atheros/dev/arspi.c 2007/02/28 04:21:53 1.5
+++ src/sys/arch/mips/atheros/dev/arspi.c 2011/06/08 23:05:48 1.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: arspi.c,v 1.5 2007/02/28 04:21:53 thorpej Exp $ */ | 1 | /* $NetBSD: arspi.c,v 1.6 2011/06/08 23:05:48 rmind Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | 4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | |
5 | * Copyright (c) 2006 Garrett D'Amore. | 5 | * Copyright (c) 2006 Garrett D'Amore. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Portions of this code were written by Garrett D'Amore for the | 8 | * Portions of this code were written by Garrett D'Amore for the | |
9 | * Champaign-Urbana Community Wireless Network Project. | 9 | * Champaign-Urbana Community Wireless Network Project. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or | 11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | 12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | 13 | * conditions are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | |
34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | 34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | |
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: arspi.c,v 1.5 2007/02/28 04:21:53 thorpej Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: arspi.c,v 1.6 2011/06/08 23:05:48 rmind Exp $"); | |
46 | 46 | |||
47 | #include "locators.h" | 47 | #include "locators.h" | |
48 | 48 | |||
49 | #include <sys/param.h> | 49 | #include <sys/param.h> | |
50 | #include <sys/systm.h> | 50 | #include <sys/systm.h> | |
51 | #include <sys/kernel.h> | 51 | #include <sys/kernel.h> | |
52 | #include <sys/device.h> | 52 | #include <sys/device.h> | |
53 | #include <sys/errno.h> | 53 | #include <sys/errno.h> | |
54 | #include <sys/malloc.h> | 54 | #include <sys/malloc.h> | |
55 | #include <sys/proc.h> | 55 | #include <sys/proc.h> | |
56 | #include <sys/queue.h> | 56 | #include <sys/queue.h> | |
57 | 57 | |||
58 | #include <machine/bus.h> | 58 | #include <machine/bus.h> | |
@@ -201,27 +201,27 @@ arspi_attach(struct device *parent, stru | @@ -201,27 +201,27 @@ arspi_attach(struct device *parent, stru | |||
201 | 201 | |||
202 | void | 202 | void | |
203 | arspi_interrupts(struct device *self) | 203 | arspi_interrupts(struct device *self) | |
204 | { | 204 | { | |
205 | /* | 205 | /* | |
206 | * we never leave polling mode, because, apparently, we | 206 | * we never leave polling mode, because, apparently, we | |
207 | * are missing some data about how to drive the SPI in interrupt | 207 | * are missing some data about how to drive the SPI in interrupt | |
208 | * mode. | 208 | * mode. | |
209 | */ | 209 | */ | |
210 | #if 0 | 210 | #if 0 | |
211 | struct arspi_softc *sc = device_private(self); | 211 | struct arspi_softc *sc = device_private(self); | |
212 | int s; | 212 | int s; | |
213 | 213 | |||
214 | s = splserial(); | 214 | s = splbio(); | |
215 | sc->sc_interrupts = true; | 215 | sc->sc_interrupts = true; | |
216 | splx(s); | 216 | splx(s); | |
217 | #endif | 217 | #endif | |
218 | } | 218 | } | |
219 | 219 | |||
220 | int | 220 | int | |
221 | arspi_intr(void *arg) | 221 | arspi_intr(void *arg) | |
222 | { | 222 | { | |
223 | struct arspi_softc *sc = arg; | 223 | struct arspi_softc *sc = arg; | |
224 | 224 | |||
225 | while (GETREG(sc, ARSPI_REG_CTL) & ARSPI_CTL_BUSY); | 225 | while (GETREG(sc, ARSPI_REG_CTL) & ARSPI_CTL_BUSY); | |
226 | 226 | |||
227 | arspi_done(sc, 0); | 227 | arspi_done(sc, 0); | |
@@ -260,27 +260,27 @@ arspi_transfer(void *cookie, struct spi_ | @@ -260,27 +260,27 @@ arspi_transfer(void *cookie, struct spi_ | |||
260 | int rv; | 260 | int rv; | |
261 | int s; | 261 | int s; | |
262 | 262 | |||
263 | st->st_busprivate = NULL; | 263 | st->st_busprivate = NULL; | |
264 | if ((rv = arspi_make_job(st)) != 0) { | 264 | if ((rv = arspi_make_job(st)) != 0) { | |
265 | if (st->st_busprivate) { | 265 | if (st->st_busprivate) { | |
266 | free(st->st_busprivate, M_DEVBUF); | 266 | free(st->st_busprivate, M_DEVBUF); | |
267 | st->st_busprivate = NULL; | 267 | st->st_busprivate = NULL; | |
268 | } | 268 | } | |
269 | spi_done(st, rv); | 269 | spi_done(st, rv); | |
270 | return rv; | 270 | return rv; | |
271 | } | 271 | } | |
272 | 272 | |||
273 | s = splserial(); | 273 | s = splbio(); | |
274 | spi_transq_enqueue(&sc->sc_transq, st); | 274 | spi_transq_enqueue(&sc->sc_transq, st); | |
275 | if (sc->sc_transfer == NULL) { | 275 | if (sc->sc_transfer == NULL) { | |
276 | arspi_sched(sc); | 276 | arspi_sched(sc); | |
277 | if (!sc->sc_interrupts) | 277 | if (!sc->sc_interrupts) | |
278 | arspi_poll(sc); | 278 | arspi_poll(sc); | |
279 | } | 279 | } | |
280 | splx(s); | 280 | splx(s); | |
281 | return 0; | 281 | return 0; | |
282 | } | 282 | } | |
283 | 283 | |||
284 | void | 284 | void | |
285 | arspi_sched(struct arspi_softc *sc) | 285 | arspi_sched(struct arspi_softc *sc) | |
286 | { | 286 | { |
--- src/sys/dev/spi/spi.c 2010/08/14 20:49:21 1.4
+++ src/sys/dev/spi/spi.c 2011/06/08 23:05:48 1.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: spi.c,v 1.4 2010/08/14 20:49:21 jym Exp $ */ | 1 | /* $NetBSD: spi.c,v 1.5 2011/06/08 23:05:48 rmind Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | 4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | |
5 | * Copyright (c) 2006 Garrett D'Amore. | 5 | * Copyright (c) 2006 Garrett D'Amore. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Portions of this code were written by Garrett D'Amore for the | 8 | * Portions of this code were written by Garrett D'Amore for the | |
9 | * Champaign-Urbana Community Wireless Network Project. | 9 | * Champaign-Urbana Community Wireless Network Project. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or | 11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | 12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | 13 | * conditions are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -32,35 +32,36 @@ | @@ -32,35 +32,36 @@ | |||
32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 32 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | 33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT | |
34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | 34 | * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT, | |
35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 35 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 41 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
42 | */ | 42 | */ | |
43 | 43 | |||
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.4 2010/08/14 20:49:21 jym Exp $"); | 45 | __KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.5 2011/06/08 23:05:48 rmind Exp $"); | |
46 | 46 | |||
47 | #include "locators.h" | 47 | #include "locators.h" | |
48 | 48 | |||
49 | #include <sys/param.h> | 49 | #include <sys/param.h> | |
50 | #include <sys/systm.h> | 50 | #include <sys/systm.h> | |
51 | #include <sys/device.h> | 51 | #include <sys/device.h> | |
52 | #include <sys/malloc.h> | 52 | #include <sys/malloc.h> | |
53 | #include <sys/proc.h> | 53 | #include <sys/mutex.h> | |
54 | #include <sys/condvar.h> | |||
54 | #include <sys/errno.h> | 55 | #include <sys/errno.h> | |
55 | 56 | |||
56 | #include <dev/spi/spivar.h> | 57 | #include <dev/spi/spivar.h> | |
57 | 58 | |||
58 | struct spi_softc { | 59 | struct spi_softc { | |
59 | struct spi_controller sc_controller; | 60 | struct spi_controller sc_controller; | |
60 | int sc_mode; | 61 | int sc_mode; | |
61 | int sc_speed; | 62 | int sc_speed; | |
62 | int sc_nslaves; | 63 | int sc_nslaves; | |
63 | struct spi_handle *sc_slaves; | 64 | struct spi_handle *sc_slaves; | |
64 | }; | 65 | }; | |
65 | 66 | |||
66 | /* | 67 | /* | |
@@ -80,27 +81,27 @@ int | @@ -80,27 +81,27 @@ int | |||
80 | spibus_print(void *aux, const char *pnp) | 81 | spibus_print(void *aux, const char *pnp) | |
81 | { | 82 | { | |
82 | 83 | |||
83 | if (pnp != NULL) | 84 | if (pnp != NULL) | |
84 | aprint_normal("spi at %s", pnp); | 85 | aprint_normal("spi at %s", pnp); | |
85 | 86 | |||
86 | return (UNCONF); | 87 | return (UNCONF); | |
87 | } | 88 | } | |
88 | 89 | |||
89 | 90 | |||
90 | static int | 91 | static int | |
91 | spi_match(device_t parent, cfdata_t cf, void *aux) | 92 | spi_match(device_t parent, cfdata_t cf, void *aux) | |
92 | { | 93 | { | |
93 | 94 | |||
94 | return 1; | 95 | return 1; | |
95 | } | 96 | } | |
96 | 97 | |||
97 | static int | 98 | static int | |
98 | spi_print(void *aux, const char *pnp) | 99 | spi_print(void *aux, const char *pnp) | |
99 | { | 100 | { | |
100 | struct spi_attach_args *sa = aux; | 101 | struct spi_attach_args *sa = aux; | |
101 | 102 | |||
102 | if (sa->sa_handle->sh_slave != -1) | 103 | if (sa->sa_handle->sh_slave != -1) | |
103 | aprint_normal(" slave %d", sa->sa_handle->sh_slave); | 104 | aprint_normal(" slave %d", sa->sa_handle->sh_slave); | |
104 | 105 | |||
105 | return (UNCONF); | 106 | return (UNCONF); | |
106 | } | 107 | } | |
@@ -178,49 +179,51 @@ CFATTACH_DECL_NEW(spi, sizeof(struct spi | @@ -178,49 +179,51 @@ CFATTACH_DECL_NEW(spi, sizeof(struct spi | |||
178 | * returned. | 179 | * returned. | |
179 | */ | 180 | */ | |
180 | int | 181 | int | |
181 | spi_configure(struct spi_handle *sh, int mode, int speed) | 182 | spi_configure(struct spi_handle *sh, int mode, int speed) | |
182 | { | 183 | { | |
183 | int s, rv; | 184 | int s, rv; | |
184 | struct spi_softc *sc = sh->sh_sc; | 185 | struct spi_softc *sc = sh->sh_sc; | |
185 | struct spi_controller *tag = sh->sh_controller; | 186 | struct spi_controller *tag = sh->sh_controller; | |
186 | 187 | |||
187 | /* ensure that request is compatible with other devices on the bus */ | 188 | /* ensure that request is compatible with other devices on the bus */ | |
188 | if ((sc->sc_mode >= 0) && (sc->sc_mode != mode)) | 189 | if ((sc->sc_mode >= 0) && (sc->sc_mode != mode)) | |
189 | return EINVAL; | 190 | return EINVAL; | |
190 | 191 | |||
191 | s = splserial(); | 192 | s = splbio(); | |
192 | /* pick lowest configured speed */ | 193 | /* pick lowest configured speed */ | |
193 | if (speed == 0) | 194 | if (speed == 0) | |
194 | speed = sc->sc_speed; | 195 | speed = sc->sc_speed; | |
195 | if (sc->sc_speed) | 196 | if (sc->sc_speed) | |
196 | speed = min(sc->sc_speed, speed); | 197 | speed = min(sc->sc_speed, speed); | |
197 | 198 | |||
198 | rv = (*tag->sct_configure)(tag->sct_cookie, sh->sh_slave, | 199 | rv = (*tag->sct_configure)(tag->sct_cookie, sh->sh_slave, | |
199 | mode, speed); | 200 | mode, speed); | |
200 | 201 | |||
201 | if (rv == 0) { | 202 | if (rv == 0) { | |
202 | sc->sc_mode = mode; | 203 | sc->sc_mode = mode; | |
203 | sc->sc_speed = speed; | 204 | sc->sc_speed = speed; | |
204 | } | 205 | } | |
205 | splx(s); | 206 | splx(s); | |
206 | return rv; | 207 | return rv; | |
207 | } | 208 | } | |
208 | 209 | |||
209 | void | 210 | void | |
210 | spi_transfer_init(struct spi_transfer *st) | 211 | spi_transfer_init(struct spi_transfer *st) | |
211 | { | 212 | { | |
212 | 213 | |||
213 | simple_lock_init(&st->st_lock); | 214 | mutex_init(&st->st_lock, MUTEX_DEFAULT, IPL_BIO); | |
215 | cv_init(&st->st_cv, "spicv"); | |||
216 | ||||
214 | st->st_flags = 0; | 217 | st->st_flags = 0; | |
215 | st->st_errno = 0; | 218 | st->st_errno = 0; | |
216 | st->st_done = NULL; | 219 | st->st_done = NULL; | |
217 | st->st_chunks = NULL; | 220 | st->st_chunks = NULL; | |
218 | st->st_private = NULL; | 221 | st->st_private = NULL; | |
219 | st->st_slave = -1; | 222 | st->st_slave = -1; | |
220 | } | 223 | } | |
221 | 224 | |||
222 | void | 225 | void | |
223 | spi_chunk_init(struct spi_chunk *chunk, int cnt, const uint8_t *wptr, | 226 | spi_chunk_init(struct spi_chunk *chunk, int cnt, const uint8_t *wptr, | |
224 | uint8_t *rptr) | 227 | uint8_t *rptr) | |
225 | { | 228 | { | |
226 | 229 | |||
@@ -257,57 +260,49 @@ spi_transfer(struct spi_handle *sh, stru | @@ -257,57 +260,49 @@ spi_transfer(struct spi_handle *sh, stru | |||
257 | } | 260 | } | |
258 | 261 | |||
259 | /* | 262 | /* | |
260 | * Match slave to handle's slave. | 263 | * Match slave to handle's slave. | |
261 | */ | 264 | */ | |
262 | st->st_slave = sh->sh_slave; | 265 | st->st_slave = sh->sh_slave; | |
263 | 266 | |||
264 | return (*tag->sct_transfer)(tag->sct_cookie, st); | 267 | return (*tag->sct_transfer)(tag->sct_cookie, st); | |
265 | } | 268 | } | |
266 | 269 | |||
267 | void | 270 | void | |
268 | spi_wait(struct spi_transfer *st) | 271 | spi_wait(struct spi_transfer *st) | |
269 | { | 272 | { | |
270 | int s; | |||
271 | 273 | |||
272 | s = splserial(); | 274 | mutex_enter(&st->st_lock); | |
273 | simple_lock(&st->st_lock); | |||
274 | while (!(st->st_flags & SPI_F_DONE)) { | 275 | while (!(st->st_flags & SPI_F_DONE)) { | |
275 | ltsleep(st, PWAIT, "spi_wait", 0, &st->st_lock); | 276 | cv_wait(&st->st_cv, &st->st_lock); | |
276 | } | 277 | } | |
277 | simple_unlock(&st->st_lock); | 278 | mutex_exit(&st->st_lock); | |
278 | splx(s); | |||
279 | } | 279 | } | |
280 | 280 | |||
281 | void | 281 | void | |
282 | spi_done(struct spi_transfer *st, int err) | 282 | spi_done(struct spi_transfer *st, int err) | |
283 | { | 283 | { | |
284 | int s; | |||
285 | 284 | |||
286 | s = splserial(); | 285 | mutex_enter(&st->st_lock); | |
287 | ||||
288 | if ((st->st_errno = err) != 0) { | 286 | if ((st->st_errno = err) != 0) { | |
289 | st->st_flags |= SPI_F_ERROR; | 287 | st->st_flags |= SPI_F_ERROR; | |
290 | } | 288 | } | |
291 | st->st_flags |= SPI_F_DONE; | 289 | st->st_flags |= SPI_F_DONE; | |
292 | if (st->st_done != NULL) { | 290 | if (st->st_done != NULL) { | |
293 | (*st->st_done)(st); | 291 | (*st->st_done)(st); | |
294 | } else { | 292 | } else { | |
295 | 293 | cv_broadcast(&st->st_cv); | ||
296 | simple_lock(&st->st_lock); | |||
297 | wakeup(st); | |||
298 | simple_unlock(&st->st_lock); | |||
299 | } | 294 | } | |
300 | splx(s); | 295 | mutex_exit(&st->st_lock); | |
301 | } | 296 | } | |
302 | 297 | |||
303 | /* | 298 | /* | |
304 | * Some convenience routines. These routines block until the work | 299 | * Some convenience routines. These routines block until the work | |
305 | * is done. | 300 | * is done. | |
306 | * | 301 | * | |
307 | * spi_recv - receives data from the bus | 302 | * spi_recv - receives data from the bus | |
308 | * | 303 | * | |
309 | * spi_send - sends data to the bus | 304 | * spi_send - sends data to the bus | |
310 | * | 305 | * | |
311 | * spi_send_recv - sends data to the bus, and then receives. Note that this is | 306 | * spi_send_recv - sends data to the bus, and then receives. Note that this is | |
312 | * done synchronously, i.e. send a command and get the response. This is | 307 | * done synchronously, i.e. send a command and get the response. This is | |
313 | * not full duplex. If you wnat full duplex, you can't use these convenience | 308 | * not full duplex. If you wnat full duplex, you can't use these convenience |
--- src/sys/dev/spi/spivar.h 2008/01/08 13:28:22 1.3
+++ src/sys/dev/spi/spivar.h 2011/06/08 23:05:48 1.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: spivar.h,v 1.3 2008/01/08 13:28:22 dogcow Exp $ */ | 1 | /* $NetBSD: spivar.h,v 1.4 2011/06/08 23:05:48 rmind Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | 4 | * Copyright (c) 2006 Urbana-Champaign Independent Media Center. | |
5 | * Copyright (c) 2006 Garrett D'Amore. | 5 | * Copyright (c) 2006 Garrett D'Amore. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Portions of this code were written by Garrett D'Amore for the | 8 | * Portions of this code were written by Garrett D'Amore for the | |
9 | * Champaign-Urbana Community Wireless Network Project. | 9 | * Champaign-Urbana Community Wireless Network Project. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or | 11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | 12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | 13 | * conditions are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -99,27 +99,28 @@ struct spi_chunk { | @@ -99,27 +99,28 @@ struct spi_chunk { | |||
99 | const uint8_t *chunk_wptr; | 99 | const uint8_t *chunk_wptr; | |
100 | int chunk_rresid; | 100 | int chunk_rresid; | |
101 | int chunk_wresid; | 101 | int chunk_wresid; | |
102 | }; | 102 | }; | |
103 | 103 | |||
104 | struct spi_transfer { | 104 | struct spi_transfer { | |
105 | struct spi_chunk *st_chunks; /* chained bufs */ | 105 | struct spi_chunk *st_chunks; /* chained bufs */ | |
106 | SIMPLEQ_ENTRY(spi_transfer) st_chain; /* chain of submitted jobs */ | 106 | SIMPLEQ_ENTRY(spi_transfer) st_chain; /* chain of submitted jobs */ | |
107 | int st_flags; | 107 | int st_flags; | |
108 | int st_errno; | 108 | int st_errno; | |
109 | int st_slave; | 109 | int st_slave; | |
110 | void *st_private; | 110 | void *st_private; | |
111 | void (*st_done)(struct spi_transfer *); | 111 | void (*st_done)(struct spi_transfer *); | |
112 | struct simplelock st_lock; | 112 | kmutex_t st_lock; | |
113 | kcondvar_t st_cv; | |||
113 | void *st_busprivate; | 114 | void *st_busprivate; | |
114 | }; | 115 | }; | |
115 | 116 | |||
116 | /* declare a list of transfers */ | 117 | /* declare a list of transfers */ | |
117 | SIMPLEQ_HEAD(spi_transq, spi_transfer); | 118 | SIMPLEQ_HEAD(spi_transq, spi_transfer); | |
118 | 119 | |||
119 | #define spi_transq_init(q) \ | 120 | #define spi_transq_init(q) \ | |
120 | SIMPLEQ_INIT(q) | 121 | SIMPLEQ_INIT(q) | |
121 | 122 | |||
122 | #define spi_transq_enqueue(q, trans) \ | 123 | #define spi_transq_enqueue(q, trans) \ | |
123 | SIMPLEQ_INSERT_TAIL(q, trans, st_chain) | 124 | SIMPLEQ_INSERT_TAIL(q, trans, st_chain) | |
124 | 125 | |||
125 | #define spi_transq_dequeue(q) \ | 126 | #define spi_transq_dequeue(q) \ |