Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/spi Probe / match routines should not have side-effe...
details: https://anonhg.NetBSD.org/src/rev/b17803897221
branches: trunk
changeset: 359728:b17803897221
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed Jan 19 05:05:45 2022 +0000
description:
Probe / match routines should not have side-effects: do the spi_configure()
calls in the attach routines.
diffstat:
sys/arch/evbarm/mpcsa/mpcsa_leds.c | 18 +++++++++++-------
sys/dev/spi/m25p.c | 24 ++++++++++++------------
sys/dev/spi/mcp23xxxgpio_spi.c | 17 ++++++++++-------
sys/dev/spi/mcp3k.c | 17 ++++++++++-------
sys/dev/spi/mcp48x1.c | 17 ++++++++++-------
sys/dev/spi/oj6sh.c | 14 ++++++++++----
sys/dev/spi/scmdspi.c | 17 +++++++++++------
sys/dev/spi/ssdfb_spi.c | 29 +++++++++++++++--------------
sys/dev/spi/tmp121.c | 19 +++++++++++--------
9 files changed, 100 insertions(+), 72 deletions(-)
diffs (truncated from 480 to 300 lines):
diff -r 5ebcca281930 -r b17803897221 sys/arch/evbarm/mpcsa/mpcsa_leds.c
--- a/sys/arch/evbarm/mpcsa/mpcsa_leds.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/arch/evbarm/mpcsa/mpcsa_leds.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,5 +1,5 @@
-/* $Id: mpcsa_leds.c,v 1.7 2021/08/07 16:18:50 thorpej Exp $ */
-/* $NetBSD: mpcsa_leds.c,v 1.7 2021/08/07 16:18:50 thorpej Exp $ */
+/* $Id: mpcsa_leds.c,v 1.8 2022/01/19 05:05:45 thorpej Exp $ */
+/* $NetBSD: mpcsa_leds.c,v 1.8 2022/01/19 05:05:45 thorpej Exp $ */
/*
* Copyright (c) 2007 Embedtronics Oy. All rights reserved.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpcsa_leds.c,v 1.7 2021/08/07 16:18:50 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpcsa_leds.c,v 1.8 2022/01/19 05:05:45 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -118,14 +118,10 @@
static int
mpcsa_leds_match(device_t parent, cfdata_t match, void *aux)
{
- struct spi_attach_args *sa = aux;
if (strcmp(match->cf_name, "mpcsa_leds"))
return 0;
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 10000000))
- return 0;
-
return 2;
}
@@ -138,10 +134,18 @@
struct gpiobus_attach_args gba;
#endif
int n;
+ int error;
aprint_naive(": output buffer\n");
aprint_normal(": 74HC595 or compatible shift register(s)\n");
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 10000000);
+ if (error) {
+ aprint_error_dev(self,
+ "failed to set Mode 0 @ 10MHz, error=%d\n", error);
+ return;
+ }
+
sc->sc_sh = sa->sa_handle;
sc->sc_pinstate = 0xffff;
callout_init(&sc->sc_c, 0);
diff -r 5ebcca281930 -r b17803897221 sys/dev/spi/m25p.c
--- a/sys/dev/spi/m25p.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/dev/spi/m25p.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.18 2021/05/14 09:25:14 jmcneill Exp $ */
+/* $NetBSD: m25p.c,v 1.19 2022/01/19 05:05:45 thorpej Exp $ */
/*-
* Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.18 2021/05/14 09:25:14 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.19 2022/01/19 05:05:45 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -125,17 +125,8 @@
m25p_match(device_t parent, cfdata_t cf, void *aux)
{
struct spi_attach_args *sa = aux;
- int res;
- res = spi_compatible_match(sa, cf, compat_data);
- if (!res)
- return res;
-
- /* configure for 20MHz, which is the max for normal reads */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 20000000))
- res = 0;
-
- return res;
+ return spi_compatible_match(sa, cf, compat_data);
}
static void
@@ -143,12 +134,21 @@
{
struct m25p_softc *sc = device_private(self);
struct spi_attach_args *sa = aux;
+ int error;
sc->sc_sh = sa->sa_handle;
aprint_normal("\n");
aprint_naive("\n");
+ /* configure for 20MHz, which is the max for normal reads */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 20000000);
+ if (error) {
+ aprint_error_dev(self,
+ "failed to set Mode 0 @ 20MHz, error=%d\n", error);
+ return;
+ }
+
config_interrupts(self, m25p_doattach);
}
diff -r 5ebcca281930 -r b17803897221 sys/dev/spi/mcp23xxxgpio_spi.c
--- a/sys/dev/spi/mcp23xxxgpio_spi.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/dev/spi/mcp23xxxgpio_spi.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp23xxxgpio_spi.c,v 1.2 2022/01/17 19:36:54 thorpej Exp $ */
+/* $NetBSD: mcp23xxxgpio_spi.c,v 1.3 2022/01/19 05:05:45 thorpej Exp $ */
/*-
* Copyright (c) 2014, 2022 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcp23xxxgpio_spi.c,v 1.2 2022/01/17 19:36:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23xxxgpio_spi.c,v 1.3 2022/01/19 05:05:45 thorpej Exp $");
/*
* Driver for Microchip serial I/O expanders:
@@ -175,14 +175,9 @@
static int
mcpgpio_spi_match(device_t parent, cfdata_t cf, void *aux)
{
- struct spi_attach_args *sa = aux;
/* MCP23S17 has no way to detect it! */
- /* run at 10MHz */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 10000000))
- return 0;
-
return 1;
}
@@ -207,6 +202,14 @@
aprint_naive("\n");
aprint_normal(": %s I/O Expander\n", sc->sc_variant->name);
+ /* run at 10MHz */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 10000000);
+ if (error) {
+ aprint_error_dev(self,
+ "failed to set Mode 0 @ 10MHz, error=%d\n", error);
+ return;
+ }
+
/*
* Before we decode the topology information, ensure each
* chip has IOCON.HAEN set so that it will actually decode
diff -r 5ebcca281930 -r b17803897221 sys/dev/spi/mcp3k.c
--- a/sys/dev/spi/mcp3k.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/dev/spi/mcp3k.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp3k.c,v 1.2 2016/11/20 12:38:04 phx Exp $ */
+/* $NetBSD: mcp3k.c,v 1.3 2022/01/19 05:05:45 thorpej Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -174,15 +174,10 @@
static int
mcp3kadc_match(device_t parent, cfdata_t cf, void *aux)
{
- struct spi_attach_args *sa = aux;
if (strcmp(cf->cf_name, "mcp3kadc") != 0)
return 0;
- /* configure for 1MHz */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000000))
- return 0;
-
return 1;
}
@@ -193,7 +188,7 @@
struct spi_attach_args *sa;
struct mcp3kadc_softc *sc;
struct mcp3kadc_model *model;
- int ch, i;
+ int error, ch, i;
sa = aux;
sc = device_private(self);
@@ -209,6 +204,14 @@
(unsigned)model->name, (unsigned)model->channels,
(unsigned)model->bits);
+ /* configure for 1MHz */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 1000000);
+ if (error) {
+ aprint_error_dev(self,
+ "failed to set Mode 0 @ 1MHz, error=%d\n", error);
+ return;
+ }
+
/* set a default Vref in mV according to the chip's ADC resolution */
sc->sc_vref_mv = 1 << ((model->flags & M3K_SIGNED) ?
model->bits - 1 : model->bits);
diff -r 5ebcca281930 -r b17803897221 sys/dev/spi/mcp48x1.c
--- a/sys/dev/spi/mcp48x1.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/dev/spi/mcp48x1.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp48x1.c,v 1.1 2014/02/25 20:09:37 rkujawa Exp $ */
+/* $NetBSD: mcp48x1.c,v 1.2 2022/01/19 05:05:45 thorpej Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.1 2014/02/25 20:09:37 rkujawa Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.2 2022/01/19 05:05:45 thorpej Exp $");
/*
* Driver for Microchip MCP4801/MCP4811/MCP4821 DAC.
@@ -115,13 +115,9 @@
static int
mcp48x1dac_match(device_t parent, cfdata_t cf, void *aux)
{
- struct spi_attach_args *sa = aux;
/* MCP48x1 is a write-only device, so no way to detect it! */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 20000000))
- return 0;
-
return 1;
}
@@ -130,7 +126,7 @@
{
struct mcp48x1dac_softc *sc;
struct spi_attach_args *sa;
- int cf_flags;
+ int error, cf_flags;
aprint_naive(": Digital to Analog converter\n");
aprint_normal(": MCP48x1 DAC\n");
@@ -143,6 +139,13 @@
sc->sc_dm = &mcp48x1_models[cf_flags]; /* flag value defines model */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 20000000);
+ if (error) {
+ aprint_error_dev(self,
+ "failed to set Mode 0 @ 20MHz, error=%d\n", error);
+ return;
+ }
+
if(!mcp48x1dac_envsys_attach(sc)) {
aprint_error_dev(sc->sc_dev, "failed to attach envsys\n");
return;
diff -r 5ebcca281930 -r b17803897221 sys/dev/spi/oj6sh.c
--- a/sys/dev/spi/oj6sh.c Wed Jan 19 01:40:05 2022 +0000
+++ b/sys/dev/spi/oj6sh.c Wed Jan 19 05:05:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: oj6sh.c,v 1.9 2021/08/07 16:19:16 thorpej Exp $ */
+/* $NetBSD: oj6sh.c,v 1.10 2022/01/19 05:05:45 thorpej Exp $ */
/*
* Copyright (c) 2014 Genetec Corporation. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.9 2021/08/07 16:19:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.10 2022/01/19 05:05:45 thorpej Exp $");
#include "opt_oj6sh.h"
@@ -138,8 +138,6 @@
if (spi_compatible_match(sa, cf, compat_data) == 0)
return 0;
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 2500000))
- return 0;
return 2;
}
@@ -184,10 +182,18 @@
struct oj6sh_softc *sc = device_private(self);
struct spi_attach_args *sa = aux;
struct wsmousedev_attach_args a;
+ int error;
aprint_naive("\n");
aprint_normal(": OJ6SH-T25 Optical Joystick\n");
Home |
Main Index |
Thread Index |
Old Index