Wed Jan 19 13:33:11 2022 UTC ()
Provide a spi_compatible_lookup() function to go along with
spi_compatible_match().


(thorpej)
diff -r1.22 -r1.23 src/sys/dev/spi/spi.c
diff -r1.11 -r1.12 src/sys/dev/spi/spivar.h

cvs diff -r1.22 -r1.23 src/sys/dev/spi/spi.c (expand / switch to unified diff)

--- src/sys/dev/spi/spi.c 2022/01/19 12:58:06 1.22
+++ src/sys/dev/spi/spi.c 2022/01/19 13:33:11 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $ */ 1/* $NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej 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: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $"); 45__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej 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/conf.h> 52#include <sys/conf.h>
53#include <sys/malloc.h> 53#include <sys/malloc.h>
54#include <sys/mutex.h> 54#include <sys/mutex.h>
55#include <sys/condvar.h> 55#include <sys/condvar.h>
56#include <sys/errno.h> 56#include <sys/errno.h>
57 57
58#include <dev/spi/spivar.h> 58#include <dev/spi/spivar.h>
@@ -262,26 +262,34 @@ spi_direct_attach_child_devices(device_t @@ -262,26 +262,34 @@ spi_direct_attach_child_devices(device_t
262} 262}
263 263
264int 264int
265spi_compatible_match(const struct spi_attach_args *sa, const cfdata_t cf, 265spi_compatible_match(const struct spi_attach_args *sa, const cfdata_t cf,
266 const struct device_compatible_entry *compats) 266 const struct device_compatible_entry *compats)
267{ 267{
268 if (sa->sa_ncompat > 0) 268 if (sa->sa_ncompat > 0)
269 return device_compatible_match(sa->sa_compat, sa->sa_ncompat, 269 return device_compatible_match(sa->sa_compat, sa->sa_ncompat,
270 compats); 270 compats);
271 271
272 return 1; 272 return 1;
273} 273}
274 274
 275const struct device_compatible_entry *
 276spi_compatible_lookup(const struct spi_attach_args *sa,
 277 const struct device_compatible_entry *compats)
 278{
 279 return device_compatible_lookup(sa->sa_compat, sa->sa_ncompat,
 280 compats);
 281}
 282
275/* 283/*
276 * API for device drivers. 284 * API for device drivers.
277 * 285 *
278 * We provide wrapper routines to decouple the ABI for the SPI 286 * We provide wrapper routines to decouple the ABI for the SPI
279 * device drivers from the ABI for the SPI bus drivers. 287 * device drivers from the ABI for the SPI bus drivers.
280 */ 288 */
281static void 289static void
282spi_attach(device_t parent, device_t self, void *aux) 290spi_attach(device_t parent, device_t self, void *aux)
283{ 291{
284 struct spi_softc *sc = device_private(self); 292 struct spi_softc *sc = device_private(self);
285 struct spibus_attach_args *sba = aux; 293 struct spibus_attach_args *sba = aux;
286 int i; 294 int i;
287 295

cvs diff -r1.11 -r1.12 src/sys/dev/spi/spivar.h (expand / switch to unified diff)

--- src/sys/dev/spi/spivar.h 2022/01/19 05:21:44 1.11
+++ src/sys/dev/spi/spivar.h 2022/01/19 13:33:11 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: spivar.h,v 1.11 2022/01/19 05:21:44 thorpej Exp $ */ 1/* $NetBSD: spivar.h,v 1.12 2022/01/19 13:33:11 thorpej 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
@@ -132,26 +132,29 @@ SIMPLEQ_HEAD(spi_transq, spi_transfer); @@ -132,26 +132,29 @@ SIMPLEQ_HEAD(spi_transq, spi_transfer);
132 SIMPLEQ_INSERT_TAIL(q, trans, st_chain) 132 SIMPLEQ_INSERT_TAIL(q, trans, st_chain)
133 133
134#define spi_transq_dequeue(q) \ 134#define spi_transq_dequeue(q) \
135 SIMPLEQ_REMOVE_HEAD(q, st_chain) 135 SIMPLEQ_REMOVE_HEAD(q, st_chain)
136 136
137#define spi_transq_first(q) \ 137#define spi_transq_first(q) \
138 SIMPLEQ_FIRST(q) 138 SIMPLEQ_FIRST(q)
139 139
140#define SPI_F_DONE 0x0001 140#define SPI_F_DONE 0x0001
141#define SPI_F_ERROR 0x0002 141#define SPI_F_ERROR 0x0002
142 142
143int spi_compatible_match(const struct spi_attach_args *, const cfdata_t, 143int spi_compatible_match(const struct spi_attach_args *, const cfdata_t,
144 const struct device_compatible_entry *); 144 const struct device_compatible_entry *);
 145const struct device_compatible_entry *
 146 spi_compatible_lookup(const struct spi_attach_args *,
 147 const struct device_compatible_entry *);
145int spi_configure(device_t, struct spi_handle *, int, int); 148int spi_configure(device_t, struct spi_handle *, int, int);
146int spi_transfer(struct spi_handle *, struct spi_transfer *); 149int spi_transfer(struct spi_handle *, struct spi_transfer *);
147void spi_transfer_init(struct spi_transfer *); 150void spi_transfer_init(struct spi_transfer *);
148void spi_chunk_init(struct spi_chunk *, int, const uint8_t *, uint8_t *); 151void spi_chunk_init(struct spi_chunk *, int, const uint8_t *, uint8_t *);
149void spi_transfer_add(struct spi_transfer *, struct spi_chunk *); 152void spi_transfer_add(struct spi_transfer *, struct spi_chunk *);
150void spi_wait(struct spi_transfer *); 153void spi_wait(struct spi_transfer *);
151void spi_done(struct spi_transfer *, int); 154void spi_done(struct spi_transfer *, int);
152 155
153/* convenience wrappers */ 156/* convenience wrappers */
154int spi_send(struct spi_handle *, int, const uint8_t *); 157int spi_send(struct spi_handle *, int, const uint8_t *);
155int spi_recv(struct spi_handle *, int, uint8_t *); 158int spi_recv(struct spi_handle *, int, uint8_t *);
156int spi_send_recv(struct spi_handle *, int, const uint8_t *, int, uint8_t *); 159int spi_send_recv(struct spi_handle *, int, const uint8_t *, int, uint8_t *);
157 160